function include(jsFile)
{
   var script=document.createElement("script");
   script.src=jsFile;
   script.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(script);
}

include("../../js/xml.js");
include("../../js/ajax.js");


function calculateTaxForm(doc, method)
{
   var xmlHttp = createXMLHttpRequest();
   var tableInput = doc.getElementById("input"); // table
   var xmlInput = createEmptyXml();
   for (var i=0; i<tableInput.rows.length; i++)
   {
      var cellVariable = tableInput.rows[i].cells[1]; // tr
      var inputVariable = cellVariable.childNodes[0]; // input
      setAttribute(xmlInput, inputVariable.name, inputVariable.value);
   }
   xmlHttp.open("POST", "action/" + method + ".do", false);
   xmlHttp.setRequestHeader("Content-Type", "text/xml");
   xmlHttp.send(xmlInput);
   if (xmlHttp.readyState==4 && xmlHttp.status==200)
   {
			var responseXML = xmlHttp.responseXML;
      if ((responseXML.tagName == "parserError") ||
          (responseXML.namespaceURI == "http://www.mozilla.org/newlayout/xml/parsererror.xml"))
      {
         setCalcError(doc, "Unable to parse output: " + xmlHttp.responseText);
            return;
      }
      var tableOutput = doc.getElementById("output"); // table
      for (var i=0; i<tableOutput.rows.length; i++)
      {
         var cellVariable = tableOutput.rows[i].cells[1]; // tr
         var inputVariable = cellVariable.childNodes[0]; // input
         inputVariable.value = getAttribute(responseXML, inputVariable.name);
      }
   }
   else
   {
      setCalcError(doc, "Error getting message: status code " + xmlHttp.status);
         return;
   }
   clearCalcError(doc);
}


function setCalcError(doc, str)
{
   var divError = doc.getElementById("errorbox"); // div
   divError.innerHTML = "<ul><li><p>" + str + "</p></li></ul>";
}

function clearCalcError(doc)
{
   var divError = doc.getElementById("errorbox"); // div
   divError.innerHTML = "";
}
