/*scroll menu*/
if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.menu_int{display: none;}\n')
document.write('</style>\n')
}

function trim(stringa){    
			while (stringa.substring(0,1) == ' '){
			stringa = stringa.substring(1, stringa.length);
			}
			while (stringa.substring(stringa.length-1, stringa.length) == ' '){
			stringa = stringa.substring(0,stringa.length-1);}
	return stringa;
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("menusx").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_int")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function initMenu(obj){
	if((typeof(obj) == 'undefined')||(obj == null)){
		var el = document.getElementById("sub_1");
	}else{
		var el = document.getElementById(obj);	
	}
	var ar = document.getElementById("menusx").getElementsByTagName("span");
	if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_int")
				ar[i].style.display = "none";
				if (ar[i].className=="menu_gruppo")/*non visualizzo i gruppi*/
				ar[i].style.display = "none";
				if (ar[i].className=="menu_sottogruppo")/*non visualizzo i sottogruppi*/
				ar[i].style.display = "none";				
			}
			el.style.display = "block";
	}
}

/*menu interni cataloghi*/
function openGruppi(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("menusx").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_gruppo")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

/*menu sottogruppi*/
function openSottogruppi(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("menusx").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_sottogruppo")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}



function openPopupInterno(contenuto,w,h){
	if (w=='') w='400';
	if (h=='') h='300';
		window.open("../popup.php?idcontenuto="+contenuto,'wndPopup','width='+w+',height='+h+',resizable=no,scrollbars=no,toolbar=no,status=yes,location=no,left=50,top=50');
}

function accedi(){
	var f = document.forms["login"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["username"].value==""){
		errore+="Codice cliente\n";
	}
	if (els["pwd"].value==""){
		errore+="Password\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		f.submit();
	}
}

function inviaContatti(){
	var f = document.forms["contatti"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["riferimento"].value==""){
		errore+="Persona di riferimento\n";
	}
	if (els["ragionesoc"].value==""){
		errore+="Ragione sociale\n";
	}
	if (els["telefono"].value==""){
		errore+="Recapito telefonico\n";
	}
	if (els["mail"].value==""){
		errore+="Email\n";
	}		
	/*if (els["area"].value==0){
		errore+="Area di contatto\n";
	}		*/
	if (els["messaggio"].value==""){
		errore+="Messaggio\n";
	}	
	if(!els["acconsento"].checked){
		errore +="Acconsentire al trattamento dei dati personali\n";
	}	

	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;
		f.submit();
	}
}

function iscrivinewsletter(){
	var f = document.forms["newsletter"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["nome"].value==""){
		errore+="Nome\n";
	}
	if (els["cognome"].value==""){
		errore+="Cognome\n";
	}	
	if (els["mail"].value==""){
		errore+="Email\n";
	}	
		if(!els["acconsento"].checked){
		errore +="Acconsentire al trattamento dei dati personali\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		f.submit();
	}	
	
}

function viewmsg(msg){
   if((typeof(msg) != 'undefined')&&(msg != null)&&(msg!="")){
    alert(msg);
   }
}

function richiedipwd(){
	var f = document.forms["richiedipass"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["piva"].value==""){
		errore+="Partita IVA\n";
	}
	if (els["codice"].value==""){
		errore+="Codice cliente\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}


function richiedipwd_new(dato){
	var f = document.forms["richiedipass"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["piva"].value==""){
		errore+="Partita IVA\n";
	}
	if (els["codice"].value==""){
		errore+="Codice cliente\n";
	}	
	if (els["email"]){
		if (els["email"].value==""){
			errore+="Email\n";
		}
	}
	if (errore!=""){
		alert(msg+errore);
	}else{
		if (dato==0){
			els["invia"].value=1;		
			f.submit();
		}else{
			els["invia"].value=0;	
			els["invia2"].value=1;	
			f.submit();
		}
	}	
}

function ricordapass(){
	var f = document.forms["ricordapass"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["piva"].value==""){
		errore+="Partita IVA\n";
	}
	if (els["codice"].value==""){
		errore+="Codice cliente\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}
function cambiapwd(){
	var f = document.forms["modpassword"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["newpwd"].value==""){
		errore+="Nuova password\n";
	}
	if (els["confpwd"].value==""){
		errore+="Conferma nuova password\n";
	}	
	if ((els["newpwd"].value!="")&&(els["confpwd"].value!="")){
		 if((els["newpwd"].value)!=(els["confpwd"].value)){
		 errore+="La password immessa è diversa da quella confermata\n";
		 }
	}
	
	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}

function ricnecessita(obj,num){
	var f = document.forms["customer"];
	var els = f.elements;
	if (obj.value!=""){
		 if(num==0){
		 		els["area"].value = obj.value;
				if(els["areaint"]){
					els["areaint"].value = 0;
				}
			}else{
				els["areaint"].value = obj.value;
			}
		 f.submit();
	}
}

function inviaCustomer(){
	var f = document.forms["customer"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";

	if (els["riferimento"].value==""){
		errore+="Riferimento\n";
	}
	if (els["mail"].value==""){
		errore+="E-mail\n";
	}	
	/*if (els["telefono"].value==""){
		errore+="Telefono\n";
	}	*/
	if (els["area"].value=="0"){
		errore+="Necessità\n";
	}	
	if (typeof(els["areaint"]) != 'undefined'){
		 if (els["areaint"].value=="0"){
		 		errore+="Problema\n";
		 }
	}
  if (typeof(els["richiestacampi"]) != 'undefined'){
  	var richiestac = els["richiestacampi"].value;
  	if (richiestac==1){
  		 if(els["numdoc"].value==""){
  		 	errore+="Numero documento di trasporto\n";
  		}	
  		if(els["datadoc"].value==""){
  		 	errore+="Data documento di trasporto\n";
  		 }	
  	}
	}
	if (els["messaggio"].value==""){
		errore+="Messaggio\n";
	}	
	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}		
}

function ricerca(){
	var f = document.forms["ricerca"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";

	if (trim(els["stringadac"].value)==""){
		errore+="Stringa da cercare\n";
	}
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}		
}
function visualizzacampi(campo){
	var f = document.forms["customer"];
	var els = f.elements;
	var errore = "";
	alert(els["campi_input_"+campo].style);
	if (els["campi_input_"+campo].style.display =="none"){
		els["campi_input_"+campo].style.display = "";
	}else{
		els["campi_input_"+campo].style.display = "none";
	}
}
function HideDiv(ID){
	document.getElementById(ID).style.display="none";
}
		
function ShowDiv(ID){
	document.getElementById(ID).style.display="";
	document.getElementById("footerInt").id = "footerCust"; 	
}
function ShowHideDiv(ID){
	if(document.getElementById(ID).style.display==""){
		HideDiv(ID);
	}else{
		ShowDiv(ID);
	}
}


function addCampi(tipo) {
	var f = document.forms["customer"];
	var obj = document.getElementById("elencoCampi_"+tipo);
	var tmpCodiceArt = new Array();
	var tmpDescrizioneArt = new Array();
	var tmpNumeroPezzi = new Array();
	var n = f.elements["numero_campi_"+tipo].value;
	n++;
	for (i = 0; i < n; i++) {
		tmpCodiceArt[i] = f.elements["codice_art_"+tipo+"["+i+"]"].value;
		tmpDescrizioneArt[i] = f.elements["descrizione_art_"+tipo+"["+i+"]"].value;
		tmpNumeroPezzi[i] = f.elements["numeropezzi_art_"+tipo+"["+i+"]"].value;
	}
	f.elements["numero_campi_"+tipo].value = n;
	var str = "<div id='campi_input["+n+"]'>\n";
  str += "<p class='intest'><input type='text' name='codice_art_"+tipo+"["+n+"]' value='' maxlength='5' size='5' class='boxinputsmall' onBlur='aggDescr(this)'></p>\n";
	str += "<p class='intest'><input type='text' name='descrizione_art_"+tipo+"["+n+"]' value='' class='boxinputsmall' size='40' disabled></p>\n";
  str += "<p class='intest'><input type='text' name='numeropezzi_art_"+tipo+"["+n+"]' value='' class='boxinputsmall' size='5'></p>\n";
  str += "</div>\n";
	obj.innerHTML += str;
	for (i = 0; i < n; i++) {
		f.elements["codice_art_"+tipo+"["+i+"]"].value = tmpCodiceArt[i];
		f.elements["descrizione_art_"+tipo+"["+i+"]"].value = tmpDescrizioneArt[i];
		f.elements["numeropezzi_art_"+tipo+"["+i+"]"].value = tmpNumeroPezzi[i];
	}
}

function aggDescr(obj) {
	var f = obj.form;
	var nome = obj.name;
	var tipo = obj.name.substring(obj.name.lastIndexOf("_")+1,obj.name.indexOf("["));
	var indice = obj.name.substring(obj.name.indexOf("[")+1,obj.name.indexOf("]"));
	var codice = obj.value.toString();
//	alert(codice);
	if (typeof(arrArticoli[codice]) != "undefined") 
		f.elements["descrizione_art_"+tipo+"["+indice+"]"].value = arrArticoli[codice];
	else
		f.elements["descrizione_art_"+tipo+"["+indice+"]"].value = "";
}
