// Controlli per form
function avviso(testo){
  alert(testo);
}
function prenotazione() {
  if(document.getElementById("prenotazione").atleti.value == "") {
    messaggio();
    return false;
  }
  if(document.getElementById("prenotazione").cro1.value == "") {
    messaggio();
    return false;
  }
  if(document.getElementById("prenotazione").bon1.value == "") {
    messaggio();
    return false;
  }
  if(document.getElementById("prenotazione").cro2.value == "") {
    messaggio();
    return false;
  }
  if(document.getElementById("prenotazione").bon2.value == "") {
    messaggio();
    return false;
  }
}

function iscrizione() {
	var messaggio = '';
  if(trim(E("iscrizione").societa.value) == "" || E("iscrizione").societa.value.length < 3 ) {
    messaggio += "Campo Società non compilato\n";
  }
  if(trim(E("iscrizione").nsqd.value) == "") {
    messaggio += "Campo Numero Squadre non compilato\n";
  }
  if(trim(E("iscrizione").sig.value) == "") {
    messaggio += "Campo Dirigente non compilato\n";
  }
  if(trim(E("iscrizione").tel.value) == "") {
    messaggio += "Campo Telefono non compilato\n";
  }
  if(trim(E("iscrizione").cell.value) == "") {
    messaggio += "Campo Cellulare non compilato\n";
  }
  if(trim(E("iscrizione").fax.value) == "") {
    messaggio += "Campo Fax non compilato\n";
  }
  if(trim(E("iscrizione").email.value) == "" || E("iscrizione").email.value.search("@") == -1 ) {
    messaggio += "Campo E-mail non compilato\n";
  }
  if(trim(E("iscrizione").ragsoc.value) == "") {
    messaggio += "Campo Ragione Sociale non compilato\n";
  }
  if(trim(E("iscrizione").indirizzo.value) == "") {
    messaggio += "Campo Indirizzo non compilato\n";
  }
  if(trim(E("iscrizione").cap.value) == "") {
    messaggio += "Campo CAP non compilato\n";
  }
  if(E("iscrizione").picf.value == "") {
    messaggio += "Campo Partita IVA e Codice Fiscale non compilato\n";
  }
  if(E("iscrizione").cro.value == "") {
   messaggio += "Campo CRO non compilato\n";
  }
  if(E("iscrizione").bon.value == "") {
    messaggio += "Campo Bonifico non compilato\n";
  }
  if(E("iscrizione").intbon.value == "") {
    messaggio += "Campo Intestatario Bonifico non compilato\n";
  }
  if(E("iscrizione").nomesoc.value == "" || E("iscrizione").nomesoc.value.length > 12) {
    messaggio += "Campo Società Max 12 Caratteri";
  }
  
  //Alla fine controllo se ho avuto alcun errore o nome
  if (messaggio != '') {
	avviso(messaggio);
	return false;
  }
}

/**
 * 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)
		var txt = "E-mail non valida / Invalid E-mail"
		if (str.indexOf(at)==-1){
		   alert(txt)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(txt)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(txt)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(txt)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(txt)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(txt)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(txt)
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var nameID=document.getElementById("guest").name
	var emailID=document.getElementById("guest").email
	var commentID=document.getElementById("guest").comment
	
	if ((nameID.value==null)||(nameID.value=="")){
		alert("Inserire un nome / Insert a name")
		nameID.focus()
		return false
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Inserisci una email / Insert an email")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	if ((commentID.value==null)||(commentID.value=="")){
		alert("Inserire un commento / Insert a comment")
		commentID.focus()
		return false
	}
	
	return true
 }
 
 function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}

function E(id)
{
	return document.getElementById(id);
}
