var ricercaForm;
var formOrdine;
var tipo_pagamento;
var tipo_spedizione;
//Attach an "onLoad" event to the current window
window.onload = init;
//====================================================	
//Initialization function
function init() {
//Attaching the onSubmit event to the login form
  ricercaForm = document.getElementById('ricerca');
  
  if (ricercaForm !== null) {
    ricercaForm.onsubmit = function () {
                              return canSubmit(this);
                           }
  }

  formOrdine = document.getElementById('frm_ordine');
  if (formOrdine !== null) {
    formOrdine.onsubmit = function () {
                            return canSubmitOrdine(this);
                          }
  }
  
  assoggettato_iva = document.getElementById('assoggettato_iva');
  if (assoggettato_iva !== null) {
    assoggettato_iva.onchange = function() {
                                return aggiornaOrdine(this);
							  }
  }

  tipo_pagamento = document.getElementById('tipo_pagamento');
  if (tipo_pagamento !== null) {
    tipo_pagamento.onchange = function() {
                                return aggiornaOrdine(this);
							  }
  }

  tipo_spedizione = document.getElementById('tipo_spedizione');
  if (tipo_spedizione !== null) {
    tipo_spedizione.onchange = function() {
                                return aggiornaOrdine(this);
							  }
  }

  zona_spedizione = document.getElementById('zona_spedizione');
  if (zona_spedizione !== null) {
    zona_spedizione.onchange = function() {
                                return aggiornaOrdine(this);
							  }
  }

}
//====================================================	
function canSubmit(form) {
  s = form.cerca.value.length;
  if (s < 3) {
	alert('Il valore di ricerca deve essere di almeno tre caratteri');
	form.cerca.focus();
	return false;
  }
  return true; 
}

//====================================================	
function canSubmitOrdine(form) {
  var sped = form.tipo_spedizione;
  var pag  = form.tipo_pagamento;
  
  if (sped.value != '' && pag.value != '') {
    //form.action = '/it/ecommerce/ecommerce_ordine.asp';
    return true;
  } else {
    if (sped.value == '' && pag.value == '') {
      alert('Attenzione: selezionare modalità di pagamento e spedizione');
	} else if (pag.value == '') {
      alert('Attenzione: selezionare una modalità di pagamento');
	} else if (sped.value == '') {
      alert('Attenzione: selezionare una modalità di spedizione');
	}
    return false;
  } 
}

//====================================================	
function aggiornaOrdine(input) {
  val = input.value;
  if (val != '') {
    formOrdine.action = "/it/ecommerce/ecommerce_ordine.asp";	
	formOrdine.submit();
  }
}

