var pg = "pricing.php?";
//var pg = "truliaholic2.php?";
function chgpg(){
  var t1;
  var t2;

  if (xb_get_element('t1'))
    t1 = trim(xb_get_element('t1').value);
  if (xb_get_element('t2'))
    t2 = trim(xb_get_element('t2').value);
  location.href = "popularity.php?t1=" + t1 + "&t2=" + t2;
}
function validate_frm(){

  var e = '';
  var f = '';
    if (xb_get_element('t1'))
    var t1 = trim(xb_get_element('t1').value);
  if (xb_get_element('t2'))
    var t2 = trim(xb_get_element('t2').value);

  if ((t1 == '') || (t2 == ''))
  {
    e += "Please enter a location.\n";
    if(t1 == '')
    {
      f = 't1';
    }
    else
    {
      f = 't2';
    }
  }
  if (e != '')
  {
    alert(e);
    xb_get_element(f).focus();
    return false;
  }
  return true;
}

function nwpg(dtst, dtend, bln)
{
  var validate = true;
  if(bln == 'true')
  {
    validate = validate_frm();
  }
  if(validate)
  {
    var t1 = trim(xb_get_element('t1').value);
    var t2 = trim(xb_get_element('t2').value);
    var nwpage = pg + '&dateStart=' + dtst + '&dateEnd=' + dtend + '&t1=' + t1 + '&t2=' + t2;
    //alert("url: " + nwpage);
    location.href = nwpage;  
  }
}
function xb_get_element(id)
{
  var el = document.all ? document.all[id] : document.getElementById(id);
  if (el)
    return el;
  else
    return null;
}

function trim(s)
{
  if (!s)
    return '';
  return s.replace(/^\s*|\s*$/g,"");
}
function mel(m,s)
{
  var f = m + '@' + 'trulia' + '.' + 'com';
  document.write('<a href=\"mailto:' + f + (s ? '?subject=' + s : '') + '\">' + f + '</a>');
}
// support functions
// returns an element by id
function $_(id)
{
  var el = document.all ? document.all[id] : document.getElementById(id);
  if (el)
    return el;
  else
    return null;
}
// creates an arbitrary dom element
function $$_(type,cls,contents,id)
{
  var el = document.createElement(type);
  if (cls)
    el.className = cls;
  if (contents)
    el.innerHTML = contents;
  if (id)
    el.id = id;
  return el;
}

// removes element from dom
function kill(id)
{
  if ($_(id))
    $_(id).parentNode.removeChild($_(id));
}
// hides an element
function hide(id)
{
  if ($_(id))
    $_(id).style.display = 'none';
}
// shows an element
function unhide(id)
{
  if ($_(id))
    $_(id).style.display = 'inline';
}
// utility functions to find an event's coordinates
// credit: http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
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;
}
// shows more info
function show_more_info(event)
{
  if (!$_('more_info_layer'))
  {
    var the_div = $$_('div','more_info_layer',$_('more_info_text').innerHTML,'more_info_layer');
    $_('more_info_link').parentNode.appendChild(the_div);
  }
  position_at_event(event,'more_info_layer',-175,5);
 // _graphs[_the_graph].hide_info();
  unhide('more_info_layer');
}
// hides more info
function hide_more_info()
{
  kill('more_info_layer');
}
// positions an element at a particular event's location
function position_at_event(e,box_id,nudge_x,nudge_y)
{
  var the_box = $_(box_id);
  if (!the_box)
    return;
  if (typeof(nudge_x) == 'undefined')
    nudge_x = 0;
  if (typeof(nudge_y) == 'undefined')
    nudge_y = 0;
  var the_w = parseInt(the_box.style.width);
  var the_h = parseInt(the_box.style.height);
  var isie = (navigator.appName.indexOf("Microsoft")!=-1);
  var c = get_eloc(e);
  var ww = c.ww;
  var wh = c.wh;
  var scrollTop = c.scrollTop;
  var posx = c.x;
  var posy = c.y;
  // offset
  if (posx + the_w > ww)
    posx = ww - the_w;
  if (posy + the_h > wh + scrollTop)
    posy = wh + scrollTop - the_h;
  posx += nudge_x;
  posy += nudge_y;
  if (posx < 0)
    posx = 0;
  if (posy < 0)
    posy = 0;
  the_box.style.position = 'absolute';
  the_box.style.top = posy + 'px';
  the_box.style.left = posx + 'px';
}
//returns event location
function get_eloc(e)
{
  if (!e && window.event)
    e = window.event;
  var posx, posy, scrtop, scrleft, ww, wh;
  var c = new Object;
  var clientSize = f_clientSize();
  ww = clientSize.width;
  wh = clientSize.height;
  scrtop = clientSize.scrollTop;
  scrleft = clientSize.scrollLeft;
  if (e.pageX || e.pageY)
  {
    posx = e.pageX;
    posy = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    posx = e.clientX + scrleft;
    posy = e.clientY + scrtop;
  }
  c.x = posx;
  c.y = posy;
  c.ww = ww;
  c.wh = wh;
  c.scrollTop = scrtop;
  c.scrollLeft = scrleft;
  return c;
}
function mel(m,s)
{
  var f = m + '@' + 'centerge' + '.' + 'com';
  document.write('<a class=\"link\" href=\"mailto:' + f + (s ? '?subject=' + s : '') + '\">' + f + '</a>');
}


