//Funzione compatibile con IE e NS
function getElementById(id){return (document.getElementById(id))?document.getElementById(id):document.all[id];}

function showHide(id, show){var el=getElementById(id);if(el){if(null==show) show=el.style.display=='none';el.style.display=(show? '':'none');}}

function changeTab(id){
	if(getElementById(id).className != 'on'){
		var iframe = getElementById("news");
		var tabNews = getElementById("tabNews");
		var tabMsg = getElementById("tabMsg");

		switch (id) {
			case 'tabNews':
				tabNews.className = 'on';
				tabMsg.className = 'off';
				frames['news'].location.href = 'public/rssnews.asp';   //'public/newsToDB.asp?target=home';
				break;
				
			case 'tabMsg':
				tabNews.className = 'off';
				tabMsg.className = 'on';
				frames['news'].location.href = 'private/messaggi.asp';
				break;
		}
	}
}

//************************************************************************************************************************************************
DaysofWeek = new Array()
DaysofWeek[0]="Domenica"
DaysofWeek[1]="Luned&igrave;"
DaysofWeek[2]="Marted&igrave;"
DaysofWeek[3]="Mercoled&igrave;"
DaysofWeek[4]="Gioved&igrave;"
DaysofWeek[5]="Venerd&igrave;"
DaysofWeek[6]="Sabato"

Months = new Array()
Months[0]=" Gen "
Months[1]=" Feb "
Months[2]=" Mar "
Months[3]=" Apr "
Months[4]=" Mag "
Months[5]=" Giu "
Months[6]=" Lug "
Months[7]=" Ago "
Months[8]=" Set "
Months[9]=" Ott "
Months[10]=" Nov "
Months[11]=" Dic "

function upclock(){
	var dte = new Date();
	var hrs = dte.getHours();
	var min = dte.getMinutes();
	var sec = dte.getSeconds();
	var day = DaysofWeek[dte.getDay()]
	var date = dte.getDate()
	var month = Months[dte.getMonth()]
	var year = dte.getFullYear()
	
	if (hrs<=9) hrs="0"+hrs;
	if (min<=9) min="0"+min;
	if (sec<=9) sec="0"+sec;
	
	if(navigator.appName == "Netscape") {
		document.clock.document.write(day+", " +date+month+year+" - "+hrs+":"+min+"."+sec);
		document.clock.document.close();
	}
	
	if (navigator.appVersion.indexOf("MSIE") != -1){
		clock.innerHTML = day+", " +date+month+year+" - "+hrs+":"+min+"."+sec;
	}
}

//************************************************************************************************************************************************

function goTo(url) {
	parent.header.location.replace ('/public/header.asp');
	parent.main.location.href (url);
	parent.blank.location.replace ('/public/blank.htm');
}

function goMain(url) {
	parent.main.location.href (url);
	parent.blank.location.replace ('/public/blank.htm');
}

function isEmpty(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}
	return true;
}

//************************************************************************************************************************************************
// aggiunge la funzione trim alla classe String di sistema
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');}

String.prototype.md5=function(){
	var s=this;
	function Z(n,c){return(n<<c)|(n>>>(32-c))}
	function Y(q,a,b,x,s,t){return X(Z(X(X(a,q),X(x,t)),s),b)}
	function A(a,b,c,d,x,s,t){return Y((b&c)|((~b)&d),a,b,x,s,t)}
	function B(a,b,c,d,x,s,t){return Y((b&d)|(c&(~d)),a,b,x,s,t)}
	function C(a,b,c,d,x,s,t){return Y(b^c^d,a,b,x,s,t)}
	function D(a,b,c,d,x,s,t){return Y(c^(b|(~d)),a,b,x,s,t)}
	function X(x,y){var l=(x&0xFFFF)+(y&0xFFFF),m=(x>>16)+(y>>16)+(l>>16);return(m<<16)|(l&0xFFFF)}
	
	var w=s.length*8,i,hx="0123456789abcdef",L=(((w+64)>>>9)<<4)+15,x=Array(L+15);
	for(i=0;i<x.length;++i)x[i]=0;
	for(i=0;i<w;i+=8)x[i>>5]|=(s.charCodeAt(i/8)&255)<<(i%32);
	x[w>>5]|=0x80<<((w)%32);
	x[L-1]=w;
	
	var a=1732584193,b=-271733879,c=-1732584194,d=271733878;
	for(i=0;i<L;i+=16){
		var oa=a,ob=b,oc=c,od=d;
		a=A(a,b,c,d,x[i],7,-680876936);d=A(d,a,b,c,x[i+1],12,-389564586);c=A(c,d,a,b,x[i+2],17,606105819);b=A(b,c,d,a,x[i+3],22,-1044525330);
		a=A(a,b,c,d,x[i+4],7,-176418897);d=A(d,a,b,c,x[i+5],12,1200080426);c=A(c,d,a,b,x[i+6],17,-1473231341);b=A(b,c,d,a,x[i+7],22,-45705983);
		a=A(a,b,c,d,x[i+8],7,1770035416);d=A(d,a,b,c,x[i+9],12,-1958414417);c=A(c,d,a,b,x[i+10],17,-42063);b=A(b,c,d,a,x[i+11],22,-1990404162);
		a=A(a,b,c,d,x[i+12],7,1804603682);d=A(d,a,b,c,x[i+13],12,-40341101);c=A(c,d,a,b,x[i+14],17,-1502002290);b=A(b,c,d,a,x[i+15],22,1236535329);
		a=B(a,b,c,d,x[i+1],5,-165796510);d=B(d,a,b,c,x[i+6],9,-1069501632);c=B(c,d,a,b,x[i+11],14,643717713);b=B(b,c,d,a,x[i],20,-373897302);
		a=B(a,b,c,d,x[i+5],5,-701558691);d=B(d,a,b,c,x[i+10],9,38016083);c=B(c,d,a,b,x[i+15],14,-660478335);b=B(b,c,d,a,x[i+4],20,-405537848);
		a=B(a,b,c,d,x[i+9],5,568446438);d=B(d,a,b,c,x[i+14],9,-1019803690);c=B(c,d,a,b,x[i+3],14,-187363961);b=B(b,c,d,a,x[i+8],20,1163531501);
		a=B(a,b,c,d,x[i+13],5,-1444681467);d=B(d,a,b,c,x[i+2],9,-51403784);c=B(c,d,a,b,x[i+7],14,1735328473);b=B(b,c,d,a,x[i+12],20,-1926607734);
		a=C(a,b,c,d,x[i+5],4,-378558);d=C(d,a,b,c,x[i+8],11,-2022574463);c=C(c,d,a,b,x[i+11],16,1839030562);b=C(b,c,d,a,x[i+14],23,-35309556);
		a=C(a,b,c,d,x[i+1],4,-1530992060);d=C(d,a,b,c,x[i+4],11,1272893353);c=C(c,d,a,b,x[i+7],16,-155497632);b=C(b,c,d,a,x[i+10],23,-1094730640);
		a=C(a,b,c,d,x[i+13],4,681279174);d=C(d,a,b,c,x[i],11,-358537222);c=C(c,d,a,b,x[i+3],16,-722521979);b=C(b,c,d,a,x[i+6],23,76029189);
		a=C(a,b,c,d,x[i+9],4,-640364487);d=C(d,a,b,c,x[i+12],11,-421815835);c=C(c,d,a,b,x[i+15],16,530742520);b=C(b,c,d,a,x[i+2],23,-995338651);
		a=D(a,b,c,d,x[i],6,-198630844);d=D(d,a,b,c,x[i+7],10,1126891415);c=D(c,d,a,b,x[i+14],15,-1416354905);b=D(b,c,d,a,x[i+5],21,-57434055);
		a=D(a,b,c,d,x[i+12],6,1700485571);d=D(d,a,b,c,x[i+3],10,-1894986606);c=D(c,d,a,b,x[i+10],15,-1051523);b=D(b,c,d,a,x[i+1],21,-2054922799);
		a=D(a,b,c,d,x[i+8],6,1873313359);d=D(d,a,b,c,x[i+15],10,-30611744);c=D(c,d,a,b,x[i+6],15,-1560198380);b=D(b,c,d,a,x[i+13],21,1309151649);
		a=D(a,b,c,d,x[i+4],6,-145523070);d=D(d,a,b,c,x[i+11],10,-1120210379);c=D(c,d,a,b,x[i+2],15,718787259);b=D(b,c,d,a,x[i+9],21,-343485551);
		
		a=X(a,oa);
		b=X(b,ob);
		c=X(c,oc);
		d=X(d,od);
	}
	b=[a,b,c,d];
	s="";
	for(i=0;i<16;i++)s+=hx.charAt((b[i>>2]>>((i%4)*8+4))&0xF)+hx.charAt((b[i>>2]>>((i%4)*8))&0xF);
	return s
}

//************************************************************************************************************************************************
voucher=null;
PrintVoucher=function(id) {
	if (!voucher) {
		voucher=window.open("voucher.asp?id="+id, "", "width=300, height=750 menubar=1, status=0, toolbar=0, scrollbars=0, resizable=0",true);
		if(voucher){voucher.print();}
		else{alert("Impossibile visualizzare il voucher.\nAssicurarsi di non avere il blocco pupup attivo.");}
	} else {
		try {CloseVoucher();}
		catch(e){voucher=null;}
		PrintVoucher(id);
	}
}

this.CloseVoucher=function() {
	if (!voucher) return;
	try{voucher.close();}
	catch(e){}
	voucher=null;
}

receipt=null;
PrintReceipt=function(id) {
	if (!receipt) {
		receipt=window.open("receipt.asp?id="+id, "", "width=300, height=510 menubar=1, status=0, toolbar=0, scrollbars=0, resizable=0",true);
		if(receipt){receipt.print();}
		else{alert("Impossibile visualizzare la ricevuta.\nAssicurarsi di non avere il blocco pupup attivo.");}
	} else {
		try {CloseReceipt();}
		catch(e){receipt=null;}
		PrintReceipt(id);
	}
}

this.CloseReceipt=function() {
	if (!receipt) return;
	try{receipt.close();}
	catch(e){}
	receipt=null;
}


ricarica=null;
PrintRicarica=function(id) {
	if (!ricarica) {
		ricarica=window.open("ricaricaWeb.asp?id="+id, "", "width=300, height=350 menubar=1, status=0, toolbar=0, scrollbars=0, resizable=0",true);
		if(ricarica){ricarica.print();}
		else{alert("Impossibile visualizzare il voucher.\nAssicurarsi di non avere il blocco pupup attivo.");}
	} else {
		try {CloseRicarica();}
		catch(e){ricarica=null;}
		PrintRicarica(id);
	}
}


receipt=null;
PrintReceiptScommessa=function(id) {
	if (!receipt) {
		receipt=window.open("receiptScommessa.asp?ids="+id, "", "width=350, height=510 menubar=1, status=0, toolbar=0, scrollbars=1, resizable=0",true);
		if(receipt){receipt.print();}
		else{alert("Impossibile visualizzare la ricevuta.\nAssicurarsi di non avere il blocco pupup attivo.");}
	} else {
		try {CloseReceipt();}
		catch(e){receipt=null;}
		PrintReceiptScommessa(id);
	}
}

this.CloseRicarica=function() {
	if (!ricarica) return;
	try{ricarica.close();}
	catch(e){}
	ricarica=null;
}

function changestyle(id){
    var TabNewsXX
        for(var i=0;i<4;i++)
        {
	        TabNewsXX = getElementById('LinkNews'+i);            
            if (TabNewsXX.id == id)
            {
                TabNewsXX.className='TabNews_sel';
            }
            else
            {
                TabNewsXX.className='elemento';                
            }
        }
}

//funzione apertura-chiusura menu
function gestioneMenu(show)
{
	
	if (show)
	{
		document.getElementById("showDiv").style.display = 'none';
		document.getElementById("hideDiv").style.display = 'block';
		
		var frameset = top.document.getElementById("bodyFrame");

		frameset.cols = "*, 220";
	}
	else
	{
		document.getElementById("showDiv").style.display = 'block';
		document.getElementById("hideDiv").style.display = 'none';
		
		var frameset = top.document.getElementById("bodyFrame");

		frameset.cols = "*, 0";
	}

	return false;
}
