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

	// SH Address
	window.document.lgoCartForm.sh_address1.value = window.document.lgoCartForm.ch_address1.value;
	window.document.lgoCartForm.sh_address2.value = window.document.lgoCartForm.ch_address2.value;
	window.document.lgoCartForm.sh_address3.value = window.document.lgoCartForm.ch_address3.value;
	window.document.lgoCartForm.sh_postcode.value = window.document.lgoCartForm.ch_postcode.value;
	window.document.lgoCartForm.sh_country.value  = window.document.lgoCartForm.ch_country.value;
	
}
//////////////////////////////////////////////////////////////////////////////////////
function validateOrderForm() {
	
	// set flag to true as default
	var flag = true
	
	// Reset all old errors
		var element = document.getElementById('name');
		element.style.backgroundColor = '#FFFFFF';

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

		var element = document.getElementById('email');
		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('mobilephone');
		element.style.backgroundColor = '#FFFFFF';

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

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

		var element = document.getElementById('ch_postcode');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('ch_country');
		element.style.backgroundColor = '#FFFFFF';
		
		// SH Address
		var element = document.getElementById('sh_address1');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('sh_address2');
		element.style.backgroundColor = '#FFFFFF';

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

		var element = document.getElementById('sh_postcode');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('sh_country');
		element.style.backgroundColor = '#FFFFFF';
		
		// Card Payment
		var element = document.getElementById('nameoncard');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('cardno');
		element.style.backgroundColor = '#FFFFFF';
				
		var element = document.getElementById('endmonth');
		element.style.backgroundColor = '#FFFFFF';
		
		var element = document.getElementById('endyear');
		element.style.backgroundColor = '#FFFFFF';

		var element = document.getElementById('securitycode');
		element.style.backgroundColor = '#FFFFFF';
		
		
	// Check if feild are filled in
	if (!window.document.lgoCartForm.name.value) {
		var element = document.getElementById('name');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.sname.value) {
		var element = document.getElementById('sname');
		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.length < 6) {
		var element = document.getElementById('phoneday');
		element.style.backgroundColor = '#FF3333';
		//flag = false;
	}
	if (window.document.lgoCartForm.phoneday.length < 6) {
		var element = document.getElementById('phoneeve');
		element.style.backgroundColor = '#FF3333';
		//flag = false;
	}
	if (window.document.lgoCartForm.phoneday.length < 6) {
		var element = document.getElementById('mobilephone');
		element.style.backgroundColor = '#FF3333';
		//flag = false;
	}
	
	// CH Address
	if (!window.document.lgoCartForm.ch_address1.value) {
		var element = document.getElementById('ch_address1');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.ch_address2.value) {
		var element = document.getElementById('ch_address2');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.ch_address3.value) {
		var element = document.getElementById('ch_address3');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.ch_postcode.value) {
		var element = document.getElementById('ch_postcode');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.ch_country.value) {
		var element = document.getElementById('ch_country');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	
	// SH Address
	if (!window.document.lgoCartForm.sh_address1.value) {
		var element = document.getElementById('sh_address1');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.sh_address2.value) {
		var element = document.getElementById('sh_address2');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.sh_address3.value) {
		var element = document.getElementById('sh_address3');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.sh_postcode.value) {
		var element = document.getElementById('sh_postcode');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.sh_country.value) {
		var element = document.getElementById('sh_country');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	
	// Card Payment
	if (!window.document.lgoCartForm.nameoncard.value) {
		var element = document.getElementById('nameoncard');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.cardno.value) {
		var element = document.getElementById('cardno');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.endmonth.value) {
		var element = document.getElementById('endmonth');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.endyear.value) {
		var element = document.getElementById('endyear');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}
	if (!window.document.lgoCartForm.securitycode.value) {
		var element = document.getElementById('securitycode');
		element.style.backgroundColor = '#FF3333';
		flag = false;
	}

	if(!flag) alert('Please check the red form fields and end date of card.');
	
	// return flag
	return flag;
}
//////////////////////////////////////////////////////////////////////////////////////
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;
	}

}
//////////////////////////////////////////////////////////////////////////////////////
var changedAddressWarningFlag = false; // set a global var so that we can test against it in following method
function changeAddress(){ // when a feild is change throw an alert to make sure that the user saves.

	if (!document.changedAddressWarningFlag){
		alert("Once you have entered the address details. Please click the 'Add Address' button, your address will then be saved.");
		document.changedAddressWarningFlag = 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'});

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

