function loadRollovers()
{
	var objList = getElementsByClass('button', null, 'img');
	for(var i = 0; i < objList.length; i++)
	{
		var objId = objList[i];
		if (objId.addEventListener)
		{
			// Every Other Modern Web Browser
			objId.addEventListener("mouseover", showRolloverImg, false);
			objId.addEventListener("mouseout", hideRolloverImg, false);
		}
		else
		{
			// IE
			objId.attachEvent('onmouseover', showRolloverImg);
			objId.attachEvent('onmouseout', hideRolloverImg);
		}
	}
}
function showElement(ElementIDToShow)
{
	var curNode = document.getElementById(ElementIDToShow);
	// Show this element
	curNode.style.display = 'block';
	
	while (curNode.nodeName != "P")
	{
		curNode = curNode.previousSibling;
	}
	curNode.setAttribute("onclick", "hideElement('"+ElementIDToShow+"'");
	curNode.onclick = function () { hideElement(ElementIDToShow); };
}
function hideElement(ElementIDToShow)
{
	var curNode = document.getElementById(ElementIDToShow);
	// Show this element
	curNode.style.display = 'none';
	
	while (curNode.nodeName != "P")
	{
		curNode = curNode.previousSibling;
	}
	curNode.setAttribute("onclick", "showElement('"+ElementIDToShow+"'");
	curNode.onclick = function () { showElement(ElementIDToShow); };
}
function showHide(ElementIDToShow, ElementIDToHide)
{
	// Hide this element
	document.getElementById(ElementIDToHide).style.display = 'none';
	// Show this element
	document.getElementById(ElementIDToShow).style.display = 'block';
}
function showRolloverImg(e)
{
	var targ;
	if (!e)
	{ e = window.event; }
	if (e.target) 
	{ targ = e.target; }
	else if (e.srcElement) 
	{ targ = e.srcElement; }
	if (targ.nodeType == 3) // defeat Safari bug
	{	targ = targ.parentNode; }
		
	var imgSrc = targ.src;
	var pieces = imgSrc.split('_', 2);
	imgSrc = pieces[0] + '_' + pieces[1].replace('.png', '_RO.png').replace('.jpg', '_RO.jpg');
	targ.src = imgSrc;
}
function hideRolloverImg(e)
{
	var targ;
	if (!e)
	{ e = window.event; }
	if (e.target) 
	{ targ = e.target; }
	else if (e.srcElement) 
	{ targ = e.srcElement; }
	if (targ.nodeType == 3) // defeat Safari bug
	{	targ = targ.parentNode; }
	
	var pieces = targ.src.split('_');
	imgSrc = pieces[0];
	for (var i = 1; i < pieces.length; i++)
	{
		var piece = pieces[i];
		if (i+1 == pieces.length)
		{
			imgSrc += piece.replace('RO', '');
		}
		else
		{
			imgSrc += '_' + pieces[i];
		}
	}
	targ.src = imgSrc;
}

function getElementsByClass(searchClass,node,tag)
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

var DetailViewPanel_width = 0;
var DetailViewPanel_height = 0;
var OverlayBackground_height = 0;
var OverlayBackground_width = 0;
var OverlayBackground_opacity = 70;
var BorderBackground_opacity = 95;
function ShowBackgroundOverlay()
{
	// Hide all SELECT elements on the entire page
	HideSelectboxes();
	
	// Retrieve PageHeight/PageWidth/PageScroll variables in array
	var dimensions = getPageSizeWithScroll();
	var pageWidth = dimensions[0];
	var pageHeight = dimensions[1];
	var viewableHeight = dimensions[2];
	
	OverlayBackground_width = pageWidth;
	OverlayBackground_height = pageHeight;
	DetailViewPanel_width = pageWidth;
	DetailViewPanel_height = viewableHeight;
	
	var OBObj = document.getElementById('OverlayBackground');
	// Apply settings to OverlayBackground element
	OBObj.style.width = OverlayBackground_width+'px';
	OBObj.style.height = OverlayBackground_height+'px';
	OBObj.style.MozOpacity = ""+(OverlayBackground_opacity/100);
	OBObj.style.opacity = ""+(OverlayBackground_opacity/100);
	OBObj.style.filter = 'alpha(opacity='+OverlayBackground_opacity+')';
	OBObj.style.display = 'block';	
}

function handleDesignImgResponse(pos)
{
	var response = httpReqQueue[pos].xmlhttp.responseText;
	var pieces = response.split("`");
	
	var outputHTML = "";
	for (var j = 0; j < pieces.length; j++)
	{
		outputHTML += '<a href="javascript:ChangeDetailImg(\''+pieces[j]+'\')">'+(j+1)+'</a>&nbsp;|&nbsp;';
	}
	outputHTML += '<a href="javascript:HideDetailView()">close</a>';
	
	// UPDATE the DIV tag element with the HTMl we just created
	document.getElementById('DetailViewLinks').innerHTML = outputHTML;
	// HIDE loading animation image
	document.getElementById('LoadingImage').style.display = "none";
	// Change Detail Image
	ChangeDetailImg(pieces[0]);
	// SHOW the detail image
	document.getElementById('DetailImage').style.display = "block";
}
function HideDetailView()
{
	document.getElementById('OverlayBackground').style.display='none';
	document.getElementById('DetailViewBackground').style.display='none';
	document.getElementById('DetailViewPanel').style.display='none';
	ShowSelectboxes();
}
function HideSelectboxes()
{
	if (!document.getElementsByTagName)
	{ return; }
	var selects = document.getElementsByTagName("select");

	// Loop through all <select> elements
	for (var i=0; i<selects.length; i++)
	{
		var selectBox = selects[i];
		selectBox.style.visibility='hidden';
	}
}
function ShowSelectboxes()
{
	if (!document.getElementsByTagName)
	{ return; }
	var selects = document.getElementsByTagName("select");

	// Loop through all <select> elements
	for (var i=0; i<selects.length; i++)
	{
		var selectBox = selects[i];
		selectBox.style.visibility='visible';
	}
}
function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) 
	{
		// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ 
		// all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} 
	else 
	{ 
		// works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  }
	
	// Retrieve viewable height
	var windowWidth, windowHeight;
	// All except Internet Explorer 5.0+
	if (self.innerHeight) 
	{	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}  
	// Internet Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight) 
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	// Other Explorers 
	else if (document.body) 
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll, windowHeight);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}
function ChangeDetailImg(imageSrc)
{
	document.getElementById('DetailImage').src = imageSrc;
}
function getEstimatedShipping(obj)
{
	if (obj.id == "Country_Code")
	{
		if (obj.value != "")
		{
			document.getElementById('ZipCode').value = '';
			var url = "ajax/getEstimatedShipping.php?zip="+escape(obj.value)+"&wt="+escape(weight);
			//alert(url);
			httpReqQUEUE(url, 'handleGetEstimatedShipping');
			return;
		}
	}
	else if (obj.id == "ZipCode")
	{
		if (obj.value.length >= 3)
		{
			document.getElementById('Country_Code').selectedIndex = 0;
			var url = "ajax/getEstimatedShipping.php?zip="+escape(obj.value)+"&wt="+escape(weight);
			//alert(url);
			httpReqQUEUE(url, 'handleGetEstimatedShipping');
			return;
		}
	}
	document.getElementById('estimated_shipping_value').innerHTML = '$0.00';
}
function handleGetEstimatedShipping(pos)
{
	var response = parseFloat(httpReqQueue[pos].xmlhttp.responseText);
	var subtotal = parseFloat(document.getElementById('subtotal_value').innerHTML.replace("$",""));
	document.getElementById('estimated_shipping_value').innerHTML = '$'+response.toFixed(2);
	var grandtotal = response + subtotal;
	document.getElementById('grand_total_value').innerHTML = '$'+grandtotal.toFixed(2);
}
function arraySearch(array, searchValue)
{
	for (var i = 0; i < array.length; i++)
	{
		if (array[i] == searchValue)
		{
			return true;
		}
	}
	return false;
}