function emailValidation(frm){
	var esito = true;
	var Lang = frm.ver.value;

	with (frm.txtMail){

		if (value.length > 0){
			apos=value.indexOf("@"); 
			dotpos=value.lastIndexOf(".");
			lastpos=value.length-1;
			spacepos=value.indexOf(" ");
			if (apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2 || spacepos>-1) {		
				esito = false;
			}
		}
	}

	if (esito==false)
	{
		if (Lang=="it") alert("Indirizzo e-mail non valido");
		if (Lang=="en") alert("E-mail address not valid");			
		if (Lang=="fr") alert("Adresse email pas valide");
		if (Lang=="de") alert("E-mail unzulässig");
		if (Lang=="es") alert("Correo e-mail inválido");					
	}

	return esito
}


function LoginValidation(frm){
var errori=false;

	with (frm){
		if (txtMail.value == "" || txtPassword.value == "") {
		errori=true;
		}
	}
return (! errori);
}


function PreloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=PreloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function NewWindow(oggetto,w,h,scroll){
	var win2 = window.open(oggetto,"NewWindow","toolbar=no,directories=no,menubar=0,scrollbars="+scroll+",width="+w+",height="+h+",top=50,left=50")
}

function DateValidation(frm){
var esito=true;
var Lang = frm.ver.value;

with (frm){
	//se non inserisco alcuna data il form viene validato comunque
	if (selGG.value == "none" && selMM.value == "none" && selAA.value == "none" ) {
		esito=true;
	}
	else {
		esito = true;
		// se inserisco una data in cui mancano il giorno o il mese o l'anno il form non viene validato
		if (selGG.value == "none" || selMM.value == "none" || selAA.value == "none" ) {
			esito = false;
		}
		//se ho inserito tutti i valori della data, verifico che questa esistita
		else {
			var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);    
			g=eval(selGG.value);
			m=eval(selMM.value);
			y=eval(selAA.value);
			
			if (g > monthDays[m-1]) {
				esito=false
			}
			if(m == 2) {
			  esito = true;
			  var resto = (y-(400*(parseInt(y/400))));
			  var resto1 = (y-(100*(parseInt(y/100))));
			  var resto2 = (y-(4*(parseInt(y/4))));

			  /* verifico che l'anno sia bisestile */
			  if (((resto2 == 0) && (resto1 != 0)) || (resto == 0)) {
					if (g <= 29) esito = true;
			  } else if (g > 28) esito = false;

			}		
		}
		if (esito==false)
		{
			if (Lang=="it") {alert("Data non valida");}
			if (Lang=="en") {alert("Date not valid");}
			if (Lang=="fr") {alert("Date pas valide");}
			if (Lang=="de") {alert("Datum unzulässig");}
			if (Lang=="es") {alert("Fecha no válida");}
		}
	}
}
return esito;
}

function DateValidation2(gg,mm,aa,Lang){
var esito=true;
	
	//se non inserisco alcun valore la data viene validata comunque
	if (gg == "none" && mm == "none" && aa == "none" ) {
		esito=true;
	}
	else {
		esito = true;
		// se inserisco una data in cui mancano il giorno o il mese o l'anno il form non viene validato
		if (gg == "none" || mm == "none" || aa == "none" ) {
			esito = false;
		}
		//se ho inserito tutti i valori della data, verifico che questa esistita
		else {
			var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);    
			g=eval(gg);
			m=eval(mm);
			y=eval(aa);
			
			if (g > monthDays[m-1]) {
				esito=false
			}
			if(m == 2) {
			  esito = true;
			  var resto = (y-(400*(parseInt(y/400))));
			  var resto1 = (y-(100*(parseInt(y/100))));
			  var resto2 = (y-(4*(parseInt(y/4))));

			  if ( resto==0 || (resto1!=0 && resto2==0)) {
				if (!(g <= 29)) esito = false;
			  } else if (!(g <= 28)) esito = false;
			}		
		}
	}

	if (esito==false) {
		if (Lang=="it")	alert("Data non valida");
		if (Lang=="en")	alert("Date not valid");
		if (Lang=="fr")	alert("Date pas valide");
		if (Lang=="de")	alert("Datum unzulässig");
		if (Lang=="es")	alert("Fecha no válida");
	}

return esito;
}


function PopUpPhoto(nome_file,didascalia,w,h){  
	var wh = w; 
	var hh = h+25;
	var s1 = "<html>"
	var s2 = "<head>"
	var s3 = "<TITLE>" + didascalia + "</TITLE>"
	var s4 = "<link rel='STYLESHEET' TYPE='text/css' HREF='magiedisardegna.css'>"
	var s5 = "</head>"
	var s6 = "<BODY STYLE='background:#000000'>"
	var s7 = "<div id='popup'><img src='pictures/" + nome_file + "' hspace=0></div><div id='popup'>" + didascalia + "</div>"
	var s8 = "</BODY>"   
	var s9 = "</html>"
	popup = window.open("","PopUpPhoto","toolbar=no,directories=no,menubar=0,scrollbars=0,width=" + wh + ",height=" + hh + ",top=50,left=50")  
	popup.document.write(s1+s2+s3+s4+s5+s6+s7+s8+s9)  
	popup.document.close()
}
