function clearFavs() {
    var myAjax = new Ajax.Request('includes/clearfavorites.php', {
        method: 'get',
        onSuccess: function() {
            window.location = location.href;
        }
    });
}
version = 0;
if (navigator.appVersion.indexOf("MSIE") != -1) {
    temp = navigator.appVersion.split("MSIE");
    version = parseFloat(temp[1]);
}
function showLocations() {
    closeTypes();
    $('locations').style.visibility = 'visible';
    $('locations').focus();
    if (version <= 6) {
        $('propselect').style.visibility = 'hidden';
        $('pricerange1').style.visibility = 'hidden';
        $('pricerange2').style.visibility = 'hidden';
    }
}
function closeLocations() {
    $('locations').style.visibility = 'hidden';
    if (version <= 6) {
        $('propselect').style.visibility = 'visible';
        $('pricerange1').style.visibility = 'visible';
        $('pricerange2').style.visibility = 'visible';
    }
}
function showTypes() {
    closeLocations();
    $('types').style.visibility = 'visible';
    $('types').focus();
    if (version <= 6) {
        $('pricerange1').style.visibility = 'hidden';
        $('pricerange2').style.visibility = 'hidden';
    }
}
function closeTypes() {
    $('types').style.visibility = 'hidden';
    if (version <= 6) {
        $('locselect').style.visibility = 'visible';
        $('pricerange1').style.visibility = 'visible';
        $('pricerange2').style.visibility = 'visible';
    }
}
Array.prototype.remove = function(from, to) {
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from: from;
    return this.push.apply(this, rest);
};
locationId = new Array();
propertytypeId = new Array();
function addToLocations(x) {
    if (x.checked) {
        locationId.push(x.value);
    } else {
        locationId.remove(locationId.indexOf(x.value));
    }
    $('locationId').value = locationId;
    if (locationId.length > 1) {
        $('locselect').options[0].text = locationId.length + ' Locations Selected';
    } else {
        $('locselect').options[0].text = locationId.length + ' Location Selected';
    }
    if (!locationId.length) {
        $('locselect').options[0].text = "Any Location";
        $('locationId').value = -1;
    }
}
function addToTypes(x) {
    if (x.checked) {
        propertytypeId.push(x.value);
    } else {
        propertytypeId.remove(propertytypeId.indexOf(x.value));
    }
    $('propertytypeId').value = propertytypeId;
    if (propertytypeId.length > 1) {
        $('propselect').options[0].text = propertytypeId.length + ' Property Types Selected';
    } else {
        $('propselect').options[0].text = propertytypeId.length + ' Property Type Selected';
    }
    if (!propertytypeId.length) {
        $('propselect').options[0].text = "Any Type";
        $('propertytypeId').value = -1
    }
}
function isblank(s) {
    for (var i = 0; i < s.value.length; i++) {
        var c = s.value.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}
function checkHomeSearch(obj) {
    if ((obj.locationId.value == -1) && (obj.propertytypeId.value == -1) && (obj.pricerange1.selectedIndex == 0) && (obj.pricerange2.selectedIndex == 0)) {
        alert("Please choose a Location, Property type or Price range.");
        return false;
    }
    return true;
}
function checkAdvancedSearch(obj) {
    if (isblank(obj.ref)) {
        if ((obj.locationId.value == -1) && (obj.propertytypeId.value == -1) && (obj.pricerange1.selectedIndex == 0) && (obj.pricerange2.selectedIndex == 0)) {
            alert("Please choose a Location, Property type or Price range.");
            return false;
        }
    }
    return true;
}
function setTown(id) {
    if (id == '') {
        alert('There are no available properties in this location');
    } else {
        var checkboxes = $('locations').getElementsByTagName("input");
        for (var i = 0; i < checkboxes.length; i++) {
            if (checkboxes[i].value == id) {
                showLocations();
                checkboxes[i].checked = true;
                checkboxes[i].focus();
                addToLocations(checkboxes[i]);
            }
        }
    }
}