/* Copyright by Pineapple - www.pineapple.it                   */
/* Tutti i diritti riservati - Vietata la riproduzione e l'uso */

//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 Casa San Francesco 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 checkForm_EN(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; }
	
	mForm.submit();

}

function modForm_EN(mForm)
{
	mForm.action = "contacts.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"; 
		fldP = document.getElementById('prodotto');
		fldP.style.visibility="visible"; 		
		fldP = document.getElementById('feedback');
		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"; 
		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"; 	
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{

    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "cursor:pointer;"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML  
    }
    
    return;
}

function showMail(n)
{
	if (n==0) location.href='mailto:info@casasanfrancesco.eu';
}
