

function elementsToString( array ) {
	var string = "";

	for( var i = 0; i < array.length; i++ ) {
		string += "\"" + array[i].firstChild.nodeValue.toString().trim() + "\", "
	}

	return string.substring( 0, string.length - 2 );
}



var myRequest = null;
//var color = new Array();
function CreateXmlHttpReq2(handler) {
	var XHR = null,
	browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
		XHR = new XMLHttpRequest();
	else 
		if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
			if(browserUtente.indexOf("MSIE 5") < 0)
				XHR = new ActiveXObject("Msxml2.XMLHTTP");
			else
				XHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
	return XHR;
}

function getXMLHttp()
  	{
   		
   		var xmlhttp = null;
   		
   		if (window.ActiveXObject)
   		{
     		
     		if (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1)
     		{
       			
       			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     		
     		}
     		else
     		{
       			
       			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       			
       		}
   		}
   		else
   		{
    		
    		if (window.XMLHttpRequest)
    		{
      			
      			xmlhttp = new XMLHttpRequest();
      			xmlhttp.overrideMimeType("text/xml");
    		}
   		}
   		if (!xmlhttp && typeof(XMLHttpRequest) != 'undefined')
   		{
     		xmlhttp = new XMLHttpRequest()
   		}
   		
   		
   		return xmlhttp
  	}

function searchProductAJ(){
    if (myRequest.readyState == 4 && myRequest.status == 200) {
    	if(myRequest.responseXML){
    		var xmlProd = myRequest.responseXML;
        	var ctProd = document.getElementById("ctProd");
        	//var testoProd = "<li>"+xmlProd.getElementsByTagName("prod")[0].getElementsByTagName("li").item(0).firstChild.nodeValue+"</li>";
        	ctProd.innerHTML = testoProd(xmlProd);

			if( ctProd.innerHTML.indexOf( "No product results from the selected criteria" ) == -1 ) {
				//ctProd.innerHTML += "<div style='margin: 10px 0px 0px 0px; z-index: 10; color: white; font: normal normal 70% sans-serif; text-align: center'>Orders placed after Friday, December 21st or December 28th at 12:00 noon EST will ship on the following Wednesday.</div>";
			}

        	var pgProd = document.getElementById("pageNav");
        	pgProd.innerHTML = testoNav(xmlProd);
			
			// Put the cloned menu on the top
            createPageNavTop();
            
    	}else{
    		var xmlProd = myRequest.responseText;
        var ctProd = document.getElementById("ctProd");
        ctProd.innerHTML = xmlProd;
      }
    }
}

function orderWait(){
    if (myRequest.readyState == 4 && myRequest.status == 200) {
    		var xmlProd = myRequest.responseText;
        var ctProd = document.getElementById("bk2Repl");		
        ctProd.innerHTML = xmlProd;
		document.body.style.cursor='wait';
    }
}

function customerWait(){
    if (myRequest.readyState == 4 && myRequest.status == 200) {
    		var page = myRequest.responseText;
        var ctCustomerService = document.getElementById("ctCustomerService");
        ctCustomerService.innerHTML = page;
    }
}

function resProductAJ(){
    if (myRequest.readyState == 4 && myRequest.status == 200) {
    	if(myRequest.responseXML){
    		var xmlProd = myRequest.responseXML;
        	var ctProd = document.getElementById("ctProd");
        	ctProd.innerHTML = testoProd(xmlProd);

			if( ctProd.innerHTML.indexOf( "No product results from the selected criteria" ) == -1 ) {
				//ctProd.innerHTML += "<div style='margin: 10px 0px 0px 0px; z-index: 10; color: white; font: normal normal 70% sans-serif; text-align: center'>Orders placed after Friday, December 21st or December 28th at 12:00 noon EST will ship on the following Wednesday.</div>";
			}

        	var pgProd = document.getElementById("pageNav");
        	pgProd.innerHTML = testoNav(xmlProd);
        	
        	// Put the cloned menu on the top
            createPageNavTop();
        	
        	
    	}else{
    		var xmlProd = myRequest.responseText;
        var ctProd = document.getElementById("ctProd");
        ctProd.innerHTML = xmlProd;
      }
    }
}


function createPageNavTop()
{
    // exact DOM node copy of result navigation bar
    var pageNavTop = $('pageNav').clone();
    
    // Updating the 'id' DOM property 
    pageNavTop.setAttribute('id','pageNavTop');
    
    
    // Updating entire top navigation bar
    // trying to delete old node 
    try
    {
        $('bk2').removeChild($('pageNavTop'));
    }
    catch (NullPageNavTopElementException)
    {}
    
    // appending just created node to the container 'div' DOM node
    $('bk2').appendChild(pageNavTop);
      
   
}

function testoProd(xmlProd){
	var testo = "";
	var arrZoomProd;
	try{
		var arrProd = xmlProd.getElementsByTagName("prod")[0].getElementsByTagName("img");
		var arrLink = xmlProd.getElementsByTagName("prod")[0].getElementsByTagName("link");
		arrZoomProd = xmlProd.getElementsByTagName("prod")[0].getElementsByTagName("zoomImg");
		var arrProdDescription = xmlProd.getElementsByTagName("prod")[0].getElementsByTagName("productDescription");
		var arrProdPrice = xmlProd.getElementsByTagName("prod")[0].getElementsByTagName("productPrice");
		var description = "";
		var price = "";

		for(var i=0; i<arrProd.length; i++){

			description = arrProdDescription[i].firstChild.nodeValue.toString().trim().replace( /\"/ig, "" ).replace( /\'/ig, "\\\'" );
			price = arrProdPrice[i].firstChild.nodeValue.toString().trim().replace( /\"/ig, "" ).replace( /\'/ig, "\\\'" );

			testo = testo+"<div id='div_img_"+i+"'><a onmouseover=\"";

				if( description != "no_description" ) {
					testo += "Tip('" + description + "<br/>" + price + "', BGCOLOR, '#FFFFFF', FONTCOLOR, '#383836', BORDERCOLOR, '#FFFFFF', WIDTH, '20', FADEIN, 200, FADEOUT, 200); ";

				}

				if( arrZoomProd[i].firstChild.nodeValue.toString().trim() != "no_image" ) {
					testo += "MM_swapImage("+i+",'','"+arrZoomProd[i].firstChild.nodeValue.toString().trim()+"',1);\" onMouseOut=\"MM_swapImgRestore( "+i+", '"+arrProd[i].firstChild.nodeValue.toString().trim()+"' );";
				}

			testo += "\" href='/bulgari/us/product/product.jsp?prod="+arrLink[i].firstChild.nodeValue.toString().trim()+"'>";
			testo += "<img name='Image"+i+"' id="+i+" border='0' src='"+arrProd[i].firstChild.nodeValue+"' class='img_"+i+"' ></img>";
			testo += "</a></div>";

		}
	}catch(e){
		testo = "<span class='A11BFF'>"+xmlProd.getElementsByTagName("empty")[0].firstChild.nodeValue+"</span>";
	}

	return testo;
}


function testoNav(xmlProd){
	try{
		if(xmlProd.getElementsByTagName("colors")[0].firstChild != null){
			if((window.location.hash.split("scProd=")[1]).split("&")[0]!=""){
				writeColor(xmlProd.getElementsByTagName("colors")[0].getElementsByTagName("color"),xmlProd.getElementsByTagName("pColor")[0].firstChild.nodeValue);
			}
		}else{
			document.getElementById("colorPalette").innerHTML = "";
			document.getElementById("colorMenu").style.display = "none";
		}
	 }catch(e){
		document.getElementById("colorPalette").innerHTML = "";
		document.getElementById("colorMenu").style.display = "none";
	}
	var testo = "<div id='numPage'><span class='A9BFF'>page ";
	try{
		var current = xmlProd.getElementsByTagName("pageNav")[0].getElementsByTagName("current")[0].firstChild.nodeValue;
		var last = xmlProd.getElementsByTagName("pageNav")[0].getElementsByTagName("last")[0].firstChild.nodeValue;
		if(last==0){
			testo = testo+last+"</span></div>";
		}else{
			testo = testo+current+" of "+last+"</span></div>";
		}
		var partial = xmlProd.getElementsByTagName("pageNav")[0].getElementsByTagName("partial")[0].firstChild.nodeValue;
		if(xmlProd.getElementsByTagName("pageNav")[0].getElementsByTagName("initial")[0].firstChild.nodeValue!="null"){
			testo = testo+"<div id='imgFsx'><a href='javascript:;' onClick='prev6("+partial+", "+last+", "+current+")'><img src='/bulgari/common/images/ffsx.gif' class='imgFsx'/></a></div>";
		}else{
			testo = testo+"<div id='imgFsx'> </div>";
			//testo2 = testo2+"<div id='imgFsxTop'> </div>";
		}
		var arrNav = xmlProd.getElementsByTagName("pageNav")[0].getElementsByTagName("a");
		var dime = arrNav.length;
		testo = testo+"<div id='nuberPg'>"
		//testo2 = testo2+"<div id='nuberPgTop'>"
		for(var i=0; i<dime-1; i++){
			if((i+1)==(current-((partial-1)*6))){
				testo = testo+"<div id='cenNum'><a href='javascript:;' class='A9BFF' onClick='scrollPage(\"&page="+arrNav[i].firstChild.nodeValue+"\")'><u>"+arrNav[i].firstChild.nodeValue+"</u></a></div><div id='meno'>-</div>";
				//testo2 = testo2+"<div id='cenNum'><a href='javascript:;' class='A9BFF' onClick='scrollPage(\"&page="+arrNav[i].firstChild.nodeValue+"\")'><u>"+arrNav[i].firstChild.nodeValue+"</u></a></div><div id='meno'>-</div>";
			}else{
				testo = testo+"<div id='cenNum'><a href='javascript:;' class='A9RFF' onClick='scrollPage(\"&page="+arrNav[i].firstChild.nodeValue+"\")'>"+arrNav[i].firstChild.nodeValue+"</a></div><div id='meno'>-</div>";
				//testo2 = testo2+"<div id='cenNum'><a href='javascript:;' class='A9RFF' onClick='scrollPage(\"&page="+arrNav[i].firstChild.nodeValue+"\")'>"+arrNav[i].firstChild.nodeValue+"</a></div><div id='meno'>-</div>";
			}
		}
		if((current-((partial-1)*6))==dime){
			testo = testo+"<div id='cenNum'><a href='javascript:;' class='A9BFF' onClick='scrollPage(\"&page="+arrNav[dime-1].firstChild.nodeValue+"\")'><u>"+arrNav[dime-1].firstChild.nodeValue+"</u></a></div>";
			//testo2 = testo2+"<div id='cenNum'><a href='javascript:;' class='A9BFF' onClick='scrollPage(\"&page="+arrNav[dime-1].firstChild.nodeValue+"\")'><u>"+arrNav[dime-1].firstChild.nodeValue+"</u></a></div>";
		}else{
			testo = testo+"<div id='cenNum'><a href='javascript:;' class='A9RFF' onClick='scrollPage(\"&page="+arrNav[dime-1].firstChild.nodeValue+"\")'>"+arrNav[dime-1].firstChild.nodeValue+"</a></div>";
			//testo2 = testo2+"<div id='cenNum'><a href='javascript:;' class='A9RFF' onClick='scrollPage(\"&page="+arrNav[dime-1].firstChild.nodeValue+"\")'>"+arrNav[dime-1].firstChild.nodeValue+"</a></div>";
		}
		testo = testo+"</div>";
		//testo2 = testo2+"</div>";
		if(xmlProd.getElementsByTagName("pageNav")[0].getElementsByTagName("final")[0].firstChild.nodeValue!="null"){
			testo = testo+"<div id='imgFdx'><a href='javascript:;' onClick='next6("+partial+", "+last+", "+current+")'><img src='/bulgari/common/images/ffdx.gif' class='imgFdx'/></a></div>";
			//testo2 = testo2+"<div id='imgFdxTop'><a href='javascript:;' onClick='next6("+partial+", "+last+", "+current+")'><img src='/bulgari/common/images/ffdx.gif' class='imgFdx'/></a></div>";
		}
	}catch(e){
		//testo = "<div id='numPage'><span class='A9BFF'>page 0</span></div>";
		
		// #####################################################################################
		testo = "<div id='numPageTop'><span class='A9BFF'>page 0</span></div>";
		//testo2= "<div id='numPageBottom'><span class='A9BFF'>page 0</span></div>";
		
		
	}
	//testo+=testo2;
	return testo;
}

function writeColor(colors,pColor){
	var dime = colors.length;
	var colorBox = document.getElementById("colorPalette");
	var colorTextBox = "<div id='wColor' style='position: absolute; top: 0px; left: 20px;'>";
	var def = false;
	var selez = 1;
	for(var scorri=0; scorri<dime; scorri++){
		var col = colors[scorri].firstChild.nodeValue;
		if(col==pColor){
			colorTextBox = colorTextBox+'<a id="aa'+col+'" href="javascript:;" onClick="onCheckClr(\''+col+'\')"><img id="cc'+col+'" src="/bulgari/common/images/color/'+col+'.gif" class="colCheck" title="'+col+'" alt="'+col+'" name="'+col+'Yes"/></a>';
			def = true;
			selez = scorri+1;
		}else{
			colorTextBox = colorTextBox+'<a id="aa'+col+'" href="javascript:;" onClick="onCheckClr(\''+col+'\')"><img id="cc'+col+'" src="/bulgari/common/images/color/no'+col+'.gif" class="colNoCheck" title="'+col+'" alt="'+col+'" name="'+col+'No"/></a>';
		}
	}
	colorTextBox = colorTextBox+"</div><div id='tt32' style='position: absolute; left: -1000px; top: 0px; width: 1020px; height: 50px; background: #121212'></div>";
	colorTextBox = colorTextBox+"<div id='ffColSx'><a href='javascript:;' onmouseover='moveCol(\"dx\");' onmouseout='stopMove();'><img src='/bulgari/common/images/ffColSx.gif' class='imgFFCol'/></a></div>";
	colorTextBox = colorTextBox+"<div id='tt23' style='position: absolute; left: 100px; top: 0px; width: 200px; height: 50px; background: #121212'></div>";
	colorTextBox = colorTextBox+"<div id='ffColDx'><a href='javascript:;' onmouseover='moveCol(\"sx\");' onmouseout='stopMove();'><img src='/bulgari/common/images/ffColDx.gif' class='imgFFCol'/></a></div>";
	if(def){
		colorBox.innerHTML = colorTextBox+"<div id='txtCol' style='position: absolute; top: 5px; left: 115px;'><span class='A10RFF'>"+pColor+"</span></div>";
		var mvCol = document.getElementById('wColor');
		if(selez == dime){
			mvCol.style.left = (75-((25*(selez-1))+5))+"px";
		}else	if(selez > 1){ 
			mvCol.style.left = (50-((25*(selez-1))+5))+"px";
		}
	}else{
		colorBox.innerHTML = colorTextBox+"<div id='txtCol' style='position: absolute; top: 5px; left: 115px;'></div>";
	}
	document.getElementById("colorMenu").style.display = "block";
}

function startDepaPage(){
	if (myRequest.readyState == 4 && myRequest.status == 200) {
		var xmlProd = myRequest.responseText;
		var ctProd = document.getElementById("ctProd");
		ctProd.innerHTML = xmlProd;
	}
}

function executeAjax(value) {
	myRequest = getXMLHttp(resProductAJ);
	myRequest.open("GET","/bulgari/us/product/lookProd.jsp?"+value);
	myRequest.onreadystatechange = resProductAJ;
	myRequest.send(null);
}

function executeAjaxSc(value) {
	myRequest = getXMLHttp(searchProductAJ);
	myRequest.open("GET","/bulgari/us/product/search/searchProd.jsp?"+value);
	myRequest.onreadystatechange = searchProductAJ;
	myRequest.send(null);
}

function executeAjaxOr() {
	myRequest = getXMLHttp(orderWait);
	myRequest.open("GET","/bulgari/us/product/orderConfirmation.jsp");
	myRequest.onreadystatechange = orderWait;
	myRequest.send(null);
}

function executeAjaxCustomer(page) {
	myRequest = getXMLHttp(customerWait);
	myRequest.open("GET",page);
	myRequest.onreadystatechange = customerWait;
	myRequest.send(null);
}

function startAjax(cat) {
	myRequest = getXMLHttp(resProductAJ);
	myRequest.open("GET","/bulgari/us/product/depaPage.jsp?folder="+cat);
	myRequest.onreadystatechange = startDepaPage;
	myRequest.send(null);
}

function startAjaxSc() {
	myRequest = getXMLHttp(searchProductAJ);
	myRequest.open("GET","/bulgari/us/product/search/searchProd.jsp");
	myRequest.onreadystatechange = searchProductAJ;
	myRequest.send(null);
}
function reduceOpacity(i){
	var element = document.getElementById(i);
	element.className = "imgN_"+i;

}
function addOpacity(i){
	var element = document.getElementById(i);
	element.className = "img_"+i;

}












	var nW, nH, oH, oW;
	var top, left;

	// margin from upper border
		top = 40;
	// margin from left border
		left = 38;

	// normal image size
		iWideSmall = 140;
		iHighSmall = 140;

	// zoomed image size
		iWideLarge = 215;
		iHighLarge = 215;


	function MM_swapImgRestore( id, url ) {
		var image = document.getElementById( id );

		image.src = url;

		image.style.width = iWideSmall;
		image.style.height = iHighSmall;

		image.style.top = image.offsetTop + top;
		image.style.left = image.offsetLeft + left;
	}

	function MM_swapImage( id, par2, url ) { //v3.0
		var image = document.getElementById( id );

		image.oldSrc = image.src;
		image.style.oldWidth = image.width;
		image.style.oldHeight = image.height;
		image.style.oldTop = image.offsetTop;
		image.style.oldLeft = image.offsetLeft;

		image.src = url;

		image.style.width = iWideLarge;
		image.style.height = iHighLarge;

		image.style.top = image.offsetTop - top;
		image.style.left = image.offsetLeft - left;
	}
