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, idntes, par,par2;
i=1;
i2 = 0;
idcog = "idcog" + i;
idnome = "idnome" + i;
idanno = "idanno" + i;
idtes = "idtes" + i;
idntes = "idntes" + 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++;
	}
	
	if (trim(document.getElementById(idtes).value) == ""){
	document.getElementById(idtes).style.background = "#f4a3eb";
	i2++;
	}
	
	if (trim(document.getElementById(idntes).value) == ""){
	document.getElementById(idntes).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 + "&" + idntes + "=" + document.getElementById(idntes).value;
  i++;  
  idcog = "idcog" + i;
  idnome = "idnome" + i;
  idanno = "idanno" + i;
  idtes = "idtes" + i;
  idntes = "idntes" + i;
  }
  
  if (i3 == 0){
  alert("E' necessario inserire almeno un atleta");
  }
  
  if (document.getElementById('id_check1').checked == false){
  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')){
       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";
       } 
      }      
      
  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, idntes, par, par2;
i=1;
i2 = 0;
idcog = "idcog" + i;
idnome = "idnome" + i;
idanno = "idanno" + i;
idtes = "idtes" + i;
idntes = "idntes" + 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 + "&" + idntes + "=" + document.getElementById(idntes).value;
  i++;  
  idcog = "idcog" + i;
  idnome = "idnome" + i;
  idanno = "idanno" + i;
  idtes = "idtes" + i;
  idntes = "idntes" + 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("idtes1").value) == ""){
  i2++;
  document.getElementById("idtes1").style.background = "#f4a3eb";
  }
  
  if (trim(document.getElementById("idntes1").value) == ""){
  i2++;
  document.getElementById("idntes1").style.background = "#f4a3eb";
  }

  
  if (document.getElementById('id_check1').checked == false){
  document.getElementById("id_checka").style.background = "#f4a3eb";
  i2++;
  }
  
  
  //alert(document.getElementById('id_radio1').checked + " " + document.getElementById('id_radio2').checked);
    
  if (i2 > 0){
  document.getElementById('id_errore').value = " ERRORE! Per favore, compilare tutti i campi obbligatori";
  }
  else
  {
  //alert(document.getElementById("idsoc1").value);
  par = par + "&idsoc1=" + document.getElementById("idsoc1").value + "&idtes1=" + document.getElementById("idtes1").value + "&idntes1=" + document.getElementById("idntes1").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";
       } 
      }     	  
      
  par2 = par.substr(1);
  cc("id_isc_main", "isc_pag_atl_1.php?" + par2);
  }

}

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

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

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

//alert(document.getElementById("idcog2").value);
par = par + "&idsoc1=" + document.getElementById("idsoc1").value + "&idtes1=" + document.getElementById("idtes1").value + "&idntes1=" + document.getElementById("idntes1").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 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("cform", "isc_check_atl_2.php?" + par2);
}

}

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

var nomeut, passw, par, par2, i2;
nomeut = trim(document.getElementById("id_nomeutente").value);
passw = trim(document.getElementById("id_password").value);
i2 = 0;

  if (nomeut == ""){
  i2++;
  document.getElementById("id_nomeutente").style.background = "#f4a3eb";
  }
  
  if (passw == ""){
  i2++;
  document.getElementById("id_password").style.background = "#f4a3eb";
  }
  
if (i2 == 0){
par = "&nomeut=" + nomeut + "&passw=" + passw;
par2 = par.substr(1);
//alert(par2);
cc("cform", "isc_check_soc_2.php?" + par2);
}

}

function isc_atl_focus(){
document.getElementById("idsoc1").focus();
}