/* jaxboy copyright 2005-2006 Houston Chronicle 
   (Chronicle) Javascript Asynchronous Xml(and other stuff) BOY
   ChronJAX lite supporting only get method and limited dhtmlapi
   Author: John StG
*/
var _ISIE = document.all && window.ActiveXObject && (navigator.userAgent.toLowerCase().indexOf("msie") > -1);
//var httpcon = jaxboy();
function replaceHTML (target,txt) {
   var tele = getObject(target);
   if(tele) {
      tele.innerHTML = txt;
   }
}
function getObject(obj) {
   if (!obj) {return null;}
   if (typeof obj == "string") {
      return document.getElementById(obj);
   } else {
      // pass through object reference
      return obj;
   }
}
function show(obj) {
   var theObj = getObject(obj);
   if (theObj) {
      if (!_ISIE && theObj.tagName.toUpperCase()=='TR') {
         theObj.style.display = "table-row";
      } else if (theObj.getAttribute('displaytype')) {
         theObj.style.display = theObj.getAttribute('displaytype');
      } else {
         theObj.style.display = 'block';
      }

      theObj.style.visibility = "visible";
   }
}
function hide(obj) {
   var theObj = getObject(obj);
   if (theObj) {
      theObj.style.display = "none";
      theObj.style.visibility = "hidden";
   }
}
// Tab control
var tabloaded = new Array();
var currTarget = '';
function loadmenu(target) {
  if (visible_tab && (target != ('content'+visible_tab))) {return true;}
  if (tabloaded[target]==undefined){
    currTarget = target;
    var stat = loadTabViaIframe(target);
    tabloaded[target] = true;
    if(target != 'content'+visible_tab) {
      trackTab(target);
    }
    visible_tab=null;
  } else {
    trackTab(target);
  }
  return true;
}
function loadTabViaIframe(target) {
 var ghost = getObject("ghostFrame");
  if (ghost.addEventListener) {
    ghost.removeEventListener("load",uber, false);
    ghost.addEventListener("load",uber, false);
  } else if (ghost.attachEvent){
   ghost.detachEvent("onload",uber); // Bug fix line
   ghost.attachEvent("onload", uber);
  }
 if (document.all) {
   ghost.contentWindow.location=tablocations[target];
  } else {
    ghost.src=tablocations[target];
  }
 //getObject(target).innerHTML=ghost.document.body;
 return true;
}
function uber() {
  var ghost = getObject("ghostFrame");
  var target = getObject(currTarget);
  target.innerHTML=' ';
  if (ghost.contentDocument && ghost.contentDocument.body) {
    //ns6 syntax
   target.innerHTML = ghost.contentDocument.body.innerHTML;
  } else if (ghost.Document && ghost.Document.body) {
   //ie5+ syntax
     target.innerHTML = ghost.Document.body.innerHTML;
  }
  target.style.margin='0';
}
function loadmenu_jax (target) {
   if (!tabloaded[target] && target && window.tablocations) {
      var loc = tablocations[target];
      loadData(jaxboy(),loc,target);
      tabloaded[target] = true;
   }
   return false;
}
function loadData(bg_con,src,target,sideeffect) {
 //open asynchronous connection as we are expecting data back
   if (bg_con) {
      bg_con.onreadystatechange = function () {
         rpcInbound(bg_con,target,sideeffect);
      };
      var domain = 'http://'+document.domain;
      if (src.indexOf(domain)>=0) {} else {
         src = domain+src;
      }
      bg_con.open("GET",src,true);
      try {
         bg_con.send(null);
      } catch(e) {
         bg_con.close;
         return null;
      }
   } else {
   // This might be the place to use DivLoader http://verbouwing.schizofreend.nl/divloader.js
   }
}
function rpcInbound (bg_con,target,sideeffect) {
   if (bg_con.readyState == 4) {
      var xmlDoc = null;
      try {
       var status = bg_con.status;
       if (status == 200) {
         if (sideeffect) {
	   evalstr = sideeffect+'(target,bg_con)';
	   eval (evalstr);
         } else if(bg_con.getResponseHeader('Content-Type').indexOf('text/xml') != -1) {
            xmlDoc = bg_con.responseXML;
         } else {
            xmlDoc = bg_con.responseText;
         }
         if (xmlDoc && xmlDoc.length>5 && !sideeffect) {
            replaceHTML(target,xmlDoc);
          }
       } else if (sideeffect){
         evalstr = sideeffect+'(target,bg_con)';
         eval (evalstr);
       }
       bg_con.close;
      } catch(e) {alert(e);}
   }
}
function jaxboy() {
   var con=false;
   if (_ISIE) {
      var classes = new Array("Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
      for (var i=0; i< classes.length && !con; i++) {
         try {
            con=new ActiveXObject(classes[i])
         } catch (e) {
            con=false;
         }
      }
   } else {
      con=false;
   }
   if (!con) {
      try {
         con = new XMLHttpRequest();
      } catch (e) {
         con=false;
         alert("XmlHttp Not supported.");
         return false;
      }
   }
   return con
}
function trackTab(id) {
  var tracker = getObject('trackingFrame');
  if(!tracker) {return false;}
  tracker.src="http://"+document.domain+'/apps/channel'+'Pro/ft/'+id+'.html';
}


