var XmlHttp;

function GetXmlHttpObject()
{
   var XmlHttp = null;
   try
   {
      XmlHttp = new XMLHttpRequest();
   }
   catch (e)
   {
      try
      {
         XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return XmlHttp;
}

function StateChanged()
{
   if (XmlHttp.readyState == 4 || XmlHttp.readyState == "complete")
   {
      document.getElementById("CalcSum").innerHTML = XmlHttp.responseText;
   }
}

function ShowSum(url, params)
{
   XmlHttp = GetXmlHttpObject();
   if (XmlHttp == null)
      return;

   XmlHttp.onreadystatechange = StateChanged; 
   XmlHttp.open('POST', url, true);
   XmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   XmlHttp.setRequestHeader("Content-length", params.length);
   XmlHttp.setRequestHeader("Connection", "close");
   XmlHttp.send(params);
}

function GetInfo()
{
   var str = "size1=" + escape(encodeURI(document.getElementById("size1").value)) + 
             "&size2=" + escape(encodeURI(document.getElementById("size2").value)) + 
             "&slop=" + escape(encodeURI(document.getElementById("slop").value)) + 
             "&difficulty=" + escape(encodeURI(document.getElementById("difficulty").value)) +
			 "&existing=" + escape(encodeURI(document.getElementById("existing").value)) +
			 "&sky=" + escape(encodeURI(document.getElementById("sky").value)) +
			 "&chim=" + escape(encodeURI(document.getElementById("chim").value));

   ShowSum('http://www.roofingcalculator.org/scripts/getcalc.php', str);
}
