/* Copyright by Pineapple - www.pineapple.it */

//GLOBAL
function act(imgName)
{
	if (document.images){ document[imgName].src = eval("j_s_" + imgName + ".src"); }
}

function inact(imgName)
{
	if (document.images) { document[imgName].src = eval("j_m_" + imgName + ".src"); }
}

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 la Tempa di Riato di registrare e mantenere i dati provenienti dal presente modulo elettronico.'); mForm.messaggio.focus(); return; }
	
	mForm.submit();

}

function modForm(mForm)
{
	mForm.action = "/contatti.asp";
	mForm.submit();
}

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"; 			
	}	
	document.fotop.src = '/img/caricamento.gif';
	hideMask();
}

function showMask() {
	var myWidth = 0, myHeight = 0, myScroll = 0, scrollTop = 0, obj;
	  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;	    	    
	  }
	  
	obj = document.getElementById("mask");
	obj.style.width=myWidth.toString() + 'px'; 
	if (myScroll > myHeight)
		obj.style.height=myScroll.toString() + 'px';	
	else
		obj.style.height=myHeight.toString() + '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"; 							
	}
	
	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"; 	
}

function showMail(n)
{
	if (n==0) location.href='mailto:info@tempariato.it';
}

function flashX(num) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,22,0" id="head" width="900" height="199">' +
		        '<param name="movie" value="/flash/anim_'+num+'.swf">' +
		        '<param name="bgcolor" value="#FFFFFF">' +
		        '<param name="quality" value="high">' +
		        '<param name="wmode" value="transparent">' +
		        '<param name="allowscriptaccess" value="samedomain">' +
		        '<embed' +
		         ' type="application\/x-shockwave-flash"' +
		         ' pluginspage="http:\/\/www.macromedia.com\/go\/getflashplayer"' +
		         ' name="pine_home_movie"' +
		         ' width="900" height="199"' +
		         ' src="/flash/anim_'+num+'.swf"' +
		         ' bgcolor="#FFFFFF"' +
		         ' quality="high"' +
		         ' wmode="transparent"' +
		         ' swliveconnect="true"' +
		         ' allowscriptaccess="samedomain">' +
		         '<noembed>' +
		         '<\/noembed>' +
		        '<\/embed>' +
		      '<\/object>');
}