/* Copyright by Pineapple - www.pineapple.it                   */
/* Tutti i diritti riservati - Vietata la riproduzione e l'uso */

//GLOBAL
var mytimeout;

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"); }}

var frex_off = new Image();
frex_off.src = "/img/b_frex_on.gif";
function frexAct(n) {document['frex' + n].src = frex_off.src;}
function frexInact(n) {document['frex' + n].src = "/img/b_frex_off.gif";}

function LTrim(value) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim(value) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim(value) {
	return LTrim(RTrim(value));
}


//HTTPRequest 
var xmlhttp=false;
try
{
 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e) 
{
 try 
 {
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 } 
 catch (E) 
 {
 xmlhttp = false;
 }
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest();
}


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 validateDate(strValue) {
  var objRegExp = /^\d{2}(\-|\/|\.)\d{2}\1\d{4}$/
  var intDay;
  if(!objRegExp.test(strValue))
    return false; 
  else{
    var strSeparator = strValue.substring(2,3)
    var arrayDate = strValue.split(strSeparator);
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
	if (arrayDate[0].substr(0,1)=='0') { intDay = parseInt(arrayDate[0].substr(1,1)) } else { intDay = parseInt(arrayDate[0]); }
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true;
    }
    var intMonth = parseInt(arrayDate[1]);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true;
       }
  }
  return false;
}

function validateCF(sCodicefiscale)
{
	CF = sCodicefiscale.value.toString();
	CF = CF.toUpperCase();

	var valori = new Array("A","0","B","1","C","2","D","3","E","4","F","5","G","6","H","7","I","8","J","9","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	var pari = new Array(0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25);
	var dispari = new Array(1,1,0,0,5,5,7,7,9,9,13,13,15,15,17,17,19,19,21,21,2,4,18,20,11,3,6,8,12,14,16,10,22,25,24,23);
	var resto = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
	var somma = 0;

	for (i=0;i<15;i=i+2) {             
		for (j=0;j<36;j++) {
			if (CF.substr(i,1) == valori[j]) {
				somma = somma + dispari[j];
			}
		}   
	}	

	for (i=1;i<15;i=i+2) {             
		for (j=0;j<36;j++) {
			if (CF.substr(i,1) == valori[j]) {
				somma = somma + pari[j];
			}
		}   
	}	
	
	somma = somma % 26;

	if (CF.substr(15,1) == resto[somma]) {
		return true;
	} else {
		alert('Codice fiscale errato');
		sCodicefiscale.focus();
		return false;
	}
}



function validatePI(piva)
{
    partita_iva=piva.value.toString();
    somma_dispari=0;

    for (I=0;I<=10;I=I+2)
      {            
      somma_dispari = somma_dispari +  parseInt(partita_iva.charAt(I));
      }
    

    somma_pari=0;
    valoreappoggio =0;
    
    for (I=1;I<=9;I=I+2)
      {            
      if ( parseInt(partita_iva.charAt(I))  < 5)
           {
            valoreappoggio =  parseInt(partita_iva.charAt(I)) * 2;
            }
      else 
            {
            valoreappoggio = ( parseInt(partita_iva.charAt(I)) * 2) - 9;
            }
      somma_pari = somma_pari + valoreappoggio;
      }

    sommadeidue = somma_dispari + somma_pari;
    if ((sommadeidue % 10) == 0)
            {

               return true;
            }
    else
            {
            alert('Partita Iva errata.');
               piva.focus();
               return false;
            }
} 

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 chiudiBoxDati()
{
	var obj=document.getElementById('data_preview');
	obj.style.visibility='hidden';
	obj.style.display="none"; 		
	if (document.contactForm) {
		var fldP = document.getElementById('provincia');
		fldP.style.visibility="visible"; 		
	}	
	hideMask();
}

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 viewGallery()
{
	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('photo-container');
	if (obj) {
		obj.style.top = (scrollTop + 50).toString() + 'px';
		obj.style.display="block"; 	
	}
}
function hideGallery()
{
	hideMask();
	var obj = document.getElementById('photo-container');
	if (obj) 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 + 40).toString() + 'px';
	obj.style.visibility="visible"; 
	obj.style.display="block"; 	
}

function mostraFotoCP(num)
{
	showMask();
	document.fotop.src = '/public/pic/big_'+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 + 40).toString() + 'px';
	obj.style.visibility="visible"; 
	obj.style.display="block"; 	
}

function mostraBoxDati()
{
	if (document.contactForm) {
		var fldP = document.getElementById('provincia');
		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('data_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';
}

function evaluatePosition(leftPos)
{
	if (document.body.clientWidth > 900) {
		var calibra = parseInt((document.body.clientWidth - 900) / 2);
		var posizione = leftPos + calibra;
		return posizione;
	}
	else
	{
		return leftPos;
	}
}

function setPositionMarker()
{
	var newPos = evaluatePosition(225);
	var obj=document.getElementById('claim-text');
	if (obj) {
	obj.style.left = newPos+'px';
	obj.style.visibility = 'visible';
	obj.style.display = "block";	
	}
	
	newPos = evaluatePosition(720);
	obj=document.getElementById('lang-selector');
	if (obj) {
	obj.style.left = newPos+'px';
	obj.style.visibility = 'visible';
	obj.style.display = "block";
	}
	
	newPos = evaluatePosition(20);
	obj=document.getElementById('home-link');
	if (obj) {
	obj.style.left = newPos+'px';
	obj.style.visibility = 'visible';
	obj.style.display = "block";	
	}	
}

function showMail(n)
{
	if (n==0) location.href='mailto:info@mp-education.com';
}


function showconf(numtoc)
{
	var a = confirm('E\' certo di voler eliminare il record selezionato?\n\nConferma l\'eliminazione?')
	if (a)
	{
		delForm.id.value=numtoc;
		delForm.submit();
	} else { return; }
}

function showMenu(m) {
	clearTimeout(mytimeout)
	var obj=document.getElementById('tendina_'+m+'_ext');
	if (obj) obj.style.visibility = 'visible';	
	mytimeout = setTimeout(hideMenu, 1500);
}

function hideMenu() {
	var obj=document.getElementById('tendina_0_ext');
	if (obj) obj.style.visibility = 'hidden';	
	obj=document.getElementById('tendina_1_ext');
	if (obj) obj.style.visibility = 'hidden';	
	obj=document.getElementById('tendina_2_ext');
	if (obj) obj.style.visibility = 'hidden';	
}

function putDate(pElem) {
	if (pElem.value!=''){
	var arDat = pElem.value.split('-')
	document.mheForm.gg.value = parseFloat(arDat[0],0).toString();
	document.mheForm.mm.value = parseFloat(arDat[1],0).toString();
	document.mheForm.aa.value = parseFloat(arDat[2],0).toString();
	document.mheForm.action='';
	document.mheForm.submit();
	}
}

function checkMail(tForm) {
	if (!validateMail(tForm.nlmail)) { return; }
	tForm.submit();
}

function checkBookFormPage(nform){
if (nform.f_city.value=='') { alert('Seleziona una destinazione dall\'elenco.'); nform.f_city.focus(); return;}
	nform.submit();
}

window.onresize = setPositionMarker;