function showother() {
	var iamasel = document.getElementById('iama').options[document.getElementById('iama').selectedIndex].value;
	var otherdiv = document.getElementById('theother');
	var otherdivinput = document.getElementById('theotherinput');
	if(iamasel == "Other"){
		otherdiv.style.display = '';
		otherdivinput.style.display = '';
		document.getElementById('other').style.backgroundColor = '#fff4eb';
		document.getElementById('other').focus();
	}
	else{
		otherdiv.style.display = 'none';
		otherdivinput.style.display = 'none';
	}
}

function loader(success) {
	//alert(success);
	if (!success)	{pageTracker._trackPageview("/funnel_G1/form_show.html");}
	else	{pageTracker._trackPageview("/funnel_G1/form_completed.html");}
}

function unhighlight(obj) {
	if(!obj.value.match(/please select/) && obj.value.match(/\w+/)){
		if(obj.id.match(/^(phone|email)$/)){
			document.getElementById('phone').style.backgroundColor = '';
			document.getElementById('email').style.backgroundColor = '';
		}
		else{
			obj.style.backgroundColor = '';
		}
	}
}
function validate()	{
	var validPostCode = /^[a-z]{1,2}(\d{1,2}|\d[a-z]{0,1}) \d[a-z]{2}$/i;
	var validEmail = /^[\w\.\-\']+@[\w\-]+\.[\w\-]+(\.[\w\-]+)?(\.[\w\-]+)?(\.[\w\-]+)?$/;
	for(i = 0; i < document.forms[0].elements.length; i++){
  		var fmElement = document.forms[0].elements[i];
  		if(fmElement.id == 'full_name' && !fmElement.value.match(/\w+/)){
  			alert("Please enter your Full Name");
  			fmElement.style.backgroundColor = '#fff4eb';
  			fmElement.focus();
  			return false;
  		}
  		else if(fmElement.id == 'postcode' && !fmElement.value.match(validPostCode)){
  			alert("Please enter a valid Postcode");
  			fmElement.style.backgroundColor = '#fff4eb';
  			fmElement.focus();
  			return false;
  		}
  		else if (fmElement.id == "addresslist" && document.getElementById('addresslist').style.display != "none")	{
  			 if (fmElement.length == 0){
  			 	
  			 	var postcode = document.getElementById('postcode').value;
  			 	postcode = postcode.toUpperCase();
 				var size = postcode.length;
				while (postcode.slice(0,1) == " ") //Strip leading spaces
  				{postcode = postcode.substr(1,size-1);size = postcode.length;}
 				while(postcode.slice(size-1,size)== " ") //Strip trailing spaces
  				{postcode = postcode.substr(0,size-1);size = postcode.length;}
  			 	
  			 	alert("No Addresses found for " + postcode + ". Please enter a different postcode");
  			 	document.getElementById('addresslist').style.display = "none";
  				document.getElementById('postcode').style.backgroundColor = '#fff4eb';
  				document.getElementById('postcode').value = "";
  				document.getElementById('postcode').focus();
  				return false;
  			}
  			else 	 if (fmElement.selectedIndex < 0){
  				alert("Please select your Address from the list");
  				fmElement.style.backgroundColor = '#fff4eb';
  				fmElement.focus();
  				return false;
  			}
  		}
  		else if (fmElement.id == 'phone'){
  			
  			if (!document.getElementById('addresslist') || document.getElementById('addresslist').style.display == "none"){
  				alert("Please click on 'Lookup Address' and select your address");
  				return false;
  			}
  			
  			var ph = document.getElementById('phone');
  			if (!ph.value.match(/\w+/)){
  				alert("Please enter a telephone number");
  				ph.style.backgroundColor = '#fff4eb';
  				fmElement.focus();
  				return false;
  			}
  		}
  		else if(fmElement.id == 'email'){
  			var em = document.getElementById('email');
  			if(em.value && !em.value.match(validEmail)){
  				alert("Please enter a valid email address");
  				em.style.backgroundColor = '#fff4eb';
  				fmElement.focus();
  				return false;
  			}
  		}
  		else if(fmElement.selectedIndex == 0){
  			alert("Please select an option for '" + fmElement.title + "'");
  			fmElement.style.backgroundColor = '#fff4eb';
  			fmElement.focus();
  			return false;
  		}
  		else if(fmElement.id == 'iama'){
  			var ia = document.getElementById('iama');
  			var ot = document.getElementById('other');
  			if(ia.value == "Other" && !ot.value.match(/\w+/)){
  				alert("Please specify who you are");
  				ot.style.backgroundColor = '#fff4eb';
  				ot.focus();
  				return false;
  			}
  		}
  		else if(fmElement.id == 'how_many' && !fmElement.value.match(/^\d+$/)){
  			alert("Please specify how many items you are interested in");
  			fmElement.style.backgroundColor = '#fff4eb';
  			fmElement.focus();
  			return false;
  		}
  	}
  	// set listing building flag to 1 if Historic range ticked
  	if( document.getElementById('historic').checked == true ){
  		document.getElementById('listed_building').checked = true;
  	}
  	else{
  		document.getElementById('listed_building').checked = false;
  	}
	return true;
}


