// AJAX for BOX OFFICE list
// initialize XMLHttpRequest object
var bo_obj=null;
var debug_ok = 'n';  // 'y' or 'n'
// send http request
function bo_readSvrData(url) {
// check for existing requests
bo_obj=null
// code for Mozilla, etc.
if (window.XMLHttpRequest) {
bo_obj = new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject)
{
bo_obj=new ActiveXObject("Microsoft.XMLHTTP")
} else {
// Ajax is not supported by the browser
bo_obj=null;
return false;
}
// assign state handler and return obj handler
bo_obj.onreadystatechange=bo_stateChecker;
// open socket connection
// open("method", "URL"[, asyncFlag[, "userName"[, "password"]]])
bo_obj.open('GET', url, true);
// send request
bo_obj.send(null);
} // bo_readSvrData(url)
// check request reponse flag ( obj.readyState )
// 0 = uninitialized
// 1 = loading
// 2 = loaded
// 3 = interactive
// 4 = complete
function bo_stateChecker(){
// if request is completed. Else, it will keep looping itself until complete
if(bo_obj.readyState==4){
// if status == 200 display text file
// Numeric code returned by server,
// such as 404 for "Not Found"
//         200 for "OK"
if(bo_obj.status==200){
// display data into Div
// Turn text string {aaa:xxx, bbb:yyy, ccc:zzz} into object
var result = eval('(' + bo_obj.responseText + ')');
//alert("bt_ajax.js -- JSON="+bo_obj.responseText);
bo_displayData(result);
} else {
if (debug_ok == 'y') {
// display debug status
document.getElementById('bo_ajax').innerHTML= "<font style='font-family: arial; font-size: 12px; color:666666; line-height: 1.4;'>Failed to get response:"+ bo_obj.statusText +"; status code="+bo_obj.status+"<br> ResponseText:"+bo_obj.responseText+" </font>";
}
}
}
} // bo_stateChecker()
function bo_displayData(result) {
var displayText = "";
var crawl_ok = result.crawl_ok;
if (crawl_ok == "yes") {
var arr_size = result.arr_loop.length;
displayText += "<Table border=0 cellspacing=0 cellpadding=0 width=100%>";
displayText += "<Tr><td width=15></td>";
displayText += "<Td>";
displayText += "<font style=\"font-family: arial; font-size: 13px; line-height: 1.4;\" color=#4e4e4e><b>"+ result.chart_d+" Weekend</b> </font>";
displayText += "</Td></tr>";
displayText += "<Tr><td height=10></td></tr>";
displayText += "</Table>";
displayText += "<Table border=0 cellspacing=0 cellpadding=0 width=100%>";
displayText += "<tr>";
displayText += "<td width=15></td>";
displayText += "<td><a href=\"javascript:goItem('"+result.arr_loop[0].BoIPtr+"')\" ><img src='"+result.BoImg+"' border='0' align='right' style='margin-left: 15px; margin-bottom: 15px;'></a>";
displayText += "<font class='moretheaters_text'>";
for (var sIdx=0;sIdx<arr_size;sIdx++) {
var item_idx = sIdx + 1;
displayText += item_idx +". <a href=\"javascript:goItem('"+result.arr_loop[sIdx].BoIPtr+"')\" class='movie_link'>"+result.arr_loop[sIdx].BoTitle+"</a><br>";
}
displayText += "</font></td>";
displayText += "<td width=15></td>";
displayText += "</tr>";
displayText += "</table>";
// use line below as iteration reference (e.g. if <reload> is needed)
// displayText += "<a href=\"javascript:bo_next('http://mongie.navidot.com/cgi-bin/bt_main.pl?idx="+result.aj_idx+"&itemPtr="+result.itemPtr+"');\" class=\"bt_r\">Reload</a>";
// ------ 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 -------
document.getElementById('bo_ajax').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;
//    }
//  }
}
function bo_next (url) {
var html_code = "<table><tr><td height=10></td></tr></table><table width=100%><tr><td align=center><img src='http://mongie.navidot.com/images/loading.gif' border=0></td></tr><tr><td height=10></td></tr><tr><td><font style='font-family: verdana; font-size: 12px; color:993300'> Please wait while we are updating the torrent info. It may take about 30 seconds to a minute... </font></td></tr><tr><td height=8></td></tr></table>";
// bring back the default display
document.getElementById('bo_ajax').innerHTML=html_code;
// Call ajax
bo_readSvrData(url);
//document.location.reload();
}
// require a pre-defined global variable: itemPtr
