<!--

//Macromedia functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

//common functions

function getNavDown(){
	
}

function checkChoice(obj) {
	objL = eval("obj.form." + obj.name + ".length")
	for(var i=0;i < objL;i++){
		eval("obj.form."+obj.name+"[i].checked = false")
	}
	obj.checked = true
}


function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function validatefrmVerifyEmail(frm){
	var msg = "Please fix the following:\n-----------------------------------------"
	var valid = true;
	if(!isEmail(frm.UserEmailAddress.value)){
		valid = false;
	}
	if (!valid){
		msg += "\nYou must enter a valid email address"
		alert(msg)
		return false;
	}
}

function askAGent_Validator(frm){
	var flg = true;
	var msg = "Please fill in the following:\n-----------------------------------------\n";
	if((frm.searchCriteria.value.length)==0){
		msg += "Your Question\n";
		flg = false;
	}
	if((frm.FirstName.value.length)==0){
		msg += "Your First Name\n";
		flg = false;
	}	
	if((frm.LastName.value.length)==0){
		msg += "Your Last Name\n";
		flg = false;
	}
	if(!isEmail(frm.Email.value)){
		msg += "Your Email Address\n";
		flg = false;
	}
if(!flg){
	alert(msg);
	return false;
}
}

function hudVa_Validator(frm){
	var flg = true;
	var msg = "Please fill in the following:\n-----------------------------------------\n";
	if((frm.FirstName.value.length)==0){
		msg += "Your First Name\n";
		flg = false;
	}	
	if((frm.LastName.value.length)==0){
		msg += "Your Last Name\n";
		flg = false;
	}
	if(!isEmail(frm.Email.value)){
		msg += "Your Email Address\n";
		flg = false;
	}
	if((frm.City.value.length)==0){
		msg += "City\n";
		flg = false;
	}
if(!flg){
	alert(msg);
	return false;
}
}

function homeValue_Validator(frm){
	var flg = true;
	var msg = "Please fill in the following:\n-----------------------------------------\n";
	if((frm.Address1.value.length)==0){
		msg += "Address\n";
		flg = false;
	}
	if((frm.City.value.length)==0){
		msg += "City\n";
		flg = false;
	}
	if((frm.Zip.value.length)==0){
		msg += "Zip\n";
		flg = false;
	}
	if((frm.poFirstName.value.length)==0){
		msg += "Owner's First Name\n";
		flg = false;
	}	
	if((frm.poLastName.value.length)==0){
		msg += "Owner Last Name\n";
		flg = false;
	}
	if(!isEmail(frm.Email.value)){
		msg += "Your Email Address\n";
		flg = false;
	}

if(!flg){
	alert(msg);
	return false;
}
}



function FormValidatorEmailAFriend(theForm)
{
 // check if Friend email field is blank
 if (theForm.friendFirstName.value.length < 1)
  {
    alert("Please enter a name in the \"Friend's First Name\" field.");
    theForm.friendFirstName.select();
    return (false);
  }
   if (theForm.friendLastName.value.length < 1)
  {
    alert("Please enter a name in the \"Friend's Last Name\" field.");
    theForm.friendLastName.select();
    return (false);
  }
 
 // check if Friend email field is blank
 if (theForm.FriendEmail.value.length < 1)
  {
    alert("Please enter a valid Email Address in the \"Friend's Email Address\" field.");
    theForm.FriendEmail.select();
    return (false);
  }
  
   // test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = theForm.FriendEmail.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
          if (EmailAt && EmailPeriod)
                break;
          if (j == checkEmail.length)
                break;
        }
        // if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
                EmailValid = true
                break;
        }
  }
  if (!EmailValid)
  {
    alert("The value you entered in the \" Friend's email\" field is invalid, please try again. It must contain an \"@\" and a \".\".");
    theForm.FriendEmail.select();
    return (false);
  }

 // check if Sender Name field is blank
 if (theForm.senderFirstName.value.length < 1)
  {
    alert("Please enter a name in the \"Sender's First Name\" field.");
    theForm.senderFirstName.select();
    return (false);
  }
  if (theForm.senderLastName.value.length < 1)
  {
    alert("Please enter a name in the \"Sender's Last Name\" field.");
    theForm.senderLastName.select();
    return (false);
  }
 // check if Sender email field is blank
 if (theForm.SenderEmail.value.length < 1)
  {
    alert("Please enter a valid Email Address in the \"Sender's Email Address\" field.");
    theForm.SenderEmail.select();
    return (false);
  }
  
   // test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = theForm.SenderEmail.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
          if (EmailAt && EmailPeriod)
                break;
          if (j == checkEmail.length)
                break;
        }
        // if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
                EmailValid = true
                break;
        }
  }
  if (!EmailValid)
  {
    alert("The value you entered in the \" Sender's email\" field is invalid, please try again. It must contain an \"@\" and a \".\".");
    theForm.SenderEmail.select();
    return (false);
  }  
  
} 


function EmailFriendValidator(theForm)
{
 // check if Friend email field is blank
 if (theForm.friendFirstName.value.length < 1)
  {
    alert("Please enter a name in the \"Friend's First Name\" field.");
    theForm.friendFirstName.select();
    return (false);
  }
  
 if (theForm.friendLastName.value.length < 1)
  {
    alert("Please enter a name in the \"Friend's Last Name\" field.");
    theForm.friendLastName.select();
    return (false);
  }
 
 // check if Friend email field is blank
 if (theForm.FriendEmail.value.length < 1)
  {
    alert("Please enter a valid Email Address in the \"Friend's Email Address\" field.");
    theForm.FriendEmail.select();
    return (false);
  }
  
   // test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = theForm.FriendEmail.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
          if (EmailAt && EmailPeriod)
                break;
          if (j == checkEmail.length)
                break;
        }
        // if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
                EmailValid = true
                break;
        }
  }
  if (!EmailValid)
  {
    alert("The value you entered in the \" Friend's email\" field is invalid, please try again. It must contain an \"@\" and a \".\".");
    theForm.FriendEmail.select();
    return (false);
  }

 // check if Sender Name field is blank
 if (theForm.senderFirstName.value.length < 1)
  {
    alert("Please enter a name in the \"Your First Name\" field.");
    theForm.senderFirstName.select();
    return (false);
  }
  
 if (theForm.senderLastName.value.length < 1)
  {
    alert("Please enter a name in the \"Your Last Name\" field.");
    theForm.senderLastName.select();
    return (false);
  }
 
 // check if Sender email field is blank
 if (theForm.SenderEmail.value.length < 1)
  {
    alert("Please enter a valid Email Address in the \"Sender's Email Address\" field.");
    theForm.SenderEmail.select();
    return (false);
  }
  
   // test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = theForm.SenderEmail.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
          if (EmailAt && EmailPeriod)
                break;
          if (j == checkEmail.length)
                break;
        }
        // if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
                EmailValid = true
                break;
        }
  }
  if (!EmailValid)
  {
    alert("The value you entered in the \" Sender's email\" field is invalid, please try again. It must contain an \"@\" and a \".\".");
    theForm.SenderEmail.select();
    return (false);
  }  
  
} 





function getQuickSearchForm_sm_Validator(theForm)
{
  // check if more than 5 options are selected
  // check if less than 1 options are selected
  var numSelected = 0;
  var i;
  for (i = 0;  i < theForm.sltCity.length;  i++)
  {
    if (theForm.sltCity.options[i].selected)
        numSelected++;
  }
  if (numSelected > 5)
  {
    alert("Please select at most 5 of the \"City\" options.");
    theForm.sltCity.focus();
    return (false);
  }
  
  if (theForm.ZipCode.value.length < 1 && numSelected < 1)
  {
    alert("Please select at least 1 of the \"City\" options or use a zip code.");
    theForm.sltCity.focus();
    return (false);
  }

  // check to see if the 1st Price Range field is blank
  if (theForm.txtMinPrice.value == "")
  {
    alert("You must enter a value in both price range fields.");
    theForm.txtMinPrice.select();
    return (false);
  }
  
  // check to see if the 2nd Price Range field is blank
  if (theForm.txtMaxPrice.value == "")
  {
    alert("You must enter a value in both price range fields.");
    theForm.txtMaxPrice.select();
    return (false);
  }
    
   // only allow numbers to be entered in the 1st Price Range Field
  var checkOK = "0123456789";
  var checkStr = theForm.txtMinPrice.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Price Range\" fields.");
    theForm.txtMinPrice.select();
    return (false);
  }
  
    // only allow numbers to be entered in the 1st Price Range Field
  var checkOK = "0123456789";
  var checkStr = theForm.txtMaxPrice.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Price Range\" fields.");
    theForm.txtMaxPrice.select();
    return (false);
  }
  
  // require at least 5 characters be entered
  if (theForm.txtMinPrice.value.length < 5)
  {
    alert("Please enter at least 5 characters in \"both price range\" fields.");
    theForm.txtMinPrice.select();
    return (false);
  }
  
   // require at least 5 characters be entered
  if (theForm.txtMaxPrice.value.length < 5)
  {
    alert("Please enter at least 5 characters in \"both price range\" fields.");
    theForm.txtMaxPrice.select();
    return (false);
  }

   // require at least 5 characters be entered
  if (eval(theForm.txtMinPrice.value) > eval(theForm.txtMaxPrice.value))
  {
    alert("The \"Min\" field must be a lesser value than the \"Max\" field.");
    theForm.txtMinPrice.select();
    return (false);
  }
   
     // because this is a sample page, don't allow to exit to the post action
  // comes in handy when you are testing the form validations and don't
  // wish to exit the page
 // alert("All Validations have succeeded. This is just a test page. There is no submission page.");
 // return (false);
  // replace the above with return(true); if you have a valid form to submit to
}


function getQuickSearchForm2_sm_Validator(theForm)
{
  
  // check to see if the 1st Price Range field is blank
  if (theForm.txtMinPrice.value == "")
  {
    alert("You must enter a value in both price range fields.");
    theForm.txtMinPrice.select();
    return (true);
  }
  
  // check if no drop down or first drop down is selected, if so, invalid selection
  if (theForm.sltCity.selectedIndex < 0)
  {
    alert("Please select a City.");
    theForm.sltCity.focus();
    return (false);
  }
     
  // check to see if the 2nd Price Range field is blank
  if (theForm.txtMaxPrice.value == "")
  {
    alert("You must enter a value in both price range fields.");
    theForm.txtMaxPrice.focus();
    return (true);
  }
}

function ooPopUp()
	{
		alert ("This area is currently under construction.")
	}
	
function ltrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function rtrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

function trim(str) {
	return rtrim(ltrim(str));
}
	

	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~KYLE'S Calculators
function format(input,p,s) {
  if(p > 0) {
    p++;
    var rounder = "."; for(var i = 1; i < p; i++) { rounder += "0"; } rounder += "5";
    var temp = eval(input) + eval(rounder);
    var decs = "" + (temp - Math.floor(temp));
    decs = decs.substring(2,p+1);
  }
  else { temp = Math.round(input); }
  var ints = "" + Math.floor(temp);
  var output = ints.substring(ints.length,(ints.length - 1));
  for(i = 1; i < ints.length; i++) {
    if(s) { if(!(i % 3)) { output = s + output; } }
    output = ints.substring((ints.length - i),(ints.length - i - 1)) + output;
  }
  if(p > 0) { output = output + "." + decs; }
  return output;
}

function checkNumber(input, min, max, msg)
{
    msg = msg + " field has invalid data: " + input.value;

    var str = input.value;
    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
            alert(msg);
            return false;
        }
    }
    var num = parseFloat(str)
    if (num < min || max < num) {
        alert(msg + " not in range [" + min + ".." + max + "]");
        return false;
    }
    input.value = str;
    return true;
}

function computeField(input)
{
    if (input.value != null && input.value.length != 0)
        input.value = "" + eval(input.value);
    computeForm(input.form);
}

function computeForm(form)
{
    if ((form.payments.value == null || form.payments.value.length == 0) ||
        (form.RATE.value == null || form.RATE.value.length == 0) ||
        (form.LIST_PRICE.value == null || form.LIST_PRICE.value.length == 0)) {
        return;
    }

    if (!checkNumber(form.payments, 1, 40, "# of years") ||
        !checkNumber(form.RATE, .001, 99, "Interest") ||
        !checkNumber(form.LIST_PRICE, 100, 10000000, "Loan Amount")) {
        form.payment.value = "Invalid";
        return;
    }

    var i = form.RATE.value;
    if (i > 1.0) {
        i = i / 100.0;
    }
    i /= 12;
    var pow = 1;
    for (var j = 0; j < (12*form.payments.value); j++)
        pow = pow * (1 + i);
		
	var price = form.LIST_PRICE.value -0;
	var dp = form.DP.value - 0;
	var loan = price - dp;
	var payment = (((price - form.DP.value) * pow * i) / (pow - 1)*100)/100
	var taxes = ( price * eval(form.taxRate.value))/12;
	var insurance = ( price * eval(form.insuranceRate.value))/12;
	var total = payment + taxes + insurance;
	form.loan.value =format(loan,2,",");
	form.taxes.value =format(taxes,2,",");
	form.insurance.value =format(insurance,2,",");
    form.payment.value = format(payment,2,",");
	form.total.value = format(total,2,",");
}

function window_open(varInputName)
{
var newWindow;
var urlstring = "/common/new_cal/calendar.asp?varInputName="+varInputName;
newWindow = window.open(urlstring,'','height=200,width=280,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no')
}

function showing_Validator(frm){
	var flg = true;
	var msg = "Please fill in the following:\n-----------------------------------------\n";
	if((frm.FirstName.value.length)==0){
		msg += "Your First Name\n";
		flg = false;
	}	
	if((frm.LastName.value.length)==0){
		msg += "Your Last Name\n";
		flg = false;
	}
	if(!isEmail(frm.Email.value)){
		msg += "Your Email Address\n";
		flg = false;
	}
	if((frm.Phone.value.length)==0){
		msg += "Your Phone\n";
		flg = false;
	}
	if((frm.showdt.value.length)==0){
		msg += "Show Date\n";
		flg = false;
	}
if(!flg){
	alert(msg);
	return false;
}
}


function frmValidateAll( formName, validStr, fieldString, fieldDisplay ) { 
	//formName ie:  this
	//validStr ie: "1234568790"
	//fieldString ie: "txtname,txtaddress,txtzipcode,txtage" - actual form element names
	//fieldDisplay ie: "Name,Address,Zip Code,Age" - element names to display in alert box
		validChars = validStr; 
		if (fieldString.indexOf(",") > -1) {
			arrFields = fieldString.split(",");
		} else {
			var arrFields = new Array(fieldString);
		}
		if (fieldDisplay.indexOf(",") > -1) { 
			arrDisplay = fieldDisplay.split(',');
		} else {
			var arrDisplay = new Array(fieldDisplay);
		}
		strAlert = '';
		for( var i = 0; i<arrFields.length; i++) {
			curField = eval("formName." + arrFields[i]);
			curVal = curField.value;
			for( var i2=0; i2<curVal.length; i2++ ) { 
					if (validChars.indexOf( curVal.charAt( i2 )) == -1 ) { 
						strAlert += arrDisplay[i] + ' must be numeric\n';
						break;
					}
			}
		}
		if (strAlert.length > 0) {
			alert(strAlert);
			return false;
		}
} 


//-->
