// JavaScript Document

function checkform(kind)
 {
 	if(kind=='privato')
	{
			if(document.privato.name.value=='' || document.privato.address.value=='' || document.privato.zip.value=='' || document.privato.state.value=='' || document.privato.city.value=='' || document.privato.email.value=='')
			{
				window.alert("You have to fill every field!");	
			}
			else if(echeck(document.privato.email.value)==false)
			{
				window.alert("Bad e-mail address!");	
			}
			else if(!(document.privato.cialda.checked ||  document.privato.decaffeinato.checked || document.privato.domus.checked || document.privato.giuggiole.checked || document.privato.mediterraneo.checked || document.privato.miscela.checked || document.privato.classica.checked || document.privato.pannanera.checked || document.privato.supermiscela.checked))
			{
				window.alert("Check at least one product!");	
			}
			else if(document.privato.commento.value=='')
			{
				window.alert("You have not inserted any comment!");	
			}
			else
			{
				document.privato.submit();	
			}			
	}
	else if(kind=='commercio')
	{
			if(document.commercio.name.value=='' || document.commercio.address.value=='' || document.commercio.zip.value=='' || document.commercio.state.value=='' || document.commercio.city.value=='' || document.commercio.email.value=='' || document.commercio.company.value=='' || document.commercio.phone.value=='' || document.commercio.fax.value=='')
			{
				window.alert("You have to fill every field!");	
			}
			else if(echeck(document.commercio.email.value)==false)
			{
				window.alert("Bad e-mail address!");	
			}
			else if(!(document.commercio.cialda.checked ||  document.commercio.decaffeinato.checked || document.commercio.domus.checked || document.commercio.giuggiole.checked || document.commercio.mediterraneo.checked || document.commercio.miscela.checked || document.commercio.classica.checked || document.commercio.pannanera.checked || document.commercio.supermiscela.checked))
			{
				window.alert("Check at least one product!");	
			}
			else if(document.commercio.commento.value=='')
			{
				window.alert("You have not inserted any comment!");	
			}
			else
			{
				document.commercio.submit();	
			}			
	}

 }
 
 function controllaform(kind)
 {
 	if(kind=='privato')
	{
			if(document.privato.name.value=='' || document.privato.address.value=='' || document.privato.zip.value=='' || document.privato.state.value=='' || document.privato.city.value=='' || document.privato.email.value=='')
			{
				window.alert("Dovete riempire tutti i campi!");	
			}
			else if(echeck(document.privato.email.value)==false)
			{
				window.alert("L'indirizzo e-mail non è corretto!");	
			}
			else if(!(document.privato.cialda.checked ||  document.privato.decaffeinato.checked || document.privato.domus.checked || document.privato.giuggiole.checked || document.privato.mediterraneo.checked || document.privato.miscela.checked || document.privato.classica.checked || document.privato.pannanera.checked || document.privato.supermiscela.checked))
			{
				window.alert("Selezionate almeno un prodotto!");	
			}
			else if(document.privato.commento.value=='')
			{
				window.alert("Non avete inserito alcun commento!");	
			}
			else
			{
				document.privato.submit();	
			}			
	}
	else if(kind=='commercio')
	{
			if(document.commercio.name.value=='' || document.commercio.address.value=='' || document.commercio.zip.value=='' || document.commercio.state.value=='' || document.commercio.city.value=='' || document.commercio.email.value=='' || document.commercio.company.value=='' || document.commercio.phone.value=='' || document.commercio.fax.value=='')
			{
				window.alert("Dovete riempire tutti i campi!");	
			}
			else if(echeck(document.commercio.email.value)==false)
			{
				window.alert("L'indirizzo e-mail non è corretto!");	
			}
			else if(!(document.commercio.cialda.checked ||  document.commercio.decaffeinato.checked || document.commercio.domus.checked || document.commercio.giuggiole.checked || document.commercio.mediterraneo.checked || document.commercio.miscela.checked || document.commercio.classica.checked || document.commercio.pannanera.checked || document.commercio.supermiscela.checked))
			{
				window.alert("Selezionate almeno un prodotto!");	
			}
			else if(document.commercio.commento.value=='')
			{
				window.alert("Non avete inserito alcun commento!");	
			}
			else
			{
				document.commercio.submit();	
			}			
	}

 }


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


