<!--

function createXMLHTTPObject() {
    // Create an xmlhttp object
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
	try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	   xmlhttp = false;
	}
     }
    @end @*/

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function getSelectedOption(element) {
    //alert("Getting option for " + element.id);
    for(var i = 0; i < element.options.length; i++) {
	 if (element.options[i].selected) {
             //if ( element.id == "study" ) alert("Selected option " + element.options[i].value);
  	     return element.options[i].value;
         }
    }
    return "";
}

function getAsyncRemoteText(url,obj) {
    var contents = "";
    //var xmlhttp = createXMLHTTPObject();
    var xmlhttp = GXmlHttp.create()
    xmlhttp.open("GET",url,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            var whatever = xmlhttp;
            var str = xmlhttp.responseText;
            GEvent.trigger(obj,'dataretrieved',str);
        }
    }
    xmlhttp.send(null);
}

function getRemoteText(url) {
    var contents = "";
    var xmlhttp = createXMLHTTPObject();
    xmlhttp.open("GET",url,false);
    xmlhttp.send(null);
    if ( xmlhttp.status == 200 ) {
        contents = xmlhttp.responseText;
    } else {
        alert("FIXME: ajax request failed!");
    }
    return contents;
}

function getRemoteXML(url) {
    var contents = "";
    var xmlhttp = createXMLHTTPObject();
    xmlhttp.open("GET",url,false);
    xmlhttp.send(null);
    if ( xmlhttp.status == 200 ) {
        contents = xmlhttp.responseXML;
    } else {
        alert("FIXME: ajax request failed! " + xmlhttp.status);
        alert(xmlhttp.status);
    }
    return contents;
}



function replaceInnerContents(url,block,asynchronous,callback) {
    if ( typeof(callback) == 'undefined' ) callback = null;
    if ( typeof(asynchronous) == 'undefined' ) asynchronous=true;
    var xmlhttp = createXMLHTTPObject();
    var wrapper = document.getElementById(block);
    if ( asynchronous ) {
        xmlhttp.open("GET",url,true);
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4) {
                wrapper.innerHTML = xmlhttp.responseText;
                if ( callback ) {
                    eval(callback + '()' );
                }
            }
        }
        xmlhttp.send(null);
    } else {
        xmlhttp.open("GET",url,false);
        xmlhttp.send(null);
        if ( xmlhttp.status == 200 ) {
            wrapper.innerHTML = xmlhttp.responseText;
            if ( callback ) {
                eval(callback + '()' );
            }
         } else {
            alert("FIXME: ajax request failed!");
        }
    }
}

function clearSelectedList(parent) {
    children = parent.childNodes;
    for ( var i = 0; i < children.length; i++ ) {
         child = children[i];
         if ( child.nodeType == 1 ) {
             child.removeAttribute("class");
            
         }
    }

}

function selectListElement(elem) {
    if ( ! elem ) {
        alert("No list element provided to select.");
        return;
    }
    clearSelectedList(elem.parentNode.parentNode);
    elem.parentNode.setAttribute("class","selected");
}

//-->
