vp3_startSess = new Date;

var countgames = 0;
var currgame = 1;
var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,width=600,height=460';
var currSubmenuShow = null;
var classNameOn = 'menu2 on';
var classNameOff = 'menu2 off';
var fontDimension = 0;
var urlVideoPanFirst = '';


/*function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}
IncludeJavaScript('https://areaclienti.mediasetpremium.it/res_AC2/js/jquery.base64.js');*/
var panoramico1 = '';
var panoramico2 = '';
var panoramico3 = '';

function initShow(page_id){	
	if (document.getElementById) {	  			
		var currSezShow = document.getElementById(page_id);	
		if (currSezShow != null)	
			currSezShow.className = 'on';
		else return;	
				
		currSubmenuShow = currSezShow.parentNode;		
	  if (currSubmenuShow != null)
			currSubmenuShow.className=classNameOn;
	}
}

function openMenu(id)
{
		if (document.getElementById){
			var menu = document.getElementById(id);
			if (menu == null || menu == currSubmenuShow ) return;
			
			menu.className=classNameOn;
  		if (currSubmenuShow != null) 
  			currSubmenuShow.className=classNameOff;
  		currSubmenuShow = menu;			    
		}			
}

function initShowPage(){
	var id_page ='';
	var url = document.location.href;
	var name_page =url.substring( url.lastIndexOf('/')+1 ,url.lastIndexOf('.') );
	switch (name_page)
			{
				case 'index_champions' : id_page = 'sez1';break;
				case 'index_campionato' : id_page = 'sez2';break;
				case 'index_cinema' : id_page = 'sez3';break;
				case 'index_serietv' : id_page = 'sez4';break;
				case 'index_reality' : id_page = 'sez5';break;				
				case 'index_teatro' : id_page = 'sez30';break;
				case 'index_comeselezevento' : id_page = 'sez6';break;
				case 'index_offerte' : id_page = 'sez8';break;
				case 'index_tutteofferte' : id_page = 'sez12';break;
				case 'index_comeselezofferta' : id_page = 'sez13';break;				
				case 'index_latessera' : id_page = 'sez9';break;
				case 'tracciapianocommerciale' : id_page = 'pag_tessera_dove_trovarla';break;
				case 'index_attivatessera' : id_page = 'sez16';break;				
				case 'index_letuericariche' : id_page = 'sez10';break;
				case 'index_acquistaricarica' : id_page = 'sez17';break;
				case 'index_ricaricatessera' : id_page = 'sez18';break;
				case 'copertura' : id_page = 'pag_copertura';break;
				case 'boxinterattivo_ricerca' : id_page = 'pag_boxinterattivo_ricerca';break;
				case 'installatori' : id_page = 'pag_installatori';break;
				default:
			}
			
	if (id_page!='') 
			initShow(id_page);
}




/*
function closeMenu(ID) {
	var menu = document.getElementById(ID);
	var uls = document.getElementsByTagName("ul");
	for (i=0;i<uls.length;i++) {
		if(uls[i].getAttribute("class")=="menu2") uls[i].style.display = "none";
		if(uls[i].getAttribute("id") && uls[i].getAttribute("id").search("sub")!= -1) uls[i].style.display = "none";
	}
}
*/

function invia(titolo){				
	var domaininvia='www.mediasetpremium.mediaset.it';
	var urlinvia=document.location.href;
	var subjPrefix="Articolo su "+domaininvia+": ";
	var bodyPrefix="Puoi trovare questo articolo all'indirizzo:\n\n";
	var bodyFooter="\n\n----------\nNews sempre aggiornate su http://"+domaininvia+"/";
	var subj=escape(subjPrefix+titolo);
	var body=escape(bodyPrefix+urlinvia+bodyFooter);
	var popup=window.open("mailto:?subject="+subj+"&body="+body,"mail");
}

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return (theWindow)?false:true;
}



function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);

}

function isUndefined(v) {

    var undef;

    return v===undef;

}

function next()
{		
	if (currgame < countgames)
	{
		document.getElementById("game-"+currgame).style.display = "none";
		document.getElementById("gametable-"+currgame).style.display = "none";
		currgame++;	
		document.getElementById("gametable-"+currgame).style.display = "block";
		document.getElementById("game-"+currgame).style.display = "block";
	}
	else
	{
		document.getElementById("gametable-"+currgame).style.display = "none";
		document.getElementById("game-"+currgame).style.display = "none";
		currgame = 1;
		document.getElementById("gametable-"+currgame).style.display = "block";
		document.getElementById("game-"+currgame).style.display = "block";
	}
}

function prev()
{
	if (currgame > 1)
	{
		document.getElementById("game-"+currgame).style.display = "none";
		document.getElementById("gametable-"+currgame).style.display = "none";
		currgame--;
		document.getElementById("gametable-"+currgame).style.display = "block";
		document.getElementById("game-"+currgame).style.display = "block";
	}
	else
	{
		document.getElementById("game-"+currgame).style.display = "none";
		document.getElementById("gametable-"+currgame).style.display = "none";
		currgame = countgames;
		document.getElementById("gametable-"+currgame).style.display = "block";
		document.getElementById("game-"+currgame).style.display = "block";
	}
}

/* **
	gestione banner 
*/
var loccode_120x240 = "m1mlgmgmbm";
var rnum=parseInt((Math.random()*(Date.parse(new Date()))));

function buildbanner(bannertype){	
	document.write('<sc'+'ri'+'pt language=javascript src="http://ad1.neodatagroup.com/ad/pub80.jsp?a='+loccode_120x240+'|rnd='+rnum+'"></sc'+'ri'+'pt>');
}

// funzioni per la ricerca google

function initFieldSearch(objform){
	var url;
	if(readUrl('cerca') !=''){
		for(i=0; i<objform.length; i++){
					if(objform.elements[i].id =='cerca'){
					url = readUrl('cerca');
					url = url.replace("+"," ");
					objform.elements[i].value = url;
					}
		}
	}
}

function readUrl(param){
	var theurl=window.location.toString()+"&";
	var posparam=theurl.indexOf(param+"=");
	if(posparam==-1)return"";
	var sottostringa=theurl.substring(posparam);
	var start=sottostringa.indexOf("=");
	var end=sottostringa.indexOf("&");
	var val=sottostringa.substring(start+1,end);
	return val;

}




function checkKeywordES() {
 	var theObj = document.ricerca_mediaset.q;
	if (tokES(theObj)) document.ricerca_mediaset.submit(); 	
 }
 
 function tokES(theObj){
 	var ALPHANUMERICS = "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890אטילעש";
 	var text=theObj.value+" ";
 	var pos,pos1=0;
 	var finale,word,ch=" ";
 	var find=true;
 	var fword=false;
 	for(var i=0;i<text.length;i++){
 		ch=text.charAt(i);
 		if(ch==" "){
 			if(find!=true){
 				find=true;
 				pos1=i;
 				word=text.substring(pos,pos1);
 				if(word.substring(0,1)==" ")word=word.substring(1,word.length);
 				var wU=word.toUpperCase();
 				if(wU=="AND"||wU=="OR"||wU=="NOT"){
 						alert("La parola ' "+wU+" ' non ט ammessa");
 					theObj.focus();
 					return false;
 				}
 				pos=pos1;
 				if(fword==false){
 					finale=word;
 					fword=true;
 				}else
 					finale=finale+" "+word;
 			}else
 				pos=i+1;
 			}else{
 				if(ALPHANUMERICS.indexOf(ch)==-1){
 					alert("Il carattere ' "+ch+" ' non ט ammesso");
 				theObj.focus();
 				return false;
 			}
 			find=false;
 			}//end if
 	}//end for
 	if(fword==false){ 	
 		alert("Inserisci la/e parola/e che vuoi ricercare!");
 		theObj.value="";
 		theObj.focus();
 		return false;
 	}
 	theObj.value=finale;
 	return true;
 }


function change(el, cl)
{
	var cn = document.getElementById(el);
	cn.className = cl; 
}


function showDiv(id){
		div = getElement(id);
		
		
		var cb = document.getElementsByName('pkgcheckbox');
		
		if(div.style.display=="block"){
			for(var i=2;i<8;i++){
				cb[i].checked=false;
			}
			div.style.display = "none";
		}else if(div.style.display=="none"){
			div.style.display = "block";
		}else{
			div.style.display="block";
		}
		
		if(cb[1].checked)
			 cb[1].checked=false;
		//else
			 //cb[1].checked=true;
		checkBOX(cb, 'pkgclass_', 'MP_pkg');							    
		visualizzaOfferta(cb);

}

function getElement(id){
		return document.getElementById(id);
	}

	
function changeLanciTab(idTab){		
	if (idTab) {	  			
		for (var i = 1; i < 5; i++){			
			try{				
				document.getElementById("tab_" + i).style.display = 'none';		
				document.getElementById("labelTab_" + i).style.zIndex = '';	
				if(document.getElementById("list_Tabs_Style") != null){				
					document.getElementById("labelTab_" + i).style.width = '168px';					
				}				
				removeClass(document.getElementById("labelTab_" + i),"li_Selected");
			} catch(exc){}			
		}
		document.getElementById("tab_" + idTab).style.display = 'block';
		document.getElementById("labelTab_" + idTab).style.zIndex = '999999';
		if(document.getElementById("list_Tabs_Style") != null){
			document.getElementById("labelTab_" + idTab).style.width = '184px';	
		}
		addClass(document.getElementById("labelTab_" + idTab), "li_Selected");
	}
}

/*function changeLanciHeaderTab(event,idTab){		
	if (idTab) {	  			
		for (var i = 1; i < 5; i++){			
			try{	
				if (i != idTab) 
				{
					document.getElementById("lanciheader_boxupperleft_" + i ).style.display = 'none';	
					document.getElementById("lanciheader_imgpanoramica_" + i ).style.display = 'none';
					if(tabCount > 3){
						document.getElementById("lanciheader_li_" + i).style.display = 'block';
					} else {
						removeClass(document.getElementById("lanciheader_li_" + i), "li_Selected");
					}						
				} 
			} catch(exc){}			
		}
		document.getElementById("lanciheader_boxupperleft_"  + idTab ).style.display = 'block';
		document.getElementById("lanciheader_imgpanoramica_"  + idTab ).style.display = 'block';
		if(tabCount > 3){
			document.getElementById("lanciheader_li_" + idTab).style.display = 'none';
		} else {
			addClass(document.getElementById("lanciheader_li_" + idTab), "li_Selected");
		}
	}
	if (event!=undefined)
		cancelEvent(event);
	return true;
}*/



function changeLanciHeaderTab(event,idTab,isVideo,urlVideo){		
	//alert(event+' '+idTab+' '+isVideo+' '+urlVideo);
	if (idTab && tabCount>1) {	
		$(".box_Featured .box_Main").css('display','block');  			
		for (var i = 1; i < 5; i++){			
			try{	
				//salvataggio degli html interni per gestire caricamento flash (fix per forzare il restart su IE)
				if($("#lanciheader_imgpanoramica_1") != null && panoramico1 ==  '')
					panoramico1 = $("#lanciheader_imgpanoramica_1").html();
				if($("#lanciheader_imgpanoramica_2") != null  && panoramico2 ==  '')
					panoramico2 = $("#lanciheader_imgpanoramica_2").html();
				if($("#lanciheader_imgpanoramica_3") != null  && panoramico3 ==  '')
					panoramico3 = $("#lanciheader_imgpanoramica_3").html();
				
				if (i != idTab) 
				{
					$("#lanciheader_boxupperleft_" + i ).css('display','none');
					$("#lanciheader_imgpanoramica_" + i ).css('display','none');
					$("#alphacont_" + i ).css('display','none');
					if(tabCount > 3){
						$("#lanciheader_li_" + i ).css('display','block');
					} else {
						$("#lanciheader_li_" + i ).removeClass("li_Selected");
					}
				}					
			} catch(exc){}			
		}
		$("#lanciheader_boxupperleft_" + idTab ).css('display','block');
		$("#lanciheader_imgpanoramica_" + idTab ).css('display','block');
		$("#alphacont_" + idTab ).css('display','block');

		if(tabCount > 3){
				$("#lanciheader_li_" + idTab ).css('display','none')
		} else {
			$("#lanciheader_li_" + idTab ).addClass("li_Selected");
		}
		if(idTab==1||idTab==2||(idTab==3 && tabCount>2)){
			//alert(idTab);
			if(isVideo==true){
				stopAutoSwitch();
				openVideoPlayerPan(urlVideo,event);
			}
			else{
				$("lanciheader_imgpanoramica_" + idTab).html(eval('panoramico'+idTab));
			}
		}
	}
	else if (isVideo==true) {
		stopAutoSwitch();
		openVideoPlayerPan(urlVideo,event);
	}
	if (isVideo==true) {
		if (event!=undefined){
		cancelEvent(event);
		}
		stopAutoSwitch();
		
	}	
	else if (event!=undefined) {
		cancelEvent(event);
		stopAutoSwitch();
		startAutoSwitch();	
	}
	
/*	if (event!=undefined) {
		cancelEvent(event);
		stopAutoSwitch();
		if(isVideo!=true){
			startAutoSwitch();	
		}
	}	*/
	return true;
}
/*
function changeLanciHeaderTab(event,idTab){		
	if (idTab && tabCount>1) {	  			
		for (var i = 1; i < 5; i++){			
			try{	
				//salvataggio degli html interni per gestire caricamento flash (fix per forzare il restart su IE)
				if(document.getElementById("lanciheader_imgpanoramica_1") != null && panoramico1 ==  '')
					panoramico1 = document.getElementById("lanciheader_imgpanoramica_1").innerHTML;
				if(document.getElementById("lanciheader_imgpanoramica_2") != null  && panoramico2 ==  '')
					panoramico2 = document.getElementById("lanciheader_imgpanoramica_2").innerHTML;
				if(document.getElementById("lanciheader_imgpanoramica_3") != null  && panoramico3 ==  '')
					panoramico3 = document.getElementById("lanciheader_imgpanoramica_3").innerHTML;
				
				if (i != idTab) 
				{
					document.getElementById("lanciheader_boxupperleft_" + i ).style.display = 'none';	
					document.getElementById("lanciheader_imgpanoramica_" + i ).style.display = 'none';
					document.getElementById("alphacont_" + i ).style.display = 'none';
					if(tabCount > 3){
						document.getElementById("lanciheader_li_" + i).style.display = 'block';
					} else {
						removeClass(document.getElementById("lanciheader_li_" + i), "li_Selected");
					}
				}					
			} catch(exc){}			
		}
		document.getElementById("lanciheader_boxupperleft_"  + idTab ).style.display = 'block';
		document.getElementById("lanciheader_imgpanoramica_"  + idTab ).style.display = 'block';
		document.getElementById("alphacont_" + idTab ).style.display = 'block';
		if(tabCount > 3){
			document.getElementById("lanciheader_li_" + idTab).style.display = 'none';
		} else {
			addClass(document.getElementById("lanciheader_li_" + idTab), "li_Selected");
		}
		if(idTab=1){
			document.getElementById("lanciheader_imgpanoramica_" + idTab).innerHTML = '';
			document.getElementById("lanciheader_imgpanoramica_" + idTab).innerHTML = panoramico1;
		}
		else if(idTab=2){
		document.getElementById("lanciheader_imgpanoramica_" + idTab).innerHTML = '';
			document.getElementById("lanciheader_imgpanoramica_" + idTab).innerHTML = panoramico2;
		}
		else if(idTab=3 && tabCount>2){
			document.getElementById("lanciheader_imgpanoramica_" + idTab).innerHTML = '';
			document.getElementById("lanciheader_imgpanoramica_" + idTab).innerHTML = panoramico3;
		}
	}
	if (event!=undefined) {
		cancelEvent(event);
		stopAutoSwitch();
		startAutoSwitch();		
	}		
		
	return true;
}

*/
//ADD Utility
function cancelEvent(event)
{
    if (document.all)
        event.cancelBubble = true;
    else
		event.stopPropagation();       
}
	
function addClass(element, value) {
	if (element != null && value != null) 
	{
		if(!element.className) {
			element.className = value;
		} else {
			newClassName = element.className;
			newClassName+= " ";
			newClassName+= value;
			element.className = newClassName;
		}
	}
}

function removeClass(element, value) {
	try{
		var v = element.className.replace(value, "");
		element.className = v;	
	}catch(exc){}
}

/*function isUserLogged () {
	var regexp = new RegExp(cookieName + '=([^;]+)');
	var result = regexp.exec(document.cookie);
	if (result == null || result.length < 2) {
		return false;
	}
	userFullname = result[1].replace(/__SEMICOLON__/g,";");
	return true;
}*/

// Verifica se utente loggato
function isUserLogged () {
	var regexp = new RegExp(cookieName + '=([^;]+)');
	var result = regexp.exec(document.cookie);
	if (result == null || result.length < 2) {
		return false;
	}
	var tempName = $.base64Decode(result[1]);
	if (tempName.match(/^[a-zA-Z\d@\. '\u00C0\u00C1\u00C8\u00C9\u00CC\u00CD\u00D2\u00D3\u00D9\u00DA\u00E0\u00E1\u00E8\u00E9\u00EC\u00ED\u00F2\u00F3\u00F9\u00FA]+$/)) {
		userFullname = tempName; 
	}
	return true;
}

function initLoginForm () {
	if (isUserLogged()) {
		document.getElementById("boxsearch").className = "logged";
		document.getElementById("div_not_logged").style.display = 'none';
		document.getElementById("div_logged").style.display = 'block';
		document.getElementById("div_user_name").innerHTML = userFullname;
	} 
	else {
		document.getElementById("boxsearch").className = "";
		document.getElementById("div_not_logged").style.display = 'block';
		document.getElementById("div_logged").style.display = 'none';
	}
}

function logout() {
	document.getElementById("logout_form").submit();
}

function resizeText(multiplier) {	
	if(multiplier != fontDimension){
		resetText();
		if (document.body.style.fontSize == "") {
			document.body.style.fontSize = "1.0em";
		}			
		document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
		fontDimension = multiplier; 
		
		var big = document.getElementById('TextResize_Big');
		var medium = document.getElementById('TextResize_Medium');
		var small = document.getElementById('TextResize_Small');
		switch (multiplier)
		{
			case -1:
				if (small != null) addClass(small, 'li_Selected');
				if (medium != null) removeClass(medium, 'li_Selected');
				if (big != null) removeClass(big, 'li_Selected');
				break;
			case 1:
				if (small != null) removeClass(small, 'li_Selected');
				if (medium != null) removeClass(medium, 'li_Selected');
				if (big != null) addClass(big, 'li_Selected');
				break;
			default:
				if (small != null) removeClass(small, 'li_Selected');
				if (medium != null) addClass(medium, 'li_Selected');
				if (big != null) removeClass(big, 'li_Selected');
				break;
		}
	}	 
}

function resetText() {
  if (document.body.style.fontSize == "") {
    document.body.style.fontSize = "1.0em";
  }
  document.body.style.fontSize = "1.0em";
  fontDimension = 0;
}

function selezioniSelezioni(sel){		
	if(sel != '') {		
		addClass(document.getElementById(sel+"-tab"), 'li_Selected');
	} else {	
		addClass(document.getElementById('offerta-tab'), 'li_Selected');
	}
}
function selezioniSelezioniHeader(sel){		
	if(sel != '' && sel != 'offerta') {		
		addClass(document.getElementById(sel+"-header"), 'selected');
	} else {	
		var offertah = document.getElementById('offerta-header');
		addClass(offertah, 'selected');
		addClass(offertah.parentNode, 'selected');
	}
}

//gestione correlati

var getRelatedVideos_ulRef = "#correlati ul";

function getRelatedVideos_success(data) {
	if (data.errorCode == 0) {
		if (data.relatedGroups != undefined) {
			jQuery(getRelatedVideos_ulRef).html("");
			for (var i = 0; i < data.relatedGroups.length; i++) {
				var relatedGroup = data.relatedGroups[i];
				if (relatedGroup.relatedRecords != undefined) {
					for (var j = 0; j < relatedGroup.relatedRecords.length; j++) {
						var relatedRecord = relatedGroup.relatedRecords[j];
						var title = "";
						var link = "";
						
						for (var k = 0; k < relatedRecord.documentProperties.length; k++) {
							var documentProperty = relatedRecord.documentProperties[k];
							if (documentProperty.name == "TITOLO") {
								title = documentProperty.value;
								title=title.toLowerCase();
								if (title.length > 65) {
									title = title.substring(0, 65) + "...";
								}
							} else if (documentProperty.name == "Document name") {
								link = documentProperty.value;
							}
						}
						
						if (title != "" && link != "") {
							jQuery(getRelatedVideos_ulRef).append("<li><a href=\"" + link + "\">" + title + "</a></li>");
						}
					}
				}
			}
		} else {
			jQuery(getRelatedVideos_ulRef).html("<li>Nessun correlato.</li>");
		}
	} else {
		jQuery(getRelatedVideos_ulRef).html("<li>Errore nel caricamento dei correlati.</li>");
	}
}

function getRelatedVideos_error(xhr) {
	jQuery(getRelatedVideos_ulRef).html("<li>Errore nel caricamento dei correlati.</li>");
}

function getRelatedVideos(id) {
	var idPadded = "" + id;
	while (idPadded.length < 12) {
		idPadded = "0" + idPadded;
	}
	
	var urlCorrelati = "http://91.211.156.138/Mediaset/related?guid=00000000030005400002" + idPadded + "&order=iev&maxitems=i:7;e:0;v:0&callback=?";
	
	jQuery.ajax({
		url: urlCorrelati,
		dataType: "json",
		scriptCharset: "iso-8859-1",
		success: getRelatedVideos_success,
		error: getRelatedVideos_error
	});
}



	function overlayPromoOff(){
		$("#overlayAutopromo").hide();
		if(startAutoSwitchFlag == true){
			
			
			if(urlVideoPanFirst!=''){
			 changeLanciHeaderTab(undefined,currenttab,true,urlVideoPanFirst);
			}
			else{
				startAutoSwitch();
				$(".box_Featured .box_Main").css('display','block');
			}
	
			//alert('startAutoSwitch');
		}
		if(checkStartVideoFlag == true){
			checkStartVideo();
			//alert('checkStartVideo');
		}
	}
	
	function restartAutoswitch(){
		autoSwitchHeader();
	}
	
	
	
	
	
	
	
	
	
	
	
	



