<!--



var ajax_lastResult = '-1';



function ajax_request(cb, url, data)

{
    var myAjax = new Ajax.Request(

        url,

        {asynchronous: true, method: 'get', parameters: data, onComplete: cb}

    );

}



function ajax_response(jsonData)

{

	//ajax_lastResult = eval('('+jsonData.responseText+')');

	ajax_lastResult = jsonData.responseText;

}









	// global request and XML document objects

	var xmlhttp=false;

	

	// global request and XML document objects

	var callerDivName= '';

	

	// global flag

	var isIE = true;

	

	// URL to post to

	// var url = "";

	// in this code this variable is passed in as part of the call to the getSubs function

	

	//TBU = To Be Updated - indicating the field that will be updated as part of the submission. Again set by the form prior to making the xml http request.

	var TBU = "";

	

	function xmlObjInit(){

		/*@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;

		   isIE= false;

		  }

		 }

		@end @*/

		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

		  xmlhttp = new XMLHttpRequest();

		  isIE= false;

		}

		return false;

	}

	

	function loadXMLDoc(url,divName) {

		xmlObjInit();

	    if (xmlhttp) {

	        xmlhttp.open("GET", url, false);

			if(isIE)

	        	xmlhttp.send();

			else

				xmlhttp.send(null);				

				processReqChange();

	    } else {

			alert("Your web browser is not supported.  Please contact us.");

		}

		return false;

	}

	

	// handle onreadystatechange event of xmlhttp object

	function processReqChange() {

	    // only if xmlhttp shows "loaded"

	    if (xmlhttp.readyState == 4) {

	        // only if "OK"

	        if (xmlhttp.status == 200) {

				clearTopicList ();

				buildTopicList ();

			} else {

	            alert("There was a problem retrieving the XML data:\n" + xmlhttp.status + ' - ' + xmlhttp.statusText);

	         }

	    }

		return false;

	}

	

	// empty Topics select list content

	function clearTopicList() {

	    var select = document.getElementById(TBU);

		select.length = 0;

		select.length = 1;

		select.options[0] = new Option();

		select.options[0].value = "-1";

		select.options[0].text = "Please Select..";

	}

	

	// add item to select element the less

	// elegant, but compatible way.

	function appendToSelect(select, value, content) {

	    var opt;

	    opt = document.createElement("option");

	    opt.value = value;

	    opt.appendChild(content);

	    select.appendChild(opt);

	}

	

	// fill Topics select list with items from

	// the current XML document

	function buildTopicList() {

		var select = document.getElementById(TBU);

	    var items = xmlhttp.responseXML.getElementsByTagName("L1");

	    // loop through <item> elements, and add each nested

	    // <title> element to Topics select element

		// appendToSelect(select, "",document.createTextNode("Please select..."));

		for (var i = 0; i < items.length; i++) {

			// alert(getElementTextNS("", "elem", items[i], 0));

			appendToSelect(select, getElementTextNS("", "elemID", items[i], 0),

	            document.createTextNode(getElementTextNS("", "elem", items[i], 0)));

	    }

	    // clear detail display

	    //document.getElementById("details").innerHTML = "";

	}



	function getSub(controller, formselectvalue, url) {

		var send = url + "&" + controller + "=" + formselectvalue;

		try {

			loadXMLDoc(send);

		}

		catch(e) {

			alert("Unable to update.");

		}

		return false;

	}

	

	// retrieve text of an XML document element, including

	// elements using namespaces

	function getElementTextNS(prefix, local, parentElem, index) {

	    var result = "";

	    if (prefix && isIE) {

	        // IE/Windows way of handling namespaces

	        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];

	    } else {

	        // the namespace versions of this method 

	        // (getElementsByTagNameNS()) operate

	        // differently in Safari and Mozilla, but both

	        // return value with just local name, provided 

	        // there aren't conflicts with non-namespace element

	        // names

	        result = parentElem.getElementsByTagName(local)[index];

	    }

	    if (result) {

	        // get text, accounting for possible

	        // whitespace (carriage return) text nodes 

	        if (result.childNodes.length > 1) {

	            return result.childNodes[1].nodeValue;

	        } else {

	            return result.firstChild.nodeValue;    		

	        }

	    } else {

	        return "n/a";

	    }

	}

//-->
