function xmlhttpPost(strURL, form, div) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, false);//true=Asynchronous false=Synchrounous
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, div);
        }
     }
    self.xmlHttpReq.send( getquerystring( form ) );
}

function getquerystring( form ) {
    var form = document.forms[form];
    var ID = form.ID.value;
    var selectedfunction = form.selectedfunction.value;
    var search = form.search.value;
    
    qstr = 'ID=' + escape(ID) + '&selectedfunction=' + escape(selectedfunction) + '&search=' + escape(search);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str, div){
    document.getElementById(div).innerHTML = str;
}

function addselected( selected )
{
	var form = document.forms['main'];
    form.ID.value=selected;
    form.selectedfunction.value = 'select';


	initialize();
}

function unselect( unselected )
{
	var form = document.forms['main'];
    form.ID.value=unselected;
    form.selectedfunction.value = 'unselect';
    
	initialize();
}

function resetapp()
{
	var form = document.forms['main'];
	form.search.value="Search";
    form.selectedfunction.value = 'reset';
    
	initialize();
}

function initialize()
{
	document.getElementById('selected').innerHTML = "Processing...";
	document.getElementById('related').innerHTML = "Processing...";

	xmlhttpPost("selected.php", "main", "selected");//Call this first to initialize SESSION for others to use
	xmlhttpPost("az.php", "main", "az");
	xmlhttpPost("common.php", "main", "common");
	xmlhttpPost("related.php", "main", "related");
}

function searchsymptom()
{
	xmlhttpPost("az.php", "main", "az");
	xmlhttpPost("common.php", "main", "common");

}
