var XmlHttp2;

function CreateXmlHttp2()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttp2 = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp2 && typeof XMLHttpRequest != "undefined")
	{
		XmlHttp2 = new XMLHttpRequest();
	}
}

function ReflectanceTypes()
{
	// URL to get states for a given client
	var requestURL = ModeLookupAjaxUrl;
	CreateXmlHttp2();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp2)
	{
		//Setting the event handler for the response
		XmlHttp2.onreadystatechange = HandleModeLookup;

		//Initializes the request object with POST (METHOD of posting),
		//Request URL and sets the request as asynchronous.
		XmlHttp2.open("POST", requestURL,  true);
			
		// send header for post
		XmlHttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		
		//Sends the request to server
		XmlHttp2.send("");
	}
}

function HandleModeLookup()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp2.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp2.status == 200)
		{
			if(XmlHttp2.responseXML != null){
				DisplayModeTypes(XmlHttp2.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 = " + XmlHttp2.status + ")");
		}
	}
}

function DisplayModeTypes(xmlString)
{
	// display radio buttons for returned Temperature Control Types
	var rDiv = document.getElementById('rDiv');
	rDiv.appendChild(document.createTextNode("Loading Reflectance Types..."));
	
	var modeNodes = xmlString.getElementsByTagName("mode");
	var rowcount = modeNodes.length;
	var helpText = "";
	
	if (rowcount > 0)
	{
		rDiv.innerHTML = "";
		var tableMs = document.createElement("table");
		tableMs.className = "radioTable";
		var hasHelp = 0;
		helpText = "<br><b>Descriptions:</b><br>";
		
		for (i=0; i<rowcount; i++)
		{
			// insert new table
			var name = modeNodes[i].getAttribute("name");
			var id = modeNodes[i].getAttribute("id");
			var hlpTxt = modeNodes[i].getAttribute("helpText");
			if (hlpTxt != "")
			{
				helpText += name + ": <i>" + hlpTxt + "</i><br><br>";
				hasHelp++;
			}
			
			try {
				var radioButton = document.createElement("<input name='rdoMode' id='rdoMode' type='radio' value='"+ id +"' onClick='uncheckNextTabsRadios(2);' />");
			} catch (e) {
				var radioButton = document.createElement('input');
				radioButton.setAttribute('type', 'radio');
				radioButton.setAttribute('name', 'rdoMode');
				radioButton.setAttribute('id', 'rdoMode');
				radioButton.setAttribute('value', id);
				radioButton.setAttribute('onclick', "uncheckNextTabsRadios(2);");
			}
			rDiv.appendChild(tableMs);
			
			var newRow = tableMs.insertRow(i);
			var cell1 = newRow.insertCell(0);
			var cell2 = newRow.insertCell(1);
			cell1.width="10px";
			cell1.appendChild(radioButton);
			cell2.innerHTML = name;
		}
		try {
			var radioButton = document.createElement("<input name='rdoMode' id='rdoMode' type='radio' value='5' onClick='uncheckNextTabsRadios(2);' />");
		} catch (e) {
			var radioButton = document.createElement('input');
			radioButton.setAttribute('type', 'radio');
			radioButton.setAttribute('name', 'rdoMode');
			radioButton.setAttribute('id', 'rdoMode');
			radioButton.setAttribute('value', '5');
			radioButton.setAttribute('onclick', "uncheckNextTabsRadios(2);");
		}
/*		var newRow = tableMs.insertRow(rowcount);
		var cell1 = newRow.insertCell(0);
		var cell2 = newRow.insertCell(1);
		cell1.width="10px";
		cell1.appendChild(radioButton);
		cell2.innerHTML = 'Both';
		
		if (hasHelp == 0)
		{
			helpText = "";
		}
		var newRow = tableMs.insertRow(rowcount+1);
		var cell1 = newRow.insertCell(0);
		var cell2 = newRow.insertCell(0);
		cell1.innerHTML = helpText;
		cell2.innerHTML = "";
*/
	}
}