function onLoadFun()
{
  document.getElementById("loading").style.visibility = "hidden";
  document.getElementById("loading").innerHTML = "<img id=\"loading-image\" src=\"../images/loading.gif\" alt=\"Loading...\"/>";
   doOperation("VIEW");
}
function doAction(action)
{
  if((document.getElementById("comment").value != "" && document.getElementById("comment").value != null) || action == "VIEW")
  {
    doOperation(action);
  }
}
function doOperation(action)
{

	var xmlHttpReq = false;
	var self = this;
	// Xhr per Mozilla/Safari/Ie7
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// per tutte le altre versioni di IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open("POST", "/ibase/E12TransCommentsServlet", true);
	self.xmlHttpReq.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4)
		{
		    if(action == "VIEW")
		    {
		      document.getElementById("loading").style.visibility = "hidden";
		    }
		    showMessage(self.xmlHttpReq.responseText,action);
		} 
		else
		{
		    if(action == "VIEW")
		    {
			document.getElementById("loading").style.visibility = "visible";
		    }
		}
	}
	self.xmlHttpReq.send(getParamValue(action));
}
function getParamValue(action)
{
  var paramString = "";
  paramString = "REF_SER="+document.getElementById("REF_SER").value;
  paramString += "&TRAN_ID="+document.getElementById("TRAN_ID").value;
  if(action == "ADD")
  {
    paramString += "&ACTION=ADD";
    paramString += "&COMMENT="+document.getElementById("comment").value;
  }
  else
  {
    paramString += "&ACTION=VIEW";
  }
  return paramString;
}
function showMessage(msg,action)
{
  if (window.DOMParser)
  {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(msg,"text/xml");
  }
  else // Internet Explorer
  {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    xmlDoc.loadXML(msg);
  }
  
  if(action == "ADD")
  {
    if(xmlDoc.getElementsByTagName("RESULT")[0].childNodes[0].nodeValue == "Success")
    {
      parent.E12ExistingComments.location.reload();
    }
  }
  else
  {
    var doc = xmlDoc.getElementsByTagName("COMMENTS")[0].childNodes;
    
    if(doc != null)
    {
      if(doc.length == 0)
      {
	document.getElementById("viewCommentsDivSub2").innerHTML = "<hr/><div>No Comments.</div><hr/>";
      }
      else
      {
	document.getElementById("viewCommentsDivSub2").innerHTML = "<hr/>";
	for ( i = 0 ; i < doc.length ; i++)
	{
	  value = doc[i].childNodes[0];
	  if(value != undefined || value != null)
	  {
	    document.getElementById("viewCommentsDivSub2").innerHTML += "<div class=\"comment\" id=\"comment\">" + doc[i].childNodes[0].nodeValue + "</div><hr/>"
	  }
	}
      }
    }
    else
    {
      document.getElementById("viewCommentsDivSub2").innerHTML = "<hr/><div>No Comments.</div><hr/>";
    }
  }
}