
	function populateBillToWithShipTo() {
		// Amended 11/04/2007 - gweller
		// Grab the form in the proper DOM way.
		//var theForm = document.form;
		var theForm = document.forms["form"];
		
		if(theForm.shiptosameasbillto.value == "no" || theForm.shiptosameasbillto.value == "") {
			theForm.billtocompany.value = theForm.shiptocompany.value;
			theForm.billtoaddress.value = theForm.shiptoaddress.value;
			theForm.billtocity.value = theForm.shiptocity.value;
			theForm.billtocounty.value = theForm.shiptocounty.value;
			theForm.billtostate.value = theForm.shiptostate.value;
			theForm.billtozip.value = theForm.shiptozip.value;
			theForm.billtophone.value = theForm.shiptophone.value;
			theForm.billtofax.value = theForm.shiptofax.value;
			
			// reset it
			theForm.shiptosameasbillto.value = "yes";
		}
		else {
			theForm.billtocompany.value = "";
			theForm.billtoaddress.value = "";
			theForm.billtocity.value = "";
			theForm.billtocounty.value = "";
			theForm.billtostate.value = "";
			theForm.billtozip.value = "";
			theForm.billtophone.value = "";
			theForm.billtofax.value = "";
			
			// reset it
			theForm.shiptosameasbillto.value = "no";
		}
	}
	
	function validateForm(theForm) {
		if(theForm.shiptocompany.value == "") {
			alert("Please fill in the Ship To Company field.");
			return false;
		}
		if(theForm.shiptoaddress.value == "") {
			alert("Please fill in the Ship To Address field.");
			return false;
		}
		if(theForm.shiptocity.value == "") {
			alert("Please fill in the Ship To City field.");
			return false;
		}
		if(theForm.shiptostate.value.length < 1) {
			alert("Please select the Ship To State.");
			return false;
		}
		if(theForm.shiptozip.value == "") {
			alert("Please fill in the Ship To Zip field.");
			return false;
		}
		if(theForm.shiptophone.value == "") {
			alert("Please fill in the Ship To Phone field.");
			return false;
		}
		
		if(theForm.billtocompany.value == "") {
			alert("Please fill in the Bill To Company field.");
			return false;
		}
		if(theForm.billtoaddress.value == "") {
			alert("Please fill in the Bill To Address field.");
			return false;
		}
		if(theForm.billtocity.value == "") {
			alert("Please fill in the Bill To City field.");
			return false;
		}
		if(theForm.billtostate.value.length < 1) {
			alert("Please select the Bill To State.");
			return false;
		}
		if(theForm.billtozip.value == "") {
			alert("Please fill in the Bill To Zip field.");
			return false;
		}
		if(theForm.billtophone.value == "") {
			alert("Please fill in the Bill To Phone field.");
			return false;
		}
		
		if(theForm.company1.value == "") {
			alert("Please fill in the first company field under Credit References.");
			return false;
		}
		if(theForm.company1phone.value == "") {
			alert("Please fill in the first Company Phone field under Credit References.");
			return false;
		}
		
		if(theForm.company2.value == "") {
			alert("Please fill in the second company field under Credit References.");
			return false;
		}
		if(theForm.company2phone.value == "") {
			alert("Please fill in the second Company Phone field under Credit References.");
			return false;
		}
		
		if(!theForm.need1.checked && !theForm.need2.checked && !theForm.need3.checked) {
			alert("Please provide what your immediate need from MARKEM is");
			return false;
		}
		
		if(!theForm.tandc.checked) {
			alert("You must agree to the Terms and Conditions in order to proceed.");
			return false;
		}
		
		// Added 10/04/2007 - gweller
		//   Extra functions to handle CA tax exemption form and other amendments

		var anyTaxBoxChecked = false;
		anyTaxBoxChecked |= theForm.elements["c1"].checked;
		anyTaxBoxChecked |= theForm.elements["c2"].checked;
		anyTaxBoxChecked |= theForm.elements["c3"].checked;
		anyTaxBoxChecked |= theForm.elements["c4"].checked;
		anyTaxBoxChecked |= theForm.elements["c5"].checked;

		if(!anyTaxBoxChecked) {
			alert("You must check at least one box under State Tax Form.");
			return false;
		}
		
		if(theForm.elements["tax_agree_applicable"].value == "Y" && !theForm.elements["tax_agree"].checked) {
			alert("You must agree to fill out the California Sales and Use Tax Exemption certificate.");
			return false;
		}

		if(theForm.elements["purchasingfax"].value == "") {
			alert("Please fill in the Purchasing Fax field.");
			return false;
		}

		// Added 18/04/2007 - gweller
		if(theForm.elements["shiptofax"].value == "") {
			alert("Please fill in the Ship To Fax field.");
			return false;
		}

		return true;
	}
	
	// Added 10/04/2007 - gweller
	//   Functions to handle CA tax exemption form

	// Initialise new variables
	var isIE = (document.all);
	
	// Check for tax exemption in the sate of CA. If found, display object with id "ca_tax"
	function checkTax() {
		var form = document.forms["form"];
		var shipToState = form.elements["shiptostate"].value;
		
		var c1Checked = form.elements["c1"].checked;
		var c2Checked = form.elements["c2"].checked;
		var c3Checked = form.elements["c3"].checked;
		var c4Checked = form.elements["c4"].checked;
		var c5Checked = form.elements["c5"].checked;
		var taxExempt = (c1Checked || c2Checked || c3Checked || c4Checked) & !c5Checked;
		
		// Notice is needed if the state is CA and the checkboxes indicate tax exempt status.
		var needNotice = (shipToState == "California" && taxExempt);

		var noticeBoxId = "ca_tax";
		var noticeBox = document.getElementById(noticeBoxId);
		
		var alreadyShown = noticeBox.style.display == "block";

		// Set display to 'block', i.e. set the notice visible, if notice is needed.
		if(needNotice) {
			noticeBox.style.display = "block";
			form.elements["tax_agree_applicable"].value = "Y";
			
			if(!alreadyShown) {
				//scrollToElement(noticeBoxId);
				
				flashElement(noticeBoxId, 5, 200);
			}
		} else {
			noticeBox.style.display = "none";
			form.elements["tax_agree_applicable"].value = "N";
		}
	}
	
	// Indicate a newly shown box to the user by making it flash!
	// Relies on a CSS class 'flash', otherwise nothing will happen.
	function flashElement(flashBoxId, flashes, interval) {
		var flashBox = document.getElementById(flashBoxId);
		
		if(flashes > 0) {
			var currentClass = flashBox.className;
			var nextClass = "";
			
			if(currentClass == "") {
				nextClass = "flash";
			}
			flashBox.className = nextClass;

			var recurseCall = "flashElement('" + flashBoxId + "', " + (flashes-1) + ", " + interval + ");";
			setTimeout(recurseCall, interval);
		} else {
			// Clear the class to restore the original look
			flashBox.className = "";
		}
	}

	/*
	JUST IGNORE THIS! - Abandoned because it doesn't really work very well!
	function scrollToElement(elementId) {
		var scrollX = 0; // We'll assume the page fits horizontally.
		var scrollY = 0;
		
		var element = document.getElementById(elementId);
		var elementTop = 0;
		var elementHeight = element.offsetHeight;

		if(element.offsetParent) {
			elementTop = element.offsetTop
			while (element = element.offsetParent) {
				elementTop += element.offsetTop
			}
		}
		
		var elementBottom = elementTop + elementHeight;
		
		var currentScrollPos = document.scrollTop;
		//alert(currentScrollPos);
		
		if(currentScrollPos < elementBottom) {
			// We are above the element and so we need to scroll down to the
			// bottom of the element, so that the whole element is visible.
			scrollY = elementBottom;
		} else {
			// We are below the element and so we need to scroll up to the
			// top of the element, so that the whole element is visible.
			scrollY = elementTop;
		}
		
		window.scrollTo(scrollX, scrollY);
	}
	*/