// Scripts used on the order Foam
//////////////////////////////////////////////////////////////////////////////////////
function copyCHAddress(){

	// SH Address
	window.document.lgoCartForm.shipping1.value = window.document.lgoCartForm.billing1.value;
	window.document.lgoCartForm.shipping2.value = window.document.lgoCartForm.billing2.value;
	window.document.lgoCartForm.shipping3.value = window.document.lgoCartForm.billing3.value;
	window.document.lgoCartForm.shipping_postcode.value = window.document.lgoCartForm.billing_postcode.value;
	window.document.lgoCartForm.shipping_country.value  = window.document.lgoCartForm.billing_country.value;
	
}
//////////////////////////////////////////////////////////////////////////////////////
function validateOrderForm(sentAction) {
	
	// set flag to true as default
	var flag = true
	
	// Reset all old errors
		var element = document.getElementById('firstname');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('lastname');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('email');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('password');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('password2');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('phoneday');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('phoneeve');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('phonemob');
		element.style.backgroundColor = '#FFFFFF';

		// CH Address
		var element = document.getElementById('billing1');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('billing2');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('billing3');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('billing_postcode');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('billing_country');
		element.style.backgroundColor = '#FFFFFF';
		
		// SH Address
		var element = document.getElementById('shipping1');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('shipping2');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('shipping3');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('shipping_postcode');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('shipping_country');
		element.style.backgroundColor = '#FFFFFF';
				
		
	// Check if feild are filled in
	if (!window.document.lgoCartForm.firstname.value) {
		var element = document.getElementById('firstname');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.lastname.value) {
		var element = document.getElementById('lastname');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.email.value) {
		var element = document.getElementById('email');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.phoneday.value) {
		var element = document.getElementById('phoneday');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.phoneeve.value) {
		var element = document.getElementById('phoneeve');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.phonemob.value) {
		var element = document.getElementById('phonemob');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	
	// CH Address
	if (!window.document.lgoCartForm.billing1.value) {
		var element = document.getElementById('billing1');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.billing2.value) {
		var element = document.getElementById('billing2');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.billing3.value) {
		var element = document.getElementById('billing3');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.billing_postcode.value) {
		var element = document.getElementById('billing_postcode');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.billing_country.value) {
		var element = document.getElementById('billing_country');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	
	// SH Address
	if (!window.document.lgoCartForm.shipping1.value) {
		var element = document.getElementById('shipping1');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.shipping2.value) {
		var element = document.getElementById('shipping2');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.shipping3.value) {
		var element = document.getElementById('shipping3');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.shipping_postcode.value) {
		var element = document.getElementById('shipping_postcode');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.shipping_country.value) {
		var element = document.getElementById('shipping_country');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	
	if (window.document.lgoCartForm.password.value != window.document.lgoCartForm.password2.value) {
			var element = document.getElementById('password');
			element.style.backgroundColor = '#FF3333';
			var element = document.getElementById('password2');
			element.style.backgroundColor = '#FF3333';
			flag = false;
			alert('Passwords do not match.')
	}
	

	if(!flag) alert('Please check the red form fields.');
	
	if(flag) {
		document.getElementById('appAction').setAttribute("value",sentAction);
		window.document.lgoCartForm.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////
var changedWarningFlag = false; // set a global var so that we can test against it in following method
function changeData(){ // when a feild is change throw an alert to make sure that the user saves.

	if (!document.changedWarningFlag){
		alert("When you have finished editing your details, make sure you press the 'Update Details' button, this will then make sure we know about your changes.");
		document.changedWarningFlag = true;
	}

}
//////////////////////////////////////////////////////////////////////////////////////
function showAddressPanel(type){ // set the address type on the new address panel

	if (type == "any"){
		// do nothing.
	}
	
	if (type == "s"){
		window.document.lgoCartForm.typeFlag.options[0].selected = true
	}
	
	if (type == "b"){
		window.document.lgoCartForm.typeFlag.options[1].selected = true
	}

	new Effect.BlindDown('newAddressForm', {direction: 'center'});

}
//////////////////////////////////////////////////////////////////////////////////////
