// Search functions


function mfPropertySearch(){
  var Location = document.getElementById('_txtPropertyLocation').options[document.getElementById('_txtPropertyLocation').selectedIndex].value;
  var Province = document.getElementById('_txtPropertyProvince').options[document.getElementById('_txtPropertyProvince').selectedIndex].value;
  var Town = document.getElementById('_txtPropertyTown').options[document.getElementById('_txtPropertyTown').selectedIndex].value;
  var Type = document.getElementById('_txtPropertyType').options[document.getElementById('_txtPropertyType').selectedIndex].value;
  var PLId = "";
  var WebPage = "/Buying/Buying-Property-Search-Results.aspx?";

  if ( Location != "" && Location != '0' )
     PLId = document.getElementById('_txtPropertyLocation').options[document.getElementById('_txtPropertyLocation').selectedIndex].value; 

  if ( Province != "" && Province != '0' )
     PLId = document.getElementById('_txtPropertyProvince').options[document.getElementById('_txtPropertyProvince').selectedIndex].value;

  if ( Town != "" )
     PLId = document.getElementById('_txtPropertyTown').options[document.getElementById('_txtPropertyTown').selectedIndex].value;

  if (Type == 12)
     WebPage = "/New-Developments/ND-PropertySearch.aspx?"
  
  ///CESActList.aspx?Keyword=" + Keyword + "&Type=" + Type + "&Style=" + Style;
    window.location.href= WebPage + "PLId=" + PLId + "&PropertyTypeId=" + Type;
}



function mfGetProvinces()
{
  var objHTTPRequest  = ICB_CreateHTTPRequestObject();
  var strLocation = document.getElementById('_txtPropertyLocation').options[document.getElementById('_txtPropertyLocation').selectedIndex].value; 
  //Make the AJAX request to get the new table with the new sort order 
  if (strLocation != "" && strLocation != 0)
  {             
    objHTTPRequest.open('GET', '/Modules/ICB/Property/Scripts/GetLocations.aspx?PropertyParentLocation=' + strLocation + '&cboName=PropertyProvince&Function=test', true);
    objHTTPRequest.onreadystatechange = function(){	
						if (objHTTPRequest.readyState==4){	
			                          if ( objHTTPRequest.responseText != "none")
						    { 	
						      document.getElementById("_divPropertyProvince").innerHTML = objHTTPRequest.responseText;
						      document.getElementById("PropertyProvince").style.display = "";
						      document.getElementById("PropertyTown").style.display = "none";
						      document.getElementById('_txtPropertyProvince').options[document.getElementById('_txtPropertyProvince').selectedIndex].value = "";
						      document.getElementById('_txtPropertyTown').options[document.getElementById('_txtPropertyTown').selectedIndex].value = "";
						    }
						else
						    document.getElementById("PropertyProvince").style.display = 'none';
						  }
						}
  objHTTPRequest.send(null);
  }
  else
  {
    document.getElementById("PropertyProvince").style.display = 'none'
    document.getElementById('_txtPropertyProvince').options[document.getElementById('_txtPropertyProvince').selectedIndex].value = "";
    document.getElementById("PropertyTown").style.display = 'none'
    document.getElementById('_txtPropertyTown').options[document.getElementById('_txtPropertyTown').selectedIndex].value = "";
  }
}

function mfGetTowns()
{
  var objHTTPRequest  = ICB_CreateHTTPRequestObject();
  var strLocation = document.getElementById('_txtPropertyProvince').options[document.getElementById('_txtPropertyProvince').selectedIndex].value; 
  //Make the AJAX request to get the new table with the new sort order    
  if (strLocation != "" && strLocation != 0)
  {          
    objHTTPRequest.open('GET', '/Modules/ICB/Property/Scripts/GetLocations.aspx?PropertyParentLocation=' + strLocation + '&cboName=PropertyTown&Function=no', true);
    objHTTPRequest.onreadystatechange = function(){	
						if (objHTTPRequest.readyState==4){	
			                          if ( objHTTPRequest.responseText != "none") 	
						    {
						      document.getElementById("_divPropertyTown").innerHTML = objHTTPRequest.responseText;
						      document.getElementById("PropertyTown").style.display = "";
					            }
						else
						    document.getElementById("PropertyTown").style.display = 'none';
						  }
						}
    objHTTPRequest.send(null);
  }
  else
  {
    document.getElementById("PropertyTown").style.display = 'none'
    document.getElementById('_txtPropertyTown').options[document.getElementById('_txtPropertyTown').selectedIndex].value = "";    
  }
}
