// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) 
       return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
       return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}

// Implement business logic    
function doWorkLeft(chapter,page){    
    httpObject = getHTTPObject();
    if (httpObject != null) {
        httpObject.open("GET", "NovelLeftPage.php?"
            + "&C=" + chapter
            + "&P=" + page, true);
        httpObject.send(null); 
        httpObject.onreadystatechange = setOutputLeft;
    }
}

// Change the value of the outputText field
function setOutputLeft(){
    if(httpObject.readyState == 4){
        document.getElementById('LeftPage').innerHTML = httpObject.responseText;
    }
 
}

// Implement business logic    
function doWorkRight(chapter,page){    
    httpObject = getHTTPObject();
    if (httpObject != null) {
        httpObject.open("GET", "NovelRightPage.php?"
            + "&C=" + chapter
            + "&P=" + page, true);
        httpObject.send(null); 
        httpObject.onreadystatechange = setOutputRight;
    }
}

// Change the value of the outputText field
function setOutputRight(){
    if(httpObject.readyState == 4){
        document.getElementById('RightPage').innerHTML = httpObject.responseText;
    }
 
}

var myReqNum = 0;
var http = new Array();

function ajreq(chapter,page,side) {
	myReqNum++;
	var myLocalReq=myReqNum;
	http[myLocalReq] = getHTTPObject();
	if (http[myLocalReq] != null) {
		http[myLocalReq].open("GET", "NovelPaging.php?"
			+ "&C=" + chapter
			+ "&P=" + page, true);
		http[myLocalReq].onreadystatechange = function(){handleResponse(http[myLocalReq],side)};
		http[myLocalReq].send(null);
	}
}

function handleResponse(theReq,side) {
	if(theReq.readyState == 4){
		var response = theReq.responseText;
		document.getElementById(side).innerHTML = response;
	}
}
