var VW = null; 
var iTck = 0;
var iFade = 0;

function InitializePage() {
	InitializeSound();
}

function InitializeSound() {
	var s=sm_CookieRead("vcbSound");
	if (s=="off") {
		document.all.suono1.volume=-10000;
		document.speaker1.src="images/sound_off.gif";
		sm_CookieWrite("vcbSound","off",1);
		document.all.suono1.src="gulls.mp3";
	}
	else {
	    document.all.suono1.volume=-10000;
		document.speaker1.src="images/sound_on.gif";
		sm_CookieWrite("vcbSound","on",1);
		document.all.suono1.src="gulls.mp3";
		document.all.suono1.volume=0;
	}
}

function ChangeSound() {
	if (sm_Right(document.speaker1.src,7)=="_on.gif") {
		document.all.suono1.volume=-10000;
		document.speaker1.src="images/sound_off.gif";
		sm_CookieWrite("vcbSound","off",1);
	}
	else {
		document.all.suono1.volume=0;
		document.speaker1.src="images/sound_on.gif";
		sm_CookieWrite("vcbSound","on",1);
		document.location=document.location;
	}
}

function PageLng() {
	var L=sm_StrBtw(sm_LowerCase(sm_Trim(sm_PageName())),'_','.php');
	if ((L=='en')||(L=='de')||(L=='nl')||(L=='fr')) { L='_'+L; } else { L=''; }
	return L;
}

function LayerLogo() {
	document.write('<div id="LayerLogo"><a href="http://www.villaggiocampingblu.com/home'+PageLng()+'.php"><img src="images/dummy.gif" alt="www.villaggiocampingblu.com" width="180" height="180" border="0" /></a></div>');
}

function InviaMessaggio() {
	var lang=PageLng();
	if (sm_InputEmpty(document.MODULO.pNome)) 
	{
		if (lang=="_en") { alert("Manca il nome."); }
		else if (lang=="_de") { alert("Manca il nome."); }
		else if (lang=="_nl") { alert("Manca il nome."); }
		else if (lang=="_fr") { alert("Manca il nome."); }
		else { alert("Manca il nome."); }
	}
	else if (sm_InputEmpty(document.MODULO.pCognome)) 
	{
		if (lang=="_en") { alert("Manca il cognome."); }
		else if (lang=="_de") { alert("Manca il cognome."); }
		else if (lang=="_nl") { alert("Manca il cognome."); }
		else if (lang=="_fr") { alert("Manca il cognome."); }
		else { alert("Manca il cognome."); }
	}
	else if (!sm_CheckEmailAddress(sm_InputValue(document.MODULO.pEmail)))
	{
		if (lang=="_en") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else if (lang=="_de") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else if (lang=="_nl") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else if (lang=="_fr") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else { alert("L'indirizzo e-mail è mancante o non corretto."); }
	}
	else if (!document.MODULO.pAccettazionePrivacy.checked)
	{
		if (lang=="_en") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else if (lang=="_de") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else if (lang=="_nl") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else if (lang=="_fr") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
	}
	else
	{
		document.MODULO.action="inviamessaggio"+lang+".php?pRnd=x"+sm_CronoID();
		document.MODULO.submit();
	}
}

function InviaIscrizione() {
	var lang=PageLng();
	if (sm_InputEmpty(document.MODULO.pNome)) 
	{
		if (lang=="_en") { alert("Manca il nome."); }
		else if (lang=="_de") { alert("Manca il nome."); }
		else if (lang=="_nl") { alert("Manca il nome."); }
		else if (lang=="_fr") { alert("Manca il nome."); }
		else { alert("Manca il nome."); }
	}
	else if (sm_InputEmpty(document.MODULO.pCognome)) 
	{
		if (lang=="_en") { alert("Manca il cognome."); }
		else if (lang=="_de") { alert("Manca il cognome."); }
		else if (lang=="_nl") { alert("Manca il cognome."); }
		else if (lang=="_fr") { alert("Manca il cognome."); }
		else { alert("Manca il cognome."); }
	}
	else if (!sm_CheckEmailAddress(sm_InputValue(document.MODULO.pEmail)))
	{
		if (lang=="_en") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else if (lang=="_de") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else if (lang=="_nl") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else if (lang=="_fr") { alert("L'indirizzo e-mail è mancante o non corretto."); }
		else { alert("L'indirizzo e-mail è mancante o non corretto."); }
	}
	else if (!document.MODULO.pAccettazionePrivacy.checked)
	{
		if (lang=="_en") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else if (lang=="_de") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else if (lang=="_nl") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else if (lang=="_fr") { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
		else { alert("Per inviare il messaggio occorre accettare i termini sulla tutela dei dati personali."); }
	}
	else
	{
		document.MODULO.action="iscrizione"+lang+".php?pRnd=x"+sm_CronoID();
		document.MODULO.submit();
	}
}

function InviaPreventivo()
{
	var L=PageLng();
    document.MODULO.action="scrivici"+L+".php?pRnd=x"+sm_CronoID();
	document.MODULO.submit();
}

function VaiPag(P)
{
	if (P=="BACK")
	{
		history.back();
	}
	else
	{
		var L=PageLng();
		document.location=P+L+".php";
	}
}

function Preventivo(sez)
{
	var L=PageLng();
	document.MODULO.action="preventivo"+L+".php?pCalc="+sez+"&pRnd=x"+sm_CronoID();
	document.MODULO.submit();
}

function SchedaMappa(n)
{
	var L=PageLng() , U="";
	if (L.substring(0,1)=="_") { L=L.substring(1); } else { L="it"; }
	U="schedamappa.php?lng="+PageLng()+"&nsc="+n+"&rnd=x"+sm_CronoID();
	sm_AjaxGetURL(U,"SchedaMappa");
}

function MostraVideo()
{
    var w=window.open("video.htm","_VIDEOVCB","resizable=0,scrollbars=0,toolbar=0,menubar=0,status=0,height=380,width=486,location=0");
    w.focus();
}

function VisualizzaFoto(n)
{
    var w=window.open("foto.php?q="+n+"&t="+sm_CronoID(),"_FOTOVCB","resizable=0,scrollbars=0,toolbar=0,menubar=0,status=0,height=432,width=646,location=0");
    w.focus();
}

function VisualizzaFotoP(n)
{
    var w=window.open("foto.php?q="+n+"&t="+sm_CronoID(),"_FOTOVCB","resizable=0,scrollbars=0,toolbar=0,menubar=0,status=0,height=646,width=432,location=0");
    w.focus();
}

function VideoHiRes() {
	PopupVideo("videohires.htm");
	return void(0); 
}

function VideoLowRes() {
	PopupVideo("videolowres.htm"); 
	return void(0); 
}

function PopupVideo(VF) {
	var D=new Date(); 
	var W=318; 
	var H=312; 
	var L=(screen.width)?(screen.width-W)/2:0; 
	var T=(screen.height)?(screen.height-H)/2:0;
	S='height='+H+',width='+W+',top='+T+',left='+L+',scrollbars=no'; VW = window.open(VF,'film'+D.getSeconds()+D.getMilliseconds(),S)
	return void(0)
}

function InitPage() {
	ChangeBackground();
	ChangeTicker();
}

function ChangeTicker() {
	if (iTck<1) {
		try { 
		    var s = sm_Trim(sm_CookieRead("vcbTicker"));
			if (s=="") iTck=0; else iTck = parseInt(s); 
		} catch(e) { iTck=0; }
	}
	iTck++; if (iTck>nTck) iTck=1;
	sm_CookieWrite("vcbTicker",""+iTck,30);
	iFade=0;
	FadeOut();
}

function FadeIn() {
	iFade--;
	if (iFade>=0) 
	{
		SetOpacity (document.getElementById("textTicker"),iFade); 
		setTimeout("FadeIn()",100);
	}
	else setTimeout("ChangeTicker()",sTck*1000);
}

function FadeOut() {
	iFade++;
	if (iFade<11) 
	{
		SetOpacity (document.getElementById("textTicker"),iFade); 
		setTimeout("FadeOut()",100);
	}
	else {
		document.getElementById("textTicker").innerHTML = aTck[iTck];
		iFade=10;
		FadeIn();
	}
}

function SetOpacity(obj,opa) { 
    var r = 0, g = 111, b = 180;
	r = r + 25*opa;
	g = g + 14*opa;
	b = b + 17*opa;
    obj.style.color="rgb("+r+","+g+","+b+")";
} 

function ChangeBackground() {
    var i = sm_Trim(sm_CookieRead("vcbHeroes"));
	if (i == "") 
	{
	    var D = new Date();
		i = D.getSeconds() % 4;
	}
	else 
	{
		i = parseInt(i) + 1;
		if (i > 3) i = 0;
	}
	if (i==1) ChangeBackgroundStyle("images/pageback_1.jpg");
	else if (i==2) ChangeBackgroundStyle("images/pageback_2.jpg");
	else if (i==3) ChangeBackgroundStyle("images/pageback_3.jpg");
	else ChangeBackgroundStyle("images/pageback_0.jpg");
	sm_CookieWrite("vcbHeroes",""+i,30);
	setTimeout("ChangeBackground()",3600000);
}

function ChangeBackgroundStyle(img) {
	document.body.style.background = 'url("'+img+'") no-repeat scroll top center';
}


