﻿/// <reference path="~/Scripts/jquery-1.4.2.js"/>
/// <reference name="MicrosoftAjax.js"/>
/// <reference path="~/Scripts/MicrosoftAjax.debug.js"/>
/// <reference path="~/Scripts/MicrosoftMvcAjax.debug.js"/>
/// <reference path="~/Scripts/MicrosoftMvcJQueryValidation.js"/>
/// <reference path="~/Scripts/jquery.helper.js"/>
/// <reference path="~/Scripts/jquery.history.js"/>
/// <reference path="~/Scripts/jquery.selectbox.js"/>
/// <reference path="~/scripts/jquery.scrollTo.js"/>
/// <reference path="~/Scripts/Helper.js"/>
/// <reference path="~/Scripts/bfdc.js"/>
/// <reference path="~/Scripts/jquery.js"/>

/// Have moved loadJsonOptions, addOption to jquery.js


/*
* Extended helper methods for select-input-fields
* Author D. Hampton
*
* Edited By: Matt Peters
*/

jQuery.fn.selectedVal = function () {
    ///<summary>Returns the hidden value field of the current selection</summary>

    return $(this).selectedOption().val();
}

jQuery.fn.isChecked = function () {
    ///<summary>For check boxes.</summary>

    return $(this).attr('checked');
}

jQuery.fn.selectedOption = function () {
    ///<summary>Returns the entire selected option</summary>

    return $("#" + $(this).attr("id") + " :selected");
}

jQuery.fn.selectedText = function () {
    ///<summary>Returns the visible value field of the current selection</summary>

    return $(this).selectedOption().text();
}

jQuery.fn.getOptions = function () {
    ///<summary>Returns an array of all available options</summary>

    return $("#" + $(this).attr("id") + " option");
}

jQuery.fn.setSelected = function (value) {
    ///<summary>Will set the option who's value is passed in to this function as selected. All other options are not selected.</summary>
    ///<param name="value" type="String">value of option to select</param>

    options = $(this).getOptions();
    $.each(options, function () {
        if ($(this).val() == value) $(this).attr("selected", "selected");
        else $(this).attr("selected", false);
    });
}

jQuery.fn.selectAll = function () {
    ///<summary>As it says on the tin...</summary>

    $("#" + $(this).attr("id") + " *").attr("selected", "selected");
}

jQuery.fn.clear = function () {
    ///<summary>Empties the select box of all options</summary>

    $("#" + $(this).attr("id")).children().remove();
}

jQuery.fn.moveSelectedTo = function (receiver) {
    ///<summary>Will move the selected item to the receiver, removing it from the initial select box.</summary>
    ///<param name="receiver" type="String">the select box to recive the selected item</param>

    id = "#" + $(this).attr("id");
    o = $(id).selectedOption();
    $(o).remove();
    o.appendTo(receiver);
}