﻿// JScript File
function getDistricts(object)
{
    var regionId = object.options[object.selectedIndex].value;
    var curTime = new Date();     
    document.getElementById('divDistrict').innerHTML ="";
    document.getElementById('ctl00_ContentPlaceHolder1_divCommunity').innerHTML ="";
    document.getElementById('ctl00_ContentPlaceHolder1_divSubCommunity').innerHTML ="";
    document.getElementById('txtDistrict').value ='Please Select District';
    document.getElementById('ctl00_ContentPlaceHolder1_txtComm').value ='Please Select community';
    document.getElementById('ctl00_ContentPlaceHolder1_txtSubComm').value ='Please select Sub-community';    
    document.getElementById('ctl00_ContentPlaceHolder1_hidDistrict').value ='';
    document.getElementById('ctl00_ContentPlaceHolder1_hidCommunity').value ='';
    document.getElementById('ctl00_ContentPlaceHolder1_hidSubCommunity').value ='';    
    if(regionId != -1)
    {
        document.getElementById('divDistrict').innerHTML ="Loading...";
        PageMethods.getDistrictByRegionId(regionId, curTime.toString(), onSuccessDistrictInfo, onFailureDistrictInfo, curTime.toString())
    }    
}
function onSuccessDistrictInfo(result, context, method)
{
    var DistrictInfo = result;
    var districtIndex = 0;
    var  FinalHTML = new String();    
    if(DistrictInfo != null)
    {
        if(DistrictInfo.length > 0)
        {
            FinalHTML = "<table cellspacing='0' cellpadding='0' border='0'>";            
            for(districtIndex = 0; districtIndex < DistrictInfo.length; districtIndex++)
            {
                if(DistrictInfo[districtIndex].DistrictId == 0)
                {
                    FinalHTML += "<tr><td style='vertical-align:top;'><input name='lstDistrict' id='allDistrict' style='vertical-align:top;margin:0px 0px;padding:0px 0px;' type='Checkbox' onclick='chkAll(this);getCommunities();' value='" + DistrictInfo[districtIndex].DistrictId + "|" + DistrictInfo[districtIndex].DistrictName + "' /></td><td style='padding-left:5px;'>" + DistrictInfo[districtIndex].DistrictName + "</td></tr>";
                }
                else
                {
                    FinalHTML += "<tr><td style='vertical-align:top;'><input name='lstDistrict' style='vertical-align:top;margin:0px 0px;padding:0px 0px;' type='Checkbox' onclick=\"getCommunities();removeAllchk('District');\" value='" + DistrictInfo[districtIndex].DistrictId + "|" + DistrictInfo[districtIndex].DistrictName + "' /></td><td style='padding-left:5px;'>" + DistrictInfo[districtIndex].DistrictName + "</td></tr>";
                }
            }            
            FinalHTML += "</table>";            
            document.getElementById('divDistrict').innerHTML = FinalHTML;
        }
    }    
}
function onFailureDistrictInfo(result, context, method)
{
   document.getElementById('divDistrict').innerHTML ="";
}
function getCommunities(object)
{
    
    var regionId = object.options[object.selectedIndex].value;
    var curTime = new Date();    
    document.getElementById('ctl00_ContentPlaceHolder1_divCommunity').innerHTML ="";
    document.getElementById('ctl00_ContentPlaceHolder1_divSubCommunity').innerHTML ="";    
    document.getElementById('ctl00_ContentPlaceHolder1_txtComm').value ='Please Select community';
    document.getElementById('ctl00_ContentPlaceHolder1_txtSubComm').value ='Please select Sub-community';    
    document.getElementById('ctl00_ContentPlaceHolder1_hidCommunity').value ='';
    document.getElementById('ctl00_ContentPlaceHolder1_hidSubCommunity').value ='';    
    if(regionId != "")
    {
        document.getElementById('ctl00_ContentPlaceHolder1_divCommunity').innerHTML ="Loading...";
        PageMethods.getDistrictAndCommunityByRegionId(regionId, curTime.toString(), onSuccessCommunityInfo, onFailureCommunityInfo, curTime.toString())
    }    
    //******************
}
function onSuccessCommunityInfo(result, context, method)
{
    var CommunityInfo = result;
    var CommunityIndex = 0;
    var  FinalHTML = new String();
    if(CommunityInfo != null)
    {
        if(CommunityInfo.length > 0)
        {
            FinalHTML = "<table cellspacing='0' cellpadding='0' border='0'>";            
            for(CommunityIndex = 0; CommunityIndex < CommunityInfo.length; CommunityIndex++)
            {
                if(CommunityInfo[CommunityIndex].CommunityId == 0)
                {
                    FinalHTML += "<tr><td style='vertical-align:top;'><input name='lstCommunity' id='allCommunity' style='vertical-align:top;margin:0px 0px;padding:0px 0px;' type='Checkbox' onclick='chkAll(this);getSubCommunities();' value='" + CommunityInfo[CommunityIndex].CommunityId + "|" + CommunityInfo[CommunityIndex].CommunityName + "' /></td><td style='padding-left:5px;'>" + CommunityInfo[CommunityIndex].CommunityName + "</td></tr>";
                }
                else
                {
                    FinalHTML += "<tr><td style='vertical-align:top;'><input name='lstCommunity' style='vertical-align:top;margin:0px 0px;padding:0px 0px;' type='Checkbox' onclick=\"getSubCommunities();removeAllchk('Community');\" value='" + CommunityInfo[CommunityIndex].CommunityId + "|" + CommunityInfo[CommunityIndex].CommunityName + "' /></td><td style='padding-left:5px;'>" + CommunityInfo[CommunityIndex].CommunityName + "</td></tr>";
                }
            }            
            FinalHTML += "</table>";            
            document.getElementById('ctl00_ContentPlaceHolder1_divCommunity').innerHTML = FinalHTML;
            if(document.getElementById("ctl00_ContentPlaceHolder1_cboRegion").options[document.getElementById("ctl00_ContentPlaceHolder1_cboRegion").selectedIndex].value == -1)
            {
                if(document.getElementById("allCommunity"))
                {
                    document.getElementById("allCommunity").checked = 'checked';
                    chkAll(document.getElementById("allCommunity"));
                    getSubCommunities();
                }
            }
        }
    }
}

function onFailureCommunityInfo(result, context, method)
{
   document.getElementById('ctl00_ContentPlaceHolder1_divCommunity').innerHTML ="";
}

function getSubCommunities()
{
    var districtLst = document.getElementsByName('lstCommunity');
    var curTime = new Date();
    var districtIndex;
    var Valuelst = new String();
    var Textlst = new String();
    
   for(var districtIndex=1;districtIndex < districtLst.length;districtIndex++)
   {
        if(districtLst[districtIndex].checked)
        {
            var keyVal = new String();
            keyVal = districtLst[districtIndex].value;
            Valuelst = Valuelst +  keyVal.split('|')[0] +",";
            Textlst = Textlst +  keyVal.split('|')[1] +",";
        }
   }
   
   if(Textlst == "")
   {
        document.getElementById('ctl00_ContentPlaceHolder1_txtComm').value ='Please Select Commmunity';
   }
   else
   {
        Valuelst = Valuelst.substr(0,Valuelst.length-1);
        Textlst = Textlst.substr(0,Textlst.length-1);
        document.getElementById('ctl00_ContentPlaceHolder1_txtComm').value = Textlst;
   }
                  
    document.getElementById('ctl00_ContentPlaceHolder1_divSubCommunity').innerHTML ="";
    

    document.getElementById('ctl00_ContentPlaceHolder1_hidCommunity').value =Valuelst;
    document.getElementById('ctl00_ContentPlaceHolder1_hidSubCommunity').value ='';
    
    document.getElementById('ctl00_ContentPlaceHolder1_txtSubComm').value ='Please select Sub-community';
    if(Valuelst != "")
    {
        document.getElementById('ctl00_ContentPlaceHolder1_divSubCommunity').innerHTML ="Loading...";
        PageMethods.getSubCommunityByCommunityId(Valuelst, curTime.toString(), onSuccessSubCommunityInfo, onFailureSubCommunityInfo, curTime.toString())
    }
    
}

function onSuccessSubCommunityInfo(result, context, method)
{
    var SubCommunityInfo = result;
    var CommunityIndex = 0;
    var  FinalHTML = new String();
    
    if(SubCommunityInfo != null)
    {
        if(SubCommunityInfo.length > 0)
        {
            FinalHTML = "<table cellspacing='0' cellpadding='0' border='0'>";
            
            for(CommunityIndex = 0; CommunityIndex < SubCommunityInfo.length; CommunityIndex++)
            {
                if(SubCommunityInfo[CommunityIndex].SubCommunityId == 0)
                {
                    FinalHTML += "<tr><td style='vertical-align:top;'><input name='lstSubCommunity' id='allSubCommunity' style='vertical-align:top;margin:0px 0px;padding:0px 0px;' type='Checkbox' onclick=\"javascript:chkAll(this);fillSubCommunityText();\"'' value='" + SubCommunityInfo[CommunityIndex].SubCommunityId + "|" + SubCommunityInfo[CommunityIndex].SubCommunityName + "' /></td><td style='padding-left:5px;'>" + SubCommunityInfo[CommunityIndex].SubCommunityName + "</td></tr>";
                }
                else
                {
                    FinalHTML += "<tr><td style='vertical-align:top;'><input name='lstSubCommunity' style='vertical-align:top;margin:0px 0px;padding:0px 0px;' type='Checkbox' value='" + SubCommunityInfo[CommunityIndex].SubCommunityId + "|" + SubCommunityInfo[CommunityIndex].SubCommunityName + "' onclick=\"javascript:fillSubCommunityText();removeAllchk('subCommunity');\"' /></td><td style='padding-left:5px;'>" + SubCommunityInfo[CommunityIndex].SubCommunityName + "</td></tr>";
                }
            }
            
            FinalHTML += "</table>";
            
            document.getElementById('ctl00_ContentPlaceHolder1_divSubCommunity').innerHTML = FinalHTML;
            fillSubCommunityText();
            if(document.getElementById("ctl00_ContentPlaceHolder1_cboRegion"))
            {
                if(document.getElementById("ctl00_ContentPlaceHolder1_cboRegion").options[document.getElementById("ctl00_ContentPlaceHolder1_cboRegion").selectedIndex].value == -1)
                {
                    if(document.getElementById("allSubCommunity"))
                    {
                        document.getElementById("allSubCommunity").checked = 'checked';
                        chkAll(document.getElementById("allSubCommunity"));
                        fillSubCommunityText();                        
                    }
                }
            }
        }
    }
    
}

function onFailureSubCommunityInfo(result, context, method)
{
   document.getElementById('ctl00_ContentPlaceHolder1_divSubCommunity').innerHTML ="";
}

 function chkAll(obj)
 {
       var comunityLst = document.getElementsByName(obj.name);
       
       for(var k=0;k < comunityLst.length;k++)
       {
            if(obj.checked)
                comunityLst[k].checked = 'checked';
            else
                comunityLst[k].checked = '';
            
       }
 
}


function removeAllchk(txt)
{
    var unchk = "checked"
    if(txt == 'Community')
    {
        var k = 0;
        var obj = document.getElementById('allCommunity');
        var objLst = document.getElementsByName('lstCommunity');
        for(k = 1;k <= objLst.length -1; k++)
        {
            if(objLst[k].checked == false)
            {
                unchk = "";
            }
        }
        if(obj != null)
        {
            obj.checked = unchk;
        }
    } 
    else if(txt == 'subCommunity')
    {
        var obj = document.getElementById('allSubCommunity');
        var objLst = document.getElementsByName('lstSubCommunity');
        for(k = 1;k <= objLst.length -1; k++)
        {
            if(objLst[k].checked == false)
            {
                unchk = "";
            }
        }
       if(obj != null)
        {
            obj.checked = unchk;
        }
    }
    else if(txt == 'District')
    {
        var obj = document.getElementById('allDistrict');
        var objLst = document.getElementsByName('lstDistrict');
        
        for(k = 1;k <= objLst.length -1; k++)
        { 
            if(objLst[k].checked == false)
            {
                unchk = "";
            }
        }
        
        if(obj != null)
        {
            obj.checked = unchk;
        }
        var objSubCom = document.getElementById('ctl00_ContentPlaceHolder1_divSubCommunity');
        objSubCom.innerHTML ="";
    }
}

function fillSubCommunityText()
 {
     var Textlst = "";
     var Valuelst = "";
      var subCommunityLst = document.getElementsByName('lstSubCommunity');
       for(var k=0;k < subCommunityLst.length;k++)
       {
            if(subCommunityLst[k].checked)
            {
                var keyVal = new String();
                keyVal = subCommunityLst[k].value;
                if(keyVal.split('|')[0] != "0")
                {
                    Textlst = Textlst +  keyVal.split('|')[1] +",";
                    Valuelst = Valuelst +  keyVal.split('|')[0] +",";
                }
            }
       }
       Textlst = Textlst.substr(0,Textlst.length-1);
       Valuelst = Valuelst.substr(0,Valuelst.length-1);
       var ctl00_ContentPlaceHolder1_txtSubCommunityTextValues = document.getElementById('ctl00_ContentPlaceHolder1_txtSubComm');
       ctl00_ContentPlaceHolder1_txtSubCommunityTextValues.value = Textlst == ""?"Please select Sub-communities":Textlst; 
   
        document.getElementById('ctl00_ContentPlaceHolder1_hidSubCommunity').value = Valuelst;
}

function setSearchOptions(obj)
{
     //Commented by Rakesh 28th Nov 2008
    /*try
    {
        var SelectedIndex= obj.selectedIndex;
        var value=obj[SelectedIndex].value;
        
         var UnityTypeObj =document.getElementById("ctl00_ContentPlaceHolder1_ddlCategoryGroup");
         
        
         if (value ==-1)
         {
         
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMinPrice").disabled='disabled';
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMaxPrice").disabled='disabled';
             UnityTypeObj.disabled='disabled';
         
         }
         else if(value==1)
         {
             UnityTypeObj.selectedIndex=1;
             //Commented by Rakesh 28th Nov 2008
             //getPriceAndSize(UnityTypeObj);
             //document.getElementById("trAvailabityChk").style.display='';
             document.getElementById("trPriceRange").style.display='';
             //document.getElementById("trAvlDate").style.display='none';
             document.getElementById("divMoreOptionsTop").style.display='';
             document.getElementById('ctl00_ContentPlaceHolder1_hidMore').value = "0";
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMinPrice").disabled='';
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMaxPrice").disabled='';
             UnityTypeObj.disabled='';
             
         }
         else if(value==2)
         {
         
             UnityTypeObj.selectedIndex=1;
             //Commented by Rakesh 28th Nov 2008
             //getPriceAndSize(UnityTypeObj);
             //document.getElementById("trAvailabityChk").style.display='';
             document.getElementById("trPriceRange").style.display='';
             //document.getElementById("trAvlDate").style.display='none';
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMinPrice").disabled='';
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMaxPrice").disabled='';
             document.getElementById("divMoreOptionsTop").style.display='none';
             document.getElementById('ctl00_ContentPlaceHolder1_hidMore').value = "0";
            UnityTypeObj.disabled='';         
         }
         else
         {
             UnityTypeObj.selectedIndex=1;
             //Commented by Rakesh 28th Nov 2008
             //getPriceAndSize(UnityTypeObj);
             //document.getElementById("trAvailabityChk").style.display='none';
             document.getElementById("trPriceRange").style.display='none';
             //document.getElementById("trAvlDate").style.display='';
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMinPrice").disabled='';
             document.getElementById("ctl00_ContentPlaceHolder1_ddlMaxPrice").disabled='';
             document.getElementById("divMoreOptionsTop").style.display='none';
             document.getElementById('ctl00_ContentPlaceHolder1_hidMore').value = "0";
             UnityTypeObj.disabled='';
         }
    }
    catch(err){alert(err);}*/
}
    
    
function getPriceAndSize(obj)
{ 
    var CategoryGroupId=obj.options[obj.selectedIndex].value;
    var category=obj[obj.selectedIndex].text;
    var curTime = new Date();     
    if(CategoryGroupId != -1)
    {
       PageMethods.CategoryGroupPriceByCategoryGroupId(CategoryGroupId, curTime.toString(), onSuccessPriceInfo, onFailurePriceInfo, curTime.toString())
    }
    else
    {
       makePriceEmpty();
    }
}
function onSuccessPriceInfo(result, context, method)
{ 
    var CategoryPriceInfo = result;
    var CategoryPriceIndex = 1;
    var  FinalHTML = new String();
    var miniPriceList = document.getElementById("ctl00_ContentPlaceHolder1_ddlMinPrice");
    var maxPriceList = document.getElementById("ctl00_ContentPlaceHolder1_ddlMaxPrice");
    makePriceEmpty();
   
    if(CategoryPriceInfo != null)
    {
        if(CategoryPriceInfo.length > 0)
        {
            var optnMin = document.createElement("OPTION");
            var optnMax;
            
             optnMin.text = "Minimum";
             optnMin.value = "-1";
                
            miniPriceList.options.add(optnMin);
                
            for(CategoryPriceIndex = 0; CategoryPriceIndex < CategoryPriceInfo.length; CategoryPriceIndex++)
            {
                optnMin = document.createElement("OPTION");
                optnMax = document.createElement("OPTION");
                
                optnMin.text = CategoryPriceInfo[CategoryPriceIndex].Price;
                optnMin.value = CategoryPriceInfo[CategoryPriceIndex].CategoryGroupPriceID;
                
                optnMax.text = CategoryPriceInfo[CategoryPriceIndex].Price;
                optnMax.value = CategoryPriceInfo[CategoryPriceIndex].CategoryGroupPriceID;
                
                miniPriceList.options.add(optnMin);
                maxPriceList.options.add(optnMax);
            }
            
            optnMax = document.createElement("OPTION");
            
            optnMax.text = "Maximum";
            optnMax.value = "-1";
                
            maxPriceList.options.add(optnMax);
            
            miniPriceList.selectedIndex = 0;
            maxPriceList.selectedIndex = maxPriceList.options.length - 1;
            
               
        }
    }
    
}

function onFailurePriceInfo(result, context, method)
{
   makePriceEmpty();
}



function onSuccessSizeInfo(result, context, method)
{ 
    var CategorySizeInfo = result;
    var CategorySizeIndex = 1;
    var miniSizeList = document.getElementById("ctl00_ContentPlaceHolder1_minsize");
    var maxSizeList = document.getElementById("ctl00_ContentPlaceHolder1_maxsize");
    makeSizeEmpty();
    if(CategorySizeInfo != null)
    {
        if(CategorySizeInfo.length > 0)
        { 
             var optnMin = document.createElement("OPTION");
             var optnMax;
            
             optnMin.text = "Minimum";
             optnMin.value = "-1";
                
            miniSizeList.options.add(optnMin);
            
            for(CategorySizeIndex = 0; CategorySizeIndex < CategorySizeInfo.length; CategorySizeIndex++)
            {
                optnMin = document.createElement("OPTION");
                optnMax = document.createElement("OPTION");
                optnMin.text = CategorySizeInfo[CategorySizeIndex].Size;
                optnMin.value = CategorySizeInfo[CategorySizeIndex].CategoryGroupSizeID;
                
                optnMax.text = CategorySizeInfo[CategorySizeIndex].Size;
                optnMax.value = CategorySizeInfo[CategorySizeIndex].CategoryGroupSizeID;
                
                miniSizeList.options.add(optnMin);
                maxSizeList.options.add(optnMax);
            }
           
            optnMax = document.createElement("OPTION");
            
            optnMax.text = "Maximum";
            optnMax.value = "-1";
                
            maxSizeList.options.add(optnMax);
            
            miniSizeList.selectedIndex = 0;
            maxSizeList.selectedIndex = maxSizeList.options.length - 1;
        }
    }
    
}

function onFailureSizeInfo(result, context, method)
{
   makeSizeEmpty();
}

function makePriceEmpty()
{
    var miniPriceList = document.getElementById("ctl00_ContentPlaceHolder1_ddlMinPrice");
    var maxPriceList = document.getElementById("ctl00_ContentPlaceHolder1_ddlMaxPrice");
    var i;
    for (i = miniPriceList.length - 1; i>=0; i--)
    {
       miniPriceList.remove(i);
    }
    for (i = maxPriceList.length - 1; i>=0; i--)
    {
       maxPriceList.remove(i);
    }



}
function makeSizeEmpty()
{
    var miniSizeList = document.getElementById("ctl00_ContentPlaceHolder1_minsize");
    var maxSizeList = document.getElementById("ctl00_ContentPlaceHolder1_maxsize");
    var i;
    
    for (i = miniSizeList.length - 1; i>=0; i--)
      {
        miniSizeList.remove(i);
      }
    for (i = maxSizeList.length - 1; i>=0; i--)
    {
       maxSizeList.remove(i);
    }
}



function validate()
 {
  //debugger;
    var obj = document.getElementById('ctl00_ContentPlaceHolder1_ddlServiceType');
    var category  = document.getElementById('ctl00_ContentPlaceHolder1_ddlCategoryGroup').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlCategoryGroup').selectedIndex].text;
    
   /* if(obj.options[obj.selectedIndex].value == "-1")
    {
        alert("Please select \"I am looking for\"");
        return false;
    }
    
    obj = document.getElementById('ctl00_ContentPlaceHolder1_ddlCategoryGroup');
    if(obj.options[obj.selectedIndex].value == "-1")
    {
        alert("Please select \"Unit type\"");
        return false;
    }
     obj = document.getElementById('ctl00_ContentPlaceHolder1_cboRegion');


    if(obj.options[obj.selectedIndex].value == "-1")
    {
        alert("Please select \"Region\"");
        return false;
    }
       
                        
    if(parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').selectedIndex].value)!= "" && parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').selectedIndex].value)!= "" &&  parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').selectedIndex].value) > parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').selectedIndex].value))
    {
        alert("Minimum price cannot be greater than maximum price");
        return false;
    }*/
   
   if(obj.options[obj.selectedIndex].value != "-1")
   {
    if(document.getElementById("ctl00_ContentPlaceHolder1_ddlMinPrice").length>0 && document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').length>0)
     {
       if(document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').selectedIndex].value!= "-1" && document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').selectedIndex].value!= "-1")
       {
           if(parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').selectedIndex].value) > parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').selectedIndex].value))
            {
                alert("Minimum price cannot be greater than maximum price");
                return false;
            }
        }
        if(document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').selectedIndex].value != "-1")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMinPrice').value = document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMinPrice').selectedIndex].text;
        }
        else
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMinPrice').value = "";
        }
        if(document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').selectedIndex].value != "-1")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMaxPrice').value = document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').options[document.getElementById('ctl00_ContentPlaceHolder1_ddlMaxPrice').selectedIndex].text;
        }
        else
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMaxPrice').value = "";
        }
     }
   }  
    
    /*if(document.getElementById('ctl00_ContentPlaceHolder1_ddlCategoryGroup').value== "-1")
    {
        alert("Please Select Category");
        return false;
    }*/
    
  
   
    if(category.toLowerCase().indexOf("apartment") > -1 || category.toLowerCase().indexOf("residential") > -1 || category.toLowerCase().indexOf("villa") > -1)
     {
          /*if(parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_minRooms').options[document.getElementById('ctl00_ContentPlaceHolder1_minRooms').selectedIndex].value)!= -1 && parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_maxRooms').options[document.getElementById('ctl00_ContentPlaceHolder1_maxRooms').selectedIndex].value)!= -1 &&  parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_minRooms').options[document.getElementById('ctl00_ContentPlaceHolder1_minRooms').selectedIndex].value) > parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_maxRooms').options[document.getElementById('ctl00_ContentPlaceHolder1_maxRooms').selectedIndex].value))
            {
                alert("Minimum bed cannot be greater than maximum bed");
                return false;
            }*/
     }
     else
     {
           /*    if(parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_minsize').options[document.getElementById('ctl00_ContentPlaceHolder1_minsize').selectedIndex].value)!= -1 && parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_maxsize').options[document.getElementById('ctl00_ContentPlaceHolder1_maxsize').selectedIndex].value)!= -1 &&  parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_minsize').options[document.getElementById('ctl00_ContentPlaceHolder1_minsize').selectedIndex].value) > parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_maxsize').options[document.getElementById('ctl00_ContentPlaceHolder1_maxsize').selectedIndex].value))
            {
                alert("Minimum size cannot be greater than maximum size");
                return false;
            }
            
            if(document.getElementById('ctl00_ContentPlaceHolder1_minsize').options[document.getElementById('ctl00_ContentPlaceHolder1_minsize').selectedIndex].value != "-1")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMinSize').value = document.getElementById('ctl00_ContentPlaceHolder1_minsize').options[document.getElementById('ctl00_ContentPlaceHolder1_minsize').selectedIndex].text;
        }
        else
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMinSize').value = "";
        }
        
        if(document.getElementById('ctl00_ContentPlaceHolder1_maxsize').options[document.getElementById('ctl00_ContentPlaceHolder1_maxsize').selectedIndex].value != "-1")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMaxSize').value = document.getElementById('ctl00_ContentPlaceHolder1_maxsize').options[document.getElementById('ctl00_ContentPlaceHolder1_maxsize').selectedIndex].text;
        }
        else
        {
            document.getElementById('ctl00_ContentPlaceHolder1_hidMaxSize').value = "";
        }*/
     }
 
 
    
    
     return true;
}
             
function CompareDate(date1, date2)
{
            var dateToArray = date1.split("-");
            var dateFromArray = date2.split("-");
            
            var yearFrom = parseInt(dateFromArray[2]);
            var monthFrom = parseInt(dateFromArray[1]);
            var dateFrom = parseInt(dateFromArray[0]);
            
            var yearTo = parseInt(dateToArray[2]);
            var monthTo = parseInt(dateToArray[1]);
            var dateTo = parseInt(dateToArray[0]);
            
            if(yearFrom > yearTo)
            {
                return true;
            }
            else if(yearFrom < yearTo)
            {
                return false;
            }
            else
            {
                if(monthFrom > monthTo)
                {
                    return true;
                }
                else if(monthFrom < monthTo)
                {
                    return false;
                }
                else
                {
                     if(dateFrom > dateTo)
                    {
                        return true;
                    }
                    else if(dateFrom < dateTo)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }  
            }
            
			return dateTo;
}
 
 
 function submittfrm(type)
 {
        if(type == "keyword")
        {
            if(document.getElementById("ctl00_ContentPlaceHolder1_txtSearchKeyword").value == " e.g. 29 Boulevard, T2, Downtown Burj Dubai" || strTrim(document.getElementById("ctl00_ContentPlaceHolder1_txtSearchKeyword").value) == "" )
            {
                //alert("Please enter a keyword");
                //return false;
                return true;
            }
            else
            { 
                var strs = document.getElementById("ctl00_ContentPlaceHolder1_txtSearchKeyword").value.split(',');
                var i = 0;
                var haveVal = false;
                for(i=0;i<strs.length;i++)
                {
                     if(strTrim(strs[i])!="")
                     {
                         haveVal = true;
                     }
                }   
                if(!haveVal)
                {
                    alert("Input not valid");
                }                         
                return haveVal;
            }
        }
        else
        {
            if(document.getElementById("ctl00_ContentPlaceHolder1_txtSearchRef").value == " e.g.AP 5678, AP5678, or 5678" || strTrim(document.getElementById("ctl00_ContentPlaceHolder1_txtSearchRef").value) == "")
            {
                //alert("Please enter a reference number");
                //return false;
                return true;
            }
            else 
            {
                return true;
            }
        }
        return false;                    
 }
 function strTrim(value)
 {
   value =  value.replace(/^\s+/,"");
    value =  value.replace(/\s+$/,"");
    return value;
 }
 
 function autoHide(ctrl, isfocus)
{
    
    if(ctrl.id == "ctl00_ContentPlaceHolder1_txtSearchKeyword")
    {
        if(isfocus == true)
        {
            ctrl.value = '';
        }
        else if(ctrl.value == '')
        {
            ctrl.value = ' e.g. 29 Boulevard, T2, Downtown Burj Dubai';
        }
    }
    else if(ctrl.id == "ctl00_ContentPlaceHolder1_txtSearchRef")
    {
        
        if(isfocus == true)
        {
             ctrl.value = '';
        }
        else if(ctrl.value == '')
        {
            ctrl.value= ' e.g.CE10000050, or 0050';
        }
    }
}
//**Cayman.Js
function OpenMoreSearchOptions(obj)
{
    var MoreSearchOptions=document.getElementById("divMoreSearchOptions");
    
    if(MoreSearchOptions.style.display!='')
    {
        MoreSearchOptions.style.display='';
        document.getElementById("imgMoreSearch1").style.display = 'none';
        document.getElementById("imgMoreSearch2").style.display = '';
        document.getElementById('ctl00_ContentPlaceHolder1_hidMore').value = "1";
        obj.innerHTML="Hide more search options";
    }
    else
    {
         MoreSearchOptions.style.display='none';
         document.getElementById("imgMoreSearch1").style.display = '';
        document.getElementById("imgMoreSearch2").style.display = 'none';
         document.getElementById('ctl00_ContentPlaceHolder1_hidMore').value = "0";
         obj.innerHTML="Show more search options";
    } 

}