//full source code visit http://www.dynamicdrive.com
var highlightcolor="#000066"
var ns6=document.getElementById&&!document.all
var previous=''
var eventobj
//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/
//Function to check whether element clicked is form element
function checkel(which){
	if (which.style&&intended.test(which.tagName)){
		if (ns6&&eventobj.nodeType==3)
		eventobj=eventobj.parentNode.parentNode
		return true
	}
	else return false
}
//Function to highlight form element
function highlight(e){
	eventobj=ns6? e.target : event.srcElement
	if (previous!=''){
	if (checkel(previous))
		previous.style.backgroundColor=''
			previous=eventobj
			if (checkel(eventobj))
			eventobj.style.backgroundColor=highlightcolor
		}
		else{
		if (checkel(eventobj))
		eventobj.style.backgroundColor=highlightcolor
		previous=eventobj
		}
	}


function sendEnquiry()
{
	var cform='';
	var theForm = eval(cform+'document.contactform');
	var theName = theForm.thename.value;
	var theEmail = theForm.theemail.value;
	var theStreet = theForm.thestreet.value;
	var theTown = theForm.thetown.value;
	var theCounty = theForm.thecounty.value;
	var theZip = theForm.thezip.value;
	var theCountry = theForm.country.options[theForm.country.selectedIndex].value;
	var theEnquiry = theForm.enquiry.value;
	if ((theForm.query.options[theForm.query.selectedIndex].value == null || theForm.query.options[theForm.query.selectedIndex].value =="none"))
	{
		alert('Please select the subject of your enquiry.')
		theForm.query.focus();
		return;
	}
	if (isEmpty(theEnquiry))
	{
		alert('Please fill in your enquiry in the space provided.');
		theForm.enquiry.value = '';
		theForm.enquiry.focus();
		return;
	}
	if (isEmpty(theName))
	{
		alert('Please fill in your name in the space provided.');
		theForm.thename.value = '';
		theForm.thename.focus();
		return;
	}
	if(!checkEmail(theEmail))
	{
		alert ('Sorry, the email address you entered is not in the correct format.\nPlease re-enter in the space provided.');
		theForm.theemail.value = '';
		theForm.theemail.focus();
		return;
	}
	if (isEmpty(theStreet))
	{
	alert('Please fill in your street name in the space provided.');
	theForm.thestreet.value = '';
	theForm.thestreet.focus();
	return;
	}
	if (isEmpty(theTown))
	{
	alert('Please fill in your town name in the space provided.');
	theForm.thetown.value = '';
	theForm.thetown.focus();
	return;
	}
	if(isEmpty(theZip))
	{
	alert("Your fill in your Postcode/Zipcode in the space provided.")
	theForm.thezip.value = '';
	theForm.thezip.focus();
	return;
	}
	if(!toAlphaNumber(theZip))
	{
	alert("Your Postcode may only contain alphanumerics")
	theForm.thezip.value = '';
	theForm.thezip.focus();
	return;
	}
	if (theCountry == 'Other')
	{
	theCountry = theForm.othercountry.value;
	}
	if (isEmpty(theCountry) || theCountry == 'none')
	{
	alert('Please indicate your country using the form provided');
	theForm.othercountry.value = '';
	theForm.othercountry.focus();
	return;
	}
		//var theMessage = 'Name: '+theName+'\n\ne-mail: '+theEmail+'\n\nAddress:\n'+theStreet+'\n'+theTown+'\n'+theCounty+'\n'+theZip+'\n'+theCountry+'\n\n';
		//theMessage = theMessage+'Enquiry:\n\n'+theEnquiry+'\n';
		//document.mailer.message.value=theMessage;
		//document.mailer.recipient.value=theForm.query.options[theForm.query.selectedIndex].value;
		//document.mailer.email.value=theEmail;
		// document.mailer.from.value=theEmail;
		// document.mailer.recipient.value= 'hotpoint.website@indesitcompany.com';
	document.contactform.submit();
}
function toAlphaNumber(postcodeString)
{
	newString = ""; // REVISED/CORRECTED STRING
	count = 0; // COUNTER FOR LOOPING THROUGH STRING
	// LOOP THROUGH STRING CHARACTER BY CHARACTER
	for (i = 0; i < postcodeString.length; i++) {
	ch = postcodeString.substring(i, i+1);
	// ENSURE CHARACTER IS AN ALPHA OR NUMERIC CHARACTER
	if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || (ch >= "0" && ch <= "9") || (ch == " ")) {
	newString += ch;
	}
	}
	if (postcodeString != newString) {
	return false;
	}
	else { return true; }
}
function isEmpty(inStr)
{
	var testStr = '';
	for (var i=0; i < 10; i++)
	{
		if(inStr==testStr) { return true; }
		testStr = testStr+' ';
	}
	return false;
}
function checkEmail(checkString)
{
	var newstr = "";
	var at = 0;
	var dot = false;
	
		for (var i = 0; i < checkString.length; i++) {
			ch = checkString.substring(i, i + 1)
			if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
			|| (ch == "@") || (ch == ".") || (ch == "_")
			|| (ch == "-") || (ch >= "0" && ch <= "9")) {
				newstr == ch;
				if (ch == "@") {
					at++;
				}
				if (ch == ".") {
					dot=true;
				}
			} else {
				return false;
			}
		}
	if ((at == 1) && (dot == true)) {
		//alert("at: "+at+" dot:"+dot)
		return true;
	}
	else {
		// DISPLAY ERROR MESSAGE
		//alert("at: "+at+" dot:"+dot)
		return false;
	}
}
