function valid_cust(form, checkCodeFiscale, checkBillingAddress){

   var regexp = /\s*/;

   var arrValidForm = new Array();
   arrValidForm[0] = new Array("u_fname", lbl_cw1);
   arrValidForm[1] = new Array("u_lname", lbl_cw1);
   arrValidForm[2] = new Array("u_email", lbl_cw2);
   arrValidForm[3] = new Array("u_phone", lbl_cw3);   
   
   if (!fl_hideship){	      
	   arrValidForm[4] = new Array("ship_street", lbl_cw5);
	   arrValidForm[5] = new Array("ship_city", lbl_cw8);
	   arrValidForm[6] = new Array("ship_zip", lbl_cw7);	   
	   arrValidForm[7] = new Array("ship_state", lbl_cw9);
	   arrValidForm[8] = new Array("ship_country", lbl_cw10);
	   
	   if (checkBillingAddress){
	   arrValidForm[9] = new Array("billing_street", lbl_cw5);
	   arrValidForm[10] = new Array("billing_city", lbl_cw8);
	   arrValidForm[11] = new Array("billing_zip", lbl_cw7);	   
	   arrValidForm[12] = new Array("billing_state", lbl_cw9);
	   arrValidForm[13] = new Array("billing_country", lbl_cw10);	 
	   }  
   }
   

//   arrValidForm[10] = new Array("u_fax", lbl_cw4);

  for (var i = 0; i < arrValidForm.length; i++){
	 if (eval("document."+form+"."+arrValidForm[i][0]+".value").replace(regexp, "") == ""){
		alert(arrValidForm[i][1]);
		eval("document."+form+"."+arrValidForm[i][0]).select();
		eval("document."+form+"."+arrValidForm[i][0]).focus();
		return false;
	 }
  }

  if (checkCodeFiscale){
    with (eval("document."+form)){
	if ( (company.value).replace(regexp, "") == ""){
		alert(lbl_cw14);   
		company.select();
		company.focus();   
		return false;			
	}      
	if ((vat_no.value).replace(regexp, "") == "" && (code_fiscale.value).replace(regexp, "") == ""  ){
		alert(lbl_cw11);   
		vat_no.select();
		vat_no.focus();   
		return false;			
	}
	if (vat_no.value.length > 0  && vat_no.value.length < 11 ){
		alert(lbl_cw13);      
		vat_no.select();
		vat_no.focus();   			
		return false;			
	}
	if (code_fiscale.value.length > 0  && code_fiscale.value.length < 11 ){
		alert(lbl_cw12);      
		code_fiscale.select();
		code_fiscale.focus();   			
		return false;			
	}		     
	}
  }
  eval("document."+form).submit();
}

function destination(code, name, ind, cap, loc, pro, phone, pariva, codfis, fax, email, country, mytype){
	this.code = code;
	this.name = name;
	this.ind = ind;
	this.cap = cap;
	this.loc = loc;
	this.pro = pro;
	this.phone = phone; 
	this.pariva = pariva;
	this.codfis = codfis;	
	this.fax = fax;
	this.email = email;	
	this.country = country;		
	this.mytype = mytype;
}


function changeDest(code){
	var i, j;
	for (i = 0; i < arrDests.length; i++){
		if (arrDests[i].code == code){
			with (document.custForm){
				ship_street.value = arrDests[i].ind;
				ship_zip.value = arrDests[i].cap;
				ship_city.value = arrDests[i].loc;
				ship_state.value = arrDests[i].pro;
				ship_country.value = arrDests[i].country;
				if (elements[elements.length-2].name == "modInf")				
					modInf.disabled = arrDests[i].mytype; 							
					
				for (j = 0; j < elements.length; j++){
					if (elements[j].type == "text" && elements[j].name != "u_fname" && elements[j].name != "u_lname" && elements[j].name != "company")
						elements[j].readOnly = arrDests[i].mytype;	
				}	
			}
			break;
		}
	}
}


function openNewDest(code){
	window.open("/wp_ecomm/ecomm_custnewdest.php?my_ucode="+code, "wndest", "width=500,height=430,resizable=1,scrollbars=1");
}

function addElem(myDest){
	var l = arrDests.length;
	arrDests[l] = new destination(myDest.code, myDest.name, myDest.ind, myDest.cap, myDest.loc, myDest.pro, myDest.phone, myDest.pariva, myDest.codfis, myDest.fax, myDest.email, myDest.country); 
}


function addOption(value_sel, text_sel){
    with(document.custForm) {
        var l = codeDest.length;
        codeDest.options[l] = new Option(text_sel, value_sel);
		codeDest.selectedIndex = l;
    }
}



function fillinvoiceaddress(){
	var arrFields = new Array("street", "zip", "city", "state", "country");
	with (document.custForm){
	  if (useshippaddr.checked){	
	      for (var i = 0; i < arrFields.length; i++){
	         eval("billing_"+arrFields[i]).value = eval("ship_"+arrFields[i]).value;
		  }	  
	  }
	}
}



