// 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("If you update your details, please be sure to click the 'Update Details' button to save your changes before proceeding with your order. If you do not click this button your details will not be saved");
		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("If you update your address details, please be sure to click the appropriate 'Update Details' button to save your changes before proceeding with your order. If you do not click this button your address will not 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'});

}
//////////////////////////////////////////////////////////////////////////////////////
function updateAddressFields(type){ // set the address type on the new address panel

	if (type == "any"){
		// do nothing.
	}
	
	if (type == "s"){
				if (document.getElementById("shippingAddress")){
					var addressString = document.getElementById("shippingAddress").value;
					addressArray = addressString.split(',  ');
					
					if(addressArray[0] != undefined)
						window.document.lgoCartForm.sh_address1.value = addressArray[0];
					else
						window.document.lgoCartForm.sh_address1.value = '';
					if(addressArray[1] != undefined)
						window.document.lgoCartForm.sh_address2.value = addressArray[1];
					else
						window.document.lgoCartForm.sh_address2.value = '';
					if(addressArray[2] != undefined)
						window.document.lgoCartForm.sh_address3.value = addressArray[2];
					else
						window.document.lgoCartForm.sh_address3.value = '';
					if(addressArray[3] != undefined)
						window.document.lgoCartForm.sh_postcode.value = addressArray[3];
					else
						window.document.lgoCartForm.sh_postcode.value = '';
					if(addressArray[4] != undefined)
						window.document.lgoCartForm.sh_country.value = addressArray[4];
					else
						window.document.lgoCartForm.sh_country.value = '';
				}
	}
	
	if (type == "b"){
				if (document.getElementById("billingAddress")) {
					var addressString = document.getElementById("billingAddress").value;
					addressArray = addressString.split(',  ');
			
					if(addressArray[0] != undefined)
						window.document.lgoCartForm.ch_address1.value = addressArray[0];
					else
						window.document.lgoCartForm.ch_address1.value = '';
					if(addressArray[1] != undefined)
						window.document.lgoCartForm.ch_address2.value = addressArray[1];
					else
						window.document.lgoCartForm.ch_address2.value = '';
					if(addressArray[2] != undefined)
						window.document.lgoCartForm.ch_address3.value = addressArray[2];
					else
						window.document.lgoCartForm.ch_address3.value = '';
					if(addressArray[3] != undefined)
						window.document.lgoCartForm.ch_postcode.value = addressArray[3];
					else
						window.document.lgoCartForm.ch_postcode.value = '';
					if(addressArray[4] != undefined)
						window.document.lgoCartForm.ch_country.value = addressArray[4];
					else
						window.document.lgoCartForm.ch_country.value = '';
				}
	}

}
//////////////////////////////////////////////////////////////////////////////////////


