function get_random() 
{
    var nRnd = Math.round(Math.random()*3);
    return(nRnd);
}


function cambiaColor(nFrame) 
{
	if(nFrame >= 2) 
	{
		document.getElementById('titoloFrame').style.backgroundColor = '#6CD049';
		document.getElementById('sfondo').style.backgroundColor = '#6CD049';
		document.getElementById('sfondoChiaro').style.backgroundColor = '#D1F1C6';
		document.getElementById('foot').style.backgroundColor = '#6CD049';
		document.getElementById('prodotto').style.border = '1px solid #6CD049';
	}
}


function caricaLink(URL) 
{
	if(a != false) 
	{
		if(a.closed == true)
			a = window.open(URL, '', 'width=1024,height=768,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes');
		else
			a.location.href = URL;
	}
	else
		a = window.open(URL, '', 'width=1024,height=768,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes');
	
	a.focus();
}


function init(nFrame, staticUrl) 
{         
	//funzione che carica oggetti e immagini
	loadingImg = new Image();    //immagine del preloading
	
	if(nFrame <= 1)
	{ 
		loadingImg.src = staticUrl + '/img/img_frame/loading_m.jpg';
		
		//preloading delle immagini necessarie allo script
		sx = new Image();                                      //freccia sinistra
		sx.src = staticUrl + '/img/img_frame/left_w_m.gif';
							   
		dx = new Image();                                      //freccia destra
		dx.src = staticUrl + '/img/img_frame/right_w_m.gif';

		vuoto = new Image();                                   //shim
		vuoto.src = staticUrl + '/img/img_frame/shim.gif';
		
		/*fine variabili globali*/
		
		costruisciOggetti(nFrame);
	}
	else if(nFrame >= 2)
	{
		loadingImg.src = staticUrl + '/img/img_frame/loading.jpg';
		
		//preloading delle immagini necessarie allo script
		sx = new Image();                                       //freccia sinistra
		sx.src = staticUrl + '/img/img_frame/left_w.gif';
											   
		dx = new Image();                                       //freccia destra
		dx.src = staticUrl + '/img/img_frame/right_w.gif';

		vuoto = new Image();                                   	//shim
		vuoto.src = staticUrl + '/img/img_frame/shim.gif';

		/*fine variabili globali*/
		
		costruisciOggetti(nFrame);  //costruisco gli oggetti e li insericsco in un array
		document.getElementById('titoloFrame').style.backgroundColor = '#6CD049';
		document.getElementById('sfondo').style.backgroundColor = '#6CD049';
		document.getElementById('sfondoChiaro').style.backgroundColor = '#D1F1C6';
		document.getElementById('foot').style.backgroundColor = '#6CD049';
		document.getElementById('prodotto').style.border = '1px solid #6CD049';
	}
}


function Prodotto(immagine, linkProdotto, testo1, testo2, testo3, testo4)
{
	//oggetto "prodotto" con relative propriet�
	this.immagine = immagine;
	this.linkProdotto = linkProdotto;
	this.nome = testo1;
	this.prezzo = testo2;
	this.taglie = testo3;
	/*this.sconto = testo4;*/
	this.nomeImmagine = false;
}


//metodi degli oggetti
Prodotto.prototype.caricaImg = caricaImg;
Prodotto.prototype.cambiaImg = cambiaImg;
Prodotto.prototype.riscriviLink = riscriviLink;
Prodotto.prototype.freccia = freccia;
Prodotto.prototype.costruisci = costruisci;


function cambiaImg(n) 
{
	//funzione che cambia l'immagine al click sulla freccia
	function swap() 
	{
		document.images['prodotto'].src = dati[n].nomeImmagine.src;
	}
	
	if(dati[n].nomeImmagine == false) 
	{        
		//controllo che la funzione di caricamento abbia gi� creato l'immagine
		dati[n].nomeImmagine = 'img' + n;                 //assegno un nome all'immagine
		dati[n].caricaImg(dati[n].nomeImmagine);          //lancio il metodo che carica le immagini
	}
	
	document.images['prodotto'].src = loadingImg.src;
	dati[n].nomeImmagine.onLoad = swap();
}


function riscriviLink(n) 
{
	//funzione che riscrive il link delle frecce
	if(n == 0)      //se si tratta della prima foto viene riscritto solo il link della freccia dx
		document.getElementById('linkFrecciadx').href = "javascript:cambia(" + (n+1) + ")";
	else if(n == (dati.length - 1))    //se si tratta dell'ultima viene riscritto solo il link della freccia dx
		document.getElementById('linkFrecciasx').href = "javascript:cambia(" + (n-1) + ")";
	else 
	{   
		//in tutti gli altri casi
		document.getElementById('linkFrecciasx').href = "javascript:cambia(" + (n-1) + ")";
		document.getElementById('linkFrecciadx').href = "javascript:cambia(" + (n+1) + ")";
	}
}


function freccia(n) 
{
    //funzione che cambia le frecce e le fa apparire / scomparire
	if(n == 0)
		document.images['frecciasx'].src = vuoto.src;
	else 
	{
		if((document.images['frecciasx'].src.indexOf('shim.gif') >- 1)) 
			document.images['frecciasx'].src = sx.src;
	}
	
	if(n == (dati.length - 1))
		document.images['frecciadx'].src = vuoto.src;
	else  
	{
		if((document.images['frecciadx'].src.indexOf('shim.gif') >- 1)) 
			document.images['frecciadx'].src = dx.src;
	}
}


function caricaImg(nomeImmagine) 
{ 
	//metodo per caricare le immagini della classe Prodotto
	this.nomeImmagine = new Image();                  //creo una nuova immagine
	this.nomeImmagine.src = this.immagine;            //le assegno il percorso
}


function costruisci(n) 
{
	//funzione che scrive l'oggetto all'interno della pagina
	testo1 = dati[n].nome;
	testo2 = dati[n].prezzo;
	
	if(dati[n].taglie == false)  
		testo3 = '&nbsp;';
	else 
		testo3 = dati[n].taglie;
	
	/*testo4 = 'you save ' + dati[n].sconto;*/
	
	linkProdotto = dati[n].linkProdotto;
	
	for(n=1; n<4; n++) 
	{      
		//ciclo per automatizzare il processo di creazione delle scritte
		scritte = "scritte" + n;
		testo = "testo" + n;
		
		if(document.all) 
			eval("document.all[\"" + scritte + "\"].innerHTML = " + testo);
		else if(document.getElementById) 
			eval("document.getElementById(\"" + scritte + "\").innerHTML = " + testo);
	}
	
	document.getElementById('linkImg').href = linkProdotto;
	document.getElementById('linkDet').href = linkProdotto;
	/*document.getElementById('linkImg').href = 'javascript:caricaLink("'+linkProdotto+'")';
	document.getElementById('linkDet').href = 'javascript:caricaLink("'+linkProdotto+'")';*/
}


function carica()
{                                                                    
	//funzione che esegue il caricamento delle immagini
	for(n=0; n<dati.length; n++) 
	{
		dati[n].nomeImmagine = 'img' + n;                          //assegno un nome all'immagine
		dati[n].caricaImg(dati[n].nomeImmagine);                   //lancio il metodo che carica le immagini
	}
}


function cambia(n)
{                     
	//funzione richiamata al click sulla freccia, che chiama tutti i metodi
	dati[n].cambiaImg(n);
	dati[n].riscriviLink(n);
	dati[n].freccia(n);
	dati[n].costruisci = costruisci(n);
}


function go() 
{                 
	// funzione lanciata all'onload che serve per visualizzare correttamente la situazione inizale
	dati[0].cambiaImg(0);
	dati[0].costruisci = costruisci(0);
	
	document.images['frecciadx'].src = dx.src;
	document.getElementById('linkFrecciadx').href = "javascript:cambia(1)";
}



function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) 
{
	var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
	var int_windowTop = (screen.height - a_int_windowHeight) / 2;
	var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
	var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties);		  
	
	if(parseInt(navigator.appVersion) >= 4) 
		obj_window.window.focus();
}

/***************** funzioni che potrebbero essere anche in home *****************/

function cambiaSelect(param)
{
	if(param.indexOf('.html') >- 1) 
		this.location.href = param;
}	

/**** Funzione per controllare che i campi della ricerca per prezzi non siano vuoti *****/

function controlSelect(that)
{
	var procedi = true;
	var sel = document[that].elements[0];
	
	for(c=0;c<sel.options.length;c++)
	{
		if(sel.options[c].selected)
		{
			if(sel.options[c].value == "sel") 
				procedi = false;
		}
	}
	
	for(c=2;c<4;c++)
	{
		inpTx = parseInt(document[that].elements[c].value);
		if(isNaN(inpTx)) 
			procedi = false;
	}
	
	if(procedi)
		document[that].action = "/interne/prices/index.php";
}

/***** fine funzioni che potrebbero essere anche in home *********/


/***** funzione per il menu di sinistra nelle pagine interne *****/

function locatMenu(Url)
{
	if(Url == '') 
		url = String(self.location);
	else 
		url = String(Url);
	name = url.substring(url.lastIndexOf("/"), url.length);
	return name;
}

var mostrato = false;
// controlla se procedere o no a mostrare il menu della pagina. se  true il menu relativo 
// gia' stato mostrato da mostraSel, se false viene mostrato da associaRange
function mostraSel()
{
	var nodo = document.getElementById('menuCont').getElementsByTagName("ul");
	mostra = true;
	nome = locatMenu('');
	
	for(var i=0;i<nodo.length;i++) 
	{
		if(nodo[i].hasChildNodes())  
		{
			jN = nodo[i].childNodes;		
			for(var j=0;j<jN.length;j++) 
			{
				links = jN[j].childNodes;
				for(var l=0;l<links.length;l++)
				{
					if(links[l].tagName == "A")
					{
						if(locatMenu(links[l].href) == nome)
						{
							if(mostra)
							{
								mostra = false;
								mostrato = true;
								evidenzia(jN[j]);
								aggiustaTesto(links[l]);
								nodo[i].style.display = "block";
							}
						}
					}
				}
			}
		}
	}
}

function associaRange(r_Id)
{
	mostra = true;
	var controlla = false;
	var indice = 0;
	
	if(!mostrato)
	{ 
		var nodo = document.getElementById('menuCont').getElementsByTagName("ul");
		
		for(var i=0;i<nodo.length;i++) 
		{
			if(nodo[i].hasChildNodes())
			{
				jN = nodo[i].childNodes;			
				for(var j=0;j<jN.length;j++) 
				{
					links = jN[j].childNodes;	
					for(var l=0;l<links.length;l++)
					{
						if(links[l].tagName == "A")
						{							
							var part = locatMenu(links[l].href); // mi restituisce l'ultima parte dell'href
							var tempHref = part.substring(part.lastIndexOf("/") + 1, part.length);
							
							if(tempHref == r_Id)
							{
								evidenzia(jN[j]);
								aggiustaTesto(links[l]);
								nodo[i].style.display = "block";
							}
						}
					}
				}
			}
		}
	}
}

function evidenzia(lin)
{
	lin.style.fontWeight = "bolder";
	lin.style.backgroundColor = "#0E1339";
	lin.style.display = "block";
	lin.style.width = "98%";
	lin.style.paddingLeft = "3px";
}

function aggiustaTesto(lin)
{
	lin.style.fontSize = "12px";
}

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";
		}
	}
	
	nome = locatMenu("");
	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");
	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 per i tab ***********************/

function assegnaCambio(nomeEl, on, off) 
{
	var elementi = document.getElementById(nomeEl).getElementsByTagName('a');
	var lunAn = elementi.length;
	var j;
	
	for(j=0;j<lunAn;j++) 
	{
		elementi[j].onmouseover=function() 
		{	
			cambiaSfondo(this, on);
			return false;
		}
		elementi[j].onmouseout = function() 
		{	
			cambiaSfondo(this, off);
			return false;
		}
	}
}

function cambiaSfondo(nome, classe)
{
	nome.previousSibling.className = classe; 
}

/****************************************************************/
/*************** funzione per il cambiamento di nome ************/


function sintetizza(stilista, azione) 
{
	var tit1 = document.getElementById('titH1');
	var testo_ti1;
	
	if(azione == 'prod') 
	{
		var newString = stilista + ' >';
		var re = new RegExp(stilista, 'gi');
	
		tit1.firstChild.nodeValue = tit1.firstChild.nodeValue.replace(re, newString);
	}
	
	var n = 0;
	var tit2 = document.getElementsByTagName('h2');
	var l = tit2.length;
	var a;
	var testo;
	var re = new RegExp(stilista, 'gi');

	for(n=0;n<l;n++) 	//scorro gli h2
	{ 
		if(tit2.item(n).className == 'secButtons')	//scorro gli h2 che hanno classe secbuttons
		{ 
			a = tit2.item(n).getElementsByTagName('a').item(0);
		
			if(a) 	//questo  il caso sia un link
			{ 
				testo = a.firstChild.nodeValue;
				a.firstChild.nodeValue = testo.replace(re,'');
			}
			else 
			{
				//questo  il caso in cui non sia un link, ma l'elemento evidenziato
				testo = document.getElementById('evidenza').firstChild.nodeValue;
				document.getElementById('evidenza').firstChild.nodeValue = testo.replace(re, '');
			}
		}
	}
}

/****************************************************************/

/***** 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 = "https://www.styledrops.com/interne/cart/index.php";
	mioForm.submit();
}

/* Funzione che cambia l'action registazione utente in step2.php */

function changeAction() 
{
	document.getElementById("makeReg").value = "true";
	document.checkon.action = "step3.php";
}

/***livello con il freeshipping **/


/***** funzione per la gestione dei cookie *****/
//la scrittura del cookie in home gestita nel js della home

function scriviCookie(name, value) 
{
	var argv = scriviCookie.arguments;
	var argc = scriviCookie.arguments.length;
	var path = (argc > 2) ? argv[2] : null;
	var domain = (argc > 3) ? argv[3] : null;
	var expires = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape(value)
	+ ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))
	+ ((path == null) ? "" : ("; path=" + path))
	+ ((domain == null) ? "" : ("; domain=" + domain()))
	+ ((secure == true) ? "; secure" :"");
}

function leggiValCookie(offset) 
{
	var endstr = document.cookie.indexOf(";", offset);
	if(endstr == -1)
		endstr = document.cookie.length;
	
	return unescape(document.cookie.substring(offset, endstr));
}

function leggiCookie(name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen) 
	{
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg)
			return leggiValCookie(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0) 
			break;
	}
	return null;
}

function cancellaCookie(name) 
{
	var exp = new Date();
	exp.setTime(exp.getTime()-1);
	var cval = leggiCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

/****************************************************************/

function avviso(idPopUp) 
{
	cokieId = "divPopUp" + idPopUp;
	
	if(leggiCookie(cokieId) == null)
	{
		document.getElementById('iframePopUp').src = "/interne/categorie/popUpOutlet.php?id=" + idPopUp;
	}
}

function avvisoIndex()
{
	if (leggiCookie("divPopUpToll") == null) 
	{
		setTimeout("document.getElementById('divPopUpToll').style.display='block'", 2000);
		scriviCookie("divPopUpToll", "true");
		setTimeout("chiudiToll()", 15000);
  	}
}

function avvisoIndex1()
{
	if (leggiCookie("divPopUpToll") == null) 
	{
		setTimeout("document.getElementById('divPopUpToll').style.display = 'block'", 2000);
		scriviCookie("divPopUpToll", "true");
  	}
}

function chiudi() 
{
	document.getElementById('iframePopUp').style.display = 'none';
	document.getElementById('divPopUp').style.display = 'none';
}

function chiudiToll() 
{
	document.getElementById('iframePopUp').style.display = 'none';
	document.getElementById('divPopUpToll').style.display = 'none';
}

function getScrollXY() 
{
	var scrOfX = 0, scrOfY = 0;
	if (typeof(window.pageYOffset) == 'number') 
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} 
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) 
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} 
	else if (document.documentElement &&( document.documentElement.scrollLeft || document.documentElement.scrollTop)) 
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	
	return [ scrOfX, scrOfY ];
}

function sposta() 
{
	a = new String(getScrollXY());
	coords = a.split(',');
	document.getElementById('divPopUp').style.top = coords[1]+'px';
}

/**********************************************************************************/

// funzione per la scelta della option della select

function selezionaVoce(select, valore) 
{
	/* parametri di ingresso: nome select, valore option azione: seleziona l'option della select con il valore indicato */
	
	var opt = eval("document.getElementById('" + select + "').getElementsByTagName('option')");
	var l = opt.length;
	
	for(var n=0;n<l;n++) 
	{
		if(opt.item(n).value == valore) 
		{
			opt.item(n).selected = 'selected';
		}
	}
}


function redirectLang(value)
{
	cancellaCookie('lang');
	scriviCookie('lang', value);
	
	document.getElementById('lang').value = value;
}


function redirectChange(value)
{	
	cancellaCookie('change');
	scriviCookie('change', value);
	
	document.frmChange.change.value = value;
	document.frmChange.submit();
}

function redirectContinent(value)
{	
	cancellaCookie('continent');
	scriviCookie('continent', value);
	
	document.getElementById('continent').value = value;
}


/****************************************************************/

/***** immagine che scende *****/

lockMove3Rid = false;

function muoviRidotto3(livello, partenza, arrivo, act, vel)
{
	raggiungiRid2 = arrivo;
	posAttualeRid2 = partenza;
	var inviaDati = "vaiRidotto2(\""+livello+"\",\""+act+"\","+vel+")";
	qv = setInterval(inviaDati, 4);
}

function vaiRidotto2(livello, act, vel) 
{
	if((lockMove3Rid==false) && (posAttualeRid2<raggiungiRid2))
	{
		lockMove3Rid = true;
	 	posAttualeRid2 += vel;
		eval("document.getElementById(livello).style."+act+"='"+posAttualeRid2+"px';");
		lockMove3Rid = false;
	}
	else 
	{
		clearInterval(qv);
		
		if(act == "left") 
		{
			scriviCookie("popupInterne", "true");
			document.getElementById('frameArchive').style.visibility = 'hidden';
		}
	}
}

function popupArchive() 
{
	muoviRidotto3('frameArchive', -300, 300, "top", 15);
}

function viaBici() 
{
	//document.getElementById('frameArchive').style.visibility='hidden';
	//muoviRidotto3('frameArchive', 300, -300, "top", 15);
	var arrivo = -370;
	muoviRidotto3('frameArchive', 316, arrivo, "left", 8);

}


