
function WM_netscapeCssFix()
{
    // This part was inspired by Matthew_Baird@wayfarer.com
    // It gets around another unfortunate bug whereby Netscape
    // fires a resize event when the scrollbars pop up. This
    // checks to make sure that the window's available size
    // has actually changed.

    if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth
        || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight)
        {
        document.location = document.location;
        }
}

function WM_netscapeCssFixCheckIn()
{
    // This function checks to make sure the version of Netscape
    // in use contains the bug; if so, it records the window's
    // width and height and sets all resize events to be handled
    // by the WM_netscapeCssFix() function.

    if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4))
        {
        if (typeof document.WM == 'undefined')
            {
            document.WM = new Object;
            }

        if (typeof document.WM.WM_scaleFont == 'undefined')
            {
            document.WM.WM_netscapeCssFix = new Object;
            document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
            document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
            }

        window.onresize = WM_netscapeCssFix;
        }
}

WM_netscapeCssFixCheckIn()

// END HIDING --->

function dummy() {return;}

function go_back() { window.history.back(); }

function onoff(imgName,state) {
  if(document.images) {
    if (state == 'on') {
      document.images[imgName].src = 'images/' + imgName + '-act.gif';
    } else {
      document.images[imgName].src = 'images/' + imgName + '.gif';
    }
  }
}

function viewHelp(url) {
  date = new Date();
  var bars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=400,height=350';
  var newWin = open (url, 'HELP_'+date.getTime(), bars);
  newWin.focus();
}

function viewVendorProfile( VendorID, ServiceID ) {
  date = new Date();
  var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,width=680,height=680';
  var location = '/CompanyProfile?VendorHook='+VendorID;
  if( ServiceID != null ) {
    location = location + '&SelectedService='+ServiceID;
  }
  var newWin = open (location+'&timestamp='+date.getTime(), 'VendorProfile_'+date.getTime(), myBars);
  newWin.focus();
}

function viewStatistics(site_url) {
  date = new Date();
  var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,resizable=yes,width=650,height=450';
  var newWin = open (site_url+'/Summary?toolkit=yes', 'Summary', myBars);
  newWin.focus();
}

function fn_isMSIE() {
  var user_agent = navigator.userAgent.toLowerCase();
  if( user_agent.indexOf( "msie" ) == -1 ) {
    return false;
  } else {
    return true;
  }
}

function isRTEAllowed() {
  var ver_idx = navigator.appVersion.indexOf("MSIE");
  return ver_idx >= 0 && navigator.appVersion.toLowerCase().indexOf("mac") == -1 && 
         parseInt(navigator.appVersion.substring(ver_idx + 5,ver_idx + 6)) >=5;
}

function handleKeyDown( event ) {
  var type, keyCode, onEvent;
  if( fn_isMSIE() ) {
    // MSIE
    type = window.event.srcElement.type;
    keyCode = window.event.keyCode;
    onEnter = window.event.srcElement.onEnter;
  } else {
    // Mozilla and others
    type = event.target.type;
    keyCode = event.which;
    onEnter = event.target.onEnter;
  }
  if( ( ( type == 'select-multiple' || type == 'text' || type == 'password' || type == 'checkbox' || type == 'radio' )
      && ( keyCode == 13 || keyCode == 10 ) )
    || ( type == 'textarea' && keyCode == 10 )
  ) {
    if( onEnter != null ) {
      //var onEnter = new Function( onEnter );
      //onEnter.call();
      eval(onEnter);
      return false;
    } else {
      if( fn_isMSIE() ) {
        // MSIE
        window.event.keyCode = 9;
      } else {
        // Mozilla and others
        return false;
      }
    }
  }
  return true;
}

if( fn_isMSIE() || navigator.userAgent.indexOf("Gecko") ) {
  // MSIE
  document.onkeydown = handleKeyDown;
} else {
  // old Mozilla and others 
  document.captureEvents( Event.KEYDOWN );
  document.onKeyDown = handleKeyDown;
}


function RunOnLoad() {
  if ( document.forms.SearchForm ){
    var idx = "";
    if(document.forms.SearchForm.areas_sort_type){
      if(document.forms.SearchForm.hdn_areas_sort_type.value == "area_code"){
        document.forms.SearchForm.areas_sort_type[1].checked="1";
      }else{
        document.forms.SearchForm.areas_sort_type[0].checked="1";
      }
      setAreasSortType(document.forms.SearchForm.hdn_areas_sort_type.value,document.forms.SearchForm.hdn_areas_sort_type,false);
    }
    if(document.forms.SearchForm.hdn_location_search_type){
      setAreasSearchType(document.forms.SearchForm.hdn_location_search_type.value);
    }

    if(document.forms.SearchForm.ls.value == "MAX"){
      idx = "idx";
    }
    if(document.forms.SearchForm.county_source && document.forms.SearchForm.county_source.value!="0"){
      if(document.forms.SearchForm.is_lmls && document.forms.SearchForm.is_lmls.value=="true"){
        InitCountyLmls(document.forms.SearchForm.county_source.value,document.forms.SearchForm.area_source,As,idx);
      }else{
        InitCounty(document.forms.SearchForm.county_source.value,document.forms.SearchForm.area_source,As,idx);
      }
    }else if(document.forms.SearchForm.def_county && document.forms.SearchForm.def_county.value !=""){
      if(document.forms.SearchForm.is_lmls && document.forms.SearchForm.is_lmls.value=="true"){
        InitCountyLmls(document.forms.SearchForm.def_county.value,document.forms.SearchForm.area_source,As,idx);
      }else{
        InitCounty(document.forms.SearchForm.def_county.value,document.forms.SearchForm.area_source,As,idx);
      }
    }else{
      if(document.forms.SearchForm.is_lmls && document.forms.SearchForm.is_lmls.value=="true"){
        getAllAreasLmls(document.forms.SearchForm.area_source,As,idx);
      }else{
        getAllAreas(document.forms.SearchForm.area_source,As,idx);
      }
    }

    if (document.forms.SearchForm.area_code) {
      InitAreas(document.forms.SearchForm.area_code.value,As, idx);
    }
    else if(document.forms.SearchForm.geo_area) {
      InitAreas(document.forms.SearchForm.geo_area.value,As, idx)
    }
    else if (document.forms.SearchForm.area) {
      InitAreas(document.forms.SearchForm.area.value,As, idx);
    }
    else if (!document.forms.SearchForm.geo_area && document.forms.SearchForm.city) {
      InitCities(document.forms.SearchForm.city.value,As, idx);
    }
    else{
    }
  }

  if(typeof parent.reverse_search_flag != 'undefined' && parent.reverse_search_flag){
      initAreas(reverse_search_county_id,reverse_search_area_id);
  }

  if(window.startToWatchSession) {
    startToWatchSession();
  } else {
//    alert('Session library was not included!');
  }
  startclock();
}


function RunOnLoadIdx() {
  if ( document.forms.SearchForm ){
    if (document.forms.SearchForm.idx_area_code){
      InitCountyIdx(document.forms.SearchForm.county_source.options[document.forms.SearchForm.county_source.selectedIndex].value, document.forms.SearchForm.idx_area_code, As);
    }
    else{
      getAllAreas(document.forms.SearchForm.city,As,"idx");
    }
  }
  if(document.forms.search){
    if(document.forms.search.area_code_tmp){
      restoreAreas(document.search.area_code_tmp,document.search.SelectedArea.value);
    }
  }
} 

function doHelp(topic) {
  if(!topic || topic=="") topic = "overview";
  date = new Date();
  var bars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=yes,scrollbars=yes,resizable=yes,width=850,height=600';
//  var newWin = open ('/Help.html', 'HELP_'+date.getTime(), bars);
  var newWin = open ('/Help?topic=toolkit&toolkit_topic='+topic, 'HELP_TOOLKIT_'+topic, bars);
  newWin.focus();
}

function doOnlineSupport() {
   document.location.href = "/OnlineSupport?timestamp=" + ( new Date() ).getTime(); 
}

function nav( page ) {
  document.location.href = "/RealtorHome?page=" + page;
}
//function ln_MyCalendar() { document.location.href = "/ViewAllServiceCalls?timestamp=" + ( new Date() ).getTime(); }
function ln_PersonalProfile() { document.location.href = "/MyProfile?timestamp=" + ( new Date() ).getTime(); }
function ln_WebPage() { document.location.href = "/WebPageEditor?timestamp=" + ( new Date() ).getTime(); }
//function ln_MBWebPage() { document.location.href = "/MBProfileEditor?operation=edit_website"; }
function ln_MyAccount() { document.location.href = "/MyAccount?timestamp=" + ( new Date() ).getTime(); }

function ln_logoff() {
  document.LogoffForm.loginAction.value = URL_Servlet;
  document.LogoffForm.loginParam.value = URL_Param;
  document.LogoffForm.submit();
}

var timerID = null;
var timerRunning = false;

function stopclock() {
  if(timerRunning) clearTimeout(timerID);
  timerRunning = false;
}

function startclock() {
  stopclock();
  showtime();
}

function showtime () {
  var now = new Date();
  var hours = now.getHours();
  var minutes = now.getMinutes();
  var seconds = now.getSeconds()
  var timeValue = "" + ((hours >12) ? hours -12 :hours)
  timeValue += ((minutes < 10) ? ":0" : ":") + minutes
  timeValue += ((seconds < 10) ? ":0" : ":") + seconds
  timeValue += (hours >= 12) ? " P.M." : " A.M."
  if (document.clock) {
    document.clock.face.value = timeValue;
  }
  // you could replace the above with this
  // and have a clock on the status bar:
  // window.status = timeValue;
  timerID = setTimeout("showtime()",1000);
  timerRunning = true;
}

function cal_dummy() {}

function Calendar_months(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) {
  this[0] = m0;
  this[1] = m1;
  this[2] = m2;
  this[3] = m3;
  this[4] = m4;
  this[5] = m5;
  this[6] = m6;
  this[7] = m7;
  this[8] = m8;
  this[9] = m9;
  this[10] = m10;
  this[11] = m11;
}

var Calendar_month_names ="JanFebMarAprMayJunJulAugSepOctNovDec";

function Calendar (hdr_color) {
  if(!hdr_color){
    hdr_color = "#6699CC";
  }
  var today = new Date();
  // do the classic leap year calculation
  var monthDays = new Calendar_months(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  if (((today.getFullYear() % 4 == 0) && (today.getFullYear() % 100 != 0)) || (today.getFullYear() % 400 == 0))
    monthDays[1] = 29;
  // start coding calendar
  document.write("<table cellspacing='0' cellpadding='0' border='0'>");
  document.write("<tr align='center' bgcolor='#CCCCCC'><td>");
  document.write("<table cellspacing='1' cellpadding='2' border='0'>");
  document.write("<tr align='center' bgcolor='"+hdr_color+"'><td colspan='7'>");
  document.write("<font class='intro' color='#FFFFFF'>");
  document.write(Calendar_month_names.substring(today.getMonth() * 3, (today.getMonth() + 1) * 3));
  document.write("&#160;");
  document.write( today.getDate() );
  document.write(", ");
  document.write(today.getFullYear());
  document.write("</td></tr>");
  document.write("<tr align='center' bgcolor='#DDEEFF'>");
  document.write("<td><font class='h' color='#AD0000'>S</td><td><font class='h'>M</td><td><font class='h'>T</td><td><font class='h'>W</td><td><font class='h'>T</td><td><font class='h'>F</td><td><font class='h' color='#AD0000'>S</font></td></tr>");
  // now write the blanks at the beginning of the calendar
  document.write("<tr bgcolor='#ffffff' align='center'>");
  column = 0;
  var curDate = new Date( today );
  curDate.setDate( 1 );
  for( i = 0; i < curDate.getDay(); i++ ) {
    document.write("<td><font class='h'>&#160;");
    column++;
    document.write("</font></td>");
  }
  // write selected month's days
  var nDays = monthDays[today.getMonth()];
  for( i = 1; i <= nDays; i++ ) {
    if (column == 7) {
      document.write("</tr><tr align='center' bgcolor='#FFFFFF'>"); // start a new row
      column = 0;
    }
    document.write("<td align='center' bgcolor='#FFFFFF'><font class='h'>");
    if( i == today.getDate() ) document.write("<font color='#FF0000'>");
    document.write(i);
    if( i == today.getDate() ) document.write("</font>");
    column++;
    document.write("</td>");
  }
  document.write("</tr>");
  document.write("</table></td></tr>");
  document.write("</table>");
}

function SubmitForm(FormName,location_id,c_ca,callback_id) {
  document.forms[FormName].action = "/Navigator?location_id="+location_id+"&c_ca="+c_ca+"&callback_prev_id="+callback_id;
  document.forms[FormName].submit();
}

function viewDetails( url ) {
  date = new Date();
  var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=yes,scrollbars=yes,resizable=yes,alwaysRaised=yes,width=680,height=480';
  var location = url;
  var newWin = open (location+'&timestamp='+date.getTime(), 'MLS_'+date.getTime(), myBars);
  newWin.focus();
}

function checkRanges(input, size, alertstr) {
  var val = input.value;
  filler = '0';
  if(val.length == 0) return true;
  numbers = "\\s*(\\d{1,"+size+"}|\\d{1,"+size+"}\\s*-\\s*\\d{1,"+size+"})\\s*";
  var regexp = new RegExp("^"+numbers+"(,"+numbers+")*$");//
  var str = "";
  if(!regexp.test(val)) {
    alert(alertstr);
    input.focus(); 
    return false;
  }
  val = val.replace(/\s/g, "");
  while((i = val.search(/,|-/)) >= 0) {
    number = val.substring(0,i);
    delim = val.substring(i,i+1);
    if(number.length > 0) str += fillLeftWith(number, size, filler) + delim;
    val = val.substring(i+1);
  }
  if(val.length > 0) str += fillLeftWith(val, size, filler);
  input.value = str;
  return true;
}


function fillLeftWith(val, len, filler) {
  if (val=="") {
    return val;
  }
  while (val.length<len) {
    val = filler+val;
  }
  return val;
}

function getAlert(sales_serv_name,sc){
  if(sales_serv_name){
    var hsize = 610;
    if(navigator.appName=="Netscape" && !sc){
      var scroll = "no";
    } else {
      var scroll = "yes";
    }

    if(sales_serv_name=="AUTOCAPTURE") hsize = 520;
    if(sales_serv_name=="CRM") scroll = "yes";
    if(sales_serv_name=="FOLLOWUP") hsize = 500;
    if(sales_serv_name=="FOLLOWUP_SENDALL") hsize = 400;
    if(sales_serv_name=="FOLLOWUP_WM") hsize = 400;
    if(sales_serv_name=="HCC") hsize = 520;
    if(sales_serv_name=="INVMANMANUAL") hsize = 570;
    if(sales_serv_name=="INVMANMLS") scroll = "yes";
    if(sales_serv_name=="MLS") scroll = "yes";
    if(sales_serv_name=="MLSBEM") scroll = "yes";
    if(sales_serv_name=="MLSBEM_TOALL") hsize = 330;
    if(sales_serv_name=="OPENHOMES") hsize = 580;
    if(sales_serv_name=="TXREPORT") hsize = 400;
    if(sales_serv_name=="WSEDIT") hsize = 580;
    if(sales_serv_name=="WSSTAT") hsize = 580;
    if(sales_serv_name=="NGU") hsize = 580;
    if(sales_serv_name=="CFM") hsize = 580;
    if(sales_serv_name=="MLS_ALERT_CC_ADVER") hsize = 580;
    if(sales_serv_name=="SYNDICATE") hsize = 580;

    hsize = 550;
    scroll = "no";

    var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=yes,toolbar=yes,scrollbars=' + scroll + ',resizable=no,alwaysRaised=yes,width=720,height=' + hsize;
    var location = '/Advertise?page=' + sales_serv_name + '&size=' + hsize;
    var newWin = open (location, sales_serv_name, myBars);
    newWin.focus();
  }
}

function Area(area_name,area_code,county_number,is_delimiter){
  this.area_name = area_name;
  this.area_code = area_code;
  this.county_number = county_number;
  this.is_delimiter = is_delimiter;
}

function N(area_name,area_code,county_number,is_delimiter){
  return new Area(area_name,area_code,county_number,is_delimiter);
}
function L(arr){
  return arr.length;
}

function C(area_name,area_code,county_number,is_delimiter){
  if( L(As) > 0 && As[L(As)-1].area_code == area_code && As[L(As)-1].county_number == county_number){
    return;
  }
  else{
    As[L(As)]=N(area_name,area_code,county_number,is_delimiter);
  }
}

function Cc(area_name,area_code,county_number){
  if( L(Asc) > 0 && Asc[L(Asc)-1].area_code == area_code && Asc[L(Asc)-1].county_number == county_number){
    return;
  }
  else{
    Asc[L(Asc)]=N(area_name,area_code,county_number,false);
  }
}

function Ca(area_name,area_code,county_number){
  if( L(Asa) > 0 && Asa[L(Asa)-1].area_code == area_code && Asa[L(Asa)-1].county_number == county_number){
    return;
  }
  else{
    Asa[L(Asa)]=N(area_name,area_code,county_number,false);
  }
}

function C_a(area_name,area_code,county_number,is_delimiter){
    if(A_s)A_s[L(A_s)]=N(area_name,area_code,county_number,is_delimiter);
}

function C_c(area_name,area_code,county_number,is_delimiter){
  C_s[L(C_s)]=N(area_name,area_code,county_number,is_delimiter);
}

function setAreasSearchType(search_type){
  var isChanged=false;
  document.forms.SearchForm.hdn_location_search_type.value = search_type;
  if(search_type=="area_code"){
    if(document.forms.SearchForm.location_search_type)document.forms.SearchForm.location_search_type[1].checked="1";
    if(As!=Asa){
      As = Asa;
      isChanged=true;
    }
  }else{ //search_type=="city_name"
    if(document.forms.SearchForm.location_search_type)document.forms.SearchForm.location_search_type[0].checked="1";
    if(As!=Asc){
      As = Asc;
      isChanged=true;
    }
  }
  var county_to_restore_num=last_county_num;
  last_county_num = document.forms.SearchForm.county_source.selectedIndex;
  makeCountiesSearchLmls(search_type);
  if(county_to_restore_num>0)document.forms.SearchForm.county_source.selectedIndex = county_to_restore_num;
  if(isChanged){
    resortAreasLmls();
    changeAreasToSearch();
  }
}

function setAreasSortType(sort_type, control, force_resort){
  if(sort_type=="area_code"){
      document.forms.SearchForm.areas_sort_type[1].checked="1";
    if(As!=A_s){
      As = A_s;
      control.value=sort_type; 
      if(force_resort){
        resortAreas();
      }
    }
  }
  else if(sort_type=="city_name"){
      document.forms.SearchForm.areas_sort_type[0].checked="1";
    if(As!=C_s){
      As = C_s;
      control.value=sort_type; 
      if(force_resort){
        resortAreas();
      }
    }
  }
  else{
    document.forms.SearchForm.areas_sort_type[0].checked="1";
    if(As!=C_s){
      As = C_s;
      control.value=sort_type; 
      if(force_resort){
        resortAreas();
      }
    }
  }
}

function resortAreas(){ 
  if(document.forms.SearchForm.county_source && document.forms.SearchForm.county_source.value!="0"){
    InitCounty(document.forms.SearchForm.county_source.value,document.forms.SearchForm.area_source,As,"");
  }
  else if(document.forms.SearchForm.def_county && document.forms.SearchForm.def_county.value !=""){
    InitCounty(document.forms.SearchForm.def_county.value,document.forms.SearchForm.area_source,As,"");
  }
  else{
    getAllAreas(document.forms.SearchForm.area_source,As,"");
  }
}

function resortAreasLmls(){
  if(document.forms.SearchForm.county_source && document.forms.SearchForm.county_source.value!="0"){
    InitCountyLmls(document.forms.SearchForm.county_source.value,document.forms.SearchForm.area_source,As,"");
  }
  else if(document.forms.SearchForm.def_county && document.forms.SearchForm.def_county.value !=""){
    InitCountyLmls(document.forms.SearchForm.def_county.value,document.forms.SearchForm.area_source,As,"");
  }
  else{
    getAllAreasLmls(document.forms.SearchForm.area_source,As,"");
  }
}

function textAreaLenCheck(textArea,maxLen,charCnt){
  var dn = document.getElementById(charCnt);
  var len = textArea.value.length;
  if (len > maxLen){
    textArea.value = textArea.value.substring(0,800);
  }
  if (dn && len <= maxLen){
    if(textArea.value.length == 0){
      dn.innerHTML = "";
    } else {
      var content = "("+(maxLen-len)+" chars has left)";
      dn.innerHTML = "";
      dn.innerHTML = content;
    }
  }
}