// JavaScript Document
function strrev(inp) { 
  var outp = ""

  for (i = 0; i <= inp.length; i++) { 
    outp = inp.charAt (i) + outp 
  } 

  return outp;
} 

function writemail(user, domain, tld)
{
	var garbage = "!Fjji68@Mfmki#"
	var at = garbage.charAt(7);
	var nothing = "";
	var eadd = user + at + domain;
	eadd = eadd + "." + strrev(tld);
	document.write("<a href='mai");
	document.write(nothing + "lto");
	document.write(":"+eadd+"' class='emailLinks'>");
	document.write(eadd + "</a>")
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//resizePopup is used by showPopupFrame and showPopupImage to resize the popup table to the right size for it's contents
//This also resizes the popupOverlay div.
function resizePopup(width, height)
{
	var bottomShadow = document.getElementById("popupBottomShadow");
	var rightShadow = document.getElementById("popupRightShadow");
	var innerTable = document.getElementById("popupTableInsideShadow");
	var table = document.getElementById("popupTable");

	var tableWidth = width + 20;
	var tableHeight = height + 50;
	cwidth = document.body.clientWidth;
	cheight = document.body.clientHeight;

	innerTable.style.width = tableWidth + "px";
	innerTable.style.height = tableHeight + "px";	

	table.style.width = tableWidth + 7 + "px";
	table.style.height = tableHeight + 7 + "px";

	table.style.left = cwidth / 2 - tableWidth / 2 + "px";
	var top = cheight / 2 - tableHeight / 2;
	
	if (goodbrowser && cwidth / 2 - tableWidth / 2 >= 10 && cheight / 2 - tableHeight / 2 >= 10)
	{
		table.style.position = "fixed";
		table.style.top = top + "px";
	} else {
		table.style.position = "absolute";
		table.style.top = top + document.body.scrollTop + "px";
	}
	
	if (cwidth / 2 - tableWidth / 2 < 10)
		table.style.left = "10px";

	if (cheight / 2 - tableHeight / 2 < 10)
		table.style.top = 10 + document.body.scrollTop + "px";

	rightShadow.height = innerTable.offsetHeight - 7;
	bottomShadow.width = innerTable.offsetWidth - 7;
}


//showPopupFrame shows the popup window with the "View Colors" area loaded into it.
//The window needs to be included in the HTML - as it is at the bottom of productdetail_body.php
function showPopupFrame(src, width, height, description)
{
	if (typeof(width) == "undefined")
		width = 600;
	if (typeof(height) == "undefined")
		height = 600;
	
	for(i = 0; i < document.getElementsByTagName("select").length; i++)
	{
		var element = document.getElementsByTagName("select")[i];
		element.style.visibility = "hidden";
	}
	
	var iframe = document.getElementById("popupFrame");
	iframe.src = src;
	
	//setup the popup viewer to display an iframe
	document.getElementById("popupImage").style.display = "none";
	document.getElementById("seriesNavigation").style.display = "none";
	iframe.style.display = "block";
	document.getElementById("popupDescription").innerHTML = description;

	iframe.style.width = width + "px";
	iframe.style.height = height + "px";

	var pageOverlay = document.getElementById("popupPageOverlay");
	document.getElementById("popupTable").style.display = "block";
	resizePopup(width, height);
	pageOverlay.style.width = cwidth + "px";
	pageOverlay.style.height = document.body.scrollHeight + "px";
	//We have to do this here incase the popup window increases the size of the body.
}

//showPopupImage shows the popup Image viewer window with an image loaded into it.
//The window needs to be included in the HTML - as it is at the bottom of productdetail_body.php
//src = absolute or relative URL of the image to show
//width = width of the image
//height = height of the image
//index = optional - index of current image in series
//series = optional - the name of the current series (if any)
//NOTE all images in a series should be the same width and height
//NOTE for series there should be a hidden input for each image in the series named
//  "[series]SRC[index]" whose value is the src of that image, 
//  another for each named "[series]Desc[index]" whose value is the description to display and
//  also one hidden input named "[series]NumPopupImages" for how many there are in that series
function showPopupImage(src, width, height, description, index, series)
{
	for(i = 0; i < document.getElementsByTagName("select").length; i++)
	{
		var element = document.getElementsByTagName("select")[i];
		element.style.visibility = "hidden";
	}
	
	var img = document.getElementById("popupImage");

	//setup the popup viewer to display an image (or series)
	document.getElementById("popupFrame").style.display = "none";
	img.style.display = "block";
	document.getElementById("popupDescription").innerHTML = description;

	if (typeof(series) == "undefined") {
		index = 0;
		series = "none";
		document.getElementById("seriesNavigation").style.display = "none";
	} else document.getElementById("seriesNavigation").style.display = "block";

	document.getElementById("currentPopupIndex").value = index;
	document.getElementById("currentPopupSeries").value = series;

	var pageOverlay = document.getElementById("popupPageOverlay");
	img.src=src;
	document.getElementById("popupTable").style.display = "block";
	resizePopup(width, height);
	pageOverlay.style.width = cwidth + "px";
	pageOverlay.style.height = document.body.scrollHeight + "px";
	//We have to do this here incase the popup window increases the size of the body.
}

//hidePopup hides the popup window.
function hidePopup()
{
	for(i = 0; i < document.getElementsByTagName("select").length; i++)
	{
		var element = document.getElementsByTagName("select")[i];
		element.style.visibility = "visible";
	}
	document.getElementById("popupTable").style.display = "none";
	document.getElementById("popupPageOverlay").style.width = 0;
}

//Switches to the next/previous (or any) image in the current series depending on the integer parameter, offset.
//offset is the number to add to the current index to find the new image.
function switchPopupImage(offset)
{
	var img = document.getElementById("popupImage");
	var current = document.getElementById("currentPopupIndex");
	var series = document.getElementById("currentPopupSeries").value;
	
	if (series != "none")
	{
		var length = document.getElementById(series+"NumPopupImages").value;
		var nextIndex = (parseInt(current.value) + offset) % length;
		if (nextIndex < 0) nextIndex = length - 1;
		var next = document.getElementById(series+"SRC"+nextIndex);
		document.getElementById("popupDescription").innerHTML = document.getElementById(series+"Desc"+nextIndex).value;
		img.src=next.value;
		current.value = nextIndex;
	}
	
}
