var XmlHttp3;

function CreateXmlHttp3()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp3 = new ActiveXObject("Msxml3.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttp3 = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp3 && typeof XMLHttpRequest != "undefined")
	{
		XmlHttp3 = new XMLHttpRequest();
	}
}

function BandwidthLookup()
{
	// URL to get states for a given client
	var requestURL = BandwidthLookupAjaxUrl;
	CreateXmlHttp3();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp3)
	{
		//Setting the event handler for the response
		XmlHttp3.onreadystatechange = HandleBandwidthLookup;

		//Initializes the request object with POST (METHOD of posting),
		//Request URL and sets the request as asynchronous.
		XmlHttp3.open("POST", requestURL,  true);
			
		// send header for post
		XmlHttp3.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		
		//Sends the request to server
		XmlHttp3.send("");
	}
}

function HandleBandwidthLookup()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp3.readyState == 4)
	{
		// To make sure valid response is received from the server, 300 means response received is OK
		if(XmlHttp3.status == 200)
		{
			if(XmlHttp3.responseXML != null){
				DisplayBandwidths(XmlHttp3.responseXML.documentElement);
			}else{
				alert("There was a problem retrieving data from the server (responseXML == null)");
			}
		}
		else
		{
			alert("There was a problem retrieving data from the server (status = " + XmlHttp3.status + ")");
		}
	}
}

function DisplayBandwidths(xmlString)
{
	// display radio buttons for returned Temperature Control Types
	var sbDiv = document.getElementById('sbDiv');
	sbDiv.appendChild(document.createTextNode("Loading Bandwidths..."));
	
	var bandwidthNodes = xmlString.getElementsByTagName("bandwidth");
	var rowcount = bandwidthNodes.length;
	var helpText = "";
	
	if (rowcount > 0)
	{
		sbDiv.innerHTML = "";
		var tableBs = document.createElement("table");
		tableBs.className = "radioTable";
		var hasHelp = 0;
		helpText = "<br><b>Descriptions:</b><br>";
		
		for (i=0; i<rowcount; i++)
		{
			// insert new table
			var name = bandwidthNodes[i].getAttribute("bandwidthType");
			var id = bandwidthNodes[i].getAttribute("bandwidthID");
			var hlpTxt = bandwidthNodes[i].getAttribute("helpText");
			if (hlpTxt != "")
			{
				helpText += name + ": <i>" + hlpTxt + "</i><br><br>";
				hasHelp++;
			}
			
			try {
				var radioButton = document.createElement("<input name='rdoBandwidths' id='rdoBandwidths' type='radio' value='"+ id +"' onClick='uncheckNextTabsRadios(3);' />");
			} catch (e) {
				var radioButton = document.createElement('input');
				radioButton.setAttribute('type', 'radio');
				radioButton.setAttribute('name', 'rdoBandwidths');
				radioButton.setAttribute('id', 'rdoBandwidths');
				radioButton.setAttribute('value', id);
				radioButton.setAttribute('onclick', "uncheckNextTabsRadios(3);");
			}
			sbDiv.appendChild(tableBs);
			
			var newRow = tableBs.insertRow(i);
			var cell1 = newRow.insertCell(0);
			var cell3 = newRow.insertCell(1);
			cell1.width="10px";
			cell1.appendChild(radioButton);
			cell3.innerHTML = name;
		}
	}
}