function handleHttpResponse() {
  if (http.readyState == 4) {
	 scstart = http.responseText.indexOf("mrecode:");
	 scend = http.responseText.indexOf('mend');
	 results = http.responseText.substr(scstart+8,scend-scstart-8);
	
	 WriteLayer ('curcount',null,results);

  }
}

function WriteLayer(ID,parentID,sText) { 
 if (document.layers) { 
   var oLayer; 
   if(parentID){ 
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
   }else{ 
     oLayer = document.layers[ID].document; 
   } 
   oLayer.open(); 
   oLayer.write(sText); 
   oLayer.close(); 
 } 
 else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") { 
   document.getElementById(ID).innerHTML = sText; 
 } 
 else if (document.all) document.all[ID].innerHTML = sText 
} 
 function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }

  return xmlhttp;

}
	var http = getHTTPObject(); 
	
function updatepropcount() {

  var url = "getpropcount.cfm?zip="; // The server-side script
  var zip = document.getElementById("zip").value;
 
 
 //alert (document.getElementById("for_sale").value);
  
  if(document.getElementById("for_sale").value == 7){
	  var PROP_TYPE = checkboxval("PROP_TYPE","");
	  if(PROP_TYPE !=''){
	  PROP_TYPE = PROP_TYPE.concat("");
	  }
	  var LEASE_PRICE_MIN = searchform.LEASE_PRICE_MIN.value;
	  var LEASE_PRICE_MAX = searchform.LEASE_PRICE_MAX.value;
  }else {
  	//document.getElementById("for_sale").value = 1;
   	var Property_Class_ID =checkboxval("Property_Class_ID",""); 
 	 if(Property_Class_ID != ''){
		 Property_Class_ID = Property_Class_ID.concat(0);
		// alert(Property_Class_ID);
	 }
	  var LISTING_PRICE_MIN = searchform.LISTING_PRICE_MIN.value;
 // alert
  		var LISTING_PRICE_MAX = searchform.LISTING_PRICE_MAX.value;
  }
  var BEDROOM_NUM = searchform.BEDROOM_NUM.value;
  var FULL_BATH_NUM = searchform.FULL_BATH_NUM.value;
  var SQURE_FEET_MIN = searchform.SQURE_FEET_MIN.value;
  var SQURE_FEET_MAX = searchform.SQURE_FEET_MAX.value;
  var GARAGE_NUM = searchform.GARAGE_NUM.value;
  var GARAGE_DESC = searchform.GARAGE_DESC.value;
  var STORIES = searchform.STORIES.value;

  var NEW_CONSTR = searchform.NEW_CONSTR.value;
  var YEAR_BUILT =searchform.YEAR_BUILT.value;
  
  var PRIVATE_POOL = '';
  var AREA_POOL = '';
  var GOLF = '';
  var VIRTUAL_TOURS = '';
  var OPEN_HOUSES = '';
  
  if(searchform.PRIVATE_POOL.checked ){
   PRIVATE_POOL = searchform.PRIVATE_POOL.value;
  }
   if(searchform.AREA_POOL.checked ){
   AREA_POOL =searchform.AREA_POOL.value;
  }
   if(searchform.GOLF.checked ){
   GOLF = searchform.GOLF.value;
  }
   if(searchform.VIRTUAL_TOURS.checked ){
   VIRTUAL_TOURS = searchform.VIRTUAL_TOURS.value;
  }
   if(searchform.OPEN_HOUSES.checked ){
   OPEN_HOUSES = searchform.OPEN_HOUSES.value;
  }

	url= url+escape(zip);//must have zipcode value
	
	
	 if(document.getElementById("for_sale").value == 7){
	 	url= url.concat('&for_sale=7');
		if (PROP_TYPE != '' ){
			url = url.concat('&PROP_TYPE=');
			url = url.concat(PROP_TYPE);
		}
		if (LEASE_PRICE_MIN != ''){
			url = url.concat('&LEASE_PRICE_MIN=');
			url = url.concat(LEASE_PRICE_MIN);
		}
		if (LEASE_PRICE_MAX != ''){
			url = url.concat('&LEASE_PRICE_MAX=');
			url = url.concat(LEASE_PRICE_MAX);
		}
	}else{
			url= url.concat('&for_sale=1');
		if (Property_Class_ID != ''){
			url = url.concat('&Property_Class_ID='); 
			url = url.concat(Property_Class_ID);
		}
		if (LISTING_PRICE_MIN != ''){
			url = url.concat('&LISTING_PRICE_MIN='); 
			url = url.concat(LISTING_PRICE_MIN);
		}
		if (LISTING_PRICE_MAX != ''){
			url = url.concat('&LISTING_PRICE_MAX=');
			url = url.concat(LISTING_PRICE_MAX);
		}
	}
	if (BEDROOM_NUM != ''){
		url = url.concat('&BEDROOM_NUM=');
		url = url.concat(BEDROOM_NUM);
	}
	if (FULL_BATH_NUM != ''){
		url = url.concat('&FULL_BATH_NUM=');
		url = url.concat(FULL_BATH_NUM);
	}
	if (SQURE_FEET_MIN != ''){
		url = url.concat('&SQURE_FEET_MIN=');
		url = url.concat(SQURE_FEET_MIN);
	}
	if (SQURE_FEET_MAX != ''){
		url = url.concat('&SQURE_FEET_MAX=');
		url = url.concat(SQURE_FEET_MAX);
	}
	if (GARAGE_NUM != ''){
		url = url.concat('&GARAGE_NUM=');
		url = url.concat(GARAGE_NUM);
	}
	if (GARAGE_DESC != ''){
		url = url.concat('&GARAGE_DESC=');
		url = url.concat(GARAGE_DESC);
	}
	if (STORIES != ''){
		url = url.concat('&STORIES=');
		url = url.concat(STORIES);
	}

	if (PRIVATE_POOL != ''){
		url = url.concat('&PRIVATE_POOL=');
		url = url.concat(PRIVATE_POOL);
	}
	if (AREA_POOL != ''){
		url= url.concat('&AREA_POOL=');
		url = url.concat(AREA_POOL);
	}
	if (NEW_CONSTR != ''){
		url = url.concat('&NEW_CONSTR=');
		url = url.concat(NEW_CONSTR);
	}
	if (YEAR_BUILT != ''){
		url = url.concat('&YEAR_BUILT=');
		url = url.concat(YEAR_BUILT);
	}
	if (GOLF != ''){
		url = url.concat('&GOLF=');
		url = url.concat(GOLF);
	}
	if (VIRTUAL_TOURS != ''){
		url = url.concat('&VIRTUAL_TOURS=');
		url = url.concat(VIRTUAL_TOURS);
	}
	if (OPEN_HOUSES != ''){
		url=url.concat('&OPEN_HOUSES=');
		url = url.concat(OPEN_HOUSES);
	}
	
	//alert(url);
	//window.open(url,'mywindow','width=650,height=500,toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	http.open("GET", url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);


 }
function checkboxval(boxname, boxval){
	var counter = 0;
	var i;
	
//	if(boxname =='Property_Class_ID'){
		for(i=0;i<6;i++){
			if(searchform.Property_Class_ID[i].checked){
				counter++;
				boxval = boxval.concat(searchform.Property_Class_ID[i].value);
				boxval = boxval.concat(',')
			}
		}
	//}else if(boxname =='PROP_TYPE'){
		for(i=0;i<3;i++){
				if(searchform.PROP_TYPE[i].checked){
				counter++;
				boxval = boxval.concat(searchform.PROP_TYPE[i].value);
				boxval = boxval.concat(',')
				}
			}
	//}	
//alert('counter'+counter);
	if(counter == 0){
		alert("You have to select at least one property type.");
		return (false);
	}
	else{
		return (boxval);
	}

}
function showdiv(divid) {
	obj = document.getElementById(divid);
	if(obj.style.display == 'none') {
		obj.style.display = '';
	}
	else {
		obj.style.display = 'none';
	}
}
function showBuyDiv(ival){
	//if(obj.checked){
	searchform.for_sale.value = 1;
		document.all.divBuy.style.display = '';
		document.all.divLease.style.display = 'none';
		document.searchform.LEASE_PRICE_MIN.selectedIndex = 0;
		document.searchform.LEASE_PRICE_MAX.selectedIndex = 0;
		document.getElementById("for_sale").value  = 1;
		for(i=0;i<3;i++){
			searchform.PROP_TYPE[i].checked =false;
		}
		if(ival==0){
			for(i=0;i<6;i++){
			searchform.Property_Class_ID[i].checked =true;
			}
		}

	//}
	//fnClearFormObjects(searchform);
	updatepropcount();
}
function showLeaseDiv(ival){
	//	alert(document.getElementById("for_sale").value);
	document.all.divLease.style.display = '';
	document.all.divBuy.style.display = 'none';
	document.searchform.LISTING_PRICE_MIN.selectedIndex = 0;
	document.searchform.LISTING_PRICE_MAX.selectedIndex = 0;
	
	
	for(i=0;i<6;i++){
	searchform.Property_Class_ID[i].checked =false;
	}
	if(ival==0){
		for(i=0;i<3;i++){
			searchform.PROP_TYPE[i].checked =true;
		}
	}	
	//fnClearFormObjects(searchform);
	//searchform.for_sale.value = 7;
	document.getElementById("for_sale").value = 7;
	updatepropcount();
}

function fnClearFormObjects(frm){
	frm.BEDROOM_NUM.selectedIndex = 0;
	frm.FULL_BATH_NUM.selectedIndex = 0;
	frm.SQURE_FEET_MIN.selectedIndex = 0;
	frm.SQURE_FEET_MAX.selectedIndex = 0;
	frm.GARAGE_NUM.selectedIndex = 0;
	frm.GARAGE_DESC.selectedIndex = 0;
	frm.STORIES.selectedIndex = 0;
	frm.NEW_CONSTR.selectedIndex = 0;
	frm.YEAR_BUILT.selectedIndex = 0;
	frm.PRIVATE_POOL.checked = false;
	frm.AREA_POOL.checked = false;
	frm.GOLF.checked = false;
	frm.VIRTUAL_TOURS.checked = false;
	frm.OPEN_HOUSES.checked = false;
}
function flipdiv(divid){
		whichviewmap = document.getElementById('mmapview');
		whichviewlisting = document.getElementById('mlistingview');
	if (divid == 'searchlist'){
		obj = document.getElementById('searchlist');
		otherobj = document.getElementById('map');
		whichviewmap.style.display = 'none';
		whichviewlisting.style.display = '';
		//alert('lisitngview now');
		
	}
	if (divid == 'map'){
		obj = document.getElementById('map');
		otherobj = document.getElementById('searchlist');
		whichviewmap.style.display = '';
		whichviewlisting.style.display = 'none';
		//alert('map view now');
	}
	
	if(obj.style.display == 'none') {
		obj.style.display = '';
		otherobj.style.display = 'none';
	}
	else {
		obj.style.display = 'none';
		otherobj.style.display = '';
	}

}
function flipsec(divid){
		whichviewmap = document.getElementById('profilep');
		whichviewlisting = document.getElementById('detailp');
	if (divid == 'detailview'){
		obj = document.getElementById('detailview');
		otherobj = document.getElementById('profileview');
		whichviewmap.style.display = 'none';
		whichviewlisting.style.display = '';
		//alert('lisitngview now');
		
	}
	if (divid == 'profileview'){
		obj = document.getElementById('profileview');
		otherobj = document.getElementById('detailview');
		whichviewmap.style.display = '';
		whichviewlisting.style.display = 'none';
		//alert('map view now');
	}
	
	if(obj.style.display == 'none') {
		obj.style.display = '';
		otherobj.style.display = 'none';
	}
	else {
		obj.style.display = 'none';
		otherobj.style.display = '';
	}

}

/*==============================================================================

    Routines written by John Gardner - 2003 - 2005

    See www.braemoor.co.uk/software for information about more freeware
    available.

/*==============================================================================

Routine to write a session cookie

    Parameters:
        cookieName        Cookie name
        cookieValue       Cookie Value
    
    Return value:
        true              Session cookie written successfullly
        false             Failed - persistent cookies are not enabled

   e.g. if (writeSessionCookie("pans","drizzle") then
           alert ("Session cookie written");
        else
           alert ("Sorry - Session cookies not enabled");
*/

function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

/*==============================================================================

Routine to get the current value of a cookie

    Parameters:
        cookieName        Cookie name
    
    Return value:
        false             Failed - no such cookie
        value             Value of the retrieved cookie

   e.g. if (!getCookieValue("pans") then  {
           cookieValue = getCoookieValue ("pans2);
        }
*/

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

/*==============================================================================

Routine to see if session cookies are enabled

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testSessionCookie())
           alert ("Session coookies are enabled");
        else
           alert ("Session coookies are not enabled");
*/

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}

/*==============================================================================

Routine to see of persistent cookies are allowed:

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testPersistentCookie()) then
           alert ("Persistent coookies are enabled");
        else
           alert ("Persistent coookies are not enabled");
*/

function testPersistentCookie () {
  writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
  if (getCookieValue ("testPersistentCookie")=="Enabled")
    return true  
  else 
    return false;
}

/*==============================================================================

Routine to write a persistent cookie

    Parameters:
        CookieName        Cookie name
        CookieValue       Cookie Value
        periodType        "years","months","days","hours", "minutes"
        offset            Number of units specified in periodType
    
    Return value:
        true              Persistent cookie written successfullly
        false             Failed - persistent cookies are not enabled
    
    e.g. writePersistentCookie ("Session", id, "years", 1);
*/       

function writePersistentCookie (CookieName, CookieValue, periodType, offset) {

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) {
    case "years":
      expireDate.setYear(expireDate.getFullYear()+offset);
      break;
    case "months":
      expireDate.setMonth(expireDate.getMonth()+offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate()+offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours()+offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes()+offset);
      break;
    default:
      alert ("Invalid periodType parameter for writePersistentCookie()");
      break;
  } 
  
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  

/*==============================================================================

Routine to delete a persistent cookie

    Parameters:
        CookieName        Cookie name
    
    Return value:
        true              Persistent cookie marked for deletion
    
    e.g. deleteCookie ("Session");
*/    

function deleteCookie (cookieName) {

  if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
  return true;     
}


