// FUNZIONI GENERALI E MENU


//immagini in italiano

     var about_us_it_off = new Image(212,17)
		 about_us_it_off.src = "../images/it/about_us_off_it.gif"
     var fabrics_it_off = new Image(212,17)
		 fabrics_it_off.src = "../images/it/fabrics_off_it.gif"
     var shipment_it_off = new Image(212,17)
		 shipment_it_off.src = "../images/it/shipment_off_it.gif"
     var payment_it_off = new Image(212,17)
		 payment_it_off.src = "../images/it/payment_off_it.gif"
     var contacts_it_off = new Image(212,16)
		 contacts_it_off.src = "../images/it/contacts_off_it.gif"

     var about_us_it_on = new Image(212,17)
	 	 about_us_it_on.src = "../images/it/about_us_on_it.gif"
     var fabrics_it_on = new Image(212,17)
	 	 fabrics_it_on.src = "../images/it/fabrics_on_it.gif"
     var shipment_it_on = new Image(212,17)
		 shipment_it_on.src = "../images/it/shipment_on_it.gif"
     var payment_it_on = new Image(212,17)
		 payment_it_on.src = "../images/it/payment_on_it.gif"
     var contacts_it_on = new Image(212,16)
		contacts_it_on.src = "../images/it/contacts_on_it.gif"
		
//immagini in inglese

     var about_us_en_off = new Image(212,17)
		 about_us_en_off.src = "../images/en/about_us_off_en.gif"
     var fabrics_en_off = new Image(212,17)
		 fabrics_en_off.src = "../images/en/fabrics_off_en.gif"
     var shipment_en_off = new Image(212,17)
		 shipment_en_off.src = "../images/en/shipment_off_en.gif"
     var payment_en_off = new Image(212,17)
		 payment_en_off.src = "../images/en/payment_off_en.gif"
     var contacts_en_off = new Image(212,16)
		 contacts_en_off.src = "../images/en/contacts_off_en.gif"

     var about_us_en_on = new Image(212,17)
	 	 about_us_en_on.src = "../images/en/about_us_on_en.gif"
     var fabrics_en_on = new Image(212,17)
	 	 fabrics_en_on.src = "../images/en/fabrics_on_en.gif"
     var shipment_en_on = new Image(212,17)
		 shipment_en_on.src = "../images/en/shipment_on_en.gif"
     var payment_en_on = new Image(212,17)
		 payment_en_on.src = "../images/en/payment_on_en.gif"
     var contacts_en_on = new Image(212,16)
		contacts_en_on.src = "../images/en/contacts_on_en.gif"

//immagini in tedesco

     var about_us_de_off = new Image(212,17)
		 about_us_de_off.src = "../images/de/about_us_off_de.gif"
     var fabrics_de_off = new Image(212,17)
		 fabrics_de_off.src = "../images/de/fabrics_off_de.gif"
     var shipment_de_off = new Image(212,17)
		 shipment_de_off.src = "../images/de/shipment_off_de.gif"
     var payment_de_off = new Image(212,17)
		 payment_de_off.src = "../images/de/payment_off_de.gif"
     var contacts_de_off = new Image(212,16)
		 contacts_de_off.src = "../images/de/contacts_off_de.gif"

     var about_us_de_on = new Image(212,17)
	 	 about_us_de_on.src = "../images/de/about_us_on_de.gif"
     var fabrics_de_on = new Image(212,17)
	 	 fabrics_de_on.src = "../images/de/fabrics_on_de.gif"
     var shipment_de_on = new Image(212,17)
		 shipment_de_on.src = "../images/de/shipment_on_de.gif"
     var payment_de_on = new Image(212,17)
		 payment_de_on.src = "../images/de/payment_on_de.gif"
     var contacts_de_on = new Image(212,16)
		contacts_de_on.src = "../images/de/contacts_on_de.gif"
		

function on(nome)
{
     var acceso = eval(nome + "_on.src")
     document[nome].src = acceso
       
}

function off(nome)
{
  
     var spento = eval(nome + "_off.src")
    document[nome].src = spento
}

// FORM CONTATTI

function verifica_mail()
 {
   if ((document.contatti.email.value.indexOf("@") == -1) | (document.contatti.email.value.indexOf(".") == -1) | (document.contatti.email.length < 7)) 
        {
		window.alert("Insert a correct E-mail address")
		document.contatti.email.value="";
		document.contatti.email.focus();
		return false
	}
   else 
        {
 		return true
	}
}


function invia() {
	if (verifica_mail()) {
	document.contatti.submit();
 		}
}

function reset() {
	document.contatti.reset();
 		}


// iscrizione

function controlla() {
      var check = 0
      if (document.iscrizione.nome.value == "") {
           alert("Inserisci il NOME");
		   return false
      }else check++

      if (document.iscrizione.cognome.value == "") {
           alert("Inserisci il COGNOME");
		   return false
      }else check++

      if (document.iscrizione.societa.value == "") {
           alert("Inserisci la SOCIETA");
		   return false
      }else check++

	  if (document.iscrizione.partita_iva.value == "") {
           alert("Inserisci la PARTITA IVA");
		   return false
      }else check++
      
      if (document.iscrizione.indirizzo.value == "") {
           alert("Inserisci il campo INDIRIZZO");
		   return false
      }else check++

      if (document.iscrizione.cap.value.value == "") {
           alert("Inserisci il CAP")
		   return false
      }else check++

      if (document.iscrizione.citta.value == "") {
           alert("Inserire la CITTA")
		   return false
      }else check++

      if (document.iscrizione.id_nazione.value == 0) {
           alert("Inserisci il PAESE")
		   return false
      }else check++

      if (document.iscrizione.telefono.value == "") {
           alert("Inserisci il TELEFONO")
		   return false
      }else check++
      
      if (document.iscrizione.userid.value == "") {
           alert("Inserisci la USERID")
		   return false
      }else check++
      
      if (document.iscrizione.password.value == "") {
           alert("Inserisci la PASSWORD")
		   return false
      }else check++
      
      if (!(document.iscrizione.password_check.value == document.iscrizione.password.value)) {
           alert("Attenzione: non è stata inserita correttamente la PASSWORD")
		   return false
      }else check++

      if (document.iscrizione.fax.value == "") {
           //alert("Insert the fax")
           document.iscrizione.fax.value == " "
		   //return false
      }else check++
  
	
	  if (document.iscrizione.modifica.value == "true") {
    
		   if(document.iscrizione.password.value == ""){
				alert("Insert your password");	
				return false;
           }else check++
      }		

	  if (document.iscrizione.modifica.value == "true") {
			if (check < 10){
				return false
			}else return true
			
	  }else{
			if (check < 9) {
				  return false
			}else return true
	  }
}


function verifica_mailiscriz()
 {
   if ((document.iscrizione.email.value.indexOf("@") == -1) | (document.iscrizione.email.value.indexOf(".") == -1) | (document.iscrizione.email.length < 7)) 
        {
		window.alert("Insert a correct E-mail")
		document.iscrizione.email.value="";
		document.iscrizione.email.focus();
		return false
	}
   else 
        {
 		return true
	}
}

function iscrizione() {
	if (controlla() && verifica_mailiscriz()) {
	document.iscrizione.submit();
 		}
}

function resetiscriz() {
	document.iscrizione.reset();
 		}


// GENERALI

function help(){
window.name = 'myWin';
window.open('../pages/help.htm',"modulo","height=400,width=530,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=0,top=0");
	}

function help_asp(){
	window.name = 'myWin';
	window.open('../pages/help.htm',"modulo","height=300,width=400,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=0,top=0");
	}
	
function mod_qt(id){
	window.name = 'myWin';
	window.open('modifica_qt.asp?id=' + id,"modulo","height=150,width=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,left=300,top=200");
	}

function barra(messaggio) 
{
        window.defaultStatus = " "
        window.status = messaggio
}

function salta(id_fam)
{
	if (id_fam != 0){	
		self.location.href = "tessuti.asp?id_fam=" + id_fam
	}
}

function ctrl_qta(){
	var controllo
	controllo = 0 
	if (document.basket.id.length == undefined){
		if (eval("document.basket.qta" + document.basket.id.value + ".value.replace(\",\",\".\")") < 0.5 || parseInt(eval("document.basket.qta" + document.basket.id.value + ".value.replace(\",\",\".\")")) > 100 || parseInt(eval("document.basket.qta" + document.basket.id.value + ".value.replace(\",\",\".\")")) > parseInt(eval("document.basket.giacenza" + document.basket.id.value + ".value.replace(\",\",\".\")"))){
				controllo++
			}
	}
	else{
		for (var elem = 0 ; elem < document.basket.id.length ; elem++ ){
			/*alert(eval("document.basket.qta" + document.basket.id[elem].value + ".value.replace(\",\",\".\")") < 0.5);
			alert(parseInt(eval("document.basket.qta" + document.basket.id[elem].value + ".value.replace(\",\",\".\")")) > 100);
			alert(parseInt(eval("document.basket.qta" + document.basket.id[elem].value + ".value.replace(\",\",\".\")")) > parseInt(eval("document.basket.giacenza" + document.basket.id[elem].value + ".value.replace(\",\",\".\")")));*/
			//alert("document.basket.qta" + document.basket.id[elem].value + ".value.replace(\",\",\".\")")
			//alert("giac:" + eval("document.basket.giacenza" + document.basket.id[elem].value + ".value")+ " -  qta: " + eval("document.basket.qta" + document.basket.id[elem].value + ".value"))
			if (eval("document.basket.qta" + document.basket.id[elem].value + ".value.replace(\",\",\".\")") < 0.5 || parseInt(eval("document.basket.qta" + document.basket.id[elem].value + ".value.replace(\",\",\".\")")) > 100 || parseInt(eval("document.basket.qta" + document.basket.id[elem].value + ".value.replace(\",\",\".\")")) > parseInt(eval("document.basket.giacenza" + document.basket.id[elem].value + ".value.replace(\",\",\".\")"))){
				controllo++
			}
		}
	}

	if (controllo == 0) {
		return true
	} else {
		window.alert("La quantità richiesta al momento\nnon è disponibile\n\nContattare info@paganini-fabrics.com") 
		return false
	}

}

function ordina()
{
	if (ctrl_qta()) {
		document.basket.action = "spedizione.asp";
		document.basket.submit();
		//alert('ok');
	}
	return true
}

function ordina_catalogo(){
	document.basket.action = "spedizione.asp";
	document.basket.submit();
}

function aggiorna()
{
	if (ctrl_qta()) {
		document.basket.submit();
	}
	return true
}

function check_sped(){

	document.spedizione.submit()
}

function login(){
	document.login.submit()	
}

//pagina spedizione

function check_sped() {
      var check = 0
      if (document.spedizione.nome_sped.value == "") {
           alert("Insert your name");
		   return false
      }else check++

      if (document.spedizione.cognome_sped.value == "") {
           alert("Insert your surname");
		   return false
      }else check++

      if (document.spedizione.societa_sped.value == "") {
           alert("Inserire il Nome dell'Azienda");
		   return false
      }else check++

      if (document.spedizione.indirizzo_sped.value == "") {
           alert("Insert your address");
		   return false
      }else check++

      if (document.spedizione.cap_sped.value.value == "") {
           alert("Insert the zip code")
		   return false
      }else check++

      if (document.spedizione.citta_sped.value == "") {
           alert("Insert the city")
		   return false
      }else check++

      if (document.spedizione.id_nazione_sped.value == 0) {
           alert("Insert the country")
		   return false
      }else check++

      if (document.spedizione.telefono_sped.value == "") {
           alert("Insert the phone number")
		   return false
      }else check++

      if (document.spedizione.fax_sped.value == "") {
           alert("Insert the fax number")
		   return false
      }else check++

      if (document.spedizione.id_sped.value == "undefined") {
           alert("Choose a kind od shipment")
		   return false
      }else check++
  		
	  if (check < 10){
			return false
	  }else return true

}

function invia_sped(){
	if (check_sped()){ 
		document.spedizione.submit()
	}	
}