/*
Functions below use "innerHTML" to fill div.
Change code in "toConsole" function to use alternate
method, e.g., appendChild, etc.

*/

/* HTTP REQUEST FUNCTIONS */
var req=null;
var contentID=null;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;

function loadXMLDoc(url, vals) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (req) {
        req.onreadystatechange = processReqChange;
        req.open("POST", url, true);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(vals);
    }
}

function processReqChange(){
  var ready=req.readyState;
  var data=null;
  if (ready==READY_STATE_COMPLETE){
    data=req.responseText;
  } else {
    data='<div "class="formOverlay overlayText overlay" style="height: 340px; width: auto;">processing...</div>';
  }
  toConsole(data);
}

function toConsole(data){
  if (contentID!=null){
  	// TODO: test for errors first
  	//
    contentID.innerHTML = data;
    /*
    var newline=document.createElement("div");
    contentID.appendChild(newline);
    var txt=document.createTextNode(data);
    newline.appendChild(txt);
	*/
  }
}

function getContent(pge, vals, container){
	if(!container){contentID = document.getElementById('modal_container');}
	else {contentID = document.getElementById(container);}
	loadXMLDoc(pge, vals);
}
// end http request #############
