var linguaggioContatti

function ControllaMail(valore){
	regexp=/\w+(\.\w+)*@\w+(\.\w+)*\.(\w\w|org|net|biz|com|info)$/g;
	temp=valore.match(regexp);
	if(temp==valore)
		return true;
	else
		return false;
}

function SendFormContatti()
{
	if(checkform(document.FormContatti))
		document.FormContatti.submit();
}

function checkData(data)
{
	var strData = data	
	var delim1 = strData.indexOf("/")
	var delim2 = strData.lastIndexOf("/")
	if(delim1 != -1 && delim1 == delim2){ // C'è un solo / nella stringa data
		if (linguaggioContatti=="it"){
			alert("La data immessa non è in un formato accettabile.\n Puoi inserire la data nel seguente formato:\n gg/mm/aaaa")
		}else if (linguaggioContatti=="eng"){
			alert("Invalid date format.\n Date must be written in the following format:\n gg/mm/aaaa");
		}else if (linguaggioContatti=="esp"){
		
		}else if (linguaggioContatti=="fr"){
		
		}else if (linguaggioContatti=="usa"){
		
		}
		return false
	}
	
	if(delim1!=-1){ // Sono presenti i / nella stringa data; estraggo i componenti
		var gg = parseInt(strData.substring(0,delim1),10)
		var mm = parseInt(strData.substring(delim1+1,delim2),10)
		var aaaa = parseInt(strData.substring(delim2+1,strData.length),10)
	}else{ // Non sono presenti i / nella stringa data quindi formato non valido
		if (linguaggioContatti=="it"){
			alert("La data immessa non è in un formato accettabile.\n Puoi inserire la data nei seguenti formati:\n gg/mm/aaaa, gg-mm-aaaa")
		}else if (linguaggioContatti=="eng"){
			alert("Invalid date format.\n Date must be written in the following formats:\n gg/mm/aaaa, gg-mm-aaaa");
		}else if (linguaggioContatti=="esp"){
		
		}else if (linguaggioContatti=="fr"){
		
		}else if (linguaggioContatti=="usa"){
		
		}
		return false
	}
	
	if(isNaN(gg) || isNaN(mm) || isNaN(aaaa)){ // Uno dei componenti la data non è in formato numerico
		if (linguaggioContatti=="it"){
			alert("La data immessa non è in un formato accettabile.\n Puoi inserire la data nei seguenti formati:\n gg/mm/aaaa, gg-mm-aaaa")
		}else if (linguaggioContatti=="eng"){
			alert("Invalid date format.\n Date must be written in the following formats:\n gg/mm/aaaa, gg-mm-aaaa");
		}else if (linguaggioContatti=="esp"){
		
		}else if (linguaggioContatti=="fr"){
		
		}else if (linguaggioContatti=="usa"){
		
		}
		return false
	}
	
	if(mm < 1 || mm > 12){ // Il valore del mese non è accettabile
		if (linguaggioContatti=="it"){
			alert("Il mese deve essere compreso tra 01(gennaio) e 12(dicembre)")
		}else if (linguaggioContatti=="eng"){
			alert("Month must be higher than 01(january) and lower than 12(dicember)");
		}else if (linguaggioContatti=="esp"){
		
		}else if (linguaggioContatti=="fr"){
		
		}else if (linguaggioContatti=="usa"){
		
		}
		return false
	}
	
	if(gg < 1 || gg > 31){ // Il valore del giorno non è accettabile
		if (linguaggioContatti=="it"){
			alert("Il giorno deve essere compreso tra 01 e 31")
		}else if (linguaggioContatti=="eng"){
			alert("Day must be higher than 01 and lower than 31");
		}else if (linguaggioContatti=="esp"){
		
		}else if (linguaggioContatti=="fr"){
		
		}else if (linguaggioContatti=="usa"){
		
		}
		return false
	}
	
	var month = new Array()
	
	if (linguaggioContatti=="it"){
		month[0] = "Gennaio"
		month[1] = "Febbraio"
		month[2] = "Marzo"
		month[3] = "Aprile"
		month[4] = "Maggio"
		month[5] = "Giugno"
		month[6] = "Luglio"
		month[7] = "Agosto"
		month[8] = "Settembre"
		month[9] = "Ottobre"
		month[10] = "Novembre"
		month[11] = "Dicembre"
	}else if (linguaggioContatti=="eng"){
		month[0] = "January"
		month[1] = "February"
		month[2] = "March"
		month[3] = "April"
		month[4] = "May"
		month[5] = "June"
		month[6] = "July"
		month[7] = "August"
		month[8] = "September"
		month[9] = "October"
		month[10] = "November"
		month[11] = "Dicember"
	}else if (linguaggioContatti=="esp"){
		month[0] = "Enero"
		month[1] = "Febrero"
		month[2] = "Marzo"
		month[3] = "Abril"
		month[4] = "Mayo"
		month[5] = "Junio"
		month[6] = "Julio"
		month[7] = "Agosto"
		month[8] = "Septiembre"
		month[9] = "Octubre"
		month[10] = "Noviembre"
		month[11] = "Diciembre"
	}else if (linguaggioContatti=="fr"){
		month[0] = "Janvier"
		month[1] = "Février"
		month[2] = "Mars"
		month[3] = "Avril"
		month[4] = "Mai"
		month[5] = "Juin"
		month[6] = "Juillet"
		month[7] = "Août"
		month[8] = "Septembre"
		month[9] = "Octobre"
		month[10] = "Novembre"
		month[11] = "Décembre"
	}else if (linguaggioContatti=="usa"){
		month[0] = "January"
		month[1] = "February"
		month[2] = "March"
		month[3] = "April"
		month[4] = "May"
		month[5] = "June"
		month[6] = "July"
		month[7] = "August"
		month[8] = "September"
		month[9] = "October"
		month[10] = "November"
		month[11] = "Dicember"
	}
	
	if(mm == 4 || mm == 6 || mm == 9 || mm == 11){ // Il mese ha trenta giorni
		if(gg > 30){
			if (linguaggioContatti=="it"){
				alert(month[mm-1] + " ha solo 30 giorni")
			}else if (linguaggioContatti=="eng"){
				alert(month[mm-1] + " has 30 days only")
			}else if (linguaggioContatti=="esp"){
			
			}else if (linguaggioContatti=="fr"){
			
			}else if (linguaggioContatti=="usa"){
			
			}
			return false
		}
	}
	
	if(aaaa%4 > 0 && mm == 2 && gg > 28){ // Anno non bisestile
		if (linguaggioContatti=="it"){
			alert("Febbraio del " + aaaa + " ha solo 28 giorni")
		}else if (linguaggioContatti=="eng"){
			alert("February  in " + aaaa + " has 28 days only")
		}else if (linguaggioContatti=="esp"){
		
		}else if (linguaggioContatti=="fr"){
		
		}else if (linguaggioContatti=="usa"){
		
		}
		return false
	}else if(mm == 2 && gg > 29){ // Troppi giorni in ogni caso
		if (linguaggioContatti=="it"){
			alert("Febbraio non può avere più di 29 giorni")
		}else if (linguaggioContatti=="eng"){
			alert("February can't have much than 29 days")
		}else if (linguaggioContatti=="esp"){
		
		}else if (linguaggioContatti=="fr"){
		
		}else if (linguaggioContatti=="usa"){
		
		}
		return false
	}
	return true
}

var arrRequestedContatti = new Array();
arrRequestedContatti[0] = "nome";
arrRequestedContatti[1] = "mail";
arrRequestedContatti[2] = "testo";

function checkformContatti(form){
	var errore = 0
	var myerr = ""
	var boolReq;
	for(var i=0; i<form.elements.length; i++){
		boolReq = false;
		for(var j = 0; j < arrRequestedContatti.length; j++)
		{
			if(form.elements[i].name == arrRequestedContatti[j])
			boolReq = true;
		}
		
		if((form.elements[i].type!="submit" && form.elements[i].value=="" && boolReq))
		{
			if (linguaggioContatti=="it"){
				alert("Attenzione! Non risulta compilato un campo richiesto");
			}else if (linguaggioContatti=="eng"){
				alert("Caution! A request field is not compiled");
			}else if (linguaggioContatti=="esp"){
			
			}else if (linguaggioContatti=="fr"){
			
			}else if (linguaggioContatti=="usa"){
			
			}
			form.elements[i].focus();
			return false;
		}
		
		if(form.elements[i].type!="submit" && form.elements[i].name=="accetto"&& !form.elements[i].checked)
		{
			if (linguaggioContatti=="it"){
				alert("Non si è data l'autorizzazione al trattamento dei dati personali");
			}else if (linguaggioContatti=="eng"){
				alert("You didn't give personal data treatment authorization");
			}else if (linguaggioContatti=="esp"){
			
			}else if (linguaggioContatti=="fr"){
			
			}else if (linguaggioContatti=="usa"){
			
			}
			return false;
		}
		
		if(String(form.elements[i].name) == "mail" && String(form.elements[i].value).length > 0)
		{
			if(!ControllaMail(String(form.elements[i].value)))
			{
				if (linguaggioContatti=="it"){
					alert("Indirizzo e-mail non valido.");
				}else if (linguaggioContatti=="eng"){
					alert("Invalid email address.");
				}else if (linguaggioContatti=="esp"){
				
				}else if (linguaggioContatti=="fr"){
				
				}else if (linguaggioContatti=="usa"){
				
				}
				return false;
			}
		}
		
		if(form.elements[i].name.indexOf("data") == 0 && String(form.elements[i].value).length > 0)
		{
			if(!checkData(String(form.elements[i].value)))
				return false;
		}
	}
	//return true
	CallSenda(form)
	return false;
}

function CallSenda(form){
	var StringaPost="nome="+escape(form.elements["nome"].value)+
				"&indirizzo="+escape(form.elements["indirizzo"].value)+
				"&nazione="+escape(form.elements["nazione"].value)+
				"&telefono="+escape(form.elements["telefono"].value)+
				"&mail="+escape(form.elements["mail"].value)+
				"&destinatario="+escape(form.elements["destinatario"].value)+
				"&testo="+escape(form.elements["testo"].value)
	
	ajaxPost("../contatti/senda.asp" ,returnSenda, StringaPost);
}

function returnSenda(content){
	if (linguaggioContatti=="it"){
		alert("Messaggio spedito correttamente. La ringraziamo per averci scritto, le nostre redazioni le risponderanno quanto prima")
	}else if (linguaggioContatti=="eng"){
		alert("Message sent successfully. Thank you for your email, our editors will respond you soon")
	}else if (linguaggioContatti=="esp"){
	
	}else if (linguaggioContatti=="fr"){
	
	}else if (linguaggioContatti=="usa"){
	
	}
	open_contatti();
}