function getTheEffect(id)
{
	var href_tag=document.getElementById(id);
	href_tag.className="on";
}
var zsbdef2='Location, District';

// misc. text-related functions
function trim(s)
{
  if (!s)
    return '';
  return s.replace(/^\s*|\s*$/g,"");
}

// pass it something
// check if is valid element or if it is id to get element
// returns element if found
// sanity check for functions
// and if you use this function 20 times through all your functions calls
// to get the same element you only do 1 DOM traverse by using whatever it returns
function xb_get_element(thing)
{
  if (typeof(thing) == 'undefined' || !thing)
  {
    return null;
  }
  else if (typeof(thing.tagName) == 'undefined' || !thing.tagName)
  {
    if (document.all)
      el = document.getElementById(thing) ? document.getElementById(thing) : document.all[thing];
    else
      el = document.getElementById(thing);

    if (el)
      return el;
    else
      return null;
  }
  else if (thing.tagName)
  {
    return thing;
  }
  else
  {
    return null;
  }
}


// sets or resets a box on focus/blur
function handle_edit_box(box, default_value, focused)
{
  var box = xb_get_element(box);
  
  if (!box)
    return;
    
  var val = trim(box.value).toLowerCase();
  var def_val = default_value.toLowerCase();
  
  // if focused and non-default, value and black
  // if non-focused and non-default, value and black
  if (val !== def_val && val !== '')
  {
    remove_class(box, 'disabled_txt');
    box.style.color='#000';
    return;
  }

  // if focused and default value, blank and black
  if (focused && (val === def_val || val === ''))
  {
    box.style.color = '#000';
    remove_class(box, 'disabled_txt');
    box.value = '';
    return;
  }

  // if non-focused and default value, default and gray
  if (!focused)
  {
    if (val === def_val || val === '')
    {
      box.style.color = '#999';
      add_class(box, 'disabled_txt');
      box.value = default_value;
    }
    else
    {
      box.style.color = '#000';
      remove_class(box, 'disabled_txt');
    }
    return;
  }
}// end of function handle_edit_box


/**
Checks if an element has a class
@param  el              element to check. Can be the id or the actual element
@param  searched_class  class to checked

@return boolean
**/
function has_class(el, searched_class)
{
  if (typeof(searched_class) == 'undefined' || !searched_class)
    return false;

  // check valid parameter
 el = xb_get_element(el);

  if (!el)
    return false;

  var class_array = el.className.split(' ');

  for(var i in class_array)
  {
    if (class_array[i] == searched_class)
      return true;
  }
  return false;
}


/**
Adds a class to an element
@param  el            element whose class to add. Can be the id or the actual element
@param  add_class     class to be added

@return boolean
**/
function add_class(el, added_class)
{
  if (typeof(added_class) == 'undefined')
    return false;

  // check valid parameter
  el = xb_get_element(el);

  // if element doesn't exist, or class already there, or no class to add
  if (!el || has_class(el, added_class))
      return false;

  el.className = el.className + ' ' + added_class;

  return true;
}


/**
Removes a class from an element
@param  el            element whose class to remove. Can be the id or the actual element
@param  remove_class  class to be removed

@return boolean
**/
function remove_class(el, removed_class)
{
  if (typeof(removed_class) == 'undefined')
    return false;

  // check valid parameter
  el = xb_get_element(el);

  // if element doesn't exist, or class not there, or no class to remove
  if (!el)
    return false;

  var class_array = el.className.split(' ');
  var class_changed = false;

  for (var i in class_array)
  {
    if (class_array[i] == removed_class)
    {
      // delete removed_class
      class_array.splice(i, 1);
      class_changed = true;
    }
  }

  if (class_changed)
    el.className = class_array.join(' ');

  return class_changed;
}


// pass it something
// check if is valid element or if it is id to get element
// returns element if found
// sanity check for functions
// and if you use this function 20 times through all your functions calls
// to get the same element you only do 1 DOM traverse by using whatever it returns
function xb_get_element(thing)
{
  if (typeof(thing) == 'undefined' || !thing)
  {
    return null;
  }
  else if (typeof(thing.tagName) == 'undefined' || !thing.tagName)
  {
    if (document.all)
      el = document.getElementById(thing) ? document.getElementById(thing) : document.all[thing];
    else
      el = document.getElementById(thing);

    if (el)
      return el;
    else
      return null;
  }
  else if (thing.tagName)
  {
    return thing;
  }
  else
  {
    return null;
  }
}


//------------------------------------------------------------------------------------------------------------------------------------

function setCookie(cookieName,cookieValue,expireDate)
{
  if (typeof(expireDate)=='undefined')
    var expireDate = '';
  document.cookie = cookieName +"="+ escape(cookieValue) +";expires=\""+ expireDate +"\";path=/;";
}

//------------------------------------------------------------------------------------------------------------------------------------

// We don't use this on details page anymore
// TODO: Delete if not used
function show_error_box(e)
{
  close_modals_except('error_box');
  // if listings page, hoist the box out of the property details div
  if (typeof(pdtl) != 'undefined')
  {
    var the_box = xb_get_element('error_box');
    the_box.parentNode.removeChild(the_box);
    document.body.appendChild(the_box);
  }
  position_at_event('error_box', 300, 600, e);
  unhide('error_box');
}

/**
@param e        event fired
@param state    can be login or anything else
@param center   position box at center of screen
@param pos      specified position in format { x:? , y:? }
@param suffix   suffix for the id of the login box (ex: id="login_box_2" --> suffix is "_2")
@return nothing
**/
/* function show_login(e, state, center, pos, suffix, addl)*/

function show_login(e, state, center, pos, suffix, pid, addl)
{     
	(pid)?(enquiry(pid)):('') // if property ID is available  call Enquiry function 
	
	if (typeof(suffix) == 'undefined' || !suffix) { suffix = ''; }
	var the_box = xb_get_element('login_box' + suffix);
	
	// if login_box not found, might be because suffix is wrong
	var i = 0;

	while (the_box == null && i < 5)
	{
		suffix = '_' + i;
		the_box = xb_get_element('login_box' + suffix);
		i++;
	}

	// if login_box still not found, redirect to login/register/password page
	if (the_box == null)
	{
		if (state.indexOf('page') == -1)
		{
			toggle_login_form(state + '_page', '', addl);
		}
		else
		{
			toggle_login_form(state, '', addl);
		}
		return;
	}

  // place the box
  if (typeof(pos) != 'undefined' && pos)
  {
    close_modals_except(the_box);
    // the box has an inside div that hass the content with a -4px margin
    var top = pos.y ? pos.y - 4 : '0';
    var left = pos.x ? pos.x - 4 : '0';

    // Yes, we call set_save_property_links twice, the first prevents page scroll hopping,
    // the second fixes offscreen popup loads
    set_safe_popup_coords(null, the_box, left, top);
    toggle_login_form(state, suffix, addl);
    var coords = set_safe_popup_coords(null, the_box, left, top);

    unhide(the_box, '')
    var dim = get_object_dimensions(the_box)
    var the_w = dim.width;
    var the_h = dim.height;

    DOMUtils.hide_selects_by_el(the_box, coords['left'], coords['top'], the_w, the_h);
  }
  // show box near event
  else
  {
    unhide(the_box, '')
    toggle_login_form(state, suffix, addl);

    if (typeof(e) != 'undefined' && e)
    {
      show_pos_menu(e, the_box, -25, 10);
    }
    else
    {
      if (center == true)
      {
        var dim = get_object_dimensions(the_box)
        var the_w = dim.width;
        var the_h = dim.height;

        position_at_center(the_box, the_w, the_h);
      }
      else
      {
        the_box.style.right = '0px';
        the_box.style.top = '20px';
      }

      close_modals_except(the_box);
    }
  }
}
function login_reset()
{
  add_class('search_info_section','hidden');
  add_class('saved_search_form_section','hidden');
  add_class('email_alert_form_section','hidden');
  add_class('saved_search_buttons', 'hidden');
  //xb_get_element('login_box_popup_header').innerHTML = 'Log in';
  sub_queue.clear(); // Clear subscribe to search queue
}

function hide_login_form(suffix)
{
   remove_class('register_form_container' + suffix, 'hidden');
   add_class('login_form_container' + suffix, 'hidden');
   add_class('password_form_container' + suffix, 'hidden');
   add_class('login_box' + suffix, 'hidden');
   unhide_selects();
}


// closes all div popups except for one
function close_modals_except(id)
{
  switch(id)
  {
    case 'email_box':
      close_error_window();
      set_show_prefs('li_box', 'li_show');
      hide('li_box');
      break;
    case 'error_box':
      set_show_prefs('li_box', 'li_show');
      hide('li_box');
      close_email_property_window();
      break;
    case 'login_box':
      close_error_window();
      close_email_property_window();
      close_email_search_window();
      break;
    case 'email_search_box':
      hide('login_box');
      hide('ea_form_top');
    default:
      break;
  }
}

/**
 * set_safe_popup_coords
 * Positions an element (good for popup divs), making sure it does not go off-screen
 * @param e event for obtaining cursor position (may be null to use provided x/y coords only)
 * @param el element object to position
 * @param x x-coord without event, otherwise horizontal offset from cursor
 * @param y y-coord without event, otherwise vertical offset from cursor
 * @return coords object containing element's 'top' and 'left' position
 */
function set_safe_popup_coords(e, el, x, y, force)
{
  var coords = {'top':0,'left':0};
  // get page width/offsets before showing element
  var pageWidth  = f_clientWidth();
  var scrollLeft = f_scrollLeft();
  var pageHeight = f_clientHeight();
  var scrollTop  = f_scrollTop();
  var buffer     = 40; // for scrollbar, etc.

  var cursor = {x:0,y:0};
  if (e!=null)
  {
    var cursor = getPosition(e);
  }
  var dim  = get_object_dimensions(el);

  // Center all popups, apart from rss
  if (el.id != 'f_rss' && el.id != 'rss_pulldown')
  {
    var cl = f_clientSize();
    var posx = Math.round((cl.width - dim['width'])/2);
    var posy = Math.round((cl.height - dim['height'])/2);
    el.style.left = posx + 'px';
    el.style.top = (posy + cl.scrollTop) + 'px';

    coords['top'] = posy + cl.scrollTop;
    coords['left'] = posx;
  }
  else
  {
    // you need to have the popup appear not under the cursor so that you don't end up with your popup going spastic,
    // hence the min 5px displacement
    var top = (cursor.y ? cursor.y : 0) + (typeof(y) != 'undefined' && y > 0 ? y : 5);
    var height  = dim['height'];

    // alert('top: '+top+ ' height: '+height+ ' pageHeight: '+pageHeight+ ' scrollTop: '+scrollTop+ ' buffer: '+buffer);
    top = get_safe_coord(top, height, pageHeight, scrollTop, buffer);

    coords['top'] = top;
    el.style.top = top + 'px';

    // make sure popup element does not show off screen (where possible)
    // modifies x/left coord only; does not take y/top into consideration
    var left   = (cursor.x ? cursor.x : 0)+ (typeof(x) != 'undefined'  && (force || x > 0) ? x : 5);
    var width  = dim['width'];

    // alert('left: '+left+ ' width: '+width+ ' pageWidth: '+pageWidth+ ' scrollLeft: '+scrollLeft+ ' buffer: '+buffer);
    left = get_safe_coord(left, width, pageWidth, scrollLeft, buffer);

    coords['left'] = left;
    el.style.left  = left + 'px';
  }

  return coords;
}

/**
 * get_safe_coord
 * Helper for set_safe_popup_coords
 * @param coord top/left of element
 * @param dimension height/width of element
 * @param pageDimension height/width of page (view port)
 * @param pageScrollOffset top/left page scroll offset
 * @param buffer amount to push from page edge
 * @return coord new top/left coordinate for element
 */
function get_safe_coord(coord, dimension, pageDimension, pageScrollOffset, buffer)
{
  if ((coord + dimension + buffer) > pageDimension + pageScrollOffset)
  {
    coord = pageDimension + pageScrollOffset - (dimension + buffer); // don't go off the right/bottom of the page
    if (coord < pageScrollOffset) // take scroll/left/top of page into account
    {
      coord = pageScrollOffset + 10;
    }
  }

  return coord;
}


function f_clientSize()
{
  var c = new Object;
  c.width = f_clientWidth();
  c.height = f_clientHeight();
  c.scrollLeft = f_scrollLeft();
  c.scrollTop =  f_scrollTop();
  return c;
}
function f_clientWidth()
{
  return f_filterResults
  (
    window.innerWidth ? window.innerWidth : 0,
    document.documentElement ? document.documentElement.clientWidth : 0,
    document.body ? document.body.clientWidth : 0
  );
}
function f_clientHeight()
{
  return f_filterResults
  (
    window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
  );
}
function f_scrollLeft()
{
  return f_filterResults
  (
    window.pageXOffset ? window.pageXOffset : 0,
    document.documentElement ? document.documentElement.scrollLeft : 0,
    document.body ? document.body.scrollLeft : 0
  );
}
function f_scrollTop()
{
  return f_filterResults
  (
    window.pageYOffset ? window.pageYOffset : 0,
    document.documentElement ? document.documentElement.scrollTop : 0,
    document.body ? document.body.scrollTop : 0
  );
}
function f_filterResults(n_win, n_docel, n_body)
{
  var n_result = n_win ? n_win : 0;
  if (n_docel && (!n_result || (n_result > n_docel)))
    n_result = n_docel;
  return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
// returns array of IDs for tags of type tag whose IDs begin with prefix
function get_ids_with_prefix(tag,prefix)
{
  var s = new Array();
  var e = document.getElementsByTagName(tag);
  for (var i = 0; i < e.length; ++i)
  {
    if (e[i].id && e[i].id.indexOf(prefix) == 0)
      s.push(e[i].id);
  }
  return s;
}
// hide filter menus
function close_all_menus(e)
{
  if(typeof(e) == 'undefined')
    var e = window.event;

  if (e)
    doNothing(e);

  toggle_menu(e,mutexes[_MENU_MUTEX],0);
  release_mutex(_MENU_MUTEX);
}

/**
Finds computed width and heigth of an element
@param  el      required, element. Can be id or actual element
@return array   {height: x, width:y}
**/
function get_object_dimensions(el)
{
  // check valid parameter
  el = xb_get_element(el);
  if (!el)
    return { 'height': null, 'width': null };

  var changed_display = false;

  // element can't be display none if we want to get the dims
  if (el.style.display == 'none')
  {
    el.style.display = '';
    changed_display = true;
  }

  var objWidth = 0;
  var objHeight = 0;
  if (el.offsetWidth || el.offsetWidth === 0)
  {
    objWidth = el.offsetWidth;
    objHeight = el.offsetHeight;
  }
  else if (document.defaultView.getComputedStyle)
  {
    objHeight = document.defaultView.getComputedStyle(el, "").getPropertyValue("height");
    objWidth = document.defaultView.getComputedStyle(el, "").getPropertyValue("width");
  }
  else if (el.clip)
   {
     objWidth = el.clip.width;
     objHeight = el.clip.height;
   }

  if (changed_display)
    el.style.display = 'none';

  return { 'height':objHeight, 'width':objWidth };
}

// ********************************
// login/register forms
function LoginForm(suffix,addl)
{
  if (typeof(suffix) == 'undefined' || !suffix) { suffix = ''; }
  this.suffix   = suffix;
  this.box      = xb_get_element('login_box'+suffix);
  this.lt       = xb_get_element('login_form'+suffix);
  this.rt       = xb_get_element('register_form'+suffix);
  this.pt       = xb_get_element('password_form'+suffix);
  this.ct       = xb_get_element('changepwd_form'+suffix);
  this.ai       = xb_get_element('active_form'+suffix); // ------------------  
  this.et       = xb_get_element('enquiry_form'+suffix); //Enquiry form
  this.at       = xb_get_element('checkbox_form'+suffix); //Checkbox alert form
  this.prt       = xb_get_element('property_form'+suffix); ///////////////////////////////  
  this.cet       = xb_get_element('comments_form'+suffix); //Comment Edit form
    
  this.ssf      = xb_get_element('saved_search_form_section');
  this.eaf      = xb_get_element('email_alert_form_section');
  this.header   = xb_get_element('login_box' + suffix + '_popup_header');
  this.login_header = 'Log in';
  this.register_header = 'Create an account';
  this.password_header = 'Forgot your Password?';
  this.changepassword_header = 'Change Password';
  this.email_header = 'Get email updates';
  this.search_header = 'Save this search';
  this.enquiry_header = 'Send Enquiry';  
  this.checkbox_header = 'Alert';
  this.activation_header = 'Activation ID'; 
  this.property_header = 'View Property'; /////////////////////////
  this.comments_header = 'Enquiry Comments'; /////////////////////////

  this.at_e    = xb_get_element('login_email_field'+suffix);
  this.at_a    = xb_get_element('login_activationId_field'+suffix);  
  this.pw_prompt = xb_get_element('enter_password_prompt'+suffix);
  this.reg_name  = xb_get_element('name_field'+suffix);
  this.reg_e    = xb_get_element('email_field'+suffix);
  this.reg_p    = xb_get_element('password_field'+suffix);
  this.log_e    = xb_get_element('login_email_field'+suffix);
  this.log_p    = xb_get_element('login_password_field'+suffix);
  this.pw_e     = xb_get_element('forgot_password_email_field'+suffix);
 // this.et    = xb_get_element('txteqmsg_field'+suffix);
 // this.cte = xb_get_element('txtComMsg _field'+suffix);
  this.pr_login = xb_get_element('login_prompt'+suffix);

  if (this.lt && this.lt.style && this.lt.style.display != 'none' && !has_class(this.lt, 'hidden'))
    this.now_showing = 'login';
  else if (this.pt && this.pt.style && this.pt.style.display != 'none' && !has_class(this.pt, 'hidden'))
    this.now_showing = 'password';
  else if (this.ct && this.ct.style && this.ct.style.display != 'none' && !has_class(this.ct, 'hidden'))
    this.now_showing = 'changepwd';
  else if (this.et && this.et.style && this.et.style.display != 'none' && !has_class(this.et, 'hidden'))
    this.now_showing = 'enquiry';    
  else if (this.at && this.ct.style && this.at.style.display != 'none' && !has_class(this.at, 'hidden'))
    this.now_showing = 'checkbox';    
   else if (this.ai && this.ai.style && this.ai.style.display != 'none' && !has_class(this.ai, 'hidden')) //-------------
    this.now_showing = 'active';  
  else if (this.prt && this.prt.style && this.prt.style.display != 'none' && !has_class(this.prt, 'hidden'))    
    this.now_showing = 'property';    
  else if (this.cet && this.cet.style && this.cet.style.display != 'none' && !has_class(this.cet, 'hidden'))    
    this.now_showing = 'comments';    
  else
    this.now_showing = 'signup';
  // additional parameters
  if (typeof addl !== 'undefined' && typeof addl.email !== 'undefined')
  {
    DOMUtils.set_value(this.log_e, addl.email);
    DOMUtils.set_value(this.pw_e, addl.email);
  }
}
LoginForm.prototype.show = function(force_state)
{
  unhide_selects();

  clear_element('reg_box_msg_txt' + this.suffix);
  clear_element('login_box_msg_txt' + this.suffix);
  clear_element('password_box_msg_txt' + this.suffix);

  // check or uncheck real estate pro status
  var re_pro = xb_get_element('us_pro' + this.suffix);
  if (re_pro)
  {
    if (typeof(login_next_step_global) != 'undefined' && login_next_step_global == 'claiming')
      re_pro.checked = true;
    else
      re_pro.checked = false;
  }

  add_class(this.pr_login, 'hidden')
  add_class('register_prompt' + this.suffix, 'hidden');

  if (this.box)
    this.box.style.zIndex = '9999';

  if (typeof(force_state) != 'undefined' && force_state != null && force_state != '')
  {   
    
    switch(force_state)
    {      
      case 'login':
        this.show_login();
        break;
      case 'password':
        this.show_password();
       break;
      case 'changepwd':
        this.show_changepwd();
       break;
      case 'enquiry':
        this.show_enquiry();
       break;
      case 'checkbox':
        this.show_checkbox();
       break;
      case 'active': 
	  this.show_active(); 
	   break; 
   	  case 'property': 
	  this.show_property(); // --------------
	   break;     
   	  case 'comments': 
	  this.show_comments(); // --------------
	   break;     
      case 'signup':
      default:
        this.show_register();
        break;
    }
  }
  else
  {
    if (this.now_showing != 'login')
      this.show_login();
    else
      this.show_register();
  }
}
//todo
LoginForm.prototype.show_save_search = function()
{
}

LoginForm.prototype.show_active = function() //------- show active function------------------
{
	if (!this.ai)
    return;

  if (this.header)
  {
    this.header.innerHTML = this.activation_header;
  }
	
  add_class(this.lt, 'hidden');  
  add_class(this.rt, 'hidden');
  add_class(this.ct, 'hidden');
  add_class(this.pt, 'hidden');
  add_class(this.et, 'hidden');
  add_class(this.prt, 'hidden');  
  add_class(this.cet, 'hidden');  
  
  hide(this.pw_prompt);

  if (!remove_class(this.ai, 'hidden'))
    unhide(this.ai, '');
  
  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);
    
  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);

}

LoginForm.prototype.show_property = function() //------- show property function------------------
{
	if (!this.prt)
    return;
 
  if (this.header)
  {
    this.header.innerHTML = this.property_header;
  }
	
  add_class(this.lt, 'hidden');  
  add_class(this.rt, 'hidden');
  add_class(this.ct, 'hidden');
  add_class(this.pt, 'hidden');
  add_class(this.et, 'hidden');
  add_class(this.ai, 'hidden');
  add_class(this.cet, 'hidden');  
  
  hide(this.pw_prompt);

  if (!remove_class(this.prt, 'hidden'))
    unhide(this.prt, '');
  
  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);
    
  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);

}



LoginForm.prototype.show_login = function()
{

 // add_class(this.ct, 'hidden');
  add_class(this.et, 'hidden');
  add_class(this.at, 'hidden');
    
  // Handle popup header
  if (this.header)
  {
    if (!has_class(this.ssf, 'hidden'))
      this.header.innerHTML = this.search_header;
//    else if (!has_class(this.eaf, 'hidden'))
//      this.header.innerHTML = this.email_header;
    else
      this.header.innerHTML = this.login_header;
  }
  add_class(this.rt, 'hidden');

  if (this.pt)
    add_class(this.pt, 'hidden');
    
  if (this.ct)
    add_class(this.ct, 'hidden');
  
 if (this.ai)
    add_class(this.ai, 'hidden'); //---------------------
   
  if (this.et)  
    add_class(this.et, 'hidden');
 
 if (this.prt)
    add_class(this.prt, 'hidden'); //---------------------

  if (this.at) //Alert
    add_class(this.ct, 'hidden');
    
  if (this.cet) //comments
    add_class(this.cet, 'hidden');    

  // Don't show main login form if this is a special instance
  var dont_focus = false;
  if (has_class('saved_search_buttons','hidden'))
  {
    if (!remove_class(this.lt, 'hidden'))
      unhide(this.lt, '');
  }
  else
    dont_focus = true; // Dont try to focus hidden fields :)

  // pre-fill email address
 // if (is_valid_email(this.reg_e.value) == EMAIL_OK)
    this.log_e.value = this.reg_e.value;

  if (!remove_class(this.box, 'hidden') || this.box.style.display == 'none')
    unhide(this.box);

  if (!dont_focus) // We need this check because IE complains if the login form is hidden
  {
    if (this.log_e.value != '')
      this.log_p.focus();
    else
      this.log_e.focus();
  }

  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);
}
LoginForm.prototype.show_register = function()
{
  if (this.header)
  {
    if (!has_class(this.ssf, 'hidden'))
      this.header.innerHTML = this.search_header;
//    else if (!has_class(this.eaf, 'hidden'))
//    this.header.innerHTML = this.email_header;
    else
      this.header.innerHTML = this.register_header;
  }
  add_class(this.lt, 'hidden');
  hide(this.pw_prompt);

  if(this.pt)
    add_class(this.pt, 'hidden');
    
  if (this.ct)
    add_class(this.ct, 'hidden');

 if (this.ai)
    add_class(this.ai, 'hidden'); //--------------

  if (this.prt)
    add_class(this.prt, 'hidden'); //---------------------
    
  if (this.at)
    add_class(this.at, 'hidden');
    
  if (this.et)
    add_class(this.et, 'hidden');
    
  if (this.cet)
    add_class(this.cet, 'hidden');

  if (!remove_class(this.rt, 'hidden'))
    unhide(this.rt, '');

  // pre-fill email address if valid
  //if (is_valid_email(this.log_e.value) == EMAIL_OK)
    this.reg_e.value = this.log_e.value;

  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);

  if (this.reg_e.value != '')
  	this.reg_p.focus();
  else
 	this.reg_e.focus();

  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);
}

LoginForm.prototype.show_password = function()
{
	if(!this.pt)
	return;

  login_reset(); // We dont need any saved search/alert stuff here
	//  if (!has_class(this.ssf, 'hidden'))
	//    this.header.innerHTML = this.search_header;
	//  else if (!has_class(this.eaf, 'hidden'))
	//    this.header.innerHTML = this.email_header;
	//  else
  if (this.header)
  {
    this.header.innerHTML = this.password_header;
  }
  add_class(this.lt, 'hidden');
  add_class(this.rt, 'hidden');
  add_class(this.et, 'hidden');
  add_class(this.at, 'hidden');
  add_class(this.ai, 'hidden');
  add_class(this.prt, 'hidden');
  add_class(this.cet, 'hidden');
  
  hide(this.pw_prompt);

  if (!remove_class(this.pt, 'hidden'))
    unhide(this.pt, '');

  // pre-fill email address if valid
 // if (is_valid_email(this.reg_e.value) == EMAIL_OK)
    this.pw_e.value = this.reg_e.value;

 // if (is_valid_email(this.log_e.value) == EMAIL_OK)
    this.pw_e.value = this.log_e.value;

  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);

  this.pw_e.focus();

  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);
}

LoginForm.prototype.show_changepwd = function()
{

 // alert("Hi Change");
  
  if (!this.ct)
    return;
    
  if (this.header)
  {
    this.header.innerHTML = this.changepassword_header;
  }
    
  add_class(this.lt, 'hidden');
  add_class(this.rt, 'hidden');
  add_class(this.et, 'hidden');
  add_class(this.at, 'hidden');
  add_class(this.ai, 'hidden');
  add_class(this.prt, 'hidden');
  add_class(this.cet, 'hidden');

  hide(this.pw_prompt);
  
  if (!remove_class(this.ct, 'hidden'))
    unhide(this.ct, '');
  
  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);
    
  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);
}

LoginForm.prototype.show_enquiry = function()
{  
    if(!this.et)
      return;
    
	if (this.header)
	{
		this.header.innerHTML = this.enquiry_header;
	}
  
  if (this.lt)  
     // alert("Hi");
 	 add_class(this.lt, 'hidden');
  if (this.rt)
	  add_class(this.rt, 'hidden');
  if (this.ct)	  
  	add_class(this.ct, 'hidden');
  if (this.pt)
  	add_class(this.pt, 'hidden');
  if (this.at)
	  add_class(this.at, 'hidden');
  if (this.ai)
	  add_class(this.ai, 'hidden');
  if (this.prt)
	  add_class(this.prt, 'hidden');
  if (this.cet)
	  add_class(this.cet, 'hidden');

  hide(this.pw_prompt);
  
  if (!remove_class(this.et, 'hidden'))
    unhide(this.et, '');
  
  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);
    
  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);
}

LoginForm.prototype.show_checkbox = function()
{

  if (!this.at)
    return;
    
  if (this.header)
  {
    this.header.innerHTML = this.checkbox_header;
  }
    
  add_class(this.lt, 'hidden');
  add_class(this.rt, 'hidden');
  add_class(this.ct, 'hidden');
  add_class(this.pt, 'hidden');
  add_class(this.et, 'hidden');
  add_class(this.ai, 'hidden');
  add_class(this.prt, 'hidden');
  add_class(this.cet, 'hidden'); 
  
  hide(this.pw_prompt);  
  
  if (!remove_class(this.at, 'hidden'))
    unhide(this.at, '');
  
  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);
    
  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);
}


LoginForm.prototype.show_comments = function()
{
  if (!this.cet)
    return;
    
  if (this.header)
  {
    this.header.innerHTML = this.comments_header;
  }
    
  add_class(this.lt, 'hidden');
  add_class(this.rt, 'hidden');
  add_class(this.ct, 'hidden');
  add_class(this.pt, 'hidden');
  add_class(this.et, 'hidden');
  add_class(this.at, 'hidden');
  add_class(this.ai, 'hidden');
  add_class(this.prt, 'hidden');
  
  hide(this.pw_prompt);  
  
  if (!remove_class(this.cet, 'hidden'))
    unhide(this.cet, '');
  
  if (!remove_class(this.box, 'hidden') && this.box.style.display == 'none')
    unhide(this.box);
    
  if (is_IE() && !is_IE7())
    DOMUtils.hide_selects_by_el(this.box, this.box.style.left, this.box.style.top);
}


// misc utility functions
function go_to_page(page)
{
  if (typeof(page) != 'undefined')
  window.location.href = site_root + page;
}


// show/hide login, register, forgot password forms
function toggle_login_form(force_state, suffix, addl)
{
  if (typeof(force_state) == 'undefined')
    force_state = null;

  var return_url = '';

  if (typeof addl !== 'undefined' && typeof addl.return_url !== 'undefined' && addl.return_url != '')
    return_url = 'r/'+addl.return_url;
    
  switch(force_state)
  {
    case 'login_page':
      go_to_page('login/'+return_url);
      break;
    case 'signup_page':
      go_to_page('signup/'+return_url);
      break;
    case 'password_page':
      go_to_page('forgot_password/'+return_url);
      break;
    case 'changepwd_page':
      go_to_page('change_password/'+return_url);
      break;
    case 'enquiry_page':
      go_to_page('enquiry/'+return_url);
      break;    
   case 'activation_page':
      go_to_page('active/'+return_url); //--------------
      break;   
   case 'property_page':
      go_to_page('property/'+return_url); //--------------
      break;          
   case 'comments_page':
      go_to_page('comments/'+return_url); //--------------
      break;          
   case 'checkbox_page':
      go_to_page('checkbox/'+return_url);
      break;            
   default:
      if (typeof(suffix) == 'undefined' || !suffix) { suffix = ''; }
      var lf = new LoginForm(suffix,addl);
      lf.show(force_state);
  }
}

function unhide_selects()
{
  if (!is_IE() || is_IE7())
    return;

  var iframe = xb_get_element('ie_iframe');

  if (iframe)
    iframe.parentNode.removeChild(iframe);
  else
  {
    var s = document.getElementsByTagName('select');
    for (var i = 0; i < s.length; ++i)
      s[i].style.display = '';
  }
}

function is_IE()
{
  return (navigator.appName.indexOf("Microsoft Internet Explorer") > -1);
};

function is_IE6()
{
  return (navigator.appName.indexOf("Microsoft Internet Explorer") > -1 && !window.XMLHttpRequest)
}

function is_IE7()
{
  return (navigator.appName.indexOf("Microsoft Internet Explorer") > -1 && window.XMLHttpRequest)
}

// clear element and dependencies
function clear_element(element)
{
  if (el = xb_get_element(element))
  {
    el.innerHTML = '';
    if (el.id == 'email_message')
      add_class('login_prompt', 'hidden');
    else if (el.id == 'login_email_message')
      add_class('register_prompt', 'hidden');
  }
}

function clear(f)
{
  if (xb_get_element(f))
    xb_get_element(f).value = '';
}

function unhide(f, val)
{
  // if ( typeof(val) == 'undefined' || (!val && !(val === '')) ) { val = 'inline'; }
  // if (xb_get_element(f))
  //   xb_get_element(f).style.display = val;

  var el = xb_get_element(f);

  if (el)
  {
    // try to get inline style
    var current_display = el.style.display;

    // if no inline style, get css style
    if (!current_display)
    {
      // ie
      if (typeof(el.currentStyle) != 'undefined')
      {
        current_display = el.currentStyle.display;
      }
      // ff
      else
      {
        current_display = document.defaultView.getComputedStyle(el, '').getPropertyValue('display');
      }
    }

    if (typeof(val) == 'undefined' || (!val && !(val === '')) || val == 'none')
    {
      // if display is none, change it to inline for backwards compatibility (use to just apply inline style to element)
      if (current_display == 'none')
        val = 'inline';
      // otherwise clear it
      else
        val = '';
    }

    // update inline style
    el.style.display = val;

    // remove class
    remove_class(el, 'hidden');
  }

}

function hide(f)
{
  var el = xb_get_element(f);

  if (el)
  {
    // try to get inline style
    var current_display = el.style.display;

    // if no inline style,
    if (!current_display)
    {
      remove_class(el, 'hidden');

      // ie
      if (typeof(el.currentStyle) != 'undefined')
      {
        current_display = el.currentStyle.display;
      }
      // ff get css style
      else
      {
        current_display = document.defaultView.getComputedStyle(el, '').getPropertyValue('display');
      }
    }

    if (!current_display)
      add_class(el, 'hidden');
    else
      el.style.display = 'none';
  }

  // unhide selects
  // if (navigator.appName.indexOf("Microsoft")!=-1)
  //  unhide_selects();
}

// hides selects under element for ie
// @param el  the element under which to hide the selects
// @param left    optional. the left position of the element
// @param top     optional. the top position of the element
// @param width   optional. the width of the element
// @param height  optional. the height of the element
DOMUtils.hide_selects_by_el = function(el, left, top, width, height)
{
  if (!is_IE() || is_IE7())
    return false;;

  var el = xb_get_element(el);
  if (!el)
    return false;

  var displacement, top, left, width, height;
  var iframe_id = 'ie_iframe';

  // No voices iframe
  if (el.parentNode.id=='voices_location_auto' || el.id == 'rss_pulldown')
    return;

  if (el.className.indexOf('popup_table') != -1)
    var newpopup = true;
  else
    var newpopup = false;

  var iframe = xb_get_element(iframe_id);

  if (iframe)
  {
    iframe.parentNode.removeChild(iframe);
    // We are moving the iframe, and the autocomplete_panel may be open - so hide that now
    if (el.id!='autocomplete_panel' && xb_get_element('autocomplete_panel'))
      hide(xb_get_element('autocomplete_panel'));
  }

  if (typeof(left) == 'undefined' || !left)
  {
    displacement = 0;
    // the inside of the popups are left -3px so we need to move the
    // iframe by that much so that it doesn't peep through the shadow
    // but we don't want that for the top nav iframe or pulldown menu classes (f_rss)
    if (el.parentNode.id.indexOf('nav_') < 0 && el.id.indexOf('f_') !== 0)
      displacement = -3;
    else if (el.id == 'autocomplete_panel') // autocomplete popup
      displacement = 1;
    if (newpopup)
      displacement = 0;

    left = el.style.left;

    if (typeof(left) == 'undefined' || !left)
      left = findPosX(el) + displacement + 'px';
    else
      left = parseInt(left) + displacement + 'px';//Number(left.substring(0, left.length - 2)) - 3 + 'px';
  }

  if (typeof(top) == 'undefined' || !top)
  {
    displacement = 0;
    if (el.parentNode.id.indexOf('nav_') < 0 && el.id.indexOf('f_') !== 0)
      displacement = -3;
    else if (el.id == 'autocomplete_panel') // autocomplete popup
      displacement = 1;
    if (newpopup)
      displacement = 0;

    top = el.style.top;

    if (typeof(top) == 'undefined' || !top)
      top = findPosY(el) + displacement + 'px';
    else
      top = parseInt(top) + displacement + 'px';//Number(left.substring(0, left.length - 2)) - 3 + 'px';
  }

  if (typeof(width) == 'undefined' || !width || typeof(height) == 'undefined' || !height)
  {
    var dim = get_object_dimensions(el);

    if (el.id == 'autocomplete_panel') // autocomplete popup
      displacement = -1;
    else if (el.parentNode.id.indexOf('nav_') < 0 && el.id.indexOf('f_') !== 0)
      displacement = 2;

      width = dim.width + displacement + 'px';
      height = dim.height + displacement + 'px';
  }

  var top_z_index = el.style.zIndex;
  if (typeof(top_z_index) == 'undefined' || !top_z_index)
    top_z_index = 995;

  // alert(el.parentNode.tagName);
  iframe = document.createElement('iframe');

  iframe.id = iframe_id;
  iframe.style.position = 'absolute';
  iframe.style.left = left;
  iframe.style.top = top;
  iframe.style.height = height;
  iframe.style.width = width;
  iframe.style.zIndex = top_z_index - 1;
  el.style.zIndex = top_z_index;
  //alert(el.id + ' - ' + left + ',' + top + ',' + width + ',' + height);
  // iframe.style.display = 'block';
  // iframe.style.filter = 'mask()';

  var parent = el.parentNode;

  if (el.id == 'autocomplete_panel') // autocomplete popup
  {
    nav = xb_get_element('nav_newsfeed');

    if (nav)
      parent = nav;
    else if (parent.id=='city_state_ac' || parent.id=='zip_ac')
      parent = parent.parentNode;
  }
  else if (el.id=='claim_learn_more_popup')
  {
    parent = parent.parentNode;
  }

  if (typeof(parent) == 'undefined' || !parent || !parent.tagName)
  {
    document.body.appendChild(iframe);
  }
  else if (parent.tagName == 'LI')
  {
    parent = parent.parentNode;

    if (typeof(parent) == 'undefined' || !parent)
      document.body.appendChild(iframe);
    else
      parent.appendChild(iframe);
  }
  else
  {
    parent.appendChild(iframe);
  }

  return true;
}

// DOMUtils namespace
function DOMUtils() {};

function doNothing(e)
{
  if (typeof(e) == 'undefined' || !e)
    var e = window.event;

  if (e && typeof(e) != 'undefined')
  {
    e.cancelBubble = true;

    if (e.stopPropagation)
      e.stopPropagation();
  }
  return false;
}

/*
Open or close popup based on whether it's closed or opened.
It can also registers the popup as a MENU_MUTEX on openeing (if you clcik anywhere the popup closes), unless state is 3 (when openning)
@param e      event
@param mid    id of the popup to toggle
@param state  optional. 0 to hide, 1 to show, 3 to show and not register as a MENU_MUTEX. It'll figure out to hide or show if this isn't specified
@return nothing
*/
function toggle_menu(e, mid, state)
{
  var menu = xb_get_element(mid);

  if (!menu)
    return;

  if (typeof(e) != 'undefined' && e)
    doNothing(e);

  if (menu.id.indexOf('login_box') > -1)
  {
    // clear global var if login box was closed
    login_next_step_global = '';
  }

  // open
  if ((menu.style.display == 'none' || has_class(menu, 'hidden')) && state != 0 || state == 1 || state == 3)
  {
    // if you can't set the mutex, clear that one mutex
    if (state != 3 && !set_mutex(_MENU_MUTEX, mid))
    {
      hlt_menu(e, xb_get_element(mutexes[_MENU_MUTEX]),0);
      hide(mutexes[_MENU_MUTEX]);
      release_mutex(_MENU_MUTEX);
    }
    unhide(mid);
    hlt_menu(e,menu,2);
    if (state != 3)
      set_mutex(_MENU_MUTEX, mid);

    DOMUtils.hide_selects_by_el(menu);
    return;
  }
  // close
  else if (menu.style.display != 'none' && !has_class(menu, 'hidden') && state != 1 || state == 0)
  {
    hide(mid);
    hlt_menu(e,menu,0);
    release_mutex(_MENU_MUTEX);
    unhide_selects();
  }
}

// hlt menu title
function hlt_menu(e,menu,state)
{
  // get title
  var menut = menu.previousSibling;

  if (typeof(menut) == 'undefined' || !menut || typeof(menut.className) == 'undefined' || menut.className.indexOf('menu_title') < 0)
    return;

  switch(state)
  {
    case 1:
      menut.className = 'menu_title_h';
      break;
    case 2:
      menut.className = 'menu_title_active';
      break;
    case 0:
    default:
      menut.className = 'menu_title';
      break;
  }
}
var mutexes = new Array();
var _MENU_MUTEX = 1;
var _SAVE_MUTEX = 2;
var _EDITOR_MUTEX = 3;

// ***********
// Queue class
// ***********
function Queue(s)
{
  this.elements = new Array();
  this.size = (typeof(s) != 'undefined' && parseInt(s) > 0 ? parseInt(s) : 5);
  this.allow_dupes = false;
  // used by iterator
  this.cursor = 0;
}
Queue.prototype.set_allow_dupes = function(n)
{
  this.allow_dupes = n;
}
Queue.prototype.set_size = function(s)
{
  this.size = parseInt(s);
}
// deletes all elements
Queue.prototype.clear = function()
{
  this.elements = new Array();
}
// returns true if we've hit capacity
Queue.prototype.is_full = function()
{
  return (this.get_size() >= this.size);
}
// returns true if the queue is empty
Queue.prototype.is_empty = function()
{
  return (this.get_size() < 1);
}
// adds an element to the queue
Queue.prototype.add = function(el)
{
  if (!this.is_full() && (this.allow_dupes || !this.contains(el)))
    this.elements.push(el);
}
// elements contains a given value
Queue.prototype.contains = function(el)
{
  return is_in_array(el,this.elements);
}
// returns how many elements are in the queue
Queue.prototype.get_size = function()
{
  return this.elements.length;
}
// removes an element from the queue
Queue.prototype.remove = function(el)
{
  var sz = this.get_size();
  if (sz < 1)
    return;
  var tmp = new Array();
  var found = false;
  for (var i = 0; i < sz; ++i)
  {
    if (this.elements[i] == el)
    {
      found = true;
      continue;
    }
    else
      tmp.push(this.elements[i]);
  }
  this.elements = tmp;
  tmp = null;
  return found;
}
// walks the elements
Queue.prototype.it_next_element = function()
{
  if (this.cursor >= this.get_size())
    return false;
  else
    return this.elements[this.cursor++];
}
// starts iterator
Queue.prototype.it_start = function()
{
  this.cursor = 0;
}
var save_queue = new Queue();
var sub_queue = new Queue();

// ******************************
// **** mutex management fns ****
// ******************************
// mutex release
function release_mutex(type)
{
  set_mutex(type, null);
}
// check on the mutex
function is_mutex_free(type)
{
  return (typeof(mutexes[type]) == 'undefined' || mutexes[type] == null);
}
// set a mutex
function set_mutex(type, value)
{
  // can't set mutex if already exists
  if (!is_mutex_free(type) && value != null)
  {
    return false;
  }
  else
  {
    mutexes[type] = value;
    return true;
  }
}


//function show_CommEditor('rejectLevelComments','rejectLevel','Rejected Level Comments','reject',1,'<?php echo $enqComments;?>'){ }

//function show_CommEditor(event,'comments', false, {x:650,y:35}, '','<?php echo $PID; ?>' )

