//====================================================================//

// Keep myWAGAjax and debug global
var myWAGAjax;
var debug = false;

function CallBackOnSuccess()
{
	if (debug)
		document.body.appendChild(document.createTextNode('BEGIN FUNCTION : CallBackOnSuccess'));

	
	var nl = myWAGAjax.GetNodeList("/SUBSPECIALTY/RECORD");
	//alert('ID of first <RECORD> element: ' + nl[0].getAttribute('subspecialtyid'));
	
	//if null then there were no subspecialties returned. Therefore disable the drop down.
	if(nl[0].getAttribute('subspecialtyid') == null)
		temp_str = '<select name="SS" id="SS" disabled=""><option value="">Show All</option></select>';
	
	else
	{
		var num_nl, temp_str;
		
		temp_str = '<select id="SS" name="SS"><option value="0">Show All</option>';
		
			for (num_nl in nl)
			{
				var subspecialtyid = nl[num_nl].getAttribute('subspecialtyid');
				var subspecialty = nl[num_nl].getAttribute('subspecialty');
				//alert(subspecialtyid + " " + subspecialty);
				
				temp_str += '<option value="' + subspecialtyid + '">' + subspecialty + '</option>';
			}

		temp_str += '</SELECT>';
	}

	document.getElementById("SubSpecialtyDropdownID").innerHTML = '';
	document.getElementById("SubSpecialtyDropdownID").innerHTML += temp_str;
}

function CallBackOnFailure()
{
	if (debug)
	{
		document.body.appendChild(document.createTextNode('BEGIN FUNCTION : CallBackOnFailure'));
		document.body.appendChild(document.createElement('<br>'));
		document.body.appendChild(document.createTextNode('Request Status : ' + myWAGAjax.XmlHttpReq.statusText));
	}
}

// send_request
function send_request()
{
	if (debug)
	{
		document.body.appendChild(document.createTextNode('Instantiate WAGAjaxUtil object:'));
		document.body.appendChild(document.createElement('<br>'));
		document.body.appendChild(document.createTextNode('var myWAGAjax = new WAGAjaxUtil("/Wagform/MainPage.aspx?config=provider_XML&_page_id=SubSpecialtiesPage_XML&s=REHABGSPP");'));
		document.body.appendChild(document.createElement('<br><br>'));
	}
			
	//Grab the value of the specialty (S)
	var sValue = document.getElementById("S").value
	//alert(sValue);
	
	// Instantiate the WAGAjaxUtil object
	//debugger;
	myWAGAjax = new WAGAjaxUtil("/Wagform/MainPage.aspx?config=provider_XML&_page_id=SubSpecialtiesPage_XML&s=" + sValue);
	
	if (debug)
	{
		document.body.appendChild(document.createTextNode('myWAGAjax : ' + myWAGAjax));
		document.body.appendChild(document.createElement('<br><br>'));
	}

	// Set the Callback functions
	myWAGAjax.CallBackOnSuccess = CallBackOnSuccess;
	myWAGAjax.CallBackOnFailure = CallBackOnFailure;
	
	if (debug)
	{
		document.body.appendChild(document.createTextNode('typeof myWAGAjax.CallBackOnSuccess = ' + typeof myWAGAjax.CallBackOnSuccess));
		document.body.appendChild(document.createElement('<br>'));
		document.body.appendChild(document.createTextNode('typeof myWAGAjax.CallBackOnFailure = ' + typeof myWAGAjax.CallBackOnFailure));
		document.body.appendChild(document.createElement('<br><br>'));
	}

	// DEBUG
	if (debug)
	{
		document.body.appendChild(document.createTextNode('Send Request:'));
		document.body.appendChild(document.createElement('<br>'));
		document.body.appendChild(document.createTextNode('myWAGAjax.SendRequest();'));
		document.body.appendChild(document.createElement('<br><br>'));
	}

	// Send Request
	myWAGAjax.SendRequest();

}
