﻿function GetHeight() {
    jQuery(document).ready(function() {


        var mainContentHeight = jQuery("#mainContent").height();
        var sideColumnHeight = jQuery("#sideColumn").height();

        var mainContentCumulativeChildHeight = 0;
        jQuery("#mainContent").children().each(function(index, element) { mainContentCumulativeChildHeight += jQuery(element).height(); });


        if (mainContentHeight > sideColumnHeight) {
            jQuery("#SideSpots").css({ marginTop: mainContentHeight - sideColumnHeight });
        }

        if (mainContentHeight > mainContentCumulativeChildHeight) {
            jQuery("#bottomImage").css({ marginTop: mainContentHeight - mainContentCumulativeChildHeight });
        }

        if (jQuery(".col-1").length > 0) { 
            jQuery(".col-1, .col-2, .col-3").equalizeCols();
        }
    });

    jQuery("#greyBox").css({ height: jQuery("#greyBox2").height() });
}

function toggle(element) {
    if (document.getElementById(element).style.display == "none") {
        document.getElementById(element).style.display = "block";
    }
    else {
        document.getElementById(element).style.display = "none";
    }
}

function createPeopleSearchForm(specialisationId, nameId, searchId, resetId, baseUrl) {

    var specialisationDropdown = jQuery("#" + specialisationId);
    var nameTextbox = jQuery("#" + nameId);
    var searchButton = jQuery("#" + searchId);
    var resetButton = jQuery("#" + resetId);

    var $specialisationDropdown = specialisationDropdown.selectbox({ debug: true });

    //var $specialisationDropdown = jQuery(specialisationDropdown);
    //var $officeDropdown = jQuery(officeDropdown);


    searchButton.bind("click", function(e) {
        var qs = "?";
        var specialisation = specialisationDropdown[0].value;
        var name = nameTextbox[0].value;
        if (specialisation) {
            if (qs != "?") qs += "&";
            qs += "specialisation=" + specialisation;
        }
        if (name) {
            if (qs != "?") qs += "&";
            qs += "name=" + name;
        }
        if (qs != "?") qs += "&";
        qs += "search=true";
        var url = baseUrl + qs;
        window.location = url;

    });

    resetButton.bind("click", function(e) {
        specialisationDropdown[0].value = "";
        nameTextbox[0].value = "";

        $specialisationDropdown.get(0).extended.reset();
    });

    // make it so enter on the textbox is same as clicking search button
    nameTextbox.bind("keydown", function(event) {
        switch (event.keyCode) {
            case 13: // return
                event.preventDefault(); // seems not working in mac !
                searchButton.trigger("click");
                break;
        }
    });
    
}

function createDdl(control) {

    var controlDropdown = jQuery("#" + control);
    var $controlDropdown = controlDropdown.selectbox({ debug: true });
}



function createSearchForm(textfield, button) {


    button.bind("click",
        function(e) {
            return search(textfield);
        }
    );

    textfield.bind("focus", function(e) {
        var keyword = textfield[0].value;
        if (keyword == "Search") textfield[0].value = "";
    });
 
    textfield.bind("blur", function(e) {
        var keyword = textfield[0].value;
        if (keyword == "") textfield[0].value = "Search";
    });

    textfield.bind("keydown", function(e) {
        if (e.keyCode == 13) {
            return search(textfield);
        }
    });

}

function search(textfield) {
    var keyword = textfield[0].value;
    if (keyword != "Search" && keyword != null && keyword != "") {
        window.location = '/search.aspx?search=' + keyword;
        return false;
    }
}


