// SelectSort.js

wCLASS['SelectSort'] = {tag:'SELECT'};
function SelectSort(obj, method)
{
    this.base    = obj;
    this.sortMethod  = (method == null)? 'alpha': method;
    this.sortOptions = _sortOptions;
    this.sortOptions();
}
function _sortOptions()
{
    var a = new Array;
    var b = this.base.options;
    for(var i = 0; i < this.base.length; i++)
        a[i] = new Option(b[i].text, b[i].value);

    a.sort( (this.sortMethod == 'alpha')? _alphaSort: _numSort );               
    for(var j = 0; j < a.length; j++)
        b[j] = new Option(a[j].text, a[j].value);    
}                        
function _alphaSort(x, y)
{                
    return (x.text > y.text)? 1: -1;
}
function _numSort(r, t)
{            
    return parseInt(r.text) - parseInt(t.text);
}