﻿// JScript File

var xmlHttp;
var theReqId=-1;

//////////////////////////
function stateChanged() 
        {
            if (xmlHttp.readyState==4){
                var xmlDoc=xmlHttp.responseText;                
                if(theReqId=='2')
                {                
                    companies = new PowerXML().GetValueOfTag(xmlDoc,'company');                   
                    listt2 = ws_ShuffleArray(companies.clone());
                    iMax = listt2.length;
                     for (i=0; i<iMax; i++)
                     {
                   
                    tmpCompany = listt2.pop();
                   
                    v_bid = new PowerXML().GetValueOfTag(tmpCompany,'compname').pop();
                    document.getElementById('txtArea').value+=' , ' +v_bid;               
                   
                    xx=new PowerXML().GetValueOfTag(tmpCompany,'contname').pop();                
                    document.getElementById('txtArea').value+=' , ' +xx;
                    }
                } 
                else if(theReqId=='3')
                {  //map                   
                    v_bid = new PowerXML().GetValueOfTag(xmlDoc,'LatLongs'); 
                    var counts = new PowerXML().GetValueOfTag(xmlDoc,'listingcount');
                    var names = new PowerXML().GetValueOfTag(xmlDoc,'cityname');
                    LoadAllCity(v_bid,counts,names);                    
                    mapdataready=true;
                    lock=false;               
                }
                else if(theReqId == '4')
                {//listing pushpin 
                    var ids = new PowerXML().GetValueOfTag(xmlDoc,'ID');
                    var alllatslongs = new PowerXML().GetValueOfTag(xmlDoc,'Lats'); 
                    var bathes = new PowerXML().GetValueOfTag(xmlDoc,'Bathrooms'); 
                    var beds = new PowerXML().GetValueOfTag(xmlDoc,'Bedrooms'); 
                    var types = new PowerXML().GetValueOfTag(xmlDoc,'Type');
                    var prices = new PowerXML().GetValueOfTag(xmlDoc,'Price');                    
                    var names = new PowerXML().GetValueOfTag(xmlDoc,'Cityname');                    
                    LoadListings(alllatslongs,ids,names,types,beds,bathes,prices);
                    //listingdataready=true;
                    mapdataready=true;
                    lock=false;
                    
                }
                else if(theReqId == '5')
                {//listing detail
                    var cleanLocation = new PowerXML().GetValueOfTag(xmlDoc,'CleanLocation');
                    var Bedrooms = new PowerXML().GetValueOfTag(xmlDoc,'Beds');
                    var Bathrooms = new PowerXML().GetValueOfTag(xmlDoc,'Bath');
                    var Image = new PowerXML().GetValueOfTag(xmlDoc,'Image');
                    var detailID = new PowerXML().GetValueOfTag(xmlDoc,'ID');
                    LoadListingDetails(cleanLocation[0],Bedrooms[0],Bathrooms[0],Image[0],detailID[0]);
                }
                else if(theReqId == '6')
                {//list view
                    var cleanLocation = new PowerXML().GetValueOfTag(xmlDoc,'Location');
                    var Bedrooms = new PowerXML().GetValueOfTag(xmlDoc,'Bedrooms');
                    var Bathrooms = new PowerXML().GetValueOfTag(xmlDoc,'Bathrooms');
                    var image = new PowerXML().GetValueOfTag(xmlDoc,'Image');
                    var detailID = new PowerXML().GetValueOfTag(xmlDoc,'ID');
                    var prices = new PowerXML().GetValueOfTag(xmlDoc,'Price');
                    var mlses = new PowerXML().GetValueOfTag(xmlDoc,'MlsNumber');
                    var pageCnt = new PowerXML().GetValueOfTag(xmlDoc,'PageCount');
                    var forleas = new PowerXML().GetValueOfTag(xmlDoc,'ForLease');
                    var forsale = new PowerXML().GetValueOfTag(xmlDoc,'ForSale');
                    var startIndex = new PowerXML().GetValueOfTag(xmlDoc,'StartIndex');
                    var endIndex = new PowerXML().GetValueOfTag(xmlDoc,'EndIndex');
                    var totalListing = new PowerXML().GetValueOfTag(xmlDoc,'TotalListings');
                    var queryString= new PowerXML().GetValueOfTag(xmlDoc,'QueryString');  
                    var cityName= new PowerXML().GetValueOfTag(xmlDoc,'CityName');                   
                    LoadMoreListingDetails(cleanLocation,Bedrooms,Bathrooms,image,detailID,prices,mlses,forleas,forsale,pageCnt,startIndex,endIndex,totalListing,cityName,queryString);
                    listingdataready=true;  
                    lock=false;
                  
                }
                else if(theReqId=='7')
                {  //leftnavigation            
                    var counts = new PowerXML().GetValueOfTag(xmlDoc,'listingcount');
                    var names = new PowerXML().GetValueOfTag(xmlDoc,'cityname');
                    SaveHistory('cityname',names[0]);
                    var sec='';
                    if(LoadHistory('cityname')!='')
                    {
                        sec = LoadHistory('cityname');
                    }
                    else
                    {
                        sec=names[0];
                        SaveHistory('cityname',sec);
                    }
                    LoadAllCityNames(counts,names,sec);
                    leftnavigationdataready=true;
                    lock=false;                 
                }
                else if(theReqId=='8')
                {  //show subregions            
                    var codes = new PowerXML().GetValueOfTag(xmlDoc,'Code');
                    var names = new PowerXML().GetValueOfTag(xmlDoc,'Name');
                    ShowSubregions(names,codes);                      
                    //lock=false;                  
                }
                else if(theReqId=='9')
                {  //show subregions            
                    var lats = new PowerXML().GetValueOfTag(xmlDoc,'Lat');
                    var longs = new PowerXML().GetValueOfTag(xmlDoc,'Long');
                    var titles = new PowerXML().GetValueOfTag(xmlDoc,'Title');
                    LoadNeibourhoods(lats,longs,titles);
                    //lock=false;                  
                }
                else if(theReqId=='10')
                {  //show subregions                                
                    var types = new PowerXML().GetValueOfTag(xmlDoc,'Type');
                    ListNeibourhoods(types);
                    lock=false;                  
                    neibourhoodataready=true;
                }
                else if(theReqId=='11')
                {  //show subregions                                
                    var Ids = new PowerXML().GetValueOfTag(xmlDoc,'ID');
                    var locs = new PowerXML().GetValueOfTag(xmlDoc,'Location');
                    Ids.reverse();
                    locs.reverse();
                    LoadListingLoacations(Ids,locs);                                      
                }
                else if(theReqId=='12')
                {  //show subregions                             
                    var Ids = new PowerXML().GetValueOfTag(xmlDoc,'ID');
                    var locs = new PowerXML().GetValueOfTag(xmlDoc,'Location');
                    Ids.reverse();
                    locs.reverse();
                    LoadNeibourhoodLoacations(Ids,locs);                                      
                }
                else if(theReqId=='13')
                {  //show subregions                             
                    var condoLat = new PowerXML().GetValueOfTag(xmlDoc,'Lat');
                    var condoLong = new PowerXML().GetValueOfTag(xmlDoc,'Long');                    
                    var ID = new PowerXML().GetValueOfTag(xmlDoc,'ID'); 
                    LoadCondo(condoLat,condoLong,ID); 
                    lock=false;
                    mapdataready=true;                                     
                }
                else if(theReqId=='14')//map fullliasting.aspx
                {  
                    var mlses = new PowerXML().GetValueOfTag(xmlDoc,'MLS');
                    var Types = new PowerXML().GetValueOfTag(xmlDoc,'Type');
                    var Locations = new PowerXML().GetValueOfTag(xmlDoc,'Location');
                    var Prices = new PowerXML().GetValueOfTag(xmlDoc,'Price');
                    var Bedroom = new PowerXML().GetValueOfTag(xmlDoc,'Bedrooms');
                    var Bathroom = new PowerXML().GetValueOfTag(xmlDoc,'Bathrooms');
                    var Kitchens = new PowerXML().GetValueOfTag(xmlDoc,'Kitchens');
                    var Taxe = new PowerXML().GetValueOfTag(xmlDoc,'Taxes');
                    var Descriptions = new PowerXML().GetValueOfTag(xmlDoc,'Description');
                    var Parkings = new PowerXML().GetValueOfTag(xmlDoc,'Parking');
                    var Attributes = new PowerXML().GetValueOfTag(xmlDoc,'Attributes');
                    var Broker = new PowerXML().GetValueOfTag(xmlDoc,'Broker');           
                    LoadFullListingDetails(mlses[0],Types[0],Locations[0],Prices[0],Bedroom[0],Bathroom[0],Taxe[0],Descriptions[0],Parkings[0],Kitchens[0],Attributes[0],Broker[0])                                     
                  
                }    
               else if(theReqId=='15')
                {  //show subregions                             
                    var ID = new PowerXML().GetValueOfTag(xmlDoc,'itemid');                                 
                    GetData('GetData/GetExternalUrl.aspx','url=GetMapFullListingData&listing='+ID[0],'14');                                                      
                }           
            }                        
        }           
/////////////////////////////////////////////////////////////////////////////////
function GetData(pag,qs,reqId)
    { 
        xmlHttp;            
        theReqId=reqId;
        xmlHttp=GetXmlHttpObject();            
        if (xmlHttp==null){alert ("Your browser does not support AJAX!");return;}
        if(qs != '')
        { 
            var sRes = pag + '?' + qs + '&sid=' + Math.random();
        }
        else
        {
            var sRes = pag + '?sid=' + Math.random();
        }      
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("GET",sRes,true);
        xmlHttp.send(null);
    }
//////////////////////////
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
/////////////////////////////

