var host = '';//'http://www.inter247.it/';
var pageExt = 'php'; //php|fake


//forums vars
var f_user_id = '0';
var f_username = '';
var f_email = '-';

function mysqlTimeStampToDate(timestamp) {
    //function parses mysql datetime string and returns javascript Date object
    //input has to be in this format: 2007-06-05 15:26:02
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
}

//var firstNews = 0;
var maxNews = 10;
function paginationNews( idnews, tags, searchString , countItems, firstNews ){
	var html = '';
	var lastNews = firstNews + maxNews;		
	if ( lastNews > countItems ) lastNews = countItems;
	html +='<a href="#sunews">^Top</a> News ' + countItems;
	if ( (firstNews+1) != lastNews ) html += ', da ' + (firstNews+1) +  ' a ' + ( lastNews ) + ' ';	
	if ( firstNews != 0 ) html += ' <a href="javascript:void(0);" onclick="firstNews=fillNews( \''+idnews+'\', \''+tags+'\', \''+searchString+'\', '+(firstNews - maxNews) + ' );">&lt;&lt;<a> ';
	if ( lastNews < countItems ) html += ' <a href="javascript:void(0);" onclick="firstNews=fillNews( \''+idnews+'\', \''+tags+'\', \''+searchString+'\', '+(firstNews + maxNews) + ' );">&gt;&gt;</a> ';	
	return '<div>'+html+'</div>';
}

//cache
//var currentIdnews;
//var currentTags;
//var currentSearchString;
//var currentRetcode;

function fillNews( idnews, tags, searchString, first ){ 
	
	    if ( idnews != "" || tags != "" || searchString != "" ){
		     $("#sliderdiv").slideUp(1000);
		     $("#sliderdiv").html("");
		     $("#lastvideo").slideUp(1000);
		     $("#lastvideo").html("");
	     }
	
	    //if ( currentIdnews == idnews && currentTags == tags && currentSearchString == searchString ){
		//     fillHtmlNews( idnews, tags, searchString, currentRetcode, first );
		//     return;
	    //}
        
	    var url = host + 'json/news.' + pageExt;
        
        if ( idnews != "" ) url +='?id='+idnews+'&start='+first;
        if ( tags != "" ) url +='?tags='+tags+'&start='+first;
        if ( searchString != "" ) url+='?search='+searchString+'&start='+first;
        
        if ( idnews == "" && tags == "" && searchString == "" ) url+='?start='+first;
        
        $("#divnews").html('<div align="center"><br><br><img src="images/loading.gif"></div>');
        //alert( url );
        
        
        try{									
						
	       
			$.getJSON( url , 
			    function( retcode ) {  
				    //currentIdnews = idnews;   
				    //currentTags = tags;
				    //currentSearchString = searchString;
				    //currentRetcode = retcode; 
					fillHtmlNews( idnews, tags, searchString, retcode, first );
					//vai all'anchor
					//jumpToAnchor( "sunews" );
				}
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}

function getDescMese(numMese){
    if ( numMese == 1 ) return "Gennaio";
	if ( numMese == 2 ) return "Febbraio";
	if ( numMese == 3 ) return "Marzo";
	if ( numMese == 4 ) return "Aprile";
	if ( numMese == 5 ) return "Maggio";
	if ( numMese == 6 ) return "Giugno";
	if ( numMese == 7 ) return "Luglio";
	if ( numMese == 8 ) return "Agosto";
	if ( numMese == 9 ) return "Settembre";
	if ( numMese == 10 ) return "Ottobre";
	if ( numMese == 11 ) return "Novembre";
	if ( numMese == 12 ) return "Dicembre";
	return "";

}

function fillHtmlNews( idnews, tags, searchString, retcode, first ) {       
		            
	var totalRow = 0;
	var html = '';                            
	$.each(retcode , function(i,item){
		
		   var dataNews = mysqlTimeStampToDate(retcode[i].date_added); 
		   var minuti = "" + dataNews.getMinutes();
		   if ( minuti.length == 1 ) minuti = "0" + minuti;
		   var dataDettaglio =  dataNews.getDate() + ' ' + getDescMese( dataNews.getMonth() + 1 ) + ' ' + dataNews.getFullYear() + ', ore ' + dataNews.getHours() + ':' + minuti;
		   
	       //if ( idnews != ""  ){// || ( i >= firstNews && i < firstNews+maxNews )
	           var buttonsNews = '<a class="linkhome" href="javascript:void(0);" onclick="fillNews(\'\',\'\',\'\',0);">Home</a>';
	           if ( idnews == "" ) buttonsNews ='<a class="linkbutton" href="javascript:void(0);" onclick="fillNews(\''+retcode[i].id+'\',\'\',\'\',0);">Leggi tutto</a>'+
			                                    retcode[i].tags;//  + '<a style="margin:1px" class="linkperm" href="/?perm=y&idnews='+retcode[i].id+'">Permalink</a>';
	           var textNews = '<p>' +retcode[i].text_extended + '</p>';
	           
	           var leggiAnche = '';
	           var feedLins = '';
	           //var bookmark = '';
	           var fbLink = '';
	           var firma = '';
	           var gallImgNews1 = ''; 
	           var gallImgNews2 = ''; 
			   var floadImageNews = 'right';
	           
	           if ( idnews != "" ){ 
	                //alert( retcode[i].tags );
	                //textNews += '<p>' + retcode[i].text_extended + '</p>';
	                buttonsNews += retcode[i].tags;//  + '<a style="margin:1px" class="linkperm" href="/?perm=y&idnews='+retcode[i].id+'">Permalink</a>';			                                
	                if ( retcode[i].news_related != "" ) leggiAnche = '<div class="ui-state-highlight ui-corner-all" style="float:right; border: 1px solid #c3c3c3; padding:2px; margin: 2px;" id="news_related_' + retcode[i].id + '"><img src="images/spinner.gif"></div>';            
	                if ( retcode[i].feeds_related != "" ) feedLins = '<div class="ui-state-highlight ui-corner-all" style="border: 1px solid #c3c3c3; padding:2px; margin: 2px;" id="feeds_related_' + retcode[i].id + '"><img src="images/spinner.gif"></div>';            
	                //bookmark += '<div id="selectBookmark" style="margin:4px"></div><br>';
	                firma += '<b>' + retcode[i].author + '</b><br><br>';	                
	                if ( $.Params.Values['idnews'] != undefined ){
		               var url_fb = 'http%3A%2F%2Fwww.inter247.it%2F%3Fperm%3Dy%26idnews%3D' + $.Params.Values['idnews'];
		               //alert( url_fb );
		               firma += '<a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4c4a824724e86f0a"><img src="http://s7.addthis.com/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4c4a824724e86f0a"></script><br>'; 
		               fbLink = '<iframe src="http://www.facebook.com/plugins/like.php?href='+url_fb+'&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe><br>';
	                }
	                gallImgNews1 = '<a href="' + retcode[i].news_image + '" rel="prettyPhoto[news]">';
	                gallImgNews2 = '</a>';
	                
	                $.get("json/views.php?t=0&id=" + idnews );
					
					floadImageNews = 'left';
	                
	           }
	           
	           var extraIcons = '';
	           
	           if ( retcode[i].images_related != "" ) extraIcons += '<span style="float: right;" class="ui-icon ui-icon-image" title="Foto"></span>';
	           if ( retcode[i].videos_related != "" ) extraIcons += '<span style="float: right;" class="ui-icon ui-icon-video" title="Video"></span>';
	           
	           html += '<div class="ui-corner-all" style="border: 1px solid #cccccc; padding:3px; margin-bottom:2px" onmouseover="$(this).css(\'background-color\',\'#FAF8CC\');" onmouseout="$(this).css(\'background-color\',\'\');">'+
	                   '<div class="ui-widget-header ui-corner-all"" style="line-height: 16px; margin: 0px; padding:4px">' + dataDettaglio + ' - ' + retcode[i].torneo+ 
					   '<span title="Letto '+retcode[i].views+' volte" style="float: right;" class="ui-icon ui-icon-document"></span>'+extraIcons+'</div>'+
	                   '<div class="ui-state-default ui-corner-all gallery" style="float:'+floadImageNews+'; padding:2px;margin:4px; width: 150px; text-align:center;">'+
	                   gallImgNews1 + '<img border="0" width="150" src="' + retcode[i].news_image + '.thumb2.gif">'+ gallImgNews2 +
	                   '</div>' +	
	                   
	                   //bookmark +    	                                                                              
	                   '<div><h2 style="margin-bottom:2px; margin-top:2px">'+
	                   '<a style="color:#005d98;" href="/?perm=y&idnews='+retcode[i].id+'">' + retcode[i].title + '</a></h2>'+  	                                                	                                              	                                                                                      
	                   '<h3 style="margin-bottom:1px; margin-top:1px">' + retcode[i].text_news + '</h3>'+   	                                           
	                   leggiAnche +   	                                              
	                   '<div style="font-size:11px;">' + textNews + '</div>' + 
	                                    
	                   '<span id="videos_related_' + retcode[i].id + '"></span>'+                	                                            
	                   '<span id="images_related_' + retcode[i].id + '"></span>'+  
	                   '<div style="clear:both"/>' +
	                   feedLins +       
	                   '<div id="sharing">' +	                   
	                   firma +   	  
	                   fbLink +	 
	                   '</div>' +                                          
	                   buttonsNews +                                        
	                   '</div>'+
	                   '<div style="clear:both"/>'+  
	                   '</div>';
	                   
	             if ( idnews != "" ){      
	                   html += '<div class="ui-widget-content ui-corner-all" style="padding:3px; margin-bottom:2px; margin-top:2px;"><span id="commenti_' + retcode[i].id + '"></span></div>' + 
	                           '<span id="players_related_' + retcode[i].id + '"></span>';
                       //Partite collegate
					   html += '<span id="match_related_' + retcode[i].id + '"></span>';							   
                 }
	      //}//pagination
	      totalRow = retcode[i].count;         
	               
	});
	
	//paginazione         
	if ( idnews == "" ) html+= paginationNews( idnews, tags, searchString, totalRow, first );    
	                         
	$("#divnews").html('<a name="sunews"></a>' + html);
	
	
	if ( idnews != "" ){
	    $.each(retcode , function(i,item){
	         //immagini collegate
	         if ( retcode[i].images_related != "" && retcode[i].images_related != "0" ){
	           $("#images_related_" + retcode[i].id).html('<img src="images/loading.gif">');
	           fillImages( retcode[i].images_related, "prettyPhoto[news]" , "images_related_" + retcode[i].id, "height=\"100\" width=\"160\"", "span", 0 );	    	           	                              
	         }else{
		       //per immagine news (altrimenti fillImages lo lancia)
		       setTimeout( "$(\".gallery a[rel^='prettyPhoto']\").prettyPhoto({theme:'facebook'});" , 1000);    
		     }
	         
	         if ( retcode[i].videos_related != "" && retcode[i].videos_related != "0" ){
	            $("#videos_related_" + retcode[i].id).html('<img src="images/loading.gif">');
	            
	            fillVideo( retcode[i].videos_related, "videos_related_" + retcode[i].id , "span", 0 );
	         }
	         
	         if ( retcode[i].news_related != "" && retcode[i].news_related != "0" ){		                                                                       
	            fillRelatedNews(  retcode[i].news_related, "news_related_" + retcode[i].id );
	         }
	         
	         if ( retcode[i].feeds_related != "" && retcode[i].feeds_related != "0" ){		                                                                       
	            fillRelatedFeeds(  retcode[i].feeds_related , "feeds_related_" + retcode[i].id );
	         }
	         
	         if ( retcode[i].player_related != "" && retcode[i].player_related != "0" ){		                                                                       
	            fillteam(  retcode[i].player_related , "players_related_" + retcode[i].id , "" );
	         }
			 
			 if ( retcode[i].match_related != "" && retcode[i].match_related != "0" ){		                                                                       
	            searchImpegni(  retcode[i].match_related , "match_related_" + retcode[i].id );
	         }
	         
	         fillComment( retcode[i].id, "0" );
	         
	         //$('#selectBookmark').bookmark({url: 'http://www.inter247.it?perm=y&idnews='+retcode[i].id, sites: ['facebook','twitter','yahoo','delicious', 'technorati','google', 'digg', 'linkedin', 'stumbleupon'], addEmail: true});
	        
	         	
	    });
	}
	           
	setTimeout("buttonUI()", 2500);

	
	
}

function fillRelatedNews(ids, div){
	
	var url = host + 'json/news.' + pageExt;
        
    if ( ids != "" ) url +='?ids='+ids;
    
	$.getJSON( url , 
	     function( retcode ) {       
		            
	            var html = '<b>News Collegate</b><br>';                            
                $.each(retcode , function(i,item){
	                if ( i != 0 ) html +='<br>';
	                //html += '<a href="javascript:void(0);" onclick="fillNews(\''+retcode[i].id+'\',\'\',\'\',0);">' +  retcode[i].title + '</a>';           
	                html += '<a href="/?perm=y&idnews='+retcode[i].id+'">' +  retcode[i].title + '</a>';           
	                
	            });	
	            
	            html += '<br><a href="javascript:void(0)" onclick="popupUrl(\'intertv.php\');">Diretta InterTV</a>';
	            
	            $( "#"+div ).html(html);  
	     }
				
    );			
}

function fillRelatedFeeds(ids, div){
	
	var url = host + 'json/feed.' + pageExt;
        
    if ( ids != "" ) url +='?ids='+ids;
    
	$.getJSON( url , 
	     function( retcode ) {       
		            
	            var html = '<b>News Collegate</b><br>';                            
                $.each(retcode , function(i,item){
	                if ( i != 0 ) html +='<br>';
	                html += '<a href="' + retcode[i].link + '" target="_blank" rel="nofollow">' + retcode[i].rss_feed_id + ' - <i>' + retcode[i].title + '</i></a>';           
	            });	
	            
	            html+='<br><a href="http://www.sinotizie.com/sport/" target="_blank">Leggi le nostre news anche su SiNotizie.com</a>';
	            
	            $( "#"+div ).html(html);  
	     }
				
    );			
}

/*
0-News
*/
function fillComment( id, ref ){
	
	var url = host + 'json/commenti.'+ pageExt + '?id_ref='+id + '&table_ref='+ref;
        
        
        try{																        
	        
			$.getJSON( url , 
			     function( retcode ) {       				     
				            
				            var html = ''; 
				                                      				          
				            $.each(retcode , function(i,item){  
					            
					               var dataCommento = mysqlTimeStampToDate(retcode[i].date_added); 
					               var iconPerson = '<a href="javascript:void(0)" onclick="selectTab(3);forumPerson(\''+retcode[i].topic_poster+'\')"><span style="float: right;" class="ui-icon ui-icon-person" title="Utente Registrato"></span></a>';
					               var iconAnonymous= '<span style="float: right;" class="ui-icon ui-icon-help" title="Utente Anonimo"></span>';
					            
					               var iconUser = '';
					               
					               if ( retcode[i].id_user == "0" ) iconUser = iconAnonymous;
					               if ( retcode[i].id_user != "0" ) iconUser = iconPerson;
					               
					               html += '<div class="ui-widget-content ui-corner-all" style="margin-bottom:2px">';   
					               html += '<div class="ui-widget-header ui-corner-all" style="line-height: 16px; margin: 2px; padding:4px">' + retcode[i].author + ' il ' + dataCommento.getDate() + '/' + ( dataCommento.getMonth() + 1 ) + '/' + dataCommento.getFullYear() + ' ha scritto<span style="float: right;" class="ui-icon ui-icon-comment"></span>' + iconUser + '</div>';                                         
					               html += '<div style="padding:2px;">';   
					               
					               
	                      
                                   html += retcode[i].comment;
                                   html += '</div>';
                                   html += '</div>';                                   
                            });
							
							if ( html == '' ){
							   html += '<div class="ui-state-highlight ui-corner-all" style="padding:2px; margin-bottom:2px">';   
							   html += '<b>Non ci sono ancora commenti per questa news! <br/>Vuoi essere il primo? Clicca su \'Nuovo Commento\'</b>';
							   html += '</div>';
							}
                            
                            html += '<a style="margin:1px" class="linkcomment" href="javascript:void(0);" onclick="formNewComment(\''+id+'\',\''+ref+'\');">Nuovo Commento</a> <a href="javascript:void(0);" class="linkaddnews" onclick="formAddNews();">Inviaci una News</a> <a href="javascript:void(0);" class="contatti" onclick="formContatti();">Contattaci</a>';
	                              
                            
                            $("#commenti_"+id).html(html);    
                            
                            //buttonUI();              
                            //setTimeout("buttonUI()", 2500);          
                  }				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
	
}


//var f_user_id = '';
//var f_username = '';
//var f_email = '';


function formNewComment( id, ref ){
	var html = '<b>Nuovo Commento</b>';	
	
	html += '<table>';
	html += '<tr>';
	html += '<td>Utente</td>';
	html += '<td>'+f_username+'<input type="hidden" id="user" value="'+f_username+'"></td>';
	html += '</tr>'
	html += '<tr>';
	html += '<td valign="top">Commento</td>';
	html += '<td><textarea id="commento" cols="80" rows="15"></textarea><br>'+
	        '<a style="margin:1px" class="linkcomment" href="javascript:void(0);" onclick="postNewComment();">Invia</a>'+
	        '<a style="margin:1px" class="linkclose" href="javascript:void(0);" onclick=\'$("#dialog").dialog("close");\'>Chiudi</a>'+
	        '</td>';
	html += '</tr>'
	html += '<tr>';
	html += '<td></td>';
	html += '<td><div class="ui-state-highlight  ui-corner-all" id="message">Compilare i campi</div></td>';
	html += '</tr>'
	html += '</table>';
    html += '<input type="hidden" id="oper" value="new_comment">'+
            '<input type="hidden" id="id" value="'+id+'">'+
            '<input type="hidden" id="ref" value="'+ref+'">'+
            '<input type="hidden" id="voto" value="0">'+
            '<input type="hidden" id="user_id" value="'+f_user_id+'">'+
            '<input type="hidden" id="email" value="'+f_email+'">'+
            '<input type="hidden" id="stato" value="1">';             
		
    $("#dialog").html(html);
    buttonUI();    
    $("#dialog").dialog( "option", "height", 350 );
    $("#dialog").dialog('open');	

}


function postNewComment(){
  
   var user = $("#user").val();
   var commento = $("#commento").val();
   var oper = $("#oper").val();
   var id = $("#id").val();
   var ref = $("#ref").val();
   var voto = $("#voto").val();
   var ref = $("#ref").val();
   var email = $("#email").val();
   var user_id = $("#user_id").val();
   var stato = $("#stato").val();
   
   //todo
   //check field
   $("#message").html( "" );
   if ( user.length < 3 ) $("#message").html( "Valorizzare il campo utente (Min. 3 caratteri)" );
   if ( commento.length < 3 ) $("#message").html( "Valorizzare il campo commento  (Min. 3 caratteri)" );
   if ( $("#message").html() != "" ) return; 	
   
   $("#commenti_"+id).html('<img src="images/loading.gif">');    
   $.post( host + "json/hub.php", { user: user, commento: commento, oper: oper, id: id, ref: ref, voto: voto, email: email, user_id: user_id, stato: stato },
   function(data){
     $("#message").html( data );
     fillComment( id, ref );
   });	
}


//divimages
//retcode.length
//


var maxImages = 12;

//fillImages("", "prettyPhoto[foto]", "divimages", "height=\"100\" width=\"160\"", "div" );	 
function fillImages(ids, gallery, div, attr, container, start ){ 
        
	    if ( attr == "" ) attr = "height=\"100\" width=\"160\"";
	
        var url = host + 'json/images.' + pageExt;        
        if ( ids != "" && ids != "0" ) url+='?ids='+ids;        
        try{																        	        
			$.getJSON( url , 
			     function( retcode ) {   
				      fillHtmlImages( ids, gallery, div, attr, container, retcode, start );           
                 }				
			);							
	    }catch(err){
		   alert( err.description );		   
	    }
}


function fillHtmlImages( ids, gallery, div, attr, container, retcode, start ){
        var html = '';                           				           
        html += '<'+container+' class="gallery">'; 
        
        var contaImages = 0;
        var total = 0;
        
        $.each(retcode , function(i,item){
              
	           total = retcode.length;
	           
	           if ( contaImages >= maxImages ) return false;
	           
	           if ( i >= start ){	        
	               html += '<div class="ui-state-default ui-corner-all" style="float:left;padding:2px;margin:12px;width:160px;"><a href="' + retcode[i].path_image + '" rel="'+gallery+'">'+
	                       '<img border="0" '+attr+' src="' + retcode[i].path_image + '.thumb.gif" alt="' + retcode[i].name + '"></a>' +                                                                                      
	                       '<div class="ui-widget-header ui-corner-all"><span style="display: inline; float:left;" class="ui-icon ui-icon-image"></span><span style="vertical-align:sub">' + retcode[i].name  + '</span></div>' +  //+ ': ' + retcode[i].description                                                                     
	                       '</div>';	                       
	              contaImages++;     
	          }                  

        });
        
        if ( container == "div" ) html += '<div style="clear:both"/>';                
        
        //solo per pagina images e non nella news
        if ( gallery == "prettyPhoto[foto]" ){
	        
	        var lastView = total;
	        
	        if ( lastView > ( start + maxImages ) ) lastView = start + maxImages;
	        
	        var htmlIndietro = "&lt;&lt; Precedente";
	        var htmlAvanti = "Successiva &gt;&gt;";        
	        
	        if ( start != 0 )  
	           htmlIndietro =' <a href="javascript:void(0);" onclick="fillImages( \''+ids+'\',\''+gallery+'\',\''+div+'\',\'\',\''+container+'\','+(start-maxImages)+')">&lt;&lt; Precedente</a> '; 
	        
	        if ( lastView < total ) 
	           htmlAvanti =' <a href="javascript:void(0);" onclick="fillImages( \''+ids+'\',\''+gallery+'\',\''+div+'\',\'\',\''+container+'\','+lastView+')">Successiva &gt;&gt;</a> '; 
	        
	                   
	        
	        
	        html +='<p>Visualizzate da ' + (start+1) + ' a ' + lastView  + ' di ' + total + '</p>';
	        html +='<p>' + htmlIndietro + ' ' + htmlAvanti + '</p>';
	        
	    }
           
        html += '</'+container+'>';                      
        $("#"+div).html(html);
        
        setTimeout( "$(\".gallery a[rel^='prettyPhoto']\").prettyPhoto({theme:'facebook'});" , 1000);
}


var maxVideo = 12;

function fillVideo( ids, div, container, start ){ 
        
        var url = host + 'json/video.' + pageExt;
        
        if ( ids != "" && ids != "0" ) url+='?ids='+ids;
        
        try{									
							        	        
			$.getJSON( url , 
			     function( retcode ) {       
				     fillHtmlVideo( ids, div, container, start, retcode );
				 }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}

function fillHtmlVideo( ids, div, container, start, retcode ){
        var html = '';                           
				            
        html += '<'+container+'>';     
        
        var contaVideo = 0;
        var total = 0;
              
        $.each(retcode , function(i,item){
	        
	          total = retcode.length;
	           
	           if ( contaVideo >= maxVideo ) return false;
                       
	           if ( i >= start ){	     
	              html +=  '<div class="ui-state-default ui-corner-all" style="float:left; padding:2px;margin:12px; width:160px;">'+
	                       '<a href="javascript:void(0);" onclick="viewVideo('+retcode[i].id+');">'+
	                       '<img border="0" height="100" width="160" src="http://i4.ytimg.com/vi/' + retcode[i].id_video + '/default.jpg" alt="' + retcode[i].name + '"></a>' +
	                       '<div class="ui-widget-header ui-corner-all"><span style="display: inline; float:left;" class="ui-icon ui-icon-video"></span><span style="vertical-align:sub">' + retcode[i].name + '</span></div>' +                                       
	                       '</div>';
	               contaVideo++;     
	          }      
                                                      
        });
        
        //solo pagina videos
        if ( container == "div" ){
        
	        var lastView = total;
	        
	        if ( lastView > ( start + maxVideo ) ) lastView = start + maxVideo;
	        
	        if ( container == "div" ) html += '<div style="clear:both"/>';
	        
	        var htmlIndietro = "&lt;&lt; Precedente";
	        var htmlAvanti = "Successiva &gt;&gt;";        
	        
	        if ( start != 0 )  
	           htmlIndietro =' <a href="javascript:void(0);" onclick="fillVideo( \''+ids+'\',\''+div+'\',\''+container+'\','+(start-maxVideo)+')">&lt;&lt; Precedente</a> '; 
	        
	        if ( lastView < total ) 
	           htmlAvanti =' <a href="javascript:void(0);" onclick="fillVideo( \''+ids+'\',\''+div+'\',\''+container+'\','+lastView+')">Successiva &gt;&gt;</a> '; 
	        
	        
	        
	        html +='<p>Visualizzati da ' + (start+1) + ' a ' + lastView  + ' di ' + total + '</p>';
	        html +='<p>' + htmlIndietro + ' ' + htmlAvanti + '</p>';
	        
	    }
        
        html += '</'+container+'>';
      
        
        
        $("#"+div).html(html);
}

function fillImpegni(){
    searchImpegni( "" , "divimpegni" );
}


function searchImpegni( ids, div ){
	
	
        var url = host + 'json/partite.' + pageExt;
		if ( ids != "" && ids != "0" ) url+='?ids='+ids;
		
        try{									
						
	    	$.getJSON( url , 
			     function( retcode ) {       
				 
				            var today = new Date;
				     
				            var html = '';      
				            
				            
				            
                            $.each(retcode , function(i,item){   
							
									html += '<div onmouseover="$(this).css(\'background-color\',\'#FAF8CC\');" onmouseout="$(this).css(\'background-color\',\'\');" class="ui-corner-all" style="border: 1px solid #cccccc; margin-top:2px">';  
									html += '<table align="center">';
						            html += '<tbody>';  
							
									html += '<tr>';
									html += '<th class="ui-widget-header ui-corner-all" style="padding:3px" colspan="4">'+retcode[i].data+'</th>';											
									html += '</tr>';
							
							
							        var dataEvento = mysqlTimeStampToDate(retcode[i].data);
							
	                                html += '<tr>';                                                                 
									html += '<td rowspan="2" valign="top">'+
									        '<div class="ui-widget-content ui-corner-all" style="float:left;padding:2px;margin:1px;text-align:center;width:140px;">'+
											'<img width="60" height="60" border="0" src="' + retcode[i].torneo_logo + '.thumb.gif">'+
											'<br>' + retcode[i].torneo + '</div></td>';
											
									html += '<td>'+
									        '<div align="center" class="ui-widget-content ui-corner-all" style="float:left;padding:2px;margin:1px;text-align:center;width:140px;">'+
									        '<img width="60" height="60" border="0" src="' + retcode[i].t_home_logo + '.thumb.gif">'+
											'<br>' + retcode[i].t_home + '</div></td>';
									
									 
                                    if ( dataEvento < today ){
									    html += '<td align="center" width="160"><h1>' + retcode[i].goal_home + ":" + retcode[i].goal_away + '</h1></td>';
									}else{
									    html += '<td align="center" width="160"><h1 style="color: gray;">0-0</h1></td>';
									}
									
									html += '<td>'+
									        '<div class="ui-widget-content ui-corner-all" style="float:left;padding:2px;margin:1px;text-align:center;width:140px">'+
									        '<img width="60" height="60" border="0" src="' + retcode[i].t_away_logo + '.thumb.gif">'+
											'<br>' + retcode[i].t_away + '</div></td>';								
									html += '</tr>';
									html += '<tr>'; 
									html += '<td colspan="3" align="center"><div id="cd_'+retcode[i].id+'"/></td>'; 
									html += '</tr>';
									
									if ( dataEvento < today ){
													
                                        if ( retcode[i].news_related != "" ){													
										
											html += '<tr>'; 
											html += '<td colspan="4">'+										        
													'<div id="link_match_news_related_'+retcode[i].id+'" class="ui-state-highlight ui-corner-all" style="margin-top:2px; padding: 2px;">'+
													'<b>::</b> <a title="'+retcode[i].news_related+'" href="javascript:void(0);" onclick="viewNewsCollegateAlMatch('+retcode[i].id+',\''+retcode[i].news_related+'\');">Visualizza News Collegate</a></div>'+
													'<div class="ui-state-highlight ui-corner-all" style="visible: hidden; display: none;" id="match_news_related_'+retcode[i].id+'">'+
													'</div>'+
													'</td>'; 
											html += '</tr>';
										
										}

										if ( retcode[i].tabellino != "" ){
											html += '<tr>'; 
											html += '<td colspan="4"><div id="link_tabellino_'+retcode[i].id+'" class="ui-state-highlight ui-corner-all" style="margin-top:2px; padding: 2px;">'+
													'<b>::</b> <a href="javascript:void(0);" onclick="viewTabellinoMatch('+retcode[i].id+');">Visualizza Tabellino</a></div>'+
													'<div class="ui-state-highlight ui-corner-all" style="visible: hidden; display: none;" id="tabellino_'+retcode[i].id+'">' + 
													'<h3 style="color:#005d98; margin-bottom:2px; margin-top:2px">Tabellino</h3>' +
													retcode[i].tabellino + '</div></td>'; 
											html += '</tr>';
										}										
									
										html += '<tr>'; 
										html += '<td colspan="4">' + getHtmlVotiMatch(retcode[i].id) + '</td>'; 
										html += '</tr>';	
										

									}
									
									html += '<tbody>';
                                    html += '</table>';
									html += '</div>';
									
                            });

                           
                            
                            $("#"+div).html(html);
                            
                            
                            
                            $.each(retcode , function(i,item){  
	                            
	                            var dataEvento = mysqlTimeStampToDate(retcode[i].data); 
                               
	                            if ( dataEvento > today ){
								    
									$('#cd_'+retcode[i].id).countdown({
										until: dataEvento, 
										format: 'YDHMS',
										layout: '<div id="t7_timer">'+
													'<div id="t7_vals">'+
														'<div id="t7_y" class="t7_numbs">{ynn}</div>'+
														'<div id="t7_d" class="t7_numbs">{dnnn}</div>'+
														'<div id="t7_h" class="t7_numbs">{hnn}</div>'+
														'<div id="t7_m" class="t7_numbs">{mnn}</div>'+
														'<div id="t7_s" class="t7_numbs">{snn}</div>'+
													'</div>'+
													'<div id="t7_labels">'+
														'<div id="t7_yl" class="t7_labs">years</div>'+
														'<div id="t7_dl" class="t7_labs">days</div>'+
														'<div id="t7_hl" class="t7_labs">hours</div>'+
														'<div id="t7_ml" class="t7_labs">mins</div>'+
														'<div id="t7_sl" class="t7_labs">secs</div>'+
													'</div>'+
													'<div id="t7_timer_over"></div>'+
												'</div>'
										});

									}
	                        });
                            
                       }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}

function viewNewsCollegateAlMatch( idMatch, relatedNews ){
  $("#link_match_news_related_" + idMatch ).slideUp(1000);  
  $("#match_news_related_" + idMatch ).slideDown(1000); 
  if ( relatedNews != "" && relatedNews != "0" ){
     $("#match_news_related_" + idMatch ).html('<img align="absmiddle" src="images/spinner.gif"> Processing...');  
      fillRelatedNews(  relatedNews, "match_news_related_" + idMatch );
  }else{
     $("#match_news_related_" + idMatch ).html("Nessun news collegata a questa partita");
  }
}


function viewTabellinoMatch(idMatch){
  $("#link_tabellino_" + idMatch ).slideUp(1000);  
  $("#tabellino_" + idMatch ).slideDown(1000);  
}

function fillSlider(){ 
        
        var url = host + 'json/news.' + pageExt + '?slider=y';
        try{									
						
	        
	        
			$.getJSON( url , 
			     function( retcode ) {       
				     
				            var html = '';      
				            html += '<ul class="slideView">';                      
                            $.each(retcode , function(i,item){
	                             
	                                //if ( retcode[i].in_teaser == "1" ){                                                                 
										html += '<li id="' + retcode[i].id + '"><a href="javascript:void(0)" onclick="fillNews(\''+retcode[i].id+'\',\'\',\'\',0);"><img src="' + retcode[i].news_image + '.thumb.gif" alt="' + retcode[i].title + '" /></a></li>';
									//}
                            });
                            html += '</ul>';
                            
                            $("#slideshow").html(html);
                            
                       }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}


//var firstFeed = 0;
var maxFeed = 5;
function paginationFeed( searchString , countItems, firstFeed ){
	var html = '';
	var lastFeed = firstFeed + maxFeed;
	if ( lastFeed > countItems ) lastFeed = countItems;
	html +='<a href="#sufeed">^Top</a> News ' + countItems;
	if ( (firstFeed+1) != lastFeed )  html += ', da ' + (firstFeed+1) +  ' a ' + ( lastFeed ) + ' ';	
	if ( firstFeed != 0 ) html += ' <a href="javascript:void(0);" onclick="fillFeed( \''+searchString+'\', ' + ( firstFeed - maxFeed ) + ' );">&lt;&lt;<a> ';
	if ( lastFeed < countItems ) html += ' <a href="javascript:void(0);" onclick="fillFeed( \''+searchString+'\', ' + ( firstFeed + maxFeed ) + ' );">&gt;&gt;</a> ';	
	return '<div>'+html+'</div>';
}

//cache
//var currentSearchString;
//var currentFeedRetcode;

function fillFeed(searchString, first){
	
	//if ( searchString == currentSearchString ){		 
	//	 fillHtmlFeed( searchString , currentFeedRetcode );
	//	 return;
	//}
			
	var url = host + 'json/feed.' + pageExt;
	if ( searchString != "" ) 
	   url+='?search='+searchString+'&start='+first;
	else
	   url+='?start='+first;
        try{									
						
	        // ID rss_feed_id link title description 
	        $("#divaccordion").html('<div align="center"><br><br><img src="images/loading.gif"></div>');
	        
			$.getJSON( url , 
			     function( retcode ) {       
				    //currentSearchString = searchString; 
				    //currentFeedRetcode = retcode;
		            fillHtmlFeed( searchString, retcode, first );                    		   
               }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
	          					
}

function fillHtmlFeed( searchString, retcode, first ) {       
				     
	    var html = '';       
	    var totalRow = 0;                     
	    $.each(retcode , function(i,item){
	          //if ( i >= firstFeed && i < firstFeed+maxFeed ){//pagination
	              if ( retcode[i].description == retcode[i].title ) retcode[i].description = 'Leggi';	                              
	              html +=  '<h3><a href="#">' + retcode[i].title + ' - <i>' + retcode[i].rss_feed_id + '</i></a></h3>' +
						   '<div>'+ 
						    retcode[i].description + ' ' +											    
							'[<a style="color:#005d98;" rel="nofollow" target="_blank" href="' + retcode[i].link + '">leggi tutto</a>]'+
							'</div>';
			  //}//paginazione
			  totalRow = retcode[i].count;
	    });
	    
	    
	    
	     
	    $("#divaccordion").html( html);
	    $("#divaccordion").accordion("destroy").accordion({autoHeight: false});
	    
	    //paginazione         
	    $("#divaccordionpagination").html( paginationFeed( searchString, totalRow , first ) );   
    

}


function viewNews(id){
	
	    var url = host + 'json/news.'+pageExt+'?id='+id;
        
	    try{									
		    
			$.getJSON( url , 
			     function( retcode ) {       
				     
				            var html = '';                            
                            $.each(retcode , function(i,item){
                                  //$("#dialog").attr("title", retcode[i].title );
                                  html += '<div  class="ui-widget-content ui-corner-all" style="padding:2px;">'+
                                           '<div class="ui-state-default ui-corner-all" style="float:left; padding:2px;margin:2px; width: 180px; text-align:center;">'+
                                           '<img width="180" src="' + retcode[i].news_image + '">'+
                                           '<br>Inter247.it News' +
                                           '</div>' +
                                           '<div style="float:left: width:100%"><h2>' + retcode[i].title + '</h2>'+                                             
                                           '<h4>' + retcode[i].text_news + '</h4>'+   
                                           '<p>' + retcode[i].text_extended + '</p>'+   
                                           '</div>'+
                                           '<div style="clear:both"/>'+
                                           '</div><br>';
                              
                            });
                          
                            $("#dialog").html(html);
                            $("#dialog").dialog('open');	

                       }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
		
}



function viewVideo(id){ 
        
        var url = host + 'json/video.'+pageExt+'?id='+id;
        try{									
						
	        //add views
	        $.get("json/views.php?t=2&id=" + id );
	        
			$.getJSON( url , 
			     function( retcode ) {       
				     
				            var html = '';                           
				            
				            html += '<div>';           
                            $.each(retcode , function(i,item){
                                  html += '<div class="ui-widget-content ui-corner-all" style="padding:2px;" align="center">'+
                                           '<object width="620" height="400"><param name="movie" value="http://www.youtube.com/v/'+retcode[i].id_video+'&hl=it_IT&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+retcode[i].id_video+'&hl=it_IT&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="620" height="400"></embed></object>'+                                           
                                           '</div>'+
                                           '<h3>' + retcode[i].name +'</h3>';
                            });
                            html += '</div>';
                          
                            
                            
                            $("#dialog").html(html);
                            $("#dialog").dialog( "option", "height", 480 );
                            $("#dialog").dialog('open');	

                       }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}

function popupUrl(url){ 
	    $("#lastvideo").hide();
		$("#lastvideo").html("");        
        $("#dialog").dialog( "option", "height", 480 );
        $("#dialog").dialog('open');
        $("#dialog").load(url);
}

function fillClassifica( page ){
	
	var url = host + 'json/'+page;
        try{									
						
	        
	        
			$.getJSON( url , 
			     function( retcode ) {       
				            //matches_won":21,"matches_drawn":10,"matches_lost":4,"goals_conceeded":31,"goals_scored":68
				            var html = '';                           
				            html += '<div class="ui-widget-content ui-corner-all">';  
				            html += '<table>';  
				            html += '<thead>';  
				            html += '<tr>';
				            html += '<th class="ui-widget-content ui-corner-all">#</th>'+
				                    '<th class="ui-widget-content ui-corner-all">Punti</th>'+
				                    '<th class="ui-widget-content ui-corner-all">Squadra</th>'+
				                    '<th class="ui-widget-content ui-corner-all">Giocate</th>';
				            html += '<th class="ui-widget-content ui-corner-all">Vinte</th>'+
				                    '<th class="ui-widget-content ui-corner-all">Pareggiate</th>'+
				                    '<th class="ui-widget-content ui-corner-all">Perse</th>'+
				                    '<th class="ui-widget-content ui-corner-all">Goal Fatti</th>'+
				                    '<th class="ui-widget-content ui-corner-all">Goal Subiti</th>';
				            html += '</tr>';
				            html += '</thead>';     
				            html += '<tbody>';    
                            $.each(retcode.items , function(i,item){
								html += '<tr>';
								html += '<td>'+retcode.items[i].position+'</td>'+
								        '<td><b>'+retcode.items[i].points+'</b></td>'+
								        '<td><b>'+retcode.items[i].team+'</b></td>' +
								        '<td>'+retcode.items[i].matches_played+'</td>'+
								        '<td>'+retcode.items[i].matches_won+'</td>'+
								        '<td>'+retcode.items[i].matches_drawn+'</td>'+
								        '<td>'+retcode.items[i].matches_lost+'</td>' +
								        '<td>'+retcode.items[i].goals_scored+'</td>' +
								        '<td>'+retcode.items[i].goals_conceeded+'</td>';
								html += '</tr>';
                            });
                            html += '</tbody>';
                            html += '</table>';
                            html += '</div>';
                          
                            
                            
                            $("#divclassifica").html(html);	

                       }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}

//I1.csv
function fillCSVSeason( csvfile, divtable ){
	
	var url = host + 'csv/' + csvfile;
	var html = '';
	jQuery.get(url,
	    function(data) { 
		    
		    //$("#"+divtable ).html( data );
		    
		    var lines = jQuery.csv()(data); 
		    
		    var contaPartiteGiornata = 0;
			var giornata = 1; 
		    
		    //alert( lines.length );
		    html += '<div class="ui-widget-content ui-corner-all">';  
		    html += '<table>';
		    html += '<thead>';  
		    html += '<tr>';
		    var legendrow = '<th class="ui-widget-content ui-corner-all">Data</th>'+
				            '<th class="ui-widget-content ui-corner-all">Squadra</th>'+
				            '<th class="ui-widget-content ui-corner-all">Squadra</th>'+
				            '<th class="ui-widget-content ui-corner-all">Ris.</th>'+		            
				            '<th class="ui-widget-content ui-corner-all" title="Tiri squadra di casa">HS</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Tiri squadra fuori casa">AS</th>'+ 
				            '<th class="ui-widget-content ui-corner-all" title="Tiri squadra di casa nello specchio">HST</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Tiri squadra fuori casa nello specchio">AST</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Falli squadra di casa">HF</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Falli squadra fuori casa">AF</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Corners squadra di casa">HC</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Corners squadra fuori casa">AC</th>'+		            
				            '<th class="ui-widget-content ui-corner-all" title="Cart. gialli squadra di casa">HY</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Cart. gialli fuori casa">AY</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Cart. rossi squadra di casa">HR</th>'+
				            '<th class="ui-widget-content ui-corner-all" title="Cart. rossi squadra fuori casa">AR</th>';
		    legendrow += '</tr>';	
		    
		    html += legendrow;    
			html += '</thead>';     
			html += '<tbody>';    
			
			var contaPartiteGiornata = 0;
			var giornata = 1; 
			
			html += '<tr>';
			html += '<th colspan="18" class="ui-widget-content ui-corner-all">Giornata '+giornata+'</th>';
			html += '</tr>';
			giornata++;
			
		    for (var x = 1; x < lines.length; x++) {
			    
			    var data = lines[x][1];
			    var homeT = lines[x][2];
			    var awayT = lines[x][3];
			    var homeG = lines[x][4];
			    var awayG = lines[x][5];
			    
			    var hs = lines[x][10];
			    var as = lines[x][11];
			    var hst = lines[x][12];
			    var ast = lines[x][13];
			    var hf = lines[x][14];
			    var af = lines[x][15];
			    
			    var hc = lines[x][16];
			    var ac = lines[x][17];
			    
				var hy = lines[x][18];
				var ay = lines[x][19];
				
				var hr = lines[x][20];
				var ar = lines[x][21];		    
			    
			     
			    if ( contaPartiteGiornata == 10 && data != undefined ){
					html += '<tr>';
					html += '<th colspan="18" class="ui-widget-content ui-corner-all">Giornata '+giornata+'</th>';
					html += '</tr>';
					html += legendrow;
					giornata++;
					contaPartiteGiornata = 0;
		        }
			    

			    if ( data != undefined ){
				    html += '<tr>';
	                html += '<td>' + data + '</td><td><b>' + homeT + '</b></td><td><b>' + awayT + '</b></td><td><b>' + homeG + ':' +  awayG + '</b></td>'; 
	                html += '<td>' + hs + '</td><td>' + as + '</td>';
	                html += '<td>' + hst + '</td><td>' + ast + '</td>';
	                html += '<td>' + hf + '</td><td>' + af + '</td>';
	                html += '<td>' + hc + '</td><td>' + ac + '</td>';
	                html += '<td>' + hy + '</td><td>' + ay + '</td>';
	                html += '<td>' + hr + '</td><td>' + ar + '</td>';
	                html += '</tr>';   
	            }
	            
	            contaPartiteGiornata++;
	            

                
		    }
		    html += '</tbody>';
		    html += '</table>';
		    html += '</div>';

		    
		    $("#"+divtable ).html( html );
		    
		}
    );
	
	
	
	
}



//var firstTopic = 0;
var maxTopic = 5;
function paginationTopics( div , countItems, firstTopic ){
	var html = '';
	var lastTopic = firstTopic + maxTopic;		
	if ( lastTopic > countItems ) lastTopic = countItems;
	html +='Topics ' + countItems;
	if ( (firstTopic+1) != lastTopic ) html += ', da ' + (firstTopic+1) +  ' a ' + ( lastTopic ) + ' ';	
	if ( firstTopic != 0 ) html += ' <a href="javascript:void(0);" onclick="fillTopics( \''+div+'\', ' + ( firstTopic - maxTopic ) + ' );">&lt;&lt;<a> ';
	if ( lastTopic < countItems ) html += ' <a href="javascript:void(0);" onclick="fillTopics( \''+div+'\', ' + ( firstTopic + maxTopic ) + ' );">&gt;&gt;</a> ';	
	return '<div class="ui-widget-content ui-corner-all" style="padding:2px;margin-top:2px;">'+html+'</div>';
}


//var currentTopicsRetcode;
//var currentDiv;

function fillTopics( div , first ){ 
	
	    //if ( currentDiv == div ){
		//   fillHtmlTopics( div, currentTopicsRetcode );
		//   return;
	    //}
        
        var url = host + 'json/topics.'+pageExt;
        
        if ( first != "" ) url+='?start='+first;
        
        try{									
							        	        
			$.getJSON( url , 
			     function( retcode ) {  
				           //currentTopicsRetcode = retcode;
				           //currentDiv = div; 				     
				           fillHtmlTopics( div , retcode, first );
                       }				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}


function fillHtmlTopics( div, retcode, first ) {       
     
            var html = '';                           
            
            html +=  '<div class="ui-widget-header ui-corner-all"" style="line-height: 16px; margin: 0px; padding:4px">Dai forums<span style="float: right;" class="ui-icon ui-icon-comment"></span></div>';                                                 
                  
            var total = 0;
                       
            $.each(retcode , function(i,item){
                  //if ( i >= firstTopic && i < firstTopic+maxTopic ){//pagination
                      var iconPost = '<span style="display: inline; padding-left:16px;" class="ui-icon ui-icon-comment"></span>';
                      var iconPool = '<span style="display: inline; padding-left:16px;" class="ui-icon ui-icon-check"></span>';
                      var iconPerson = '<a href="javascript:void(0)" onclick="selectTab(3);forumPerson(\''+retcode[i].topic_poster+'\')"><span style="display: inline; padding-left:16px;" class="ui-icon ui-icon-person"></span></a>';

                      
                      var icons = iconPost + iconPerson;
                      if ( retcode[i].poll_title != "" ) icons=iconPool + iconPerson;
                      html +=  '<div class="ui-state-highlight ui-corner-all" style="margin:1px">'+icons+'<a href="javascript:void(0)" onclick="selectTab(3);forumUrl(\''+retcode[i].forum_id+'\',\''+retcode[i].topic_id+'\')">' + retcode[i].topic_title + '</a></div>';
                  //}//pagination
                  
                  total = retcode[i].count;
                                                          
            });
          
            //paginazione         
            html+= paginationTopics( div, total, first );    
            $("#"+div).html(html);
}




function getUserLoginForum( div ){
	 
	   var now = new Date();
       var ticks = now.getTime();
	
       //alert(ticks);
       
       
	   var url = host + 'json/loginforum.'+pageExt+'?tick='+ticks;
       var anonymous = 'Utente Anonimo';
       try{									
							        	        
			$.getJSON( url , 
			     function( retcode ) {       
				     
				            var html = '';                           
				          
				            //alert( retcode.logged );
				              
				            if ( retcode.logged == "0" ){
					            html += anonymous + ' (<a href="javascript:void(0);" onclick="selectTab(3);forumLogin();">Login/Registrati</a>)';
				            	f_user_id = '0';
					            f_username = anonymous;
					            f_email = '-';
					            
					            $("#div_registrati").show();
					        }
				            if ( retcode.logged == "1" ) {
					            html += retcode.username + ' (' + retcode.email + ')';
					            f_user_id = retcode.user_id;
					            f_username = retcode.username;
					            f_email = retcode.email;
					        }                            
                   
					        
                            $("#"+div).html(html);
                 }
				
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}



function formAddNews(){
	var html = '<b>Invio Notizia su Inter247.it</b>';	
	
	html += '<table>';
	html += '<tr>';
	html += '<td>Utente</td>';
	html += '<td>'+f_username+'<input type="hidden" id="user" value="'+f_username+'"></td>';
	html += '</tr>'
	
	html += '<tr>';
	html += '<td>Email (Opzionale)</td>';
	html += '<td><input type="text" id="email" size="30"></td>';
	html += '</tr>'
	
	html += '<tr>';
	html += '<td>Titolo Notizia</td>';
	html += '<td><input type="text" id="titolo" size="40"></td>';
	html += '</tr>'
	
	html += '<tr>';
	html += '<td valign="top">Testo Notizia</td>';
	html += '<td><textarea id="notizia" cols="80" rows="20"></textarea><br>'+
	        '<span id="btnInvia"><a style="margin:1px" class="linkcomment" href="javascript:void(0);" onclick="postAddNews();">Invia</a></span>'+
	        '<a style="margin:1px" class="linkclose" href="javascript:void(0);" onclick=\'$("#dialog").dialog("close");\'>Chiudi</a>'+
	        '</td>';
	html += '</tr>'
	html += '<tr>';
	html += '<td></td>';
	html += '<td><div class="ui-state-highlight  ui-corner-all" id="message">Compilare i campi</div></td>';
	html += '</tr>'
	html += '</table>';
            
		
    $("#dialog").html(html);
    buttonUI();    
    $("#dialog").dialog( "option", "height", 450 );
    $("#dialog").dialog('open');	

}

function postAddNews(){
  
   var user = $("#user").val();
   var titolo = $("#titolo").val();
   var notizia = $("#notizia").val();
   var email = $("#email").val();

   
   
   
   //todo
   //check field
   $("#message").html( "" );
   if ( notizia.length < 50 ) $("#message").html( "Valorizzare il campo Testo Notizia (Min. 50 caratteri)" );
   if ( titolo.length < 3 ) $("#message").html( "Valorizzare il campo Titolo Notizia (Min. 3 caratteri)" );   
   if ( $("#message").html() != "" ) return; 	
   
   $("#message").html('<img src="images/spinner.gif">');    
   $.post( host + "json/hub.php", { user: user, titolo: titolo, notizia: notizia, email: email, oper: 'add_news' },
   function(data){
     $("#message").html( data );
     $("#btnInvia").html( "" );
   });	
}


function formContatti(){
	var html = '<b>Contatta lo Staff di Inter247.it</b>';	
	
	html += '<table>';
	html += '<tr>';
	html += '<td>Utente</td>';
	html += '<td>'+f_username+'<input type="hidden" id="user" value="'+f_username+'"></td>';
	html += '</tr>'
		
    html += '<tr>';
	html += '<td>Email (Opzionale)</td>';
	html += '<td><input type="text" id="email" size="30"></td>';
	html += '</tr>'
	
	html += '<tr>';
	html += '<td valign="top">Messaggio</td>';
	html += '<td><textarea id="messaggio" cols="80" rows="20"></textarea><br>'+
	        '<span id="btnInviaMessaggio"><a style="margin:1px" class="linkcomment" href="javascript:void(0);" onclick="postContatti();">Invia</a></span>'+
	        '<a style="margin:1px" class="linkclose" href="javascript:void(0);" onclick=\'$("#dialog").dialog("close");\'>Chiudi</a>'+
	        '</td>';
	html += '</tr>'
	html += '<tr>';
	html += '<td></td>';
	html += '<td><div class="ui-state-highlight  ui-corner-all" id="message">Compilare i campi</div></td>';
	html += '</tr>'
	html += '</table>';
            
		
    $("#dialog").html(html);
    buttonUI();    
    $("#dialog").dialog( "option", "height", 450 );
    $("#dialog").dialog('open');	

}

function postContatti(){
  
   var user = $("#user").val();
   var email = $("#email").val();
   var messaggio = $("#messaggio").val();

   //todo
   //check field
   $("#message").html( "" );
   if ( messaggio.length < 3 ) $("#message").html( "Valorizzare il campo Messaggio (Min. 3 caratteri)" );   
   if ( $("#message").html() != "" ) return; 	
   
   $("#message").html('<img src="images/spinner.gif">');    
   $.post( host + "json/hub.php", { user: user, messaggio: messaggio,email: email, oper: 'add_contatti' },
   function(data){
     $("#message").html( data );
     $("#btnInviaMessaggio").html( "" );
   });	
}


//Simple jump to anchor point 
function jumpToAnchor(anchor){ 
	location.href = location.href+"#"+ anchor; 
} //Nice little


function fillSliderTabs(){ 
				        
        var url = host + 'json/news.' + pageExt + '?slider=y';
        try{																		
			$.getJSON( url , 
			     function( retcode ) {       								    
				            var html = ''; 
				            html += '<ul id="s3sliderContent">';                     
				            $.each(retcode , function(i,item){
	                                //if ( retcode[i].in_teaser == "1" ){   
		                                html += '<li class="s3sliderImage">';
		                                html += '<a href="javascript:void(0)" onclick="fillNews(\''+retcode[i].id+'\',\'\',\'\',0);"><img height="250" width="450" src="' + retcode[i].news_image + '.thumb.gif" /></a>';   
		                                html += '<span class="bottom"><strong>' + retcode[i].title + '</strong><br/>' + retcode[i].text_news + '<br/><br/></span>';						                                                                                         
										html += '</li>';														
								    //}
								    
							});
							
							html += '<div class="clear s3sliderImage"></div>';
                            html += '</ul>';
                             			                            
                            $("#s3slider").html(html);
                            $("#s3slider").s3Slider({
					            timeOut: 5000
					        });				                            
                       }								
			);						
	
	    }catch(err){
		   alert( err.description );		   
	    }
}
				
