    //These functions are being used in AdvancedListingSearch.
    var arrayCalDays = new Array("S", "M", "T", "W", "T", "F", "S");
    var calToday = "Today";
    var arrayCalMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

    var cal = new CalendarPopup('calendardiv');
    cal.dayHeaders = arrayCalDays;
    cal.monthNames = arrayCalMonths;
    cal.todayText = calToday;
    cal.showYearNavigation();
    cal.showYearNavigationInput(true);
    var curFunction = cal.returnFuction;
    cal.returnFuction = function()
		    {curFunction()
		    //SetValue(document.getElementById('ctl01_txtAvailabilityDate'), 'AvailabilityDate');
		    UpdateCountAJAX('');
		    }

    //To ensure that btnSearch_Click will fire first if applicable. block to set up the correctt form post action
	var BufAction = document.forms[0].action
	BufAction = BufAction.replace(/(\&CurrentPage\=\d+)|(CurrentPage\=\d+\&)/i,'')
	document.forms[0].action = BufAction; 
								    
    // This function is used to show/hide different controls on AdvancedListingSearch.ascx based on selected radio button for Residential or Commercial Property Type.
    function ShowHideFeaturesAdvancedListingSearch(obj, divPropertyTypeClientId, divCommPropertyTypeClientId, 
    divMinSqMeterClientId, divMinNumOfBedroomsClientId,
     accessToAdvancedSearchHideMinNumOfBedrooms, divTotalNumberOfRoomsClientId, divFloorLevelClientId, 
     ddlPropertyTypeClientId, ddlCommPropertyTypeClientId, ddlMinSqMetersClientId, ddlMinNumOfBedroomsClientId, 
     ddlTotalNumOfRoomsClientId, ddlFloorLevelClientId, accessToAdvancedSearchHideMinSqMeter, 
     accessToAdvancedSearchHideFloorLevel)
	{
		var ddlPropertyType = document.getElementById(ddlPropertyTypeClientId);
		var ddlCommPropertyType = document.getElementById(ddlCommPropertyTypeClientId);
		var ddlMinSqMeters = document.getElementById(ddlMinSqMetersClientId);
		var ddlMinNumOfBedrooms = document.getElementById(ddlMinNumOfBedroomsClientId);
		var ddlTotalNumOfRooms = document.getElementById(ddlTotalNumOfRoomsClientId);
		var ddlFloorLevel = document.getElementById(ddlFloorLevelClientId);		
		var PropertyType = document.getElementById("PropertyType");
		var SqMeter = document.getElementById("SqMeter");
		var MinNumOfBedrooms = document.getElementById("MinNumOfBedrooms");
		var TotalNumOfRooms = document.getElementById("TotalNumOfRooms");
		var FloorLevel = document.getElementById("FloorLevel");		
		var divBedRooms = document.getElementById(divMinNumOfBedroomsClientId);
	    var divTotalRooms = document.getElementById(divTotalNumberOfRoomsClientId);
		        
		if(obj != null)
		{
			if(obj.value == 2) //Residential
			{
		        if(accessToAdvancedSearchHideMinNumOfBedrooms.toString().toLowerCase() == "true" && divBedRooms != null)
		        {
				    divBedRooms.style.display = 'none';
				    divBedRooms.style.visibility = 'hidden';
				    divTotalRooms.style.display = '';
				    divTotalRooms.style.visibility = 'visible';
				}
				
				if(accessToAdvancedSearchHideMinNumOfBedrooms.toString().toLowerCase() == "false" && divTotalRooms != null)
		        {
				    divBedRooms.style.display = '';
				    divBedRooms.style.visibility = 'visible';
				    
				    divTotalRooms.style.display = 'none';
				    divTotalRooms.style.visibility = 'hidden';
				}
				
				if(accessToAdvancedSearchHideMinSqMeter.toString().toLowerCase() == "true")
				{
				    document.getElementById(divMinSqMeterClientId).style.display = 'none';
				    document.getElementById(divMinSqMeterClientId).style.visibility = 'hidden';
				}
				else
				{
				    document.getElementById(divMinSqMeterClientId).style.display = '';
				    document.getElementById(divMinSqMeterClientId).style.visibility = 'visible';
				}
				
				if(accessToAdvancedSearchHideFloorLevel.toString().toLowerCase() == "true")
				{
				    document.getElementById(divFloorLevelClientId).style.display = 'none';
				    document.getElementById(divFloorLevelClientId).style.visibility = 'hidden';
				}
				else
				{
				    document.getElementById(divFloorLevelClientId).style.display = '';
				    document.getElementById(divFloorLevelClientId).style.visibility = 'visible';
				}
				
				if (document.getElementById(divPropertyTypeClientId) != null)
				{
					document.getElementById(divPropertyTypeClientId).style.visibility = "visible";
					document.getElementById(divPropertyTypeClientId).style.display = "";
				}
				
				if (document.getElementById(divCommPropertyTypeClientId) != null)
				{
					document.getElementById(divCommPropertyTypeClientId).style.visibility = "hidden";
					document.getElementById(divCommPropertyTypeClientId).style.display = "none";
				}
				
				ddlCommPropertyType.selectedIndex = 0;
				PropertyType.value = "";
				ddlMinSqMeters.selectedIndex = 0;
				SqMeter.value = "";
				ddlMinNumOfBedrooms.selectedIndex = 0;
				MinNumOfBedrooms.value = "";
				ddlTotalNumOfRooms.selectedIndex = 0;
				TotalNumOfRooms.value = "";
				ddlFloorLevel.selectedIndex = 0;
				FloorLevel.value = "";
			}
			if(obj.value == 1) //Commercial
			{
				if(divBedRooms != null)
		        {
				    divBedRooms.style.display = 'none';
				    divBedRooms.style.visibility = 'hidden';
				}
				if(divTotalRooms != null)
		        {
				    divTotalRooms.style.display = 'none';
				    divTotalRooms.style.visibility = 'hidden';
				}
				document.getElementById(divFloorLevelClientId).style.display = 'none';
				document.getElementById(divFloorLevelClientId).style.visibility = 'hidden';
				document.getElementById(divMinSqMeterClientId).style.display = '';
				document.getElementById(divMinSqMeterClientId).style.visibility = 'visible';
				
				if (document.getElementById(divPropertyTypeClientId) != null)
				{
					document.getElementById(divPropertyTypeClientId).style.visibility = "hidden";
					document.getElementById(divPropertyTypeClientId).style.display = "none";
				}
				
				if (document.getElementById(divCommPropertyTypeClientId) != null)
				{
					document.getElementById(divCommPropertyTypeClientId).style.visibility = "visible";
					document.getElementById(divCommPropertyTypeClientId).style.display = "";
				}
				
				ddlPropertyType.selectedIndex = 0;
				PropertyType.value = "";
				ddlMinSqMeters.selectedIndex = 0;
				SqMeter.value = "";
				ddlMinNumOfBedrooms.selectedIndex = 0;
				MinNumOfBedrooms.value = "";
				ddlTotalNumOfRooms.selectedIndex = 0;
				TotalNumOfRooms.value = "";
				ddlFloorLevel.selectedIndex = 0;
				FloorLevel.value = "";
			}
		}			
	}

// This function is used to set Min/Max price on AdvancedListingSearch.ascx based on selected radio button for Transaction Type.
        function SetMinMaxPriceRangeAdvancedListingSearch(obj, divMinPriceClientId, divMaxPriceClientId, divRentalMinPriceClientId, divRentalMaxPriceClientId, ddlMinPriceClientId, ddlMaxPriceClientId, ddlRentalMinPriceClientId, ddlRentalMaxPriceClientId)
		{	 
			var ddlMinPrice = document.getElementById(ddlMinPriceClientId);
			var ddlMaxPrice = document.getElementById(ddlMaxPriceClientId);
			var ddlRentalMinPrice = document.getElementById(ddlRentalMinPriceClientId);
			var ddlRentalMaxPrice = document.getElementById(ddlRentalMaxPriceClientId);
			
			var MinPrice = document.getElementById("MinPrice");
			var MaxPrice = document.getElementById("MaxPrice");
			var RentalMinPrice = document.getElementById("RentalMinPrice");
			var RentalMaxPrice = document.getElementById("RentalMaxPrice");
			
			//alert(obj.value);
			if (obj.value == 'For Rent/Lease' || obj.value == 'Holiday/Short Term Rental')
			{
					if (document.getElementById(divMinPriceClientId) != null)
					{
						document.getElementById(divMinPriceClientId).style.visibility = "hidden";
						document.getElementById(divMinPriceClientId).style.display = "none";
					}
					if (document.getElementById(divMaxPriceClientId) != null)
					{
						document.getElementById(divMaxPriceClientId).style.visibility = "hidden";
						document.getElementById(divMaxPriceClientId).style.display = "none";
					}
					
					if (document.getElementById(divRentalMinPriceClientId) != null)
					{
						document.getElementById(divRentalMinPriceClientId).style.visibility = "visible";
						document.getElementById(divRentalMinPriceClientId).style.display = "";  
					}
					if (document.getElementById(divRentalMaxPriceClientId) != null)
					{
						document.getElementById(divRentalMaxPriceClientId).style.visibility = "visible";
						document.getElementById(divRentalMaxPriceClientId).style.display = "";  
					}
					
					if (document.getElementById("divCurrencySymbol") != null)
					{
					  document.getElementById("divCurrencySymbol").style.visibility = "hidden";
					  document.getElementById("divCurrencySymbol").style.display = "none";
					}
					
					//ddlMinPrice.selectedIndex = 0;
					MinPrice.value = "";
					ddlMaxPrice.selectedIndex = 0;
					MaxPrice.value = "";
			/*		if (document.getElementById("divCurrency") != null)
					{
						document.getElementById("divCurrency").style.visibility = "hidden";
						document.getElementById("divCurrency").style.display = "none";  
					}
			*/
			}   
			else
			{
					if (document.getElementById(divMinPriceClientId) != null)
					{
						document.getElementById(divMinPriceClientId).style.visibility = "visible";
						document.getElementById(divMinPriceClientId).style.display = "";
					}
					if (document.getElementById(divMaxPriceClientId) != null)
					{
						document.getElementById(divMaxPriceClientId).style.visibility = "visible";
						document.getElementById(divMaxPriceClientId).style.display = "";
					}
					if (document.getElementById(divRentalMinPriceClientId) != null)
					{
						document.getElementById(divRentalMinPriceClientId).style.visibility = "hidden"; 
						document.getElementById(divRentalMinPriceClientId).style.display = "none";
					}
					if (document.getElementById(divRentalMaxPriceClientId) != null)
					{
						document.getElementById(divRentalMaxPriceClientId).style.visibility = "hidden"; 
						document.getElementById(divRentalMaxPriceClientId).style.display = "none";
					}
					
					if (document.getElementById("divCurrencySymbol") != null)
					{
				    document.getElementById("divCurrencySymbol").style.visibility = "visible";
				    document.getElementById("divCurrencySymbol").style.display = "";
          }
          					
					MinPrice.value = "<%= hidMinPrice %>";
					ddlRentalMinPrice.selectedIndex = 0;
					RentalMinPrice.value = "";
					ddlRentalMaxPrice.selectedIndex = 0;
					RentalMaxPrice.value = "";
			/*		if (document.getElementById("divCurrency") != null)
					{
						document.getElementById("divCurrency").style.visibility = "visible";
						document.getElementById("divCurrency").style.display = "";  
					}
			*/
			}
		}
		
		function SetStatusValue(obj, target, defaultVal)
		{	
			if(obj.checked)
			{
				document.getElementById(target).value = defaultVal;
			}
			else
			{
				document.getElementById(target).value = "";
				obj.value = "";
			}
		}
		
		function SetCurrency(currencyCode, ddlCurrencyClientId, lblCurrencyClientId)
		{
			document.getElementById("Currency").value= currencyCode;
			var ddlCurrency = document.getElementById(ddlCurrencyClientId);
			var lblCurrency = document.getElementById(lblCurrencyClientId);
			//alert(ddlCurrency.options.length);
			for(var i=0; i<= ddlCurrency.options.length; i++)
			{
				if(ddlCurrency.options[i].value == currencyCode)
				{
					//alert(i);
					ddlCurrency.selectedIndex = -1;
					ddlCurrency.selectedIndex = i;
					break;
				}
			}
			
			if(currencyCode == "GBP")
			{
				lblCurrency.innerHTML = "&pound;";
			}
			else if(currencyCode == "EUR")
			{
				lblCurrency.innerHTML = "&euro;";
			}
			else if(currencyCode == "USD")
			{
				lblCurrency.innerHTML = "$";
			}
			else if(currencyCode == "FRF")
			{
				lblCurrency.innerHTML = "&#x20a3;";
			}
			else
			{
				lblCurrency.innerHTML = currencyCode ;
			}
			
		}
		
		function AvDate(Show, searchRemaxRegionID, divAvDateClientId, txtAvailabilityDateClientId)
		{
            if(searchRemaxRegionID == 24)
            {
                DivAvDate = document.getElementById(divAvDateClientId);
                TxtAvailabilityDate = document.getElementById(txtAvailabilityDateClientId);
                if (Show)
	            {
		            DivAvDate.style.display = "";
		            //As user switched from For Sale to For Rent/Lease, let's reset the MinPrice value to 0;
		            document.getElementById("MinPrice").value=0;
	            }
                else
                {
                    DivAvDate.style.display = "none";
	                TxtAvailabilityDate.value = ''
	            }
            }
        }
        
        
        function FindNameValue(param)
        {
          var MissingElement = '';
          if (param != null && param != '')
          {
            var i = 0;
            for (i = 0; i < document.getElementsByName(param).length; i++)
            {
              if (document.getElementsByName(param)[i].checked != false)
              {
                MissingElement += document.getElementsByName(param)[i].value + ',';
              }
            }
            MissingElement = MissingElement.slice(0, MissingElement.length-1);
          }
          return MissingElement;
        }

        function UpdateSparamsAJAX(param)
        {
            //Used with function UpdateCountAJAX in ListingSearch. Does not execute spListingSearch only updates the sParams.
            if (param != null && param != '')
            {
              var paramElm = '';
              if (MM_findObj(param) == null || MM_findObj(param).value == null || MM_findObj(param).value == '' || MM_findObj(param).value == 'undefined')
              {
                paramElm = FindNameValue(param);
                var newcount = Gryphtech.RemaxEurope.RemaxEuropeSearchEngine.ListingSearch.UpdateCountAJAX(searchKey, currentSiteId, param, (paramElm != null)?paramElm:'');
              }
              else
              {
                paramElm = MM_findObj(param);
                var newcount = Gryphtech.RemaxEurope.RemaxEuropeSearchEngine.ListingSearch.UpdateCountAJAX(searchKey, currentSiteId, param, (paramElm != null)?paramElm.value:'');
              }
            }
        }

        function UpdateCountAJAX(param)
        {
            setTimeout('UpdateCountTimer(\''+param+'\')', 5000);
	    	//setTimeout('ShowHideSaveButton()', 5000);
        }

        function UpdateCountTimer(param)
        {
            var lblCount = MM_findObj(lblCountClientId);

            if (param != null && param != '')
            {
                var paramElm = '';
                if (MM_findObj(param) == null || MM_findObj(param).value == null || MM_findObj(param).value == '' || MM_findObj(param).value == 'undefined')
                {
                    paramElm = FindNameValue(param);
                    var newcount = Gryphtech.RemaxEurope.RemaxEuropeSearchEngine.ListingSearch.GetCountAJAX(searchKey, currentSiteId, param, (paramElm != null)?paramElm:'');
                }
                else
                {
                    paramElm = MM_findObj(param);
                    var newcount = Gryphtech.RemaxEurope.RemaxEuropeSearchEngine.ListingSearch.GetCountAJAX(searchKey, currentSiteId, param, (paramElm != null)?paramElm.value:'');
                }
            }
            else
            {
                var newcount = Gryphtech.RemaxEurope.RemaxEuropeSearchEngine.ListingSearch.GetCountAJAX(searchKey, currentSiteId, '', '');
            }
            lblCount.innerHTML = newcount.value;
        }
        
