// AJAX for BOX OFFICE list
// initialize XMLHttpRequest object
var ps_obj=null;
var debug_ok = 'n';  // 'y' or 'n'
// send http request
function ps_readSvrData(url) {
// check for existing requests
ps_obj=null
// code for Mozilla, etc.
if (window.XMLHttpRequest) {
ps_obj = new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject)
{
ps_obj=new ActiveXObject("Microsoft.XMLHTTP")
} else {
// Ajax is not supported by the browser
ps_obj=null;
return false;
}
// assign state handler and return obj handler
ps_obj.onreadystatechange=ps_stateChecker;
// open socket connection
// open("method", "URL"[, asyncFlag[, "userName"[, "password"]]])
ps_obj.open('GET', url, true);
// send request
ps_obj.send(null);
} // ps_readSvrData(url)
// check request reponse flag ( obj.readyState )
// 0 = uninitialized
// 1 = loading
// 2 = loaded
// 3 = interactive
// 4 = complete
function ps_stateChecker() {
// if request is completed
if(ps_obj.readyState==4){
// if status == 200 display text file
// Numeric code returned by server,
// such as 404 for "Not Found"
//         200 for "OK"
if(ps_obj.status==200){
// display data into Div
//alert("ajax_ps.js -- JSON="+ps_obj.responseText);
var result = eval('(' + ps_obj.responseText + ')');
ps_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:"+ ps_obj.statusText +"; status code="+ps_obj.status+"<br> ResponseText:"+ps_obj.responseText+" </font>";
}
}
}
} // ps_stateChecker()
function ps_displayData(result) {
var ps_status   = result.pst_st;
var ps_imgURL   = result.ps_url;
var ps_itmPtr   = result.ps_ptr;
var ps_nxtIdx   = result.ps_nxt;
// ------ debug -------
// To debug turn on the line below so you can tell if the Ajax and Perl's return
// alert("debug -- bt_ajax. \n"+displayText);
// ------ End debug -------
if (ps_status == 1) {
var ps_img_html = "<table border='0' cellspacing='0' cellpadding='0'><tr><Tdwidth=295 height='196' valign=middle align=center><a href=\"javascript:goItem('"+ps_itmPtr+"');\"><img src='"+ps_imgURL+"' border='0'></a></td></tr></table>";
document.getElementById('ps_poster').innerHTML=ps_img_html  ;
var ps_nxt_html = "<a href=\"javascript:next_poster('"+ps_nxtIdx+"');\"><img src='http://mongie.navidot.com/images/bttn_next.gif' border='0'></a>";
document.getElementById('nxt_ps').innerHTML=ps_nxt_html  ;
}
}
// 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
