//
// Base code from "Rasmus' 30 second AJAX Tutorial"
// http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html
//
//

function createRequestObject() {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }

 return req;
}



var http = createRequestObject();


function dataReq(action,itemguid, pagename,sectionname) {
//	document.getElementById(action).innerHTML = '<b>Loading...</b><br /><br />' + document.getElementById(action).innerHTML ;
		if(document.getElementById('loadingSection')) {

			document.getElementById('loadingSection').style.visibility='visible';
			document.getElementById('loadingSection').style.zIndex=18;

		};
	
	http.open('GET', '/data/ajax/?rand=' + Math.random()*9.83 +'&a='+action+'&i='+itemguid+'&p='+pagename+'&s='+sectionname);
    http.onreadystatechange = handleResponse;
    http.send(null);


  }


function cleardiv(mydiv) {
	document.getElementById(mydiv).innerHTML="";
  }




function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|*|' != -1)) {
            update = response.split('|*|');
            document.getElementById(update[0]).innerHTML = update[1];
        }


		if(document.getElementById('loadingSection')) {
			document.getElementById('loadingSection').style.visibility='hidden';
			document.getElementById('loadingSection').style.zIndex=-18;


		};
    }
}
