function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var avvisoMail=true;

	if (str.indexOf(at)==-1) avvisoMail=false;
	if ((str.indexOf(at)==-1) || (str.indexOf(at)==0) || (str.indexOf(at)==lstr)) avvisoMail=false;
	if ((str.indexOf(dot)==-1) || (str.indexOf(dot)==0) || (str.indexOf(dot)==lstr)) avvisoMail=false;
	if (str.indexOf(at,(lat+1))!=-1) avvisoMail=false;
	if ((str.substring(lat-1,lat)==dot) || (str.substring(lat+1,lat+2)==dot)) avvisoMail=false;
	if (str.indexOf(dot,(lat+2))==-1) avvisoMail=false;
	if (str.indexOf(" ")!=-1) avvisoMail=false;

	return avvisoMail;
}

function validateMail(type){
	var tipo=type; // eng , ita
	var msg='';
	var avviso=true;

	var fn=document.contact_en.FIRST_NAME;
	var sur=document.contact_en.Surname;
	var phone=document.contact_en.Tel;
	var emailID=document.contact_en.mail;
	var messaggio=document.contact_en.Message;

	if ((fn.value==null)||(fn.value=="")){
		if (tipo=='eng') {
			msg+=". Please enter your First Name<br>";
		} else {
			msg+=". Perfavore inserisci il tuo Nome<br>";
		}
		fn.focus();
		avviso=false;
	}

	if ((sur.value==null)||(sur.value=="")){
		if (tipo=='eng') {
			msg+=". Please enter your Surname<br>";
		} else {
			msg+=". Perfavore inserisci il tuo Cognome<br>";
		}
		sur.focus();
		avviso=false;
	}

	if ((phone.value==null)||(phone.value=="")){
		if (tipo=='eng') {
			msg+=". Please enter your Phone Number<br>";
		} else {
			msg+=". Perfavore inserisci il tuo Telefono<br>";
		}
		phone.focus();
		avviso=false;
	}

	if ((emailID.value==null)||(emailID.value=="")){
		if (tipo=='eng') {
			msg+=". Please enter your E-mail<br>";
		} else {
			msg+=". Perfavore inserisci la tua E-mail<br>";
		}
		emailID.focus();
		avviso=false;
	} else if (echeck(emailID.value)==false){
		emailID.value="";
		if (tipo=='eng') {
			msg+=". Please check the given E-mail address<br>";
		} else {
			msg+=". Perfavore controlla l'indirizzo E-mail introdotto<br>";
		}
		emailID.focus();
		avviso = false;
	}

	if ((messaggio.value==null)||(messaggio.value=="")){
		if (tipo=='eng') {
			msg+=". Please enter your Message<br>";
		} else {
			msg+=". Perfavore inserisci il tuo Messaggio<br>";
		}
		messaggio.focus();
		avviso=false;
	}

	if (avviso==false) {
		DisplayAlert('AlertBox',300,200, msg);
	}

	return avviso;
 }

 function DisplayAlert(id,width,height,testo) {

	var ele = document.getElementById(id);
	ele.style.width=		width+'px';
	ele.style.height=		height+'px';
	ele.style.display=	'block';

	var cont = document.getElementById('container');
	//alert( windows.innerHeight+" - " + windows.innerWidth);
	//alert( cont.clientHeight+" - " + cont.clientWidth);
	ele.style.marginTop=		(window.innerHeight-height) /2 +30 + 'px';
	ele.style.marginLeft=	(cont.clientWidth-width) /2 + 'px';

   document.getElementById(id).innerHTML = "<p>"+testo+"</p>"
				+"<div style=\"text-align:right;\"><button type=\"button\" onclick=\"document.getElementById('AlertBox').style.display='none'\" style=\"width: 75px;\">OK</button></div>";
}
