/* Copyright by Pineapple - www.pineapple.it                   */
/* Tutti i diritti riservati - Vietata la riproduzione e l'uso */

//GLOBAL

	var j_m_zero = new Image();
	j_m_zero.src = "/img/key_off_000.gif";
	
	var j_s_zero= new Image();
	j_s_zero.src = "/img/key_on_000.gif";
	
	
	var j_m_uno = new Image();
	j_m_uno.src = "/img/key_off_001.gif";
	
	var j_s_uno = new Image();
	j_s_uno.src = "/img/key_on_001.gif";
	
	var j_m_due = new Image();
	j_m_due.src = "/img/key_off_002.gif";
	
	var j_s_due = new Image();
	j_s_due.src = "/img/key_on_002.gif";	
	
	var j_m_tre = new Image();
	j_m_tre.src = "/img/key_off_003.gif";
	
	var j_s_tre = new Image();
	j_s_tre.src = "/img/key_on_003.gif";	
	
	var j_m_quattro = new Image();
	j_m_quattro.src = "/img/key_off_004.gif";
	
	var j_s_quattro = new Image();
	j_s_quattro.src = "/img/key_on_004.gif";	
	
	var j_m_cinque = new Image();
	j_m_cinque.src = "/img/key_off_005.gif";
	
	var j_s_cinque= new Image();
	j_s_cinque.src = "/img/key_on_005.gif";	


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 Ditta Giuseppe Veneri di registrare e mantenere i dati provenienti dal presente modulo elettronico.'); mForm.messaggio.focus(); return; }
	
	mForm.submit();

}

function modForm(mForm)
{
	mForm.action = "/arredo_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;	
	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@arredoveneri.it';
}
