
function lz(numero, cifre) {
	n = String(numero);
	while (n.length<cifre) { 
		n="0"+n 
	}
	return n;
}

function dateFormat(data, formato) { 
// (c) br1 - 2002 

	var giorni = new Array("Domenica","Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato");
	//var mesi = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
	var mesi = new Array("Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic");

// preparo la data...  verificare di passarla corretta!
	var adesso = new Date(data); 
	var anno = adesso.getFullYear();
	var mese = adesso.getMonth()+1;
	var giorno = adesso.getDate();
	var settim = adesso.getDay()
	var ore = adesso.getHours()
	var minuti = adesso.getMinutes()
	var secondi = adesso.getSeconds()

// preparo la stringa di risposta
	var rVal = '';

	if (formato.length==0) { 
// assenza del secondo parametro
		return String(adesso); 
	} else {

	// inizio loop
		while (formato.length>0) {

	// verifico se c'e' qualche separatore e lo aggiungo
			while (formato.length>0 && String("ymdphnst").indexOf(formato.charAt(0).toLowerCase())<0) {
				rVal += formato.charAt(0);
				formato = formato.substr(1);
			}


	// Separo il gruppo
			if (formato.length>0) {
				ff = formato.charAt(0);
				formato = formato.substr(1);
				while (formato.length>0 && formato.charAt(0).toLowerCase()==ff.charAt(0).toLowerCase()) {
					ff += formato.charAt(0);
					formato = formato.substr(1);
				}

	// espando il formato nella stringa corrispondente
				ff = ff.toLowerCase();	 // operazione preliminare... tutto in minuscolo
				switch (ff) 	{ 					 
					case "yyyy" : 
						rVal += String(anno); 
						break; 					
					case "mmmm" : 
						rVal += mesi[mese-1];
						break; 					 
					case "dd" : 
						rVal += lz(giorno,2); 
						break; 
					case "ddd" : 
						rVal += giorni[settim].substr(0,3);
						break; 					 
					case "hh" : 
						rVal += lz(ore,2); 
						break; 					 
					case "nn" : 
						rVal += lz(minuti,2); 
						break; 					 
					default :  // il numero dei caratteri del formato non e' permesso
						rVal += ff.replace(/./gi,"?");
				} 

			}

		} // fine loop principale

		return rVal;
	}
}



function switchto(name, image){
	document[name].src = image;
}

function carrello(func,ID){
	url="/carrello/carrello.php";
	if(func=="add" || func=="sub"){
		url += "?func="+func+"&ID="+ID;
		location.href=url;
	}
	else if(func=="show") location.href=url;
	else if(func=="indisp") alert("Spiacenti!\nL'articolo non è disponibile");
}

function wishlist(func,ID){
	url="/cataloghi/wishlist.php";
	if(func=="add" || func=="sub"){
		url += "?func="+func+"&ID="+ID;
	}
	location.href=url;
}


function ColorIN(voce){
	eval("voce.style.backgroundColor='#444444';")
}

function ColorOUT(voce){
	eval("voce.style.backgroundColor='';")
}

String.prototype.upper = new Function("return this.trim().accent2Apostroph().toUpperCase()");
String.prototype.accent2Apostroph = new Function("return this.replace(/à$|à(?=\\s)/ig,'a\\'').replace(/è$|è(?=\\s)/ig,'e\\'').replace(/é$|é(?=\\s)/ig,'e\\'').replace(/ì$|ì(?=\\s)/ig,'i\\'').replace(/ò$|ò(?=\\s)/ig,'o\\'').replace(/ù$|ù(?=\\s)/ig,'u\\'').replace(/à/g,'a').replace(/è/g,'e').replace(/é/g,'e').replace(/ì/g,'i').replace(/ò/g,'o').replace(/ù/g,'u');");
String.prototype.trim = new Function("return this.replace(/^\\s+|\\s+$/g,'');");
String.prototype.lower = new Function("return this.trim().toLowerCase();");

function activeJsControl(){
	try{jsControl=document.createElement("<input type='hidden' name='javascriptOk' value='1'>");}
	catch(e){
		jsControl=document.createElement("input");
		jsControl.name='javascriptOk';
		jsControl.type='hidden';
		jsControl.value='1';
	}
	for(i=0; document.getElementsByTagName('form')[i]; i++){
		document.getElementsByTagName('form')[i].appendChild(jsControl);
	}
}

function bgImgCache(){
	try {document.execCommand('BackgroundImageCache', false, true);} 
	catch(e) {}
}
