// JavaScript Document

var activeTab;
var activeTabArea;
var rightMenus;
var rightPlaced;

function setActiveTabIDS(tabID,divID)
{
	activeTab = tabID;
	activeTabArea = divID;
}

function changeTabDivs(tabID,divID)
{
	activateTab(activeTab,activeTabArea,false);
	activateTab(tabID,divID,true);
	setActiveTabIDS(tabID,divID);
}

function activateTab(tabID,divID,state)
{
	var tempObj;
	if(document.getElementById)
	{
		if(tabID)
		{

			tempObj =  document.getElementById(tabID);
			if(state)
			{
				tempObj.className = 'tabActiveTab';
			}
			else
			{
				tempObj.className = '';
			}

		}

		if(divID)
		{
			tempObj =  document.getElementById(divID);

			if(state)
			{
				tempObj.className = 'tabShowDiv';
			}
			else
			{
				tempObj.className = 'tabHideDiv';
			}
		}
	}
}

function showElementTab(id, showTab)
{
	var tab = document.getElementById(id);

	if (!tab)
	{
		return;
	}

	if (showTab == true)
	{
		tab.style.display = "inline";
	}
	else
	{
		tab.style.display = "none";
	}
}

function showHideElement(id)
{
        var contentDiv = document.getElementById(id);

        if (contentDiv.className == 'showHideContent')
        {
                contentDiv.className = 'showHideNone';
        }
        else
        {
                contentDiv.className = 'showHideContent';
        }
}

function showHideElementInline(id)
{
        var contentDiv = document.getElementById(id);

        if (contentDiv.className == 'showHideInline')
        {
                contentDiv.className = 'showHideNone';
        }
        else
        {
                contentDiv.className = 'showHideInline';
        }
}

function showHideElementAction(id)
{
        showHideElement('element' + id);
        showHideElementInline('Close' + id);
        showHideElementInline('Open' + id);
}

function showHTMLElement(id,state,displayType)
{
	if(document.getElementById)
	{
		var element = document.getElementById(id);
		if(state)
		{
			if(!displayType)
			{
				displayType = "block";
			}
			element.style.display = displayType;
		}
		else
		{
			element.style.display = "none";
		}
	}
}

function forceFormRefresh(form)
{
        if (form)
        {
                var e = form.elements;
                var l = e.length;
                for (var i=0;i<l;i++)
                {
                        switch (e[i]['type'])
                        {
                                case ('select-one'):
                                        e[i].selectedIndex = -1;
                                        e[i].options[0].selected = true;
                                        break;

                                case ('text'):
                                case ('textarea'):
                                        e[i].value = "";
                                        break;

                                case ('radio'):
                                case ('check'):
                                        e[i].checked = false;
                                        break;
                        }
                }
        }
}



function addInnerHTML(id,htmlContent)
{
	if(document.getElementById)
	{
		document.getElementById(id).innerHTML = htmlContent;
	}
}

function reposRightMenus(aIDs,nWidth)
{
	if(document.getElementById)
	{
		var n = aIDs.length;
		var leftEdge;
		for(var i=0;i<n;i++)
		{
			parentLI = document.getElementById('li'+aIDs[i]);
			resizeUL = document.getElementById('ul'+aIDs[i]);
			if(!rightMenus)
			{
				rightMenus = new Array();
			}
			rightMenus.push({parent:parentLI,child:resizeUL,width:nWidth});
		}
	}
}

function placeRightMenus()
{
	if(!rightPlaced && rightMenus.length)
	{
		var n = rightMenus.length;
		var leftEdge;
		var o;
		for(var i=0;i<n;i++)
		{
			o = rightMenus[i];
			parentWidth = Number(o['parent'].offsetWidth);
			leftEdge = 0-(o['width']-parentWidth)+2;
			o['child'].style.left = leftEdge + "px";
		}
		rightPlaced = true;
	}
}

function fakeHover(theElement) { theElement.className = 'submenuHover'; }
function fakeUnHover(theElement) { theElement.className = 'submenu'; }

function showWindowedElements(tagName)
{
	var e=document.getElementsByTagName(tagName);

	for (var i=0; i<e.length; i++)
	{
		e[i].style.visibility = '';
	}
}

function hideWindowedElements(tagName)
{
	var e=document.getElementsByTagName(tagName);

	for (var i=0; i<e.length; i++)
	{
		if(e[i].className.indexOf('noDropDownHide') == -1)
		{
			e[i].style.visibility = 'hidden';
		}
	}
}

function showAllWindowedElements()
{
	showWindowedElements('select');
	showWindowedElements('input');
	showWindowedElements('textarea');
}

function hideAllWindowedElements()
{
	hideWindowedElements('select');
	hideWindowedElements('input');
	hideWindowedElements('textarea');
}


function jumpToLink(formSelect)
{
	if(formSelect && formSelect.value)
	{
		window.location.href = 	formSelect.value;
	}
}



/* -----------------------------------------------------------------
		show large product image and center it on screen but always
		leave room for the upper menu
*/
function viewLargeImage(imageURL,imageWidth,imageHeight) {

	if(document.getElementById)
	{
		var pw = document.getElementById('zoomLayer');
		if(!pw) pw = createImagePopUp();
		var s = '<div class="button">';
		s += '<a href="#" id="zoomClose" title="Click to close" onclick="hideLargeImage();return false;">Close</a>';
		s += '</div>';
		s += '<div class="clearMargins"></div>';
		s += '<img src="'+imageURL+'" id="largeProductImage" alt="Product image" title="Product Image" width="'+imageWidth+'" height="'+imageHeight+'" /><br />';
		pw.innerHTML = s;


		var x;
		var imageHeight, imageWidth, windowWidth, windowHeight;

		windowWidth = getWindowInnerWidth();
		windowHeight = getWindowInnerHeight();

		imageWidth = (imageWidth == 0 ? 365 : imageWidth+5);
		imageHeight = (imageHeight == 0 ? 400 : imageHeight);

		pw.style.width = imageWidth+"px";

		pw.style.left = parseInt((windowWidth - imageWidth) / 2) + "px";
		x = parseInt((windowHeight - imageHeight) / 2);

		pw.style.top = (x < 145 ? "145px" : x + "px")
		pw.style.display = "block";
	}
}

function createImagePopUp()
{
	var elem = document.createElement("div");
	elem.setAttribute("id", "zoomLayer");
	var child = document.body.appendChild(elem);
	return child;
}


/* -----------------------------------------------------------------
		get inner height of browser window
*/
function getWindowInnerHeight() {
	var x;

	if (self.innerHeight) {
		x = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientHeight;
	} else if (document.body) {
		x = document.body.clientHeight;
	}
	return x;
}

/* -----------------------------------------------------------------
		get inner width of browser window
*/
function getWindowInnerWidth() {
	var x;

	if (self.innerWidth) {
		x = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		x = document.documentElement.clientWidth;
	} else if (document.body) {
		x = document.body.clientWidth;
	}
	return x;
}


/* -----------------------------------------------------------------
		hide large image layer
*/
function hideLargeImage() {
	var elm;


	if (elm = document.getElementById("zoomLayer"))
	{
		elm.style.display = "none";
	}
}