//<![CDATA[
var msgConfermaCancProdotto = "Si è sicuri di voler eliminare il prodotto selezionato?";
var msgConfermaCancCliente = "Si è sicuri di voler eliminare il cliente selezionato?";
var aperta = 0;
var pAperta = 0;
var finScheda;
var finPop;
var finestra;
var topPrev = 0;

function FormattaImporto(importo)
{
	var strImporto = new String(importo);
	// i decimali nel database hanno il punto: lo sostituisco con la virgola:
	strImporto = strImporto.replace(".", ",");

	if (strImporto.indexOf(",") < 1)
		strImporto = strImporto + ",00";
	else
	{
		// tronca le cifre decimali a 2
		if (strImporto.indexOf(",") < (strImporto.length -3))
			strImporto = strImporto.substring(0, strImporto.indexOf(",") + 3);
		// minimo di cifre decimali: 2
		if (strImporto.indexOf(",") == (strImporto.length -2))
			strImporto = strImporto + "0";
	}
	return strImporto;
}

//Per formattare input dai formper il db.
function FormattaImportoPerDB(importo)
{
	var strImporto = new String(importo);
	//alert(importo);
	// se l'utente ha usato la virgola, la sostituisco con il punto (per il db)
	strImporto = strImporto.replace(",", ".");
	// tronca le cifre decimali a 2
	if (strImporto.indexOf(".") < (strImporto.length -3))
		strImporto = strImporto.substring(0, strImporto.indexOf(".") + 3);
	//alert(strImporto);
	return strImporto;
}

function ControllaDatiForm(idForm)
{
	// tipoStr = campo testo opzionale
	// tipoStrO = campo testo obbligatorio
	// tipoStrOR = campo testo obbligatorio in alternativa al successivo
	// tipoCur = campo valuta o float opzionale
	// tipoCurO = campo valuta o float obbligatorio
	// tipoCurOR = campo valuta a float obbligatorio in alternativa al successivo
	// tipoCurMax = campo valuta o float opzionale: se vuoto valore massimo
	// tipoInt = campo numerico intero
	// tipoIntO = campo numerico intero obbligatorio
	// tipoIntOR = campo numerico intero obbligatorio in alternativa al successivo

	seOK = true;
	if (navigator.appName == "Netscape")
		var modDati = document.forms[idForm];
	else
		var modDati = document.getElementById(idForm);

	for (i=0; i<modDati.length;i++)
	{
		pref1 = new String(modDati.elements[i].id);
		try {
				val = document.getElementById(pref1).value;
		}
		catch (e) {
		    continue;
		}
		pref = pref1.substring(0, pref1.indexOf("_"));


		switch (pref)
		{
			case "tipoStrOR":
			case "tipoIntOR":
			case "tipoCurOR":
			{
				if (modDati.elements[i].value == "" && modDati.elements[i+1].value == "")
				{
					seOK = false;
					break;
				}
			}
			case "tipoCheckOR":
			{
				if (modDati.elements[i].checked == false && modDati.elements[i+1].checked == false)
				{
					seOK = false;
					break;
				}
			}
			case "tipoCheckStrOR":
			{
				if (modDati.elements[i].checked == false && modDati.elements[i+1].value == "")
				{
					seOK = false;
					break;
				}
			}

			case "tipoStrO":
			case "tipoCurO":
			case "tipoIntO":
			{
				if (val == "")
				{
					seOK = false;
					break;
				}
			}

			case "tipoStr":
			case "tipoStrO":
			{
				if (val == "")
					document.getElementById(pref1).value = "N/A";
				else
				{
					var strC = new String(val);
					// se l'utente ha usato i tag, li elimino
					while (strC.indexOf('<') >= 0)
						strC = strC.replace('<', '');
					while (strC.indexOf('>') >= 0)
						strC = strC.replace('>', '');
					// QUI:
					// cosa fare con le virgolette?
					// sul mio pc non vengono slashate (magic_quotes off)
					// ma sul server credo di sì
					// CONROLLARE
					//while (strC.indexOf("'") >= 0)
						//strC = strC.replace("'", "");
					document.getElementById(pref1).value = strC;
				}
				break;
			}
			case "tipoInt":
			case "tipoIntO":
			{
				if (val == "")
					document.getElementById(pref1).value = "0";
				if (isNaN(parseInt(val)) == true)
					seOK = false;
				break;
			}
			case "tipoCur":
			case "tipoCurO":
			case "tipoCurMax":
			{
				if (val == "")
				{
					if(pref == "tipoCurMax")
						document.getElementById(pref1).value = "1000.00";
					else
						document.getElementById(pref1).value = "0.00";
				}
				else
				{
				  val = val.replace(",", ".");
					if (isNaN(parseFloat(val)) == false)
						document.getElementById(pref1).value = FormattaImportoPerDB(document.getElementById(pref1).value);
					else
						seOK = false;
				}
				break;
			}
			case "tipoCheckM":
			{
				if (document.getElementById(pref1).value=='' || !document.getElementById(pref1).value.match(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i))
					seOK = false;
				break;
			}
			case "tipoCheckO":
			{
				if (document.getElementById(pref1).checked == false)
					seOK = false;
				break;
			}
		}
		if (seOK == false)
		    break;
	}
	if (seOK == false)
		alert ("Campo n. " + (i+1) + ": sono stati immessi valori non validi oppure non sono stati immessi dati obbligatori");
	return seOK;
}

function ControllaDatiForm2(idForm)
{
	var modDati = document.forms[idForm];
	for (i=0; i<modDati.length;i++)
	{
		pref = new String(modDati.elements[i].id);
		pref = pref.substring(0, 3);
		switch (pref)
		{
			case "imp":
			{
				if (modDati.elements[i].value == "")
					return false;
				else
				{
					if (isNaN(parseFloat(modDati.elements[i].value)) == false)
						modDati.elements[i].value = FormattaImportoPerDB(modDati.elements[i].value);
					else
						return false;
				}
				break;
			}
		}
	}
	return true;
}


function controllo(idForm)
{
	// tipoStr = campo testo opzionale
	// tipoStrO = campo testo obbligatorio
	// tipoStrOR = campo testo obbligatorio in alternativa al successivo
	// tipoCur = campo valuta o float opzionale
	// tipoCurO = campo valuta o float obbligatorio
	// tipoCurOR = campo valuta a float obbligatorio in alternativa al successivo
	// tipoCurMax = campo valuta o float opzionale: se vuoto valore massimo
	// tipoInt = campo numerico intero
	// tipoIntO = campo numerico intero obbligatorio
	// tipoIntOR = campo numerico intero obbligatorio in alternativa al successivo

	seOK = true;
	if (navigator.appName == "Netscape")
		var modDati = document.forms[idForm];
	else
		var modDati = document.getElementById(idForm);

	for (i=0; i<modDati.length;i++)
	{
		pref1 = new String(modDati.elements[i].id);
		try {
				val = document.getElementById(pref1).value;
		}
		catch (e) {
		    continue;
		}
		pref = pref1.substring(0, pref1.indexOf("_"));
		switch (pref)
		{
			case "tipoStrOR":
			case "tipoIntOR":
			case "tipoCurOR":
			{
				if (modDati.elements[i].value == "" && modDati.elements[i+1].value == "")
				{
					seOK = false;
					break;
				}
			}
			case "tipoCheckOR":
			{
				if (modDati.elements[i].checked == false && modDati.elements[i+1].checked == false)
				{
					seOK = false;
					break;
				}
			}
			case "tipoCheckStrOR":
			{
				if (modDati.elements[i].checked == false && modDati.elements[i+1].value == "")
				{
					seOK = false;
					break;
				}
			}

			case "tipoStrO":
			case "tipoCurO":
			case "tipoIntO":
			{
				if (val == "")
				{
					seOK = false;
					break;
				}
			}

			case "tipoStr":
			case "tipoStrO":
			{
				if (val == "")
					document.getElementById(pref1).value = "N/A";
				else
				{
					var strC = new String(val);
					// se l'utente ha usato i tag, li elimino
					while (strC.indexOf('<') >= 0)
						strC = strC.replace('<', '');
					while (strC.indexOf('>') >= 0)
						strC = strC.replace('>', '');
					// QUI:
					// cosa fare con le virgolette?
					// sul mio pc non vengono slashate (magic_quotes off)
					// ma sul server credo di sì
					// CONROLLARE
					//while (strC.indexOf("'") >= 0)
						//strC = strC.replace("'", "");
					document.getElementById(pref1).value = strC;
				}
				break;
			}
			case "tipoInt":
			case "tipoIntO":
			{
				if (val == "")
					document.getElementById(pref1).value = "0";
				if (isNaN(parseInt(val)) == true)
					seOK = false;
				break;
			}
			case "tipoCur":
			case "tipoCurO":
			case "tipoCurMax":
			{
				if (val == "")
				{
					if(pref == "tipoCurMax")
						document.getElementById(pref1).value = "1000.00";
					else
						document.getElementById(pref1).value = "0.00";
				}
				else
				{
				  val = val.replace(",", ".");
					if (isNaN(parseFloat(val)) == false)
						document.getElementById(pref1).value = FormattaImportoPerDB(document.getElementById(pref1).value);
					else
						seOK = false;
				}
				break;
			}
			case"tipoCheckO":
			{
				if (document.getElementById(pref1).checked == false)
					seOK = false;
				break;
			}
		}
		if (seOK == false)
		    break;
	}
	if (seOK == false)
		alert ("Sono stati immessi valori non validi oppure non sono stati immessi dati obbligatori");
	return seOK;
}


function RefreshScroll()
{
	eval("fin = document" + layerRef + parentesiID_1 + "'notizie'" + parentesiID_2);
	fin.src = "scroll.htm";
}

function RicercaAltavista()
{
	eval("document" + layerRef + parentesiID_1 + "'stringa'" + parentesiID_2 + ".value = document" + layerRef + parentesiID_1 + "'q'" + parentesiID_2 + ".value");
	eval("document" + layerRef + parentesiID_1 + "'AltavistaSearch'" + parentesiID_2 + ".submit()");
}

function Conferma(messaggio)
{
	if(confirm(messaggio))
		return (true);
	else
   		return (false);
}

function Ingrandisci2(path)
{
   	if (aperta==1)
	{
  		finImg.close();
	}
	finImg = window.open("popup.php?cod=" + path,"finPopup","top=70px,left=100px,width=500px,height=400px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriPopup(url)
{
   	if (pAperta==1)
	{
  		finPop.close();
	}
	finPop = window.open(url,"finPop","top=40px,left=40px,width=400px,height=500px,scrollbars=yes,menubar=no");
	pAperta = 1;
}

function ApriDettagli(codProdotto)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("scheda.php?cod=" + codProdotto,"finScheda","top=100px,left=370px,width=400px,height=450px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriDettagliAdmin(codProdotto)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("schedaProdotto.php?cod=" + codProdotto,"finScheda","top=110px,left=400px,width=300px,height=400px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriDettagliCl(codice)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("schedaCliente.php?cod=" + codice,"finScheda","top=110px,left=350px,width=400px,height=400px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriDettagliOrdine(codice)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("schedaOrdine.php?cod=" + codice,"finScheda","top=60px,left=250px,width=500px,height=450px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriDettagliFattura(codice)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("schedaFattura.php?cod=" + codice,"finScheda","top=40px,left=40px,width=700px,height=500px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriDettagliNotaCredito(codice)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("schedaNotaCredito.php?cod=" + codice,"finScheda","top=40px,left=40px,width=700px,height=500px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriDettagliOrdineF(codice)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("schedaOrdineF.php?cod=" + codice,"finScheda","top=60px,left=250px,width=500px,height=450px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriDettagliForn(codice)
{
   	if (aperta==1)
	{
  		finScheda.close();
	}
	finScheda = window.open("schedaFornitore.php?cod=" + codice,"finScheda","top=110px,left=400px,width=300px,height=400px,scrollbars=yes,menubar=no");
	aperta = 1;
}

function ApriFinTesto(testo)
{
   	if (aperta==1)
   	{
	  	finestra.close();
	}
	finestra=window.open("","finestra","top=30px,left=30px,width=150px,height=320px,scrollbars=yes,menubar=no");
	aperta=1;
	//finestra.document.getElementById('corpo').innerHTML = testo;
	finestra.document.write (testo);
}

function ApriSito()
{
	document.getElementById('menu').style.visibility = 'hidden';
	document.getElementById('corpo').style.visibility = 'visible';
	//topPrev = document.getElementById('imgSfondo').style.pixelHeight;
	//setTimeout("scrollImg()", 20);
	document.getElementById('corpo').style.zIndex = 3;
	document.getElementById('sfondo').style.zIndex = 0;
	document.getElementById('imgSfondo').style.visibility = 'hidden';
}

function scrollImg()
{
	if (topPrev >= 0)
	{
		topPrev = topPrev - 6;
		document.getElementById('imgSfondo').style.pixelHeight = topPrev;
		setTimeout("scrollImg()", 5);
	}
	else
	{
		document.getElementById('corpo').style.zIndex = 3;
		document.getElementById('sfondo').style.zIndex = 0;
	}
}

function CaricaParteCentraleH()
{
	document.getElementById('parteCentrale').innerHTML = document.getElementById('parteDiversa').innerHTML;
}

function CaricaParteCentrale()
{
 	strAdd = "1024";
  var pathImg = "img" + strAdd + "/";

	avvisoTemp = "";
	if (document.getElementById('pathImgTitolo').innerHTML == "")
	{
		strTit = new String(document.getElementById('testotitolo').innerHTML);
  	add = "1024";
  	widthTot = "468";
  	height1 = "1";
  	height2 = "22";
  	height2b = "22";
  	width1 = "40";
  	width2 = "423";
  	width3 = "5";

		strHTMLtit = "<table border='0' cellpadding='0' cellspacing='0' width='" + widthTot + "'>";
		strHTMLtit += "<tr><td><img src='img" + add + "/spacer" + add + ".gif' width='" + width1 + "' height='" + height1 + "' border='0' alt=''></td>";
		strHTMLtit += "<td><img src='img" + add + "/spacer" + add + ".gif' width='" + width2 + "' height='" + height1 + "' border='0' alt=''></td>";
		strHTMLtit += "<td><img src='img" + add + "/spacer" + add + ".gif' width='" + width3 + "' height='" + height1 + "' border='0' alt=''></td></tr>";
		strHTMLtit += "<tr><td><img name='n1partecentrale_r1_c1' src='img" + add + "/partecentrale" + add + "_r1_c1.gif' width='" + width1 + "' height='" + height2 + "' border='0' alt=''></td>"
		strHTMLtit += "<td><img name='n1partecentrale_r1_c2' src='img" + add + "/partecentrale" + add + "_r1_c2.gif' width='" + width2 + "' height='" + height2 + "' border='0' alt=''></td>";
		strHTMLtit += "<td><img name='n1partecentrale_r1_c3' src='img" + add + "/partecentrale" + add + "_r1_c3.gif' width='" + width3 + "' height='" + height2 + "' border='0' alt=''></td></tr>";
		strHTMLtit += "<tr><td><img name='n1partecentrale_r2_c1' src='img" + add + "/partecentrale" + add + "_r2_c1.gif' width='" + width1 + "' height='" + height2b + "' border='0' alt=''></td>";
		strHTMLtit += "<td background='img" + add + "/partecentrale" + add + "_r2_c2.gif' width='" + width2 + "' height='" + height2b + "'><span class='titoloPag'>.:";
		strHTMLtit += "<b>" + strTit.toUpperCase() + "</b>";
		strHTMLtit += "</span></td>";
		strHTMLtit += "<td><img name='n1partecentrale_r2_c3' src='img" + add + "/partecentrale" + add + "_r2_c3.gif' width='" + width3 + "' height='" + height2b + "' border='0' alt=''></td></tr>";
		strHTMLtit += "</table>";
		document.getElementById('divTitolo').innerHTML = strHTMLtit;
		avvisoTemp = "<center><img src='" + pathImg + "parto" + strAdd + ".gif'></center>";
	}
	else
	{
		document.getElementById('divTitolo').innerHTML = "<center><img id=imgTitolo src='" + document.getElementById('pathImgTitolo').innerHTML + "'></center>";
		avvisoTemp = "<center><img src='" + pathImg + "partoIndex" + strAdd + ".gif'></center>";
		//avvisoTemp += "<br><font style='font-size: 14px'><b>mi presento: sono Alessio<br>e vi spiego cosa troverete in questo sito</b></font></center>";
	}

	document.getElementById('parteCentrale').innerHTML = document.getElementById('parteDiversa').innerHTML;
}

function Stampa(selezione)
{
	if (window.print)
	{
  		text = selezione;
	  	winId = window.open('','newwin');
  		with (winId.document)
		{
    			write("<body onLoad='window.focus();window.print()'><pre>" + text + "</pre></body>");
	    		close();
  		}
	}

}

function StampaFatturaOrdine(codOrdine)
{
	DaImplementare();
}

function DaImplementare()
{
	alert("Da implementare");
}
//]]>
