// jshop.js JavaScript Development by JavaScriptDesign.com
// ****Begin shopping cart functions.****
// ** global variables for the shopping cart.**

var itemNum = new Array();
var itemDescr = new Array();
var itemCost = new Array();
var itemQt=new Array();
var extCst=new Array();
var cost_adj=new Array();
var grand_total = "0.00"
var sShippingType;
var sCountry="";
function OnLoader()
{
	GetCustomerDetails()
	update()
	PutField("AUTHORISED","TRUE")
	document.shopCart.notes.value=""
	document.shopCart.notes2.value=""
	document.shopCart.notes3.value=""
}

// **Function to parse the cookie and extract the ordered **
// **items from the string. This in turn triggers the **
// **writeCart() function to display the shopping cart. **

function itemsOrdered() {
 if (getCookieData("Scart")) {
 substr0 = getCookieData("Scart")
 cLen = substr0.length
 offset0 = substr0.indexOf("@")
 counter = substr0.substring(0,offset0)
 j = 0;
 for (i=1; i<=counter; i++) {
  offsetq = eval('offset' + j + '');
  substrq = eval('substr' + j + '');
  eval('ind' + i + ' = offsetq + 1');
  eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
  eval('offset' + i + ' = substr' + i + '.indexOf("^")');
  eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
  eval('catInd' + i + ' = item' + i + '.indexOf("`")');
  eval('itemCat' + i + ' = item' + i + '.substring(0,catInd' + i + ')');
  eval('catqt' + i + ' = item' + i + '.indexOf("*")');
  eval('qtcat' + i + ' = item' + i + '.substring((catInd'+i+'+1),catqt' + i + ')');
  eval('descrInd' + i + ' = item' + i + '.indexOf("~")');
  eval('itemDes' + i + ' = item' + i + '.substring((catqt' + i + ' + 1),descrInd' + i + ')');
  eval('itemPr' + i + ' = item' + i + '.substring((descrInd' + i + ' + 2),offset' + i + ')'); 
  eval('orderDetail(i,itemCat' + i + ',qtcat' + i + ',itemDes' + i + ',itemPr' + i + ')');
  j++
 }
 writeCart();
 }
}

// **Builds an array of the items to load the cart.**

function orderDetail(seq,num,qt,descr,cost) 
{
	itemNum[seq] = num
 	itemQt[seq] = qt
 	itemDescr[seq] = descr
 	itemCost[seq] = cost
}




// ** Function to write the shopping cart details **
// ** into the table on the shopping cart page.
function writeCart() 
{
	sCountry=GetFieldValue("Country");
	var ordFrm = '<p>'
	// **** CONTENTS OF SHOPPING CART ****
	ordFrm += '<table border=1 align=center width="90%" >	'
	ordFrm += '<tr><td>Item</td><td>Item Description</td><td align="center">Item<br>Price</td><td align="center">Order<br>Qty</td><td align="center">Extended<br>Cost</td><td align="center">Click to<br>Remove</td></tr>'
	for (i = 1; i <= counter; i++) {
		//000605 
		cost_adj[i] = itemCost[i]
		if (itemQt[i] > 4 && itemQt[i] < 10) {
			cost_adj[i] = itemCost[i]*.85  
		}
		if (itemQt[i] > 9 && itemQt[i] < 100) {
			cost_adj[i] = itemCost[i]*.80  
		}
		if (itemQt[i] > 99) {
			cost_adj[i] = itemCost[i]*.75  
		}


//040916============================ Lower Discounts 5 = 5%, 10 = 10%, 100 = 20%
		if (itemDescr[i].charAt(1) == '!') // is the first chr a !?? //5%

		if (itemQt[i] > 4 && itemQt[i] < 10) { 
			cost_adj[i] = itemCost[i]*.95  
		}
//============================
		if (itemDescr[i].charAt(1) == '!') // is the first chr a !?? //10%

		if (itemQt[i] > 9 && itemQt[i] < 100) {
			cost_adj[i] = itemCost[i]*.90 
		}
//============================
		if (itemDescr[i].charAt(1) == '!') // is the first chr a !?? //15%		

		if (itemQt[i] > 99) {
			cost_adj[i] = itemCost[i]*.85 
		}

//============================

		if (itemDescr[i].charAt(1) == '#') { // is the first chr a #?? //0%
			cost_adj[i] = itemCost[i]

		}
//============================







		// ----------------------------------
		cost_adj[i] = fix(cost_adj[i])
		extCst[i]=eval(cost_adj[i]*itemQt[i])
		ordFrm += '<tr><td>' + itemNum[i] + '</td>'
		ordFrm += '<td>' + itemDescr[i].split(":")[0] + '</td>'
		ordFrm += '<td align="center">' + cost_adj[i] + '</td>'
		ordFrm += '<td align="center">' + itemQt[i] + '</td>'
		ordFrm += '<td align="center">' + fix(extCst[i]) + '</td>'
		ordFrm += '<td align=center><a href="javascript:clearIt('+i+')">Remove</a></td></tr>'
		ordFrm += '<input type="Hidden" name="item'+itemNum[i]+'" value="'+ itemDescr[i].split(":")[0]+' cost = '+cost_adj[i]+' quantitiy='+itemQt[i]+' extended price:'+fix(extCst[i])+' ">' 
	}
	ordFrm += '<tr><td align=right colspan=4>SUB TOTAL AUD$: </td><td>'

//041202

  	ordFrm += '<input type="text" name="subTotal" size=8 maxlength=8 value="0.00" '


  	ordFrm += 'onFocus="document.shopCart.subTotal.blur()"></td><td>&nbsp; </td></tr>'
  	
	// shipping -----------------------------------------
	ordFrm += '<tr><td align=right colspan=4>' + writeShipping() + '</td><td align=center> &nbsp; </td></tr>'	
	if(sCountry == "AUS"){
		ordFrm += '<tr><td align=left colspan=6> <font color="black"><B>'
		ordFrm += '$5AUD now covers small and large packages. '
		ordFrm += 'Printed Circuit Board Only Orders (min $20AUD) are post free, as these can '
		ordFrm += 'be posted as a letter. This doesn\'t include components. Use $5AUD '
		ordFrm += 'shipping if components are ordered also. </font><BR><P>' 
		


		ordFrm += '<FONT color="red">Australia Post Overnight Bag</FONT> <BR>'
		ordFrm += 'To allow adequate time to process and pack goods, orders submitted to us '
		ordFrm += 'by 12 noon will be despatched on the same day as they are received, whenever possible. '
		ordFrm += 'Orders received after 12 noon will be despatched in an Overnight Bag at '
		ordFrm += '9.00 am on the next business day. <BR><P>'


		
		ordFrm += '<FONT color="red">Products that have the shipping price included in the '
		ordFrm += 'cost are post free. In many cases, additional goods can be sent with the same '
		ordFrm += 'package at no additional cost.</FONT> <BR>'
		
		ordFrm += '<FONT color=#3333ff>If unsure, please check with us first by sending an email '
		ordFrm += 'order for price verification. This can then be followed up with the final order, '
		ordFrm += 'as your order details are saved in the order form.</FONT></B>'
		
		ordFrm += '</td></tr>'
	}
  	if(sCountry == "USA" || sCountry == "OT"){
		ordFrm += '<tr><td align=left colspan=6> <font color="black"><B>'
		ordFrm += '$10AUD is the most common Air Mail shipping amount. If you are unsure, use '
		ordFrm += '$10AUD. Printed Circuit Board Only Orders (min $20AUD) are post free, as '
		ordFrm += 'these can be posted as an air mail letter. This doesn\'t include components. Use '
		ordFrm += '$10AUD shipping if components are ordered also.  Larger orders are $15AUD '
		ordFrm += 'shipping.  <BR><B><FONT '
		ordFrm += 'color=#ff0000>Products that have the shipping price included in the cost are ' 
		ordFrm += 'post free. In many cases, additional goods can be sent with the same package at '
		ordFrm += 'no additional cost.</FONT></B> <BR><B><FONT color=#3333ff>If unsure, please '
		ordFrm += 'check with us first by sending an email order for price verification. This can '
		ordFrm += 'then be followed up with the final order, as your order details are saved in the '
		ordFrm += 'order form. </FONT></B>	'
		ordFrm += '</td></tr>'
	}
	if(sCountry == "NZ"){
		ordFrm += '<tr><td align=left colspan=6> <font color="black"><B>'
		ordFrm += '$6AUD is the most common Air Mail shipping amount. If you are unsure, use $6AUD. '
		ordFrm += 'Printed Circuit Board Only Orders (min $20AUD) are post free, as these can '
		ordFrm += 'be posted as an air mail letter. This doesn\'t include components. Use $6AUD '
		ordFrm += 'shipping if components are ordered also. Larger orders are $9AUD shipping. A ' 
		ordFrm += 'cable will put the shipping into this class. <BR><B><FONT color=#ff0000>Products '
		ordFrm += 'that have the shipping price included in the cost are post free. In many cases, ' 
		ordFrm += 'additional goods can be sent with the same package at no additional '
		ordFrm += 'cost.</FONT></B> <BR><B><FONT color=#3333ff>If unsure, please check with us '
		ordFrm += 'first by sending an email order for price verification. This can then be '
		ordFrm += 'followed up with the final order, as your order details are saved in the order '
		ordFrm += 'form. </FONT></B> '
		ordFrm += '</td></tr>'
	}

	// GST ----------------------------------------
	if(sCountry == "AUS"){
		ordFrm += '<tr><td align=right colspan=4>Australian Resident? If so Is this product subject to Australian GST?: &nbsp; <br><a href="gst.html">GST Explanation </a>&nbsp;Effective 1-Jul-2000<input type="radio" '
  		ordFrm += 'name="GST_Payable" value="No"  onClick=update()>No<input type="radio" '
	  	ordFrm += 'name="GST_Payable" value="Yes" CHECKED onClick=update()>Yes = 10.00% GST</td><td> '

// 041202
  		ordFrm += '<input type="text" name="GST_Tax_Paid" size=8 maxlength=8 value="0.00" '


  		ordFrm += 'onFocus="document.shopCart.GST_Tax_Paid.blur()"</td><td align=center> &nbsp; </td></tr>'

		ordFrm += '<tr><td align=left colspan=6> <font color="red" >'
		ordFrm += 'This menu is default set to Yes. If you answer No, then it means you selected '
		ordFrm += 'it, and must understand the reasons why it is GST Free. If your selection is '
		ordFrm += 'incorrect, you will be asked for additional funds. <BR><B><FONT '
		ordFrm += 'color=#ff0000>All file and key orders are subject to GST for Australians, so you '
		ordFrm += 'must answer Yes to this question.</FONT></B> <BR><B><FONT color=#3333ff>If '
		ordFrm += 'unsure, please check with us first by sending an email order for price '
		ordFrm += 'verification. This can then be followed up with the final order, as your order '
		ordFrm += 'details are saved in the order form. </FONT></B><BR>'
		ordFrm += 'If the goods purchased are shipped from Dontronics Australia, to an '
		ordFrm += 'Australian address, then click the <B>"Yes"</B> radio button.  This includes ' 
		ordFrm += 'all software keys or files. GST must be paid on these items.  Goods marked '
		ordFrm += '"GST Free" on the order page, are physical goods that are shipped directly to '
		ordFrm += 'the customer from overseas suppliers. We can\'t charge GST, as you may be liable ' 
		ordFrm += 'for GST when the goods arrive in the country, and this would mean double GST. '
		ordFrm += 'There is a full GST explanation for Australian customers <A '
		ordFrm += 'href="gst.html">here.</A> If you have a mixture of GST free, and GST payable '
		ordFrm += 'items, you must submit individual orders for each group of items. (Yes we '
		ordFrm += 'love the Australian Taxation system too) :-) <BR><B><FONT color=#ff0000>If '
		ordFrm += 'unsure, leave the GST set to Yes, and we will credit any over-payment back to '
		ordFrm += 'you.</FONT></B><I><FONT color=#cc33cc></FONT></I>'
		ordFrm += '</font></td></tr>'
	}
	else{

//041202
  		ordFrm += '<input type="hidden" name="GST_Tax_Paid" size=8 maxlength=8 value="0.00" '


	}

// grand total ------------------------------------
	ordFrm += '<tr><td align=right colspan=4> <font color="red" >Totals Will Be Confirmed &nbsp;&nbsp;&nbsp;&nbsp;  </font><a href="gst.html#round">Rounding and GST</a>&nbsp; GRAND TOTAL AUD$: </td><td align=left><input type="text" '

//041202
  	ordFrm += 'name="grandtotal_AUD" size=8 maxlength=8 value="0.00" '

  	ordFrm += 'onFocus="document.shopCart.grandtotal_AUD.blur()"></td>&nbsp; <td align=center>&nbsp;  '  	
  	ordFrm += '<font color="red"></font></td></tr></table>'

  	document.write(ordFrm);
  	document.close();
}

function manual()
{
	PutField("AUTHORISED","FALSE")
	if(validate_form()){
		document.location="okmanual.html"
	}
}

// ** Function to delete a line item upon user request. **

function clearIt(num) 
{
 itemNum[num] = "item"
 rewriteCookie(num)
}

// **Function to rewrite the cookie when the user **
// **deletes a line item from the shopping cart. **

function rewriteCookie(num) 
{
	dataUpdate = ""
	for (i=1; i<=counter; i++) {
   		if (itemNum[i] != "item") {
	   		dataUpdate += itemNum[i] + '`' + itemQt[i] + '*' + itemDescr[i] + '~$' + itemCost[i] + '^'
		}
	}
 	counter = counter - 2
 	cookData = dataUpdate
 	if (counter >= 0) {
  		setCookieData("Scart", cookData, expdate.toGMTString())
  		history.go(0)
 	} 
 	else 
 	{ 
  		killCookie("Scart")
		history.go(-1)
	}
}

// ***************************** U P D A T E **************************
// ****End shopping cart detail section.****
// ****Start of code section to display subtotal.****

function update() 
{
	if (getCookieData("Scart")) {
  		var sub_total = 0;
  		for (i=1; i<itemNum.length; i++)
   			eval('sub_total += parseFloat(extCst[' + i + ']);');
  		document.shopCart.subTotal.value= fix(sub_total);

		// *********** SHIPPING ***********
		shippingCost()
		with_Shipping = shipCost
		document.shopCart.ShipCharges.value = fix(with_Shipping)
		
		// ************ calc gst **************
		taxes = fix(sub_total) * .10 // adjust for your tax rate.		
		if(sCountry == "AUS"){
			if (document.shopCart.GST_Payable[0].checked) {
				GST_Taxes = "0.00"
				//grand_total  = "0.00"
				document.shopCart.GST_Tax_Paid.value = "0.00"
				GST_Shipping = 0
			}
			else 
			{
				GST_Shipping = fix(with_Shipping) * .10
				GST_Taxes = fix(taxes+GST_Shipping)
				document.shopCart.GST_Tax_Paid.value = (GST_Taxes)
			}
		}
		else
		{
				GST_Taxes = "0.00"
				//grand_total  = "0.00"
				document.shopCart.GST_Tax_Paid.value = "0.00"
				GST_Shipping = 0
		}
		grand_total = sub_total + taxes + with_Shipping + GST_Shipping
		noTaxTotal = sub_total + with_Shipping
// DON: This is where the limit is specified
   

		if(sCountry == "AUS"){
			if (document.shopCart.GST_Payable[0].checked) {
				document.shopCart.grandtotal_AUD.value = fix(Math.floor(noTaxTotal)) // GT output to lower integer.
			}
			else 
			{
				grand_total = Math.floor(grand_total) // GT output to lower integer.
				document.shopCart.grandtotal_AUD.value = fix(grand_total)
				document.shopCart.GST_Tax_Paid.value = fix(grand_total/11)
			}
		}
		else{
				document.shopCart.grandtotal_AUD.value = fix(Math.floor(noTaxTotal)) // GT output to lower integer.
		}
		
		// BANK FIELD
		document.shopCart.AMT.value=document.shopCart.grandtotal_AUD.value
 	}
}

function fix(num) 
{
// fix fix 000503 new
	var decplaces = 2
  	var str = "" + Math.round (eval(num) * Math.pow(10,decplaces))
  	while (str.length <= decplaces) {
  		str = "0" + str
  	}
  	var decpoint = str.length - decplaces
  	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
	return str;
}



// ****************************************************************************
// **** VALIDATE FORM DATA **** -------------------------------------
// ****************************************************************************

function pre_validate_form() {
	if (validate_form()){
		//var w = window.open('','payform','width=550,height=550,resiazable=yes,status=yes,scrollbars=yes');
		return true;
	}else {
		return false;
	}
}


function validate_form() {

	Today = new Date
	
	document.shopCart.MTID.value=document.shopCart.firstName.value.slice(0,1) + document.shopCart.LastName.value.slice(0,1) + formatStr(Today.getUTCDate()) + formatStr(eval(Today.getUTCMonth()+1)) + formatStr(Today.getUTCHours())+ formatStr(Today.getUTCMinutes())
	document.shopCart.NAME.value=document.shopCart.firstName.value + " " + document.shopCart.LastName.value

	check_order()
	StoreCustomerDetails()  

document.shopCart._SBILL_IN_bill_id.value = document.shopCart.MTID.value;
var cost = document.shopCart.AMT.value;

document.shopCart.SessionID.value = document.shopCart.MTID.value;
document.shopCart.PurchaseAmount.value = cost.substr(0,cost.indexOf("."))+cost.substr(cost.indexOf(".")+1);

document.shopCart._SBILL_IN_dollar_amount.value = cost.substr(0,cost.indexOf(".")); 
document.shopCart._SBILL_IN_cents_amount.value = cost.substr(cost.indexOf(".")+1);

	
// 	return true;

	if (document.shopCart.firstName.value == "") {
  		alert('You must enter your first name!');
  		document.shopCart.firstName.focus();
		return (false);
	}

	if (document.shopCart.LastName.value == "") {
  		alert('You must enter your last name!');
  		document.shopCart.LastName.focus();
		return (false);
	}
	
	if (document.shopCart.EMAIL.value == "") {
		alert('You must enter your email address!');
		document.shopCart.EMAIL.focus();
		return (false);
	}

	if (document.shopCart.phone.value == "") {
  		alert('You must enter your phone number! (and fax if applicable)');
  		document.shopCart.phone.focus();
		return (false);
	}

	if ((document.shopCart.address1.value == "") && (document.shopCart.address1.value == "")) {
  		alert('You must enter a street address!');
  		document.shopCart.address1.focus();
		return (false);
	}
	if (document.shopCart.city.value == "") {
		alert('You must enter a city!');
		document.shopCart.city.focus();
		return (false);
	}
	
	if (document.shopCart.state.value == "") {
  		alert('You must enter a state or province!');
  		document.shopCart.state.focus();
		return (false);
	}
	if (document.shopCart.country.value == "") {
  		alert('You must enter a Country!');
  		document.shopCart.country.focus();
		return (false);
	}

	if (document.shopCart.zip.value == "") {
  		alert('You must enter your zip code or postal code!');
  		document.shopCart.zip.focus();
		return (false);
	}
	if (document.shopCart.ShipVia.options[document.shopCart.ShipVia.selectedIndex].value == "Enter Shipping Type")
	{
  		alert('Please choose a shipping option');
  		document.shopCart.ShipVia.focus();
		return (false);
	}

	
	
	
	//var w = window.open('','payform','width=450,height=550,resiazable=yes,status=yes,scrollbars=yes');
 	//document.shopCartDummy.submit();
	
	return true;
	
}
 

function check_order() 
{
	var sNotes
// THESE FIELDS ARE CALCULATED (only stored for sending the order)	
// put shipping
	PutField("ShipType",document.shopCart.ShipVia.options[document.shopCart.ShipVia.selectedIndex].value)
	PutField("ShipCharges", document.shopCart.ShipCharges.value)

// put GST
	PutField("GST_Tax_Paid",document.shopCart.GST_Tax_Paid.value)

// put TOTALS
	PutField("subTotal",document.shopCart.subTotal.value)
	PutField("grandtotal",document.shopCart.grandtotal_AUD.value)
	PutField("GST_Tax_Paid",document.shopCart.GST_Tax_Paid.value)

// 
	sNotes=""
	if(document.shopCart.notes.value != "")
		sNotes = document.shopCart.notes.value + " "

	if(document.shopCart.notes2.value != "")
		sNotes += document.shopCart.notes2.value + " "

	if(document.shopCart.notes3.value != "")
		sNotes += document.shopCart.notes3.value

	if (sNotes == "")
		sNotes="NONE"
	PutField("instructions",sNotes)

	PutField("MTID",document.shopCart.MTID.value)
//	PutField("EMAIL",document.shopCart.EMAIL.value)
}

// ********************* STORE CUSTOMER DETAILS ***********************

function StoreCustomerDetails()
{
// Put customer details into a cookie
	var sCookieData
	sCookieData = ""
	sCookieData += "FirstName" + "@@" + document.shopCart.firstName.value + "**"
	sCookieData += "LastName" + "@@" + document.shopCart.LastName.value + "**"
	sCookieData += "CompanyName" + "@@" + document.shopCart.company_name.value + "**"
	sCookieData += "OrderNo" + "@@" + document.shopCart.orderNo.value + "**"
	sCookieData += "address1" + "@@" + document.shopCart.address1.value + "**"
	sCookieData += "address2" + "@@" + document.shopCart.address2.value + "**"
	sCookieData += "city" + "@@" + document.shopCart.city.value + "**"
	sCookieData += "state" + "@@" + document.shopCart.state.value + "**"
	sCookieData += "zip" + "@@" + document.shopCart.zip.value + "**"
	sCookieData += "country" + "@@" + document.shopCart.country.value + "**"
	sCookieData += "phone" + "@@" + document.shopCart.phone.value + "**"
	sCookieData += "fax" + "@@" + document.shopCart.fax.value + "**"
	sCookieData += "email" + "@@" + document.shopCart.EMAIL.value + "**"
	sCookieData += "dummy" + "@@" + "Nothing" + "**"
	PutField("Customer",sCookieData)
}

// ********************* RECALL CUSTOMER DETAILS ***********************
function GetCustomerDetails()
// Get customer details from a cookie
{
	var sCookieData
	var sEmail
	sCookieData = GetFieldValue("Customer").split("**")
	if (sCookieData != ""){
		document.shopCart.firstName.value = sCookieData[0].split("@@")[1]
		document.shopCart.LastName.value = sCookieData[1].split("@@")[1]
		document.shopCart.company_name.value = sCookieData[2].split("@@")[1]
//		document.shopCart.orderNo.value = sCookieData[3].split("@@")[1]
		document.shopCart.address1.value = sCookieData[4].split("@@")[1] 
		document.shopCart.address2.value = sCookieData[5].split("@@")[1]
		document.shopCart.city.value = sCookieData[6].split("@@")[1]
		document.shopCart.state.value = sCookieData[7].split("@@")[1]
		document.shopCart.zip.value = sCookieData[8].split("@@")[1]
		document.shopCart.country.value = sCookieData[9].split("@@")[1]
		document.shopCart.phone.value = sCookieData[10].split("@@")[1]
		document.shopCart.fax.value = sCookieData[11].split("@@")[1]
		document.shopCart.EMAIL.value = sCookieData[12].split("@@")[1]
	}
	if(sCountry == "USA")
		document.shopCart.country.value = "USA"

	if(sCountry == "AUS")
		document.shopCart.country.value = "AUSTRALIA"

	if(sCountry == "NZ")
		document.shopCart.country.value = "NEW ZEALAND"
		
//	sEmail = GetFieldValue("EMAIL") // added because the email addres was getting corrupted
//	if(sEmail !="") 
//		document.shopCart.EMAIL.value = sEmail
		
}


// *************** COOKIE FUNCTIONS ************************

function GetFieldValue(cookieName)
{
	thisCookie=document.cookie.split("; ")
	for(i=0 ; i < thisCookie.length ; i++)
	{
		if(cookieName == thisCookie[i].split("=")[0]){
			return(thisCookie[i].split("=")[1])
		}
	}
	return("")
}

function PutFieldName(CookieData,CookieValue)
{
	expireDate = new Date
	expireDate.setMonth(expireDate.getMonth()+6)	
	document.cookie = CookieData + "=" + CookieValue + "; expires=" + expireDate.toGMTString()	// or use "Thu, 08-Apr-2010 00:00:01 GMT" 
}

function PutField(CookieData,CookieValue)
{
	expireDate = new Date
	expireDate.setMonth(expireDate.getMonth()+6)	
	if(CookieValue.length > 1){
		document.cookie = CookieData + "=" + CookieValue + "; expires=" + expireDate.toGMTString()	
	}
	else {
		document.cookie = CookieData + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
//		document.cookie = CookieData + "=" + " " + "; expires=" + expireDate.toGMTString()	
	}
}

// **Function to clear the shopping cart.**

function killCart() {
 killCookie("Scart")
 history.go(-1)
}


// 
function killCustomerData()
{
	killCookie("AUTHORISED")

	killCookie("EMAIL")
	killCookie("ShipType")
	killCookie("ShipCharges")
	killCookie("GST_Tax_Paid")
	killCookie("subTotal")
	killCookie("grandtotal")
	killCookie("inst")

	killCookie("instructions")
	killCookie("MTID")
	killCookie("Customer")
}



function ClearCustomerDetails(CookieData)
// Clear customer details cookie
{
	document.cookie = CookieData + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}


// ******* SHIPPING *********

function writeShipping() {
 // you can change the values in the shipping pop-up menu
 // by changing the values in the options array below

	leng = 5;
	options = new Array(leng);
	
	options[0] = "Enter Shipping Type";
 	options[1] = "Free or Shipping charges included as indicated";
  	if(sCountry == "USA" || sCountry == "OT"){
		options[2] = "International Small Package to 250gms $10AUD";
		options[3] = "International Large Package to 500gms $15AUD";
 		options[4] = "EMS Postal Courier $65AUD";
	}
	if(sCountry == "AUS"){
		options[2] = "Australia Small & Large Packages, $5AUD";

// *********************************************************************
// Alternate the following two lines of code for overnight bags.

		options[3] = "Aust Post Office Yellow Over Night Bag $12AUD";
		options[4] = "Aust P.O. Web Trackable Platinum Over Night Bag $20AUD";

//		options[3] = "Sorry, Overnight Bag Options suspended for a few days";
//		options[4] = "Sorry, Overnight Bag Options suspended for a few days";

// Alternate the above two lines of code for overnight bags.
// *********************************************************************

	}
	if(sCountry == "NZ"){
//		options[2] = "New Zealand Small Package to 250gms $6AUD";
//		options[3] = "New Zealand Large Package to 500gms $9AUD";

		options[2] = "New Zealand Small & Large Package $8AUD";
		options[3] = "New Zealand Small & Large Package $8AUD";

        	options[4] = "EMS Postal Courier $65AUD";
	}
	html_code2 = "";
 	html_code2 += 'SHIPPING and HANDLING: &nbsp; <select size=1 '  + 'name="ShipVia" onChange="update()">';
	for (o=0;o<leng;o++)
  		html_code2 += '<option value="'+options[o]+'"' + ((o==0) ? ' selected>':'>') + options[o];
	html_code2 += '</select><br>'
	html_code2 += '</td><td>';
	html_code2 += '<input type="text" name="ShipCharges" size=6 '

//041202
	html_code2 += 'maxlength=8 value="0.00" '


	html_code2 += 'onFocus="document.shopCart.ShipCharges.blur()">';
	return html_code2;
}


// **These definitions correspond to the shipping select**
// **options defined in the writeShipping() function.**

function shippingCost() 
{
	shipCost = 0
  	if(sCountry == "USA"){
		if (document.shopCart.ShipVia.options[0].selected)
		   shipCost = 0
 		if (document.shopCart.ShipVia.options[1].selected) 
   			shipCost = 0
 		if (document.shopCart.ShipVia.options[2].selected)
   			shipCost = 10
		if (document.shopCart.ShipVia.options[3].selected) 
   			shipCost = 15
   		if (document.shopCart.ShipVia.options[4].selected) 
   			shipCost = 65
   	}

  	if(sCountry == "NZ"){
		if (document.shopCart.ShipVia.options[0].selected)
		   shipCost = 0
 		if (document.shopCart.ShipVia.options[1].selected) 
   			shipCost = 0
 		if (document.shopCart.ShipVia.options[2].selected)
   			shipCost = 8
		if (document.shopCart.ShipVia.options[3].selected) 
   			shipCost = 8
   		if (document.shopCart.ShipVia.options[4].selected) 
   			shipCost = 65
         }   	

  	if(sCountry == "AUS"){
		if (document.shopCart.ShipVia.options[0].selected)
		   shipCost = 0
 		if (document.shopCart.ShipVia.options[1].selected) 
   			shipCost = 0
 		if (document.shopCart.ShipVia.options[2].selected)
   			shipCost = 5
		if (document.shopCart.ShipVia.options[3].selected) 
   			shipCost = 12
		if (document.shopCart.ShipVia.options[4].selected) 
   			shipCost = 20
        }

  	if(sCountry == "OT"){
		if (document.shopCart.ShipVia.options[0].selected)
		   shipCost = 0
 		if (document.shopCart.ShipVia.options[1].selected) 
   			shipCost = 0
 		if (document.shopCart.ShipVia.options[2].selected)
   			shipCost = 10
		if (document.shopCart.ShipVia.options[3].selected) 
   			shipCost = 15
   		if (document.shopCart.ShipVia.options[4].selected) 
   			shipCost = 65}
		}


function check_email(oItem) 
{
	if( oItem.value==" " ||
		oItem.value.indexOf('\@', 0) == -1 ||
		oItem.value.indexOf('.', 0) == -1 ||
		oItem.value.length < 8)
	{
			window.alert("Type in a REAL email address!");
			oItem.focus();
	}

	if( 	oItem.value.indexOf('hotmail', 0) != -1 ||
		oItem.value.indexOf('yahoo.', 0) != -1 


//041105
		||
		oItem.value.indexOf('gmail.', 0) != -1 

	  )
	{
		window.alert("Sorry! We don't accept email orders from that domain!");			oItem.focus();
	}

	document.shopCart.EMAIL.value=oItem.value
}

function formatStr(sString)
{
	if (sString < 10)
		sString= "0" + sString
	return sString
}



