﻿
// *** HTML element functions ***

function populateDropdown(select, data, firstItemText, disabledItemText) {
    select.empty();

    if (data.Items.length > 0) {

        $(select).removeAttr("disabled");

        select.
            append($("<option></option>").
            attr("value", "").
            text(firstItemText));

        $.each(data.Items,
					function (i, Item) {

					    select.
                          append($("<option></option>").
                          attr("value", Item.Value).
                          text(Item.Name));
					});
    }
    else {

        if (disabledItemText == null) {
            select.hide();
        }
        else {
            select.
            append($("<option></option>").
            attr("value", "").
            text(disabledItemText));

            select.attr("disabled", "disabled");
        }

    }
}


// *** General helpers ***
function showLoading() {
    $('#divLoading').show('fast');
}

function hideLoading() {
    $('#divLoading').hide('fast');
}

jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
} 

// *** jQUERY UI extension methods ***
// Script to initialise for each page
function initialiseDatePickers() {
    $(".datepicker").datepicker({ dateFormat: 'dd M yy' });
}





// *** Drop Down Menus ***
function makeDropDownMenus() {
    
        $('.nav li').hover(
		        function () {
		            //show its submenu
		            $('ul', this).slideDown(100);

		        },
		        function () {
		            //hide its submenu
		            $('ul', this).slideUp(100);
		        }
	        );

		        $('.nav li').click(

                function () {
                    //hide its submenu
                    $('ul', this).slideUp(100);
                }

                );
   
    }
