  var rootDivs         = null;
  var divIndex         = -1;

  var ajaxReq          = null;
  var ajaxDoc          = null;
  var aForumForm       = null;
  var aForumMessageUrl = null;
  var aCreateUrl       = null;
  var forumSubmitParams = null;
	var IE;
	var WrongCaptcha  = 1;



  function doDelay(Amount) {
   d = new Date(); //today's date
   while (1) {
     mill = new Date(); // Date Now
     diff = mill-d; //difference in milliseconds
     if( diff > Amount ) {
       break;
     }
   }
 }

  function newRequest() {
    if (IE == true)  {
      return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      return new XMLHttpRequest();
    }
  } // newRequest()

  function processAjax() {
    if ((ajaxReq.readyState == 4) && (ajaxReq.status == 200)) {
      ajaxDoc           = ajaxReq.responseText;
      aForumMessageUrl  = ajaxDoc;
      checkForm();
    }
  } // processAjax()

  function processAjaxForumSubmit() {
    if ((ajaxReq.readyState == 4) && ((ajaxReq.status == 200) || (ajaxReq.status == 404))) {
      ajaxDoc           = ajaxReq.responseText;
      if (ajaxDoc.indexOf("Invalid Captcha") > -1) {
        alert("Invalid Captcha");
        document.getElementById('submitbutton').disabled = false;
  	    document.getElementById('progress').style.visibility = "hidden"
      } else{
        lStr = window.location.href;
		    lStr = lStr.replace(/^(.*?)#[^#]*$/,'$1');
		    window.location = lStr;
      }
    }
  } // processAjaxPollResult()

  function processForumSubmit() {
    try {
      ajaxReq = newRequest();
      ajaxReq.onreadystatechange = processAjaxForumSubmit;
      ajaxReq.open("POST", aForumMessageUrl, true);
      ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      ajaxReq.setRequestHeader("Content-length", forumSubmitParams.length);
      ajaxReq.send(forumSubmitParams);
    } catch(e) {
      alert(e);
    }
  }  // processPollMiniResult()

  function checkForm() {
  	formErrors      = true;
  	aForm           = document.getElementById(aForumForm);
    var getstr = '';
    for (i=0; i<aForm.childNodes.length; i++) {
       if (aForm.childNodes[i].tagName == "INPUT"){
          if (aForm.childNodes[i].type == "text") {
             getstr += aForm.childNodes[i].name + "=" + escape(aForm.childNodes[i].value) + "&";
          }
          if (aForm.childNodes[i].type == "checkbox") {
             if (aForm.childNodes[i].checked) {
                getstr += aForm.childNodes[i].name + "=" + aForm.childNodes[i].value + "&";
             } else {
                getstr += aForm.childNodes[i].name + "=&";
             }
          }
          if (aForm.childNodes[i].type == "radio") {
             if (aForm.childNodes[i].checked) {
                getstr += aForm.childNodes[i].name + "=" + aForm.childNodes[i].value + "&";
             }
          }
       }
       if (aForm.childNodes[i].tagName == "TEXTAREA"){
         getstr += aForm.childNodes[i].name + "=" + escape(aForm.childNodes[i].value) + "&";
      }
       if (aForm.childNodes[i].tagName == "SELECT") {
          var sel = aForm.childNodes[i];
          getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
       }
       if (aForm.childNodes[i].type == "hidden") {
         getstr += aForm.childNodes[i].name + "=" + aForm.childNodes[i].value + "&";
       }
    }

	//HACK
	//add the captcha
	getstr += "Captcha=" + aForm.Captcha.value + "&";
    forumSubmitParams = getstr;
    ajaxReq = null;
    processForumSubmit();
  }


  function processForum() {
    try {
        ajaxReq                    = newRequest();
        ajaxReq.onreadystatechange = processAjax;
        ajaxReq.open("GET", aCreateUrl, true);
        ajaxReq.send(null);
    } catch(e) {
      alert(e);
    }
  } // processPollMini()

