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_del_campo(val){
  if (document.getElementById(val)){
  document.getElementById(val).style.background = "#ffffff";
  }
document.getElementById('id_errore').value = "";
}

function check(val){
//alert("ciao");
var a, file, val2;
a = "r" + (Number(val) + 1);
file = "new_riga.php?id=" + a;
//alert(file);
  if (!document.getElementById("idcog" + a)){
  //alert(file + " " + a);
  cc(a, file);
  }
}


function convalida_soc(){
var i, i2, i3, idcog, idnome, idanno, idtes, par,par2;
i=1;
i2 = 0;
idcog = "idcog" + i;
idnome = "idnome" + i;
idanno = "idanno" + i;
idtes = "idtes" + i;
par = "";

//alert(document.getElementById("idcog2").value);
i3=0;
  while(trim(document.getElementById(idcog).value) != ""){
  //alert(trim(document.getElementById(idcog).value));
  i3++;
   if (trim(document.getElementById(idnome).value) == ""){
	document.getElementById(idnome).style.background = "#f4a3eb";
	i2++;
	}
	
   if (trim(document.getElementById(idanno).value) == ""){
	document.getElementById(idanno).style.background = "#f4a3eb";
	i2++;
	}

  par = par + "&" + idcog + "=" + document.getElementById(idcog).value + "&" + idnome + "=" + document.getElementById(idnome).value + "&" + idanno + "=" + document.getElementById(idanno).value + "&" + idtes + "=" + document.getElementById(idtes).value;
  i++;  
  idcog = "idcog" + i;
  idnome = "idnome" + i;
  idanno = "idanno" + i;
  idtes = "idtes" + i;
  }
  
  if (i3 == 0){
  alert("E' necessario inserire almeno un atleta");
  }
  
  if (document.getElementById('id_check1').checked == false){
  document.getElementById("id_check_bg").style.background = "#f4a3eb";
  i2++;
  }
  
  
  //alert(document.getElementById('id_radio1').checked + " " + document.getElementById('id_radio2').checked);
    
  if (i2 > 0 || i3 == 0){
  document.getElementById('id_errore').value = " ERRORE! Per favore, compilare tutti i campi obbligatori";
  }
  else
  {
      if (document.getElementById('id_radio1').checked == true){
      par = par + "&pag=1";
      }
      if (document.getElementById('id_radio2').checked == true){
      par = par + "&pag=2";
      }
      
  par2 = par.substr(1);
  cc("id_isc_main", "isc_pag_1.php?" + par2);
  }

}

function convalida_soc_2(){
var i, i2, i3, idcog, idnome, idanno, idtes, par, par2;
i=1;
i2 = 0;
idcog = "idcog" + i;
idnome = "idnome" + i;
idanno = "idanno" + i;
idtes = "idtes" + i;
par = "";

//alert(document.getElementById("idcog2").value);
i3=0;
  while(document.getElementById(idcog)){
  par = par + "&" + idcog + "=" + document.getElementById(idcog).value + "&" + idnome + "=" + document.getElementById(idnome).value + "&" + idanno + "=" + document.getElementById(idanno).value + "&" + idtes + "=" + document.getElementById(idtes).value;
  i++;  
  idcog = "idcog" + i;
  idnome = "idnome" + i;
  idanno = "idanno" + i;
  idtes = "idtes" + i;
  }
  
par = par + "&pag=" + document.getElementById("pag").value + "&tot=" + document.getElementById("tot").value;
  
  //alert(document.getElementById('id_radio1').checked + " " + document.getElementById('id_radio2').checked);
    

      
par2 = par.substr(1);
cc("id_isc_main", "isc_pag_2.php?" + par2);
//alert(par2);
}

function convalida_atl(){
var i, i2, par, par2;
i=1;
i2 = 0;
par = "";

  if (trim(document.getElementById("idsoc1").value) == ""){
  i2++;
  document.getElementById("idsoc1").style.background = "#f4a3eb";
  }

  if (trim(document.getElementById("idtipo1").value) == ""){
  i2++;
  document.getElementById("idtipo1").style.background = "#f4a3eb";
  }

  if (trim(document.getElementById("idtes1").value) == ""){
  i2++;
  document.getElementById("idtes1").style.background = "#f4a3eb";
  }  

  
  if (document.getElementById('id_check1').checked == false){
  i2++;
  document.getElementById("id_check_bg").style.background = "#f4a3eb";
  }
  
  
  //alert(document.getElementById('id_radio1').checked + " " + document.getElementById('id_radio2').checked);
    
  if (i2 > 0){
  document.getElementById('id_errore9').innerHTML = "<font color='red'> ERRORE! Per favore, compilare tutti i campi obbligatori </font>";
  }
  else
  {
  //alert(document.getElementById("idsoc1").value);
  par = par + "&idsoc1=" + document.getElementById("idsoc1").value + "&idtes1=" + document.getElementById("idtes1").value + "&idtipo1=" + document.getElementById("idtipo1").value + "&id_tcosto=" + document.getElementById("id_tcosto").value;
  
      if (document.getElementById('id_radio1')){
       if (document.getElementById('id_radio1').checked == true){
       par = par + "&pag=1";
       }
      }

      if (document.getElementById('id_radio2')){
       if (document.getElementById('id_radio2').checked == true){
       par = par + "&pag=2";
       }
      }
      
      if (document.getElementById('id_radio3')){
       if (document.getElementById('id_radio3').checked == true){
       par = par + "&pag=3";
       }
      }
      
      if (document.getElementById('id_radio4')){
       if (document.getElementById('id_radio4').checked == true){
       par = par + "&pag=4";
       }
      }
      
      
      if (document.getElementById('id_radio5')){
       if (document.getElementById('id_radio5').checked == true){
       par = par + "&pag=5";
       }
      }

      if (document.getElementById('id_radio6')){
       if (document.getElementById('id_radio6').checked == true){
       par = par + "&pag=6";
       }
      }
      
  par2 = par.substr(1);
  cc("id_isc_main", "isc_pag_atl_1.php?" + par2);
  }

}

function convalida_atl_c(){
var i, i2, par, par2;
i=1;
i2 = 0;
par = "";

  if (trim(document.getElementById("idsoc1").value) == ""){
  i2++;
  document.getElementById("idsoc1").style.background = "#f4a3eb";
  }

  if (trim(document.getElementById("idsoc1_c").value) == ""){
  i2++;
  document.getElementById("idsoc1_c").style.background = "#f4a3eb";
  }
  
  if (trim(document.getElementById("idcog1_c").value) == ""){
  i2++;
  document.getElementById("idcog1_c").style.background = "#f4a3eb";
  }
  
  if (trim(document.getElementById("idnome1_c").value) == ""){
  i2++;
  document.getElementById("idnome1_c").style.background = "#f4a3eb";
  }

  if (trim(document.getElementById("idanno1_c").value) == ""){
  i2++;
  document.getElementById("idanno1_c").style.background = "#f4a3eb";
  }

  
  if (trim(document.getElementById("idtipo1").value) == ""){
  i2++;
  document.getElementById("idtipo1").style.background = "#f4a3eb";
  }

  if (trim(document.getElementById("idtes1").value) == ""){
  i2++;
  document.getElementById("idtes1").style.background = "#f4a3eb";
  }  

  
  if (document.getElementById('id_check1').checked == false){
  i2++;
  document.getElementById("id_check_bg").style.background = "#f4a3eb";
  }
  
  
  //alert(document.getElementById('id_radio1').checked + " " + document.getElementById('id_radio2').checked);
    
  if (i2 > 0){
  document.getElementById('id_errore9').innerHTML = "<font color='red'> ERRORE! Per favore, compilare tutti i campi obbligatori </font>";
  }
  else
  {
  //alert(document.getElementById("idsoc1").value);
  par = par + "&idsoc1=" + document.getElementById("idsoc1").value + "&idtes1=" + document.getElementById("idtes1").value + "&idtipo1=" + document.getElementById("idtipo1").value + "&id_tcosto=" + document.getElementById("id_tcosto").value + "&idcog1_c=" + document.getElementById("idcog1_c").value + "&idnome1_c=" + document.getElementById("idnome1_c").value + "&idanno1_c=" + document.getElementById("idanno1_c").value + "&idsoc1_c=" + document.getElementById("idsoc1_c").value;
  
      if (document.getElementById('id_radio1')){
       if (document.getElementById('id_radio1').checked == true){
       par = par + "&pag=1";
       }
      }

      if (document.getElementById('id_radio2')){
       if (document.getElementById('id_radio2').checked == true){
       par = par + "&pag=2";
       }
      }
      
      if (document.getElementById('id_radio3')){
       if (document.getElementById('id_radio3').checked == true){
       par = par + "&pag=3";
       }
      }
      
      if (document.getElementById('id_radio4')){
       if (document.getElementById('id_radio4').checked == true){
       par = par + "&pag=4";
       }
      }
      
      
      if (document.getElementById('id_radio5')){
       if (document.getElementById('id_radio5').checked == true){
       par = par + "&pag=5";
       }
      }

      if (document.getElementById('id_radio6')){
       if (document.getElementById('id_radio6').checked == true){
       par = par + "&pag=6";
       }
      }
      
  par2 = par.substr(1);
  cc("id_isc_main", "isc_pag_atl_1_c.php?" + par2);
  }

}


function convalida_atl_2(){
var idtes, idsoc, par, par2, idtipo;
i=1;
i2 = 0;

idtes = "idtes1";
idsoc = "idsoc1";
idtipo = "idtipo1";
par = "";

//alert(document.getElementById("idsoc1").value);

//alert(document.getElementById("idcog2").value);
par = par + "&idsoc1=" + document.getElementById("idsoc1").value + "&idtes1=" + document.getElementById("idtes1").value + "&idtipo1=" + document.getElementById("idtipo1").value;

par = par + "&pag=" + document.getElementById("pag").value + "&tot=" + document.getElementById("tot").value;
  
  //alert(document.getElementById('id_radio1').checked + " " + document.getElementById('id_radio2').checked);
    

      
par2 = par.substr(1);
cc("id_isc_main", "isc_pag_atl_2.php?" + par2);
//alert(par2);
}

function convalida_atl_2_c(){
var idtes, idsoc, par, par2, idtipo, cognome_c, nome_c, anno_c, societa_c;
i=1;
i2 = 0;

idtes = "idtes1";
idsoc = "idsoc1";
idtipo = "idtipo1";
par = "";

//alert(document.getElementById("idsoc1").value);

//alert(document.getElementById("idcog2").value);
par = par + "&idsoc1=" + document.getElementById("idsoc1").value + "&idtes1=" + document.getElementById("idtes1").value + "&idtipo1=" + document.getElementById("idtipo1").value + "&idcog1_c=" + document.getElementById("idcog1_c").value + "&idnome1_c=" + document.getElementById("idnome1_c").value + "&idanno1_c=" + document.getElementById("idanno1_c").value + "&idsoc1_c=" + document.getElementById("idsoc1_c").value;

par = par + "&pag=" + document.getElementById("pag").value + "&tot=" + document.getElementById("tot").value;
  
  //alert(document.getElementById('id_radio1').checked + " " + document.getElementById('id_radio2').checked);
    

      
par2 = par.substr(1);
cc("id_isc_main", "isc_pag_atl_2_c.php?" + par2);
//alert(par2);
}


function isc_check_atl(){
//alert("ciao");

var idcog, idnome, idanno, par, par2, i2;
idcog = trim(document.getElementById("id_cognome").value);
idnome = trim(document.getElementById("id_nome").value);
idanno = trim(document.getElementById("id_anno").value);
i2 = 0;

  if (idcog == ""){
  i2++;
  document.getElementById("id_cognome").style.background = "#f4a3eb";
  }
  
  if (idnome == ""){
  i2++;
  document.getElementById("id_nome").style.background = "#f4a3eb";
  }
  
  if (idanno == ""){
  i2++;
  document.getElementById("id_anno").style.background = "#f4a3eb";
  }

if (i2 == 0){
par = "&cognome=" + idcog + "&nome=" + idnome + "&anno=" + idanno;
par2 = par.substr(1);
//alert(par2);
cc("id_isc_main", "isc_check_atl_2.php?" + par2);
}

}

function isc_del_campo(val){
  if (document.getElementById(val)){
  document.getElementById(val).style.background = "#ffffff";
  }
  
 if (document.getElementById("id_errore9")){
 document.getElementById("id_errore9").innerHTML = "";
 }
}

