function CheckAll()
{
	//check si su tutte le coreg
	//Vistaprint
	//document.regform.partner1[0].checked= true ;
}

function IsDate(txtDate)
{
    try
    {
        if (txtDate.length != 10)
        {
            return null;
        }
        else if
             (
                 isNaN(txtDate.substring(0, 2))       ||
                       txtDate.substring(2, 3) != "-" ||
                 isNaN(txtDate.substring(3, 5))       ||
                       txtDate.substring(5, 6) != "-" ||
                 isNaN(txtDate.substring(6, 15))
             )
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    catch (e)
    {
        return null;
    }
}


function validateFields() {
	var strErrorMsg='';	
	
	var strnome=document.regform.nome.value;
	if ((strnome.length < 3) || (strnome.length > 50))  {
		strErrorMsg+='* Nome \n';
	}
	
	
	var strcognome=document.regform.cognome.value;
	if ((strcognome.length < 3) || (strcognome.length > 50))  {
		strErrorMsg+='* Cognome \n';
	}

	var strcap=document.regform.cap.value;
	if (!verifyCap(strcap)) {
		strErrorMsg+='* CAP\n';
	}
	
	var stremail=document.regform.email.value;
	var stremail2=document.regform.email2.value;
	if (!verifyEmail(stremail) || stremail != stremail2) {
		strErrorMsg+='* E-mail \n';
	}	
  
   if (document.regform.sesso.value == "nd") {
		strErrorMsg+='* Sesso \n';
	}
	
	var data=document.regform.giorno.value +'-'+ document.regform.mese.value +'-'+ document.regform.anno.value;

	if (IsDate(data) == false || IsDate(data) == null)
	{
		strErrorMsg+='* Data di nascita \n';
	}
	else	
	{
		var regex = new RegExp("[/-]");
		var giorno=document.regform.giorno.value;
		var mese=document.regform.mese.value;
		var anno=document.regform.anno.value;
		//var date = input.split(regex);
		var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
		var result = true;

		if ( anno%4 == 0 && anno%100 > 0 || anno%400 == 0 )
		nbJours['2'] = 29;

		if( isNaN(anno) )
		result=false;

		if ( isNaN(mese) || mese > 12 || mese < 1 )
		result=false;

		if ( isNaN(giorno) || giorno > nbJours[Math.round(mese)] || giorno < 1 )
		result=false;

		if(result==false)
		{
			strErrorMsg+='* Data di nascita \n';
		}
	}

  		
		if (document.regform.prov.value == "nd" || document.regform.prov.value == 0) {
		strErrorMsg+='* Provincia \n';
	}
	

	var strtelm=document.regform.telm.value;
	if (((strtelm.length <= 9) || (strtelm.length >= 11)) || !verifyNumeric(strtelm) || document.regform.telm.value ==0)  {
		strErrorMsg+='* Cellulare\n';
	}		
		
radio_button_checker();

function radio_button_checker()
{
  var radio_choice = false;
  var radio_scelta = false;
  
  //vistaprint
  var radio_partner1 = false;

	for (counter = 0; counter < 2; counter++)
	{
		if (document.regform.privacy[counter].checked) radio_choice = true; 
		if (document.regform.terzi[counter].checked) radio_scelta = true; 
		//vistaprint
		//if (document.regform.partner1[counter].checked) radio_partner1 = true;  		
	}

	if (!radio_choice)
	{
		strErrorMsg+='* Devi confermare l\'informativa Privacy ai trattamenti di tipo A!\n'; 
	}
	else
	{
		for (var i=0; i < 2; i++)
		{
			if (document.regform.privacy[i].checked)
			{
				var rad_val = document.regform.privacy[i].value;
				if(rad_val!= 's') 
				{
					strErrorMsg+='* Devi confermare l\'informativa Privacy ai trattamenti di tipo A!\n'; 
				}
			}	
		}
	}

	if (!radio_scelta)
	{
		strErrorMsg+='* Devi specificare se desideri confermare il trattamento per le finalità di tipo B!\n'; 
	}
	
	//Vistaprint
	/*if (!radio_partner1)
	{
		strErrorMsg+='* Devi specificare se desideri confermare il trattamento per l\'iscrizione a VISTAPRINT!\n'; 
	}*/	
	
}

	if (strErrorMsg!='') {
		strErrorMsg='I campi di seguito non sono stati compilati correttamente\n'+strErrorMsg;
		alert(strErrorMsg);
		return false;
	} else {
		return true;
	}
	

	}

function submitForm() {
	return validateFields();
	}

function verifyEmail(s) {
	var chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-@';
	var sLen = s.length; var i=0, c=0, cCnt=0, step=0;
	if (sLen < 6) return false;
	if (s.indexOf('@.')>=0) return false;
	if (s.indexOf('.@')>=0) return false;
	while (i < sLen){
		c=s.charAt(i);
		if (!(chrs.indexOf(c)>=0 || (c=='_' && step<1))) return false;
		if (c=='.') { if (cCnt<1) return false; cCnt=0; }
		if (c=='@') { if (step>0) return false; if (cCnt<1) return false; step++; cCnt=0; }
		cCnt=cCnt+1; i++;
	}
	if (cCnt < 3 || cCnt > 5 || step==0 || (s.indexOf(".")<0) ) return false;
	return true;
	}

function verifyNumeric(strInput) {
	if (strInput != '') {
		if (!strInput.match(/[^0-9]/)) return true;
	}
	}

function verifyCap(strCap) {
	var bValid = false;
	var intLength = strCap.length;
	if (verifyNumeric(strCap) && intLength ==5)
		bValid = true;


	return bValid;
	}

