function instr(s0,s1,s2) {
        if(s0 > 0){
        	s1 = right(s1,s1.length - s0)
        }
        var instr = s1.indexOf(s2);
        return instr + 1;
}

function a() {}

function tgM(){
	history.go(-1);
}

function tgM2(){
	//history.go(-1);
	var c=document.getElementById("divC");
	var h=document.getElementById("divH");
	if (c.style.display!="none") {
		c.style.display="none";c.innerHTML=''
		var m=document.getElementById("divMain");m.style.display="block";
		//location.hash="#";}
		window.scroll(0,0);}
	//call reset function for search linkstrip
	try{
		selectSearchTab('');
	}
	catch(e){}

}

function v4(u2){
	var u='/reader/app/callback/preview.aspx?M=HB&U='+u2;
	loadDisDiv(u);
}

function vx(id){
	var u='/reader/app/callback/rdritems.aspx?B=NF&T=FD|'+id+'&FID='+id;
	curArgs=u;
	curLetter='';
	loadDisDiv(u);
}

function vy(id){
	var u='/reader/app/callback/rdritems.aspx?T=F|'+id;
	loadDisDiv(u);
}

function disDiv(stream){
	//load divC with preview results
	var ma = document.getElementById('divMain');
	var co=document.getElementById('divC');
	var h=document.getElementById('divH');
	var s = unescape(stream);
	if (co.innerHTML != s) {
	h.innerHTML = co.innerHTML;
	co.innerHTML = s;
	}
	var l = document.getElementById("divL");
	l.style.display="none";
	co.style.display="block";
	ma.style.display="none";
	//add script to document
	parseScript(unescape(stream));
}	

function disPop(stream){
	//load divC with preview results
	var co=document.getElementById('dvPopC');
	var s = unescape(stream);
	co.innerHTML = s;
	var p=document.getElementById('dvPop');

	var l = document.getElementById("dvPopL");
	l.style.display="none";
	co.style.display="inline";

	var c=co.childNodes[0];
	var root = (document.compatMode == "CSS1Compat"? 
		document.documentElement: document.body); 
	
	if (c.tagName=='DIV') {
		var iMax=root.offsetHeight-150;
		
		if (c.scrollHeight>c.offsetHeight) {
			if (c.scrollHeight>iMax) {
				c.style.height=iMax;
			}
			else {
				c.style.height=c.scrollHeight;
			}
		}
	}
	if (c.children==null) {
		p.style.left=((document.body.offsetWidth-p.offsetWidth)/2);
		p.style.top=((document.body.offsetHeight-p.offsetHeight)/2);
	}
	else {
		p.style.left=root.scrollLeft+((document.body.offsetWidth-p.offsetWidth)/2);
		p.style.top=root.scrollTop+((document.body.offsetHeight-p.offsetHeight)/2);
	}
	//add script to document
	parseScript(unescape(stream));
}	


function disL(stream){
	alert('DisL!');
	var r=document.getElementById("divResults");
	r.innerHTML = unescape(stream);
	r.style.display="block";
	var d=document.getElementById("divBack");
	d.style.display = "block";
	var l=document.getElementById("divLoading");
	l.style.display="none";
	//add script to document
	parseScript(unescape(stream));
}

function callHelp(sHelpTopic) {
	var help_win;
	help_win = window.open('http://<%=Request.ServerVariables("SERVER_NAME")%>/blogpublisher/help/mainhelp.aspx?src=' + sHelpTopic,'PortHelpWin','width=300,height=350,scrollbars=yes,resizable=no,status=no,location=no,menubar=no');
	help_win.focus();
}

var mw = 205;
var tdGo;
var slidingDiv; 
var o1;
var dw = 0;//018;
var wi = 0;
var inp="0"; 
var iv;

function maxL(s,i){
if (s.length > i){s=left(s,i)+'...'}
return s
}
			
function setCookie2 (name,value,domain,expires) {
	document.cookie = name + "=" + value +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((domain) ? "; domain=" + domain : "");// +
//			"; path=/";
	}

function goBack(){
	var d;
	d=document.getElementById("divResults");
	d.style.display = "none";
	d=document.getElementById("divBack");
	d.style.display = "none";
	d=document.getElementById("divTree");
	d.style.display = "block";
}	

function openPreviewCC(u){
	v4(u);
}

function openPreview(u){
//'DS 20100310: Invalid url -blogapp is deprecated; 
//A valid url should be determind before re-enabling this functionality
//	u='http://'+location.host+'/blogapp/'+u+'.atom';
//	v4(u);
}

function openWin(u) {
	if (u.length > 0){
	var win;
	win=window.open(u,"linkwin");
	win.focus()
	}
}		
 
function loadDisDiv(u) {
	var r = 'rnd='+Math.random();
	var u2 = u;
	if (instr(0,u2,'?') == 0) {u2=u2+'?'+r;} else {u2=u2+'&'+r;}
	
	curArgs=u2;
	curLetter='';
	//parent.loader.location='loader.aspx?q='+escape(u);
	tploader.location.href='loader.aspx?q='+escape(u);
	//loader passes u back to parent.viewer.loadDisFrame(u)
	//call loadDisFrame if no parent
}

function loadDisFrame(u) {
	var ma = document.getElementById('divMain');
	var co=document.getElementById('divC');
	co.style.display="none";
	ma.style.display="none";
	var l = document.getElementById("divL");
	l.style.display="block";
	GetURL(u,0,'disDiv');
	//location.hash="#";
	window.scroll(0,0);
}

var tpDispDivName = '';

function tpLoadDiv(u,d) {
	tpDispDivName = d;
	var co=document.getElementById(d);
	co.style.display="none";
	GetURL(u,0,'tpDisVarDiv');
	window.scroll(0,0);
}

function tpDisVarDiv(stream){
	//load divC with preview results
	var co=document.getElementById(tpDispDivName);
	//alert(co.style.display);
	var s = unescape(stream);
	co.innerHTML = s;
	co.style.display="block";
	//add script to document
	parseScript(unescape(stream));
}	

function loadPopDiv(u) {
	var c=document.getElementById('dvPop');
	c.style.display="block";
	var co=document.getElementById('dvPopC');
	co.style.display="none";
	var l = document.getElementById("dvPopL");
	l.style.display="block";
	var p=document.getElementById('dvPop');
	p.style.left=((document.body.offsetWidth-p.offsetWidth)/2);
	GetURL(u,0,'disPop');
	hideL();
}

function cs(){
	var u = appPath+'/app/nf/callback/comingsoon.aspx';
	loadDisDiv(u);
}

function setCurDiv(id,u){
	vy(id)
	//location.hash="#";
	window.scroll(0,0);
}

function Module(id, URL) {
	this.ID = id;
	this.Container = 'con'+id;
	this.LoadDiv = 'ld'+id;
	this.URL = URL; // +r;
}
Module.prototype.Load = function() {
try {
	if (getObj(this.Container)) {
	var r = 'rnd='+Math.random();
	if (instr(0,this.URL,'?') == 0) {r='?'+r;} else {r='&'+r;}
	GetURL(this.URL+r,0,'var f2=new Module("'+this.ID+'");f2.Display') 
	}
} catch(e) {}
}
//Added by TJM -- Doesn't append rnd at the end (which was causing my call to get preview feeds to blow up)
Module.prototype.LoadSpecial = function() {
try {
	if (getObj(this.Container)) {
	var r = 'rnd='+Math.random();
	if (instr(0,this.URL,'?') == 0) {r='?'+r;} else {r='&'+r;}
	GetURL(this.URL,0,'var f2=new Module("'+this.ID+'");f2.Display') 
	}
} catch(e) {}
}

//********************************************************************
// ~derived from  http://www.quirksmode.org/js/findpos.html#
//********************************************************************
Module.prototype.findPosXY = function(obj,x,y)
{
  x.value = 0;
  y.value = 0;
  if (obj.offsetParent) {
	while (obj.offsetParent) {
	  x.value += obj.offsetLeft;
	  y.value += obj.offsetTop;
	  obj = obj.offsetParent;
  	  }
  	}
  else {
        if (obj.x)
		  x.value += obj.x;
        if (obj.y)
		  y.value += obj.y;
	   }
  return;
}

function parm(value){this.value = value;}

//*********************************************************************
//
//*********************************************************************
Module.prototype.createIframeArea = function(url,parentNode)
{
  var x1 = new parm();
  var y1 = new parm();
  this.findPosXY(parentNode,x1,y1);
  
//  alert('creating iframe with url='+url+' and x='+x1.value+' y='+y1.value);
  var IFrameDoc;
  if (!document.createElement) {alert('cannot create element');return true};
  if (!this.m_IFrameObj && document.createElement) {
    try {
        this.m_tempIFrame=document.createElement('iframe');
        this.m_tempIFrame.setAttribute('id',this.m_guid);
        this.m_tempIFrame.style.border='0px';
        this.m_tempIFrame.style.width='210px';
        this.m_tempIFrame.style.height='900px';
        this.m_IFrameObj = parentNode.appendChild(this.m_tempIFrame);
        this.m_tempIFrame.src = url;
      } catch(exception) {
        //alert('creation route #2');
        iframeHTML='\<iframe id="'+this.m_guid+'" style="';
        iframeHTML+='border:0px;';
        iframeHTML+='width:100px;';
        iframeHTML+='height:200px;';
        iframeHTML+='"><\/iframe>';
        document.body.innerHTML+=iframeHTML;
        this.m_IFrameObj = new Object();
        this.m_IFrameObj.document = new Object();
        this.m_IFrameObj.document.location = new Object();
        this.m_IFrameObj.document.location.iframe = document.getElementById(this.m_guid);
        this.m_IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
        }
      }
    }
  return false;
}


Module.prototype.AjaxLoad = function() {
try {
  //alert('navigator.appVersion = '+navigator.appVersion);
	if (instr(0,navigator.appVersion,'Safari')) {
	  //alert('it is safari');
	  var r = 'rnd='+Math.random();
	  if (instr(0,this.URL,'?') == 0) {r='?'+r;} else {r=''+r;}
	  //alert('iframe url = '+this.URL+r);
	  this.createIframeArea(this.URL+r,getObj(this.Container));
	  var l = getObj(this.LoadDiv);
	  l.style.display="none";
	  return;
	  }
	
	if (getObj(this.Container)) {
  	  var r = 'rnd='+Math.random();
	  if (instr(0,this.URL,'?') == 0) {r='?'+r;} else {r=''+r;}
	  var myAjax = new Ajax.Request(this.URL+r,{method: 'get', parameters: null, onComplete: this.Render.bind(this)});
	  }
} catch(e) {}
}


Module.prototype.Render = function(originalRequest){
 //   alert('inside the callback');
	var s = originalRequest.responseText;
	var d = getObj(this.Container);
	d.innerHTML = s;
	d.style.display = "block";
	var l = getObj(this.LoadDiv);
	l.style.display="none";
	parseScript(s);
	//ComponentArt_NavBar_Page_Loaded = true;
}

Module.prototype.Display = function(stream) {
	var d = getObj(this.Container);
	d.innerHTML = unescape(stream);
	d.style.display = "block";
	var l = getObj(this.LoadDiv);
	l.style.display="none";
	//process any script
	try {
	parseScript(unescape(stream));
	}catch (e) {}
}

function enterSite() {
	window.location.href='/reader/app/nf/mypage2.aspx';
}
function logout() {
	lOp();
	window.location.reload();
}

function closePopDiv() {
var x=document.getElementById('dvPop').style.display='NONE';
showL();
}

function subscribex() {
	//var dvsub = document.getElementById('dvSubscribe');
	document.getElementById('dvSubscribe').style.display = 'BLOCK';
}

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}

function bTh(id){
top.location.href = "/reader/app/nf/blogthis.aspx?fiid=" + id;
}

function tTh(id){
top.location.href = "/reader/app/nf/tagthis.aspx?fiid=" + id;
}

function sTh(id){
openWin("/blogpublisher/app/ext/sendthis.aspx?fiid="+id,"sendthis","width=450,height=450,scrollbars=yes,resizable=yes,status=no,menubar=no");//location=no,
}

//need this code for dvPop

var lsts;
function hideL() {
	lsts = document.getElementsByTagName("SELECT") ;
	for (i=0;i<lsts.length;i++) {
		lsts[i].style.display ="none";
	}
}
function showL() {
	for (i=0;i<lsts.length;i++) {
		lsts[i].style.display ="";
	}
}

//ajax paging
var curArgs = "";
var curLetter = "";

function ldPg(pi){
 var p="&p=1";
 var l="&SL=" + curLetter;
 if (ldPg.arguments[0]){p="&p="+ldPg.arguments[0];}
 if (instr(0,curArgs,'?') == 0){curArgs=curArgs+'?';}
 //loadDisDiv(curArgs+p+l);
 GetURL(curArgs+p+l,0,'disDiv');
 //location.hash="#"
 window.scroll(0,0);
}
//*****************************************************************************
// JScript Code to launch the PodCastPlayer.
//*****************************************************************************
//
//*****************************************************************************
function GetPlayerAXCode (playerWidth, playerHeight, rssFileUrl, configFileUrl)
{
	flashCode = '<center>';
	flashCode += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'  width='"+playerWidth+"' height='"+playerHeight+"' id='player' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'>"
	flashCode += "<param name='movie' value='/reader/podplayer/mp3player.swf?file="+rssFileUrl+"&config="+configFileUrl+"'/>"
//	flashCode += "<param name='movie' value='mp3player.swf?config="+configFileUrl+"&file="+rssFileUrl+"'/>"
	flashCode += "<param name='allowScriptAccess' value='always'>"
//	flashCode += "<embed src='mp3player.swf?file="+rssFileUrl+"&config="+configFileUrl+"' allowScriptAccess='always' width='"+playerWidth+"' height='"+playerHeight+"' name='player'"
	flashCode += "<embed src='/reader/podplayer/mp3player.swf?config="+configFileUrl+"&file="+rssFileUrl+"' allowScriptAccess='always' width='"+playerWidth+"' height='"+playerHeight+"' name='podCastPlayer'"
  flashCode += "type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"
  flashCode += "</object>"
	flashCode += '</center>';
  return flashCode;
}


//*****************************************************************************
//
//*****************************************************************************
function GetPlayerHTML(width,height,fssFeed,controlFile)
{
   var rssUrl 	  =  encodeURI(fssFeed);
   var controlUrl =  encodeURI(controlFile); 
   var html = this.GetPlayerAXCode(width,height,rssUrl,controlUrl);
   return html;
}


//*****************************************************************************
//
//*****************************************************************************
function EmitPlayer(streamName, winWidth, winHeight)
{
  var podCastWin=window.open('','PodCastWin','width='+winWidth+',height='+winHeight);
  if (podCastWin) {
    podCastWin.document.write('<html><head><title>PodCast Player</title>');
    podCastWin.document.write('<link rel="stylesheet" href="style.css">');
    podCastWin.document.write('</head><body>');
    podCastWin.document.write(GetPlayerHTML(winWidth-4,winHeight-20,streamName,'/reader/podplayer/config.xml'));
    podCastWin.document.write('</body></html>');
    podCastWin.document.close();
    }
}
