// for sorting lists
function getTextValue(el) {
    var i;
    var s;
    // Find and concatenate the values of all text nodes contained within the
    // element.
    s = "";
    try{
	for (i = 0; i < el.childNodes.length; i++) {
	    if (el.childNodes[i].nodeType == document.TEXT_NODE)
		s += el.childNodes[i].nodeValue;
	    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
		    el.childNodes[i].tagName == "BR")
		s += " ";
	    else
		// Use recursion to get text within sub-elements.
		s += getTextValue(el.childNodes[i]);
	}
    }catch(err){}
    return $.trim(s);
}

function getSpanWithClass(el, className)
{
    var s;
    // we want the string value of the span subelement 
    // having the given class attribute
    s = "";
    try {
	var i;
	for (i = 0; i < el.childNodes.length; i++) {
	    if (el.childNodes[i].nodeType == document.ELEMENT_NODE) {
		if (el.childNodes[i].className == className) {
		    return getTextValue(el.childNodes[i]);
		} else {
		    s = getSpanWithClass(el.childNodes[i], className);
		    if (s != "") return s;
		}
	    }
	}
    } catch(err){}
    return s;
}

function sortList(myid, field) {
    var A = $.makeArray($('#' + myid + ' li').remove());
    A.sort(function(a, b){
	    var aval = getSpanWithClass(a, field);
	    var bval = getSpanWithClass(b, field);
	    if (aval == bval) return 0;
	    if (aval < bval) return 1;
	    return -1;
	    });

    $('#' + myid).append(A);
}

