// this initializes our xmlQuery http array
var xmlHttp = new Array();

var NORMAL_STATE = 4;

var h;
var xmlExec;
var DataString = new Object();
//var DataString = new Array();

function xmlPrepare(url, parameters, xmlReady, queryType, h1) {
    h = h1;
    xmlExec = xmlReady;
    xmlQuery(url, parameters, queryType);
}

/*
 * xmlQuery - function to handle XML queries from within javascript
 *
 * url is the xmlQuery.php url (the php file we want to get results from)
 * parameters are the values being passed to the url (xmlQuery.php) file
 * xmlReady is the "Ready Function" that is executed after the xmlQuery is received by
 *   the js on the client
 * queryType is the type of request to be sent (GET or POST)
 * h is the name used to reference the xmlHttp[h] array (e.g. 'main' or 'title')
 *
 */
//function xmlQuery(url, parameters, xmlReady, queryType, h1) {
function xmlQuery(url, parameters, queryType) {

    //h = h1;

    xmlHttp[h] = getHTTPObject();

    try {
        xmlHttp[h].onreadystatechange = xmlHandle;
        if (queryType == 'GET') {
            xmlHttp[h].open('GET', url + parameters, true);
            xmlHttp[h].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlHttp[h].setRequestHeader("Content-length", parameters.length);
            xmlHttp[h].setRequestHeader("Connection", "close");
            xmlHttp[h].send(null);
        }
        else if (queryType == 'POST') {
            xmlHttp.open('POST', url, true);
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlHttp.setRequestHeader("Content-length", parameters.length);
            xmlHttp.setRequestHeader("Connection", "close");
            xmlHttp.send(parameters);
        }
        else { }

    }
    catch (e) { }
}


function xmlHandle() {
	// if there hasn't been any errors
	if (xmlHttp[h].readyState == NORMAL_STATE) {

		//titleResults = '';
		// split the days by the divider #!#
		//titleResults = xmlHttp['title'].responseText.split('#');
		
		//sqlTlength = titleResults.length - 2;

		//hasTitleSql = true;
        
		DataString[h] = '';		
		
		DataString[h] = xmlHttp[h].responseText;
	
        xmlExec();
	}
}
