 <!--

function window_open(filename, x, y, posx, posy, target)
  { windowops = eval("'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=" + x + ",height=" + y + ",left=" + posx + ",top=" + posy + "'");
    newwindow=window.open(filename, target, windowops);
    return;
  }

 function check(campo) 
	{
		var valore_field = document.order[campo].value;	  
			if ((valore_field == "") || (valore_field == "undefined"))
				{ 
					messaggio = campo.replace("_required","");
					messaggio = messaggio.replace("_rpayment","");

					alert("Il campo "+messaggio+" non è valido.");
					return false;

				}
	}

 function check_numeric(campo) 
	{
		var valore_field = document.order[campo].value;	  
			if ((isNaN(valore_field)) || (valore_field == "") || (valore_field == "undefined"))
				{
					messaggio = campo.replace("_required","");
					messaggio = messaggio.replace("_rpayment","");
					alert("Il campo "+messaggio+" contiene caratteri non validi.");
					return false;

				}
				else { return true;}
		}

 function check_mail(campo) 
	{
		var valore_field = document.order[campo].value;	  
		var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
			if (!email_reg_exp.test(valore_field) || (valore_field == "") || (valore_field == "undefined"))
				{
					messaggio = campo.replace("_global","");
					alert("Il campo "+messaggio+" non è valido.");
					return false;

				} 				else { return true;}
    }

 function check_option(campo) 
	{
		var valore_field = document.order[campo].options[document.order[campo].selectedIndex].value;
			if ((valore_field == "") || (valore_field == "undefined"))
				{
					messaggio = campo.replace("_required","");
					messaggio = messaggio.replace("_rpayment","");
					alert("Il campo "+messaggio+" non è valido.");
					return false;

				}
	}

function ControllaCF(campo)
{
    var cf = document.order[campo].value;	
	var err = 0;
    var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  err=1;
    cf = cf.toUpperCase();
    if( cf.length != 16 ) err=1;
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 )err=1;
    }
    set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
    s = 0;
    for( i = 1; i <= 13; i += 2 )
        s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    for( i = 0; i <= 14; i += 2 )
        s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )err=1;
	
	if (err != 0) 
			{
				alert ("IL CODICE FISCALE INSERITO PER RICEVERE LA FATTURA NON E' CORRETTO.\n");
				document.order[campo].value = "";
				return false;
			}
	else return true;
	
}

function ControllaPI(campo)
{
	var err = 0;
	var pi = document.order[campo].value;	

    if( pi == '' )  return '';
    if( pi.length != 11 ) err=1;
        validi = "0123456789";
        for( i = 0; i < 11; i++ ){
                if( validi.indexOf( pi.charAt(i) ) == -1 ) err=1;
        }
        s = 0;
        for( i = 0; i <= 9; i += 2 )
                s += pi.charCodeAt(i) - '0'.charCodeAt(0);
        for( i = 1; i <= 9; i += 2 ){
                c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
                if( c > 9 )  c = c - 9;
                s += c;
        }
        if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ) err=1;


	
	if (err != 0) 
			{
				alert ("LA PARTITA IVA INSERITA PER RICEVERE LA FATTURA NON E' CORRETTA. \n");
				 document.order[campo].value = "";	
				return false;
			}
	else return true;
}

 function copia() 
	{
		var intestazione = document.order.Nome_required.value + " " + document.order.Cognome_required.value;	  
		var indirizzo = document.order.Indirizzo_required.value ;
		var cap =document.order.Cap_required.value;
		var citta = document.order.Citta_required.value;
		var provincia = document.order.Provincia_required.value;


		document.order.Fattura_intestatario.value = intestazione;
		document.order.Fattura_indirizzo_fatturaz.value = indirizzo;
		document.order.Fattura_cap_fatturaz.value = cap;
		document.order.Fattura_citta_fatturaz.value = citta;
		document.order.Fattura_provincia_fatturaz.value = provincia;
	}
function cambia_form() {
	if (document.getElementById('Nome_required')){
		 document.forms['order'].Nome_required.value="";
	//	 alert("cod");
		 }
	if (document.getElementById('Azienda_required')){
		 document.forms['order'].Azienda_required.value="";
	//	 alert("PI");	
	}
	document.order.submit();
}

 function check_c_fiscale_piva() 
	{	
		if (document.getElementById('Codfiscale')){ 
			c_fiscale = document.forms['order'].Codfiscale.value; 
			if (c_fiscale == "")
				{
					alert ("E' NECESSARIO INSERIRE IL CODICE FISCALE.");
					document.order.Codfiscale.focus();
					return false;
				}
			else
				{
					if (ControllaCF('Codfiscale'))	document.order.submit();
					else return false;
				}
			}
		
		if (document.getElementById('Fattura_p_iva')){ 
			p_iva = document.forms['order'].Fattura_p_iva.value; 
			if (p_iva != "")
				{
					if (ControllaPI('Fattura_p_iva')) document.order.submit();
					else return false;
					
				}
			else 
				{
					alert ("E' NECESSARIO INSERIRE LA PARTITA IVA.");
					document.order.Fattura_p_iva.focus();
					return false;
				}
			}
	
		
		/*
		var p_iva = "";
		document.order.Fattura_p_iva.value ;
		*/


		if (document.getElementById('Codizioni_vendita_global')){ 
			condizioni = document.forms['order'].Codizioni_vendita_global.checked; 
			if (condizioni)  document.order.submit();
			else {
					alert ("E' NECESSARIO APPROVARE LE CONDIZIONI GENERALI DI VENDITA.");
					document.forms['order'].Codizioni_vendita_global.focus();
				return false;
			}
		}
	
			

	}

function check_acquisto_diretto() 
	{	var ok=0;
		if (document.getElementById('importo')){ 
			importo = document.forms['order'].importo.value; 
			if (importo == "")
				{
					alert ("E' NECESSARIO INSERIRE UN IMPORTO VALIDO.");
				ok1=0;
				}
			else
				{
			if(	check_numeric("importo")==true){ok1=1;}
				}
			}
		
		if (document.getElementById('causale')){ 
			causale = document.forms['order'].causale.value; 
			if (causale == "")
			{
					alert ("E' NECESSARIO INSERIRE LA CAUSALE.");
			ok2=0;
	
				}
			else 
					{
					ok2=1;				
				}
			}

		if (document.getElementById('email')){ 
			email = document.forms['order'].email.value; 
			if (email == "")
			{
					alert ("E' NECESSARIO INSERIRE L'E-MAIL.");
					ok3=0;			
	
				}
			else 
					{
			if (check_mail("email")==true){	ok3=1;}
				}
			}


			
if ((ok1==1) && (ok2==1) && (ok3==1) ){ 	 document.order.submit();
    }else {
	return false;}

	}