﻿// JScript File
    //alert('1');
function ShowHideControls()
{
    var Label = document.getElementById('LblBedrooms');
    var minBr = document.getElementById('DdlMinBR');
    var maxBr = document.getElementById('DdlMaxBR');
    
    var Label1= document.getElementById('LblBathrooms');
    var minBt = document.getElementById('DdlMinBath');
    var maxBt = document.getElementById('DdlMaxBath');
    
    
    var ddlProp = document.getElementById('DdlAPropertyType');
    var propType = ddlProp.value;
    if (propType == "1" || propType == "2" || propType == "3" || propType == "5" || propType == "6" || propType == "8"  || propType == "24")
	{
	    Label.style.display = '';
	    minBr.style.display = '';
	    maxBr.style.display = '';
	    Label1.style.display = '';
	    minBt.style.display = '';
	    maxBt.style.display = '';
	}
	else
	{
	    Label.style.display = 'none';
	    minBr.style.display = 'none';
	    maxBr.style.display = 'none';
	    Label1.style.display = 'none';
	    minBt.style.display = 'none';
	    maxBt.style.display = 'none';
	}
    return false;
}

function ValidateSelections()
{
var ddlRadCom = document.getElementById('DdlRadiusFromCom');
var ddlRadLoc = document.getElementById('DdlRadiusFromLoc');
var ddlRadSec = document.getElementById('DdlRadiusFromSec');
/*
var lblRadCom = document.getElementById('LblRadiusFromCom');
var lblRadLoc = document.getElementById('LblRadiusFromLoc');
var lblRadSec = document.getElementById('LblRadiusFromSec');
*/


var ddlradcomIndex = ddlRadCom.selectedIndex;
var a = CountSelections('DdlACommunity', ddlradcomIndex);
if(a == false)
    return false;
    
var ddlradlocIndex = ddlRadLoc.selectedIndex;
a = CountSelections('DdlALocality', ddlradlocIndex);
if(a == false)
    return false;


var ddlradsecIndex = ddlRadSec.selectedIndex;
a = CountSelections('DdlASector', ddlradsecIndex);
if(a == false)
    return false;
       

return true;
}

function CountSelections(id, indx)
{
var limit = 5
var selItems = 0;
        var control = document.getElementById(id);
            
        for(var iCount = 1; iCount < control.length ; iCount++) // 0 index has 'Select'
        {  
            if(control[iCount].selected == true)
            {   
                selItems++;
                if(selItems > limit)
                {
                    /* Deselect all items till end  */
                    for(  iCount = 1  ; iCount < control.length ; iCount++)
                        control[iCount].selected = false;
                    break;
                    //alert('Maximum items that can be selected are : ' + limit);
                    //return false;            
                }
            }
        }
        
        if(selItems > 1 && indx > 0)
        {
            alert('Please select one option if specifying the radius.');
            return false;
        }
        return true;       
    

}
