	//////////////////////////////////////////////////////////////////////////
//        Copyright © 1999. Mario Marcos. LocalShots Corporation.       //
//        Nș - MJSSC1011. All rights reserved. www.localshots.net       //
//////////////////////////////////////////////////////////////////////////
//                                                                      //
// The following shopping cart program uses the concept of cookies to   //
// store and process ordering information on a client's computer. It    //
// has been written using JavaScript and is therefore considered to be  //
// software. This script is only authorized for use with this specific  //
// website and not considered to be freeware or shareware. It may not   //
// be modified in any way, shape, or form, by anyone, other than by the //
// original author. By using this script, you agree to indemnify its    //
// author from any liability that might arise from its misuse. Using    //
// the code for this script other than for its sole intended purpose,   //
// is expressly forbidden by the author. Redistribution of this script  //
// over the Internet, or in any other medium, is expressly forbidden by //
// the author. Copyright notice and header must accompany this script   //
// at all times.                                                        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
//                                                                      //
// WARNING: This program is protected by copyright law. Unauthorized    //
// reproduction or distribution of this program, or any portion of it,  //
// may result in severe civil and criminal penalties, and will be       //
// prosecuted to the fullest extent possible under the law.             //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
//
// Begin shopping cart functions.
//
function alterError(value) {
	if (value<=0.99) {
	newPounds = '0';
	} else {
	newPounds = parseInt(value);
	}
	newPence = parseInt((value+.0008 - newPounds)* 100);
	if (eval(newPence) <= 9) newPence='0'+newPence;
	newString = newPounds + '.' + newPence;
	return (newString);
}
function buyItem(newItem, newPrice, newQuantity) {
	if (newQuantity < "1" || newQuantity > "99") {
	rc = alert('The quantity entered is incorrect');
	return false;
	}
	if (confirm('Add '+newQuantity+' x '+newItem+' to basket')) {
	index = document.cookie.indexOf("TheBasket");
	countbegin = (document.cookie.indexOf("=", index) + 1);
	countend = document.cookie.indexOf(";", index);
	if (countend == -1) {
	countend = document.cookie.length;
	}
	document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newPrice+"#"+newQuantity+"]";
	}
	return true;
}
function resetShoppingBasket() {
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket=.";
}
function gotoViewCart() {
	if(self.location == self.location) {
	self.location.href = "viewcart.html";
	}
}
function gotoCheckOut() {
	if(self.location == self.location) {
	self.location.href = "checkout.html";
	}
}
function viewCart() {
	index = document.cookie.indexOf("TheBasket");
	countbegin = (document.cookie.indexOf("=", index) + 1);
   	countend = document.cookie.indexOf(";", index);
   	if (countend == -1) {
	countend = document.cookie.length;
	}
	fulllist = document.cookie.substring(countbegin, countend);
	totprice = 0;
	document.writeln('<FORM><DIV ALIGN="CENTER"><TABLE BORDER="0">');
	document.writeln('<TR><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Item:</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Quantity:</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Cost Each:</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Total Cost:</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Action:</P></TD></TR>');
	itemlist = 0;
	shippingquantity = 0;
	for (var i = 0; i <= fulllist.length; i++) {
	if (fulllist.substring(i,i+1) == '[') {
	itemstart = i+1;
	} else if (fulllist.substring(i,i+1) == ']') {
	itemend = i;
	thequantity = fulllist.substring(itemstart, itemend);
	shippingquantity = shippingquantity + (eval(1*thequantity));
	itemtotal = 0;
	itemtotal = eval(theprice*thequantity);
	temptotal = itemtotal * 100;
	totprice = totprice + itemtotal;
	itemlist=itemlist+1;
	document.writeln('<TR><TD ALIGN="LEFT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">'+theitem+'</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">'+thequantity+'</P></TD><TD ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">$ '+theprice+'&nbsp;</P></TD><TD ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">$ '+top.frame.alterError(itemtotal)+'&nbsp;</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><INPUT ID="listing" TYPE="BUTTON" VALUE="Remove" onClick="removeItem('+itemlist+')"></TD></TR>');
	} else if (fulllist.substring(i,i+1) == ',') {
	theitem = fulllist.substring(itemstart, i);
	itemstart = i+1;
	} else if (fulllist.substring(i,i+1) == '#') {
	theprice = fulllist.substring(itemstart, i);
	itemstart = i+1;
	}
	}
	document.writeln('<TR><TD COLSPAN="3" ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Sub Total:&nbsp;</P></TD><TD ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">$ '+top.frame.alterError(totprice)+'&nbsp;</P></TD></TR>');
	// discount functions go here
	document.writeln('</TABLE></DIV></FORM>');
}
function removeItem(itemno) {
	newItemList = null;
	itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++) {
	if (fulllist.substring(i,i+1) == '[') {
	itemstart = i+1;
	} else if (fulllist.substring(i,i+1) == ']') {
	itemend = i;
	theitem = fulllist.substring(itemstart, itemend);
	itemlist=itemlist+1;
	if (itemlist != itemno) {
	newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
	}
	}
	}
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket="+newItemList;
	location = "viewcart.html";
}
function clearBasket() {
	if (confirm('Are you sure you wish to clear the basket')) {
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket=.";
	location = "viewcart.html";
	}
}
function checkOut() {
	index = document.cookie.indexOf("TheBasket");
	countbegin = (document.cookie.indexOf("=", index) + 1);
   	countend = document.cookie.indexOf(";", index);
   	if (countend == -1) {
	countend = document.cookie.length;
   	}
	fulllist = document.cookie.substring(countbegin, countend);
	totprice = 0;
	document.writeln('<FORM ACTION="https://secure.authorize.net/gateway/transact.dll" METHOD="POST" TARGET="_top">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_LOGIN" VALUE="9921824">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_VERSION" VALUE="3.0">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_CUST_ID" VALUE="N/A">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_SHOW_FORM" VALUE="PAYMENT_FORM">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_RECIPIENT" VALUE="info@haleassociates.com">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_SUBJECT" VALUE="Web Site Order Form for Hale Associates">');
	document.writeln('<DIV ALIGN="CENTER"><TABLE BORDER="0">');
	document.writeln('<TR><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Item:</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Quantity:</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Cost Each:</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Total Cost:</P></TR>');
	itemlist = 0;
	theitem = 0;
	shippingquantity = 0;
	for (var i = 0; i <= fulllist.length; i++) {
	if (fulllist.substring(i,i+1) == '[') {
	itemstart = i+1;
	} else if (fulllist.substring(i,i+1) == ']') {
	itemend = i;
	thequantity = fulllist.substring(itemstart, itemend);
	shippingquantity = shippingquantity + (eval(1*thequantity));
	itemtotal = 0;
	itemtotal = (eval(theprice*thequantity));
	temptotal = itemtotal * 100;
	totprice = totprice + itemtotal;
	itemlist=itemlist+1;
	document.writeln('<TR><TD ALIGN="LEFT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">'+theitem+'</P></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">'+thequantity+'</P></TD><TD ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">$ '+theprice+'&nbsp;</P></TD><TD ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">$ '+alterError(itemtotal)+'&nbsp;</P></TD></TR>');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_PRODUCT'+itemlist+'" VALUE="'+theitem+'">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_PRODUCT'+itemlist+'_QUANT" VALUE="'+thequantity+'">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_PRODUCT'+itemlist+'_PRICE" VALUE="'+theprice+'">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_PRODUCT'+itemlist+'_TOTAL" VALUE="'+alterError(itemtotal)+'">');
	} else if (fulllist.substring(i,i+1) == ',') {
	theitem = fulllist.substring(itemstart, i);
	itemstart = i+1;
	} else if (fulllist.substring(i,i+1) == '#') {
	theprice = fulllist.substring(itemstart, i);
	itemstart = i+1;
	}
	}
	document.writeln('<TR><TD COLSPAN="3" ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="gradient.gif"><P ID="table">Sub Total:&nbsp;</P></TD><TD ALIGN="RIGHT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC" BACKGROUND="spacer_grey.gif"><P ID="listing">$ '+alterError(totprice)+'&nbsp;</P></TD></TR>');
	// discount functions go here
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_DESCRIPTION" VALUE="Please see merchant defined fields for itemization of entire order.">');
	document.writeln('<INPUT TYPE="HIDDEN" NAME="x_AMOUNT" VALUE="'+alterError(totprice)+'">');
	document.writeln('</TABLE></DIV>');
}
	// Setup for secure sever link; DESCRIPTION passes the information of the Items Ordered, both name and quantity; x_AMOUNT and x_GRANDTOTAL pass the value of Grand_Total; x_SUBTOTAL passes the value of Sub_Total; x_TAX passes the value of Tax; x_SHIPPING passes the value of Shipping; //
function calc(form) {
	x_SUBTOTAL = totprice;
	x_TAX = 0;
	x_SHIPPING = shippingquantity * 5.00;
	statechoice = form.x_State.selectedIndex
	state = form.x_State.options[statechoice].value
	if (form.x_State.options[statechoice].value == "Illinois") {
	x_TAX = (x_SUBTOTAL) * 0.0675;
	} else {
	x_TAX = 0;
	}
	x_GRANDTOTAL = x_SUBTOTAL + x_TAX + x_SHIPPING;
	x_AMOUNT = x_GRANDTOTAL;
	form.x_SUBTOTAL.value = convdec(x_SUBTOTAL);
	form.x_TAX.value = convdec(x_TAX);
	form.x_SHIPPING.value = convdec(x_SHIPPING);
	form.x_GRANDTOTAL.value = convdec(x_GRANDTOTAL);
	form.x_AMOUNT.value = convdec(x_AMOUNT);
}
function convdec(strng) {
	if (strng == 0) {
	return "0.00";
	} else {
	var str = "" + Math.round(strng * 100);
	return(str.substring(0, str.length-2) + "." + str.substring(str.length-2, str.length));
	}
}