(function populateForm() {
	var i, l, obj, hash,
	hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	
	// init
	for (i = 0, l = hashes.length; i < l; i++) {
		hash = hashes[i].split('=');
		obj = document.getElementById(hash[0]);
		if (obj) {
			obj.value = hash[1];
		}
	}
})();

function validateIntForm() {
	var i, l, field, email2,
	emailPatt = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/,
	reqFields = ['fname', 'lname', 'address', 'city', 'postal-code', 'phone', 'email', 'product-url-1', 'qty-1', 'payment', 'ship-estimate'];
	
	for (i = 0, l = reqFields.length; i < l; i++) {
		field = document.getElementById(reqFields[i]);
		if (reqFields[i] === 'email') {
			email2 = document.getElementById('email2');
			if (field.value !== email2.value || !emailPatt.test(field.value)) {
				alert('Please make sure to enter your email correctly in both fields.');
				field.focus();
				return false;
			}
		} else {
			if (field.value === '') {
				alert('Please fill in all required fields marked by *');
				field.focus();
				return false;
			}
		}
	}
	return true;
}
