function submitRichiestaInfo (oForm,messaggio) {
	campi="";
	var elem = oForm.elements;
  for(var i = 0; i <= elem.length-1; i++){

	
	
	//for (i=0;i<=oForm.all.length-1;i++) {
		//alert(oForm.all.length);
		//alert(i);
		
		//if (oForm.all(i).getAttribute("mandatory") && oForm.all(i).getAttribute("mandatory")=="true" ) {
		if (elem[i].getAttribute("mandatory") && elem[i].getAttribute("mandatory")=="true" ) {
			
			oggetto=elem[i]
			nome=oggetto.name;
			
			if (oggetto.tagName=="INPUT" && oggetto.value=="" && nome!=null ) {
				campi=campi+", " +nome;
			}
			if (oggetto.tagName=="TEXTAREA" && oggetto.value=="" && nome!=null ) {
				campi=campi+", " +nome;
			}
			if (oggetto.tagName=="SELECT" && oggetto.SelectedIndex==0 && nome!=null ) {
				campi=campi+", " +nome;
			}
			
			if (oggetto.tagName=="INPUT" && oggetto.type=="checkbox" && nome!=null ) {
				idCheckPadre=oggetto.id
				pos=idCheckPadre.lastIndexOf("_");
				idCheckPadre=idCheckPadre.substring(0,pos);
				
				almenoUno=false;
				for (j=0;j<=oForm.all.length-1;j++) {
					oggettoCheck=oForm.all(j)
					idCheck=oggettoCheck.id;
					pos=idCheck.lastIndexOf("_");
					idCheck=idCheck.substring(0,pos);
					
					if (oggettoCheck.tagName=="INPUT" && oggettoCheck.type=="checkbox" && idCheck!=null && idCheck==idCheckPadre && oggettoCheck.checked) {
						almenoUno=true;
					}
					
				}
			
				if (almenoUno==false) {
					pos=campi.lastIndexOf(idCheckPadre);
					if (pos==-1) campi=campi+", " +idCheckPadre;
				}
			}

		}
	}
	if (campi.length >0) {
		campi=campi.substring(1);
		alert(messaggio+"\n\n " + campi);
		return false;
	}
	return true;
}

	function openImmagini(tipo,nomeText,copiaPath) {
		openWindowPopup1("immagini.asp?type=" + tipo +"&virtualPath=false&nomeText=" + nomeText,null);
	}
	function openWindowPopup1(url,winToClose) {
  popupWinFull = window.open(url,'Full','scrollbars=yes,toolbar=no,menubar=no,resizable=yes,fullscreen=no')
  popupWinFull.focus();
  if (winToClose)  winToClose.close();
}
	function onPreview(tipo,nomeText,virtualPath) {
  var f_url = document.getElementById(nomeText);
  var url1 = "" + virtualPath +"" + f_url.value;
  //alert(url1);
  if (!url1) {
    alert("You have to enter an URL first");
    f_url.focus();
    return false;
  }
  document.getElementById(nomeText+"_ipreview").src=url1;
  document.getElementById(nomeText+"_link_ipreview").href=url1;
  //if (nomeText=="PFoto") window.PFoto_ipreview.src=url;
//  if (nomeText=="GFoto") window.GFoto_ipreview.location.replace(url);
//  if (nomeText=="PFoto2") window.PFoto2_ipreview.location.replace(url);
//  if (nomeText=="GFoto2") window.GFoto2_ipreview.location.replace(url);
  return false;

	}
	
	function openWindowStampa(winParent) {
  popupWin = window.open("stampa.asp",'Full','width=200,height=200,scrollbars=no,toolbar=no,menubar=no,resizable=no,fullscreen=no')

  //alert(popupWin.document.all("centerStampa").innerHTML);
  popupWin.focus();
  //popupWin.document.all("centerStampa").innerHTML=winParent.document.all("corpo_stampabile").innerHTML;
  //alert(winParent.document.all("corpo_stampabile").innerHTML);
  //if (winParent)  winParent.close();
}	

	function openWindowStampaAdmin(winParent) {
  popupWin = window.open("../stampa.asp",'Full','width=180,height=50,scrollbars=no,toolbar=no,menubar=no,resizable=no,fullscreen=no')

  //alert(popupWin.document.all("centerStampa").innerHTML);
  popupWin.focus();
  //popupWin.document.all("centerStampa").innerHTML=winParent.document.all("corpo_stampabile").innerHTML;
  //alert(winParent.document.all("corpo_stampabile").innerHTML);
  //if (winParent)  winParent.close();
}	

function blinkIt() {
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}

var message="Questa operazione non è permessa, se avete bisogno di informazioni o materiale contattateci. \n\nLa riproduzione e l’uso, totale o parziale, in qualsiasi forma e-o con qualsiasi mezzo, di contenuti e immagini senza autorizzazione scritta dell’autore, non è autorizzata ad alcuno.\n\nSi richiama allo scopo la tutela del diritto d’autore e dei diritti connessi alla ideazione e progettazione per la comunicazione visiva così come previsto dal D.L. 29 dicembre 1992 n. 518 e D.L. 16 novembre 1994 n. 685"; 
function click(e) {
if (document.all) {
if (event.button == 2 && window.location.href.indexOf("RSS")==-1 && window.location.href.indexOf("admin")==-1) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

	function openWindowStampaPrezzi(winParent,tipoPrezzo) {

	  popupWin = window.open("stampaScheda.asp?tipoPrezzo=" + tipoPrezzo,'Full','width=200,height=30,scrollbars=no,toolbar=no,menubar=no,resizable=no,fullscreen=no')

 
//  popupWin.focus();
 }	


function adminSelSuperCategoria(scat) {
		checka=document.all['SCAT_'+scat].checked;
		for (var oggetto in document.all) {
			if (document.all[oggetto].name) {
				nomeOggetto=document.all[oggetto].name;
				if (nomeOggetto.substring(0,5+scat.toString().length)=='SCAT_'+scat && (nomeOggetto !=('SCAT_'+scat)) ) {
					document.all[oggetto].checked=checka;
				}	
			}
		}
}
function adminSelCategoria(scat,cat) {
		checka=document.all['SCAT_'+scat+'_CAT_'+cat].checked;
		for (var oggetto in document.all) {
			if (document.all[oggetto].name) {
				nomeOggetto=document.all[oggetto].name;
				if (nomeOggetto.substring(0,5+scat.toString().length+5+cat.toString().length)=='SCAT_'+scat+'_CAT_'+cat && (nomeOggetto !=('SCAT_'+scat+'_CAT_'+cat))
					|| ( nomeOggetto.substring(0,5+scat.toString().length)=='SCAT_'+scat && nomeOggetto.indexOf('_CAT_') ==-1) && checka
				
				 ) {
					document.all[oggetto].checked=checka;
				}	
				if (nomeOggetto.substring(0,5+scat.toString().length+5+cat.toString().length)=='SCAT_'+scat+'_CAT_'+cat && (nomeOggetto !=('SCAT_'+scat+'_CAT_'+cat))
					 && !checka
				
				 ) {
					document.all[oggetto].checked=checka;
				}	
				
			}
		}
}

function adminSelSubCategoria(scat,cat,subcat) {
		checka=document.all['SCAT_'+scat+'_CAT_'+cat+'_SUBCAT_'+subcat].checked;
		for (var oggetto in document.all) {
			if (document.all[oggetto].name) {
				nomeOggetto=document.all[oggetto].name;
				if (nomeOggetto.substring(0,5+scat.toString().length+5+cat.toString().length+8+subcat.toString().length)=='SCAT_'+scat+'_CAT_'+cat +'_SUBCAT_'+subcat && (nomeOggetto !=('SCAT_'+scat+'_CAT_'+cat+'_SUBCAT_'+subcat))
					|| ( nomeOggetto=='SCAT_'+scat || nomeOggetto=='SCAT_'+scat+'_CAT_'+cat ) && checka
				
				 ) {
					document.all[oggetto].checked=checka;
				}	
				if (nomeOggetto.substring(0,5+scat.toString().length+5+cat.toString().length)=='SCAT_'+scat+'_CAT_'+cat && (nomeOggetto !=('SCAT_'+scat+'_CAT_'+cat))
					 && !checka
				
				 ) {
					document.all[oggetto].checked=checka;
				}	
				
			}
		}
}

function adminSelProdotto(scat,cat,subcat,prod) {
		//alert('SCAT_'+scat+'_CAT_'+cat+'_PROD_'+prod);
		checka=document.all['SCAT_'+scat+'_CAT_'+cat+'_SUBCAT_'+subcat+'_PROD_'+prod].checked;
		
		for (var oggetto in document.all) {
			if (document.all[oggetto].name) {
				nomeOggetto=document.all[oggetto].name;
				if (
				(nomeOggetto.substring(0,5+scat.toString().length+5+cat.toString().length+8+subcat.toString().length)=='SCAT_'+scat+'_CAT_'+subcat+'_SUBCAT_'+cat || nomeOggetto=='SCAT_'+scat || nomeOggetto=='SCAT_'+scat+'_CAT_'+cat || nomeOggetto=='SCAT_'+scat+'_CAT_'+cat +'_SUBCAT_'+subcat) && 
				(nomeOggetto !=('SCAT_'+scat+'_CAT_'+cat+'_SUBCAT_'+subcat+'_PROD_'+prod))&& 
				(nomeOggetto.indexOf('PROD_') ==-1 ) &&
				checka
				 ) {
					document.all[oggetto].checked=checka;
				}	
			}
		}
}

function adminSelTutto() {
		checka=document.all['export_tutto'].checked;

		for (var oggetto in document.all) {
			if (document.all[oggetto].name) {
				nomeOggetto=document.all[oggetto].name;
				
				if (nomeOggetto.substring(0,5)=='SCAT_' ) {
					document.all[oggetto].checked=checka;
				}	
			}
		}
}


function resetForm(frm_elements) {
	for(i=0; i<frm_elements.length; i++) {

		field_type = frm_elements[i].type.toLowerCase();

		switch(field_type) {

		case "text":
		case "password":
		case "textarea":
		case "hidden":

			frm_elements[i].value = "";
			break;

		case "radio":
		case "checkbox":

			if (frm_elements[i].checked) {

				frm_elements[i].checked = false;

			}
			break;

		case "select-one":
		case "select-multi":

			frm_elements[i].selectedIndex = 0;
			break;

		default:
			break;

		}

	} 
}

	     function aggiungiRigaProdotto() {
     			//if (ritorno_valori.codice.value!="") {
     				//opener.document.getElementById("codice").value=ritorno_valori.codice.value
     				//opener.document.getElementById("prodotto").value=ritorno_valori.prodotto.value
     				//opener.document.getElementById("cprezzo").value=ritorno_valori.cprezzo.value
     				//opener.document.getElementById("rprezzo").value=ritorno_valori.rprezzo.value
     			//	if (opener.document.getElementById("rivenditore").value=='SI') {
     				//	prezzo=ritorno_valori.rprezzo.value;
     			//	}
     			//	else {
     			//		prezzo=ritorno_valori.cprezzo.value;
     			//	}	
     				
     				var tab_prodotti=document.getElementById("tab_prodotti");
     				id_riga=(new Date()).getTime();
    				
    				codiceProdotto="0";
    				prezzoProdotto="0,00";
    				nomeProdotto="";
    				giacenzaProdotto="1";

						//var attributiTextId= "onFocus='jFocus(this)' onBlur='RichiestaDato(this.value)' onKeyUp='return keyPressTextUserid(event,this)' onchange='toggleDisabled(document.getElementById(\'div_stato\'));toggleDisabled(document.getElementById(\'div_prodotti\'))\'";
    				var attributiTextId= "onFocus='jFocus(this)' onBlur='RichiestaDato(this.value)'  ";
     				//alert(attributiTextId);
     				riga="<tr id='"+id_riga+"'><td>" + "<input onFocus='jFocus(this)' onBlur=\"this.value=this.value.toUpperCase();if (this.tag!=this.value) {this.tag=this.value;RichiestaDato(this.value,\'Prodotti\',\'"+id_riga+"\')}\" onKeyUp=\"return keyPressTextUserid(event,this,\'Prodotti\',\'"+id_riga+"\')\"  type='text'  style='width:45px'  value='"+ codiceProdotto +"' name='codice' />" + "</td><td style='font-weight:bold'>" + nomeProdotto + "</td><td><input name='quantita' type='text' value='1' style='text-align:right' size='3' onBlur =\"controlloQuantita(this.value,this.parentNode.childNodes[1].value,0,this.parentNode.parentNode.firstChild.firstChild.value,this.parentNode.parentNode.childNodes[1].innerText,this)\" ><input name=\"giacenza\" type=\"hidden\" value=\"1\" /></td><td align='right'>"+"<input name='prezzo' type='text' value='"+prezzoProdotto+"' style='text-align:right' size='7' >"+"</td><td align='right'>"+"<input name='sconto' type='text' value='"+"0"+"' style='text-align:right' size='3' >% "+"</td><td></td><td><img style='cursor:hand' onclick=\"cancellaRiga(\'"+id_riga+"\',\'"+codiceProdotto+"\',\'"+codiceProdotto+"\')\" align='ambsmiddle' alt='Elimina' src='images/icon_elimina.png' /></td></tr>"
     				//alert(id_riga);
     				var tempDiv = document.createElement("DIV");
						//alert(riga);
						tempDiv.innerHTML = "<table><tbody>"+riga+"</tbody></table>";

//						alert(tempDiv.firstChild.innerHTML);
						var tab_riga=tab_prodotti.appendChild(tempDiv.firstChild.firstChild.firstChild);
						tab_riga.firstChild.firstChild.focus();
						tab_riga.firstChild.firstChild.select()
     				//tab_prodotti.innerHTML=tab_prodotti.innerHTML+"<tr><td>pippo</td></tr>"
//     				alert(tab_prodotti.innerHTML);
     		//	}
     			//window.close()
     		
      }
      
   function controllaFormProdotti() {
     				var tab_prodotti=document.getElementById("tab_prodotti");
				  for (var loop1=2, max1=tab_prodotti.rows.length; loop1<=max1-1; loop1++) {     			  

							codiceProdotto1="";
    	        if (tab_prodotti.rows[loop1].cells[0].childNodes[0].childNodes[1]){
    	        	if (tab_prodotti.rows[loop1].cells[0].childNodes[0].childNodes[1].name=="codice"){
    	        		
    	        		codiceProdotto1=(tab_prodotti.rows[loop1].cells[0].childNodes[0].childNodes[1].value);
		        		}
		        	}
    	        if (tab_prodotti.rows[loop1].cells[0].childNodes[0]){
    	        	if (tab_prodotti.rows[loop1].cells[0].childNodes[0].name=="codice"){
    	        		codiceProdotto1=(tab_prodotti.rows[loop1].cells[0].childNodes[0].value);
		        		}
		        	}
		        	//alert(codiceProdotto1)
							if (codiceProdotto1!="") {
								loop=0;
								max=0;
     			  		for (var loop=2, max=tab_prodotti.rows.length; loop<=max-1  ; loop++) {
    	        		
    	        		codiceProdotto2="";
    	        		if (loop!=loop1) {
    	        			if (tab_prodotti.rows[loop].cells[0].childNodes[0].childNodes[1]){
    	        				if (tab_prodotti.rows[loop].cells[0].childNodes[0].childNodes[1].name=="codice"){
    	        					codiceProdotto2=(tab_prodotti.rows[loop].cells[0].childNodes[0].childNodes[1].value);
    	        				//alert(tab_prodotti.rows[loop].cells[0].childNodes[0].childNodes[1].value);
				        			}
				        		}
    	  		      	if (tab_prodotti.rows[loop].cells[0].childNodes[0]){
    	      		  		if (tab_prodotti.rows[loop].cells[0].childNodes[0].name=="codice"){
    	        					codiceProdotto2=(tab_prodotti.rows[loop].cells[0].childNodes[0].value);
    	        				//alert(tab_prodotti.rows[loop].cells[0].childNodes[0].value);
		        					}
		        				}
				        		//alert(codiceProdotto1 + "-" + codiceProdotto2)
				        		if (codiceProdotto2==codiceProdotto1 && (codiceProdotto2!='NC' && codiceProdotto1!='NC')) {
				        			alert("Attenzione! Il codice prodotto " + codiceProdotto2 + " è presente più di una volta nell'elenco. Non è possibile salvare.")
		  		      			return false;
		    		    		}		

		        			}

		        		}
		        	}

     			  		for (var loop=2, max=tab_prodotti.rows.length; loop<=max-1  ; loop++) {
    	        		
    	        		nomeProdotto2="";
    	        		
   	        			if (tab_prodotti.rows[loop].cells[1] && tab_prodotti.rows[loop].cells[0]){
   	        				nomeProdotto2=tab_prodotti.rows[loop].cells[1].innerText;
   	        				codiceProdotto2=tab_prodotti.rows[loop].cells[0].childNodes[0].value
   	        				//alert(tab_prodotti.rows[loop].cells[0].childNodes[0].childNodes[1].value);
				        		
				        	}
				        		
				        	if ((nomeProdotto2=="" || nomeProdotto2=="CODICE PRODOTTO NON TROVATO") && codiceProdotto2!="NC" ) {
				        		alert("Attenzione! Il codice prodotto è errato.");
		  		      		return false;
		    		    	}		
		        		} 



		      }
		        form_prodotti.submit();
		        return true;
     		
      }      
      var XMLHTTP;
function keyPressTextUserid(e,oText,nomeDato)
{
	
	
	if(window.event) // IE 
	{
		keynum = e.keyCode;
	}else  if(e.which) // Netscape/Firefox/Opera
		{
		keynum = e.which;
		}
		keychar = String.fromCharCode(keynum);
		 //alert (e.keyCode);

    if (oText.value.length >0 && e.keyCode==94)
    {
        RichiestaDato(oText.value,nomeDato,oText.id)
        
        
        
    }
    else
    {
        //document.getElementById("risultati").innerHTML = "";
    } 
}
    function trim(str){
    
        return str.replace(/^\s+|\s+$/g,"");
        
    } 
    function removeSpaces(string) {
 				return string.split(' ').join('');
		}
    

    function RichiestaDato(Iniziale,nomeDato,idTextBox){
        //alert("combo.asp?abc=" + Iniziale + "&" + getTime());
        var url_combo = "combo_" + nomeDato+  ".asp?abc=" + Iniziale + "&idTextBox=" + idTextBox + "&" + new Date().getTime();
        //alert(url_combo);
        XMLHTTP = RicavaBrowser(CambioStato);
        //XMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
				//XMLHTTP.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-9");
        
        XMLHTTP.open("GET", url_combo, true);
        
        
				XMLHTTP.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-9");
        XMLHTTP.send(null);
        
		} 


function CambioStato()
{
    if (XMLHTTP.readyState == 4)
    {
    	
      var nomeDatoResponse=trim(XMLHTTP.responseText.substring(1,21));
      //alert(nomeDatoResponse);
      if (nomeDatoResponse=="Utenti") {
        if (XMLHTTP.responseText.substring(0,1)=="0") {
        	var R1 = document.getElementById("userid");
        	R1.value = trim(XMLHTTP.responseText.substring(1+20+30,255+20+30));
        	var R2 = document.getElementById("cognome");
        	R2.value = trim(XMLHTTP.responseText.substring(256+20+30,256+255+20+30));
        	var R3 = document.getElementById("nome");
        	R3.value = trim(XMLHTTP.responseText.substring(256+255+20+30,255*3+1+20+30));
        	R2.style.background="#33FF66";
        	R3.style.background="#33FF66";
        	
    		} else {
    			var R1 = document.getElementById("userid");
        	var R2 = document.getElementById("cognome");
        	R2.value = trim(XMLHTTP.responseText.substring(20+1+30));
        	var R3 = document.getElementById("nome");
        	R3.value = trim(XMLHTTP.responseText.substring(20+1+30));
        	R2.style.background="red";
        	R3.style.background="red";
        	R1.select();
    			
    		}    
			}
      if (nomeDatoResponse=="Prodotti") {
        if (XMLHTTP.responseText.substring(0,1)=="0") {
        	var idTextBox=trim(XMLHTTP.responseText.substring(20,20+30));
        	//alert(idTextBox);
        	codiceProdotto=trim(XMLHTTP.responseText.substring(20+30,256+20+30));
        	//alert('*'+XMLHTTP.responseText+'*');
        	nomeProdotto=trim(XMLHTTP.responseText.substring(256+20+30,256+255+20+30));
					if (document.getElementById("rivenditore").value=='SI') {
     					prezzo=trim(XMLHTTP.responseText.substring(256+255*2+20+30,255*4+1+20+30));;
     				}
     				else {
     					prezzo=trim(XMLHTTP.responseText.substring(256+255+20+30,255*3+1+20+30));;
     				}	        	
        	giacenza=trim(XMLHTTP.responseText.substring(256+255*3+20+30,255*5+1+20+30));;
        	var R1 = document.getElementById(idTextBox);
        	
        	R1.firstChild.firstChild.value=trim(XMLHTTP.responseText.substring(1+20+30,255+20+30));;
        	//R1.firstChild.firstChild.select();
        	if (codiceProdotto=='NC') {
        		//alert(R1.childNodes[1].innerHTML);
        		R1.childNodes[1].innerHTML='<input type="text" value="'+nomeProdotto+'" id="descrizione_prodotto" name="descrizione_prodotto"  style="width:405px" />';
        		R1.childNodes[1].firstChild.focus();
        		R1.childNodes[1].firstChild.select();
        		
        	} else {
        		R1.childNodes[1].innerHTML=nomeProdotto + '<input type="hidden" value="'+nomeProdotto+'" id="descrizione_prodotto" name="descrizione_prodotto"/>';
        		//R1.childNodes[1].innerText=nomeProdotto;
        	}
        	
        	
        	R1.childNodes[1].style.color="green";
        	R1.childNodes[3].firstChild.value=prezzo;
        	R1.childNodes[2].childNodes[1].value=giacenza;
        	//R1.value = trim(XMLHTTP.responseText.substring(1+20+30,255+20+30));
        	
    		} else {
        	var idTextBox=trim(XMLHTTP.responseText.substring(20,20+30));
        	var R1 = document.getElementById(idTextBox);
        	testoErrore=trim(XMLHTTP.responseText.substring(1+20+30,255+20+30));
        	R1.childNodes[1].style.color="red";
        	
        	R1.childNodes[1].innerText=testoErrore;
        //	R1.firstChild.firstChild.select();
    			
    		}    
   
			}
			
    }
}

function RicavaBrowser(QualeBrowser)
{
    if (navigator.userAgent.indexOf("MSIE") != (-1))
    {
        var Classe = "Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5") != (-1));
        {
            Classe = "Msxml2.XMLHTTP";
        } 
        try
        {
            OggettoXMLHTTP = new ActiveXObject(Classe);
            
            OggettoXMLHTTP.onreadystatechange = QualeBrowser;
            return OggettoXMLHTTP;
        }
        catch(e)
        {
            alert("Errore: l'ActiveX non verrà eseguito!");
        }
    }
    else if (navigator.userAgent.indexOf("Mozilla") != (-1))
    {
        OggettoXMLHTTP = new XMLHttpRequest();
        OggettoXMLHTTP.onload = QualeBrowser;
        OggettoXMLHTTP.onerror = QualeBrowser;
        return OggettoXMLHTTP;
    }
    else
    {
        alert("L'esempio non funziona con altri browser!");
    }
}

function jFocus(elm) {
    if(typeof(elm) == 'string') {
        elm = xGetElementById(elm);
    }
    if (elm) {      
        //elm.focus();
        elm.select();
    }
}

