function handleFormReturn(newPage){
    tb_remove();
    window.location='/commercial/'+newPage;
}
function validatePropSearch(frm)
{
    locat = frm.locationQuery.value
    if (locat == 'City, State, Zip Code, or County')
    {
        frm.locationQuery.value = '';
    }
    return handlePropReturn(true,frm);
}

function handlePropReturn(returnValue,frm)
{
    index = window.location.href.indexOf('popUpSearch');
    if (index > -1)
    {//this is a popup text
        propertyType='';
        var count = 0;
        for (var i=0; i<frm.propertyType.length; i++) {
         if (frm.propertyType[i].checked) 
         {
            if (count > 0) {propertyType+='&propertyType='; }
            
            propertyType+=frm.propertyType[i].value;
            
            count++;
         }
        }
        locat = frm.locationQuery.value
        params = '?locationQuery='+handleHtmlEncoding(locat,false);
        if (count > 0)
        {
            params += '&propertyType='+propertyType;
        }           
        self.parent.closeChildAndDPropSearch(params);
        return false;
    }
    
    return returnValue;    
}


function validateAgtSearch()
{
 var fname = document.forms['AgtSearchGet'].firstName.value;
 var lname = document.forms['AgtSearchGet'].lastName.value;
 var city = document.forms['AgtSearchGet'].city.value;
 var state = document.forms['AgtSearchGet'].state.value;
 var expertise = document.forms['AgtSearchGet'].expertise.value;
 
 if (fname != '' || lname != '' || (city != '' && state != '') || expertise != '')
 {
    return handleAgentReturn(true);
 }
 else 
 {
    alert('You must include either First Name, Last Name, Expertise or both City and State in your search criteria.');
    return false;
 }
}

function validateOfficeSearch()
{
    var city = document.getElementsByName('value.city')[0].value;
    var state = document.getElementsByName('value.stateProv')[0].value;
    var zip = document.getElementsByName('value.postalCd')[0].value;
    if ((city != '' && state != '') && zip == '')
    {
        return handleOfficeReturn(true);
    }
    else if ((city == '' && state == '') && zip != '')
    {
        return handleOfficeReturn(true);
    }
    else 
    {
        alert('You must include City and State/Province or Zip/Postal Code but not both in your search criteria.');
        return false;
    }
}

function handleOfficeReturn(returnValue)
{
    index = window.location.href.indexOf('popUpSearch');
    if (index > -1)
    {//this is a popup text
        params = '?value.city='+handleHtmlEncoding(document.getElementsByName('value.city')[0].value,false)
                    +'&value.stateProv='+handleHtmlEncoding(document.getElementsByName('value.stateProv')[0].value,false)
                    +'&value.postalCd='+handleHtmlEncoding(document.getElementsByName('value.postalCd')[0].value,false);
        self.parent.closeChildAndDoOfficeSearch(params);
        return false;
    }
    
    return returnValue;    
}

function handleAgentReturn(returnValue)
{
    index = window.location.href.indexOf('popUpSearch');
    if (index > -1)
    {//this is a popup
          params = '?firstName='+handleHtmlEncoding(document.forms['AgtSearchGet'].firstName.value,false)
             +'&lastName='+handleHtmlEncoding(document.forms['AgtSearchGet'].lastName.value,false)
             +'&city='+handleHtmlEncoding(document.forms['AgtSearchGet'].city.value,false)
             +'&state='+handleHtmlEncoding(document.forms['AgtSearchGet'].state.value,false)
             +'&expertise='+handleHtmlEncoding(document.forms['AgtSearchGet'].expertise.value,false);
        self.parent.closeChildAndDoAgentSearch(params);
        return false;
    }
    
    return returnValue;    
}


function showhide(val){
              if (nNAV = document.getElementById(val).style){
                nNAV.display = (nNAV.display == 'block')? 'none' : 'block';
              }
          }
          
          function TabNext(obj,len,next_field) {
             if (obj.value.length == len) {
                 next_field.focus();
             }
          } 
          
          maxL=4000;
        function taCount(taObj,Cnt) { 
                objCnt=document.getElementById(Cnt);
                objVal=taObj.value;
                objCnt.innerHTML=maxL-objVal.length;
        }
        
        function validate(form)
        {
            errors = "";
            if (form.memberName.value.length == 0)
            {
                errors += "Name is required.\n";
            }
            if (form.email.value.length == 0)
            {
                errors += "Email is required.\n";
            }
            if (form.city.value.length == 0)
            {
                errors += "City is required.\n";
            }
            if (form.comments.value.length == 0)
            {
                errors += "Comments are required.\n";
            }
            if (form.comments.value.length > maxL)
            {
                errors += "Comments are to be less than "+maxL+" characters.\n";
            }
            if (errors == "")
            {
                return true;
            }
            alert(errors);
            return false;
        }
        
        
        
function handleHtmlEncoding(text,convertFromHtml) 
{

    fromTo = new Array(//'&copy;','©',
//    '&deg;','°',
//    '&frac12;','½',
//    '&frac14;','¼',
//    '&frac34; ','¾',
    '&gt;','>',
    '&gt','>',
//    '&laquo;','«',
    '&lt;','<',
    '&lt','<',
//    '&mdash;','—',
//    '&micro;','µ',
//    '&middot;','·',
    '&ndash;','–',
//    '&not;','¬',
//    '&pound;','£',
    '&quot;','\"',
//    '&raquo;','»',
    '&reg;','®',
    '&tilde;','˜',
    '&trade;','™'
     );
     
    
    
    if (convertFromHtml) 
    {
        fromTo[fromTo.length] = '&amp;';
        fromTo[fromTo.length] = '&';
    }
    else 
    {
        text = text.replace(eval('/&/g'), '&amp;');
    }
    
    var nextKey = 0;
    var nextVal = 0;
    for (i=0; i < fromTo.length; i=i+2)
    {
        if (convertFromHtml)
        {
            nextKey = i;
            nextVal = i+1;
        }
        else
        {
            nextKey = i+1;
            nextVal = i;
        }

            text = text.replace(eval('/'+fromTo[nextKey]+'/'), fromTo[nextVal]);

    }

    return text;
}
