	
	// die Formvalidators
	
	// routine used on locate for
	function checkLocatorForm(f)
	{
		if(isEmpty(f.postalCode.value))
		{
			alert('Please enter a valid US or Canadian postal code.');
			f.postalCode.focus();	
			return false;
		}	
		else
		{
			if(isValidZip(f.postalCode.value))
			{
				return true;
			}
			else
			{
				alert('You have entered an invalid US or Canadian postal code. \n Please check your entry.');
				f.postalCode.focus();
				return false;	
			}
				
		}
	}
	
	// routine used on locate for
	function checkRequestForm(f)
	{
		var alertMessage = '';
		var checkState = true;
		
		// firstname
		if(isEmpty(f.contact_name_first.value))
		{
			alertMessage += 'Please enter your first name.\n';
		}	
		
		// lastname
		if(isEmpty(f.contact_name_last.value))
		{
			alertMessage += 'Please enter your last name.\n';
		}
		
		// address1
		if(isEmpty(f.contact_address1.value))
		{
			alertMessage += 'Please enter your primary mailing address.\n';
		}
		
		// city
		if(isEmpty(f.contact_city.value))
		{
			alertMessage += 'Please enter your city of residence.\n';
		}
		
		// country
		if(f.contact_country.selectedIndex == 0 || f.contact_country.selectedIndex == -1)
		{
			alertMessage += 'Please select a country.\n';
		}
		else
		{
			var selVal = f.contact_country.options[f.contact_country.selectedIndex].value;
			if(selVal == 'USA' || selVal == 'CA' || selVal == 'CAN')
			{
				// zip code
				if(isEmpty(f.contact_zip.value))
				{
					alertMessage += 'Please enter a valid US or Canadian postal code.\n';
				}	
				else if(!isValidZip(f.contact_zip.value))
				{
					alertMessage += 'You have entered an invalid US or Canadian postal code. \n Please check your entry.\n';
				}
			}
			else
			{
				f.contact_state_province.selectedIndex = 1;
				if(isEmpty(f.contact_zip.value))
				{
					alertMessage += 'Please enter a postal code.\n';
				}
			}	
		}
		
		// state
		if(f.contact_state_province.selectedIndex == 0 || f.contact_state_province.selectedIndex == -1)
		{
			alertMessage += 'Please select a state or province.\n';
		}
		
		
		
		
		// phone
		if(isEmpty(f.contact_phone1.value))
		{
			alertMessage += 'Please enter your phone number.\n';
		}
		
		// email
		if(!isEmail(f.contact_email.value))
		{
			alertMessage += 'Please enter a valid email address.\n';
		}
		
		// age
		if(f.demo_age_range.selectedIndex == 0 || f.demo_age_range.selectedIndex == -1)
		{
			alertMessage += 'Please select an age range.\n';
		}
		
		// gender
		if(f.demo_gender.selectedIndex == 0 || f.demo_gender.selectedIndex == -1)
		{
			alertMessage += 'Please select your gender.\n';
		}
		
		// housing
		
		
		// when do they plan on buying
		if(f.demo_when_buy.selectedIndex == 0 || f.demo_when_buy.selectedIndex == -1)
		{
			alertMessage += 'Please select the time period you plan to buy in.\n';
		}
		
		
		// income
		if(f.demo_income_range.selectedIndex == 0 || f.demo_income_range.selectedIndex == -1)
		{
			alertMessage += 'Please select your income range.\n';
		}
		
		if(alertMessage.length > 0)
		{
			alert(alertMessage);
			checkState =  false;
		}
		return checkState;
	}
	
	
	
	
	// reqexp string match routine
	function isValidZip(pc)
	{
		var zipPattern 	=	"^\\d{5}$|^\\d{5}\-\\d{4}$|^[a-zA-Z][0-9][a-zA-Z]\\s?[0-9][a-zA-Z][0-9]$";
		var oRegExp 	= 	new RegExp(zipPattern);	
		return oRegExp.test(pc);
	}
	
	// Check whether string s is empty.
	function isEmpty(s)
	{   
		return ((s == null) || (s.length == 0))
	}
	
	function isEmail(s)
	{   
		if (isEmpty(s)) return false;
			
		// is s whitespace?
	    if (isWhitespace(s)) return false;
	    
	    // there must be >= 1 character before @, so we
	    // start looking at character position 1 
	    // (i.e. second character)
	    var i = 1;
	    var sLength = s.length;
	
	    // look for @
	    while ((i < sLength) && (s.charAt(i) != "@"))
	    { i++
	    }
	
	    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	    else i += 2;
	
	    // look for .
	    while ((i < sLength) && (s.charAt(i) != "."))
	    { i++
	    }
	
	    // there must be at least one character after the .
	    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	    else return true;
	}
	
	
	// Returns true if string s is empty or whitespace characters only.
	function isWhitespace (s)
	{   
		var i;
	    var whitespace = " \t\n\r";
	
	    // Is s empty?
	    if (isEmpty(s)) return true;
	    // Search through string's characters one by one
	    // until we find a non-whitespace character.
	    // When we do, return false; if we don't, return true.
	    for (i = 0; i < s.length; i++)
	    {   
	        // Check that current character isn't whitespace.
	        var c = s.charAt(i);
	        if (whitespace.indexOf(c) == -1) return false;
	    }
	    // All characters are whitespace.
	    return true;
	}
	
	function check_country_state(f)
	{
		var selected_country = f.options[f.selectedIndex].value;
		if(selected_country != 'USA' && selected_country != 'CA')
		{
			document.forms.grf.contact_state_province.selectedIndex = 1;	
		}
	}