///////////////////////////////////FUNCTIONS JS//////////////////////////////////////
function inviaqta(q,x,xf) { //q=qta, x=idprod, xf=num. del form
//alert(q+" - "+x+" - "+xf)
if ((! q=="") || (!isNaN(q)) || (!isNaN(x))) {
/*
//disattivato se si utilizza la select x selezionare la qta da 
//inserire nel carrello, attivato se si utilizza input text
df=document.forms["form"+xf]
df.elements["qta"+xf].value=""  
*/
//alert(df)
//ajax2(q,x)
new Ajax.Updater('divcarrello',"ajax.asp?azione=1&qtaprod="+q+"&idprod="+x);
new Ajax.Updater('divnumprodottikart',"ajaxscripts.asp?aggiornanumprodottikart=1");
//new Ajax.Updater('divtest',"ajaxtest.asp?test=1");
}
else {
alert("Attenzione:quantità non valida")
}
}


function showdivajax(nomediv,url) {
	if (url=="") {
		new Ajax.Updater(nomediv,"ajax.asp");
	}
	else {
		new Ajax.Updater(nomediv,url);
	}
}
///////////////////////////////////FUNCTIONS JS//////////////////////////////////////
function fixPNG(myImage,w,h) // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   	 var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	 var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	 var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
	 var imgStyle = "display:inline-block;" + myImage.style.cssText 
	 var strNewHTML = "<span " + imgID + imgClass + imgTitle
	 strNewHTML += " style=\"" + "width:" + w + "px; height:" + h + "px;" + imgStyle + ";"
	 strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	 strNewHTML += "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>" 
	 myImage.outerHTML = strNewHTML
   }
   
   
function admin() 
   {
open("admin/login.asp","admin","width=900,height=700,status=0,scrollbars=0")
   }
   
   
function insert() {
new_w=window.open("ins2.asp","insert","width=600,height=650,status=1,scrollbars=1");
new_w.focus()
}
function modifica(par) {
window.open("mod2.asp?id_modello="+par,"modifica","width=600,height=650,status=1,scrollbars=1")
}
function mod_img(par) {
window.open("ins_img.asp?id="+par,"modifica","width=600,height=650,status=1,scrollbars=1")
}
function gestionefoto(x) {
open('ins_foto1.asp?id='+x,'stampa','width=600,height=650,status=0,scrollbars=1')
}


function fullsize(x) {
if (x!="") {
open("schedafoto.asp?foto="+x,"schedafoto","width=10,height=10,status=0,scrollbars=1")
}
}


function popnews(x) {
open("popnews.asp?idnews="+x,"popnews","width=450,height=450,status=0")
}
   
function privacy() {
open("util/privacy.htm","privacy","width=450,height=250,status=0,scrollbars=0")
}

//function stampa() {
//window.print()
//}

function confronta_print() {
open("confronta_print.asp","confronta_print","width=650,height=500,status=0,scrollbars=1")
}

function confronta_print_riv() {
open("confronta_print_riv.asp","confronta_print","width=650,height=500,status=0,scrollbars=1")
}

function park(x) {
if (document.all || document.getElementById) {
x.innerHTML="<p style='margin-top: 2; margin-bottom: 0' onmouseover='showlay(1)' onmouseout='showlay(0)'><img src=img/ListatoAuto/parcheggioSi.gif border='0'></p>"
}
}


function showlay(n) {
x=document.body.scrollLeft + event.clientX
y=document.body.scrollTop + event.clientY
lay1.style.posLeft=x;
lay1.style.posTop=y;
if ((document.all || document.getElementById) && n==1) {
lay1.style.visibility="visible";
}
if ((document.all || document.getElementById) && n==0) {
lay1.style.visibility="hidden";
}
}

function showlay2(n) {
x=document.body.scrollLeft + event.clientX
y=document.body.scrollTop + event.clientY
lay2.style.posLeft=x;
lay2.style.posTop=y;
if ((document.all || document.getElementById) && n==1) {
lay2.style.visibility="visible";
}
if ((document.all || document.getElementById) && n==0) {
lay2.style.visibility="hidden";
}
}


function setprov(x) {
	df=document.forms[x]
	if (df.nazione.value=="Italia" || df.nazione.value=="Italy" || df.nazione.value=="ITALIA") {
	df.provincia.disabled = false
	df.citta.disabled = false
}
else {
	df.provincia.disabled = true
	df.citta.disabled = true
}
}

//////////////////////////////SCHEDA   

function stampascheda(par,par2,par3) {
if (par3==3) {
	if (par2==1) {
		open('print_admin_prev.asp?id_modello='+par+'&foto=1','stampaprev','width=650,height=600,status=0,scrollbars=1')
	}
	else if (par2==0) {
		open('print_admin_prev.asp?id_modello='+par+'&foto=0','stampaprev','width=650,height=600,status=0,scrollbars=1')
	}
}
else if (par3==2) {
	if (par2==1) {
		open('riv_scheda_stampa.asp?id_modello='+par+'&foto=1','stampa','width=650,height=600,status=0,scrollbars=1')
	}
	else if (par2==0) {
		open('riv_scheda_stampa.asp?id_modello='+par+'&foto=0','stampa','width=650,height=600,status=0,scrollbars=1')
	}
}
else if (par3==1) {
	if (par2==1) {
		open('scheda_stampa.asp?id_modello='+par+'&foto=1','stampa','width=650,height=600,status=0,scrollbars=1')
	}
	else if (par2==0) {
		open('scheda_stampa.asp?id_modello='+par+'&foto=0','stampa','width=650,height=600,status=0,scrollbars=1')
	}
}
}



function info(par) {
open('pop_info.asp?id_modello='+par,'info','width=500,height=545,status=1,scrollbars=1')
}
function prova(par) {
open('pop_prova.asp?id_modello='+par,'prova','width=500,height=555,status=0,scrollbars=1')
}
function noleggio(par) {
open('pop_noleggio.asp?id_modello='+par,'noleggio','width=500,height=545,status=0,scrollbars=0')
}
function permuta(par) {
open('pop_permuta.asp?id_modello='+par,'permuta','width=500,height=500,status=0,scrollbars=1')
}
function finanziamento(par) {
open('pop_finanziamento.asp?id_modello='+par,'finanziamento','width=500,height=500,status=0,scrollbars=1')
}
function inviamico(par) {
open('pop_inviamico.asp?id='+par,'inviamico','width=500,height=450,status=0,scrollbars=1')
}
function confronto(id,modello) {
open('confronto.asp?id_modello='+id+'&modello='+modello,'conronto','width=650,height=535,status=0,scrollbars=0')
}
function pop_foto(x) {
open("img_scheda.asp?id="+x,"img_foto","width=580,height=610,status=0,scrollbars=0")
}

function parkscheda() {
if (document.all || document.getElementById) {
parcheggio.innerHTML="<span style='color:cccc00;padding-left:5px'>Veicolo parcheggiato</span>"
}
}


function info_prodotto(par) {
open('pop_prodottiinfo.asp?id_modello='+par,'info_prodotto','width=500,height=545,status=1,scrollbars=1')
}

////////////////////////////////////

//valoreglobal="";
function setCookie(sNome, sValore, iGiorni, valore) {
valoreglobal=valore
//alert(sNome+sValore+iGiorni+valore)
  if (valoreglobal.indexOf("_" + sValore + "_")!=-1) {
  alert("Veicolo gi&agrave; parcheggiato")
  }
  
  else {
  var dtOggi = new Date()
  var dtExpires = new Date()
  dtExpires.setTime(dtOggi.getTime() + 24 * iGiorni * 3600000)
  //if (valoreglobal!='') {
  //valoreglobal+=sValore
  valoreglobal=valoreglobal + sValore
  ////alert(valoreglobal)
  //}
  //else  {
  //valoreglobal='_' + sValore
  ////alert("valore 1")
  //}
  //document.cookie = sNome + "=" + escape(valoreglobal) + "_" + "; expires=" + dtExpires.toGMTString();
	document.cookie = sNome + "=" + getCookie(sNome) + sValore + "_" + "; expires=" + dtExpires.toGMTString();
	//alert(getCookie(sNome))
}

// restituisce il valore del cookie sNome
function getCookie(sNome) {
  // genera un array di coppie "Nome = Valore"
  // NOTA: i cookies sono separati da ';'
  var asCookies = document.cookie.split("; ");
  // ciclo su tutti i cookies
  for (var i = 0; i < asCookies.length; i++)
  {
    // leggo singolo cookie "Nome = Valore"
    var asCookie = asCookies[i].split("=");
    if (sNome == asCookie[0]) { 
      return (unescape(asCookie[1]));
    }
  }

  // SE non esiste il cookie richiesto
  return("");
}
}


/////////////////////////////////////////////////////////////////////////
function ctrlform(nomeform) {
df=document.forms[nomeform];
//alert(nomeform)
if (nomeform=="richiesta") {
	if (df.elements["modello"].value=="") {
	alert('Attenzione: modello non inserito')
	return false
	}
}
if (nomeform=="rivenditori") {
	if (df.elements["azienda"].value=="") {
	alert('Attenzione: nome azienda non inserito')
	return false
	}
	if (df.elements["piva"].value=="") {
	alert('Attenzione: P.IVA non inserita')
	return false
	}
}
if (nomeform=="contatti" || nomeform=="richiesta") {
	if (df.elements["nome"].value=="") {
	alert('Attenzione: Nome non inserito')
	return false
	}
	if (df.elements["cognome"].value=="") {
	alert('Attenzione: Cognome non inserito')
	return false
	}
}
if (nomeform=="contatti") {
	if (df.elements["citta"].value=="" || df.elements["citta"].value=="0") {
	alert('Attenzione: Citta\' non inserita')
	return false
	}
}
if (df.elements["tel"].value=="") {
alert('Attenzione: Numero di telefono non inserito')
return false
}
if (isNaN(df.elements["tel"].value)) {
alert('Attenzione: Numero di telefono non valido')
return false
}
if (df.elements["mail"].value=="") {
alert('Attenzione: eMail non inserita')
return false
}
if (df.elements["mail"].value.indexOf("@")==-1) {
alert('Attenzione: eMail non valida')
return false
}
if (nomeform=="rivenditori") {
	if ((df.elements["passw"].value=="") || (df.elements["passw"].value.length<6) || (df.elements["passw"].value.length>10)) {
	alert('Attenzione: password non valida')
	return false
	}
}
if (nomeform=="formnewsletter") {
	if (df.elements[0].value=="") {
	alert('Attenzione: campo \"OGGETTO\" vuoto.');
	return false
	}
	if (df.elements[1].value=="") {
	alert('Attenzione: campo \"TESTO\" vuoto.');
	return false
	}
}
if (!df.elements["privacy"].checked) {
alert('Attenzione: e\' necessario autorizzare il trattamento dei dati personali');
return false
}
}


function control_chk(nomeform) {
df=document.forms[nomeform];
if (!df.elements["privacy"].checked) {
alert('Attenzione: disabilitando questo campo la richiesta non verra\' inviata')
}
}



function divdisplay(ndiv) {
//alert(nomediv.style.display)
//nomediv="subcats" + id
nomediv=document.getElementById(ndiv);
if ((document.all || document.getElementById)) {
if (nomediv.style.display=="none") {
nomediv.style.display="inline";
}
else {
nomediv.style.display="none";
}
}
}


//controlla se sessione iscritto attiva, in caso negativo appare il div
function controlcarrellosession(x,p) {
if (x==0) {
//alert("nn log")
divdisplay('alert_sfondo')
divdisplay('alert')
return false
}
else {
location.href=p
}
}


function delcarrello(x) {
if (confirm("Eliminare l'elemento selezionato?")) {
location.replace("areapriv_carrelli.asp?delcarrello="+x)
}
}


//aumenta o diminuisce qta del carrello
function kartaddqta(q,inpt,idprod,prz) {
	//alert("yy")
	//divtest=document.getElementById("divtest")
	//hidcarrellototale=document.getElementById("hidcarrellototale")
	//df=document.forms["carrello"]
	formqta=document.getElementById(inpt)
	//hidcarrellototale=document.getElementById("hidcarrellototale")
	//alert(hidcarrellototale.value)
	//alert(hidcarrellototale.value)
	if (q==1) {
	//formqta=document.getElementById(inpt)
	//newqta=parseInt(formqta.value)+1
	//formqta.value=newqta  //parseInt(formqta.value)+1 //df.qta.value+1
	//ajax2(1,idprod)
	//divcarrellototale.innerHTML=hidcarrellototale.value+prz
	//alert(idprod)
	//ajax3(1,idprod)
	newqta=1
	new Ajax.Updater('divpagcarrello',"ajaxcarrello.asp?azione=1&qtaprod="+newqta+"&idprod="+idprod);
	}
	if (q==0) {
	//formqta=document.getElementById(inpt)
	if (parseInt(formqta.value)>1) {
		//newqta=parseInt(formqta.value)-1
		//formqta.value=newqta  //parseInt(formqta.value)-1 //df.qta.value+1
		//ajax3(-1,idprod)
		//divcarrellototale.innerHTML=hidcarrellototale.value-prz
		newqta=-1
		new Ajax.Updater('divpagcarrello',"ajaxcarrello.asp?azione=1&qtaprod="+newqta+"&idprod="+idprod);
		}
	}
	new Ajax.Updater('divnumprodottikart',"ajaxscripts.asp?aggiornanumprodottikart=1");
}

function canccarrelloprod(id) {
	if (confirm("Cancellare il prodotto selezionato?")) {
		new Ajax.Updater('divpagcarrello',"ajaxcarrello.asp?azione=1&delprod="+id);
		new Ajax.Updater('divnumprodottikart',"ajaxscripts.asp?aggiornanumprodottikart=1");
	}
}
////////////////////////////////////////////////////////////////////////////////////////////

function messaggio() {
open("messaggio.asp","messaggio","width=400,height=400,status=0")
}

////////////////////////////////////////////////////////////////////////////////////

function linkhome(x) {
	if(x=="usatosicuro"){
	open("pop_usato.htm","_blank","width=500,height=400,scrollbars=1")
	}
	if(x=="assistenza"){
	open("pop_assistenza.htm","_blank","width=500,height=550,scrollbars=1")
	}
	if(x=="garanzia"){
	open("pop_garanzia.htm","_blank","width=550,height=600,scrollbars=1")
	}
	if(x=="domicilio"){
	open("pop_domicilio.htm","_blank","width=400,height=400,scrollbars=1")
	}
	if(x=="finanziamenti"){
	open("pop_finanziamenti.htm","_blank","width=500,height=600,scrollbars=1")
	}
}

/////////////////////////////////POP INS/MOD ADM//////////////////////////////////////////
function showdiv(par) {
if (document.all || document.getElementById) {
if (par==1) div1.style.visibility="visible";
if (par==0) div1.style.visibility="hidden";
}
}

function ins_options() {
ins_val="";
df1=document.forms["div-opts"]
for (i=0;i<df1.elements.length-2;i++) {
if (df1.elements[i].checked) {
ins_val=ins_val+df1.elements[i].value+"\n"
}
}
document.forms["form1"].elements["optionals"].value=ins_val
document.all.div1.style.visibility="hidden"
}

function popscheda(x) {
open("popscheda.asp?id="+x,"popscheda","width=350,height=300,status=0")
}
//////////////////////////////////////RIVENDITORI////////////////////////////////////////////
function del_rivenditore(x) {
if(confirm("Eliminare il rivenditore selezionato?")) {
location.href="gestione_rivenditori.asp?del=" + x
}
}
//////////////////////////////////////DATI AZIENDA///////////////////////////////////////////
function ins_aziendadati() {
new_w=window.open("gestione_aziendadati.asp","ins_aziendadati","width=550,height=590,status=1,scrollbars=1");
new_w.focus()
}
/////////////////////////////////////NEWSLETTER//////////////////////////////////////////////
function valid_f() {
df=document.forms[0];
if (df.elements[0].value=="") {
alert('Attenzione: campo \"OGGETTO\" vuoto.');
return false
}
if (df.elements[1].value=="") {
alert('Attenzione: campo \"TESTO\" vuoto.');
return false
}
}

function anteprima(x) {
open("nl_anteprima-txt.asp?txta="+x,"anteprima_txt","width=600,height=450,status=0,scrollbars=1")
}

function anteprima2(par,txta) {
for (i=0;i<=txta.length;i++) {
txta=txta.replace("'","\'")
txta=txta.replace('"','\"')
txta=txta.replace('\n','<br>')
}
window.open("nl_anteprima.asp?id="+par+"&txta="+txta,"anteprima","width=600,height=600,status=0,scrollbars=1")
}


function del_iscritti(x) {
df=document.forms[x]
if (!confirm("eliminare gli iscritti selezionati?"))  {
return false
}
else
{return true}
}

function nl_insmod(x) {
window.open("nl_insmod.asp?id="+x,"nl_insmod","width=550,height=400,status=0")
}
/////////////////////////////////////////////////////////////////////////////////////////////

function mostraordine(x) {
wo=open("areapriv_ordine.asp?idordine="+x,"ordine","width=600,height=600,scrollbars=1,status=0")
wo.focus()
}

//////////////////////////////////RICAMBI///////////////////////////////////////////
function prodottifullsize(x) {
if (x!="") {
open("schedaprodottifoto.asp?foto="+x,"schedaprodottifoto","width=10,height=10,status=0,scrollbars=1")
}
}


function scheda_stampa_prodotto(x) {
wo=open("scheda_stampa_prodotto.asp?idprod="+x,"scheda_stampa_prodotto","width=675,height=600,status=0,scrollbars=1")
wo.focus()
}


var ricambinstato=1

function mostraprodotti(nomediv,nst) {
//alert(nomediv.style.display)
//nomediv="subcats" + id
//nomediv=document.getElementById(ndiv);
if ((document.all || document.getElementById)) {
if (nomediv.style.display=="none") {
nomediv.style.display="inline";
}
else {
//alert(nst)
nomediv.style.display="none";
ricambinstato=1
//return nstato
}
}
}


function fullsizediv(ndiv,img,wid) {
//alert(ndiv)
imgw=wid/2
nomediv=document.getElementById(ndiv)
//sfondodiv=document.getElementById(bgdiv)
if (wid<900) {
	marginleftnumero=-(imgw+28)
	nomediv.style.marginLeft=marginleftnumero+"px"
}
else {
	nomediv.style.marginLeft="-476px"
}
image = document.getElementById('fullimg');
image.src=img   //'fotoprodotti/' + img
		if (nomediv.style.display="inline") {
			nomediv.style.display="inline";
			bg_fullsize.style.display="inline";
		}
		else {
			nomediv.style.display="none"
			bg_fullsize.style.display="none";
		}
}

