function decodeResponse(responseText,separator){
    var list = responseText.split(separator);
    var obj = new Object();
    for (var i = 0; i < list.length; i++){
            var pair = list[i];
            var fv = pair.split('=');
            obj[fv[0]] = fv[1];
    }
    return obj;
}


function loadData(reqmethod, URL, postdata, asxml, targetdiv, callBack, advanced)
{
// Create the XML request  
	xmlReq = null;
	if(window.XMLHttpRequest) 		xmlReq = new XMLHttpRequest();
	else if(window.ActiveXObject) 	xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
	if(xmlReq==null) return; // Failed to create the request

// Anonymous function to handle changed request states
	xmlReq.onreadystatechange = function()
	{
		switch(xmlReq.readyState)
		{
		case 0:	// Uninitialized
			break;
		case 1: // Loading
			break;
		case 2: // Loaded
			break;
		case 3: // Interactive
			break;
		case 4:	// Done!
		    if (asxml) {
		    	if (advanced != null){
		    		responseHandler(xmlReq);
		    	} else {
	    			var myresult = xmlReq.responseXML.getElementsByTagName('result')[0].firstChild.data;
	    			var myfn = xmlReq.responseXML.getElementsByTagName('handleby')[0].firstChild.data;
	                eval(myfn + '(myresult)');
                }
            } else {
                if (targetdiv==null){
                	return xmlReq.responseText.length;
                } else {
                	document.getElementById(targetdiv).innerHTML = xmlReq.responseText;
                	if (callBack != null){
                		callBack(xmlReq.responseText);
                	}
                }
            }
			break;
		default:
			break;
		}
	}


// Make the request
	xmlReq.open (reqmethod, URL, true);
    if (reqmethod=='POST')
	   xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlReq.send (postdata);
}

function ajaxPost(URL, postdata)
{
    loadData('POST', URL, postdata, true, null);
}

function ajaxPostAdv(URL, postdata)
{
    loadData('POST', URL, postdata, true, null, null, true);
}

function ajaxGet(URL)
{
    loadData('GET', URL, null, true, null);
}

function fetchDivBody(URL, divname,callBack)
{
	if (callBack == null){
    	loadData('GET', URL, null, false, divname);
    } else {
    	loadData('GET', URL, null, false, divname, callBack);
    }
}

function fetchDivBodyPost(URL, divname, postdata)
{
    loadData('POST', URL, postdata, false, divname);
}
