function NullVal() {
	document.getElementById('cognome').value='';
	document.getElementById('nome').value='';
	document.getElementById('sesso_id').selectedIndex=00;
	document.getElementById('datanascita_gg').selectedIndex=00;
	document.getElementById('datanascita_mm').selectedIndex=00;
	document.getElementById('datanascita_aaaa').selectedIndex=00;
	document.getElementById('cittanascita').value='';
	document.getElementById('email').value='';
	document.getElementById('telefono').value='';
	document.getElementById('provincia').value='';
	document.getElementById('citta').value='';
	document.getElementById('indirizzo').value='';
	document.getElementById('caplavoro').value='';
	document.getElementById('provincialavoro').value='';
	document.getElementById('professione_id').selectedIndex=00;
	document.getElementById('importorichiesto').value='';
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
		return 1;
	else
		return 0;
}

function checkEmail(){
	if (isEmail(document.getElementById('email').value)==0) {
		alert("Indirizzo e-mail non valido")
		//document.getElementById('email').focus();
		return false;
	}
}

function checkData(strValue) {
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	if(!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	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}
		var intDay = parseInt(arrayDate[1],10); 
		if(arrayLookup[arrayDate[0]] != null) {
			if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
				return true; //found in lookup table, good date
		}
		var intMonth = parseInt(arrayDate[0],10);
		if (intMonth == 2) { 
			var intYear = parseInt(arrayDate[2]);
			if (intDay > 0 && intDay < 29) {
				return true;
			}
			else if (intDay == 29) {
				if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
					(intYear % 400 == 0)) {
					// year div by 4 and ((not div by 100) or div by 400) ->ok
					return true;
				}   
			}
		}
	}  
	return false; //any other values, bad date
}

function onlyNumbers(myfield, e, dec) {
	var key;
	var keychar;

	if (window.event)
	 key = window.event.keyCode;
	else if (e)
	 key = e.which;
	else
	 return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
	 return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	 return true;

	// decimal point jump
	else if (dec && (keychar == ".")) {
	 myfield.form.elements[dec].focus();
	 return false;
	} else
	 return false;
}

function chkForm() {
	var bOk=false;
	var result='I seguenti campi sono obbligatori:\n';
	if (document.getElementById('cognome').value=='') {
		result=result + '- Cognome\n';
		bOk=true;
	}
	if (document.getElementById('nome').value=='') {
		result=result + '- Nome\n';
		bOk=true;
	}
	if (document.getElementById('datanascita_gg').selectedIndex==00 ||
		document.getElementById('datanascita_mm').selectedIndex==00  ||
		document.getElementById('datanascita_aaaa').selectedIndex==00 ) {
		result=result + '- Data di nascita\n';
		bOk=true;
	}
	if (document.getElementById('sesso_id').selectedIndex==00) {
		result=result + '- Sesso\n';
		bOk=true;
	}
	if (document.getElementById('cittanascita').value=='') {
		result=result + '- Cittą di nascita\n';
		bOk=true;
	}
	if (document.getElementById('telefono').value=='') {
		result=result + '- Numero telefonico\n';
		bOk=true;
	}
	if (document.getElementById('professione_id').selectedIndex==00) {
		result=result + '- Professione\n';
		bOk=true;
	}
	if (document.getElementById('importorichiesto').value=='') {
		result=result + '- Importo richiesto\n';
		bOk=true;
	}
	if(document.getElementById('email').value!='' && isEmail(document.getElementById('email').value)==0) {
		resultEmail='Attenzione\nIndirizzo e-mail non valido\n\n';
		if (bOk==true) {
			result=resultEmail+result;
		} else {
			result=resultEmail;
		}
		bOk=true;
	}
	if (bOk==false) {
		document.sendWG.submit();
	} else {
		alert(result);
	}
}