var xmlHttp

function showAttach(){
	document.getElementById("attachInput").style.display = "inline";
	document.getElementById("imageInput").focus();
	document.getElementById("attachClick").style.display = "none";
}

function removeAttach(){
	document.getElementById("attachInput").style.display = "none";
	document.getElementById("attachClick").style.display = "inline";
	document.getElementById("imageInput").value="";
}

function clearForm(){
	document.getElementById("heading").value = ""
	document.getElementById("caption").value = ""
	document.getElementById("newstext").value = ""
	document.getElementById("nid").value = ""
}

function URLDecode(url) {//function decode URL
	// Replace + with ' '
	// Replace %xx with equivalent character
	// Put [ERROR] in output if %xx is invalid.
	var HEXCHARS = "0123456789ABCDEFabcdef";
	var encoded = url;
	var plaintext = "";
	var i = 0;
	while (i < encoded.length) {
		var ch = encoded.charAt(i);
		if (ch == "+") {
			plaintext += " ";
			i++;
		}
		else if (ch == "%") {
			if (i < (encoded.length-2)
			&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
			&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
			plaintext += unescape( encoded.substr(i,3) );
			i += 3;
			}
			else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		}
		else {
			plaintext += ch;
			i++;
		}
	} // while

return plaintext;
}; 

function fillForm(nid){
	//clearForm();
	
	document.getElementById("nid").value = nid
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request")
	  return
	  } 
	var url="getnewsxml.php"
	url=url+"?q="+nid
	url=url+"&sid="+Math.random()
	//xml_req.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 
	xmlHttp.onreadystatechange=updateNewsTextHandler 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	
}

function updateNewsTextHandler() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 xmlDoc=xmlHttp.responseXML;
 document.getElementById("heading").value = URLDecode(xmlDoc.getElementsByTagName("heading")[0].childNodes[0].nodeValue);
 document.getElementById("caption").value = URLDecode(xmlDoc.getElementsByTagName("caption")[0].childNodes[0].nodeValue);
 //document.getElementById("disabled").checked = disabled == "1"
 //xmlDoc.getElementsByTagName("heading")[0].childNodes[0].nodeValue;
 document.getElementById("newstext").value = URLDecode(xmlDoc.getElementsByTagName("text")[0].childNodes[0].nodeValue);
 
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari, IE7
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}