/*
 Carpenter Goodwin - Javascript
---------------------------------------------------------
  Copyright©2008 Red Cherry Solutions Ltd.
  http://www.RedCherrySolutions.co.uk
 
  Single use permitted for Carpenter Goodwin Limited.
  Website provided by 7Y Services Limited.
  http://www.7Y.co.uk

  Duplication of this script or any associated scripts
  in whole or in part is strictly forbidden.
---------------------------------------------------------
*/

/* Swap the active CSS */
function setActiveStyleSheet(title) {
	if (document.getElementsByTagName) {
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) a.disabled = true;
			if (a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

/* validate the checkout form */
function validateCheckout(oForm) {

	var bValid = true;

	//shipping country
	if (oForm.deliveryCountry.options[oForm.deliveryCountry.selectedIndex].value == '0') {
		alert('Please fill out all required fields *');
		bValid = false;
		return false;
	}
	if (oForm.deliveryCountry.options[oForm.deliveryCountry.selectedIndex].value == 'other') {
		alert('We cannot complete your order online. Please contact us to complete this order and arrange delivery to another country.');
		bValid = false;
		return false;
	}

	//check delivery form
	if (oForm.deliveryName.value == '' || 
		oForm.deliveryAddress.value == '' || 
		oForm.deliveryTel.value == '' || 
		oForm.deliveryTown.value == '' ||
		oForm.deliveryPostcode.value == '' ||
		oForm.customerEmail.value == '') {
		bValid = false;
	}

	//return correctly
	if (bValid == false) {
		alert('Please fill out all required fields *');
		return false;
	}
}

/* validate the registration form */
function validateRegistration(oForm) {

	if (oForm.terms.checked == false) {
		alert('You must state that you accept the terms and conditions to register.');
		return false;
	} else {
		var bValid = true;

		//check password and confirm
		//check for registration and password
		if (oForm.password.value.length < 5) {
			alert('Your password must be 5 or more characters.');
			return false;
		}
		if (oForm.password.value != oForm.confirm.value) {
			alert('Your password and confirmation do not match.');
			return false;
		}

		//check for valid email
		if (oForm.email.value.length < 5) {
			alert('Your email address must be valid.');
			return false;
		}

		//check form
		if (oForm.fullName.value == '' || 
			oForm.address1.value == '' || 
			oForm.postcode.value == '' ||
			oForm.telephone.value == '') {
			bValid = false;
		}

		//return correctly
		if (bValid == false) {
			alert('Please fill out all required fields *');
			return false;
		}
	}
}

/* validate the password reset form */
function validateReset(oForm) {

	var bValid = true;

	//check password and confirm
	//check for registration and password
	if (oForm.password.value.length < 5) {
		alert('Your password must be 5 or more characters.');
		return false;
	}
	if (oForm.password.value != oForm.confirm.value) {
		alert('Your password and confirmation do not match.');
		return false;
	}
}

/* validate the login form */
function validateLogin(oForm) {
	var bValid = true;

	//check form
	if (oForm.email.value == '' || oForm.password.value == '') {
		alert('Please enter your login information.');
		return false;
	}
}