// JavaScript Document
function addLoader(f) {
	if (f!=undefined) {
	if (window.onload) {
		var z=window.onload	
		window.onload=function () {f();z()}
	} else {
		window.onload=f
	}}
}
function addUnLoader(f) {
	if (window.onunload) {
		var z=window.onunload	
		window.onunload=function () {z();f()}
	} else {
		window.onunload=f
	}
}
var oObjMng=new Array()
function postLoad() {
	for (var i=0;i<oObjMng.length;i++) {
		if (oObjMng[i].postInit) {oObjMng[i].postInit()}
	}
}

function postUnload() {
	for (var i=0;i<oObjMng.length;i++) {
		if (oObjMng[i].unload) {oObjMng[i].unload()}
	}
}
addLoader(postLoad)
addUnLoader(postUnload)

addLoader(homeSlide)
function homeSlide() {
	var o=$("autoservizi")
	if (o) {
			callAction(new Array("P",homeSlideRun,"/_interno/home.asp",""))
	}
}
function homeSlideRun(m,x,n,f) {
	if (m) {
		var gl=$t(x,"GLS")
		if (gl.length==1) {
			var g=$t(gl[0],"GL")
			var o=$("autoservizi")
			if (g.length==1) {
				o.style.backgroundImage="url(/css/home/"+g[0].getAttribute("uid")+".jpg)"
			} else if (g.length!=0) {
				var vv=[]
				for(var i=0;i<g.length;i++) {
					vv[i]=g[i].getAttribute("uid")
				}
				animahome(o,"/css/home/",vv,5000)
			}
		}
	}
}
function getSafExx(s) {
	return  s.replace(/&#(\d{1,4});/gi,function (a,b,c,d) {return String.fromCharCode(b)})
}

function $(id) {return document.getElementById(id)}
function $t(o,id) {return o.getElementsByTagName(id)}
function $b(id) {return document.createElement(id)}
function $ct(t) {return document.createTextNode(t)}
function $ae(o,eName,f) {
	if(window.addEventListener){ // Mozilla, Netscape, Firefox
		o.addEventListener(eName, f, false);
	} else { // IE
		o.attachEvent('on'+eName, f);
	}
}
function sc(o,ncn,ocn) {
	if (o) {
		if (ocn!=undefined) {
			if(ocn!="") {
				var re=new RegExp("\\b"+ocn+"\\b","gi")
				var i=o.className.search(re)
				if (i!=-1) {o.className=o.className.replace(re,"")}
			}
		}
		if (ncn!="") {
			var re=new RegExp("\\b"+ncn+"\\b","gi")
			var i=o.className.search(re)
			if (i==-1) {o.className=o.className.replace(/\s*$/,'')+" "+ncn}
		}
	}
}
var oAnimaHome=null
function animahome(a,b,c,d) {
	oAnimaHome=new cls_animazione(oObjMng.length,a,b,c,d)
	oObjMng[oObjMng.length]=oAnimaHome
}
function cls_animazione(obIndx,inObj,inBase,inSrc,inStop) {
	this.obIndex=obIndx
	this.cimg=0
	this.base=inBase
	this.ext=".jpg"
	this.maximg=inSrc.length
	this.runTime=50
	this.stopTime=(inStop==undefined)?2000:inStop
	this.opa=100
	this.multiloop=true
	this.pr=10
	this.images=new Array()
	this.vcimg=inSrc
	this.oExt=$b("div")
	this.oExt.className="anima"
	inObj.appendChild(this.oExt)
	this.oInt=$b("div")
	this.oInt.className="anima"
	this.oExt.appendChild(this.oInt)
	this.clock=0
	
	
	this.postInit2=function postInit2() {
		this.maximg=this.vcimg.length-1
		for (var i=0;i<=this.maximg;i++) {
			var ci=new Image()
			ci.src=this.base+this.vcimg[i]+this.ext
			this.images[i]=ci
		}
		if (this.oInt) {this.oInt.style.backgroundImage="url("+this.base+this.vcimg[0]+this.ext+")"}
		if (this.oExt) {this.oExt.style.backgroundImage="url("+this.base+this.vcimg[1]+this.ext+")"}
		if (this.oExt&&this.oInt) {this.vcimg=null;this.clock=setTimeout("oObjMng["+this.obIndex+"].prerun()",10)}
	}
	this.postInit2()

	this.prerun=function prerun() {
		var ok=true
		for(var i=0;i<this.images.length;i++) {
			if (!this.images[i].complete) {ok=false}
		}
		if(ok) {
			var nt=this.stopTime-this.pr
			if (nt<10) {nt=10}
			this.clock=setTimeout("oObjMng["+this.obIndex+"].run()",nt)
		} else {
			this.pr+=10
			this.clock=setTimeout("oObjMng["+this.obIndex+"].prerun()",10)
		}
	}

	this.run=function run() {
		this.opa--
		this.opa--
		if (this.opa<1) {this.opa=1}
		this.oInt.style.opacity=(this.opa/100);this.oInt.style.filter="alpha(opacity="+this.opa+")"
		if (this.opa==1) {
			if (this.multiloop) {
				this.cimg=(this.cimg<this.maximg)?(this.cimg+1):0
				var nstagione=(this.cimg<this.maximg)?(this.cimg+1):0
				this.oInt.style.backgroundImage="url("+this.images[this.cimg].src+")"
				this.opa=99
				this.oInt.style.opacity=(this.opa/100)
				this.oInt.style.filter="alpha(opacity="+this.opa+")"
				this.oExt.style.backgroundImage="url("+this.images[nstagione].src+")"
				this.clock=setTimeout("oObjMng["+this.obIndex+"].run()",this.stopTime)
			} else {
				if (this.cimg<this.maximg) {
					this.cimg++
					this.oInt.style.backgroundImage="url("+this.images[this.cimg].src+")"
					this.opa=99
					this.oInt.style.opacity=(this.opa/100)
					this.oInt.style.filter="alpha(opacity="+this.opa+")"
					this.oExt.style.backgroundImage="url("+this.images[this.cimg].src+")"
					if (this.cimg<this.maximg) {this.clock=setTimeout("oObjMng["+this.obIndex+"].run()",this.stopTime)}
				}
			}
		} else {
			this.clock=setTimeout("oObjMng["+this.obIndex+"].run()",this.runTime)
		}
	}

	this.unload=function unload() {
		clearTimeout(this.clock)
		this.oInt=null
		this.oExt=null
		this.images=null
	}
}

function paginatoreProdotti() {paginatore("paginatore")}

function paginatore(id)  {
	var e=$(id)	
	if (e) {
		var k=Math.ceil(e.offsetHeight/e.parentNode.offsetHeight)
		if (k>1) {
			var nn=$b("div")
			nn.className="navbar"
			nn.id="navbar"
			e.parentNode.parentNode.appendChild(nn)
			for(var i=0;i<k;i++) {
				var a=$b("a")
				a.href="javascript:gpp("+i+")"
				a.innerHTML=(i==0)?"\u25cf":"\u25cb"
				nn.appendChild(a)
			}
		}
	}
}
function gpp(id) {
	var o=$("paginatore")
	o.style.top="-"+o.parentNode.offsetHeight*id+"px"
	var o=$("navbar")
	var v=$t(o,"a")
	for (var i=0;i<v.length;i++) {
		v[i].innerHTML=(id==i)?"\u25cf":"\u25cb"
	}
}

function addCart(id) {
	callAction(new Array("P",addCartDone,"_interno/cart.asp","cmd=add&id="+id,"T"))
}
function addCartDone(m,x,n,f) {
	if (m) {
		var o=$("cart")
		if (o) {o.innerHTML=x}
	}
}
function delProd(id) {
	callAction(new Array("P",cartDone,"_interno/cart.asp","cmd=delp&id="+id,"T"))
}
function addProd(id) {
	callAction(new Array("P",cartDone,"_interno/cart.asp","cmd=add1&id="+id,"T"))
}
function remProd(id) {
	callAction(new Array("P",cartDone,"_interno/cart.asp","cmd=del1&id="+id,"T"))
}
function cartMod() {
	callAction(new Array("P",cartDone,"_interno/cart.asp","cmd=mod","T"))
}
function cartDone(m,x,n,f) {
	if (m) {
		var o=$("carrello")
		if (o) {o.innerHTML=x}
	}
}

function sameAddress() {
	var v=["rif","via","cap","luogo","pr"]
	var o=null
	var d=null
	for(var i=0;i<v.length;i++) {
		d=$("sp_"+v[i])
		o=$(v[i])
		if (d&&o) {	d.value=o.value}
	}
	sendsped()
}
function sendsped(){
	var o
	o=$("sp_pr")
	if (o) {callAction(new Array("P",spedCartDone,"_interno/cart.asp","cmd=sped&spr="+o.value,"T"))}
}

function spedCartDone(m,x,n,f) {
	if (m) {
		var o=$("totalicart")
		if (o) {o.innerHTML=x}
	}
}

function cartConferma() {
	var s=getValues(["rif","via","cap","luogo","pr","tel","mail","mail2","sp_rif","sp_via","sp_cap","sp_luogo","sp_pr"])
	callAction(new Array("P",cartConfermaDone,"_interno/cart.asp","cmd=conf"+s,"X"))
}

function cartConfermaDone(m,x,n,f) {
	if (m) {
		var vx=$t(x.responseXML,"OK")
		if (vx.length==1) {
			for(var i=0;i<vx[0].attributes.length;i++) {
				if (vx[0].attributes[i].name.length>2) {setErr(vx[0].attributes[i].name,vx[0].attributes[i].value)}
			}
		} else {
			var o=$("carrello")
			o.innerHTML=x.responseText	
		}
	}
}

function paga() {
	callAction(new Array("P",pagaDone,"_interno/cart.asp","cmd=pay","T"))
}
function pagaDone(m,x,u,nfo) {
	if (m) {
		var o=$("carrello")
		o.innerHTML=x
		o=$("bancaform")
		if (o) {o.submit()}
	}
}

function getValues(vv) {
	var r=""
	for(var i=0;i<vv.length;i++) {
		var c=getValue(vv[i])
		if (c!="") {r=r+"&"+c}
	}
	return r
}
function getValue(id) {
	var o=$(id)
	if (o) {
		if (o.type=="checkbox") {
			return id+"="+(o.checked?o.value:"")
		} else {
			return id+"="+escape(o.value)	
		}
	} else {
		return ""
	}
}
function setErr(id,msg) {
	var o=$(id) 
	if (o) {o.innerHTML=msg}
	
	o=$(id.substr(2))
	if (o) {
		if (msg!="") {
			sc(o,"alert")	
		} else {
			sc(o,"","alert")
		}
	}
}

var vxc=new Array()
var vxr=false

function callAction(ve) {
	vxc.push(ve)
///	wl("callA")
	if (!vxr) {callX()}
}

function callX() {
	if (vxc.length==0) {return}
	vxr=true
	ve=vxc.pop()
	var isXML=false
	var isIE=false
//	wl("callX")
	var callback=ve[1]
	
	isXML=(window.XMLHttpRequest?true:false)
	isIE=(window.ActiveXObject?true:false)
	if (isIE) {
		try {
			req = new ActiveXObject("Microsoft.XMLHTTP")
			isIE=(req?true:false)
		} catch (e) {
       		isIE = false;
		}
	}
	if (isIE) {isXML=true}
	if (isXML) {
		if (isIE) {
			var Req = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		    var Req = new XMLHttpRequest();
		}
		if (ve[0]=="P") {
			Req.onreadystatechange = mycallback
		    Req.open("POST", ve[2], true)
			Req.setRequestHeader('Accept','jsxfalcosoft')
			Req.setRequestHeader('Content-Type','charset=iso-8859-1')
			Req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			Req.send(ve[3]);
		} else {
			Req.onreadystatechange = mycallback
		    Req.open("GET", ve[2]+"?"+ve[3], true);
			Req.setRequestHeader('Accept','jsxfalcosoft')
			Req.setRequestHeader('Content-Type','charset=iso-8859-1')
			Req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    		Req.send(null);
		}
	} else {
		document.location=ve[2]+"?"+ve[3]
	}
	function mycallback() {
        if (Req.readyState != 4) return;
        if (Req.status == 200) {
			if (ve[4]=="T") {
				callback(true, Req.responseText,ve[2],ve[3])
			} else {
				if (ve[4]=="X") {
					callback(true, Req,ve[2],ve[3])
			   } else {
					callback(true, Req.responseXML,ve[2],ve[3])
			   }
			}
        } else {
			callback(false, Req.status + ": " + Req.statusText,ve[2],ve[3])
		}
		if(vxc.length!=0) {
			callX()
		} else {
			vxr=false
		}
    }
}

