// ******************************* GENERALE ***********************************************************
var lStr_MandatoryID = new Array()
var lStr_MandatoryDesc = new Array()
lStr_MandatoryID.length = 2
lStr_MandatoryDesc.length = lStr_MandatoryID.length
lStr_MandatoryID[1] = "txtNominativo"
lStr_MandatoryDesc[1] = "Nominativo"
lStr_MandatoryID[2] = "txtMail"
lStr_MandatoryDesc[2] = "e-Mail"

var lStr_MandatoryID1 = new Array()
var lStr_MandatoryDesc1 = new Array()
lStr_MandatoryID1.length = 2
lStr_MandatoryDesc1.length = lStr_MandatoryID1.length
lStr_MandatoryID1[1] = "txtDescrizione"
lStr_MandatoryDesc1[1] = "Descrizione"
lStr_MandatoryID1[2] = "txtPrezzo"
lStr_MandatoryDesc1[2] = "Prezzo"

function checkMandatory(aStr_MandatoryID, aStr_MandatoryDesc)
{
	lBln_OK = true
	for (var i=1;i<aStr_MandatoryID.length;i++)
	{
		lObj_Mandatory = document.getElementById(aStr_MandatoryID[i])
		lStr_Trimmed = lObj_Mandatory.value.replace(" ", "")
		if (lStr_Trimmed == "")
		{
			lBln_OK = false
			lStr_Msg = "Il campo \"" + aStr_MandatoryDesc[i] + "\" è obbligatorio"
			alert(lStr_Msg)
			lObj_Mandatory.focus()
			break
		}
	}
	lObj_Mandatory = null
	return lBln_OK
}

// ******************************* GESTIONE CARRELLO **************************************************
function inviaPreventivo()
{
	if (checkMandatory(lStr_MandatoryID, lStr_MandatoryDesc))
	{
		document.all.frmInvioPreventivo.submit()
	}
}
function aggiungiAlCarrello(aStr_IdArticolo)
{
	lStr_URL = "carrello.asp?art=" + aStr_IdArticolo
	window.open(lStr_URL, "winCarrello", "width=740, height=512, status=yes")
}

function sottraiQta(aStr_Index, aStr_IdArticolo)
{
	lObj_Qta = document.getElementById("txtQta" + aStr_Index)
	lInt_Qta = parseInt(lObj_Qta.value)
	lInt_Qta -= 1
	lObj_Qta.value = lInt_Qta
	if (lInt_Qta == 0)
	{
		lStr_Response = confirm("Conferma l\'eliminazione dell\'articolo dal carrello?")
		if (lStr_Response)
		{
			location.replace("carrello.asp?art=" + aStr_IdArticolo + "&qta=" + lInt_Qta)
		}
		else
		{
			lObj_Qta.value = 1
		}
	}
	else
	{
		//azione modifica
		location.replace("carrello.asp?art=" + aStr_IdArticolo + "&qta=" + lInt_Qta)
	}
}

function aggiungiQta(aStr_Index, aStr_IdArticolo)
{
	lObj_Qta = document.getElementById("txtQta" + aStr_Index)
	lInt_Qta = parseInt(lObj_Qta.value)
	lInt_Qta += 1
	lObj_Qta.value = lInt_Qta
	location.replace("carrello.asp?art=" + aStr_IdArticolo + "&qta=" + lInt_Qta)
}

function eliminaArticolo(aStr_Index, aStr_IdArticolo)
{
	lObj_Qta = document.getElementById("txtQta" + aStr_Index)
	lInt_OldQta = lObj_Qta.value
	lStr_Response = confirm("Conferma l\'eliminazione dell\'articolo dal carrello?")
	if (lStr_Response)
	{
		lInt_Qta = 0
		location.replace("carrello.asp?art=" + aStr_IdArticolo + "&qta=" + lInt_Qta)
	}
	else
	{
		lObj_Qta.value = lInt_OldQta
	}
}

function showPayMod()
{
	lObj_PayMod = document.getElementById("pPayMod");
	if (lObj_PayMod.style.display == "none")
	{
		lObj_PayMod.style.display = "block"
		document.all.aPayMod.innerHTML = "nascondi modalit&agrave; di pagamento"
		document.all.aPayMod.title = "clicca qui per nascondere le modalit&agrave; di pagamento"
	}
	else
	{
		lObj_PayMod.style.display = "none"
		document.all.aPayMod.innerHTML = "visualizza modalit&agrave; di pagamento"
		document.all.aPayMod.title = "clicca qui per visualizzare le modalit&agrave; di pagamento"
	}
}

// ******************************* GESTIONE ARTICOLI **************************************************
function setDefaultFoto()
{
	lObj_ComboBox = document.getElementById("cmbCategoria")
	lInt_SelectIndex = lObj_ComboBox.selectedIndex
	document.all.imgPreview.src = "public/" + lObj_ComboBox.options(lInt_SelectIndex).foto
	document.all.hidFotoPath.value = lObj_ComboBox.options(lInt_SelectIndex).foto
}
function artInsert()
{
	window.open("articolo.asp?idart=&action=1", "winArticolo", "toolbar = no, address = no, width = 640, height = 420, status=yes")
}
function artUpdate(aStr_IdArticolo)
{
	window.open("articolo.asp?idart=" + aStr_IdArticolo + "&action=2", "winArticolo", "toolbar = no, address = no, width = 640, height = 420, status = yes")
}
function artDelete(aStr_IdArticolo)
{
	lStr_Response = confirm("Sei sicuro di voler eliminare l\'articolo dalla lista?")
	if (lStr_Response)
	{
		document.all.hidIdArticolo.value = aStr_IdArticolo
		document.all.hidAction.value = "3"
		document.all.frmArticoli.submit()
	}
}
function checkOfferta()
{
	lObj_Element = event.srcElement;
	if (lObj_Element.id == "chkPrimapagina")
	{
		if (lObj_Element.checked)
		{
			document.all.chkOfferta.checked = true
		}
	}
	else
	{
		if (!lObj_Element.checked)
		{
			document.all.chkPrimapagina.checked = false
		}
	}
}
	
function uploadFoto()
{
	document.all.hidFotoPath.value = document.all.txtFoto.value
	document.all.frmUpload.submit()	
}

function salva(aStr_Action)
{	
	if (checkMandatory(lStr_MandatoryID1, lStr_MandatoryDesc1))
	{
		window.opener.document.all.hidIdArticolo.value = document.all.hidIdArticolo.value
		window.opener.document.all.hidDescrizione.value = document.all.txtDescrizione.value
		window.opener.document.all.hidFoto.value = document.all.hidFotoPath.value
		window.opener.document.all.hidIdCategoria.value = document.all.cmbCategoria.value
		window.opener.document.all.hidIdMarca.value = document.all.cmbMarca.value
		window.opener.document.all.hidPrezzo.value = document.all.txtPrezzo.value
		window.opener.document.all.hidIVA.value = document.all.txtIVA.value
		window.opener.document.all.hidDisponibilita.value = document.all.cmbDisponibilita.value
		window.opener.document.all.hidDettaglio.value = document.all.txtDettaglio.innerText
		if (document.all.chkOfferta.checked)
		{
			window.opener.document.all.hidOfferta.value = "1"
		}
		else
		{
			window.opener.document.all.hidOfferta.value = "0"
		}
		if (document.all.chkTop5.checked)
		{
			window.opener.document.all.hidTop5.value = "1"
		}
		else
		{
			window.opener.document.all.hidTop5.value = "0"
		}
		if (document.all.chkPrimapagina.checked)
		{
			window.opener.document.all.hidPrimaPagina.value = "1"
		}
		else
		{
			window.opener.document.all.hidPrimaPagina.value = "0"
		}
		window.opener.document.all.hidAction.value = aStr_Action
		window.opener.document.frmArticoli.submit()
		window.close()
	}
}

function fotoPreview()
{
	document.all.imgPreview.src = document.all.txtFoto.value
}

function checkIva()
{
	lObj_Iva = event.srcElement
	if (isNaN(parseInt(lObj_Iva.value)))
	{
		alert("In questo campo sono ammessi soltanto valori numerici interi")
		lObj_Iva.value = ""
		lObj_Iva.focus()
	}
}

function checkPrezzo()
{
	lObj_Prezzo = event.srcElement
	lDec_Prezzo = lObj_Prezzo.value.replace(",", ".")
	if (isNaN(lDec_Prezzo))
	{
		alert("In questo campo non sono ammessi valori alfanumerici")
		lObj_Prezzo.value = ""
		lObj_Prezzo.focus()
	}
	else
	{
		if (parseFloat(lDec_Prezzo) > 99999.99)
		{
			alert("Il massimo prezzo consentito è 99999,99")
			lObj_Prezzo.value = ""
			lObj_Prezzo.focus()
		}
	}
}

function changeSmiley()
{
	lObj_Disponibile = event.srcElement;
	lStr_Disp = lObj_Disponibile.value
	lObj_Smiley = document.getElementById("imgSmiley")
	if (lStr_Disp == 'A')
	{
		lObj_Smiley.src = "images/smileyAdmin_verde.jpg"
	}
	if (lStr_Disp == 'B')
	{
		lObj_Smiley.src = "images/smileyAdmin_giallo.jpg"
	}
	if (lStr_Disp == 'N')
	{
		lObj_Smiley.src = "images/smileyAdmin_rosso.jpg"
	}
}

function showDetail(aStr_IdArt)
{	
	window.open("dettaglioArticolo.asp?art=" + aStr_IdArt, "winDettaglio", "width=740, height=512, status=yes")
}
