/****************************************************************************************************/
/*                           CORCORAN MAPS/CorcoranMapXMLHttpClient				 					*/
/* 						This file is used to send XML and Http request to the server 				*/
/*						and redirect the data to the appropriate processing function 				*/
/*											Date Created: 09/06/2006		 						*/
/*																			 						*/
/*						Copyright © 2006 The Corcoran Group, Inc. All Rights Reserved 				*/
/****************************************************************************************************/
//<![CDATA[
		   
var ServiceURL 	= 		"/Healthcare/CorcoranMapService.aspx?";		// The server-side script
var HttpObject 	= 		getHTTPObject();				// the HTTP Object
var isWorking 	= 		false;
var isAsync		=		true;							//synchronous or asynchronous request
var requestType	=		"";								//holds the request type //all listings
var subRequest	=		"";								//holds the subpart of the request //eg manhattan
var r_count		=		0;
var start		=		0;								//initial position for getting data from the ServiceUrl
var increment	=		50;								//the ending value for each result set. It is increase by s_limit
var s_limit		=		50;								//the amount of listings to return at a time
var srchOpLoaded=		false;							//reuse already loaded footer search options
var sortOpLoaded=		false;							//reuse already loaded header options
var isPostBack	=		false;
var sortorder	=		"price";						//the default sortorder
var q_detail	=		"";								//string containg built user search preferences
var t_count		=		"";
var count_by	=		"";								//used to return total listings count to the right searchtype
var ts			=		0;


function HandleHttpResponse() {

	if (HttpObject.readyState == 4) {

   		if (HttpObject.responseText.indexOf('invalid') == -1) {
			results = HttpObject.responseText;
			isWorking = false;
			ProcessListingsData(results,'manhattan');
//			switch(requestType)
//			{
//				case "AllListings":
//					ProcessAllListings(results,subRequest);
//					break;
//				case "ListingsCount":
//					switch(count_by)
//					{
//						case "ngbh":
//							SendSearchByNeighborhoods(results);
//							break;
//						default:
//							ProcessLoading(results);
//							break;
//					}
//					break;
//				default://"SrchAllListings"://"NewestListings"://"FeaturedListings"://"OpnhseListings":
//					ProcessListingsData(results,subRequest);
//					break;
//			}
		}
	}
}


function SendXmlHttpRequest(type,subtype) {//eg type=srchalllistings, subtype=manhattan
	requestType=type;
	subRequest=subtype;
	if (!isWorking && HttpObject) {
	  HttpObject.open("POST", ServiceURL +"type="+ escape(requestType)+"&subtype="+escape(subRequest)+"&start="+escape(start)+"&increment="+increment, true);	
	  HttpObject.onreadystatechange = HandleHttpResponse;	
	  HttpObject.send(null);
	}
}

function SendPreciseXmlHttpRequest(type,subtype,detail, area, rentSale)
{
    if((area != "") && (rentSale != ""))
    {
        ShowDHTML();
	    if(requestType!=type){requestType=type};
	    if(subRequest!=subtype){subRequest=subtype};
	    if (!isWorking && HttpObject) {        
	      HttpObject.open("POST", ServiceURL +"type=SrchAllListings&subtype=manhattan&s_detail=&area="+area + "&rentSale="+rentSale, true);	
	      //HttpObject.open("POST", ServiceURL +"type=SrchAllListings&subtype=manhattan&start=1&increment=15&s_detail=&area="+area + "&rentSale="+rentSale, true);	
	      //HttpObject.open("POST", ServiceURL +"type="+ escape(requestType)+"&subtype="+escape(subRequest)+"&start="+escape(start)+"&increment="+increment+"&s_detail="+detail+"&subway_line="+escape(subwayline), true);	
	      HttpObject.onreadystatechange = HandleHttpResponse;	
	      HttpObject.send(null);
	    }
	}
	else
	{
	    clearMap();
	    document.getElementById("fntLoadingCounter").innerHTML = "&nbsp;";
	}
	    
}

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;

}
 //]]>