document.domain = "sky.it";
//document.domain = "localhost";
var staticBaseURL = "http://static.sky.it";

function clearSearch() {
	document.getElementById('inputRicerca').value='';
}

function setOn(target,sezione){
	if (target.indexOf("suSkyImg")!= -1){
		var target2 = target.replace(/suSkyImg/, "inReteImg");
		var scrollsky = target.replace(/suSkyImg/, "divScrollSuSky");
		var scrollrete = target.replace(/suSkyImg/, "divScrollInRete");
		//alert("target: "+target+ " target2: "+target2+ " scrollsky: "+scrollsky+ " scrollrete: "+scrollrete);
		document.getElementById(target).src='/static/images/sito/labelSuSky'+sezione+'On.gif';
		document.getElementById(target2).src='/static/images/sito/labelInReteOff.gif';
		
		
		document.getElementById(scrollrete).style.display='none';
		document.getElementById(scrollsky).style.display='block';
		
	}
	if (target.indexOf("inReteImg")!= -1){
		var target2 = target.replace(/inReteImg/, "suSkyImg");
		var scrollsky = target.replace(/inReteImg/, "divScrollSuSky");
		var scrollrete = target.replace(/inReteImg/, "divScrollInRete");
		//alert("target: "+target+ " target2: "+target2+ " scrollsky: "+scrollsky+ " scrollrete: "+scrollrete);
		document.getElementById(target2).src='/static/images/sito/labelSuSkyOff.gif';
		document.getElementById(target).src='/static/images/sito/labelInReteOn.gif';
		
		document.getElementById(scrollrete).style.display='block';
		document.getElementById(scrollsky).style.display='none';
	}
}

// Funzioni PopUp

function openpopupGenerico(urlPopup,popWidth,popHeight){
	window.open(urlPopup,'','width='+popWidth+',height='+popHeight+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
}

function openpopup(urlPopup)
{
window.open(urlPopup,"","width=500,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=5,left=5");
}

function openpopupMp3(urlMp3) {
	var url = "/common/mp3player.html?f="+urlMp3;
	window.open(url, "", "width=235,height=111,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=5,left=5");
}

function openpopupLiveSport(urlPopup)
{
window.open(urlPopup,"","width=697,height=375,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=200,left=400");
}

function openpopupLiveTg24(urlPopup)
{
window.open(urlPopup,"","width=575,height=370,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=200,left=400");
}

function openpopupPhotogallery(urlPopup)
{
	window.open(urlPopup,"","width=820,height=740,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=5,left=5");
	//window.open(urlPopup,"","width=820,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=5,left=5");
}

function openpopupPhotogalleryLink(urlPopup)
{
	window.open(urlPopup,"","width=800,height=600,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,top=50,left=50");
}

function openpopupAudio(urlPopup)
{
window.open(urlPopup,"","width=383,height=124,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=300,left=300");
}

// Generatore numero random per i bannerADV
v_randomnumber=Math.random()*10000000000000000;

// Fix immagini PNG
$().ready(function() {
		thisPage = document.location.href;
		if (thisPage.search("speciale_elezioni/2009/") == -1 && thisPage.search("rugby/sixnations/") == -1 )
		{
			$(".fixmypng").pngfix();
		}
	}
);

//Ricerca Google Spalla Destra
function sendSearch(){
		mySch=$("#mS").val();
		if (mySch=='Ricerca nel sito'){
			mySch='';
		}
		var prefix = '';
		(document.location.href.indexOf("guidatv.sky.it")>=0)?prefix="http://www.sky.it":"";
		location.href=prefix+'/common/sky_search.html?q=' + mySch;
}
	
	
function onEnterSearch(evt) {
		var keyCode = null;
		if( evt.which ) 
		{
			keyCode = evt.which;
		} 
		else if(evt.keyCode) 
		{
			keyCode = evt.keyCode;
		}
		if(13 == keyCode) {
			sendSearch();
		}
}


function bookmarkURL(bookmark, url, title) {
	var new_url = bookmark + 'url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
	window.open(new_url);
}

function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}


function inviaURLAmico(url) {
	var uri = "";
	uri += "http://www.sky.it/common/invia_amico.html?pageLink=" + arguments[0];
	if (arguments.length >= 2) { uri += "&sez="	+ arguments[1]; }
	if (arguments.length >= 3) { uri += "&ssez=" + arguments[2]; }
	if (arguments.length >= 4) { uri += "&sssez=" + arguments[3]; }

	popupOW(uri, 'invia_amico', 500, 400, 'scrollbar=no');
}


// Creazione ADV iFrame
function createAdvFrame(w,h,page,sez){
	/*if (sez!="olimpiadi"){*/
		// Creazione Iframe vuoto
		myWidth=w;
		myHeight=h;
		myIF = 'frAdv'+Math.ceil(Math.random()*1000000);
		document.write("<IFRAME ID='"+myIF+"' width='"+myWidth+"' height='"+myHeight+"' src='"+page+"' marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='no' bordercolor='#000000'></IFRAME>");
	/*}*/
}

// Refresh ADV iFrame
function refreshAdvFrame(){
	var data = new Date()
	var allAdv= jQuery("iframe[id^='frAdv']");
	for(var i=0;i<allAdv.length;i++){
		var mySrc=allAdv[i].src
		if (mySrc.indexOf('?rel=')!=-1){
			mySrc=mySrc.substr(0,mySrc.indexOf('?rel='));
		}
		allAdv[i].src=mySrc + '?rel='+data.getMilliseconds()
	}
}

// Creazione Brick x Preview
function createBrickFrame(brick,w,h){
	var myIF = 'frBrk'+Math.ceil(Math.random()*1000000);
	var page="http://www.sky.it/contenuti/brick/masterBrick.shtml?p="+brick+"&n="+myIF
	document.write("<IFRAME ID='"+myIF+"' width='"+w+"' height='"+h+"' src='"+page+"' marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='no' bordercolor='#000000'></IFRAME>");
}

//refresha le chiamate nielsen (iframe + url passato come parametro)
function nielsenRefresh(url) {
	var baseUrl = "http://secure-it.imrworldwide.com/cgi-bin/m?ci=sky-it&rnd="+new Date().getTime()+"&cg=0&si=";
	url = baseUrl + escape(url);
	t= new Image()
	t.src=url;
	refreshAdvFrame();
}

function isLogged() {
	return !($("#username").length > 0 && $("#password").length > 0) && $(".login_error").length == 0;
}



/******************** BANNER OLIMPIADI ************************/
$(document).ready(function() {
			$.getJSON("/EtSkyIt/getServerDate.do",
				function(data){
				  currentDate = o2s.parseDate(data.TIMESTAMP, "dd/mm/yyyy HH:ii:ss");
   					formatDate = o2s.format(currentDate, "yyyymmddHHiiss")
				 	 if(formatDate >= "20100211030000" && (document.location.href=="http://www.sky.it/" || document.location.href.indexOf("/sport/") != -1 || document.location.href.indexOf("/home/") != -1 || document.location.href.indexOf("/guidatv/")!= -1 )){
						$("#extra-logo").css('height', "71px");
						$("#extra-logo").html('<a href="http://sport.sky.it/sport/olimpiadi/index.html"><img width="225" border="0" src="http://www.sky.it/static/images/sezioni/sport/olimpiadi/vancouver_official.gif"></a>');
					}
				 	
				});
		});
/******************** FINE BANNER OLIMPIADI ************************/