// ajax constants - same as in the ajax.asp mod
var ajx_status_success='!SCS!',ajx_status_fail='!ERR!';
var ajx_caboose='!ZZZ!';
var ajx_delim0='!#~',ajx_delim1='!a~',ajx_delim2='!b~';

function ajx_getresponsevars(resp){
 var vars=resp.split(ajx_delim0);
 if (vars.length!=3) return Array(false,resp);
 if (vars[0]!=ajx_status_success){
  if (vars[0]==ajx_status_fail){
   return Array(false,vars[1]);
  } else {
   return Array(false,resp);
  }
 }
 if (vars[2]!=ajx_caboose) return Array(false,resp);
 return  Array(true,vars[1]);
}

function GetControlType() {
 if (GetControlType.currentct)
  return GetControlType.currentct;
 var p = ["MSXML2","Microsoft","MSXML","MSXML3"];
 var test1, test2;
 for (var i=0;i<p.length;i++) {
  try {
   test1 = new ActiveXObject(p[i] + ".XmlHttp");
   test2 = new ActiveXObject(p[i] + ".XmlDom");
   return GetControlType.currentct = p[i];
  }
  catch (ex) {};
 }
}

function XmlHttp() {}
XmlHttp.create = function () {
 try {
  if (window.XMLHttpRequest) {
   var xhr = new XMLHttpRequest();
   // Older Mozilla does not allow readyState. Handle this
   if (xhr.readyState == null) {
    xhr.readyState = 1;
    xhr.addEventListener("load", function () {
     xhr.readyState = 4;
     if (typeof xhr.onreadystatechange == "function")
      xhr.onreadystatechange();
    }, false);
   }
   return xhr;
  }
  if (window.ActiveXObject) {
   return new ActiveXObject(GetControlType() + ".XmlHttp");
  }
 }
 catch (ex) {}
};

if (window.XMLSerializer &&	window.DOMParser &&	window.Node){
 if (Node.prototype.__defineGetter__ && Node.prototype) {
 	Document.prototype.loadXML = function (x) {
 		var thisdoc = (new DOMParser()).parseFromString(x, "text/xml");
 		while (this.hasChildNodes())
 			this.removeChild(this.lastChild);
 		for (var i=0;i<thisdoc.childNodes.length;i++) {
 			this.appendChild(this.importNode(thisdoc.childNodes[i], true));
 		}
 	};
 	Document.prototype.__defineGetter__("xml", function(){
 		return (new XMLSerializer()).serializeToString(this);
 	});
 }
}






function gettagcontent(thisnode,path){ //move to inc_rssfeeds.js
 var node=getnodebypath(thisnode,path,0);
 if (node==null)
  return "";
 return node.childNodes[0].data;
}

//gets node by path local to current node
function getnodebypath(node,path,idx){ //move to inc_rssfeeds.js
 if (node.length==0 || path.length==0)
  return null;
 var lpos=-1;
 var pos=0;
 var thisnode=node;
 var foundit=false;
 
 while(1) {
  pos=path.indexOf(".",lpos+1);
  if (pos==-1)
   pos=path.length;
  if (pos<=lpos)
   break;
  thisname=path.substring(lpos+1,pos).toLowerCase();
  lpos=pos;
  
  foundit=false;
  var thisidx=0;
  if(thisnode.hasChildNodes()) {
   for (var i=0;i<thisnode.childNodes.length;i++){
    node=thisnode.childNodes[i];
    if (isdefined(node.tagName)){
     if (node.tagName.toLowerCase()==thisname){
      if (thisidx++>=idx){
       foundit=true;
       thisnode=node;
       break;
      }
     }
    }
   }
  }
  if (!foundit)
   break;
 
 }
 if (foundit){
  return thisnode;
 }
 
 return null;
}

function loadXMLurl(xmlurl, loadingfunct, donefunct, doneparameter1, isasync) {
 if (isdifferentdomain(xmlurl)){
  return loadXMLurl_xdomain(xmlurl, loadingfunct, donefunct, doneparameter1, isasync);
 }
 isasync=(isasync==null?true:isasync);
 var xmlhttpobj = XmlHttp.create();
	xmlhttpobj.open("GET", xmlurl, isasync);
	if (isasync) {
  if (loadingfunct!=null)
   loadingfunct();
  if (donefunct!=null){
   xmlhttpobj.onreadystatechange = function () {
    if (xmlhttpobj.readyState == 4) {//if (xmlhttpobj.status == 200)
     if (doneparameter1!=null)
      donefunct(xmlhttpobj.responseText,doneparameter1);
     else
      donefunct(xmlhttpobj.responseText);
    }
    xmlhttpobj.close;
  }
	 }
	}
	xmlhttpobj.send(null);
	if (!isasync) {
  if (donefunct!=null){
   if (doneparameter1!=null)
    donefunct(xmlhttpobj.responseText,doneparameter1);
   else
    donefunct(xmlhttpobj.responseText);
   xmlhttpobj.close;
  }
	}
}






var isdifferentdomain_force=false;
var currentdomain=getdomain(location.href).toLowerCase();
if (currentdomain.indexOf('pagebuilder.planetbuzz')>=0 || currentdomain.indexOf('content.planetbuzz')>=0) isdifferentdomain_force=true;

function getdomain(url){
 var re = new RegExp("(http|https|file|ftp)://[^/]*/");
 var x = re.exec(url);
 if (x == null) return '';
 return x[0];
}
function isdifferentdomain(url){
 var thisdomain=getdomain(url).toLowerCase();
 if (mt(thisdomain) && !isdifferentdomain_force) return false;
 return (currentdomain!=thisdomain);
}






//***************************************************//
//** cross-domain support **//

var jsonobjs=Array();
var jsonobjs_cnt=0;

function loadXMLurl_xdomain(xmlurl, loadingfunct, donefunct, doneparameter1, isasync) {
 //loadXMLurl_xdomain must always be used asynchronously. isasync is simply here to mirror params of loadXMLurl
 jsonobjs_cnt++;
 if (jsonobjs_cnt>=200) jsonobjs_cnt=0;
 var url=xmlurl+'&jsoid='+jsonobjs_cnt;
 
 if (loadingfunct!=null) loadingfunct();
 
 jsonobjs[jsonobjs_cnt] = new JSONscriptRequest(url,donefunct,doneparameter1);
 jsonobjs[jsonobjs_cnt].buildScriptTag();
 jsonobjs[jsonobjs_cnt].addScriptTag();
}

function loadXMLurl_xdomain_commit(jsonobjid,data){
 if (jsonobjs[jsonobjid].donefunct!=null){
  if (jsonobjs[jsonobjid].doneparameter1!=null)
   jsonobjs[jsonobjid].donefunct(data,jsonobjs[jsonobjid].doneparameter1);
  else
   jsonobjs[jsonobjid].donefunct(data);
 }
 jsonobjs[jsonobjid].removeScriptTag;
}


function JSONscriptRequest(fullUrl,donefunct,doneparameter1) {
  this.fullUrl = fullUrl; 
  this.noCacheIE = '&noCacheIE=' + (new Date()).getTime() + (Math.random());
  this.headLoc = document.getElementsByTagName("head").item(0);
  this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
  this.donefunct = donefunct;
  this.doneparameter1 = doneparameter1;
}

JSONscriptRequest.scriptCounter = 1;

JSONscriptRequest.prototype.buildScriptTag = function () {
  this.scriptObj = document.createElement("script");
  this.scriptObj.setAttribute("type", "text/javascript");
  this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
  this.scriptObj.setAttribute("id", this.scriptId);
}

JSONscriptRequest.prototype.removeScriptTag = function () {
  this.headLoc.removeChild(this.scriptObj); 
}

JSONscriptRequest.prototype.addScriptTag = function () {
  this.headLoc.appendChild(this.scriptObj);
}
