// AJAX for BOX OFFICE list
// initialize XMLHttpRequest object
var hc_obj=null;
var debug_ok = 'n';  // 'y' or 'n'
// send http request
function hc_readSvrData(url) {
// check for existing requests
hc_obj=null
// code for Mozilla, etc.
if (window.XMLHttpRequest) {
hc_obj = new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject)
{
hc_obj=new ActiveXObject("Microsoft.XMLHTTP")
} else {
// Ajax is not supported by the browser
hc_obj=null;
return false;
}
// assign state handler and return obj handler
hc_obj.onreadystatechange=hc_stateChecker;
// open socket connection
// open("method", "URL"[, asyncFlag[, "userName"[, "password"]]])
hc_obj.open('GET', url, true);
// send request
hc_obj.send(null);
} // hc_readSvrData(url)
// check request reponse flag ( obj.readyState )
// 0 = uninitialized
// 1 = loading
// 2 = loaded
// 3 = interactive
// 4 = complete
function hc_stateChecker() {
// if request is completed
if(hc_obj.readyState==4){
// if status == 200 display text file
// Numeric code returned by server,
// such as 404 for "Not Found"
//         200 for "OK"
if(hc_obj.status==200){
// display data into Div
//alert("bt_ajax.js -- JSON="+hc_obj.responseText);
// Turn text string form {aaa:xxx, bbb:yyy, ccc:zzz} into object
var result = eval('(' + hc_obj.responseText + ')');
//var result = hc_obj.responseText;
//alert("ajax_hc.js -- JSON="+result);
hc_displayData(result);
} else {
if (debug_ok == 'y') {
// display debug status
document.getElementById('hcount').innerHTML= "<font style='font-family: arial; font-size: 12px; color:666666; line-height: 1.4;'>Failed to get response:"+ hc_obj.statusText +"; status code="+hc_obj.status+"<br> ResponseText:"+hc_obj.responseText+" </font>";
}
}
}
} // hc_stateChecker()
function hc_displayData(result) {
var displayText = result.usr_count;
displayText += "-"+ result.hit_count;
// ------ debug -------
// To debug turn on the line below so you can tell if the Ajax and Perl's return
//alert("debug --ajax_hc\n"+displayText);
// ------ End debug -------
document.getElementById('hcount').innerHTML=displayText;
}
// following code used to display HTML in a text area
//  if (document.main_form) {
//    if (document.main_form.debugArea) {
//      document.main_form.debugArea.value = displayText;
//    }
//  }
// require a pre-defined global variable: itemPtr
