/*
	checkout.js
	contains all functions for the checkout information form
	validates form fields
	disables/enables delivery information fields
	date created: 16 july 2005
	author: ari rizos webology www.webology.net.au
*/

/*
	function validatecheckoutform()
	checks all form fields in the check out form
	date created: 16 july 2005
	author: ari rizos webology www.webology.net.au
*/

function validatecheckoutform()
{
	submitform = true;
	errormessage = "Error: \n";
	validatetextfield(document.forms[0].name, "Name");
	validatetextfield(document.forms[0].address, "Address");
	validatetextfield(document.forms[0].city, "City");
	validatetextfield(document.forms[0].state, "State");
	validatetextfield(document.forms[0].postcode, "Postcode");
	validatetextfield(document.forms[0].country, "Country");
	validatetextfield(document.forms[0].phone, "Phone");
	verification(document.forms[0].email, document.forms[0].verifyemail, "Emails");
	
	//if submit form is false, checkout information will not submit and error message will be displayed
	if(submitform == false){
		alert(errormessage);
	}	
	if(submitform == true){
		document.forms[0].submit();
	}
}

/*
	function cancelcheckout()
	a confirmation pop up box appears, clears all the fields and
	redirects the page back to shopping cart
	date created 16 july 2005
	author: ari rizos webology www.webology.net.au
*/
function cancelcheckout()
{
	var confirmcancel = confirm("Are you sure you want to cancel?");
	if(confirmcancel == true){
			document.forms[0].reset();
			window.location = "cart.php";
	}
}

/*	function changeaction()
	changes the form action parameter depending on what the user selects for the payment
	method
	date created	23 August 2005
	author			ari rizos www.webology.net
*/
function changeaction()
{
		if(document.forms[0].payment[0].checked == true){
			document.forms[0].action = "chequedetails.php";
		}
		
		if(document.forms[0].payment[1].checked == true){
			document.forms[0].action = "creditcarddetails.php";
		}
		
		if(document.forms[0].payment[2].checked == true){
			document.forms[0].action = "email/redirect.php";
		}
}

//	JavaScript blockEvent.js


/*	Function: blockEnter(event)
	Reference: JavaScript & DHTML Cookbook, from O'Reilly
	Chapter 8 Dynamic Forms
	www.webReference.com
*/

function blockEnter(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        return false;
    } else {
        return true;
    }
}