var _roomSelectionID = null;
var _housingSelectionID = null;
var _landlordSelection = null;

function checkBedRoom(elementID) {
    var e = document.getElementById(elementID);
    
    if (_landlordSelection == null){
        if (e.checked) {
            if (_roomSelectionID != null && _roomSelectionID != e) {
                document.getElementById(_roomSelectionID.id).checked = false;
                _roomSelectionID = e;
                //document.all('SearchCriteria_Rooms').value = e.value;
                var updSearchCriteria = document.getElementById('SearchCriteria_Rooms');
                updSearchCriteria.setAttribute('value', e.value);
            }
            if (_roomSelectionID == null) {
                _roomSelectionID = e;
                //document.all('SearchCriteria_Rooms').value = e.value;
                var updSearchCriteria = document.getElementById('SearchCriteria_Rooms');
                updSearchCriteria.setAttribute('value', e.value);               
            }
        }
        else if (_roomSelectionID == e) {
                _roomSelectionID = null;
                //document.all('SearchCriteria_Rooms').value = '';
                var updSearchCriteria = document.getElementById('SearchCriteria_Rooms');
                updSearchCriteria.setAttribute('value', '');
            }
    }
    else if (e.checked) {
            document.getElementById(e.id).checked = false;
            showError('E001 - Room selection is not valid in combination with a Landlord search.');
        }
            
}

function checkHousing(elementID) {
    var e = document.getElementById(elementID);

    if (_landlordSelection == null || e.id == 'CheckSupported') {
        if (e.checked) {
            if (_housingSelectionID != null && _housingSelectionID != e) {
                document.getElementById(_housingSelectionID.id).checked = false;
                _housingSelectionID = e;
                //document.all('SearchCriteria_Housing').value = e.value;
                var updSearchCriteria = document.getElementById('SearchCriteria_Housing');
                updSearchCriteria.setAttribute('value', e.value);
            }
            if (_housingSelectionID == null) {
                _housingSelectionID = e;
                //document.all('SearchCriteria_Housing').value = e.value;
                var updSearchCriteria = document.getElementById('SearchCriteria_Housing');
                updSearchCriteria.setAttribute('value', e.value);               
            }
        }
        else if (_housingSelectionID == e) {
                _housingSelectionID = null;
                //document.all('SearchCriteria_Housing').value = '';
                var updSearchCriteria = document.getElementById('SearchCriteria_Housing');
                updSearchCriteria.setAttribute('value', '');
             }
    }
    else if (e.checked && e.id == 'CheckShared') {
            document.getElementById(e.id).checked = false;
            showError('E002 - Housing selection is not valid in combination with a Landlord search.');
         }
}

function checkLandlord() {
    if (_roomSelectionID != null && _housingSelectionID != null) {
        showError('E003 - Landlord search is not valid in combination with Room and Housing selection.');
        document.getElementById(_roomSelectionID.id).focus();
    }
    else if (_roomSelectionID != null) {
            showError('E004 - Landlord search is not valid in combination with Room selection.');
            document.getElementById(_roomSelectionID.id).focus();
        }
        else if (_housingSelectionID != null && _housingSelectionID.id != 'CheckSupported') {   
            showError('E005 - Landlord search is not valid in combination with Housing selection.');
            document.getElementById(_housingSelectionID.id).focus();            
    }
}

function setLandlord(elementValue) {
    if (elementValue != '') {
        _landlordSelection = true;
    }
    else _landlordSelection = null;
}

function showError(p_Error) {
    if (p_Error.valueOf != '') {
        alert(p_Error);
    }
}
