﻿
var searchType = "";
var searchLeaseSale = "";

function AdvancedSearchSwitchLeaseSale(elem) {
    searchLeaseSale = elem.getAttribute("value");
    if (searchType == "") {
        searchType = document.getElementById("radio_PropertyCategoryCommercial").checked ? "Commercial" : "Residential";
    }
    AdvancedSearchSwitchTypes();
}

function AdvancedSearchSwitchType(elem) {
    searchType = elem.getAttribute("value");
    if (searchLeaseSale == "") {
        searchLeaseSale = document.getElementById("radio_ContractTypeLease").checked ? "Lease" : "Sale";
    }
    AdvancedSearchSwitchTypes();
}


function HomeSwitchLeaseSale(elem) {
    searchLeaseSale = elem.getAttribute("value");
    HomeSwitchTypes();
}

function HomeSwitchType(elem) {
    searchType = elem.getAttribute("value");
    HomeSwitchTypes();
}

function menuMouseOver(elem) {
    if (elem.className == "menuItem") {
        $("#" + elem.id + " img").animate({ "opacity": "1" }, 200);
    }
}

function pictureBoxMouseOver(elemId, elemId2) {
    if (document.getElementById(elemId).getAttribute("eventdone") == undefined) {
        $('#' + elemId).mouseenter(function () {
            pictureFrameMouseOver(elemId);
        });
        $('#' + elemId).mouseleave(function () {
            pictureFrameMouseOut(elemId);
        });
        pictureFrameMouseOver(elemId);
        document.getElementById(elemId).setAttribute("eventdone", "true");
    }
}

function menuMouseOut(elem) {
    if (elem.className == "menuItem") {
        $("#" + elem.id + " img").animate({ "opacity": "0" }, 200);
    }
}

function pictureFrameMouseOver(elemId) {
    var elem = document.getElementById(elemId);
    $("#" + elem.id + " .pictureBoxImage").animate({ "opacity": "0.5" }, 200);
}

function pictureFrameMouseOut(elemId) {
    var elem = document.getElementById(elemId);
    $("#" + elem.id + " .pictureBoxImage").animate({ "opacity": "1.0" }, 200);
}

function HomeSwitchTypes() {
    var elem = document.getElementById("homePriceAnnotations");
    if (searchLeaseSale == "Lease") {
        if (searchType == "Commercial") {
            elem.innerHTML = "(yearly)";
        } else {
            elem.innerHTML = "(monthly)";
        }
    } else {
        elem.innerHTML = "";
    }
    if (searchType == "Commercial") {
        document.getElementById("propertyTypeCommercial").style.display = "";
        document.getElementById("propertyTypeResidential").style.display = "none";
    } else {
        document.getElementById("propertyTypeCommercial").style.display = "none";
        document.getElementById("propertyTypeResidential").style.display = "";
    }
}

function viewOpenGallery() {
    $("#viewOpenGalleryA1").trigger('click');
}


function sendToFriend() {
    $.fx.speeds._default = 800;
    $("#sendToFriend").dialog({
        modal: true,
        resizable: false,
        show: "fade",
        hide: "fade",
        width: 'auto',
        title: 'Send to Friend'
    });
    AjaxUnloading();
}

function sendEnquiry() {
    $.fx.speeds._default = 800;
    $("#sendToFriend").dialog({
        modal: true,
        resizable: false,
        show: "fade",
        hide: "fade",
        width: 950,
        title: 'Send Enquiry'
    });
    AjaxUnloading();
}

function AdvancedSearchSwitchTypes() {
    if (searchType == "Commercial") {
        document.getElementById("advancedSearchInternalSpace").style.display = "";
        document.getElementById("advancedSearchMinBedrooms").style.display = "none";
    } else {
        document.getElementById("advancedSearchInternalSpace").style.display = "none";
        document.getElementById("advancedSearchMinBedrooms").style.display = "";
    }
    var elem = document.getElementById("advancedSearchPriceAnnotations");
    if (searchLeaseSale == "Lease") {
        if (searchType == "Commercial") {
            elem.innerHTML = "(yearly)";
        } else {
            elem.innerHTML = "(monthly)";
        }
    } else {
        elem.innerHTML = "";
    }
    if (searchType == "Commercial") {
        document.getElementById("propertyTypeCommercial").style.display = "";
        document.getElementById("propertyTypeResidential").style.display = "none";
    } else {
        document.getElementById("propertyTypeCommercial").style.display = "none";
        document.getElementById("propertyTypeResidential").style.display = "";
    }
}


function AjaxLoading(elem) {
    try {
        document.getElementById(elem).style.opacity = "0.5";
        document.getElementById(elem).style.filter = "alpha(opacity = 50)";
    } catch (ex) { }
    $("#ajaxLoading").animate({ "top": "0px" }, "slow");
}


function AjaxUnloading(elem) {
    try {
        document.getElementById(elem).style.opacity = "1";
        document.getElementById(elem).style.filter = null;
    } catch (ex) { }
    $("#ajaxLoading").animate({ "top": "-25px" }, "slow");
    searchPage_Scroll();
    setTimeout(function () { searchPage_Scroll(); }, 10);
    setTimeout(function () { searchPage_Scroll(); }, 50);
    setTimeout(function () { searchPage_Scroll(); }, 150);
}

function AdvancedSearchLoaded(elem) {
    $("#searchOptionsPanel").animate({ "height": "0px" }, 400);
    $("#searchBarToolTip").animate({ "opacity": "1" }, 100);
    $("#searchBarToolTip").effect("shake", 300);
    document.getElementById("searchExpand").className = "searchExpandButton";
    document.getElementById("menuContact").className = "menuItem";
    document.getElementById("menuSearch").className = "menuItemSelected";
    AjaxUnloading(elem);
    searchPanelOpen = false;
}

function SanitizeCurrency(elem) {
    var num = new NumberFormat();
    num.setInputDecimal('.');
    num.setNumber(elem.value);
    num.setPlaces('0', false);
    num.setCurrencyValue('$');
    num.setCurrency(false);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    num.setNegativeFormat(num.LEFT_DASH);
    num.setNegativeRed(false);
    num.setSeparators(true, ',', ',');
    var currency = num.toFormatted();
    if (elem.value != currency) {
        elem.value = currency;
    }
}

function SanitizeNumberDecimal(elem) {
    var num = new NumberFormat();
    num.setInputDecimal('.');
    num.setNumber(elem.value);
    num.setPlaces('0', false);
    num.setCurrencyValue('$');
    num.setCurrency(false);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    num.setNegativeFormat(num.LEFT_DASH);
    num.setNegativeRed(false);
    num.setSeparators(false, ',', ',');
    elem.value = num.toFormatted();

}

var searchPanelOpen = null;
function ExpandSearchPanel() {
    $("#searchBarToolTip").animate({ "opacity": "0" }, 200);
    if (searchPanelOpen == null) {
        searchPanelOpen = (document.getElementById("searchExpand").className == "searchUnExpandButton");
    }
    document.getElementById("searchResultsContainer").style.display = "";
    if (searchPanelOpen) {
        $("#searchOptionsPanel").animate({ "height": "0px" }, 400);
        document.getElementById("searchExpand").className = "searchExpandButton";
        searchPanelOpen = false;
    } else {
        $("#searchOptionsPanel").animate({ "height": "249px" }, 400);
        document.getElementById("searchExpand").className = "searchUnExpandButton";
        searchPanelOpen = true;
    }
}

function Component_CheckBox_onChange(elem) {
    var compElem = document.getElementById("custom" + elem.id);
    if (compElem.getAttribute("checked") == "true") {
        elem.value = "false";
        compElem.setAttribute("checked", "false");
        compElem.className = "checkboxUnchecked";
    } else {
        elem.value = "true";
        compElem.setAttribute("checked", "true");
        compElem.className = "checkboxChecked";
    }
}


function Component_CheckBox(elem, compId) {
    var compElem = document.getElementById(compId);
    if (elem.getAttribute("checked") == "true") {
        compElem.checked = false;
        compElem.value = "false";
        elem.setAttribute("checked", "false");
        elem.className = "checkboxUnchecked";
    } else {
        compElem.checked = true;
        compElem.value = "true";
        elem.setAttribute("checked", "true");
        elem.className = "checkboxChecked";
    }
}

function Component_RadioButton_onChange(elem, groupName) {
    var groupElems = $(".radio_" + groupName);
    for (i = 0; i < groupElems.length; i++) {
        var tmpElem = document.getElementById("customradio_" + groupName + groupElems[i].value);
        tmpElem.className = "radiobuttonUnchecked";
        tmpElem.setAttribute("checked", "false");
    }
    var compElem = document.getElementById("custom" + elem.id);
    compElem.setAttribute("value", elem.value);
    compElem.setAttribute("checked", "true");
    compElem.className = "radiobuttonChecked";
}



function Component_RadioButton(elem, groupName, compId) {
    var groupElems = $(".radio_" + groupName);
    for (i = 0; i < groupElems.length; i++) {
        var tmpElem = document.getElementById("customradio_" + groupName + groupElems[i].value);
        tmpElem.className = "radiobuttonUnchecked";
        tmpElem.setAttribute("checked", "false");
    }
    var compElem = document.getElementById(compId);
    compElem.checked = true;
    elem.setAttribute("value", compElem.value);
    elem.setAttribute("checked", "true");
    elem.className = "radiobuttonChecked";
}



function activateSearchStaticBar(doShake) {
    window.onscroll = function () {
        searchPage_Scroll();
    }
    if (doShake) {
        $(window).load(function () {
            $("#searchBarToolTip").effect("shake", 300);
        });
    }
}

function searchPage_Scroll() {
    var elemPlaceholder = $("#searchBarPlaceholder");
    var elem = document.getElementById("searchBar");
    if (elemPlaceholder.position().top <= ($(window).scrollTop())) {
        elem.style.top = 0;
        elem.style.position = "fixed";
        elem.style.marginTop = "0px";
    } else {
        elem.style.top = null;
        elem.style.position = "relative";
        elem.style.marginTop = "-45px";
    }

}

function submitForm(elemId) {
    document.getElementById(elemId).click();
}

function resultsChangePage() {
    AjaxLoading('searchResultsContainer');
    var elemPlaceholder = $("#searchBarPlaceholder");
    $('html, body').animate({ scrollTop: elemPlaceholder.position().top + 5 }, 400);

}



function customUploaderRemove_onClick(elem) {
    document.getElementById(elem.id + "_span").innerHTML = "";
}

function customUploaderAdd_onClick(elem) {
    var rootElem = elem.parentNode;
    rootElem.setAttribute("count", rootElem.getAttribute("count") + 1);
    var span = document.createElement("div");
    span.id = rootElem.id + rootElem.getAttribute("count") + "_span";
    var fileinput = document.createElement("input");
    fileinput.type = "file";
    fileinput.setAttribute("multiple", "multiple");
    fileinput.name = rootElem.getAttribute("elemname");
    fileinput.setAttribute("elemname", rootElem.id + rootElem.getAttribute("count"));
    span.appendChild(fileinput);

    var removebutton = document.createElement("input");
    removebutton.type = "button";
    removebutton.value = "Remove";
    removebutton.setAttribute("onclick", "customUploaderRemove_onClick(this)");
    removebutton.name = rootElem.getAttribute("elemname");
    removebutton.id = rootElem.id + rootElem.getAttribute("count");
    span.appendChild(removebutton);
    rootElem.insertBefore(span, elem);
}

function customUploaderActivate_onClick(elem) {
    if (true) {
        var rootelem = elem.parentNode.parentNode;
        document.getElementById(elem.getAttribute("elemname")).style.display = "";
        document.getElementById(rootelem.id + "_add").style.display = "";
    }
}

$(document).ready(function () {
    if (document.getElementById("s3slider") != undefined) {
        $('#s3slider').s3Slider({
            timeOut: 4000
        });
    }
});

function closePopup() {
}
