function highlightLink(element, enable)
{
        document.getElementById(element).style.backgroundColor = (enable) ? "#FF6600" : "#FFFFFF";
}

function writeText(element, text)
{
		document.getElementById(element).innerHTML = text;
}

// Generate copyright text displayed in footer
function writeCopyright(element)
{
		var currentDate = new Date();
		document.getElementById(element).innerHTML = "Copyright, " + currentDate.getFullYear() + " kwik kardz &amp; more";
}

// Display dialog containing detailed product image
function showPopup(productName, productImg) {
	
		var prodName = unescape(productName);
		// append random number to workaround browser caching
		var prodImg = "images/"+productImg+"?t="+Math.floor(Math.random()*10);
		
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		$( "#lrgImg" ).attr("src",prodImg);
		
		$( "#dialog-modal" ).display="block";
		
		$( "#dialog-modal" ).dialog({
			width: 360,
			height: 300,
			modal: true,
			resizable: false,
			draggable: false,
			title: prodName
		});
	
};

// Construct the product table and array on Product page by reading in XML doc and extracting data
function loadXMLDoc(url)
{
	var xmlhttp;
	var txt,xx,x,y,i;
	var productImgSm,productImgLg,productImgClass,productAnchor,productName,productPrice,productNumber,productId,selectOptions;

	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			txt="<table class='tabledata'><tr><th align='left'>Product</th><th align='left'>Description</th><th align='left'>Item</th><th align='left'>Price</th><th align='left'>Qty</th></tr>";
			txt=txt + "<form id='productform'>";
			x=xmlhttp.responseXML.documentElement.getElementsByTagName("ITEM");
			productList = new Array(x.length);
			for (i=0;i<x.length;i++)
			{
				// product name
				txt=txt + "<tr class='productNameBg'>";
				productName=x[i].getElementsByTagName("NAME");
				productAnchor=x[i].getElementsByTagName("ANCHOR");
				{
					try
					{
						txt=txt + "<td colspan='5'><span class='productName'>";
						txt=txt + "<a name='"+productAnchor[0].firstChild.nodeValue+"'>";
						txt=txt + productName[0].firstChild.nodeValue + "</span></td>";
					}
					catch (er)
					{
						txt=txt + "<td colspan='5'>&nbsp;</td>";
					}
				}

				txt=txt + "</tr>";

				productImgSm=x[i].getElementsByTagName("IMAGE_SM");
				productImgLg=x[i].getElementsByTagName("IMAGE_LG");
				productImgClass=x[i].getElementsByTagName("IMAGE_CLASS");

				// image and "enlarge image" dialog
				txt=txt + "<tr>";
				{
					try
					{
						txt=txt + "<td height='120px' style='text-align:center;'>";
						txt=txt + "<a href='#t' onclick='showPopup(\""+escape(productName[0].firstChild.nodeValue)+"\",\""+productImgLg[0].firstChild.nodeValue+"\")'>";
						
						if (productImgClass[0].firstChild)
						{
							txt=txt + "<img src='images/img_trans.gif' class='" + productImgClass[0].firstChild.nodeValue + " " + productAnchor[0].firstChild.nodeValue + "'>";						
						}
						else
						{
							txt=txt + "<img src='images/" + productImgSm[0].firstChild.nodeValue + "?t="+Math.floor(Math.random()*10)+"' alt='"+ productName[0].firstChild.nodeValue +"'>";
						}
						
						txt=txt + "<span class='enlarge'>enlarge</span>";
						txt=txt + "</a>";
						txt=txt + "</td>";
					}
					catch (er)
					{
						txt=txt + "<td>&nbsp;</td>";
					}
				}
				productDesc=x[i].getElementsByTagName("DESCRIPTION");

				// description
				selectOptions=productDesc[0].getElementsByTagName("SELECT_OPTION");
				{
					try
					{
						var desc = productDesc[0].firstChild.nodeValue;

						var selectId = productAnchor[0].firstChild.nodeValue + "Message";
						desc = desc.replace(/\*/g,"<li>");
						desc = desc.replace("(","<br/>(");
						txt=txt + "<td>";
						txt=txt + "<ul class='productDesc'>" + desc;
						
						// custom message options (if any)
						if (selectOptions.length > 0) {
							txt=txt + "<select id='" + selectId + "'>";
							for (y=0; y < selectOptions.length; y++) {
								msg = selectOptions[y].firstChild.nodeValue;
								txt=txt + "<option value='" + msg + "'>" + msg + "</option>";
							}
							txt=txt + "</select>";
						}
						txt=txt + "</ul>";
						txt=txt + "</td>";
					}
					catch (er)
					{
						txt=txt + "<td>&nbsp;</td>";
					}
				}
				
				// item number
				productNumber=x[i].getElementsByTagName("NUMBER");
				{
					try
					{
						txt=txt + "<td>" + productNumber[0].firstChild.nodeValue + "</td>";
					}
					catch (er)
					{
						txt=txt + "<td>&nbsp;</td>";
					}
				}
				
				// price
				productPrice=x[i].getElementsByTagName("PRICE");
				{
					try
					{
						txt=txt + "<td>$" + productPrice[0].firstChild.nodeValue + "</td>";
					}
					catch (er)
					{
						txt=txt + "<td>&nbsp;</td>";
					}
				}
				
				// quantity
				productId=x[i].getElementsByTagName("SELECT_ID_QTY");
				{
					try
					{
						var id = productId[0].firstChild.nodeValue;
						txt=txt + "<td><select id=\"" + id + "\" class=\"productSelectQuantity\">";
						for (y=0; y<=9; y++) {
						  txt=txt + "<option value=" + y + ">" + y + "</option>";
						}
						txt=txt + "</select>"
						txt=txt + "<input type=\"button\" name=\"submit\" value=\"Add\" alt=\"Make payments with PayPal - its fast, free and secure!\" onClick=\"" + "addToCart(\'" + id + "\'); return false;\"/>";
						txt=txt + "</td>";
					}
					catch (er)
					{
						txt=txt + "<td>&nbsp;</td>";
					}
				}
								
				var id = productId[0].firstChild.nodeValue
				
				//build array of products for shopping cart functionality
				productList[id] = new Array(3);
				productList[id][0] = productName[0].firstChild.nodeValue;
				productList[id][1] = productPrice[0].firstChild.nodeValue;
				productList[id][2] = productNumber[0].firstChild.nodeValue;
				
				txt=txt + "</tr>";
				
			}
			txt=txt + "</form>";
			txt=txt + "</table>";
			document.getElementById('productTable').innerHTML=txt;

		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
	
	var t = setTimeout("jumpToAnchor()",500);
};

// Used on Products page for jumping to a page anchor (required since page is dynamically generated)
function jumpToAnchor()
{
	if (location.hash.length > 0)
	{
		location.href='products.htm'+ location.hash;
	}

}

// Fill in necessary form data for PayPal shopping cart api
function addToCart(item)
{
	var selectobject = null;
	var count = 0;
	selectobj = document.forms["productform"].elements[item];
	itemcount = selectobj.options[selectobj.selectedIndex].value;

	document.forms["addtocart"].elements["item_name"].value = productList[item][0];
	document.forms["addtocart"].elements["amount"].value = productList[item][1];
	document.forms["addtocart"].elements["item_number"].value = productList[item][2];
	document.forms["addtocart"].elements["quantity"].value = itemcount;

	// determine if there is a custom message option for the product
	var msgitem = item + "Message";
	var msgSelectObj = document.forms["productform"].elements[msgitem];
	if (msgSelectObj)
	{
		msg = " (" + msgSelectObj.options[msgSelectObj.selectedIndex].value + ")";
		document.forms["addtocart"].elements["item_name"].value += msg;
	}

	// remove sales tax for stamps
	if ( productList[item][2] == "100USPS" ) {
	  document.forms["addtocart"].elements["tax"].value = 0;
	}
	document.forms["addtocart"].submit();
	return false;
};




