var flag = 0;
var curr_to = null;

function get(str) { return document.getElementById(str) }

function getFormString(element, frmName)
{
	//if(eval(frmName) != null || typeof eval(frmName) != 'undefined') form1 = eval(frmName);
	form1 = get('searchForm');//alert(form1);
	var count = form1.elements.length;
	var str = "";
	var name, value;
	
	for(var i = 0; i < count; i++)
	{
	  el = form1.elements[i];
	  name = form1.elements[i].name;
	  value = form1.elements[i].value;
		
	  if(name != "" && value != "")
		{
		    //if(name == "body") str += name + "=" + escape(get('ae_frame1').contentDocument.body.innerHTML);
			//if(name == "morebody") str += name + "=" + escape(get('ae_frame1').contentDocument.body.innerHTML);
			if(el.type == "radio" && el.checked == false) continue;
			//else if(el.type == "submit" && el.value != element.value) continue;
			else if(el.type == "button") continue;
			else if(el.type == "select") continue;
			else if(el.type == "reset") continue;
			else str += name + "=" + escape(value);
		  if(i != count - 1) str += "&";
		}
	}
	
	return str;
}

function goPg(num)
{
	//location.href='?'+getFormString('', 'searchForm')+'pg='+num;
	get('pg').value = num;
	get('searchForm').submit();
}

function changeView(num, val)
{
	get(val).value = num;
	get('searchForm').submit();
}

function doFlag(ctrl, bit)
{
  if(ctrl.checked == true)
  {
    get('flag').value = 1;  //set form value
	flag = flag | bit;      //set bit value
  }
  else if(get('flag').checked == false)
  {
    flag = flag & (~bit);                //remove bit value
	if(flag == 0) get('flag').value = 0; //remove form value
  }
}

function setPropFieldsForLease()
{
  get('PROPERTY_CLASS_ID').style.display = "none";
  get('sf_prop_type').style.display = "block";
  get('divPriceSale').style.display = "none";
  get('divLeasePrice').style.display = "block";
}

function setPropFieldsForSale()
{
  get('sf_prop_type').style.display = "none";
  get('PROPERTY_CLASS_ID').style.display = "block";
  get('divPriceSale').style.display = "block";
  get('divLeasePrice').style.display = "none";
}

function upcnt()
{
}

function refineSearch()
{
  if(get('searchForm') != null)
  {
    get('searchForm').action = "property-search.cfm?adv=1";
    get('searchForm').submit();
  }
  else
  {
	location.href='property-search.cfm';  
  }
}

function validate_search()
{
  //Validate listing price if visible
  if(get('divPriceSale').style.display == "block")
  {
    if(get('LISTING_PRICE_MIN').value != "" && get('LISTING_PRICE_MAX').value != "" && Number(get('LISTING_PRICE_MIN').value) > Number(get('LISTING_PRICE_MAX').value))
	{
	  alert("The value you entered for Minimum Price is greater than the value you entered for Maximum Price");
	  return false;
	}
  }
  else if(get('divLeasePrice').style.display == "block")
  {
	if(get('LEASE_PRICE_MIN').value != "" && get('LEASE_PRICE_MAX').value != "" && Number(get('LEASE_PRICE_MIN').value) > Number(get('LEASE_PRICE_MAX').value))
	{
	  alert("The value you entered for Minimum Lease Price is greater than the value you entered for Maximum Lease Price");
	  return false;
	}
  }
  
  if(get('LOTSIZE_MIN') && get('LOTSIZE_MIN').value != "" && get('LOTSIZE_MAX').value != "" && Number(get('LOTSIZE_MIN').value) > Number(get('LOTSIZE_MAX').value))
  {
	alert("The value you entered for Minimum Lot Size is greater than the value you entered for Minimum Lot Size");
	return false;
  }
}

function popup_est(ctrl, e)
{
  var IE = document.all?true:false; //Browser detect
  var x, y;
  
  if(IE)
  {
    x = e.clientX + document.body.scrollLeft + 12;
	y = e.clientY + document.body.scrollTop + 2;
  }
  else
  {
    x = e.pageX + 12;
	y = e.pageY + 2;
  }
  
  get('disclaim').style.top  = y + 'px';
  get('disclaim').style.left = x + 'px';
  get('disclaim').style.display = 'block';
  //curr_to = setTimeout(popout_est, 1000);
}

function popout_est()
{
  get('disclaim').style.display = 'none';
  popclear_est(); //Clear the timeout so that it won't trigger on the next popup
}

function popclear_est()
{
  if(curr_to != null) clearTimeout(curr_to);
}

function popdelay_est()
{
  curr_to = setTimeout(popout_est, 1000);
}

function showPh(mid, oid)
{
  document.getElementById("phbroker"+mid+ "_"+ oid).innerHTML = "<span class='plainsmalltext'>" + '1-877-307-1645' + "</span> ";
  objHTTP = getHTTPObject();
  if (objHTTP)
  {
    objHTTP.open('GET','doBrokerPhone.cfm?officeid='+oid, false);
    objHTTP.send(null);
  }
}

function getHTTPObject()
{
  if(navigator.appName=='Netscape') { var objHTTP = new XMLHttpRequest(); }
  else if (navigator.appName.indexOf("Explorer") > 0) { var objHTTP = new ActiveXObject("Microsoft.XMLHTTP"); }
  return objHTTP;
}