risoluzioni = screen.width+"x"+screen.height;
document.cookie= "schermo" + "=" + escape(risoluzioni);
var colore_selezionata = null;

function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = document.getElementById(element);
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}
/* ========================  */
Object.extend = function(destination, source) {
	for (property in source) {
		destination[property] = source[property];
	}
	return destination;
};
/* ======================== */
function cBrowser(){
	/*  ENGINE  */
	var catchBrowser = navigator.appName;
	var browser = "";
	if(/Internet Explorer/.test(catchBrowser))
		browser = "ie";
	else if((/Opera/.test(catchBrowser)))
		browser = "opera";
	else if((/Netscape/.test(catchBrowser)))
		browser = "firefox";

	this.name = browser;

	/* VERSIONE */
	this.versione = navigator.appVersion;
}
var nav = new cBrowser();
/* ======================= */
// Metodi statici
var element = {
	show: function(id, value){ 
		obj = $(id);
		obj.style.display = "";
		obj.style.MozOpacity=1;
		obj.style.filter="alpha(opacity=100)";
		obj.style.opacity = 1;
	},
	hide: function(id, value){	
		obj = $(id);
		obj.style.display = "none"; 
		obj.style.MozOpacity=0;
		obj.style.filter="alpha(opacity=0)";
		obj.style.opacity = 0;
	},
	setAlpha: function(id, value){	
		obj = $(id);
		alpha = value/100;
		obj.style.MozOpacity=alpha;
		obj.style.opacity = alpha;
		obj.style.filter="alpha(opacity="+value+")";
	},
	setClass: function(id, value){	
		$(id).className  = value;
	},
	setTop: function(id, value){
		$(id).style.top = value+"px";
	},
	setLeft: function(id, value){
		$(id).style.left = value+"px";
	},
	setRight: function(id, value){
		$(id).style.right = value+"px";
	},
	setHeight: function(id, value){
		$(id).style.height = value+"px";
	},
	setWidth: function(id, value){
		$(id).style.width = value+"px";
	},
	getVisible: function(id){
		obj = $(id);
		var prendeVis = obj.style.display;
		if(prendeVis=="none") return false;
		else {
			if(nav.name == 'ie'){
				if(/alpha/.test(obj.style.filter) && !(/opacity=100/.test(obj.style.filter))) return obj.style.filter;
				else return true;
			} else {
				if(obj.style.opacity<1 && obj.style.opacity!="") return obj.style.opacity;
				else return true;
			}
		}
	},
	getTop: function(id){
		vl = $(id).style.top.length-2;
		ay = tElem.style.top.substr(0,vl);
		return Number(ay);
	},
	getLeft: function(id){
		vl = $(id).style.left.length-2;
		ax = tElem.style.left.substr(0,vl);
		return Number(ax);
	},
	getRight: function(id){
		vl = $(id).style.left.length-2;
		ax = tElem.style.right.substr(0,vl);
		return Number(ax);
	},
	getHeight: function(id){
		vl = $(id).style.height.length-2;
		ah = tElem.style.height.substr(0,vl);
		return Number(ah);
	},
	getWidth: function(id){
		vl = $(id).style.width.length-2;
		wh = tElem.style.width.substr(0,vl);
		return Number(wh);
	}	
}
/* ========================  */
// Metodi Effetti
Object.extend(element, {
	fadeIn: function(id, value){
		tElem = $(id);
		if(tElem.style.display == "none") tElem.style.display = "";
		if(tElem.style.visibility == "hidden") tElem.style.visibility = "";
		if(!value || value == undefined) value=0;
		if(value < 100){
			value+=10;
			alpha = value/100;
			tElem.style.MozOpacity=alpha;
			tElem.style.filter="alpha(opacity="+value+")";
			tElem.style.opacity = alpha;
			setTimeout("element.fadeIn('"+id+"',"+value+")",1);
		}
	},
	fadeOut: function(id, value){
		tElem = $(id);
		if(value == undefined) value=100;
		if(value > 0){
			value-=10;
			alpha = value/100;
			tElem.style.MozOpacity=alpha;
			tElem.style.opacity = alpha;
			tElem.style.filter="alpha(opacity="+value+")";
			setTimeout("element.fadeOut('"+id+"',"+value+")",1);
		}
	},	
	goTo: function(id, xf, yf, vel, fade, xi, yi, xt, yt){
		tElem = $(id);
		if(!vel || vel == undefined) vel=10;
		if(fade){			
			if(xt == undefined) xt = xi = element.getLeft(id);
			if(yt == undefined) yt = yi = element.getTop(id);
			if(xi < xf) { if(xt<xf) xt+=vel; else xt=xf; } else { if(xt>xf) xt-=vel; else xt=xf; }
			if(yi < yf) { if(yt<yf) yt+=vel; else yt=yf; } else { if(yt>yf) yt-=vel; else yt=yf; }
			posX = xt+"px";
			posY = yt+"px";
			tElem.style.left=posX;
			tElem.style.top=posY;
			
			if((xt<xf && xi<xf)||(xt>xf && xi>xf)||(yt<yf && yi<yf)||(yt>yf && yi>yf)){
				setTimeout("element.goTo('"+id+"', "+xf+", "+yf+", "+vel+", "+fade+", "+xi+", "+yi+", "+xt+", "+yt+")",1);
			}
		} else {
			element.setTop(id,yf);
			element.setLeft(id,xf);
		}
	},
	expandV: function(id, list, hm, ht){
		tElem = $(id);
		ht = element.getHeight(id);
		if(hm>ht){
			prendeEf[list] = false;
			ht+=10;
			element.setHeight(id,ht);
			setTimeout("element.expandV('"+id+"','"+list+"','"+hm+"','"+ht+"')",1);
		} else {
			prendeEf[list] = true;
			element.setHeight(id,hm);
		}
	},
	expandH: function(id, list, wm, wt){
		tElem = $(id);
		wt = element.getWidth(id);
		if(nav.name != "firefox") vel = 20;
		else vel = 10;
		if(wm>wt){
			prendeEf[list] = false;
			wt+=vel;
			element.setWidth(id,wt);
			setTimeout("element.expandH('"+id+"','"+list+"','"+wm+"','"+wt+"')",1);
		} else {
			prendeEf[list] = true;
			element.setWidth(id,wm);
		}
	},
	contractH: function(id, list, wm, wt){
		tElem = $(id);
		wt = element.getWidth(id);
		vel = 10;
		if(wm<wt){
			prendeEf[list] = false;
			wt-=vel;
			if(wt<0) wt=0;
			element.setWidth(id,wt);
			setTimeout("element.contractH('"+id+"','"+list+"','"+wm+"','"+wt+"')",3);
			//alert("element.contractH('"+id+"','"+list+"','"+wm+"','"+wt+"')");
		} else {
			prendeEf[list] = true;
		}
	},
	contractV: function(id, hm, ht){
		tElem = $(id);
		ht = element.getHeight(id);
		if(hm<ht){
			ht-=10;
			if(ht<0) ht=0;
			element.setHeight(id,ht);
			setTimeout("element.contractV('"+id+"','"+hm+"','"+ht+"')",3);
			//alert("element.contractV('"+id+"','"+hm+"','"+ht+"')");
		}
	}
});
/* ========================  */
function estrarreScript(testo){
    // inizia
    var ini = 0;
	
    while (ini!=-1){
		
        // cerca per una tag di script
        ini = testo.indexOf('<script', ini);
        // si trova
			
        if (ini >=0){
            ini = testo.indexOf('>', ini) + 1;
            // cerca il fine dello script
            var fine = testo.indexOf('</script>', ini);
            codice = testo.substring(ini,fine);
            eval(codice);
        }
    }
}
function iniziaAjax(file, div, msg, opz){
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      	}
   		catch (e){
      		try{
        		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        	}
      		catch (e){
				alert("Il suo navigatore non supporta AJAX!");
				return false;
        	}
      	}
    }
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			$(div).innerHTML=xmlHttp.responseText;
			estrarreScript(xmlHttp.responseText);				
		}else{
			if($(div)) $(div).innerHTML=msg; 
		}
	}
	xmlHttp.open("GET",file,true);
	xmlHttp.send(null);
}

/*
// INVIA RICHIESTA(SERVIZIO CLIENTI)
function invia_richiesta()
{
	var form = document.formserv_clienti;
	for(i=0;i<form.length;i++){
		if(form[i].type=="text" || form[i].type=="textarea"){
			if(form[i].value == ""){
				alert("Tutti i campi sono obbligatori");
				form[i].focus();
				return false;
			}
		} 
	}
	if(form.email.value!=form.conf_email.value)
	{
		alert("La email di conferma non corrisponde alla email inserita");
		form.email.focus();
		form.email.select();
		return false;
	}
	form.action = "/servizio_clienti/invia";
	form.method = "POST";
	form.submit();	
}
// CONCLUDI ORDINE
function concludi(){
	var form = document.formindirizzo;
	
	for(i=0;i<form.length;i++){
		if(form[i].type=="text"){
			if(form[i].value == "" && form[i].name!="fiscale")
			{
				alert("Tutti i campi sono obbligatori");
				form[i].focus();
				return false;
			}
		}		
	}
	form.action = "/carrello/concludi/ordine_inviato";
	form.method = "POST";
	form.submit();
}
// LOGIN
function falogin(){
	if(document.formlogin.user.value==""){
		alert("Il campo user è obbligatorio");
		document.formlogin.user.focus();
		return false;
	}	
	if(document.formlogin.password.value==""){
		alert("Il campo password è obbligatorio");
		document.formlogin.password.focus();
		return false;
	}	
	document.formlogin.method = "POST";
	document.formlogin.submit();
}
// REGISTRATI
function registrati()
{
	var form = document.cad_utenti;
	
	for(i=0;i<form.length;i++){
		if(form[i].type=="text" || form[i].type=="password"){
			if(form[i].value == ""){
				alert("Tutti i campi con asterisco sono obbligatori");
				form[i].focus();
				return false;
			}
		}
		if(form[i].type=="select-one"){
			if(form[i].value == "-"){
				alert("Tutti i campi con asterisco sono obbligatori");
				form[i].focus();
				return false;
			}
		}
	}
	if(form.dati.checked==false) {
		alert("E' necessario autorizzare il trattamento dei dati per continuare");
		form.dati.focus();
		return false;
	}	
	form.method = "POST";
	form.submit();	
}
*/

// CONTROLLO QUANTITA
function quantita(ogg,max){
	if(ogg.value<max && ogg.value!=""){
		ogg.value=max;
	}
}
function chiudiTooltip(){
	$("fstooltip_janela").style.display='none';
}
// valore carrello
function calcola(id,qt,chiave){
	//alert(id+" - "+qt);
	iniziaAjax("/include/calcolo.php?id="+id+"&qt="+qt+"&chiave="+chiave, "totale_articoli", "loading","");
}

// foto
// Array per mettere tutti l'immagini
var tuttiImg = new Array;
// pre caricamento dell'immagini
function preCarica(img,atuale){
	nuova_img = new Image();
	nuova_img.onload=function(){
		var totale = img.length;
		prossima = atuale+1;
		if(prossima<totale) preCarica(img,prossima);
	}
	nuova_img.src = img[atuale];
}
function preCaricaImg(){
	// Aqui montaremos o array com todos endereços validos das imagens
	var tuttiLink = document.getElementsByTagName("a");
	var cl=0;
	for (var i=0; i<tuttiLink.length; i++){ 
		var ogni_link = tuttiLink[i];
		var atributo_rel = String(ogni_link.getAttribute('rel'));
		if (ogni_link.getAttribute('href') && (atributo_rel.toLowerCase().match('mudafoto'))){ 
			tuttiImg.push(ogni_link.getAttribute('href'));
			cl++;
		}
	}
	preCarica(tuttiImg,0);
}
function caricaCoord(colore,prodotto){
	iniziaAjax("/include/carica_cons.php?id_col="+colore+"&id_prod="+prodotto, "scheda_coordinati", "loading","");
}
// Per prendere l'eventi dell'albero DOM  
function addEvent(objeto, TipoEvento, funcao){
	if(objeto.addEventListener){ // tutti navigatore  tranne IE
		objeto.addEventListener(TipoEvento, funcao, false);
		return true;
	} else if (objeto.attachEvent){ // IE
		var r = objeto.attachEvent('on'+TipoEvento, funcao);
		return r;
	} else {
		return false;
	}
}
function cambiaColore(id,da){
	switch (da){
		case 0:
			 $(id).style.background = "#93ABD9";
			 break;
		case 1:
			 $(id).style.background = "#A6BADF";
		 	break;
		case 2:
			 $(id).style.background = "#B0C2E3";
		 	break;
		case 3:
			 $(id).style.background = "#C0CEE9";
		 	break;
		case 4:
			 $(id).style.background = "#CBD7ED";
		 	break;
		case 5:
			 $(id).style.background = "#D9E1F2";
		 	break;
		case 6:
			 $(id).style.background = "#E8EDF7";
		 	break;
		case 7:
			 $(id).style.background = "#F2F5FB";
		 	break;
	}
	da++;
	setTimeout("cambiaColore('"+id+"', "+da+")",10);
}

/*
function aggiungiCarr()
{
	var form = document.carrello;
	var tot = form.length;
	var ok = false;
	for(i=0;i<tot;i++)
	{
		if(form[i].type == "text")
		{
			if(form[i].value != "") ok = true;
		}		
	}
	form.method = "POST";
	form.action = "/carrello";
	if(ok==true) 
		form.submit();
	else 
		alert("Attenzione: per aggiungere un prodotto al carrello devi inserire una quantità.");
}
*/

// quando la pagina é stata caricata, pre carica l'immagine nascosti e anche mette i link per cambiare le foto
function comincia(){
	preCaricaImg();
	var tuttiLink = document.getElementsByTagName("a");
	for (var i=0; i<tuttiLink.length; i++){ 
		var ogni_link = tuttiLink[i];
		var atributo_rel = String(ogni_link.getAttribute('rel'));
		var opz = atributo_rel.split(",");
		if (ogni_link.getAttribute('href') && (opz[0].toLowerCase().match('mudafoto'))){ 
			ogni_link.onclick = function () {
				var opz = String(this.getAttribute('rel'));
				opz = opz.split(",");
				caricaCoord(opz[2],opz[1]);
				element.fadeOut("immagine_grande");
				$("immagine_grande").onload=function(){
					element.fadeIn("immagine_grande");
					if($(colore_selezionata)) $(colore_selezionata).style.background="#FFF";
					var ultimo = this.src.split("/");
					var idTR = "colore_"+ultimo[ultimo.length-1]; 
					idTR = idTR.substring(0,idTR.length-4);
					colore_selezionata = idTR;
					cambiaColore(idTR,0);
					
				}
				$("immagine_grande").src=this.getAttribute('href');
				return false; 
			} 
		}
	}		
}
addEvent(window,"load", comincia);

// disabilita tasto destro

function nrcIE(){
if (document.all){return false;}}
function nrcNS(e){
if(document.layers||(document.getElementById&&!document.all)){ 
if (e.which==2||e.which==3){
return false;}}} 
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=nrcNS;
}else{document.onmouseup=nrcNS;document.oncontextmenu=nrcIE;}
document.oncontextmenu=new Function("return false");

