function startList()
{
	if(document.all&&document.getElementById)
	{
		//startListByName("leftmenulist", "LI");
	}
}

function startListByName(name, element)
{
	navRoot = document.getElementById(name);
	for (i=0; i<navRoot.childNodes.length; i++)
	{
		node = navRoot.childNodes[i];
		if (node.nodeName==element)
		{
			node.onmouseover=function()
			{
				this.className+=" over";
			}
			node.onmouseout=function()
			{
			  this.className=this.className.replace(" over", "");
			}
		}
	}
}

function switchThumbnail(newImg)
{
	var gallery = document.getElementById("galleryPlaceholder");
	
	gallery.src = newImg;
}

function showDocumentTitle(szTitle)
{
	document.getElementById("txtTitleDocument").innerHTML = szTitle;
}

function sndEml(eml)
{
	var szNewAddress = eml;
	
	szNewAddress = replaceAll(szNewAddress, "_dot_", ".");
	szNewAddress = replaceAll(szNewAddress, "_at_", "@");
	location.href = "mailto:" + szNewAddress;
}

function replaceAll(str, from, to)
{
    var idx = str.indexOf(from);

    while(idx > -1)
    {
        str = str.replace(from, to);
        idx = str.indexOf(from);
    }

    return str;
}

var currentImg = null;

function showCatalogHighlight(img, id, hightlightSrc, lang)
{
	currentImg = img;
	var msg = document.getElementById("msg");
	var highlightPlaceholder = document.getElementById("highlightPlaceholder");
	
	highlightPlaceholder.setAttribute("productId", id);
	highlightPlaceholder.style.display = "block";
	highlightPlaceholder.style.left = findPosX(img) + "px";
	highlightPlaceholder.style.top = findPosY(img) - 20 + "px";
	highlightPlaceholder.style.background = "url(" + hightlightSrc + ") no-repeat";
	highlightPlaceholder.onclick = function(){
		getDescriptionById(id, lang);
	}
	
	//msg.innerHTML = findPosX(img) + ", " + findPosY(img);
	//msg.innerHTML = img.offsetLeft + ", " + img.offsetTop;
}

function cancelCatalogHighlight()
{
	var highlightPlaceholder = document.getElementById("highlightPlaceholder");
	highlightPlaceholder.style.display = "none";
}

function popDescription(response)
{
//	alert("popDescription");

	try
	{
		var doc = response.responseXML.documentElement;
		
		//alert(doc.getAttribute("id") + " - " + doc.getAttribute("name"));
		
	//	alert(" doc.firstChild.nodeValue="+ doc.firstChild.nodeValue);
		
		var buffer = "";
		buffer += "<div id=\"title\">         <div id=\"text\">                 PART #: ";
		buffer += doc.getAttribute("no");
		buffer += " | DESCRIPTION         </div>         <div id=\"closeButton\">                 <a href=\"javascript:closeCatalogItemPop()\">X</a>         </div> </div>  <div id=\"body\">         <div id=\"left\">                 <p class=\"description\">                         ";
		buffer += doc.getAttribute("name") + "<br/>" + doc.firstChild.nodeValue;
		buffer += "                 </p>                  <div id=\"itemData\">                         <div id=\"specifications\">                                 <span>SPÉCIFICATIONS</span>                                 <p>                                                                          </p>                         </div>                          <div id=\"price\">                                 <span>PRIX</span>                                 <p>                                         $ ";
		buffer += doc.getAttribute("price");
		buffer += "                                         + shipp.                                         + handl.                                 </p>                                  Commander                         </div>                 </div>                 <div class=\"blocker\">&nbsp;</div>         </div>          <div id=\"right\">                 <img src=\"http://www.arnegusa.com/transaction_arneg/photos/articles/";
		buffer += doc.getAttribute("id");
		buffer += "-1.jpg\" />         </div> </div> <div class=\"blocker\">&nbsp;</div> <div id=\"bottom\">         &nbsp; </div>";
		
		var holder = document.getElementById("catalogItemDescription");
		holder.innerHTML = buffer;
	//	alert("currentImg = " + currentImg)
		if(currentImg){
	//	alert("findPosY(currentImg) =" + findPosY(currentImg) )
	//		holder.style.left = findPosX(currentImg) + "px";
			displayDescription();
			holder.style.top = findPosY(currentImg) - 20 + "px";
		}
		
	}
	catch(e)
	{
		alert("Error [popDescription]: " + e.description);
	}
        
    
}

function getDescriptionById(productId, lang){
//alert('lang='+lang)
//	alert("productId : " + productId);
	doc = new XML();
	doc.setAttribute("langId", (lang=="fr") ? 1 : 2);
	doc.addListener(popDescription);
	//alert('productId='+productId);
	doc.setAttribute("id", productId);
	doc.setAttribute("uniqId", Math.round(Math.random()*100000));
	doc.sendAndLoad("/transaction_arneg/product/get.do");
}

function getDescription(e,lang)
{
    doc = new XML();
    doc.addListener(popDescription);
    doc.setAttribute("langId", (lang=="fr") ? 1 : 2);
    doc.setAttribute("id", e.getAttribute("productId"));
    doc.setAttribute("uniqId",Math.round(Math.random()*10000));
    doc.sendAndLoad("/transaction_arneg/product/get.do");
}

function displayDescription()
{
	try
	{
		var catalogCanvas = document.getElementById("catalogCanvas");
		var catalogMask = document.getElementById("catalogMask"), content = document.getElementById("content");
		var catalogItemDescription = document.getElementById("catalogItemDescription");

		if(catalogMask == null)
		{
			catalogMask = document.createElement("div");
			catalogMask.id = "catalogMask";
			content.insertBefore(catalogMask, catalogCanvas);
		}

		catalogMask.style.width = content.offsetWidth + "px";
		catalogMask.style.height = content.offsetHeight + "px";
		catalogMask.style.left = 0 + "px";
		catalogMask.style.top = findPosY(catalogCanvas) + "px";
		catalogMask.style.display = "block";

		catalogItemDescription.style.top = "340px";
		catalogItemDescription.style.display = "block";
	}
	catch(e)
	{
		alert(e.description);
	}
}

function closeCatalogItemPop()
{
	var catalogMask = document.getElementById("catalogMask");
	var catalogItemDescription = document.getElementById("catalogItemDescription");
	
	catalogMask.style.display = "none";
	catalogItemDescription.style.display = "none";
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent && obj.id != "global")
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent && obj.id != "global")
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}
