/* Copyright by Pineapple - www.pineapple.it */
/* Diritti riservati. Vietata la copia. 	 */

//GLOBAL
var mytimeout;
var subMenu = 3;
var openedMenu = 0;
var page = 0;
var langsite = "it";

function validateMail(oggetto) {
        var s = oggetto.value;
        s = s.replace(/^\s*|\s*$/, "");
        if (s == "undefined" || s.length < 8) {
             alert("La lunghezza dell\'indirizzo EMAIL deve essere di almeno 8 caratteri");
             oggetto.focus();
             return false;
            }
        re = /\s+/
        if (re.test(s)) {
             alert("Gli spazi non sono ammessi all'interno dell\'indirizzo email.");
             oggetto.focus();
             return false;
            }
        re = /^[\w-][\w-]*((\.[\w-]+)+)*@([\w-]+\.)*([\w-]{2,}\.)+([a-zA-Z]{2,4})$/
        if (!re.test(s)) {
             alert("Indirizzo EMAIL non corretto.");
             oggetto.focus();
             return false;
            }
        re = /\.(a[c-gil-oq-uwz]|b[a-bd-jm-or-tvwyz]|c[acdf-ik-orsuvx-z]|d[ejkmoz]|e[ceghr-u]|f[i-kmorx]|g[abd-ilmnp-uwy]|h[kmnrtu]|i[delm-oq-t]|j[emop]|k[eg-imnprwyz]|l[a-cikr-vy]|m[acdghk-z]|n[ace-giloprtuz]|om|p[ae-hk-nrtwy]|qa|r[eouw]|s[a-eg-ort-vyz]|t[cdf-hjkm-prtvwz]|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[admrw]|com|edu|net|org|mil|gov|biz|pro|aero|coop|info|name|museum|int)$/i
        if (!re.test(s)) {
             alert("Suffisso di dominio inesistente per l'email indicata.");
             oggetto.focus();
             return false;
            }
  return (true);
}

function checkForm(mForm)
{
	if (mForm.nome.value == '') { alert('Il campo nome e\' vuoto.'); mForm.nome.focus(); return; }
	if (mForm.nome.value != '' && mForm.nome.value.length < 2) { alert('Il nome indicato non e\' valido.\nLunghezza minima: 2 caratteri'); mForm.nome.focus(); return; }

	if (mForm.cognome.value == '') { alert('Il campo cognome e\' vuoto.'); mForm.cognome.focus(); return; }
	if (mForm.cognome.value != '' && mForm.cognome.value.length < 3) { alert('Il cognome indicato non e\' valido.\nLunghezza minima: 2 caratteri'); mForm.cognome.focus(); return; }
	
	if (!validateMail(mForm.email)) { return; }

	if (mForm.messaggio.value == '') { alert('Il campo messaggio e\' vuoto.'); mForm.messaggio.focus(); return; }
	if (mForm.messaggio.value != '' && mForm.messaggio.value.length < 10) { alert('Il testo del messaggio non e\' valido.\nLunghezza minima: 10 caratteri'); mForm.messaggio.focus(); return; }
	if (mForm.messaggio.value != '' && mForm.messaggio.value.length > 3000) { alert('Il testo del messaggio non e\' valido.\nLunghezza massima: 3000 caratteri'); mForm.messaggio.focus(); return; }
	
	if (!mForm.liberatoria.checked) { alert('Attenzione\nLa mancata accettazione della liberatoria per il trattamento dei dati in rispetto della n.196\\2003\ncomporta l\'impossibilita\' per Lara s.r.l. di registrare e mantenere i dati provenienti dal presente modulo elettronico.'); mForm.messaggio.focus(); return; }
	
	mForm.submit();

}

function modForm(mForm)
{
	mForm.action = "/lara_alimentari_contatti.asp";
	mForm.submit();
}

function checkFormEN(mForm)
{
	if (mForm.nome.value == '') { alert('NAME field is empty'); mForm.nome.focus(); return; }
	if (mForm.nome.value != '' && mForm.nome.value.length < 2) { alert('The name is incorrect'); mForm.nome.focus(); return; }

	if (mForm.cognome.value == '') { alert('SURNAME field is empty'); mForm.cognome.focus(); return; }
	if (mForm.cognome.value != '' && mForm.cognome.value.length < 3) { alert('The surname is incorrect'); mForm.cognome.focus(); return; }
	
	if (!validateMail(mForm.email)) { return; }

	if (mForm.messaggio.value == '') { alert('TEXT field is empty'); mForm.messaggio.focus(); return; }
	if (mForm.messaggio.value != '' && mForm.messaggio.value.length < 10) { alert('The message in too short'); mForm.messaggio.focus(); return; }
	if (mForm.messaggio.value != '' && mForm.messaggio.value.length > 3000) { alert('The message is too long'); mForm.messaggio.focus(); return; }
	
	if (!mForm.liberatoria.checked) { alert('Attention. The non-acceptance of the disclaimer for the processing of data in accordance of the Italian Law No. 196\/2003 will make it impossible for Lara s.r.l. record and maintain data from this form electronically.'); mForm.messaggio.focus(); return; }

	
	mForm.submit();

}

function modFormEN(mForm)
{
	mForm.action = "/en/contact_lara_rome.asp";
	mForm.submit();
}

function evaluatePosition(leftPos)
{
	if (document.body.clientWidth > 1000) {
		var calibra = parseInt((document.body.clientWidth - 1000) / 2);
		var posizione = leftPos + calibra;
		return posizione;
	}
	else
	{
		return leftPos;
	}
}

function setPositionMarker()
{
	if (langsite=='it') { var newPos = evaluatePosition(437); }
	if (langsite=='en') { var newPos = evaluatePosition(459); }
	var obj=document.getElementById('tendina_ext');
	if (obj) obj.style.left = newPos+'px';
	
	newPos = evaluatePosition(51); //+ 130 a natale!! (originale = 51)
	obj=document.getElementById('lang-selector');
	if (obj) {
	obj.style.left = newPos+'px';
	obj.style.visibility = 'visible';
	obj.style.display = "block";
	}	
	
}

function chiudiFoto()
{
	var obj=document.getElementById('foto_preview');
	obj.style.visibility='hidden';
	obj.style.display="none"; 		
	if (document.contactForm) {
		var fldP = document.getElementById('provincia');
		fldP.style.visibility="visible"; 
		fldP = document.getElementById('prodotto');
		fldP.style.visibility="visible"; 		
		fldP = document.getElementById('feedback');
		fldP.style.visibility="visible"; 			
	}	
	if (document.fotop) {
		document.fotop.src = '/img/caricamento.gif';
	} else	{
		obj = document.getElementById('int_foto');
		if (obj) obj.innerHTML = '<img name="fotop" src="\/img/caricamento.gif" alt="Caricamento foto" width="600" height="378">';
			
		obj = document.getElementById('foto_toolbar');
		if (obj) obj.style.display="block";		
	}
	
	hideMask();
}

function showMask() {

	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    //xScroll = document.documentElement.scrollWidth;
		    yScroll = document.documentElement.scrollHeight;				
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		
		obj = document.getElementById("mask");
		obj.style.width=pageWidth + 'px'; 
		obj.style.height=pageHeight + 'px'; 				
		obj.style.visibility="visible"; 
		obj.style.display="block"; 		
}

function hideMask() {
	var obj;
	obj = document.getElementById("mask");
	obj.style.visibility="hidden"; 
	obj.style.display="none"; 		
}

function mostraFoto(num)
{
	if (document.contactForm) {
		var fldP = document.getElementById('provincia');
		fldP.style.visibility="hidden"; 
		fldP = document.getElementById('prodotto');
		fldP.style.visibility="hidden";
		fldP = document.getElementById('feedback');
		fldP.style.visibility="hidden"; 							
	}
	
	showMask();
	
	document.fotop.src = '/img/foto_g_'+num+'.jpg';
	
	var myWidth = 0, myHeight = 0, myScroll = 0, scrollTop = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	    myScroll = document.body.offsetHeight;
	    scrollTop = document.body.scrollTop;	  
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	    myScroll = document.documentElement.scrollHeight;	
	    scrollTop = document.documentElement.scrollTop;	    	        
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	    myScroll = document.body.scrollHeight;	
	    scrollTop = document.body.scrollTop;	    	    
	  }
	

	var obj = document.getElementById('foto_preview');
	obj.style.left = ((myWidth - 630) / 2).toString() + 'px'; 
	obj.style.top = (scrollTop + 100).toString() + 'px';
	obj.style.visibility="visible"; 
	obj.style.display="block"; 	
	
	for (var i=1; i<51;i++) {
		obj = document.getElementById('ft' + i.toString());
		if (obj) obj.style.backgroundColor = "";
	}
	
	obj = document.getElementById('ft' + parseFloat(num));
	if (obj) obj.style.backgroundColor = "#dabd7c";	
}

function mostraVideo(num)
{
	if (document.contactForm) {
		var fldP = document.getElementById('provincia');
		fldP.style.visibility="hidden"; 
		fldP = document.getElementById('prodotto');
		fldP.style.visibility="hidden";
		fldP = document.getElementById('feedback');
		fldP.style.visibility="hidden"; 							
	}
	
	showMask();
		
	var myWidth = 0, myHeight = 0, myScroll = 0, scrollTop = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	    myScroll = document.body.offsetHeight;
	    scrollTop = document.body.scrollTop;	  
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	    myScroll = document.documentElement.scrollHeight;	
	    scrollTop = document.documentElement.scrollTop;	    	        
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	    myScroll = document.body.scrollHeight;	
	    scrollTop = document.body.scrollTop;	    	    
	  }
	

	var obj = document.getElementById('foto_preview');
	obj.style.left = ((myWidth - 630) / 2).toString() + 'px'; 
	obj.style.top = (scrollTop + 100).toString() + 'px';
	obj.style.visibility="visible"; 
	obj.style.display="block"; 	
	
	obj = document.getElementById('foto_toolbar');
	if (obj) obj.style.display="none";
	
	obj = document.getElementById('int_foto');
	
	if (obj && num == '1') obj.innerHTML = '<object id="player1" type="application\/x-shockwave-flash" data="\/video\/player_flv_maxi.swf" width="490" height="370">' +
							'<noscript><\/noscript>' +
							'<param name="movie" value="\/video\/player_flv_maxi.swf" />' +
							'<param name="allowFullScreen" value="true" \/>' +
							'<param name="FlashVars" value="configxml=\/video\/video_storia_fin.xml" \/>' +
						'<\/object>';
						
	if (obj && num == '2') obj.innerHTML = '<object id="player2" type="application\/x-shockwave-flash" data="\/video\/player_flv_maxi.swf" width="490" height="370">' +
							'<noscript><\/noscript>' +
							'<param name="movie" value="\/video\/player_flv_maxi.swf" />' +
							'<param name="allowFullScreen" value="true" \/>' +
							'<param name="FlashVars" value="configxml=\/video\/video_pasta_fin.xml" \/>' +
						'<\/object>';	
						
	if (obj && num == '3') obj.innerHTML = '<object id="player3" type="application\/x-shockwave-flash" data="\/video\/player_flv_maxi.swf" width="490" height="370">' +
							'<noscript><\/noscript>' +
							'<param name="movie" value="\/video\/player_flv_maxi.swf" />' +
							'<param name="allowFullScreen" value="true" \/>' +
							'<param name="FlashVars" value="configxml=\/video\/video_tutto_fin.xml" \/>' +
						'<\/object>';		
						
	if (obj && num == '4') obj.innerHTML = '<object id="player4" type="application\/x-shockwave-flash" data="..\/video\/player_flv_maxi.swf" width="490" height="370">' +
							'<noscript><\/noscript>' +
							'<param name="movie" value="\/video\/player_flv_maxi.swf" />' +
							'<param name="allowFullScreen" value="true" \/>' +
							'<param name="FlashVars" value="configxml=..\/video\/video_carni_fin.xml" \/>' +
						'<\/object>';					
}


function showMenu() {
	clearTimeout(mytimeout)
	setPositionMarker();
			
	var obj=document.getElementById('tendina_ext');
	if (obj) obj.style.visibility = 'visible';	

	mytimeout = setTimeout(hideMenu, 1500);
}

function hideMenu() {
	
	var obj=document.getElementById('tendina_ext');
	if (obj) obj.style.visibility = 'hidden';	

	if (openedMenu > 0) {
		showMenu(openedMenu);
		clearTimeout(mytimeout);
	}	
}

function ShowHide(handler) {
	var obj;

	for (var i = 0; i < 2; i++) {
		obj = document.getElementById('citbox'+i);
	
		if (i == handler)
		{
			if (obj.style.display == "none")
			{
				obj.style.display = 'block';
				document['cbox'+i].src = '/img/frex_up.gif';	
			}
			else
			{
				obj.style.display = 'none';
				document['cbox'+i].src = '/img/frex_down.gif';	
			}
			
		}
		else
		{
			obj.style.display = 'none';
			document['cbox'+i].src = '/img/frex_down.gif';	
		}
		
	}
	return;
}

function showMail(n)
{
	if (n==0) location.href='mailto:info@gastronomialara.it';
}

window.onresize = setPositionMarker;
window.onload = setPositionMarker;
