function checkrequired() {
if (document.forms.length > 0)
	{
	var field = document.forms[0];
	for (i = 0; i < field.length; i++)
		{
		if (field.elements[i].name.substring(0,3)=="req")
			{
			if (((field.elements[i].type == "text" || field.elements[i].type == "textarea") && field.elements[i].value=='') || (field.elements[i].type.toString().charAt(0) == "s" && field.elements[i].selectedIndex==0))
				{
				if(field.elements[i].name=='reqtype')
					{
					alert("You must select a Property Type.");
					return false;
					}
				alert("Please ensure all required fields are completed.");
				return false;
				}
			}
		}
	}
return true;
}

function checkreqsub() {
	if(document.Form.FirstName.value=="")
		{
		alert("You must enter a First Name.");
		return false;
		}
	if(document.Form.LastName.value=="")
		{
		alert("You must enter a Last Name.");
		return false;
		}
	if(document.Form.Email.value=="")
		{
		alert("You must enter a Valid Email Address.");
		return false;
		}
	if(document.Form.DivResi.checked==false && document.Form.DivBus.checked==false)
		{
		alert("You must select at least one division.");
		return false;
		}
	return true;
	}
 

function checkreqwealth() {
	if(document.Form.FirstName.value=="")
		{
		alert("You must enter a First Name.");
		return false;
		}
	if(document.Form.LastName.value=="")
		{
		alert("You must enter a Last Name.");
		return false;
		}
	if(document.Form.Email.value=="")
		{
		alert("You must enter a Valid Email Address.");
		return false;
		}
	return true;
	}

function emailCheck (emailStr) {

var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.");
    return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!");
		return false;
	    }
    }
    return true;
}
var domainArray=domain.match(domainPat);
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.");
    return false;
}
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
   alert("The address must end in a three-letter domain, or two letter country.");
   return false;
}
if (len<2) {
   var errStr="This address is missing a hostname!";
   alert(errStr);
   return false;
}
return true;
}

function Update_Search_Boxes()
	{ 
	document.search.search_type.options.length = 10;
	var sp = document.search.search_type.options.length;
	while(sp > 0)
		{
		sp--;
		document.search.search_type.options[sp].text = '';
		document.search.search_type.options[sp].value = '';
		}
	document.search.search_type.options[0].selected = true;

	document.search.search_value.options.length = 10;
	var sp = document.search.search_value.options.length;
	while(sp > 0)
		{
		sp--;
		document.search.search_value.options[sp].text = '';
		document.search.search_value.options[sp].value = '';
		}
	document.search.search_value.options[0].selected = true;
	/* figure out which Listing Selection is selected*/
	var Listing_Selected = 0;
	while(document.search.w.options[Listing_Selected].selected==false) Listing_Selected ++;

	if(document.search.w.options[Listing_Selected].value != '')
		{
		if(document.search.w.options[Listing_Selected].value == 'R')
			{
			document.search.search_value.options[0].value = '99';
			document.search.search_value.options[0].text = 'Any Rents';
			document.search.search_value.options[1].value = '0';
			document.search.search_value.options[1].text = 'less than $200 per week';
			document.search.search_value.options[2].value = '1';
			document.search.search_value.options[2].text = '$200 - $250 per week';
			document.search.search_value.options[3].value = '2';
			document.search.search_value.options[3].text = '$250 - $300 per week';
			document.search.search_value.options[4].value = '3';
			document.search.search_value.options[4].text = '$300 - $350 per week';
			document.search.search_value.options[5].value = '4';
			document.search.search_value.options[5].text = '$350 - $400 per week';
			document.search.search_value.options[6].value = '5';
			document.search.search_value.options[6].text = 'more than $400 per week';
			document.search.search_value.options.length = 7;
			}
		else
			{
			document.search.search_value.options[0].value = '99';
			document.search.search_value.options[0].text = 'Any Price';
			document.search.search_value.options[1].value = '0';
			document.search.search_value.options[1].text = 'less than $200,000';
			document.search.search_value.options[2].value = '1';
			document.search.search_value.options[2].text = '$200,000 - $300,000';
			document.search.search_value.options[3].value = '2';
			document.search.search_value.options[3].text = '$300,000 - $400,000';
			document.search.search_value.options[3].value = '3';
			document.search.search_value.options[3].text = '$400,000 - $500,000';
			document.search.search_value.options[4].value = '4';
			document.search.search_value.options[4].text = 'more than $500,000';
			document.search.search_value.options.length = 5;
			}
		if(document.search.w.options[Listing_Selected].value == 'R'||document.search.w.options[Listing_Selected].value == 'S'||document.search.w.options[Listing_Selected].value == 'I')
			{
			document.search.search_type.options[0].value = '';
			document.search.search_type.options[0].text = 'All Types';
			document.search.search_type.options[1].value = 'H';
			document.search.search_type.options[1].text = 'Houses';
			document.search.search_type.options[2].value = 'U';
			document.search.search_type.options[2].text = 'Units';
			document.search.search_type.options[3].value = 'T';
			document.search.search_type.options[3].text = 'Townhouses';
			document.search.search_type.options[4].value = 'L';
			document.search.search_type.options[4].text = 'Land';
			document.search.search_type.options.length = 5;
			document.search.search_type.disabled = false;
			}
		else
			{
			document.search.search_type.options[0].value = '';
			document.search.search_type.options[0].text = 'All Types';
			document.search.search_type.options.length = 1;
			document.search.search_type.disabled = true;
			}
		document.search.search_value.disabled = false;
		}
	else
		{
		document.search.search_value.options[0].value = '99';
		document.search.search_value.options[0].text = 'Any Prices/Rents';
		document.search.search_value.options.length = 1;
		document.search.search_value.disabled = true;
		document.search.search_type.options[0].value = '';
		document.search.search_type.options[0].text = 'All Types';
		document.search.search_type.options.length = 1;
		document.search.search_type.disabled = true;
		}
	}


