/* author: sales@wheatgrassjuicer.com.au */
/* Generated by AceHTML Freeware http://freeware.acehtml.com */
/* Creation date: 3/15/2004 */
// CREDITS:
// Dirty Form-Check
// by Urs Dudli and Peter Gehrig 
// Copyright (c) 2000 Peter Gehrig and Urs Dudli. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.24fun.ch.
// info@24fun.ch
// 2/29/2000

// IMPORTANT: 
// If you add this script to a script-library or script-archive 
// you have to add a link to http://www.24fun.ch on the webpage 
// where this script will be running.

var submitcount=0;
var valid = "0123456789";

var agree = 0;  // 0 means 'no', 1 means 'yes'

function checkFields(emailStr) {                       // field validation -
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var matchArray = emailStr.match(emailPat);

if (document.order.firstname.value=="") {
	alert("Please enter your first name.")
	document.order.firstname.focus();
	return false
}

if (document.order.lastname.value=="") {
	alert("Please enter your last name.")
	document.order.lastname.focus();
	return false
}

if (document.order.streetname.value=="") {
	alert("Please enter your street name.")
	document.order.streetname.focus();
	return false
}

if (document.order.suburb.value=="") {
	alert("Please enter your suburb or city name.")
	document.order.suburb.focus();
	return false
}

if (document.order.state.value.length=="") {
	alert("Please select your State.");
	document.order.state.focus();
	return false;
}

if (document.order.postcode.value=="") {
	alert("Please enter your post code.");
	document.order.postcode.focus();
	return false
}

for (var i=0; i < document.order.postcode.value.length; i++) {
	temp = "" + document.order.postcode.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") {
		alert("Invalid characters in your post code.  Please try again.");
		document.order.postcode.focus();
		return false;
	}
}

if (document.order.postcode.value.length!=4) {
	alert("Please enter your 4 digit post code.");
	document.order.postcode.focus();
	return false;
}

if (document.order.email.value=="") {
	alert("Please enter your email address.");
	document.order.email.focus();
	return false;
}

// make sure the IP address domain is valid
var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
if (IPArray != null) {
    for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
		alert("Destination IP address is invalid!");
		document.order.email.focus();
		return false;
      	}
   }
}

if (document.order.phone.value=="") {
	alert("Please enter your phone number.");
	document.order.phone.focus();
	return false;
}

if (document.order.mk3juicers.value==0 && document.order.easypack2.value==0) {
	alert("You must order at least one juicer.");
	document.order.easypack2.focus();
	return false;
}

if (document.order.paymentmethod.value=="") {
	alert("Please select your method of payment.")
	document.order.paymentmethod.focus();
	return false;
}

if (document.order.TermsOfUse.checked!=1) {
	alert("Please acknowledge that you've read and accepted our Terms & Conditions.")
	document.order.TermsOfUse.focus();
	return false;
}

else 
   {
      if (submitcount == 0)
      {
      submitcount++;
	  document.order.ref.value = Math.round(Math.pow(10,10)*Math.random());

if (document.order.paymentmethod.value == "Paymate") {
	document.order.success_page.value="https://www.paymate.com/PayMate/ExpressPayment?mid=cynlia&ref="+document.order.ref.value+"&amt="+document.order.totalprice.value+"&PMT_SENDER_EMAIL="+document.order.email.value+"&PMT_CONTACT_FIRSTNAME="+document.order.firstname.value+"&PMT_CONTACT_SURNAME="+document.order.lastname.value+"&regindi_address1="+document.order.streetname.value+"&regindi_address2="+document.order.streetname2.value+"&regindi_sub="+document.order.suburb.value+"&regindi_pcode="+document.order.postcode.value;
	document.order.nextsteps.value="We will be posting your item to you within 2 business days after receiving payment.";
	alert("Please wait while we take you to the Paymate website to complete your order.");
}

//https://www.paypal.com/xclick/business=wj@grad.com
//https://66.111.61.145/cgi-bin/webscr?cmd=_ext-enter&redirect_cmd=_xclick&business=wj@grad.com

else if (document.order.paymentmethod.value == "Paypal") {

document.order.success_page.value="https://www.paypal.com/xclick/business=wj@grad.com&&item_name=Wheatgrass+Juicer&item_number="+document.order.ref.value+"&amount="+document.order.totalprice.value+"&currency_code=AUD&lc=AU&first_name="+document.order.firstname.value+"&last_name="+document.order.lastname.value+"&address="+document.order.streetname.value+"&address2="+document.order.streetname2.value+"&city="+document.order.suburb.value+"&zip="+document.order.postcode.value+"&day_phone_a="+document.order.phone.value+"&email="+document.order.email.value;
	document.order.nextsteps.value="We will be posting your item to you within 2 business days after receiving payment.";
	alert("Please wait while we take you to the Paypal website to complete your order. ");
}


else if (document.order.paymentmethod.value == "BankDeposit"){	 
	document.order.nextsteps.value="Please deposit into - BSB: 036048. Account: 151988. Bank name: Westpac Bank. Account Name: Wai Sze Kwok. Please include your full name as reference. We will be posting your item to you within 2 business days after receiving payment.";
	document.order.success_page.value="http://www.wheatgrassjuicer.com.au/cgi-bin/success.cgi?p=1&firstname={firstname}&lastname={lastname}&streetname={streetname}&streetname2={streetname2}&suburb={suburb}&state={state}&postcode={postcode}&email={email}&phone={phone}&originaljuicers={originaljuicers}&mk3juicers={mk3juicers}&totalprice={totalprice}&paymentmethod={paymentmethod}&paymentcomments={paymentcomments}&ref={ref}&comments={comments}&nextsteps={nextsteps}&totalpricelabel={totalpricelabel}";
}

else if (document.order.paymentmethod.value == "MoneyOrder"){	 
	document.order.nextsteps.value="Please address your money order to 'Wai Sze Kwok' and post to Wai Sze Kwok, PO Box 1122, Joondalup DC, WA 6919, Australia. Please include your full name as reference. We will be posting your item to you within 2 business days after receiving payment.";
	document.order.success_page.value="http://www.wheatgrassjuicer.com.au/cgi-bin/success.cgi?p=1&firstname={firstname}&lastname={lastname}&streetname={streetname}&streetname2={streetname2}&suburb={suburb}&state={state}&postcode={postcode}&email={email}&phone={phone}&originaljuicers={originaljuicers}&mk3juicers={mk3juicers}&totalprice={totalprice}&paymentmethod={paymentmethod}&paymentcomments={paymentcomments}&ref={ref}&comments={comments}&nextsteps={nextsteps}&totalpricelabel={totalpricelabel}";
} 
else if (document.order.paymentmethod.value == "Cheque"){	 
document.order.nextsteps.value="Please address your cheque to 'Wai Sze Kwok' and post to Wai Sze Kwok, PO Box 1122, Joondalup DC, WA 6919, Australia. Please include your full name as reference. We will be posting your item to you within 2 business days after receiving payment.";
document.order.success_page.value="http://www.wheatgrassjuicer.com.au/cgi-bin/success.cgi?p=1&firstname={firstname}&lastname={lastname}&streetname={streetname}&streetname2={streetname2}&suburb={suburb}&state={state}&postcode={postcode}&email={email}&phone={phone}&originaljuicers={originaljuicers}&mk3juicers={mk3juicers}&totalprice={totalprice}&paymentmethod={paymentmethod}&paymentcomments={paymentcomments}&ref={ref}&comments={comments}&nextsteps={nextsteps}&totalpricelabel={totalpricelabel}";
} 
      return true;
      }
   else 
      {
      alert("This form has already been submitted.  Thanks!");
      return false;
      }
   }
}

function Reset() {
document.order.paymentmethod.value = "";
document.order.paymentcomments.value = "";
}

function openWindow(strURL)
        {
            addWindow = self.open(strURL,'addWindow','height=500,width=750,scrollbars=1,toolbar=1','alwaysRaised=true');
            addWindow.focus();
        }


function Update_Comments() {

Calculate_Total();
if (document.order.paymentmethod.value == "") {
document.order.paymentcomments.value="";
}

if (document.order.paymentmethod.value == "Paymate") {
document.order.paymentcomments.value="After you click the Submit button, You will be transferred to the Paymate website to complete your order. This may take a few minutes, depending on your Internet connection. After your Paymate payment is successful (for which you will receive a Paymate Transaction ID and payment has cleared into our bank account, we will ship your juicer/s within 2-3 business days. You will also be emailed a confirmation of your order.";
document.order.totalpricelabel.value="(AUD)";
return true;
}

if (document.order.paymentmethod.value == "Paypal") {
document.order.paymentcomments.value="After you click the Submit button, You will be transferred to the Paypal website to complete your order. This may take a few minutes, depending on your Internet connection. After your Paypal payment is successful (for which you will receive a Paypal Transaction ID and payment has cleared into our bank account, we will ship your juicer/s within 2-3 business days. You will also be emailed a confirmation of your order.";
document.order.totalpricelabel.value="(AUD)";
return true;
}

if (document.order.paymentmethod.value == "BankDeposit" || document.order.paymentmethod.value == "MoneyOrder") {
document.order.paymentcomments.value="After you click the Submit button, you will be emailed a confirmation of the order details above, along with instructions on how to pay. Once payment has cleared into our bank account, we will ship your juicer/s within 2-3 business days.";
document.order.totalpricelabel.value="(AUD)";
return true;
}

if (document.order.paymentmethod.value == "Cheque" || document.order.paymentmethod.value == "Cheque") {
document.order.paymentcomments.value="After you click the Submit button, you will be emailed a confirmation of the order details above, along with instructions on how to pay. Once payment has cleared into our bank account, we will ship your juicer/s within 2-3 business days.";
document.order.totalpricelabel.value="(AUD)";
return true;
}
}		

function Calculate_Total() {
var totalprice=0

Check_Seed();

/************** No Original juicer pack **************
if (document.order.easypack1.value==1)	{
totalprice=79;
}
else	{
totalprice=79*document.order.easypack1.value;
}
*/

if (document.order.easypack2.value==1)	{
totalprice+=98;
}
else	{
totalprice+=98*document.order.easypack2.value;
}

/********** No Original any more ******************
if (document.order.originaljuicers.value==1)	{
totalprice+=69;
}
else	{
totalprice+=69*document.order.originaljuicers.value;
}
*/


if (document.order.mk3juicers.value==1)	{
totalprice+=79;
}
else	{
totalprice+=79*document.order.mk3juicers.value;
}

if (document.order.kit.value==1)	{
totalprice+=5;
}
else	{
totalprice+=5*document.order.kit.value;
}

if (document.order.seeds.value==2)	{
totalprice+=5;
}

if (document.order.state.value=="NZ")	{
totalprice+=20;
}

//if (document.order.paymentmethod.value == "Paypal") {
//totalprice*=.82;
//}


document.order.totalprice.value=Math.round(totalprice*Math.pow(10,2))/Math.pow(10,2);
}

function Check_Seed() {

if (document.order.state.value=="NZ")	{
	if (document.order.seeds.value == 1 || document.order.seeds.value == 2) {
		alert("I'm afraid I cannot ship wheatgrass seeds outside of Australia. I'll uncheck the seed option. Please note that an extra $AU20 will be addded to total price for postage to New Zealand")
		document.order.seeds.value = "0";
		Calculate_Total();
		} 
	}
}

// - End of JavaScript - -->