function fvalAll() {
  if ( fval1() && fval2() && fval3() && fval4() && fval5() && fval6() && fvaltel() && checkEmail() && fval7() && fval8()) {
	 // if the fields validate then submit the form
	riempicampi();
	document.forms['ckout1'].submit();
    return(false);
  }
  else return(false);
}   

// function fvalpay1() {
// var radio_choice = false;
 // Loop from zero to the one minus the number of radio button selections
// for (counter = 0; counter < document.forms['ckout1'].paytype.length; counter++)
//{
//if (document.forms['ckout1'].paytype[counter].checked)
//radio_choice = true; 
//}

//if (!radio_choice)
//{
// If there were no selections made display an alert box 
//alert("Selezionare una forma di pagamento.")
//return (false);
//}
//return (true);
//}


function fval1() {
    if (document.forms['ckout1'].in_name.value == "") {
      alert("Inserire nome e cognome dell'acquirente");
      document.forms['ckout1'].in_name.focus();
      return(false);
    }
    else{
         return(true);  
         }
  }

  function fval2() {
    if (document.forms['ckout1'].in_add_1.value == "") {
      alert("Inserire l'indirizzo");
      document.forms['ckout1'].in_add_1.focus();
      return(false);
    }
    else return(true);  
  }
  
  function fval3() {
    if (document.forms['ckout1'].in_add_4.value == "") {
      alert("Inserire il Comune o Cittā");
      document.forms['ckout1'].in_add_4.focus();
      return(false);
    }
    else return(true);  
  }
  
  function fval4() {
    if (document.forms['ckout1'].in_cap.value == "") {
      alert("Inserire il cap");
      document.forms['ckout1'].in_cap.focus();
      return(false);
    }
    else return(true);  
  }
  
  function fval5() {
    if (document.forms['ckout1'].in_prov.selectedIndex == 0) {
      alert("Selezionare la Provincia");
      document.forms['ckout1'].in_prov.focus();
      return(false);
    }
    else return(true);  
  }
  
  function fval6() {
    if (document.forms['ckout1'].in_country.selectedIndex == 0) {
      alert("Selezionare la nazione");
      document.forms['ckout1'].in_country.focus();
      return(false);
    }
    else{
         return(true);  
         }
  }
  
    function fvaltel() {
	var strlen = document.forms['ckout1'].in_phone.value;
	strlen = strlen.length
    if (strlen <= 7) {
      alert("Inserire un numero di telefono valido");
      document.forms['ckout1'].in_phone.focus();
      return(false);
    }
    else{
         return(true);  
         }
  }
  
  function checkEmail()
{
var tlds = ".ac .ad .ae .af .ag .ai .al .am .an .ao .aq .ar .as .at .au .aw .ax .az .ba .bb .bd .be .bf .bg .bh .bi .bj .bm .bn .bo .br .bs .bt .bu .bv .bw .by .bz .ca .cc .cd .cf .cg .ch .ci .ck .cl .cm .cn .co .cr .cs .cu .cv .cx .cy .cz .dd .de .dj .dk .dm .do .dz .ec .ee .eg .eh .er .es .et .eu .fi .fj .fk .fm .fo .fr .ga .gb .gd .ge .gf .gg .gh .gi .gl .gm .gn .gp .gq .gr .gs .gt .gu .gw .gy .hk .hm .hn .hr .ht .hu .id .ie .il .im .in .io .iq .ir .is .it .je .jm .jo .jp .ke .kg .kh .ki .km .kn .kp .kr .kw .ky .kz .la .lb .lc .li .lk .lr .ls .lt .lu .lv .ly .ma .mc .md .mg .mh .mk .ml .mm .mn .mo .mp .mq .mr .ms .mt .mu .mv .mw .mx .my .mz .na .nc .ne .nf .ng .ni .nl .no .np .nr .nu .nz .om .pa .pe .pf .pg .ph .pk .pl .pm .pn .pr .ps .pt .pw .py .qa .re .ro .ru .rw .sa .sb .sc .sd .se .sg .sh .si .sj .sk .sl .sm .sn .so .sr .st .su .sv .sy .sz .tc .td .tf .tg .th .tj .tk .tl .tm .tn .to .tp .tr .tt .tv .tw .tz .ua .ug .uk .um .us .uy .uz .va .vc .ve .vg .vi .vn .vu .wf .ws .ye .yt .yu .za .zm .zr .zw .com .net .org .mil .gov .edu .nato .info .int .name .biz .museum .pro";
var myRegex = new RegExp("^[A-Za-z0-9\.\-_]+@[A-Za-z0-9-\.\-_]+\.[A-Za-z]+$")
var endofString = document.forms['ckout1'].in_email.value.split('.');
var ending = endofString.length - 1;
var tld = endofString[ending];
	if (! document.forms['ckout1'].in_email.value.match(myRegex))
	{alert('Indirizzo email non valido.');
	 return false;
	}
	else if (tlds.search(tld) < 0)
	{
	alert('Indirizzo email inesistente.');
	 return false;
	}
	else
	{return true;}
}
 
   function fval7() {
    if (document.forms['ckout1'].accept.checked == "") {
      alert("Per acquistare č necessario acconsentire al trattamento dei dati personali");
      document.forms['ckout1'].accept.focus();
      return(false);
    }
    else return(true);  
  }

  function fval8() {
    if (document.forms['ckout1'].accetta.checked == "") {
      alert("Per procedere č necessario indicare l'accettazione delle condizioni");
      document.forms['ckout1'].accetta.focus();
      return(false);
    }
    else return(true);  
  }


// validation codice cliente
 function fvalCod() {
  if ( fvalcd1()) {
	 // if the fields validate then submit the form
	document.forms['validt'].submit();
    return(false);
  }
  else return(false);
}   

function fvalcd1() {
    if (document.forms['validt'].cod_val.value == "") {
      alert("Inserire il codice cliente");
      document.forms['validt'].cod_val.focus();
      return(false);
    }
    else{
         return(true);  
         }
  }

// riempi i campi da solo
function riempicampi() {
	var myprov ;
    if (document.forms['ckout1'].sh_name.value == "") {document.forms['ckout1'].sh_name.value = document.forms['ckout1'].in_name.value;}
    if (document.forms['ckout1'].sh_co.value == "") {document.forms['ckout1'].sh_co.value = document.forms['ckout1'].in_co.value;}
    if (document.forms['ckout1'].sh_add_1.value == "") {document.forms['ckout1'].sh_add_1.value = document.forms['ckout1'].in_add_1.value;}
    if (document.forms['ckout1'].sh_add_2.value == "") {document.forms['ckout1'].sh_add_2.value = document.forms['ckout1'].in_add_2.value;}
    if (document.forms['ckout1'].sh_add_3.value == "") {document.forms['ckout1'].sh_add_3.value = document.forms['ckout1'].in_add_3.value;}
    if (document.forms['ckout1'].sh_add_4.value == "") {document.forms['ckout1'].sh_add_4.value = document.forms['ckout1'].in_add_4.value;}
    if (document.forms['ckout1'].sh_cap.value == "") {document.forms['ckout1'].sh_cap.value = document.forms['ckout1'].in_cap.value;}
	myprov = document.forms['ckout1'].in_prov[document.forms['ckout1'].in_prov.selectedIndex].value;
	if (document.forms['ckout1'].sh_prov.selectedIndex == 0) {document.forms['ckout1'].sh_prov[document.forms['ckout1'].sh_prov.selectedIndex].value = myprov;}
	//document.frmChange.cboTest[document.frmChange.cboTest.selectedIndex].value = document.frmChange.text.value;

  }