
function sortAllDropDownListByText() {
    // Loop for each select element on the page.
    $j("select").each(function() {
    	if($j(this).attr('class')=="unsort")
    		return;
        // Keep track of the selected option.
        var selectedValue = $j(this).val();
 
        // Sort all the options by text. I could easily sort these by val.
        $j(this).html($j("option", $j(this)).sort(function(a, b) {
            return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
        }));
 
        // Select one option.
        $j(this).val(selectedValue);
    });
}

function sortSpecificDropDownListByText(id) {
    // Loop for each select element on the page.
   
        // Keep track of the selected option.
        var selectedValue = $j("#"+id).val();
 
        // Sort all the options by text. I could easily sort these by val.
        $j("#"+id).html($j("option", $j("#"+id)).sort(function(a, b) {
            return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
        }));
 
        // Select one option.
        $j("#"+id).val(selectedValue);
}

$j(document).ready(sortAllDropDownListByText);

