var timeout=0;
var areaSito="";

function ie6custom(){
	if(isIE() && $.browser.version<=6){

	}
}

function fixPng(){
	if(isIE()){
		// alert("1");
		$("img").ifixpng();
		// alert("2");
		// $("#popNews").ifixpng();
		// $("#popStore").ifixpng();

	}
}

function attivaCufon(idElemento, callback){
	idElemento=(typeof(idElemento)=="undefined")?"":(idElemento+" ");
	idElemento=(typeof(idElemento)=="undefined")?"":(idElemento+" ");
	Cufon.replace(idElemento+'.interstateLComp, '+idElemento+' .interstateLComp', { fontFamily: 'interstateLComp', hover:'true' });
	Cufon.CSS.ready(function(){
		if(!(typeof(callback)=="undefined")){
			callback();
		}
	});
}

function actBottCheckbox(jqObjBott,jqObjInput){
	var valAtt=jqObjInput.val();
	valAtt=(valAtt==0)?1:0;
	jqObjInput.attr("value",valAtt);
	if(valAtt==0){ jqObjBott.removeClass("selected"); } else { jqObjBott.addClass("selected"); }
}

function objVis(obj, act){
	if(act==1){ $(obj).fadeIn(500); } else { $(obj).fadeOut(500); }
}

function objVisSwap(obj, tempo){
	if(typeof(tempo)=="undefined"){ tempo=100; }
	$(obj).slideToggle(tempo, function(){ /* nulla */ });
}

function txtCampiSwap(objContainer, obj){
	var campi=$(objContainer);
	$.each(campi, function(key, value){
		if($(value).attr("value")==$(value).attr("title") && $(obj).attr("value")==$(value).attr("value")){
			$(value).attr("value","");
		} else {
			if($(value).val()==""){
				$(value).attr("value",$(value).attr("title"));
			}
		}
	});
}

function resizeFooter(){

}

/* ------------------- FUNZIONI PER I FORM ----------------------------------- */

function getGifText(idText){
	img="img/"+idText+".gif";
	txt=arrJsTexts[idText];
	htmlRis='';
	htmlRis+='<img';
	htmlRis+=' src="'+img+'"';
	htmlRis+=' alt="'+txt+'"';
	htmlRis+=' title="'+txt+'"';
	htmlRis+=' />';
	return(htmlRis);
}

var scrolling=null;
function doJsScroll(container,px,time){
	scrolling = setInterval (function(){ $(container)[0].scrollBy(px); }, time );
}

function stopJsScroll(){
	clearInterval(scrolling);
}

function doAzione(action){

}

var timeFade=(isIE())?0:0;

function attivaRollOvers(){
	$(".rollover").bind("mouseover",function(){ $(this).attr('src',$(this).attr('imgOn')); });	
	$(".rollover").bind("mouseout",function(){ $(this).attr('src',$(this).attr('imgOff')); });	
}

function attivaBotts(area){
	attivaRollOvers();
}

/* --------------------------- SFONDO PROIETTORE ---------------------------------- */

function resetWH100(val_selector){
	$(val_selector).css("width","100%"); $(val_selector).width("100%");
	$(val_selector).css("height","100%"); $(val_selector).height("100%");
}

function resetW100Hauto(val_selector){
	$(val_selector).css("width","100%");  $(val_selector).width("100%");
	$(val_selector).css("height","auto"); $(val_selector).height("auto");
}

function resizeBackground(){
	var diffW_IE=0;
	var diffH_IE=0;
	if(isIE()){
		switch(true){
			case($.browser.version>7):
				diffW_IE=0;
				diffH_IE=0;
			break;
		}
	}
	resetWH100("#background");
	resetW100Hauto(".imgBgHome");
	var totalWidth=Math.max($(window).width(),$(document).width());
	totalWidth=totalWidth-diffW_IE;
	var totalHeight=Math.max($(window).height(),$(document).height());
	totalHeight=Math.max(totalHeight,$("#contImgBgHome").height());
	totalHeight=totalHeight-diffH_IE;
	$("#background").width(totalWidth);
	$("#background").height(totalHeight);

	$("#imgBackgroundHomeF, #imgBackgroundHomeFN").height(totalHeight);
	$("#imgBackgroundHomeF, #imgBackgroundHomeFN").width(totalWidth);

	var imgW=parseInt($("#imgBackgroundHome").width());
	var imgH=parseInt($("#imgBackgroundHome").height());
	
	if(false){}
	else if(imgH<totalHeight){ // resta bianco sotto? (es. landscape)
		$(".imgBgHome").css("width","auto"); $(".imgBgHome").width("auto");
		$(".imgBgHome").css("height",totalHeight+"px"); $(".imgBgHome").height(totalHeight);
	} else if(imgW<totalWidth){ // resta bianco destra? (es. portrait)
		$(".imgBgHome").css("height","auto"); $(".imgBgHome").height("auto");
		$(".imgBgHome").css("width",totalWidth+"px"); $(".imgBgHome").width(totalWidth);
	}
	// centra orizzontalmente
	$("#imgBackgroundHome, .imgBgHome").css("left",parseInt((($("#background").width()-$("#imgBackgroundHome").width())/2))+"px");
	// centra verticalmente
	areaToScroll=parseInt((totalHeight-imgH)/2);
	// alert($('#imgBackgroundHome').attr("src")+" - "+areaToScroll);
	if(areaToScroll<0){
		$('#imgBackgroundHome').animate({
			top: areaToScroll
		}, 0);
	} else {
		$('#imgBackgroundHome, .imgBgHome').css("top","0px");
	}
}

function changeBgImg(arrBgImgs, idAtt, newSrc, bianco, val_auto){
	attivaPulse(".close", 0);
	var imgNew=$('<img />');
	imgNew.animate({ opacity: 0.00 }, 0);
	loading(1);
	imgNew.bind("load",function(){
		loading(0);
		$("#tmcLogo img").attr("src",((parseInt(bianco,10)==1)?$("#tmcLogo img").attr("bianco"):$("#tmcLogo img").attr("nero")));
		// la inserisce trasparente, ne calcola posizione, poi la sposta insieme all'esistente, poi elimina la vecchia, poi da l'id alla nuova
		imgNew.attr("class","imgBgHome");
		imgNew.css("z-index","10");
		imgNew.attr("width","auto");
		imgNew.attr("height","auto");
		$("#contImgBgHome").append(imgNew);
		$('#imgBackgroundHome').attr("id","oldBg");
		imgNew.attr("id","imgBackgroundHome");
		resizeBackground();
		imgNew.animate({ opacity: 1.00 }, 0);
		offsetImg=imgNew.offset();
		vOffset=offsetImg.top;
		oOffset=offsetImg.left;

		var tipoGhigliottina=rand(1, 4);
		// tipoGhigliottina=2; // sovrascrive
		if(tipoGhigliottina==1){ // ghigliottina dall'alto al basso
			imgNew.animate({
				top: -(imgNew.height()-vOffset)
			}, 0);
			
			imgNew.animate({
				top: vOffset
			}, 1000);
			$("#oldBg").animate({
				top: (imgNew.height()+(4*vOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}
		if(tipoGhigliottina==2){ // ghigliottina dal basso all'alto
			var totalHeight=Math.max($(window).height(),$(document).height());
			totalHeight=Math.max(totalHeight,$("#contImgBgHome").height());

			imgNew.animate({
				top: totalHeight+vOffset
			}, 0);
			
			imgNew.animate({
				top: vOffset
			}, 1000);
			$("#oldBg").animate({
				top: (-totalHeight+(vOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}
		if(tipoGhigliottina==3){ // ghigliottina da sx a dx
			imgNew.animate({
				left: -(imgNew.width()-oOffset)
			}, 0);
			
			imgNew.animate({
				left: oOffset
			}, 1000);
			$("#oldBg").animate({
				left: (imgNew.width()+(4*oOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}
		if(tipoGhigliottina==4){ // ghigliottina da dx a sx
			imgNew.animate({
				left: (imgNew.width()-oOffset)
			}, 0);
			
			imgNew.animate({
				left: oOffset
			}, 1000);
			$("#oldBg").animate({
				left: -(imgNew.width()+(4*oOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}

	});
	imgNew.attr('src', newSrc);
}

function swapGllHome(arrBgImgs, idAtt){
	var totImgs=arrBgImgs.length;
	idAtt=idAtt+1;
	var newSrc=arrBgImgs[idAtt][0];
	if(typeof(newSrc)=="undefined"){ idAtt=1; newSrc=arrBgImgs[idAtt][0]; }
	do{
		idAtt=rand(1,(arrBgImgs.length)-1);
		newSrc=arrBgImgs[idAtt][0];
	}while(newSrc==$('#imgBackgroundHome').attr("src") || typeof(newSrc)=="undefined" || newSrc=="");
	// alert(newSrc);
	changeBgImg(arrBgImgs, idAtt, newSrc, arrBgImgs[idAtt][1], false);
}

function backgroundImg(){
	arrBgImgs.sort(randOrd);
	if($("#imgBackgroundHome").length<=0){ // appende immagine cha cambia
		var newSrc="img/0.gif";
		newImg=null;
		newImg=$("<img>");
		$(newImg).attr("id","imgBackgroundHome");
		$(newImg).attr("class","imgBgHome");
		$(newImg).attr("src",newSrc);
		$(newImg).css("z-index","10");
		$(newImg).attr("width","auto");
		$(newImg).attr("height","auto");
		$("#contImgBgHome").append(newImg);
	}
	swapGllHome(arrBgImgs, 1);
	return(false);
}

/* -------------------------- VIDEO -------------------------------- */

function playMovie(idVideo,idFlash){
	try{
		var movie = document.getElementById(idVideo);
		movie.play();	
	} catch(err){ }
	try{
		var flashObj = document.getElementById(idFlash);
		flashObj.playVideo();
	} catch(err){ }
	return(false);

}

function stopMovie(){
	try{
		var movie = document.getElementById(idVideo);
		movie.pause();	
	} catch(err){ }	
	try{
		var flashObj = document.getElementById(idFlash);
		flashObj.pauseVideo();
	} catch(err){ }

}

/* -------------------------------------------- */

function attivaLogo(){
	$("#tmcLogo").unbind("click");
	$("#tmcLogo").bind("click", function(){
		if($(".boxCenter").height()>0){
			$(".boxCenter").animate({
					height: '0'
				}, 0);
			setTimeout(function(){ $("#contSite").html(""); },500);
		}
		return(false);
	});
}

function attivaScrollBars(){
	$(".boxTxtScroll").jScrollPane({showArrows:false, verticalDragMinHeight:13, verticalDragMaxHeight:13, scrollbarWidth:13, hideFocus:true });
	// $('.jScrollPaneContainer').bind("click", function(e){ $('.jScrollPaneContainer').blur(); });
}

var pulseTimeout=new Array();
function attivaPulse(selector, act){
	$(selector).unbind("click");
	$(selector).bind("click", function(){
		if($(".boxCenter").height()>0){
			$(".boxCenter").animate({ height: '0' }, 0);
			$(".slideWhiteBg, .slideBlackBg, #sxSlideDn, #dxSlideDn").hide(0);
		} else {
			$(".boxCenter").animate({ height: '390' }, 0);
			$(".slideWhiteBg, .slideBlackBg, #sxSlideDn, #dxSlideDn").show(0);
		}
		// setTimeout(function(){ $("#contSite").html(""); },500);
		/* return(false); */
	});
	// return(false);
	if(act==1){
		pulseTimeout[selector]=setInterval(function(){
				$(selector+" img").fadeToggle(1000);
			},
			1000);
	} else {
		clearTimeout(pulseTimeout[selector]);
		$(selector+" img").animate({
			opacity: 1.00
		}, 0).show(0);
	}
}

function setEndMenu1Width(){
	var endWidth=527;
	var links=$(".dxCenter .menuUp a:visible");
	if(links.length>0){
		$.each(links, function(key, value){
			endWidth-=parseInt($(value).width(),10);
		});
	}
	$("#endMenu1").width(endWidth);
	$("#endMenu1").css("float","right");
}

function loadAnchorPage(url){
	if(strpos(url, "#")>0){
		url = url.split("#");
		if(url[1]!=""){
			newBott=$("<a>");
			$(newBott).attr("href",url[1]+".php");
			cliccaMenuPrincipale(newBott);
		}
	}
}

function cliccaMenuPrincipale(obj){
	$(".bottClose").hide(0);
	// loading(1);
	urlLoad=$(obj).attr("href");
	if($(obj).attr("target")=="_blank"){
		return(true);
	}
	if(strpos(urlLoad, ".")>0){
		urlAnchor=urlLoad.substring(0, strrpos(urlLoad, "."));
		location.href="#"+urlAnchor;
	} else {
		return(false);
	}
	$.post(urlLoad,{
		inc: 1,
		time: unixTime()
	}, function(data){
		// loading(0);
		$(".boxCenter").animate({
			height: '0'
		}, 0);
		setTimeout(function(){
				backgroundImg();	
		},1000);
		setTimeout(function(){
			$("#contSite").html(data);
			$(".contTxtScroll").animate({ left:'+600' }, 0);
			$("#slideScroll").animate({ left:('+'+Math.max($(window).width(),$(document).width())) }, 0);
			funzioniOnLoadGen(); // x lingua
			funzioniOnLoad(); // generali
			$(".boxCenter").height(0);
			$(".boxCenter").animate({
					height: '390'
				}, 0, function(){
					// nulla
			});
			setTimeout(function(){
				$(".contTxtScroll").animate({ left:'0' }, 300, function(){ attivaScrollBars(); });
				$("#slideScroll").animate({ left:'0' }, 300);
			},500);
			contrLoadVideo();
			var area=$(".boxCenter").attr("area");
			$("#menuItems a img").animate({ opacity: 1.00 }, 0);
			$("#m_"+area+" img").animate({ opacity: 0.50 }, 2000);
		},0);
	});
}

function attivaMenuPrincipale(){
	$("#menuItems a, .linkIntS").unbind("click");
	$("#menuItems a, .linkIntS").bind("click",function(){
		cliccaMenuPrincipale(this);
		return(false);	
	})	
}

function cliccaMenuUp(obj){
	// loading(1);
	urlLoad=$(obj).attr("href");
	if($(obj).attr("target")=="_blank"){
		// loading(0);
		return(true);
	}
	if(strpos(urlLoad, ".")>0){
		urlAnchor=urlLoad.substring(0, strrpos(urlLoad, "."));
		location.href="#"+urlAnchor;
	} else {
		// loading(0);
		return(false);
	}
	$.post(urlLoad,{
		inc: 1,
		time: unixTime()
	}, function(data){
		// loading(0);
		$("#contSite").html(data);
		$(".contTxtScroll").animate({ left:'+600' }, 0);
		$("#slideScroll").animate({ left:('+'+Math.max($(window).width(),$(document).width())) }, 0);
		funzioniOnLoadGen(); // x lingua
		funzioniOnLoad(); // generali
		setTimeout(function(){
			$(".contTxtScroll").animate({ left:'0' }, 300, function(){ attivaScrollBars(); });
			$("#slideScroll").animate({ left:'0' }, 300);
		},500);
		attivaPulse(".close", 1);
		contrLoadVideo();
		var area=$(".boxCenter").attr("area");
		$("#menuItems a img").animate({ opacity: 1.00 }, 0);
		$("#m_"+area+" img").animate({ opacity: 0.50 }, 0);
	});
	return(false);
}

function attivaMenuUp(){ // menu di categoria (2° livello)
	$(".menuUp a, .menuUp1 a, .linkInt").unbind("click");
	$(".menuUp a, .menuUp1 a, .linkInt").bind("click",function(){
		return(cliccaMenuUp(this));
	});

	$("#menuMap a").unbind("click");
	$("#menuMap a").bind("click",function(){
		closeMap();
		return(cliccaMenuUp(this));
	});
	
	
}

function attivaMenuUp1(){ // menu di sotto categoria (3° livello)
	attivaMenuUp();
}


function scrollSxSlide(){
	attivaPulse(".close", 0);
	attivaIntervalIE(0);
	timeoutScroll=setTimeout(function(){
		$("#slideScroll").animate({
				scrollLeft: "-=795"
			},{duration:1000, queue:true});
	},100);
	setTimeout(function(){
		attivaPulse(".close", 1);
		attivaIntervalIE(1);	
	},1100);
}

function scrollDxSlide(){
	attivaPulse(".close", 0);
	attivaIntervalIE(0);
	timeoutScroll=setTimeout(function(){
		$("#slideScroll").animate({
				scrollLeft: "+=795"
			},{duration:1000, queue:true});
	},100);
	setTimeout(function(){
		attivaPulse(".close", 1);
		attivaIntervalIE(1);	
	},1100);
}

function attivaScroll(){
	$("#sxSlideDn, #sxSlideDnB").bind("click",function(){
		scrollSxSlide();
	});
	$("#dxSlideDn, #dxSlideDnB").bind("click",function(){
		scrollDxSlide();
	});
}

function requestTicket(val_id){
	$(".popServizi").html("");
	var urlLoad="request_ticket.php";
	$.post(urlLoad,{
		id: val_id,
		time: unixTime()
	}, function(data){
		$(".popServizi").html(data);
		attivaCufon(".popServizi");
		popServices(1);
	});
	return(false);
}

function popServices(stato){
	if(stato==1){
		$('.popServizi').show(0);
	} else {
		$('.popServizi').hide(0);
		$(".popServizi").html("");
	}
	return(false);
}

function contrRequestTicket(){
	$(".alertForm1").html("&nbsp;");
	var langReg=$("#lang").val();
	$.post("background.php",{
			act: "requestTicket",
			idDoc: parseInt($("#idDoc").val(),10),
			lang: langReg,
			cognome: $("#cognome").val(),
			nome: $("#nome").val(),
			company: $("#company").val(),
			country: $("#country").val(),
			email: $("#email").val(),
			privacy: $("#privacy:checked").val(),
			authtmc: $("#authtmc:checked").val(),
			time: unixTime()
		}, function(data){
			if(data=="ok"){
				var urlLoad="request_ticket.php";
				$.post(urlLoad,{
					id: parseInt($("#idDoc").val(),10),
					act: "ok",
					time: unixTime()
				}, function(data){
					$(".popServizi").html(data);
					attivaCufon(".popServizi");
					popServices(1);
				});
			} else {
				if(langReg=="it"){
					if(data=="doc_missing"){ $(".alertForm1").html("Richiesta documento non valida document request"); return(false); }
					if(data=="cognome_missing"){ $("#cognome").focus(); $(".alertForm1").html("Inserire il cognome"); return(false); }
					if(data=="nome_missing"){ $("#nome").focus(); $(".alertForm1").html("Inserire il nome"); return(false); }
					if(data=="company_missing"){ $("#company").focus(); $(".alertForm1").html("Inserire l'azienda"); return(false); }
					if(data=="country_missing"){ $("#country").focus(); $(".alertForm1").html("Inserire la nazione"); return(false); }
					if(data=="email_missing"){ $("#email").focus(); $(".alertForm1").html("Inserire l'email"); return(false); }
					if(data=="email_wrong"){ $("#email").focus(); $(".alertForm1").html("Email errata"); return(false); }
					if(data=="privacy"){ $("#privacy").focus(); $(".alertForm1").html("Accettare la privacy policy"); return(false); }
				} else {
					if(data=="doc_missing"){ $(".alertForm1").html("Invalid document request"); return(false); }
					if(data=="cognome_missing"){ $("#cognome").focus(); $(".alertForm1").html("Insert surname"); return(false); }
					if(data=="nome_missing"){ $("#nome").focus(); $(".alertForm1").html("Insert first name"); return(false); }
					if(data=="company_missing"){ $("#company").focus(); $(".alertForm1").html("Insert company"); return(false); }
					if(data=="country_missing"){ $("#country").focus(); $(".alertForm1").html("Insert country"); return(false); }
					if(data=="email_missing"){ $("#email").focus(); $(".alertForm1").html("Insert email"); return(false); }
					if(data=="email_wrong"){ $("#email").focus(); $(".alertForm1").html("Wrong email"); return(false); }
					if(data=="privacy"){ $("#privacy").focus(); $(".alertForm1").html("Authorize privacy policy"); return(false); }
				}
				$(".alertForm1").html("Error: "+data); return(false);
			}
		});
	return(false);
}

function contrRegister(){
	$(".alertForm1").html("&nbsp;");
	var preSelC="#formRegister ";
	var langReg=$(preSelC+"#lang").val();
	$.post("background.php",{
			act: "register",
			lang: langReg,
			nome: $(preSelC+"#nome").val(),
			cognome: $(preSelC+"#cognome").val(),
			email: $(preSelC+"#email").val(),
			citta: $(preSelC+"#citta").val(),
			country: $(preSelC+"#country").val(),
			privacy: $(preSelC+"#privacy:checked").val(),
			time: unixTime()
		}, function(data){
			if(data=="ok" || data=="Captcha non valido"){
				$(".alertForm1").html("ok...");
				if(langReg=="it"){
					$("#formRegisterInt").html("<br /><br />Registrazione completata.<br />Riceverai un'email con i dati di accesso");
				} else {
					$("#formRegisterInt").html("<br /><br />Registration completed.<br />You will receive an email with your login information");
				}
				// loadAnchorPage("press_room.php#press_room");
				return(false);
			} else {
				if(langReg=="it"){
					if(data=="nome_missing"){ $(preSelC+"#nome").focus(); $(".alertForm1").html("Inserire il nome"); return(false); }
					if(data=="cognome_missing"){ $(preSelC+"#cognome").focus(); $(".alertForm1").html("Inserire il cognome"); return(false); }
					if(data=="email_missing"){ $(preSelC+"#email").focus(); $(".alertForm1").html("Inserire l'email"); return(false); }
					if(data=="email_wrong"){ $(preSelC+"#email").focus(); $(".alertForm1").html("Email errata"); return(false); }
					if(data=="email_used"){ $(preSelC+"#email").focus(); $(".alertForm1").html("Email in uso"); return(false); }
					if(data=="citta_missing"){ $(preSelC+"#citta").focus(); $(".alertForm1").html("Inserire l'azienda"); return(false); }
					if(data=="country_missing"){ $(preSelC+"#country").focus(); $(".alertForm1").html("Inserire la nazione"); return(false); }
					if(data=="privacy"){ $(preSelC+"#privacy").focus(); $(".alertForm1").html("Accettare la privacy policy"); return(false); }
				} else {
					if(data=="nome_missing"){ $(preSelC+"#nome").focus(); $(".alertForm1").html("Insert first name"); return(false); }
					if(data=="cognome_missing"){ $(preSelC+"#cognome").focus(); $(".alertForm1").html("Insert surname"); return(false); }
					if(data=="email_missing"){ $(preSelC+"#email").focus(); $(".alertForm1").html("Insert email"); return(false); }
					if(data=="email_wrong"){ $(preSelC+"#email").focus(); $(".alertForm1").html("Wrong email"); return(false); }
					if(data=="email_used"){ $(preSelC+"#email").focus(); $(".alertForm1").html("Email used"); return(false); }
					if(data=="citta_missing"){ $(preSelC+"#citta").focus(); $(".alertForm1").html("Insert company"); return(false); }
					if(data=="country_missing"){ $(preSelC+"#country").focus(); $(".alertForm1").html("Insert country"); return(false); }
					if(data=="privacy"){ $(preSelC+"#privacy").focus(); $(".alertForm1").html("Authorize privacy policy"); return(false); }
				}
				$(".alertForm1").html("Error: "+data); return(false);
			}
		});
	return(false);
}

function contrLogin(){
	$(".alertForm1").html("&nbsp;");
	var preSelC="#formLogin ";
	var langReg=$(preSelC+"#lang").val();
	$.post("background.php",{
			act: "login",
			lang: langReg,
			email: $(preSelC+"#email").val(),
			password: $(preSelC+"#password").val(),
			time: unixTime()
		}, function(data){
			if(data=="ok"){
				$(".alertForm2").html("ok...");
				loadAnchorPage("press_room.php#press_room");
				return(false);
			} else {
				if(langReg=="it"){
					if(data=="email_missing"){ $(preSelC+"#email").focus(); $(".alertForm2").html("Inserire l'email"); return(false); }
					if(data=="email_wrong"){ $(preSelC+"#email").focus(); $(".alertForm2").html("Email errata"); return(false); }
					if(data=="password_missing"){ $(preSelC+"#password").focus(); $(".alertForm2").html("Inserire la password"); return(false); }
					if(data=="err_auth"){ $(preSelC+"#password").focus(); $(".alertForm2").html("Email o password errati"); return(false); }
				} else {
					if(data=="email_missing"){ $(preSelC+"#email").focus(); $(".alertForm2").html("Insert email"); return(false); }
					if(data=="email_wrong"){ $(preSelC+"#email").focus(); $(".alertForm2").html("Wrong email"); return(false); }
					if(data=="password_missing"){ $(preSelC+"#password").focus(); $(".alertForm2").html("Insert password"); return(false); }
					if(data=="err_auth"){ $(preSelC+"#password").focus(); $(".alertForm2").html("Wrong Email or password"); return(false); }
				}
				$(".alertForm2").html("Error: "+data); return(false);
			}
		});
	return(false);
}

function logout(){
	$.post("background.php",{
			act: "logout",
			time: unixTime()
		}, function(data){
			location.reload();
		});
	return(false);
}

function contrRecuperaPwd(){
	$(".alertForm3").html("&nbsp;");
	var preSelC="#formRecuperaPwd ";
	var langReg=$(preSelC+"#lang").val();
	$.post("background.php",{
			act: "recuperaPwd",
			lang: langReg,
			email: $(preSelC+"#email").val(),
			time: unixTime()
		}, function(data){
			if(data=="ok"){
				$(".alertForm3").html("ok...");
				if(langReg=="it"){
					$("#formRegisterInt").html("<br /><br />Procedura completata.<br />Riceverai un'email con i dati di accesso");
				} else {
					$("#formRegisterInt").html("<br /><br />Procedure completed. <br />You will receive an email with your login information");
				}
				return(false);
			} else {
				if(langReg=="it"){
					if(data=="email_missing"){ $(preSelC+"#email").focus(); $(".alertForm3").html("Inserire l'email"); return(false); }
					if(data=="email_wrong"){ $(preSelC+"#email").focus(); $(".alertForm3").html("Email errata"); return(false); }
					if(data=="err_user"){ $(preSelC+"#email").focus(); $(".alertForm3").html("Email non in database"); return(false); }
				} else {
					if(data=="email_missing"){ $(preSelC+"#email").focus(); $(".alertForm3").html("Insert email"); return(false); }
					if(data=="email_wrong"){ $(preSelC+"#email").focus(); $(".alertForm3").html("Wrong email"); return(false); }
					if(data=="err_user"){ $(preSelC+"#email").focus(); $(".alertForm3").html("Email not in our database"); return(false); }
				}
				$(".alertForm3").html("Error: "+data); return(false);
			}
		});
	return(false);
}

function openMap(){
	if($(".boxCenter").height()>0){
		$(".boxCenter").animate({
				height: '0'
			}, 0);
	}
	$("#mapLink").attr("mapOpen","1");
	setTimeout(function(){
		$("#contSite").html("");
		$("#menuDnSf").animate({
				height:'258',
				bottom:'0'
			},1000);
		$("#menuWorld, #menuLines, #menuItems").animate({
			bottom: '+=112'
			},1000);
		$("#mapLink, #linksLangs, #pte").fadeOut(500);
		setTimeout(function(){
			$("#menuMap").fadeIn(500);
		},1000);
	},500);
	return(false);
}

function closeMap(){
	$("#mapLink").attr("mapOpen","0");
	$("#menuDnSf").animate({
			height:'116',
			bottom:'30'
		},1000);
	$("#menuWorld, #menuLines, #menuItems").animate({
		bottom: '-=112'
		},1000);
	$("#mapLink, #linksLangs, #pte").fadeIn(500);
	$("#menuMap").fadeOut(500);
}

function loadVideo(urlVideo,idContainer){
	// urlVideo=urlVideo+".mp4";
	// $("#piva").html($("#piva").html()+"loadVideo:"+urlVideo+" to:"+idContainer);
	var swfVersionStr = "9.0.124";
	var xiSwfUrlStr = "";
	var flashvars = {url:urlVideo, usePlayPause: "1", useFit: "1", useLoop: "1", callbackEndVideoOn: "0", usePattern:"0", layerColor:"0x000000", layerAlpha:".5", showControls:"1"};
	var params = {};
	params.quality = "high";
	params.bgcolor = "#000000";
	params.play = "true";
	params.loop = "false";
	params.wmode = "opaque";
	params.scale = "noscale";
	params.menu = "false";
	params.devicefont = "false";
	params.salign = "";
	params.allowscriptaccess = "sameDomain";
	var attributes = {};
	attributes.id = "playervideo";
	attributes.name = "playervideo";
	attributes.align = "middle";
	swfobject.createCSS("html", "height:100%; background-color: #000000;");
	swfobject.createCSS("body", "margin:0; padding:0; overflow:hidden; height:100%;");
	
	swfobject.embedSWF(
		"playervideo.swf", idContainer,
		"100%", "100%",
		swfVersionStr, xiSwfUrlStr,
		flashvars, params, attributes);

	setTimeout(function(){
		attivaPulse(".close", 0);
	},4000);
	
	function onEndVideo(){
		// alert("fine video");
	}
	
}

function contrLoadVideo(){
	if($("#divContVideo").length>0 && $("#divContVideo").attr("urlVideo")!="" && !($("#divContVideo").attr("is_I_Mobile")=="1")){
		loadVideo($("#divContVideo").attr("mp4V"),"divContVideo");
	}
}


