/***** funzione che regola le dimensioni delle pagine interne *****/

function aggiustaDim() 
{	
	if ((largWin<=805) && (largWin)) 
	{
		document.getElementById("wmr_box1").style.width="555px";
		document.getElementById("wmr_outer1").style.width="555px";
		document.getElementById("wmr_inner1").style.width="555px";
		
		/*document.getElementById("testa").style.width="779px";
		document.getElementById("testa1").style.width="779px";
		document.getElementById("corpo").style.width="779px";
		document.getElementById("piedipagina").style.width="779px";
		document.getElementById("filettoPiede").style.width="779px";*/
	}
	/*else if (largWin>=1003) {
		document.getElementById("testa").style.width="1003px";
		document.getElementById("testa1").style.width="1003px";
		document.getElementById("corpo").style.width="1003px";
		document.getElementById("piedipagina").style.width="1003px";
		document.getElementById("filettoPiede").style.width="1003px";
	}*/
	else
	{
		if ((Br=="IE")&&(Os!="mac")) var perc="730px";
		else var perc="730px";
		
		document.getElementById("wmr_box1").style.width=perc;
		document.getElementById("wmr_outer1").style.width=perc;
		document.getElementById("wmr_inner1").style.width=perc;
				
		/*document.getElementById("testa").style.width=perc;
		document.getElementById("testa1").style.width=perc;
		document.getElementById("corpo").style.width=perc;
		document.getElementById("piedipagina").style.width=perc;
		document.getElementById("filettoPiede").style.width=perc;*/
	}
}


/****************************************************************/

/***** funzione per aggiustare le pagine delle categorie *****/

function aggiustaCategorie() 
{
	var boxProdotto= document.getElementsByTagName("div");
	
	for (var i=0;i<boxProdotto.length;i++) 
	{
		if (boxProdotto.item(i).className.indexOf("boxProdotto")>-1) 
		{
			if ((largWin<=805) && (largWin)) boxProdotto.item(i).className="boxProdotto";
			//else boxProdotto.item(i).className="boxProdotto2";
			/*else
			{
				if ((Br=="IE")&&(Os!="mac")) boxProdotto.item(i).className="boxProdotto3";
				else boxProdotto.item(i).className="boxProdotto2";
			}*/
		}
	}
}


/****************************************************************/

/***** funzione per il menu di sinistra nelle pagine interne *****/

function mmenu(mID) 
{
	var menu = document.getElementById(mID);
	var display = menu.style.display;

	menu.style.display = (display == "block") ? "none" : "block";
	
	if (mID.length=="submenu-1".length) 
	{
		var uls = document.getElementsByTagName("ul");
		for (i=0;i<uls.length;i++) 
		{
			if (uls[i].id==mID) uls[i].style.display = "block";
		}
	}

	var nodoUL=document.getElementById(mID).parentNode.parentNode;
	var nodo=nodoUL.childNodes;

	for (var i=0;i<nodo.length;i++) 
	{
		if ((nodo[i].tagName=="LI")&&(nodo[i].hasChildNodes()))  
		{
			for (var j=0;j<nodo[i].childNodes.length;j++) 
			{
				if((nodo[i].childNodes[j].tagName=="UL")&&(nodo[i].childNodes[j].id!=mID)) 
				{
					nodo[i].childNodes[j].style.display="none";
				}
			}
		}
	}

	var menu=new Array("submenu-1","submenu-2","submenu-3");
	for (var i=0;i<menu.length;i++) 
	{
		var myUls=document.getElementById(menu[i]).getElementsByTagName("ul");
		if (nodoUL.id.indexOf(menu[i])==-1)
		{
			for (var j=0;j<myUls.length;j++) 
			{
				 myUls[j].style.display="none";
			}
		}
	}
}

/****************************************************************/

/***** funzione che regola la scelta della taglia nelle pagine della categoria e del prodotto***/

function scegliTaglia(questo) 
{
	mioForm=eval("document."+questo);

	if (mioForm.sizes.type=="select-one") 
	{
        if (mioForm.sizes.selectedIndex==0)
        {
	        alert("You have to choose a size for this product");
	        mioForm.action="javascript:void(0);";
        }
        else 
        	inviaDati(mioForm);
    }
	else if (mioForm.sizes.type=="hidden") 
		inviaDati(mioForm);
}

function inviaDati(mioForm) 
{
	mioForm.action="/interne/cart/index.php";
	mioForm.submit();
}
	
/****************************************************************/

/***** funzione per i dettagli nella pagina del prodotto***/

moreDetails=new Image();
moreDetails.src="/imgs/interne/prodotto/moredetails.gif";

goBack=new Image();
goBack.src="/imgs/interne/prodotto/previousdetails.gif";

moreDetailsOver=new Image();
moreDetailsOver.src="/imgs/interne/prodotto/moredetails_h.gif";

goBackOver=new Image();
goBackOver.src="/imgs/interne/prodotto/previousdetails_h.gif";
	
function mostraDet(param) 
{
	var questoLink=document.getElementById("moreStuff");
	
	if (param=="more") 
	{
		document.getElementById("boxDettagli1").style.display="none";
		document.getElementById("boxDettagli2").style.display="block";
		cambiaImg("imgMoreDet","goBack");
		questoLink.href="javascript:mostraDet('back')";
	}
	else if (param=="back") 
	{
		document.getElementById("boxDettagli2").style.display="none";
		document.getElementById("boxDettagli1").style.display="block";
		cambiaImg("imgMoreDet","moreDetails");
		questoLink.href="javascript:mostraDet('more')";
	}
}

function cambiaSot(param) 
{
	var questoLink=document.getElementById("moreStuff");
	if (param=='over') 
	{
		if (questoLink.href.indexOf("more")>-1) 
			cambiaImg("imgMoreDet","moreDetailsOver");
		else if (questoLink.href.indexOf("back")>-1) 
			cambiaImg("imgMoreDet","goBackOver");	
	}
	else if (param=='out') 
	{
		if (questoLink.href.indexOf("more")>-1) 
			cambiaImg("imgMoreDet","moreDetails");
		else if (questoLink.href.indexOf("back")>-1) 
			cambiaImg("imgMoreDet","goBack");	
	}
}

/****************************************************************/

/***** funzione per le customer pages***/

function cambiaDomanda(param) 
{
	var parag=document.getElementById("corpo-colonna2").getElementsByTagName("p");
	
	for (var i=0;i<parag.length;i++) 
	{
		if ((parag.item(i).className=="parDomanda")&& (parag.item(i).id!=param)) 
			parag.item(i).style.display="none";
		else if (parag.item(i).id==param) 
			parag.item(i).style.display="block";
	}
}

/**** pop up dinamiche ***/

function initleft(valleft,valwidth) 
{
	if(typeof(valleft)== "string") 
	{
	    switch(valleft) 
	    {
	        case "left":    retleft = 0;                                   break;
	        case "center":  retleft = (screen.width - valwidth)/2;         break;
	        case "right":   retleft = screen.width - valwidth;             break;
	        default: alert("STRINGA ERRATA\n(avviso per il debugging)");break;
	    }
	}
	else 
		retleft = valleft
	
	return(retleft)
}

function inittop(valtop,valheight) 
{
	if(typeof(valtop)== "string") 
	{
	    switch(valtop) 
	    {
	        case "top":     rettop = 0;                                   break;
	        case "center":  rettop = (screen.height - valheight)/2;       break;
	        case "bottom":  rettop = screen.height - valheight;           break;
	        default: alert("STRINGA ERRATA\n(avviso per il debugging)");break;
	    }
	}
	else rettop = valtop
	return(rettop)
}

function initpassitot() 
{
	this.passitot = Math.round(Math.max(Math.abs((this.fw-this.iw))/Math.abs(this.passow),Math.abs((this.fh-this.ih))/Math.abs(this.passoh))) 
	
	if(!this.passitot || this.passitot==0) 
		this.passitot = Math.round(Math.max(Math.abs((this.fl-this.il))/Math.abs(this.passow),Math.abs((this.ft-this.it))/Math.abs(this.passoh)))
}

function popplay() 
{
	if(!this.pp.closed)
	{
		this.pp.focus()
		
		if(this.ciclo < this.passitot) 
		{
			opw = (this.passow > 0) ? "<" : ">" ;
			oph = (this.passoh > 0) ? "<" : ">" ;
			
			if(eval("this.iw "+opw+" this.fw")) this.iw += this.passow
			if(eval("this.ih "+oph+" this.fh")) this.ih += this.passoh
			
			this.il += this.passol
			this.it += this.passot
			this.pp.resizeTo(this.iw,this.ih)
			this.pp.moveTo(this.il,this.it)
			this.ciclo++
			eval("setTimeout(this.obj+'.play()',"+this.ms+")")
		}
		else 
		{
			this.ciclo = 0
			eval(this.af)
		}
	}
}

function popslide(fw,fh,fileft,fitop,passow,passoh,ms,af,noslide)
{
	this.fw = (fw == "max") ? screen.width : (fw || this.iw);
	this.fh = (fh == "max") ? screen.height : (fh || this.ih);
	this.fl = (fileft) ? initleft(fileft,this.fw) : initleft(this.inleft,this.fw);
	this.ft = (fitop) ? inittop(fitop,this.fh) : inittop(this.intop,this.fh);
	this.inleft = fileft || this.inleft;
	this.intop = fitop || this.intop;
	this.passow = (this.fw - this.iw >=0) ? (passow || 10) : eval("-"+(passow || 10));
	this.passoh = (this.fh - this.ih >=0) ? (passoh || 10) : eval("-"+(passoh || 10));
	this.passi()
	this.passol = (this.fl - this.il)/this.passitot
	this.passot = (this.ft - this.it)/this.passitot
	this.ms = ms || 10;
	this.af = af || ''
	if(!noslide) this.play()
}

function pop(nome,url,tools,iw,ih,fw,fh,inleft,intop,fileft,fitop,passow,passoh,ms,af,noslide) 
{
	this.obj = nome
	this.iw = (iw == "max") ? screen.width : iw;
	this.ih = (ih == "max") ? screen.height : ih;
	
	this.il = initleft(inleft,this.iw)
	this.it = inittop(intop,this.ih)
	
	tools = tools || '';
	if(document.layers)
	tools = (tools.toLowerCase().indexOf("resizable")==-1) ? 'resizable=yes,'+tools : tools;
	
	this.pp = window.open(url,nome,tools+" width=100,height=100,left="+this.il+",top="+this.it)
	this.pp.resizeTo(this.iw,this.ih)
	this.ciclo = 0
	
	this.inleft = inleft
	this.intop = intop
	this.slide(fw,fh,fileft,fitop,passow,passoh,ms,af,noslide)
}

function popclose() 
{
	this.pp.close()
}


function poplocation(url) 
{
	this.pp.location = url
	this.pp.focus()
}

function addpop(nome,url,tools,iw,ih,fw,fh,inleft,intop,fileft,fitop,passow,passoh,ms,af,noslide) 
{
	eval(nome+" = new pop(nome,url,tools,iw,ih,fw,fh,inleft,intop,fileft,fitop,passow,passoh,ms,af,noslide);")
}

pop.prototype.passi = initpassitot
pop.prototype.slide = popslide
pop.prototype.play = popplay
pop.prototype.close = popclose
pop.prototype.location = poplocation
