function noenter(e) { //WHAT DOES THIS FUNCTION DO???
	var code;
	if(e.keyCode) {
		code = e.keyCode;
	}
	else if(e.which) {
		code = e.which;
	}
	return !(code == 13);
}

function addressinfoSubmitCheck(storepath) {
	document.UpdateCart.getAttributeNode("action").value = storepath + "paymentdetails.cfm";
	document.UpdateCart.submit();
}

function RemoveItem(input, file_action) {
	document.getElementById(input).value = 0;
	document.UpdateCart.getAttributeNode("action").value = file_action;
	document.UpdateCart.submit();
}

function UpdateBasket(cartcontent, file_action) {
	invalid = false;
	
	var cartlength = cartcontent.length;
	for(var i = 1; i <= cartlength; i++) {
	//check all are numbers, if not set to 1
		if(!isNumeric(document.getElementById(cartcontent[i]).value)) {
			invalid = true;
			document.getElementById(cartcontent[i]).value = 1;
		}
	}

	if(invalid == true) {
		alert('Please enter only numbers in the quantity field');
	}
	document.UpdateCart.getAttributeNode("action").value = file_action;
	document.UpdateCart.submit();
}

function UpdateShipping(storepath) {
	document.UpdateCart.getAttributeNode("action").value = storepath + "updatecart2.cfm";
	document.UpdateCart.submit();
}

function validateBillingForm(){
	var errormessage = new Array;
	
	if(empty(document.getElementById("Ecom_BillTo_Postal_Name_First").value)) {
		errormessage[1] = '#Ecom_BillTo_Postal_Name_First_Label#';
	}
	if(empty(document.getElementById("Ecom_BillTo_Postal_Name_Last").value)) {
		errormessage[2] = '#Ecom_BillTo_Postal_Name_Last_Label#';
	}
	if(empty(document.getElementById("Ecom_BillTo_Postal_Street_Line1").value)) {
		errormessage[3] = '#Ecom_BillTo_Postal_Street_Line1_Label#';
	}
	if(empty(document.getElementById("Ecom_BillTo_Postal_City").value)) {
		errormessage[4] = '#Ecom_BillTo_Postal_City_Label#';
	}
	if(empty(document.getElementById("Ecom_BillTo_Postal_PostalCode").value)) {
		errormessage[5] = '#Ecom_BillTo_Postal_PostalCode_Label#';
	}

	if(empty(document.getElementById("Ecom_BillTo_Postal_CountryCode").value)) {
		errormessage[6] = '#Ecom_BillTo_Postal_CountryCode_Label#';
	}
	if(empty(document.getElementById("Ecom_BillTo_Telecom_Phone_Number").value)) {
		errormessage[7] = '#Ecom_BillTo_Telecom_Phone_Number_Label#';
	}
	if(empty(document.getElementById("Ecom_BillTo_Online_Email").value)) {
		errormessage[8] = '#Ecom_BillTo_Online_Email_Label#';
	}
	else {
		if(!isEmailAddr(document.getElementById("Ecom_BillTo_Online_Email").value)) {
			errormessage[9] = '#Ecom_BillTo_Online_Email_Label# is not valid';
		}
	}
	
	if(!empty(errormessage)) {
		alert("Please complete the following\n\n" + getErrorMessage(errormessage));
		return false;
	}
	else {
		return true;
	}	
}

function validateForgetForm() {
	var errormessage = new Array;

	if(empty(document.getElementById("forgot_username").value)) {
		errormessage[1] = 'Email Address';
	}
	else {
		if(!isEmailAddr(document.getElementById("forgot_username").value)) {
			errormessage[2] = 'Email Address is not valid';
		}
	}
	if(!empty(errormessage)) {
		alert("Please complete the following\n\n" + getErrorMessage(errormessage));
		return false;
	}
	else {
		return true;
	}
}

function validateLoginForm(theform) {

	tabline = "        ";
	alertmessage = "";
				
	if(theform.Username.value == "") {
		alertmessage += tabline +' - Email Address\n';
	}
	else {
		if(theform.Username.value == "" || theform.Username.value.indexOf ('@', 0) == -1 || theform.Username.value.indexOf ('.', 0) == -1) {
			alertmessage += tabline +' - Email Address is invalid\n';
		}
	}
						
	if(theform.Password.value == "") {
		alertmessage += tabline +' - Password\n';
	}
		
	if(alertmessage != "") {
		alert('The following fields must be completed\n' + alertmessage);
		return false;
	}
	return true;
}

function validateNewLoginForm(theform) {

	tabline = "        ";
	alertmessage = "";
		
	if(theform.Username.value == "") {
		alertmessage += tabline +' - Email Address\n';
	}
	else {
		if(theform.Username.value == "" || theform.Username.value.indexOf ('@', 0) == -1 || theform.Username.value.indexOf ('.', 0) == -1) {
			alertmessage += tabline +' - Email Address is invalid\n';
		}
	}
						
	if(theform.Password.value == "") {
		alertmessage += tabline +' - Password\n';
	}
		
	if(theform.ConfirmPassword.value == "") {
		alertmessage += tabline +' - Confirm Password\n';
	}
		
	if(theform.Password.value != "" && theform.ConfirmPassword.value != "") {
		if(theform.Password.value != theform.ConfirmPassword.value) {
			alertmessage += tabline +' - Password and Confirm Password must match\n';
		}
	}
		
	if(alertmessage != "") {
		alert('The following fields must be completed\n' + alertmessage);
		return false;
	}
	else {
		return true;
	}
}

function validatePasswordForm(){
	var errormessage = new Array;
	var pw_min_length = 6;
	
	if(empty(document.getElementById("username").value)) {
		errormessage[1] = 'Email Address';
	}
	else {
		if(!isEmailAddr(document.getElementById("username").value)) {
			errormessage[2] = 'Email Address is not valid';
		}
	}
	
	if(empty(document.getElementById("new_password").value) || empty(document.getElementById("new_confirm_password").value)) {
		if(empty(document.getElementById("new_password").value)) {
			errormessage[3] = 'New Password';
		}
		if(empty(document.getElementById("new_confirm_password").value)) {
			errormessage[4] = 'Confirm Password';
		}
	}
	else {	
		if(document.getElementById("new_password").value != document.getElementById("new_confirm_password").value) {
			errormessage[5] = 'New Password & Confirm Password do not match';
		}
		else {
			if(document.getElementById("new_password").value.length < pw_min_length || document.getElementById("new_confirm_password").value.length < pw_min_length) {
				errormessage[6] = 'New Password must be at least ' + pw_min_length + ' characters long';
			}
		}
	}
	
	if(!empty(errormessage)) {
		alert("Please complete the following\n\n" + getErrorMessage(errormessage));
		return false;
	}
	else {
		return true;
	}
}

function validatePaymentDetailsForm() {
	theform = document.payment;
	var errormessage = new Array;
	
	var today = new Date();
	var month = parseInt(today.getMonth() + 1);
	var year = parseInt(today.getFullYear());

	if(parseInt(theform.Ecom_Payment_Card_SrtDate_Month.value) > month && parseInt(theform.Ecom_Payment_Card_SrtDate_Year.value) >= year) {
		errormessage[1] = 'Start Date Invalid';
	}
	
	//check year, then month
	if(parseInt(theform.Ecom_Payment_Card_ExpDate_Year.value) <= year) {
		if(parseInt(theform.Ecom_Payment_Card_ExpDate_Month.value) < month) {
			errormessage[2] = 'Expiry Date Invalid';
		}
	}

	if(empty(theform.Ecom_Payment_Card_Name.value)) {
		errormessage[3] = 'Card Name';
	}
	
	theform.Ecom_Payment_Card_Number.value = removeSpaces(theform.Ecom_Payment_Card_Number.value);
	if(empty(theform.Ecom_Payment_Card_Number.value)) {
		errormessage[4] = 'Card Number';
	}
	else { //not empty
		
		if (!isNumeric(theform.Ecom_Payment_Card_Number.value)){
			errormessage[5] = 'Card Number Invalid';
		}
	}
	
	theform.issuenumber.value = removeSpaces(theform.issuenumber.value);
	if(!empty(theform.issuenumber.value)) {
		if (!isNumeric(theform.issuenumber.value)) {
			errormessage[6] = 'Issue Number Invalid';
		}
	}
	
	theform.securitycode.value = removeSpaces(theform.securitycode.value);
	if(empty(theform.securitycode.value)) {
		errormessage[7] = 'Security Code';
	}
	else{ //not empty
		if (!isNumeric(theform.securitycode.value)) {
			errormessage[8] = 'Security Code Invalid';
		}
	}

	if(theform.termsandconditions.checked == false) {
		errormessage[9] = 'Terms and Conditions';
	}
	
	if(!empty(errormessage)) {
		alert("Please complete the following\n\n" + getErrorMessage(errormessage));
		return false;
	}
	else {
		return true;
	}
}

function validateReviewsForm() {
	alertmessage = "";
	
	var myTextField1 = document.getElementById('review').value;
	var myTextField2 = document.getElementById('title').value;
	var myTextField3 = document.getElementById('posted').value;
	
	if(myTextField2 == "") {
		alertmessage += '- Your Name\n';
	}
	if(myTextField1 == "") {
		alertmessage += '- Subject\n';
	}
	if(myTextField3 == "") {
		alertmessage += '- Review\n';
	}
	
	if(alertmessage == "") {
		return true;
	}	
	else {
		TopMessage = "You have not entered the following form elements correctly: \n\n";
    	BottomMessage = "\nPlease correct these fields to continue";
    	alertmessage = TopMessage + alertmessage + BottomMessage;
    	alert(alertmessage);
		return false;
	}
}

function validateShippingForm() {
	var errormessage = new Array;
	
	if(empty(document.getElementById("Ecom_ShipTo_Postal_Name_First").value)) {
		errormessage[1] = '#Ecom_ShipTo_Postal_Name_First_Label#';
	}
	if(empty(document.getElementById("Ecom_ShipTo_Postal_Name_Last").value)) {
		errormessage[2] = '#Ecom_ShipTo_Postal_Name_Last_Label#';
	}
	if(empty(document.getElementById("Ecom_ShipTo_Postal_Street_Line1").value)) {
		errormessage[3] = '#Ecom_ShipTo_Postal_Street_Line1_Label#';
	}
	if(empty(document.getElementById("Ecom_ShipTo_Postal_City").value)) {
		errormessage[4] = '#Ecom_ShipTo_Postal_City_Label#';
	}
	if(empty(document.getElementById("Ecom_ShipTo_Postal_PostalCode").value)) {
		errormessage[5] = '#Ecom_ShipTo_Postal_PostalCode_Label#';
	}

	if(empty(document.getElementById("Ecom_ShipTo_Postal_CountryCode").value)) {
		errormessage[6] = '#Ecom_ShipTo_Postal_CountryCode_Label#';
	}
	
	if(!empty(errormessage)) {
		alert("Please complete the following\n\n" + getErrorMessage(errormessage));
		return false;
	}
	else {
		return true;
	}	
}


