var nbsp = 160;    // non-breaking space char
var node_text = 3; // DOM text node-type
emptyString = /^\s*$/
pleaseChoose = /na/

// -----------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// -----------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
};

// -----------------------------------------
//                  msg
// Display warn/error message in HTML element
// commonCheck routine must have previously been called
// -----------------------------------------

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a 
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
  // simply use a space, but IE demands something more, like a non-breaking space.)
  
  //alert(" in msg " + message);
  
  var dispmessage;
  var elem = document.getElementById(fld);

  if (emptyString.test(message))
  {
    dispmessage = String.fromCharCode(nbsp);    
    elem.style.display = "none";
  }
  else  
  {
    dispmessage = message;
    elem.style.display = "";
  }

  elem.firstChild.nodeValue = dispmessage;  
  elem.className = msgtype;
  elem.style.color="red";
  elem.style.fontFamily ="tahoma";
  elem.style.align ="left";
  elem.style.fontWeight="bold"; 

};


// -----------------------------------------
//            commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//         false (validation failed) or 
//         proceed (don't know yet)
// -----------------------------------------

var proceed = 2;  

function commonCheck    (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
	//alert("vfld.name" + vfld.name);
	
	var sub_index = ifld.lastIndexOf("_");

	var fldrequired = "required" + ifld.substring(sub_index,ifld.length);

	var prevRequiredElem = document.getElementById(fldrequired);
		
  if (!document.getElementById) 
  {
  	//alert("not available on this browser - leave validation to the server");
    return true;  // not available on this browser - leave validation to the server
 }
  
  //alert("ifld is " + ifld);
  
  var elem = document.getElementById(ifld);
  
  //alert("what is elem " + elem);

  if (!elem.firstChild)
  {
  	//alert("// not available on this browser " + elem.firstChild);
  	return true;  // not available on this browser 
  }
	//alert("common check5");
	
  if (elem.firstChild.nodeType != node_text)
  {
  	//alert(" ifld is wrong type of node " + elem.firstChild.nodeType);
    return true;  // ifld is wrong type of node  
	}
	//alert("common check6");
	
	//alert(vfld.value);
	
	//alert("common check7");
	
	//alert (vfld.name);
	
  if (emptyString.test(vfld.value) || (vfld.selectedIndex == 0)) 
  {
    if (reqd) 
	{
		
	  	//alert("empty string required ifld" + vfld.id );
	  	//alert("empty string " + "required_" + ifld);
		
		
		if ( ifld.indexOf('required') != -1 )
		{
	      	msg (ifld, "error", vfld.id );  
			vfld.focus();
			return false;

		}
		else
		{
				//alert("display is for " + vfld.name + " is " + document.getElementById('required_cboSellHome').style.display);

				document.getElementById(ifld).innerHTML =String.fromCharCode(nbsp);
				document.getElementById(ifld).style.display = "none";

				//alert ("innerhtml" + fldrequired);
				
				//alert(fldrequired);
		      	
				msg (fldrequired, "error", vfld.id );  
				vfld.focus();

				return false;

		}
		
		
		//alert (document.homefinderForm.elements[document.homefinderForm.cboOwnRent.name].style.visibility == "hidden")

		/**
		if ( document.homefinderForm.elements[vfld.name] || document.getElement)
		{
			alert("In focus here " + vfld.name + " visible");
		}
		**/
      	
    } 
	else 
	{
	//	alert("else reqd");
      msg ( ifld, "warn", "");
	  return true;   // OK
      //alert("returned true");
    }
  }
  else
  {
	  
	//  alert ("set elements to black");
	  
	  prevRequiredElem.style.color="black";
	  prevRequiredElem.style.fontFamily ="tahoma";
	  prevRequiredElem.style.align ="left";
	  prevRequiredElem.style.fontWeight="bold"; 
	  	  
	  elem.style.color="black";
	  elem.style.fontFamily ="tahoma";
	  elem.style.align ="left";
	  elem.style.fontWeight="bold"; 
	  return true;  
  }
  return proceed;
}

function popUp( vfld, ifld, popupIds, reqd )
{

	words = new String(popupIds);
	var popup = words.split(";")
	
	var popupId = popup[0];
	var styleObj = document.getElementById(popupId).style;

	if ( vfld != null )
	{
		if ( vfld.selectedIndex == 1)
		{
			document.getElementById(popupId).style.color = "red";
			document.getElementById(popupId).style.display = "";
			
			var cboName = "required_cbo" + popupId;
			msg(cboName ,"warn", document.getElementById(cboName).innerHTML);
		
		}
		else if(vfld.selectedIndex == 0)
		{
			//alert("vfld is 0");
			UnPop(vfld, ifld, popupIds, reqd);					
			msg(ifld,"warn", "");
		}
		else
		{
			//alert("vfld is 2");
			UnPop(vfld, ifld, popupIds, reqd);					
			msg(ifld,"warn", "");
		}
		
	}
	return validatePresent(vfld,ifld,true);
}

function UnPop ( vfld, ifld, popupIds, reqd )
{
	words = new String(popupIds);
	var popup = words.split(";")
	
	var popupId = popup[0];
	var styleObj = document.getElementById(popupId).style;
	
		for (var i=0; i < popup.length; i++)
		{
		
			if ( popup[i].indexOf("inf_") == -1 )
			{
				//alert(popup[i]);
				cboName = "cbo" + popup[i];
				
				if (document.homefinderForm.elements[cboName] != null)
				{
					//alert(" cboName is " + cboName + "selected index : " + document.homefinderForm.elements[cboName].selectedIndex) ;

					document.homefinderForm.elements[cboName].selectedIndex = 0;
				}
			}
			document.getElementById(popup[i]).style.display = "none";
		}
}

 function validateOnSubmit() 
 {
 	//alert("on submit");
    var elem;
    var errs = 0;
	var flag;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
	// check contact info


    if (!validatePresent(document.homefinderForm.primary_firstname,'required_primaryfirstname', true))
	{ 
		//alert("validatePresent1 " + errs );
		flag = document.homefinderForm.primary_firstname;
		errs += 1;
	}
	
    if (!validatePresent(document.homefinderForm.primary_lastname,'required_primarylastname', true)) 
	{
		//alert("validatePresent2 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.primary_lastname;
		}
		errs += 1; 
	}

	// field that requires 2 kinds of validation such as highligting the text and checking the null value of the
	// field should follow the javacript parameters , see dayphone, evephone and zip
	
    if (!validateTelnr  (document.homefinderForm.txtdayphone, 'inf_txtdayphone', true)) 
	{ 
		//alert("validatePresent3 "  + errs );

		if ( errs  == 0 )
		{
			flag = document.homefinderForm.txtdayphone;
		}
		
		errs +=  1; 
	}
	
    if (!validateTelnr(document.homefinderForm.txtevephone, 'inf_txtevephone', true)) 
	{
		//alert("validatePresent4 "  + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.txtevephone;
		}
		errs += 1; 
		
	}
	
    if (!validateEmail(document.homefinderForm.txtemail, 'inf_txtemail', true)) 
	{
			//alert("validatePresent5 "  + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.txtemail;
		}
		errs += 1; 
	}

	// check address info
    if (!validatePresent(document.homefinderForm.current_address,'required_currentaddress', true)) 
	{
			//alert("validatePresent6 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.current_address;
		}
		errs += 1; 
	}
	
    if (!validatePresent(document.homefinderForm.current_city,'required_currentcity', true)) 
	{
			//alert("validatePresent7 "  + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.current_city;
		}
		errs += 1; 
	}
	
    if (!validateZip(document.homefinderForm.current_zip,'inf_currentzip', true)) 
	{
			//alert("validatePresent8 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.current_zip;
		}
		errs += 1; 
	}


// validate General Info section

	if (!validateMessage(document.homefinderForm.havebuyersagent,'inf_havebuyersagent','havebuyersagentMessage',true))
	{
			//alert("validatePresent10 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.havebuyersagent;
		}
		errs += 1; 

	}
	
	if (popUp(document.homefinderForm.cboOwnRent,'inf_cboOwnRent','Own;SellHome;NoListingAgent;noListingAgentMessage',true) )
	{
		if ( document.homefinderForm.cboOwnRent.selectedIndex==1)
		{
			if(popUp(document.homefinderForm.cboOwn,'inf_cboOwn','SellHome;NoListingAgent;noListingAgentMessage',true))
			{
				if (document.homefinderForm.cboOwn.selectedIndex==1)
				{
					if(popUp(document.homefinderForm.cboSellHome,'inf_cboSellHome','NoListingAgent;noListingAgentMessage',true))
					{
						if ( document.homefinderForm.cboSellHome.selectedIndex == 1)
						{
							if (validateNoListingAgent(document.homefinderForm.cboNoListingAgent,'inf_cboNoListingAgent','noListingAgentMessage',true))
							{
								if ( document.homefinderForm.cboNoListingAgent.selectedIndex==0 )
								{
										//alert("validatePresent11 " + errs );

									if ( errs == 0 )
									{
										flag = document.homefinderForm.cboNoListingAgent;
									}
									errs += 1; 
								}
							}
							else
							{
									//alert("validatePresent12 " + errs );

								if ( errs == 0 )
								{
									flag = document.homefinderForm.cboNoListingAgent;
								}
								errs += 1; 
							}

						}

					}
					else
					{

		//alert("validatePresent13 " + errs );
						if ( errs == 0 )
						{

							flag = document.homefinderForm.cboSellHome;
						}
						errs += 1; 
					
					}
				}
			}
			else
			{
					//alert("validatePresent14 " + errs );

				if ( errs == 0 )
				{
					flag = document.homefinderForm.cboOwn;
				}
				errs += 1; 
			}

		}
	}
	else
	{
			//alert("validatePresent15 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.cboOwnRent;
		}
		errs += 1; 
	}

	if(!validatePresent(document.homefinderForm.cboHowSoonToBuy,'inf_cboHowSoonToBuy',true))
	{
		if ( errs == 0 )
		{
			flag = document.homefinderForm.cboHowSoonToBuy;
		}
		errs += 1; 	
	}
	
	if(!validateMessage(document.homefinderForm.cboAppliedFinance,'inf_cboAppliedFinance','AppliedFinanceMessage',true))
	{
		//alert("validatePresent16 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.cboAppliedFinance;
		}
		errs += 1; 
	}
	
	//check how did you hear about us 
    if (!validateHowdidyouhearaboutus(document.homefinderForm.howdidyousearchaboutus,'required_howdidyouhearaboutus', true)) 
	{
			//alert("validatePresent9 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.chk_howdidyouhearaboutus_blue_arrow_sign;
		}
		errs += 1; 
	
	}	

	
		//check homesearch
    if (!validateHomeSearchInfo(document.homefinderForm.homesearch,'inf_homesearch', true)) 
	{
			//alert("validatePresent9 " + errs );

		if ( errs == 0 )
		{
			flag = document.homefinderForm.chkNorthSub_Irvine;
		}
		errs += 1; 
	
	}

	
    if (errs>1) 
	{
		alert('There are fields which need correction before sending, Please look for the fields highlighted in Red');
	}
	
    if (errs==1) 
	{
		alert('There is a field which needs correction before sending, Please look for the fields highlighted in Red');
	}


    if (errs==0)
	{
		//alert("everythings submitted");
		document.homefinderForm.submit();
	}
	else
	{
		//alert(flag.name);
		if ( flag != null)
		{
			flag.focus();
		}
	}
	
  }

  
function checkPriceRangeValue(vfld, ifld, reqd)
{
	if ( document.homefinderForm.cboMinPrice.selectedIndex > document.homefinderForm.cboMaxPrice.selectedIndex)
	{
		if ( vfld == document.homefinderForm.cboMinPrice )
		{
			document.homefinderForm.cboMaxPrice.selectedIndex = document.homefinderForm.cboMinPrice.selectedIndex;
			document.getElementById(ifld).style.display = "";
			msg(ifld,"warn", "FROM price is greater than TO price.  Please confirm price range");
			//alert("From price is greater than To price, please confirm price range");
		}
		else
		{
			document.homefinderForm.cboMinPrice.selectedIndex = document.homefinderForm.cboMaxPrice.selectedIndex;		
			document.getElementById(ifld).style.display = "";
			msg(ifld,"warn", "TO price is less than FROM price.  Please confirm price range");
			//alert("To price is less than From price, please confirm price range");
		}
	
		return false;
	}
	else
	{
			document.getElementById(ifld).style.display = "none";
			msg(ifld,"warn", "");
	}
	return true;
}

// -----------------------------------------
//            validatePresent
// Validate if something has been entered
// Returns true if so 
// -----------------------------------------
function validatePresent(vfld,   // element to be validated
                         ifld )  // id of element to receive info/error msg
{
//	alert("In Validate Present");
  var stat = commonCheck (vfld, ifld, true);
  if (stat != proceed) return stat;
  var elem = document.getElementById(ifld);
  //msg (ifld, "warn", vfld.name );  
  return true;
};


function validateRequired(vfld,   // element to be validated
                         ifld )  // id of element to receive info/error msg
{
  var stat = commonCheck (vfld, ifld, true);
   var elem = document.getElementById(ifld);

  if (stat != proceed) return stat;

  if (emptyString.test(vfld.value)) 
  {
   //elem.innerHtml= vfld.name;	
   elem.style.color="red";
   elem.style.fontFamily ="tahoma";
   elem.style.align ="left";
   elem.style.fontWeight="bold"; 
  }

  return true;
};

// -----------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validateEmail  (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
	//alert("validateEmail");
  //var stat = commonCheck (vfld, ifld, reqd);
  //if (stat != proceed) return stat;
  
  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
  if (!email.test(tfld)) {
    msg ( ifld, "error", "Please enter a valid e-mail address");
    vfld.focus();
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
  if (!email2.test(tfld)) 
  {
    msg ( ifld, "warn", "Unusual e-mail address - check if correct");
	  vfld.focus();
    return false;
 	} else{
    msg (ifld,"warn","");
	}
  return validatePresent(vfld, ifld, true);
};


function validateMessage( vfld, ifld, popupIds, reqd )
{
	words = new String(popupIds);
	var popup = words.split(";")
	var popupId = popup[0];

	if ( vfld.selectedIndex == 1)
	{
		document.getElementById(popupId).style.display = "";
		msg(ifld,"warn", "");
	}
	else 
	{
			document.getElementById(popupId).style.display = "none";
			msg(ifld,"warn", "");
	}
	return validatePresent(vfld, ifld);
}




function validateHowSoonToBuy ( vfld, ifld, popupIds, reqd )
{
	return validatePresent(vfld, ifld);
}


function validateNoListingAgent(vfld, ifld, popupIds, reqd )
{

	words = new String(popupIds);
	var popup = words.split(";")
	var popupId = popup[0];

	if ( vfld.selectedIndex == 1 )
	{
		document.getElementById(popupId).style.display = "";
		document.getElementById(ifld).style.color = "red";
		msg(ifld,"warn", "");
	}
	else 
	{
			document.getElementById(popupId).style.display = "none";
			msg(ifld,"warn", "");
	}
	//return true;
	return validatePresent(vfld, ifld);
}






// -----------------------------------------
//            validateTelnr
// Validate telephone number
// Returns true if so (and also if could not be executed because of old browser)
// Permits spaces, hyphens, brackets and leading +
// -----------------------------------------

function validateTelnr  (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
 
  //var stat = commonCheck (vfld, ifld, reqd);

  //alert ("stat " + stat + " proceed " + proceed);
  
  //if (stat != proceed) return stat;

  //alert ("stat " + stat + " proceed " + proceed);
  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  //alert("tfld " + tfld);

  var 	telnr = /^\+?[0-9 ()-]+[0-9]$/
  if (!telnr.test(tfld)) {
    msg ( ifld, "error", "Please enter a valid telephone number. example: 1-999-999-9999 or 9999999999");
    vfld.focus();
	//alert("msg1");
    return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<6) 
  {
    msg ( ifld, "error", "ERROR: " + numdigits + " digits - too short");
    vfld.focus();
	//alert("msg2");
    return false;
  }

  if (numdigits>14)
  {
    msg (ifld, "warn", numdigits + " digits - check if correct");
	//alert("msg3");
	}
  else 
  { 
    if (numdigits<10)
	{
      msg ( ifld, "warn", "Only " + numdigits + " digits - check if correct");
	  //alert("msg4");
    }
	else{
      msg ( ifld, "warn", "");
	  //alert("msg5");
	}
  }
  return validatePresent(vfld,ifld,true);
};




// -----------------------------------------
// validateZip
// Returns true if OK 
// -----------------------------------------

function validateZip(vfld,   // element to be validated
                     ifld,   // id of element to receive info/error msg
                     reqd)   // true if required
{

	
	//var stat = commonCheck (vfld, ifld, reqd);
	//alert ("stat " + stat + " proceed " + proceed);
  	//if (stat != proceed) return stat;

  	var field = trim(vfld.value);
	
	//alert (field);
	
	var valid = "0123456789-";
	var hyphencount = 0;
	
	if (field.length!=5 && field.length!=10) 
	{
		//alert ("Please enter your 5 digit or 5 digit+4 zip code.");
	    msg ( ifld, "error", "Please enter your 5 digit or 5 digit+4 zip code.");
	    vfld.focus();
	    return false;
	}
	else
	{
		//alert("msg warn");
	    msg ( ifld, "warn", "");
	    //msg ( vfld, "warn", "Zip*");

	}
	
	
	for (var i=0; i < field.length; i++) 
	{
	temp = "" + field.substring(i, i+1);
	if (temp == "-") hyphencount++;
	
	if (valid.indexOf(temp) == "-1")
	{
		//alert ("Invalid characters in your zip code.  Please try again.");

	    msg ( ifld, "error", "Invalid characters in your zip code.  Please try again.");
	    vfld.focus();
		return false;
	}
	if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
	{
		//alert ("The hyphen character should be used with a properly formatted 5 digit+four zip code, example: '12345-6789'.   Please try again.");			
	    msg ( ifld, "error", "The hyphen character should be used with a properly formatted 5 digit+four zip code, example: '12345-6789'.   Please try again.");
	    vfld.focus();
		return false;
	}
	
	}
	return validatePresent(vfld, ifld, true);
}

/************************************************
DESCRIPTION: Removes currency formatting from
  source string.

PARAMETERS:
  strValue - Source string from which currency formatting
     will be removed;

RETURNS: Source string with commas removed.
*************************************************/

function removeCommas( strValue )
{
  var objRegExp = /\(/;
  var strMinus = '';

  //check if negative
  if(objRegExp.test(strValue))
  {
    strMinus = '-';
  }

  objRegExp = /\)|\(|[,]/g;
  strValue = strValue.replace(objRegExp,'');
  if(strValue.indexOf('$') >= 0)
  {
    strValue = strValue.substring(1, strValue.length);
  }
  return strMinus + strValue;
}

function validatePrice    (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
	payment = removeCommas(vfld.value);
 	var p = /^((\$\d*)|(\$\d*\.\d{2})|(\d*)|(\d*\.\d{2}))$/;
	if( !p.test(payment) )
	{
	    msg ( ifld, "error", "Please enter a valid housing payment");
		vfld.focus()
		return false;
	}
	else
	{
	  	msg ( ifld, "", "");
	    vfld.focus();
	  	return true;
	}
}

function validateHomeSearchInfo  (vfld,   // element to be validated
       		             		ifld,   // id of element to receive info/error msg
    		                     reqd)   // true if required
{

	//alert ("In validate HomeSearch Info");

	//var stat = commonCheck (vfld, ifld, reqd);
  	//if (stat != proceed) return stat;

	var len = document.homefinderForm.elements.length;
	var i=0;
	var counter=0;
			
	for( i=0; i < len; i++)
	{
		var subName = document.homefinderForm.elements[i].name;
		//alert(subName);
		
		if (subName.indexOf("Sub") != -1)
		{
			
			//alert ("element " + document.homefinderForm.elements[i].name + " is " + document.homefinderForm.elements[i].checked);
			if (document.homefinderForm.elements[i].checked)
			{
				counter++;
				//alert ("counter is hit" + counter);
				if ( counter>0)
				{
					//alert("ifld WARN");
					msg ( ifld, "WARN", "");
					return true;
				}
			}
		}
	
	}// end of for
	
	
	if (counter == 0)
	{
		msg ( ifld, "error", "*In order to assist you in targeting your home search,  Please choose city/cities that you are interested in below.");
	    //vfld.focus();
    	return false;
	}

}



	
function enablePropertyTypeOthers(chkPropertyTypes_8) 
{
	if (chkPropertyTypes_8.disabled==true)
	{
		enableComponent(chkPropertyTypes_8);
		chkPropertyTypes_8.focus()

	}else{
		disableComponent(chkPropertyTypes_8);
	}
}


function isOldNetscape()
{
  var browserName = navigator.appName;
  var browserVersion = navigator.appVersion;
  if ((browserName == "Netscape") && parseFloat(browserVersion)<5)
  {
       return true;
  }
  return false;
}
/**
 * Disables the input component
 */
function disableComponent( inputObject )
{
	// Netscape	
	if( isOldNetscape() ) 
	{
		// Handle disabling a checkbox
		if( inputObject.type == "checkbox" || inputObject.type == "radio" )
		{
			inputObject.onclick = function()
			{ 
				return false;
			}
		}

		// Handle the other components
		else
		{
			inputObject.onfocus = function() 
			{ 
				this.blur(); 
			}
		}
		
		//inputObject.style.backgroundColor = "#c3c3c3";
		//inputObject.class = "DISABLEDSTYLE";
		
	}
			
	// IE
	else
	{
		inputObject.disabled = true;
		inputObject.style.backgroundColor = "#c3c3c3";
	}
}


function enableComponent( inputObject )
{

	// Netscape	
	if( isOldNetscape() ) 
	{
		// Handle enabling a checkbox
		if( inputObject.type == "checkbox" || inputObject.type == "radio" )
		{
			inputObject.onclick = function() 
			{ 
				return;
			}
		}
		
		else
		{
			inputObject.onfocus = function() { return; }
			//inputObject.style.backgroundColor = "#FFFFFF";
		}

		//inputObject.class = "ENABLEDSTYLE";
	}
			
	// IE
	else
	{
		inputObject.disabled = false;
		inputObject.style.backgroundColor = "#FFFFFF";
	}
}


var texttop = 400;

function move(amount)
{
	if (!DHTML) return;
	var x = new getObj('text');
	texttop += amount;
	x.style.top = texttop;
}

function changeCol(col)
{
	if (!DHTML) return;
	var x = new getObj('text');
	x.style.color = col;
}

function changeStyle(style)
{
	if (!DHTML) return;
	var x = new getObj('text');
	x.style.fontStyle = style;
}

function changeFamily(family)
{
	if (!DHTML) return;
	var x = new getObj('text');
	x.style.fontFamily = family;
}


function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}


function expand(checkBox,thistag) {
   var styleObj = document.getElementById(thistag).style;
   
   if (checkBox.checked) 
   
   {styleObj.display = '';}
   
   else 
   
   {styleObj.display = 'none';}
   
   subCheckAll(checkBox);
   
}


function CheckAll(obj)
{

		var len = document.homefinderForm.elements.length;
		var i=0;
		
		var constant= obj.name;
		var selection = obj.checked;
		if ( selection)
		for( i=0; i < len; i++)
		{
			var pidName = document.homefinderForm.elements[i].name;
			
				if (pidName.indexOf(constant) != -1)
				{
				//	alert ("need checked " + pidName + " " + constant);
					document.homefinderForm.elements[i].checked=true;
					
					//document.homefinderForm.elements[i].disabled=!selection;
	
				}
		}

}


function subCheckAll(obj)
{
		
		var len = document.homefinderForm.elements.length;
		var i=0;
		var constant="";
	
	//chkNorthSub_Irvine
	
		if ( obj.name.indexOf("Sub_") != -1 )
		{
			var sub_index = obj.name.lastIndexOf("_");
			
			var startName = obj.name.substring(0, sub_index - 3 ); //chknorth
			
			//alert(obj.name + " start index at " + sub_index + "end index = " + obj.name.length);
			
			var lastName = obj.name.substring( sub_index , obj.name.length);
			
			constant = startName + lastName + "Sub_";
			//alert(constant);
		}
		
	    var selection = obj.checked;
	
		for( i=0; i < len; i++)
		{
			var elemName = document.homefinderForm.elements[i].name;
			
			//alert ("elemName is " + elemName);
					
			if (elemName.indexOf(constant) != -1)
			{
				//alert ("constant is " + constant + " elem name is " + elemName);

			//	alert ("need checked " + pidName + " " + constant);
				document.homefinderForm.elements[i].checked=selection;
				//document.homefinderForm.elements[i].disabled=!selection;

			}
		}
	}

function onloadpage()
{
	document.homefinderForm.primary_firstname.focus();
	
	expand( document.homefinderForm.chkNorthSub_Irvine, 'chkNorth_IrvineSub');
	expand( document.homefinderForm.chkSouthSub_SanClemente, 'chkSouth_SanClementeSub');
	expand( document.homefinderForm.chkEastSub_MissionViejo, 'chkEast_MissionViejoSub');
	expand( document.homefinderForm.chkEastSub_RanchoSantaMargarita, 'chkEast_RanchoSantaMargaritaSub');
	expand( document.homefinderForm.chkWestSub_LagunaNiguel, 'chkWest_LagunaNiguelSub');
	expand( document.homefinderForm.chkBeachCommunitiesSub_DanaPoint, 'chkBeachCommunities_DanaPointSub');
	expand( document.homefinderForm.chkBeachCommunitiesSub_LagunaBeach, 'chkBeachCommunities_LagunaBeachSub');
	
	
	// set general info to default
	document.homefinderForm.havebuyersagent.selectedIndex = 0;
	document.homefinderForm.cboOwnRent.selectedIndex = 0;
	document.homefinderForm.cboOwn.selectedIndex = 0;
	document.homefinderForm.cboSellHome.selectedIndex = 0;
	document.homefinderForm.cboNoListingAgent.selectedIndex = 0;

}


  
function popUpWindow(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=600,left = 0,top = 0');");
}
  
  
function toggleComponent( inputObject )
{
	if ( inputObject.disabled == true)
	{
		enableComponent(inputObject);
		inputObject = "";
		inputObject.focus();
	}
	else
	{
		disableComponent(inputObject);
	}
}

  
function validateHowdidyouhearaboutus(	vfld,   // element to be validated
       		             				ifld,   // id of element to receive info/error msg
    		                     		reqd )   // true if required
{
    var elem = document.getElementById(ifld);
	var len = document.homefinderForm.elements.length;
	var i=0;
	var counter=0;
			
	for( i=0; i < len; i++)
	{
		var subName = document.homefinderForm.elements[i].name;
		//alert(subName);
		
		if (subName.indexOf("chk_howdidyouhearaboutus") != -1)
		{
			
			//alert ("element " + document.homefinderForm.elements[i].name + " is " + document.homefinderForm.elements[i].checked);
			if (document.homefinderForm.elements[i].checked)
			{
				counter++;
				//alert ("counter is hit" + counter);
				if ( counter>0)
				{
					//alert("ifld WARN");
					elem.firstChild.nodeValue = "How did you hear about us? ";  
			  		elem.style.color="black";
			  		elem.style.fontFamily ="tahoma";
			  		elem.style.align ="left";
			  		elem.style.fontWeight="bold"; 
					//msg ( ifld, "WARN","");
				}
			}
		}
	
	}// end of for
	
	if ( document.homefinderForm.chk_howdidyouhearaboutus_ad_in_magazine.checked)
	{
		if ( document.homefinderForm.txt_ad_in_magazine.value.length == 0 )
		{
			counter=0;
		}
	}
					
	if ( document.homefinderForm.chk_howdidyouhearaboutus_other_sources.checked )
	{
		if ( document.homefinderForm.txt_other_sources.value.length == 0 )
		{
			counter=0;
		}
	}
					
	if (counter == 0)
	{
		
		elem.firstChild.nodeValue = "How did you hear about us? ";  
	  	elem.style.color="red";
  		elem.style.fontFamily ="tahoma";
  		elem.style.align ="left";
  		elem.style.fontWeight="bold"; 
		//msg ( ifld, "error", "How did you find us?");
	    //vfld.focus();
    	return false;
	}
	else
	{
		return true;
	}

}