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 form_check_priv(){
var ragione, nome, ric, sett, sito, come, pre, cognome, indirizzo, cap, citta, provincia, telefono, email, ran, ran1, accetto, oggetto, messaggio;
var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
var ck = new Array();
ck[1] = "a7f1c8";
ck[2] = "b2r3ac";
ck[3] = "q2et89";
ck[4] = "p1y5h3";
ck[5] = "mh3g77";
ck[6] = "nf33t4";
ck[7] = "l2ep77";
ck[8] = "nu55h3";
ck[9] = "nu55h3";
ck[10] = "yh3na2";
ck[11] = "yv77e8";
ck[12] = "psa662";
ck[13] = "wf43l1";
ck[14] = "cxz234";
ck[15] = "ke2p37";

i=0;
come = trim(document.getElementById('id_come').value);
pre = trim(document.getElementById('id_pre').value);
sito = trim(document.getElementById('id_sito').value);
ric = trim(document.getElementById('id_ric').value);
sett = trim(document.getElementById('id_sett').value);
ragione = trim(document.getElementById('id_ragione').value);
nome = trim(document.getElementById('id_nome').value);
cognome = trim(document.getElementById('id_cognome').value);
//codfis = trim(document.getElementById('id_codfis').value);
telefono = trim(document.getElementById('id_telefono').value);
email = trim(document.getElementById('id_email').value);
indirizzo = trim(document.getElementById('id_indirizzo').value);
cap = trim(document.getElementById('id_cap').value);
citta = trim(document.getElementById('id_citta').value);
provincia = trim(document.getElementById('id_provincia').value);
//ran1 = document.getElementById('ran1').value;
ran = trim(document.getElementById('id_ran').value); 
ran1 = document.getElementById('id_ran1').value; 
accetto = document.getElementById('id_accetto').checked;
//oggetto = trim(document.getElementById('id_oggetto').value);
messaggio = trim(document.getElementById('id_messaggio').value);


  if (ragione == ""){
  document.getElementById('id_ragione').style.background = "#f498ee";
  document.getElementById('id_ragione').style.border = "1px solid #C4C4C4";
  i++;
  }

  if (email == ""){
  document.getElementById('id_email').style.background = "#f498ee";
  document.getElementById('id_email').style.border = "1px solid #C4C4C4";
  i++;
  }
  else
  {
  	
	if (!espressione.test(email))
	{
	document.getElementById('id_email').style.background = "#f498ee";
	document.getElementById('id_email').style.border = "1px solid #C4C4C4";
	i++;
	}
  }
  
  if (nome == ""){
  document.getElementById('id_nome').style.background = "#f498ee";
  document.getElementById('id_nome').style.border = "1px solid #C4C4C4";
  i++;
  }
  
  if (cognome == ""){
  document.getElementById('id_cognome').style.background = "#f498ee";
  document.getElementById('id_cognome').style.border = "1px solid #C4C4C4";
  i++;
  }  
  
  /*
  if (codfis == ""){
  document.getElementById('id_codfis').style.background = "#f498ee";
  i++;
  }
  */
  
  if (telefono == ""){
  document.getElementById('id_telefono').style.background = "#f498ee";
  i++;
  }
  
  if (indirizzo == ""){
  document.getElementById('id_indirizzo').style.background = "#f498ee";
  i++;
  }
  
  if (cap == ""){
  i++;
  document.getElementById('id_cap').style.background = "#f498ee";
  }
  
  if (citta == ""){
  document.getElementById('id_citta').style.background = "#f498ee";
  i++;
  }
  
  if (provincia == ""){
  document.getElementById('id_provincia').style.background = "#f498ee";
  i++;
  }
  
  
  if (oggetto == ""){
  document.getElementById('id_oggetto').style.background = "#f498ee";
  document.getElementById('id_oggetto').style.border = "1px solid #C4C4C4";
  i++;
  }  
  
  if (messaggio == ""){
  document.getElementById('id_messaggio').style.background = "#f498ee";
  document.getElementById('id_messaggio').style.border = "1px solid #C4C4C4"; 
  i++;
  }  
  
  if (ran == ""){
  document.getElementById('id_ran').style.background = "#f498ee";
  document.getElementById('id_ran').style.border = "1px solid #C4C4C4";
  i++;
  }
  else
  {
    if ( !((ran == ck[ran1]) || (ran == ck[ran1].toUpperCase())) ){
    document.getElementById('id_ran').style.background = "#f498ee";
    document.getElementById('id_ran').style.border = "1px solid #C4C4C4";
    i++;
    }
  }
  
  
  if (accetto == false){
  document.getElementById('idd_accetto').style.background = "#f498ee";
  i++;
  }
  
  if (i > 0){
  cc('id_errore', 'cont_form_errore.php');
  }
  else
  {
  par = "ragione=" + ragione + "&nome=" + nome + "&cognome=" + cognome + "&citta=" + citta + "&telefono=" + telefono + "&email=" + email + "&indirizzo=" + indirizzo + "&cap=" + cap + "&provincia=" + provincia  + "&ran1=" + ran1 + "&ran=" + ran + "&messaggio=" + messaggio + "&ric=" + ric + "&sett=" + sett + "&sito=" + sito + "&pre=" + pre + "&come=" + come;
  //alert(par);  
  cc('corpo2', 'cont_form_ver_real.php', 'post', par);
  }

}

function form_del_campo(val){

  if (document.getElementById(val)){
  document.getElementById(val).style.background = "#ffffff";
  document.getElementById(val).style.border = "1px solid #C4C4C4";
  cc('id_errore', 'form_errore_vuoto.php');
  }
//cc('id_errore', 'form_errore_vuoto.php');  
}

function form_del_campo2(val){
  if (document.getElementById(val)){
  document.getElementById(val).style.background = "";
  }
cc('id_errore', 'form_errore_vuoto.php');  
}