/**

* Selecting gift voucher radio buttons

**/

$(document).ready(function() {


// options for gift vouchers page

    if ($("input#deliveryMethodEmail:checked").attr("value") == 'email'){
        $('.gvemail').show();
        $('.gvpost').hide();
    } else {
        $('.gvemail').hide();
        $('.gvpost').show();
    };
    $("input#deliveryMethodEmail").click(function(){
        if ($("input#deliveryMethodEmail").attr("checked") != true){
            $('.gvemail').show();
            $('.gvpost').hide();
        }
    });
    $("input#deliveryMethodPost").click(function(){
        if ($("input#deliveryMethodPost").attr("checked") != true){
            $('.gvemail').hide();
            $('.gvpost').show();
            $('.mediumInput').getSetSSValue("Please select");
        }
    });
});



/* sorting options in select box */



//get the select

var $dd = $('#select-id');

if ($dd.length > 0) { // make sure we found the select we were looking for



    // save the selected value

    var selectedVal = $dd.val();



    // get the options and loop through them

    var $options = $('option', $dd);

    var arrVals = [];

    $options.each(function(){

        // push each option value and text into an array

        arrVals.push({

            val: $(this).val(),

            text: $(this).text()

        });

    });



    // sort the array by the value (change val to text to sort by text instead)

    arrVals.sort(function(a, b){

        if(a.val>b.val){

            return 1;

        }

        else if (a.val==b.val){

            return 0;

        }

        else {

            return -1;

        }

    });



    // loop through the sorted array and set the text/values to the options

    for (var i = 0, l = arrVals.length; i < l; i++) {

        $($options[i]).val(arrVals[i].val).text(arrVals[i].text);

    }



    // set the selected value back

    $dd.val(selectedVal);

}






