// Hiscore Warrior specific script

var checkingSubmit = false;
function checkQuantities(form)
{
	var	i, quantity, j = 0;

	if (checkingSubmit)
		return false;

	checkingSubmit = true;

	for (i = 1; i < 100; i++)
	{
		quantity = form.elements["quantity_" + i];
		if (quantity)
		{
			if (quantity.selectedIndex > 0)
			{
				if (j == 0)
					form.elements["business"].value = String.fromCharCode(112, 97, 121, 112, 97, 108, 64, 117, 116, 105, 108, 105, 116, 121, 119, 97, 114, 114, 105, 111, 114, 46, 99, 111, 109);
				j++;
				
				CookieSet("item" + j, form.elements["item_number_" + i].value);
				CookieSet("qty" + j, quantity.selectedIndex);
				
				form.elements["item_name_" + i].name	= "item_name_" + j;
				form.elements["item_number_" + i].name	= "item_number_" + j;
				form.elements["amount_" + i].name		= "amount_" + j;
				form.elements["quantity_" + i].name		= "quantity_" + j;
			}
			else
			{
				form.elements["item_name_" + i].name	= "no_name_" + i;
				form.elements["item_number_" + i].name	= "no_number_" + i;
				form.elements["amount_" + i].name		= "no_amount_" + i;
				form.elements["quantity_" + i].name		= "no_quantity_" + i;
			}
		}
		else
			break;
	}
	
	if (j > 0)
	{
		CookieSet("total", j);
		document.getElementById("pleasewait").style.visibility = "visible";
		return true;
	} 
	
	alert("You have not entered any quantities.");	
	checkingSubmit = false;
	return false;
}

function Thanks()
{
	var expiresGMT, now = new Date();
	var i;
	for (i = 1; i < 100; i++)
	{		CookieSet("item"+i,"");
		CookieSet("qty"+i,"");
	}	CookieSet("total","");
	now.setTime(now.valueOf() - (1000 * 60 * 60 * 24 * 365)); // expire last year	expiresGMT = now.getDate() + "-" + now.getMonth() + "-" + now.getFullYear() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + " GMT";
	document.cookie = "expires=" + expiresGMT; 
}

function ChangeQuantity(which)
{
	var form		= document.forms[0];
	var amount		= parseFloat(form.elements["amount_" + which].value);
	var quantity	= form.elements["quantity_" + which].selectedIndex;
	var total		= "" + (amount * quantity);
	var pos			= total.indexOf(".");
	var grandtotal	= 0.0;
	var	i;

	if (pos == -1)
		total = total + ".00";
	else if (pos == total.length - 2)
		total = total + "0";
	else if (pos < total.length - 3)
		total = total.slice(0, pos + 3);
	document.getElementById("total_" + which).firstChild.nodeValue = total;
	
	for (i = 1; i < 100; i++)
	{
		total = document.getElementById("total_" + i);
		if (total)
			grandtotal += parseFloat(total.firstChild.nodeValue);
		else
			break;
	}
	grandtotal = "" + grandtotal;
	pos = grandtotal.indexOf(".");
	if (pos == -1)
		grandtotal = grandtotal + ".00";
	else if (pos == grandtotal.length - 2)
		grandtotal = grandtotal + "0";
	else if (pos < grandtotal.length - 3)
		grandtotal = grandtotal.slice(0, pos + 3);
	
	document.getElementById("total").firstChild.nodeValue = grandtotal;
}

var cookieExpirySet = false;
function CookieSet(Name,Value)
{	document.cookie = Name + "=" + escape(Value); 	if (!cookieExpirySet)	{
		var expiresGMT, now = new Date();
		now.setTime(now.valueOf() + (1000 * 60 * 60 * 24 * 2)); // add two days		expiresGMT = now.getDate() + "-" + now.getMonth() + "-" + now.getFullYear() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + " GMT";
		document.cookie = "expires=" + expiresGMT; 
		cookieExpirySet = true;	}	}

function CookieGet(Name,DefaultValue)
{
    var dc		= document.cookie;
    var prefix	= Name + "=";
    var begin	= dc.indexOf("; " + prefix);
    if (begin == -1)
		{
        begin = dc.indexOf(prefix);
        if (begin != 0) return DefaultValue;
		}
    else
        begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

var mai = "mai";
var lto = "lto:";
var hash= "@";
var hisc= "hisc";
var orew= "orew";
var arri= "arri";
var ordot="or.";
var com = "com";
var who = "support" + hash + hisc + orew + arri + ordot + com;
function contactCheck(form)
{
	var		codeElements = 0;

	if (form.subject.selectedIndex == 0)
	{
		alert("Please select the most appropriate contact type."); 
		return false;	
	}

	form.action = mai + lto + who;
	
	return true;
}

function me()
{
	document.write(who);
}