// Preload images
i1 = new Image();
i1.src = "http://pennormedtryck.com/images/menuBgOn.gif";

i2 = new Image();
i2.src = "http://pennormedtryck.com/images/category_1On.gif";
i3 = new Image();
i3.src = "http://pennormedtryck.com/images/category_2On.gif";
i4 = new Image();
i4.src = "http://pennormedtryck.com/images/category_3On.gif";
i5 = new Image();
i5.src = "http://pennormedtryck.com/images/category_4On.gif";

function changeMenu(id,on)
{
	if(on)
		document.getElementById("menuItem_" + id).style.background = "url('images/menuBgOn.gif')";
	else
		document.getElementById("menuItem_" + id).style.background = "url('images/menuBgOff.gif')";
}

function hoverCategory(id,on)
{
	if(on)
		document.getElementById("category_" + id).src = "images/category_" + id + "On.gif";
	else
		document.getElementById("category_" + id).src = "images/category_" + id + "Off.gif";	
}

function showPennorMenu()
{
	document.getElementById("pennorSubmenu").style.visibility = "visible";
}

function hidePennorMenu()
{
	document.getElementById("pennorSubmenu").style.visibility = "hidden";
}

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function showPrice(amount)
{
	var a = amount;
	var form = document.priceform;
	var num = eval(form.amount.value);
	var win;
	var print = URLEncode(form.print[form.print.selectedIndex].text);

	if(num == null || num<a)
		alert("Minsta beställning av denna pennan är " + a + " st.");
	else
		win = window.open("price_index.php?product=" + form.product.value + "&amount=" + num + "&print=" + print, "price_" + form.product.value, "WIDTH=500,HEIGHT=550,STATUS=YES");
}