<!-- // Hide code from old browsers
// 4/2/2001 - Validation added for Numeric Checking using onBlur event 
function validate(Field) {
      s = Field.value;
      if (  (isNaN(Math.abs(s)) && (s.charAt(0) != '#'))) {
          if ( validate.arguments.length  == 1 )
             alert( Field.name + " Value must be a number." );
          else 
             alert( Field +  " must be a number. Please re-enter." );
        Field.focus();
        return false;
      }
      return true;
}


function countit(what){
formcontent=what.form.charcount.value
what.form.displaycount.value=formcontent.length
}
//___________________________________________________________________
// This is the back count script
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Written by Steve - http://jsmadeeasy.com/ -->

<!--
function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

//Count  
function Count(entry,exit,text,character) {
  var entryObj=getObject(entry);
  var exitObj=getObject(exit);
  var length=character - entryObj.value.length;
  if(length <= 0) {
    length=0;
    text='<span class="disable">&nbsp;'+text+'&nbsp;</span>';
    entryObj.value=entryObj.value.substr(0,character);
  }
  exitObj.innerHTML = text.replace("{CHAR}",length); }



function blank(field){
		field_cont=field.value;
		if (field_cont=="" || field_cont.trim()=="" ) {            
   			alert(field.name+" is a required field. Please enter a value.");
    		field.focus();
   		return false;
             }
}




// 3/6/2002 - Returns true if field contains html tag(s), otherwise false 
function containsHTML(field) {
	if ((field.value.indexOf("<") >= 0) && (field.value.indexOf(">") >= 0)) {
		alert("HTML tags are not allowed in " + field.name + ".  Please enter only plain text.");
		field.focus();
		field.select();
		return true;
	}
	return false;
}




function validatedec(field) {
	var valid = "0123456789.";
	var ok = 0;
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = -1;
	}
	if (ok == -1) {
		alert("Invalid entry:  Only numbers and a decimal point are accepted for " + field.name + ". Enter your number with up to two decimal places.");
		field.focus();
		field.select();
                return false;
	}
        return true;
}


function quicksearch(){
        if((document.f2.STATE[document.f2.State.selectedIndex].value == "null") && (document.f2.quicknbr.value=="")  ){
		alert("Enter either State, Ad Number, or Phone Number.");
		return false;
	}
	return true;
}




function validatedecimalforacres(field, text) {
	var valid = "0123456789.";
	var ok = 0;
	var temp;
        if(field.value >999999.99){
                alert("Invalid entry for "+text+" .Max Value=999999.99");
                field.focus();
                field.select();
                return false;
        }
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = -1;
	}
	if (ok == -1) {
		alert("Invalid entry:  Only numbers and a decimal point are accepted for " + text + ". Enter your number with up to two decimal places. DO NOT include any spaces, letters, or commas (,)  in this field.");
		field.focus();
		field.select();
                return false;
	}
        return true;
}


function validateZIPlist(field) {
	var valid = "0123456789,* ";
	var ok = 0;
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = -1;
	}
	if (ok == -1) {
		alert("Incorrect list of ZIP Codes:  Only numbers (five-digit or less), commas, and asterix may be used.");
		field.focus();
		return false;
	}




        if(field.value==""){
        alert(field.name+" is a required field. ");
    		field.focus();
   			return false;
		}
			
		if(field.value.length>255){
			alert("List of ZIP Codes can only be 255 characters. Please shorten list.");      
    		field.focus();      
			return false;
		}
	return true;
}


function validatePercentage(field) {
	var valid = "0123456789.";
	var ok = 0;
	var decCount = 0;
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = -1;
		if (temp==".") decCount += 1;
	}
	
	if((field.value.length==0) || (ok==-1) || (decCount > 1) || (0.0 + field.value > 9.0)) {
		alert("A commission bid amount is required.  Please enter a single value between 0.0 and 9.0 in the Bid Amount field.");
		field.focus();
		return false;
	}
    return true;
}


function validateFee(field) {
	var valid = "0123456789.";
	var ok = 0;
	var decCount = 0;
	var temp;
	
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = -1;
		if (temp==".") decCount += 1;
	}
		
	if((field.value.length==0) || (ok==-1) || (decCount > 1)) {
		alert("A fee amount is required in the Bid Amount field.");
		field.focus();
		return false;
	}
	return true;
}


function validatedecimal(field) {
	var valid = "0123456789.";
	var ok = 0;
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = -1;
	}
	if (ok == -1) {
		alert("Invalid entry:  Only numbers and a decimal point are accepted for " + field.name + ". Enter your number with up to two decimal places.  DO NOT include the dollar sign ($) or any commas (,) in this field.");
		field.focus();
		return false;
	}
  	if(field.value==""){
        	alert(field.name+" is a required field. ");
                field.focus();
                return false;
        }
        return true;
}




// Get checked value from radio button.
function getRadioButtonValue (radio)
{
   for (var i = 0; i < radio.length; i++) {
       if (radio[i].checked) { break }
    }
    return radio[i].value
}




function validateAgree(field) {
  	if(!field.checked){
    	alert("Please indicate you agree to the terms and conditions.");
    	field.focus();
   		return false;
    }
    return true;
}


function validateBid(fm, str){ 
	if (!limit(fm.Remarks, 1000)) return false;
	if (str=="%" && !validatePercentage(fm.PRICEAmount)) return false;
	if (str=="$" && !validateFee(fm.PRICEAmount)) return false;
        return true;
}  


function seller(fm)
{ 
	sellerFields = new Array();         // to hold the form field names 
        sellerText = new Array();           // to hold user-friendly strings for error message - should be exact same as form field label 
        sellerFields[1]="LotSize";          sellerTextFields[1]="Lot Size";
	sellerFields[2]="YearBuilt";        sellerTextFields[2]="Year Built";
        sellerFields[3]="Value";            sellerTextFields[3]="Value";
	sellerFields[4]="Street";           sellerTextFields[4]="Street";
        sellerFields[5]="CITY";             sellerTextFields[5]="CITY Name ";
        sellerFields[6]="STATE";            sellerTextFields[6]="STATE Name";
        sellerFields[7]="ZIP";              sellerTextFields[7]="ZIP Code";
        
        // confirm all the required fields 
        for(i=1;i<=7;i++)
        {
        
            field_cont=fm.elements[sellerFields[i]].value;
		if (field_cont=="" || field_cont=="null")
                {            
                                // display user-friendly field name   
                                alert("This field "+sellerTextFields[i]+" is required.");
                                fm.elements[sellerFields[i]].focus();
                                return false;
                 }
        }
        var ZIP=fm.ZIP;
   	if(!ZIPValidation(ZIP)) return false;	
        var STATE=fm.STATE;
	if(!selectSTATE(STATE)) return false;	
    	if(!validateAgree(fm.agree)) return false;                    
    
	return true;
}    


function buyer(fm){
    if(document.f1.Bedrooms[document.f1.Bedrooms.selectedIndex].value =="") {
		                alert("The field Bedrooms is required.");
				document.f1.Bedrooms.focus();
				return false;
                            }
    else if(document.f1.Size[document.f1.Size.selectedIndex].value =="null") {
		                alert("The field Size is required.");
				document.f1.Size.focus();
                                return false;
                                }
        
    else if(document.f1.Bathrooms[document.f1.Bathrooms.selectedIndex].value ==""){
	                        alert("The field Bathrooms is required.");
				document.f1.Bathrooms.focus();
                                return false;
                                }




    else if(document.f1.PRICE[document.f1.PRICE.selectedIndex].value =="null"){


		                alert("This field PRICE is required.");     
				document.f1.PRICE.focus() ;         
				return false;
                                }
    else if(document.f1.ZIP.value =="" || document.f1.ZIP.Value <5){     
                                alert("The field ZIP is required and must be five charecters.");     
				document.f1.ZIP.focus() ;         
				return false;
                                }
    if(!validateAgree(fm.agree)) return false;  								


    return true;
                                    
}    


//Validation for the pop_contact_us.shtml form - email - added JKGill 9/5/2005
function validContact(fm)
 { 
	rField = new Array();           // to hold the form field names 
    rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
	rField[1]="realname";           rText[1]="Your Name";
	rField[2]="email";              rText[2]="Your Email";
	

	//Check email - requried and in a valid format
	var txt="A valid email address is required. Please check your email address and re-enter your information and send again.";
	var EmailAddress=fm.email;

	if(!emailValidation(EmailAddress,txt)) {
		fm.email.focus();
		return false;
	}

	// Confirm all required fields      
	for(i=1;rField.length;i++)
        {         
		if (field_cont=fm.elements[rField[i]].value=="")
                {            
	  	        // display user-friendly field name   
	  		alert("An entry for '"+rText[i]+"' is required.");
	      	        fm.elements[rField[i]].focus();
	    	        return false;

		}   
	}       
	return true;
}  


// Validate for all signup pages - Randy 03/11/02                
function validSignup(fm) 
{ 
	rField = new Array();       // to hold the form field names 
        rText = new Array();        // to hold user-friendly strings for error message - should be exact same as form field label 
	rField[1]="FirstName";      rText[1] ="First Name";
	rField[2]="LastName";       rText[2] ="Last Name";
	rField[3]="UserName";       rText[3] ="User Name";
	rField[4]="Pwd";            rText[4] ="Password";
	rField[5]="ReenterPwd";     rText[5] ="Re-enter Password";
	rField[6]="PwdQ";           rText[6] ="Password Retrieval Question";

	rField[7]="PwdAns";         rText[7] ="Password Retrieval Answer";
	
	// Confirm all required fields      
	for(i=1;i<rField.length;i++) {         
		if (field_cont=fm.elements[rField[i]].value=="") 
                {            
	  	        // display user-friendly field name   
	  		alert("This field "+rText[i]+" is required.");  
	      	        fm.elements[rField[i]].focus();


	    	        return false;
	  	}        
	}       

	if (!isAlphaNumeric(fm.UserName.value.toUpperCase())) { 
		alert('Your username must only contain A-Z, a-z, 0-9, @ or . and no spaces'); 
		fm.UserName.focus();
		return false;
	}


	if( fm.Pwd.value.length < 5 ) {
	    alert("Password must be at least 5 characters.");    
	    fm.Pwd.focus();
	    return false;
	}
	
	if(fm.Pwd.value.toUpperCase() != fm.ReenterPwd.value.toUpperCase() ) {
	    alert("Your Confirmation Password didn't match.");    
	    fm.ReenterPwd.focus();
	    return false ;
	}  


	return true;
}         


// Be sure popup email is non empty - John 03/13/04
function validSellerEmail(fm)
 { 
	rField = new Array();           // to hold the form field names 
    rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
	rField[1]="name";           	rText[1]="Your Name";
	rField[2]="email";              rText[2]="Your Email";
	rField[3]="message";            rText[3]="Your Message";
	

	//Check email - requried and in a valid format
	var txt="A valid email address is required. Please check your email address and re-enter your information and send again.";
	var EmailAddress=fm.email;

	if(!emailValidation(EmailAddress,txt)) {
		fm.email.focus();
		return false;
	}

	// Confirm all required fields      
	for(i=1;rField.length;i++)
        {         
		if (field_cont=fm.elements[rField[i]].value=="")
                {            
	  	        // display user-friendly field name   
	  		alert("An entry for '"+rText[i]+"' is required.");
	      	        fm.elements[rField[i]].focus();
	    	        return false;

		}   
	}       
	return true;
}  


// Be sure all the required fileds are non-empty for NEW AD
function validNewAd(fm,roomCnt){
  	if(fm.ReferenceCode.value.length!=0){
		if (fm.retailLocation[fm.retailLocation.selectedIndex].value == "" &&  fm.otherRetail.value == "" ) {
			alert("If you enter a reference code, you must also indicate where you purchased your GoneHome product.")
			fm.retailLocation.focus();
			return false;
		}
	}
        if(!newAndExistingAdd(fm,roomCnt)) return false;
        return true;
}    


// Be sure all the required fileds are non-empty for EXISTING AD
function validAd(fm,roomCnt) {
        if(!newAndExistingAdd(fm,roomCnt)) return false;
        return true;
}    




// make sure all the required fields are non-empty in New Add and Existing Add
function newAndExistingAdd(fm,roomCnt) {
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
  	rField[1]="PRICE";              rText[1]="Price";
	rField[2]="ADDRESS1";           rText[2]="Address";
	rField[3]="CITY";               rText[3]="City Name";
	rField[4]="ZIP";                rText[4]="Zip Code";
	rField[5]="COUNTY";             rText[5]="County";
	rField[6]="FIRSTNAME";          rText[6]="First Name";
	rField[7]="LASTNAME";           rText[7]="Last Name";
    rField[8]="PHAREA";             rText[8]="Phone Area Code";
    rField[9]="PHPREFIX";           rText[9]="Phone Prefix Number";
    rField[10]="PHSUFFIX";          rText[10]="Phone Suffix Number";
    rField[11]="BDRS";              rText[11]="Bedrooms";
	rField[12]="BATHRS";            rText[12]="Bathrooms";
	    
        if(((fm.PHAREA.value.length!=0) && (fm.PHAREA.value.length < 3))||(isNaN(Math.abs(fm.PHAREA.value))))
        {
             alert("Please enter 3 numbers for Phone Area Code.");    
             fm.PHAREA.focus();
             return false;
        }

        if(((fm.PHPREFIX.value.length!=0)&& (fm.PHPREFIX.value.length < 3))||(isNaN(Math.abs(fm.PHPREFIX.value))))
        {
             alert("Please enter 3 numbers for the Phone Number Prefix.");    
             fm.PHPREFIX.focus();
             return false;
        }

        if(((fm.PHSUFFIX.value.length!=0)&& (fm.PHSUFFIX.value.length < 4))||(isNaN(Math.abs(fm.PHSUFFIX.value))))
        {
             alert("Please enter 4 numbers for the Phone Number Suffix.");    
             fm.PHSUFFIX.focus();
             return false;
        }


        if(((fm.PRICE.value.lenth!=0) && (fm.PRICE.value >99999999.99))||(isNaN(Math.abs(fm.PRICE.value))))
         {
                 alert("PRICE field must only contain numbers and cannot exceed 8 digits. DO NOT include the dollar sign ($) or any commas (,) in the price.");
                 fm.PRICE.focus();
                 return false;
         }
		 
        if(fm.COUNTY.value.lenth!=0 && (fm.COUNTY.value.toUpperCase()=="US" || fm.COUNTY.value.toUpperCase()=="USA"  || fm.COUNTY.value.toUpperCase()=="UNITED STATES" || fm.COUNTY.value.toUpperCase()=="UNITEDSTATES" ) )
        {
                 alert("Please enter the COUNTY not country.");
                 fm.COUNTY.focus();
                 return false;
         }
	
        // confirm all the required fields
	for(i=1;i<rField.length;i++) 
        {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {
                   	// display user-friendly field name   
	  				alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   					return false;
    	        }
        }

        var STATE=fm.STATE;
        if(!selectSTATE(STATE)) return false;	

        var ZIP=fm.ZIP;
        if(!ZIPValidation(ZIP)) return false;	

//        if(fm.OwnerType[fm.OwnerType.selectedIndex].value == "" || fm.OwnerType[fm.OwnerType.selectedIndex].value == "null" )
//        {
//                alert("This field Offered By is required.")
//		fm.OwnerType.focus();
//		return false;
//	}
        var YEARBUILT=fm.YEARBUILT;
        if(!validateField(YEARBUILT)) return false;
        var squareFoot=fm.SQUAREFOOT;
        if(!validateField(squareFoot)) return false;
        var totalAcres=fm.ACRES;
        if(!validatedecimalforacres(totalAcres, 'Acres')) return false;




        // validating features and dimentions ...........
        for(var k=1;k<=roomCnt;k++){
                        var features=fm.elements['DESCRIPTION'+k];
                        if(!limitNoHTML(features,900)) return false;
                        var width=fm.elements['WDFT'+k];
//                        if(!validateField(width)) return false;
                        var length=fm.elements['LNFT_'+k];
//                        if(!validateField(length)) return false;
                }        


        var gasCostLow=fm.GASCOST;
        if(!validateUtilityBills(gasCostLow)) return false;
        var gasCostHigh=fm.GASCOST_HIGHT;
        if(!validateUtilityBills(gasCostHigh)) return false;




        var electricCostLow=fm.ELECTRICCOST;
        if(!validateUtilityBills(electricCostLow)) return false;
        var electricCostHigh=fm.ELECTRICCOST_HIGH;
        if(!validateUtilityBills(electricCostHigh)) return false;




        var waterCostLow=fm.WATERCOST;
        if(!validateUtilityBills(waterCostLow)) return false;
        var waterCostHigh=fm.WATERCOST_HIGH;
        if(!validateUtilityBills(waterCostHigh)) return false;




        var sewerCostLow=fm.SEWERCOST;
        if(!validateUtilityBills(sewerCostLow)) return false;
        var sewerCostHigh=fm.SEWERCOST_HIGH;
        if(!validateUtilityBills(sewerCostHigh)) return false;


        var propertyTaxes=fm.SEMIANNUALTAXES;
        if(!validatedec(propertyTaxes)) return false;
        var otherFee=fm.OTHFEEASSMTS;
        if(!validatedec(otherFee)) return false;


        var descShort=fm.DESCSHORT;
        if(!limitNoHTML(descShort,500)) return false;


        var openhouse_msg=fm.OPENHOUSE_MSG;
        if(!limitNoHTML(openhouse_msg,60)) return false;


        var yardDescr=fm.YARD;
        if(!limitNoHTML(yardDescr,1200)) return false;


        var feeDesc=fm.FEE_DESCRIPTION;
        if(!limitNoHTML(feeDesc,255)) return false;


        var appliances=fm.APPLIANCES;
        if(!limitNoHTML(appliances,100)) return false;


        var addDescr=fm.DESCLONG;
        if(!limitNoHTML(addDescr,1500)) return false;


        return true;
 }    
     
function limitNoHTML(name,x){ 
	if(!limit(name,x)){
		return false;
	}
	if (containsHTML(name)) {
		return false;
	}
	return true;
} 
	
function limit(name,x){ 
	if(name.value == null) return true;
	if(name.value.length>x){
		alert("This field can only hold "+x+" characters. Please shorten the description.");      
    	        name.focus();      
		name.select();
		return false;
	}
	return true;
}




// JKGill - Validation added for Numeric Checking using onBlur event
function over1(topic){
	temp=document.images[topic].src;
	re=/.gif/ ;    
	document.images[topic].src=temp.replace(re,'ovr.gif');
}




function out1(topic){
	temp=document.images[topic].src;
	re=/ovr.gif/ ;    
	document.images[topic].src=temp.replace(re,'.gif');
}


function openwin(url){
	newwin=open(url,"Detail",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=550,height=560');
}




function openwin1(url)
{
      newwin=open(url,"Detail",'toolbar=no,location=no,directories=no,status=no,menubar=no,photobars=yes,resizable=yes,top=20, left=20,width=570,height=455');
}




// make sure all the required fileds are non-empty on homepage
function search()
{
    if((document.f1.State[document.f1.State.selectedIndex].value == "..") && (document.f1.Zip.value=="")  )
    {
        alert("Either State or ZIP is required.");
        return false;
    }
    return true;
}




// make sure multiple email addresses are seperated by enter key and email address is valid
function emailValidation(EmailAddress,txt)
{
        if(txt=="text")
        {
            var alertMessage="Enter at least one email address. For multiple addresses, enter one per line without any additional punctuation,\n" +
					" for example:\n" +
					"                   bill@acme.com\n"+
					"                   sue@acme.com\n"+
					"                   larry@acme.com" ;
        }
        else
         {
            var alertMessage=txt;
         }
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-._";
	var count = 0; // is used to check how many times @ symbol appears in the mail id, if it appears more than once display error message.
	var temp="";
	var separator = '\n';
	var emailArray = EmailAddress.value.split(separator); 
	loop: for (var i=0; i < emailArray.length; i++)
	{ 
                var emailLength=0;	
		for (var k=0; k<emailArray[i].length; k++) 
		{	
			
			var lastCharacter=emailArray[i].substring(emailArray[i].length-1,emailArray[i].length);
                        // check the last character  enter key or not in the email address
			if(lastCharacter.charCodeAt(emailArray[i].substring(emailArray[i].length-1,emailArray[i].length)) == 13)
			{
				emailLength=emailArray[i].length-1; // last character is enter key
				break;
			}
			else
			{
				emailLength=emailArray[i].length;  // last character is not enter key
				break;
			}
			

        	}
                // get the email address from emailArray and validate 
		for (var j=0; j<emailLength; j++) 
		{
			temp = "" +emailArray[i].substring(j, j+1);
			if (valid.indexOf(temp) == -1 || emailArray[i].indexOf('@') == -1 || emailArray[i].indexOf('.') == -1  || emailArray[i].length<6 || emailArray[i].substring(0, 1)=='@' || emailArray[i].substring(0, 1)=='.') 
			{
				alert(alertMessage);
				EmailAddress.focus();
		  	        return false;
				break loop;
			}
			else if(temp=='@')
			{
			      count=count+1;
			}
			
		}
		if(count >1)
		{
			alert(alertMessage);
			EmailAddress.focus();
		  	return false;
			break;
		}
		else
		{
			count=0;
		}
	}
	return true;
}




// make sure all the required fields are non-empty after accepting a bid ( mydesktop_bidacceptedUI.jsp ) - Chenna 01/04/02
function bidAcceptedValidation(fm)
{
        rField = new Array();           // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
	rField[1]="FirstName";          rText[1]="First Name";
	rField[2]="LastName";           rText[2]="Last Name";
	rField[3]="Street1";            rText[3]="Street";
	rField[4]="CITY";               rText[4]="CITY Name";
	rField[5]="ZIP";                rText[5]="ZIP Code";
	rField[6]="Phone1";             rText[6]="Phone Number";




        var STATE=fm.STATE;
        var ZIP=fm.ZIP;
        var string=fm.Phone1;
        var alertTxt="Phone Number";
        // confirm all the required fields
        for(i=1;i<rField.length;i++) 
        {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   			return false;
    	        }
        }
        if(!selectSTATE(STATE)) return false;
        if(!ZIPValidation(ZIP)) return false;
        if(!phoneValidation(string,alertTxt)) return false;
        return true;
        
}
// make sure the the text field contains only digits
function digitsValidation(input,txtMsg){
        if(input.value.length!=0 && isNaN(Math.abs(input.value)) ){
          alert("This field "+txtMsg+" must be a number.");    
          input.focus();
          return false;
        }
        return true;
}


// make sure ZIP contains only digits and it should be minimum digits
function ZIPValidation(ZIP)
{
        if(((ZIP.value.length!=0) && (ZIP.value.length < 5))|| (ZIP.value.length == 0)||(isNaN(Math.abs(ZIP.value))))
        {




          alert("ZIP must be at least 5 characters and must be a number.");    
          ZIP.focus();
          return false;
        }
        return true;
}
// make sure the STATE field is non-empty
function selectSTATE(STATE)
{
        if(STATE[STATE.selectedIndex].value == "" || STATE[STATE.selectedIndex].value == ".." || STATE[STATE.selectedIndex].value == "null" )
        {
                alert("This field STATE Name is required.")


		STATE.focus();
        	return false;
        }
        return true;
}




//  make sure phone number contains only digits and it should be minimum 10 characters
function phoneValidation(string ,alertTxt)
{
	var phone=string;
        var temp;
        var count=0;
        var valid="0123456789";
        for (var i=0; i<phone.value.length; i++) 
	{
		temp = "" + phone.value.substring(i, i+1);
        	if(valid.indexOf(temp) != -1)
                     count=count+1;   // counting the number of digits in phone number
        }
	if(count <10)
        	{
	            alert("Please enter a full "+alertTxt+" including area code.");    
	            phone.focus();
	            return false;
	        }
        return true;
}




function newWindow(url,X,Y)
{
     newwin=open(url,"Detail","toolbar=no,location=no,directories=no,status=no,menubar=no,photobars=yes,resizable=yes,width="+X+",height="+Y);
}


// Cancel
function validCancel(f1)
{
	if(document.f1.cancelReason[document.f1.cancelReason.selectedIndex].value =="null") {
		alert("Please enter the reason for cancelling this ad");
		document.f1.cancelReason.focus();
		return false;
   	}
        return true;
}


// make sure all the required fields are non-empty
function validMLSInquiry(fm)
{
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
        rField[1]="firstName";          rText[1]="First Name";
	rField[2]="lastName";           rText[2]="Last Name";
        rField[3]="ZIP";                rText[3]="ZIP Code";
	rField[4]="phone";              rText[4]="Phone Number";
 
        var string=fm.phone;
        var alertTxt="Phone Number";
        var ZIP=fm.ZIP;
        var hearAboutUs=fm.hearAboutUs;




        for(i=1;i<rField.length;i++) 
        {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   			return false;
    	        }
        }
        if(!ZIPValidation(ZIP)) return false;
        if(!phoneValidation(string,alertTxt)) return false;
        if(!selectHearAboutUsFn(hearAboutUs)) return false;
        return true;
}


// function for becomeBuilder.jsp. Make sure all the required fields are non-empty
function validBuilderInquiry(fm)
{
   
    if(!validMLSInquiry(fm)) return false;
    if(fm.companyName.value=="" || fm.companyName.value=="null")
    {
        alert(" This field Builder Company Name is required.");
        fm.companyName.focus();
        return false;
    }
    return true;
}
// function for mydesktop_account.jsp. Make sure all the required fields are non-empty
function validateMyBuilderAccount(fm)
{
            var rField = new Array();       // to hold the form field names 
            rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
            rField[1]="profile";            rText[1]="Profile Information";
            rField[2]="buildArea";          rText[2]="Building Areas";
            rField[3]="companyName";        rText[3]="Company Name";
            rField[4]="address1";           rText[4]="Address";
            rField[5]="CITY";               rText[5]="CITY Name";
            rField[6]="STATE";              rText[6]="STATE Name";
            rField[7]="ZIP";                rText[7]="ZIP Code";
            rField[8]="phone_nbr";          rText[8]="Phone Number";
            var string=fm.phone_nbr;
            var alertTxt="Phone Number";
            for(i=1;i<rField.length;i++) 
            {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();

   			return false;
    	        }
            }
            if(!validateMyDesktopAccount(fm)) return false;
            var STATE=fm.STATE;
            if(!selectSTATE(STATE)) return false;
            var ZIP=fm.ZIP;
            if(!ZIPValidation(ZIP)) return false;
            if(!phoneValidation(string,alertTxt)) return false;
            return true;
}


// function for partner_account.jsp. Make sure all the required fields are non-empty
function validPartnerAccount(fm)
{
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
        rField[1]="Profile";            rText[1]="Profile Information";
        rField[2]="CompanyName";        rText[2]="Company Name";
	rField[3]="FirstName";          rText[3]="First Name";
        rField[4]="LastName";           rText[4]="Last Name";
	rField[5]="TypeOfBusiness";     rText[5]="Type Of Business";
        rField[6]="Address";            rText[6]="Address";
        rField[7]="CITY";               rText[7]="CITY Name";
        rField[8]="STATE";              rText[8]="STATE Name";
        rField[9]="ZIP";                rText[9]="ZIP Code";
        rField[10]="PhoneNumber";       rText[10]="Phone Number";
        rField[11]="EmailAddress";      rText[11]="Email Address";
        
        var STATE=fm.STATE;
        var ZIP=fm.ZIP;
        var string=fm.PhoneNumber;
        var alertTxt="Phone Number";
        var txt="text";
        var EmailAddress=fm.EmailAddress;
        for(i=1;i<rField.length;i++) 
        {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   			return false;
    	        }
        }
        if(!selectSTATE(STATE)) return false;
        if(!ZIPValidation(ZIP)) return false;
        if(!phoneValidation(string,alertTxt)) return false;
        if(!emailValidation(EmailAddress,txt)) return false;
        return true;
}




// function for hbs_become_a_partner.jsp. Make sure all the required fields are non-empty
function validHBSBecomeAPartner(fm)
{ 
        if(!validMLSInquiry(fm)) return false;
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
        rField[1]="companyName";        rText[1]="Company Name";
        rField[2]="typeBusiness";       rText[2]="Type Of Business";
        for(i=1;i<rField.length;i++) 
        {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {


                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   			return false;
    	        }
        }
        return true;
}       


  
// function for become_retailer.jsp. Make sure all the required fields are non-empty
function validBecomeRetailer(fm)
{
            if(!validHBSBecomeAPartner(fm)) return false;
            return true;
}




// function for qualitybidUI.jsp. Make sure the user must select some option from the combo box
function validQualityBidUI(fm)
{ 
      if(fm.ServiceType[fm.ServiceType.selectedIndex].value == "" || fm.ServiceType[fm.ServiceType.selectedIndex].value == "null" )
        {
                alert("Please select the type of service desired.")
		fm.ServiceType.focus();
        	return false;
        }
        return true;
}       




// funtion for mydesktop_accountUI.jsp and mydesktopbuilderUI. Validation for form fileds
// added by venkat 04/18/02
function validateMyDesktopAccount(fm){ 
    rfield = new Array();
    rfield[1]="firstName";

    rfield[2]="lastName";
    rfield[3]="pwd";
    rfield[4]="reEnterPwd";
    rfield[5]="pwdQ";
    rfield[6]="pwdAns";


    errorText = new Array();            // Array assigning error name for form fileds 
    errorText[1]="First name";
    errorText[2]="Last name";
    errorText[3]="Choose a New Password";
    errorText[4]="Re-enter Your New Password";
    errorText[5]="Password Retrievial Question";
    errorText[6]="Password Retrival Answer";


      for(i=1;i<=6;i++)
        {         

                field_cont=fm.elements[rfield[i]].value
                if (field_cont=="")
                {            
                   alert("This field "+errorText[i]+" is required.");
                   fm.elements[rfield[i]].focus();
                   return false;
                }        
        }       
     if( fm.pwd.value.length < 5 )
        {
            alert("Password must be at least 5 characters.");    
            fm.pwd.focus();
            return false;
        }
    if(fm.pwd.value != fm.reEnterPwd.value )
    {
            alert("Your Confirmation Password didn't match.");    
            fm.reEnterPwd.focus();
            return false ;
    }  
    return true;
}   
// funtion for qualitybid.jsp (Seller Agent Request) . Validation for form fileds
function validSellRequest(fm)
{
       if(fm.mt[fm.mt.selectedIndex].text == ".."  )
        {
              	alert("This field 'How soon do you intend to begin selling your property' is required.");
	        fm.mt.focus();
		return false;
        }
       if(fm.s_PRICE[fm.s_PRICE.selectedIndex].text == ".." )
        {
              	alert("This field 'What is the estimated selling PRICE of your home' is required.");
	        fm.s_PRICE.focus();
		return false;
        }
       if(fm.s_stnm[fm.s_stnm.selectedIndex].value == "" || fm.s_stnm[fm.s_stnm.selectedIndex].value == "null" )
        {


              	alert("This field 'STATE where your home is located' is required.");
	        fm.s_stnm.focus();
		return false;
        }
         return true;
}




// make sure the HearAboutUs field is non-empty
function selectHearAboutUsFn(hearAboutUs)
{
        if(hearAboutUs[hearAboutUs.selectedIndex].text ==".." ){
                alert("This field Hear About Us is required.")
		hearAboutUs.focus();
        	return false;
        }
        return true;
}
// make sure single dropdown forms should not require hitting "Go" button
function go(formObject)
{
    formObject.form.submit();
}




// make sure Name and Email Address is required in popup_email.jsp
function validPopupEmail(fm)
{
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
        rField[1]="fullName";            rText[1]="Your Name";
        rField[2]="email";          rText[2]="Your Email";




        var EmailAddress=fm.email;
        var txt="A valid email address is required. Please re-enter.";




        for(i=1;i<rField.length;i++) 
        {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   			return false;
    	        }
        }
       if(!emailValidation(EmailAddress,txt)) return false;
        return true;
}


//confimation for deletion of tracked ad in mydesktop_overviewUI.jsp..
function confirmBox(deleteTrackNbr) {
    var agree = confirm('Are you sure you want to delete this bookmark? ');
    if (agree) {
            // code to execute if 'yes' goes here
            window.location="mydesktop_overview.jsp?deleteTrackedAd="+deleteTrackNbr ;
            return true;
    }
    else {
            // code to execute if 'no' goes here
            return false;
    }
}


// validate Utility Bills  in create_ad02.jsp
function validateUtilityBills(field) 
{
	var valid = "0123456789.";
	var ok = 0;
	var temp;
        var temp1=field.value;
        if(temp1.indexOf(".") > 4 || (temp1.indexOf(".")== -1 && temp1.length >4 ) )
        {
		        alert("Invalid entry: Maximum you can enter 4 digits with 2 decimal digits.  DO NOT include the dollar sign ($) or any commas (,) in this field.");
		        field.focus();
		        field.select();
                        return false;
        }
        else if (temp1.indexOf(".") != -1 && temp1.substring(temp1.indexOf(".")+1).length >2 )
        {
		        alert("Invalid entry: Only numbers and a decimal point are accepted for " + field.name + ". Enter your number with up to two decimal places.  DO NOT include the dollar sign ($) or any commas (,) in this field.");
		        field.focus();
		        field.select();
                        return false;
        }
       else
        {
             	for (var i=0; i<field.value.length; i++) {
		        temp = "" + field.value.substring(i, i+1);
		        if (valid.indexOf(temp) == "-1") ok = -1;
	        }
	        if (ok == -1) {
		        alert("Invalid entry:  Only numbers and a decimal point are accepted for " + field.name + ". Enter your number with up to two decimal places.  DO NOT include the dollar sign ($) or any commas (,) in this field.");
		        field.focus();
		        field.select();
                        return false;
	        }
        }
       return true;
}
// function for orderDetail.jsp. Make sure property ZIP field is non-empty
function validOrderDetail() {
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message 
        rField[1]="dfltPropAddress1";    rText[1]="Property address";
        rField[2]="firstName";           rText[2]="First name";
        rField[3]="lastName";            rText[3]="Last name";
        rField[4]="phoneNbr";            rText[4]="Phone1";
        rField[5]="dfltPropZIP";         rText[5]="property ZIP code";
        for(i=1;i<rField.length;i++){
               if(document.form.elements[rField[i]].value=="" || document.form.elements[rField[i]].value=="null"){
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        document.form.elements[rField[i]].focus();
   			return false;

    	        }
        }
        var ZIP=document.form.dfltPropZIP;
        if(!ZIPValidation(ZIP)) return false;
        var hearAboutUs=document.form.hearAboutUs;
        if(!selectHearAboutUsFn(hearAboutUs)) return false;
//      var EmailAddress=document.form.emailAddr;
//      var txt="A valid email address is required. Please re-enter.";
//      if(!emailValidation(EmailAddress,txt)) return false;
        var comments=document.form.comments;
        if(!limitNoHTML(comments,3000)) return false;
        return true;
}
// function for orderDetail.jsp. if Payment type is not 'check' or not '..' then validate required fields in billing information 
function billingInformationFunction() {
       if(document.form.dfltBillType[document.form.dfltBillType.selectedIndex].value !=".." && document.form.dfltBillType[document.form.dfltBillType.selectedIndex].value.toUpperCase() !="CK" ){
             if(!creditCardValidation()) return false;
       }
       return true;
}
// function to validate credit card information
 function creditCardValidation() {
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message 
        rField[1]="dfltCCNumber";       rText[1]="Card/Check number ";
        rField[2]="dfltCCExpMo";        rText[2]="Credit card expiration month ";
        rField[3]="dfltCCExpYr";        rText[3]="Credit card expiration year ";
        rField[4]="dfltBillAddress1";   rText[4]="Billing address";
        rField[5]="dfltBillCITY";       rText[5]="Billing CITY";
        rField[6]="dfltBillSTATE";      rText[6]="Billing STATE";
        rField[7]="dfltBillZIP";        rText[7]="ZIP / Postal code";
        for(i=1;i<rField.length;i++){
               if(document.form.elements[rField[i]].value=="" || document.form.elements[rField[i]].value=="null"){
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        document.form.elements[rField[i]].focus();
   			return false;
    	        }
        }
        if(document.form.dfltCCExpMo.value <=0) {
                   alert("This field Credit card expiration month should be > 0 ");
    	           document.form.dfltCCExpMo.focus();
   		   return false;
        }
        if(document.form.dfltCCExpYr.value <=0) {
                   alert("This field Credit card expiration year should be > 0 ");
    	           document.form.dfltCCExpYr.focus();

   		   return false;
        }
        var ZIP=document.form.dfltBillZIP;
        if(!ZIPValidation(ZIP)) return false;
        var STATE=document.form.dfltBillSTATE;
	if(!selectSTATE(STATE)) return false;	
        return true;
}
// make sure the Firm field is non-empty
function selectFirmFn(firm){
        if(firm[firm.selectedIndex].text ==".." ) {
                alert("This field Firm is required.")
		firm.focus();
        	return false;
        }
        return true;
}
// function for providerDetail.jsp. Make sure provider ZIP field is non-empty
function validProviderDetail(fm) {
        var ZIP=fm.ZIP;
        if(!ZIPValidation(ZIP)) return false;
        return true;
}
// function for originatorDetail.jsp. Make sure provider ZIP field is non-empty
function validOriginatorDetail(fm) {
        var ZIP=fm.ZIP;
        if(!ZIPValidation(ZIP)) return false;
        return true;
}




// function for find_retailer.jsp. Make sure ZIP field is non-empty
function validFindRetailer(fm)
{
           var ZIP=fm.ZIP;
           if(!ZIPValidation(ZIP)) return false;
           return true;
}




//  Validation added for Numeric Checking 
function validateField(Field)
{
	 var s = Field.value;
     if(s.charAt(s.length-1)==' ' ) { // check last character is not space
  	        alert( Field.name + " Value must be a number with out any spaces.  DO NOT include the dollar sign ($) or any commas (,) in this field." );
	        Field.focus();
		Field.select();
	        return false;
     }
     if ( !(isNaN(Math.abs(s)) ) ) { // checking number or not
          if (   s.charAt(0)==' '  ){ // checking first character is not space
	        alert( Field.name + " Value must be a number with out any spaces.  DO NOT include the dollar sign ($) or any commas (,) in this field." );
	        Field.focus();
			Field.select();
	        return false;
          }
     }
     else {  // not a number
     	    alert( Field.name + " Value must be a number with out any spaces.  DO NOT include the dollar sign ($) or any commas (,) in this field." );
	        Field.focus();
			Field.select();
	        return false;
          }
      return true;
}




// function to display alert when user checks 'ok to pay' in orderDetail.jsp                    
   function displayPaymentsAlert(checkObj){
        if(checkObj.checked){
	        if(navigator.appName == 'Microsoft Internet Explorer') { // call VB function to display 'Yes' and 'No' buttons 
		      makeMsgBox("GoneHome Inc","Are you sure these are the correct payment amounts?",32,4);
                 }else {
                          confirm("Are you sure these are the correct payment amounts?");
                    }
       }
   }
// function to display alert when user checks 'ok to refund' in orderDetail.jsp                   
   function displayRefundsAlert(checkObj){
        if(checkObj.checked){
	        if(navigator.appName == 'Microsoft Internet Explorer') { // call VB function to display 'Yes' and 'No' buttons 
		      makeMsgBox("GoneHome Inc","Are you sure these are the correct refund amounts?",32,4);
                 }else {
                          confirm("Are you sure these are the correct refund amounts?");
                   }
       }
  }
// function to display alert when user checks 'ok to refund' in orderDetail.jsp                   
   function displayRefundsAlert1(checkObj){
        if(checkObj.checked){
	        if(navigator.appName == 'Microsoft Internet Explorer') { // call VB function to display 'Yes' and 'No' buttons 
		      retVal=makeMsgBox("GoneHome Inc","Are you sure these are the correct refund amounts?",32,4);
		      if(retVal == 7){ // no button pressed
                                document.form.authAmt1.focus(); 
                      }
                 }else {
                          if (!confirm("Are you sure these are the correct refund amounts?")) {
                                      document.form.authAmt1.focus(); 
                           }
                   }
       }
  }
// function to open new window when user clicks on view website add hyper link  
     function viewWebSite(fm) {
                var str="http://"+fm.adURL.value;
                window.open(str);
     }
// function to open new window when user clicks on view online add add hyper link  
     function viewAdd(fm) {
                var str="http://www.infotube.net/"+fm.adURL.value;
                window.open(str);
     }
<!-- function to submit form when user clicks save button (which is beside of ok to pay checkbox) -->
                    function formSubmit(){
                                document.form.action="orderDetail.jsp?save=save";
                                document.form.submit();
                    }
<!-- function to submit form when user clicks recalculate button (which is beside of ok to pay button) -->
                    function recalculateFirmPRICE(name){
                                document.form.action="orderDetail.jsp?save=save&recal=cal";
                                document.form.submit();
                    }




<!-- function to change payments block authAmt(if it appears) automatically if user changes mls PRICE -->
                    function changeAuthAmt(mlsPRICE){
                            document.form.authAmt.value=mlsPRICE.value;
                    }
<!-- function to change payments block deferredAuthAmt(if it appears) automatically if user changes mlsPrePay -->
                    function changeDeferredAuthAmt(mlsPrePay){
                            document.form.deferredAuthAmt.value=mlsPrePay.value;
                    }
<!-- function to validate payments fields and to get values based on cliked btn in paymentProcess.jsp -->
        function paidFunction(btn){
                var str=btn.substring(4,btn.length);
                var rField = new Array();       // to hold the form field names 
                rText = new Array();            // to hold user-friendly strings for error message 
                rField[1]="amount"+str+"";            rText[1]="Amount";
                rField[2]="paymentType"+str+"";       rText[2]="Payment Type";
                rField[3]="ccNumber"+str+"";          rText[3]="Card / Check Number";
                rField[4]="authCode"+str+"";          rText[4]="Authorization Code";
                for(i=1;i<rField.length;i++){
                       if(document.paymentsForm.elements[rField[i]].value=="" || document.paymentsForm.elements[rField[i]].value=="null"){
                                // display user-friendly field name
                                alert("This field "+rText[i]+" is required.");
                                document.paymentsForm.elements[rField[i]].focus();
                                return false;
                        }
                }                
                document.paymentsForm.btnName.value=str;
                document.paymentsForm.submit();
        }




// function used to open popup windows..
function saleMailPopup(url, w, h){
   var winsize = ',width='+w+',height='+h;
   var winpos  = (window.screen && document.layers) ? ',screenX='+((screen.availWidth-w)/2)+',screenY='+((screen.availHeight-h)/2) :(window.screen && !document.layers) ? ',left='+((screen.availWidth-w)/2)+',top='+((screen.availHeight-h)/2) : '';
   newwin = window.open(url,'Sellermail','toolbar=no,scrollbars=yes,location=no'+winsize+winpos);
   //newwin=open(url,"Detail","top=30,left=30,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + escape(w) + ",height="+escape(h));
   parent.focus();
}








// make sure Name and Email Address is required in popup_email.jsp
function validateSellerBuyerPopup(fm)
{
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
        rField[1]="fullName";            rText[1]="Your Name";
        rField[2]="email";               rText[2]="Your Email";
       




        var EmailAddress=fm.email;
        var txt="A valid email address is required. Please re-enter.";
        


        for(i=1;i<rField.length;i++) 
        {         
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null")
                {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   			return false;
    	        }
        }
       if(!emailValidation(EmailAddress,txt)) return false;




       if(!((fm.sellerEmail.checked) || (fm.buyerEmail.checked))){
            alert("check buying a home or selling a home ");
            return false;
       }
       return true;
}
// function to calculate total value in retailerOrderForm.jsp 
       function totalFunction(cost,qty,total) {
            var x=String(cost*qty);
            var result=getFloatValueUpto2DecimalPoints(x);
            total.value=result;
            sumOfTotalFunction();
       }
       function sumOfTotalFunction(){
              var x=String((document.form1.txtPRICE1.value*document.form1.txtQty1.value) + (document.form1.txtPRICE2.value*document.form1.txtQty2.value) + (document.form1.txtPRICE3.value*document.form1.txtQty3.value));
              var result=getFloatValueUpto2DecimalPoints(x);
              document.form1.txtTotalSum.value = result;
       }
// function to get value upto 2 decimal points in retailerOrderForm.jsp 
      function getFloatValueUpto2DecimalPoints(str){
          if(str.indexOf('.') < 0) { // if str doesn't have decimal points add 2 decimal points to it 
                     var result=str+".00";
          }else { // str contains decimal points get float value upto 2 decimal points
                     var result=str.substring(0,str.indexOf('.')+3);
          }
          return result;
     }


// /function used in ReferFriend.jsp ..includes  validation for multiple emails separated by commas
var str;
function validateReferFriendEmail(fm)
{
   var txt="A valid email address is required. Please re-enter.";
   if(fm.emailAddresses.value == ""){
            alert(txt);
            fm.emailAddresses.focus();
            return false;
    }
    var  str = fm.emailAddresses.value+",";
    while(str.indexOf(",") != -1){
            i =	str.indexOf(",")
            str1 = str.substring(0 ,i);
            if(!checkemail(str1)) return false;
                    str = str.substring(i+1 );
    }                
    if(!checkemail(str1)) return false;	
    
    return true;
}




// check emailadress for any mistyped invalid chars..
var testresults
function checkemail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
	if (filter.test(str))
		testresults=true ;
	else{
		alert("Please input a valid email address!");
		testresults=false;
	}
	return (testresults);


}


//    Included for MortgageCalculator.jsp
function standardPopup(url, w, h,windowName){
   var winsize = ',width='+w+',height='+h;
   var winpos  = (window.screen && document.layers) ? ',screenX='+((screen.availWidth-w)/2)+',screenY='+((screen.availHeight-h)/2) :(window.screen && !document.layers) ? ',left='+((screen.availWidth-w)/2)+',top='+((screen.availHeight-h)/2) : '';
   newwin = window.open(url,windowName,'toolbar=no,scrollbars=yes,location=no'+winsize+winpos);
   newwin.focus();
}


// intialize values on onload() in  MortgageCalculator.jsp;
// calculate principle value depending on load amount , intrest and term ..
    function computeLoan(){
            var i = document.f1.intrestRate[document.f1.intrestRate.selectedIndex].value;
            if (i >= 1.0){
                    i = i / 100.0;
            }
            var tmppmt = 0;
            var r=(i/12)+1
   
            var t = Math.pow(Math.pow(r,12),document.f1.years[document.f1.years.selectedIndex].value);
            var mp = (document.f1.loanAmount.value * t * (r-1))/(t-1);




           document.f1.principle.value = Math.round(((mp*1)) * 100)/100;
           pValue = document.f1.principle.value * 1;
           document.f1.escrowPayment.value = Math.round((document.f1.annualTax.value/12) * 100)/100;
           mesc = document.f1.escrowPayment.value * 1;
           document.f1.tMp.value= Math.round((mesc+ pValue)*100)/100;
     }      


// validate fields in MortgageCaluator.jsp 
    function computeloanAmount(form){
        if (form.askingPRICE.value != ""){
                var str1 = form.askingPRICE;
                if (!checkNumber(str1,"Asking PRICE must be numeric.!")){
                        return;
                 }
               num = form.askingPRICE.value * 1;
               if (num > 10000000 || num < 1000){
                        alert("Sale PRICE must be in the range 1,000 to 10,000,000!");
                        return;
                        }

                }
        if (form.downPayment.value != ""){
                var str1 = form.downPayment;
                if (!checkNumber(str1,"Down Payment must be numeric!")){
                        return;
                        }
                num = form.downPayment.value * 1;
                }




	if (form.loanAmount.value != ""){
                var str1 = form.loanAmount;
                if (!checkNumber(str1,"Loan Amount must be numeric!")){
                        return;
                        }
                num = form.loanAmount.value * 1;
                }




        if ((form.askingPRICE.value == null || form.askingPRICE.value.length == 0) ||
        (form.downPayment.value == null || form.downPayment.value.length == 0)) {
              return;
                }
        form.principal.value = form.askingPRICE.value - form.downPayment.value
        form.loanAmount.value = form.principal.value;
        }




/// validate for number bvalues only  and "." value for PRICE amounts...
 function checkNumber(input,  msg){
        var str = input.value;
        for (var i = 0; i < str.length; i++){
                var ch = str.substring(i, i + 1);
                if ((ch < "0" || ch >"9") && ch != "." && ch != ""){
                        alert(msg);
                        return false;
                }
         }
        return true;
  }
    function computeForm(form , val){
	    computeloanAmount(form);




	if(form.downPayment.value == null || form.downPayment.value.length == 0) 
	{
            form.downPayment.value=0;
	}
                
        if(val == 'ap'){ // if asking PRICEs changes
                form.downPayment.value = form.askingPRICE.value*20/100; 
                form.loanAmount.value = form.askingPRICE.value - form.downPayment.value;
        }




	if(val == 'dp'){ // if downpayment value changes
               form.loanAmount.value = form.askingPRICE.value - form.downPayment.value;
        }
        if ((form.years[form.years.selectedIndex].value == null || form.years[form.years.selectedIndex].value.length == 0) ||
                (form.intrestRate[form.intrestRate.selectedIndex].value == null || form.intrestRate[form.intrestRate.selectedIndex].value.length == 0) ||
                    (form.askingPRICE.value == null || form.askingPRICE.value.length == 0) ||
                        (form.downPayment.value == null || form.downPayment.value.length == 0) ||
                            (form.loanAmount.value == null || form.loanAmount.value.length == 0) ) {




                                    return;
        }
        var i = form.intrestRate[form.intrestRate.selectedIndex].value;
        if (i >= 1.0){
                i = i / 100.0;
        }
        var tmppmt = 0;
        var r=(i/12)+1
        var t = Math.pow(Math.pow(r,12),form.years[form.years.selectedIndex].value);
        var mp = (form.loanAmount.value * t * (r-1))/(t-1);
        form.principle.value = Math.round(((mp*1)) * 100)/100;
        pValue = form.principle.value * 1;
        form.escrowPayment.value = Math.round((form.annualTax.value/12) * 100)/100;
        mesc = form.escrowPayment.value * 1;
	form.tMp.value= Math.round((mesc+ pValue)*100)/100;
        }






// function for titile_inquiry.jsp. Make sure all the required fields are non-empty
function validTitleInquiry(fm)
{
        if(!validMLSInquiry(fm)) return false;
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
        rField[1]="titleFirstName";     rText[1]="title First Name";
        rField[2]="titleLastName";      rText[2]="title Last Name";
        
        for(i=1;i<rField.length;i++) {
               if(fm.elements[rField[i]].value=="" || fm.elements[rField[i]].value=="null") {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[rField[i]].focus();
   			return false;
    	        }
        }
        var sellingProcess=fm.process;
        if(!selectSellingProcessFn(sellingProcess)) return false;




}
// make sure  where are u in the selling process field is non-empty
function selectSellingProcessFn(sellingProcess)
{
       if(sellingProcess[sellingProcess.selectedIndex].text ==".." ) {
                alert("This field Where are you in the selling process is required.")
		sellingProcess.focus();
        	return false;
        }
        return true;
}


function maxLength(obj,i) {
	if (obj.value.length >= i) {
		obj.value = obj.value.slice(0,i);
	}
}




function popup_xy(url, x, y){
	newwin=open(url,"Detail","top=30,left=30,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + escape(x) + ",height="+escape(y));
}




function popup_msg(bkgd, cl, title, breaks, msg)
{
 open("popup_message.jsp?bkgd="+escape(bkgd)+"&title="+escape(title)+"&message="+escape(msg)+"&class="+escape(cl), "popupwin", "top=90,left=90,width=400,height=" + (135 + (((msg.length+60)/60)+breaks)*12.5) + ",resizeable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0");
}





// added for popupforgot.jsp. validate username and email for required.
function popUpforgot(fm){
   if((fm.UserName.value == "") && (fm.email.value=="")){
            alert("This field username or email address is required.");
            fm.email.focus();
            return false;
    }
   if(fm.email.value != ""){
        if(!checkemail(fm.email.value)) return false;	
       //return checkemail(fm.email.value)  ;
   }     
    return true;
}


// function used  in mya_request.jsp ...simple filed validation for required ones...


function namePRICE(fm){


        namePRICEAgent = new Array();           // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message - should be exact same as form field label 
        namePRICEAgent[1]="realESTATECo";
        namePRICEAgent[2]="agentName";
        namePRICEAgent[3]="commission";
        namePRICEAgent[4]="fName";
        namePRICEAgent[5]="lName";
        namePRICEAgent[6]="address";
        namePRICEAgent[7]="CITY";
		namePRICEAgent[8]="ZIP";  
        namePRICEAgent[9]="phone";    
                                            rText[1]="Real ESTATE Company ";
                                            rText[2]="Real ESTATE Aget Name";
                                            rText[3]="Commission";
                                            rText[4]="First Name";
                                            rText[5]="Last Name";
                                            rText[6]="Property Address";
                                            rText[7]="CITY";
                                            rText[8]="ZIP";
                                            rText[9]="phone";


        for(i=1;i<namePRICEAgent.length;i++) 
        {         
               if(fm.elements[namePRICEAgent[i]].value=="" || fm.elements[namePRICEAgent[i]].value=="null")
                {
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        fm.elements[namePRICEAgent[i]].focus();
   		 	return false;
    	        }
        }
        var STATE=fm.STATE;
        var ZIP=fm.ZIP;
        
        var string=fm.phone;
        var alertTxt="Phone";
        var commission =fm.commission;
        if(!validateField(commission)) return false;
        if(!selectSTATE(STATE)) return false;
        if(!ZIPValidation(ZIP)) return false;
        if(!phoneValidation(string,alertTxt)) return false;
        if(fm.email.value != ""){
                if(!checkemail(fm.email.value)) return false;	
        }    
   return true;
    }


//popupwindow for flash objects
function flashWin(name, url, width, height, args,popOver) {
		var newWin = new Object();




		newWin.args = args;
		newWin.url = url;
		newWin.name = name;
		newWin.width = width;
		newWin.height = height;




		if (document.layers) {// browser is NN
			newWin.left = window.screenX + ((window.outerWidth - newWin.width) / 2);
			newWin.top = window.screenY + ((window.outerHeight - newWin.height) / 2);
			var attr = 'screenX=' + newWin.left + ',screenY=' + newWin.top + ',resizable=yes,width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
		}
		else {// browser is MSIE
			newWin.left = (screen.width - newWin.width) / 2;
			newWin.top = (screen.height - newWin.height) / 2;
			var attr = 'left=' + newWin.left + ',top=' + newWin.top + ',width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
		}




		newWin.win=window.open(newWin.url, newWin.name, attr);
		//newWin.win.opener=self;


                if(popOver == 'Y'){
                    newWin.win.focus();


                }else{
                    parent.focus();
                }    
               






	}
    
// added for mortgage_bid_request.jsp
function validateMortgageForm(fm)
{ mortfields = new Array();                // to hold the form field names 
        mortrText = new Array();         // to hold user-friendly strings for error 	message - should be exact same as form field label 
        mortfields[1]="Borrowers_fName";          mortrText[1]="Borrowers First Name";  
	mortfields[2]="Borrowers_lName";	 mortrText[2]="Borrowers Last Name";  	
	mortfields[3]="Borrowers_Birth";         mortrText[3]="Borrowers Date Of Birth"; 
        mortfields[4]="Borrowers_Address";       mortrText[4]="Borrowers Address"; 
	mortfields[5]="Borrowers_CITY";          mortrText[5]="Borrowers CITY Name"; 
        mortfields[6]="Borrowers_STATE";         mortrText[6]="Borrowers STATE Name"; 
        mortfields[7]="Borrowers_ZIP";           mortrText[7]="Borrowers ZIP Code"; 
        mortfields[8]="Borrowers_Home_Phone";    mortrText[8]="Borrowers Home Phone Number"; 
	mortfields[9]="Borrowers_Work_Phone";    mortrText[9]="Borrowers work Phone Number"; 
	mortfields[10]="Borrowers_SSN";           mortrText[10]="Borrowers Social Security Number"; 
	mortfields[11]="Borrower_Salary";           mortrText[11]="Borrowers Yearly Income"; 
	mortfields[12]="Borrower_MonHouEx";           mortrText[12]="Borrowers Monthly House Expense"; 
	mortfields[13]="Borrower_MonExOth";           mortrText[13]="Borrowers Monthly Expense Other"; 

        mortfields[14]="propCITY";           mortrText[14]="Borrowers Property Information CITY";


	co_name = fm.elements["Co-Borrowers_fName"];
        co_lname = fm.elements["Co-Borrowers_lName"];
	co_ssn  = fm.elements["Co-Borrowers_SSN"];
	co_birth  = fm.elements["Co-Borrowers_Birth"];
        co_sal  = fm.elements["CoBorrower_Salary"];
       


         if(((fm.Borrowers_ZIP.value.length!=0) && (fm.Borrowers_ZIP.value.length < 5))||(isNaN(Math.abs(fm.Borrowers_ZIP.value))))
        {
            alert("Borrowers ZIP must be at least 5 characters and must be a number.");    
            fm.Borrowers_ZIP.focus();
	    fm.Borrowers_ZIP.select();
    	    return false;
        }		
        // confirm all the required fields
	for(i=1;i<=14;i++)
        {
		field_cont=fm.elements[mortfields[i]].value;
		if (field_cont=="" || field_cont=="null") 
                {     
                    // display user-friendly field name
      		    alert("This field "+mortrText[i]+" is required.");         
         	    fm.elements[mortfields[i]].focus();
          	    return false;
		}
	}


        var dob = fm.elements[mortfields[3]];
        if(!validateForm(dob)) return false;
        var string=fm.elements[mortfields[8]];
        var alertTxt="Borrowers Home Phone Number"; 
        if(!phoneValidation(string,alertTxt)) return false;
 	var string=fm.elements[mortfields[9]];
        var alertTxt="Borrowers Work Phone Number"; 
        if(!phoneValidation(string,alertTxt)) return false;



        if(fm.Borrowers_STATE[fm.Borrowers_STATE.selectedIndex].value == ".." || fm.Borrowers_STATE[fm.Borrowers_STATE.selectedIndex].value == "null" )
        {
                alert("This field Borrowers STATE is required.")
		fm.Borrowers_STATE.focus();
		return false;
        }
       
        if(fm.propSTATE[fm.propSTATE.selectedIndex].value == ".." || fm.propSTATE[fm.propSTATE.selectedIndex].value == "null" )
        {
                alert("This field Borrowers Property Information STATE is required.")
		fm.propSTATE.focus();
		return false;
        }
        




        var yearlyIncome=fm.Borrower_Salary;
        if(!validatedecimalforacres(yearlyIncome, 'Yearly Income')) return false;
        var monHouseExpense=fm.Borrower_MonHouEx;
        if(!validatedecimalforacres(monHouseExpense, 'Monthly House Expense')) return false;
        var monExpenseOth=fm.Borrower_MonExOth;
        if(!validatedecimalforacres(monExpenseOth, 'Monthly Expense other')) return false;
       
	if (fm.BorrowInitials.value =="" || fm.BorrowInitials.value.length != 3) {
		alert("Initials for the Borrower must be 3 charecters to submit this form.");
		fm.BorrowInitials.focus();
		return false;
	}    
               
        if (co_name.value!="") {
              
              if (fm.coBorrowers_Relation[fm.coBorrowers_Relation.selectedIndex].value == "N/A") {            
                        alert("The Co-Borrower's realtionship with borrower must also be provided.");
                        fm.coBorrowers_Relation.focus();
                        return false;
		}
                if (co_lname.value=="") {            
                        alert("The Co-Borrower's last name must also be provided.");
                        co_lname.focus();
                        return false;
		}
                
		if (co_birth.value=="") {            
                        alert("The Co-Borrower's date of birth must also be provided.");
                        co_birth.focus();
                        return false;
		}
                if(!validateForm(co_birth)) return false;
		if (co_ssn.value=="") {            
                        alert("The Co-Borrower's Social Security number must also be provided.");
                        co_ssn.focus();
                        return false;
		}


                if (co_sal.value=="") {             
                        alert("The Co-Borrower's Yearly Income must also be provided.");
                        co_sal.focus();
                        return false;
		}
		if(fm.CoBorrowInitials.value=="" || fm.CoBorrowInitials.value.length != 3) {
			alert("Initials for the Co-Borrower must be entered in order to submit this form.");
			fm.CoBorrowInitials.focus();
			return false;
		} 
	}
         
        var hearAboutUs=fm.hearAboutUs;
        if(!selectHearAboutUsFn(hearAboutUs)) return false;
	return true;
} 
// for date format check 'mm/dd/yyyy' format 
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
// make sure 's' contains all numbers..
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
   } 
   return this;
}


function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
return true
}
        
function validateForm(dob){
	var dt=dob;
	if (isDate(dt.value)==false){
		dt.focus();
		return false;
	}
    return true;
 }


// end of date format check methods....


// function in retailerOrderForm.jsp. Make sure all required fields are non-empty
function validateRequiredFields(retailerFm) {
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message 
        rField[1]="dfltShipCompanyName";    rText[1]="Shipping Company";
        rField[2]="dfltShipAddress1";       rText[2]="Shipping Address";
        rField[3]="dfltShipCITY";           rText[3]="CITY";
        rField[4]="dfltShipSTATE";          rText[4]="STATE";
        rField[5]="dfltShipZIP";            rText[5]="ZIP Code";
        for(i=1;i<rField.length;i++){
               if(retailerFm.elements[rField[i]].value=="" || retailerFm.elements[rField[i]].value=="null"){
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        retailerfm.elements[rField[i]].focus();
   			return false;
    	        }
        }
        if(retailerFm.txtQty1.value == 0 && retailerFm.txtQty2.value == 0 && retailerFm.txtQty3.value == 0) {
            alert("At least one quantity should be > 0 ");
            retailerFm.txtQty2.focus();
            return false;
        }
        var STATE=retailerFm.dfltShipSTATE;
        if(!selectSTATE(STATE)) return false;
        var ZIP=retailerFm.dfltShipZIP;
        if(!ZIPValidation(ZIP)) return false;
        var input=retailerFm.shipToPhoneNbrArea;
        var txtMsg="Phone";
        if(!digitsValidation(input,txtMsg)) return false;
        var input=retailerFm.shipToPhoneNbrPrefix;
        if(!digitsValidation(input,txtMsg)) return false;
        var input=retailerFm.shipToPhoneNbrSuffix;
        if(!digitsValidation(input,txtMsg)) return false;
        return true;
}








function warrantyReq(warranty) {
    if(warranty.ZIP.value == ""){
     alert("This field ZIP/Postal Code is required.");
            warranty.ZIP.focus();
            return false;
    }


       var hearAboutUs=warranty.hearAboutUs;
        if(!selectHearAboutUsFn(hearAboutUs)) return false;
	return true;


}


function warrantyDetails(warranty) {
        var rField = new Array();       // to hold the form field names 
        rText = new Array();            // to hold user-friendly strings for error message 
        rField[1]="street_nbr";    rText[1]="Street Number ";
        rField[2]="street_name";       rText[2]="Street Name";

        rField[3]="firstname";           rText[3]="First name";
        rField[4]="lastname";          rText[4]="Last name";
        rField[5]="phone_nbr";            rText[5]="phone number ";
        for(i=1;i<rField.length;i++){
               if(warranty.elements[rField[i]].value=="" ){
                        // display user-friendly field name
                   	alert("This field "+rText[i]+" is required.");
    		        warranty.elements[rField[i]].focus();
   			return false;
    	        }
        }




}
// function in retailOrderForm.jsp 
// goto page retailerSelection.jsp when cancel btn is clicked
function goToRSelection(){
        document.form1.action="retailerSelection.jsp";
        document.form1.canBtn.value="go";
        document.form1.submit();
}


// make sure the sales Rep field is non-empty in retailerSetup.jsp
function validateRetailer(retailerFm){
        if(retailerFm.salesID[retailerFm.salesID.selectedIndex].value == "" || retailerFm.salesID[retailerFm.salesID.selectedIndex].value == ".." || retailerFm.salesID[retailerFm.salesID.selectedIndex].value == "null" ){
                alert("This field Sales Rep is required.")
		retailerFm.salesID.focus();
        	return false;
        }
        return true;
}

// Returns true if the string only contains alpha numeric characters (empty string = true)
function isAlphaNumeric(txt)
{
	return ValidString(txt,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@.');
}

// Returns true if the CheckString only contains characters passed in ValidString (empty string = true)
function ValidString(ChkString,ValidString)
{
	for (i=0; i<ChkString.length; i++)
	{
		if (ValidString.indexOf(ChkString.substring(i,i+1)) == -1) return false;
	}
	return true;
}


// End hide script from old browsers -->




