//var xmlHttpReq = null;

function newtopic(param) {
	sendDataGet(param);
}

function openwin(url) {
	window.open(url,'Motoman','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
}

function popup(robottype) {
	window.open('roboticszoom.htm?type=' + robottype,'mywindow','width=500, height=500, scrollbars=yes, resizable=yes')
}

function GetXMLHttpReqObject() {
	var xmlHttpReq = null;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttpReq = new XMLHttpRequest();

		if (xmlHttpReq.overrideMimeType) {
			xmlHttpReq.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	return xmlHttpReq;
}

function SendData() {
   sData = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"
   sData = sData & "<plcdata>"
   sData = sData & "   <value1>1234</value1>"
   sData = sData & "   <value2>Alarms all over the place</value2>"
   sData = sData & "</plcdata>"
}

function sendDataPost() {
	var xmlHttpReq, strResult;
	var xmldata;

   xmldata = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>";
   xmldata = xmldata + "<plcdata>";
   xmldata = xmldata + "   <value1>1234</value1>";
   xmldata = xmldata + "   <value2>Alarms all over the place</value2>";
   xmldata = xmldata + "</plcdata>";

	xmlHttpReq = GetXMLHttpReqObject();
	if (xmlHttpReq == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url = "demo.php?func=testxml&";
	xmlHttpReq.onreadystatechange = function() { state_Change(xmlHttpReq); };
	xmlHttpReq.open("post", url, true);

	//xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpReq.send(xmldata);



	//xmlHttpReq.send("id=1&user="+txtUser.value+"&password="+txtPassword.value);
	//strResult=objHTTP.responseText;
}

function sendDataGet(param) {
	var xmlHttpReq;

	xmlHttpReq = GetXMLHttpReqObject();
	if (xmlHttpReq == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url = "robotics.php?func=testxml&param=" + param + "&";
	//url = url + "?q=" + str;
	//url = url + "&sid=" + Math.random();

	//xmlHttpReq.onreadystatechange=stateChanged
	xmlHttpReq.onreadystatechange = function() { state_Change(xmlHttpReq); };
	xmlHttpReq.open("GET", url, true);
	xmlHttpReq.send(null);
}

function state_Change(xmlHttpReq) {
	// if xmlhttp shows "loaded"

	if (xmlHttpReq.readyState==4) {
		// if "OK"
		if (xmlHttpReq.status==200) {
			//var ele = document.getElementById('box');
			//ele.innerHTML = result[i].firstChild.data;
			//var ele = document.getElementById('output');

			var response = xmlHttpReq.responseXML.documentElement;
			//var method = response.getElementsByTagName('text1');
			var textvar = response.getElementsByTagName('text1')[0].firstChild.data;
			var titlevar = response.getElementsByTagName('titletext')[0].firstChild.data;
			//var picvar = response.getElementsByTagName('pic')[0].firstChild.data;
			//document.getElementById('textarea').innerHTML = method;

			document.getElementById('textarea').innerHTML = textvar;
			document.getElementById('titletext').innerHTML = titlevar;
			//document.getElementById('picarea').innerHTML = picvar;
			//var picele = document.getElementById('picture');

			//picele.src = picvar;
			//var result = response.getElementsByTagName('value2')
			//ele.innerHTML = result;

      	//for (var i=0; i<result.length; i++) {
    			//ele.text = result[i].firstChild.data;
    		//	ele.value = result[i].firstChild.data;
			//}
			//alert(xmlHttpReq.responseText);
			//document.getElementById('textarea').innerHTML = xmlHttpReq.responseText;

		} else {
			alert("There was a problem retrieving the XML data:\n" + xmlHttpReq.statusText);
			//document.getElementById("FirstName").value = xmlhttp.responseText;
		}
	}
}