var prevQuickCiteCnt;
var prevQuickCiteVol;
var prevQuickCiteRptr;
var prevQuickCitePg;
var SearchParamsObj;
var prevSearches;

//Custom Start Page state information
var userName = "";
var userProduct = "";
var stateLogoImg = "";
var isAdditionalPrimaryLawDivOpen = false;
var isPrimaryLawDivOpen = false;
var quickSearchStrAlias = "";
var quickSearchExpression = "";
var isCinLawUser = ((GetCookie("CinLawUser")=="true"))?true:false;
var restrictSrcQuery = "";

function topInit()
{
  SearchParamsObj = new Array();
  SearchParamsObj["boolNewSearch"] = true;
  SearchParamsObj["PrevConstructSearch"] = "";
  SearchParamsObj["PrevEvalResults"] = "";
  SearchParamsObj["PrevEvalResultsBegDate"] = "";
  SearchParamsObj["PrevEvalResultsEndDate"] = "";
  SearchParamsObj["PrevEvalResultsDateRange"] = "";
  SearchParamsObj["boolRerun"] = false;
  SearchParamsObj["prevSrcQuery"] = "";
  SearchParamsObj["PrevSearchFieldCount"] = "";
  //SearchParamsObj["prevCaseType"] = "";
  SearchParamsObj["prevPubUnpubOp"] = 0;//default to Published
  SearchParamsObj["prevSearchDataName"] = new Array();
  SearchParamsObj["prevSearchDataValue"] = new Array();
  SearchParamsObj["prevPageUrl"] = "";
  SearchParamsObj["origSrcQuery"] = "";
  SearchParamsObj["boolOldSearch"] = false;
  prevSearches = new Array();
}

var PopUpURLTree; //set variable for fpopwind.htm to detect nav/tree window 
var SubmitFACForm = false;
var TheFACForm = null;
function openFACMultiWindow(url,url2, CiteTxt)
{ 
	popupLink( "/pns/FACMultiStart.htp?logauto=FMAUTO","Find A Case - Multiple Citations",790,600); 
}
//Find A Case on Top frame
function FindIt(theForm, buttonclicked,url,url2){

	var d = theForm.Citetxt.value;
	//we wnat to ba able to pull CiteTxt data into url's CiteTxt area, and trigger an auto submit of url's form
  if(theForm.Citetxt && theForm.Citetxt.value && theForm.Citetxt.value.length )
  {
    SubmitFACForm = true; //url page needs to reset this after pulling the CiteTxt and auto-submitting it's form
    TheFACForm = theForm;
    openFACMultiWindow();
    //popupLink( '/pns/FAClink.htp?logauto=FCAUTO&errtemp=/pns/facerror.htp&Cite=' + escape(d) );
  }
  else
    alert('Please enter valid search criteria.');

  if(buttonclicked==0)
		return false;  
}


function openSubscribeWindow()
{ TutorialWindow=window.open("/info/content/usamap.htm","tutorial","width=770,height=600,status=yes,scrollbars=yes,location=yes,resizable=yes,menubar=yes,toolbar=yes"); }
function openFormWindow(url)
{
	window.parent.content.location.href = url;
}

function openBooks()
{
	if( Site != 'MPS' )
  	window.open("http://www.aspenpublishers.com?promoID=WEBLOISLAW","books","width=770,height=500,status=yes,scrollbars=yes,location=yes,resizable=yes,menubar=yes,toolbar=yes");
}



function replEscapeChar(strKeyword)	{
	if (strKeyword.indexOf("+")>0)
		//replace the + sign with the some other character and parse it back in the posted asp page.
		return strKeyword.replace("+","~");
	else
		return strKeyword;
}	
function IsSpaceOnly(s) 
{
	var i;
	for(i=0; i<=s.length-1; i++)	{
		if ((s.charAt(i) != ' ')) {
			return false;
		}
	}
	return true;	
}
function trimit(s)
{
	
	while (s.length!=0)
	{
		s = s.replace(" ","");	
	}
	return s;
}

function openGBCWindow()
{
  popupLink( "/info/content/global.htm","Loislaw GlobalCite" );
}

function openAccWindow()
{	//BUG: GetCookie() does not work well if "LOISLAWID" is within LLGlobal cookie string...
	var SessId = GetCookie("LOISLAWID"); //needed for IPAuth users, if never visited ecom during login (otherwise, we create a new session)
	if(SessId.length == 36 ) SessId = "&SessId="+SessId;
	else SessId = "";
	var url = "https://ecom.loislaw.com/pns/index.htp?content=/pns/admin/index.htp"+SessId;
	popupNoFrameLink( url, "My Account", 700, 500, false ); 
}

function openTimerWindow()
{
  popupLink( "/pns/timer.tim","Loislaw Client Billing Timer", 500, 300, false );
}

function openSavedSearchWindow()
{
  popupLink( "/pns/lwlist.htp?action=lwlist","My Saved Searches" );
}

function gotoPrevConstructSearch()
{
  parent.content.location.href = SearchParamsObj["PrevConstructSearch"].replace(" ","%20");
}

function gotoEvaluateResults()
{
  parent.content.location.href = SearchParamsObj["PrevEvalResults"].val;
}

function openCQWindow()
{
  if( top.content.GetCQURL ) {
    popupLink( top.content.GetCQURL(), "Loislaw Common Questions", 700, 500 );
  }else{
    popupLink( "/help/help.htm", "Loislaw Common Questions", 700, 500 );
  }
}

function logout()
{
  parent.top.location.replace( "/pns/logout.htp" );
}

function HideFromMaine()
{
  var mpsdiv = document.getElementById? document.getElementById('mpsdiv'):document.mps1.document.mps2.mpsdiv;
  if( Site == 'MPS' ){
    mpsdiv.style.visibility='hidden';
		mpsdiv.style.display='none';
	}
}

function elementCollection()
{

  this.addAll = function(doc)
  {
    if(!doc) doc = document;
    var arr = (doc.all)? doc.all : doc.getElementsByTagName('*');
    for(var e in arr)
    {
      var name = '';
      if(e.id)  name = e.id;
      else if(e.name)  name = e.name;
      if(name == '') return;
      name = name.toLowerCase();
      this[name] = e;
    }
  }
  this.find = function(name)
  {
    if(typeof(name) != 'string' || name == '' ) return;
    var e = document.getElementById(name);
    if(e){ e['is'] = name.toLowerCase(); return (e); }
    else return null;
  }
  this.get = function(name)
  {
    if(typeof(name) != 'string' || name == '' ) return;
    name = name.toLowerCase();
    if(this[name]) return this[name];
    else return this.find(name);
  }
  this.add = function()//variable number param list of strings
  {
    for(var i=0; i < arguments.length; i++)
    {
      var e = this.find(arguments[i]);
      if(e){ this[e.is] = e; }
    }
  }
  this.remove = function()
  {
    for(var i=0; i < arguments.length; i++)
    {
      arguments[i] = arguments[i].toLowerCase();
      if(this[arguments[i]]) delete this[arguments[i]]; //eval('with(this) delete '+arguments[i]+';');
    }
  }
  this.show = function()
  {
    for(var i=0; i < arguments.length; i++)
    {    
      arguments[i] = arguments[i].toLowerCase();
      if(this[arguments[i]] && this[arguments[i]].style)
      {
        this[arguments[i]].style.visibility = 'visible';
        this[arguments[i]].style.display    = 'block';
      }
    }
  }
  this.hide = function()
  {
    for(var i=0; i < arguments.length; i++)
    {    
      arguments[i] = arguments[i].toLowerCase();
      if(this[arguments[i]] && this[arguments[i]].style)
      {
        this[arguments[i]].style.visibility = 'hidden';
        this[arguments[i]].style.display    = 'none';
      }
    }
  }
  this.hideAll = function()
  {
    for(var e in this)
      this.hide(e);
  }
  this.removeAll = function()
  {
    for(var e in this)
      this.remove(e);
  }
  
  //optional add all constructor function
  for(var i=0; i < arguments.length; i++)
  {
    arguments[i] = arguments[i].toLowerCase();
    this.add(arguments[i]);
  }
}
function GetElementY(e)
{
  if(e){ var y = e.offsetTop; var el = e; while( (el = el.offsetParent) != null) { y += el.offsetTop; } return y; } 
}

//globals and flags  
var init = false;
var caller = null;
var isFixedWidth = true;
var CurrentState = '';
var CurrentStateFunc = null;
var bCrumbs = new BCS;
var allDivs = new elementCollection();
var hitButtons;
var commonDiv;
var headerDiv;

function GetBullet() { return  "<span style='color:#CB0066'>&bull;</span>"; }


window.onunload = function()
{
  if(!top.opener)//I'm the main window, save some state info
  {
    var topState = new CookieObj('topState');
    topState.CurrentStateFunc = (CurrentStateFunc)?CurrentStateFunc.name:"NullFunc";//used to set current state if user navigated off our site
    topState.set();
  }
}

function Sync()
{
  topInit();
  init = true;
  allDivs.add('Main','LogoDiv','ancillaryHomeDiv','ancillaryMembersDiv','FACDiv','ProductDiv', 'StateLogoDiv');
  allDivs.add('bannerLeftDiv','bannerRightDiv','bannerDiv');
  allDivs.add('homeNavLinksDiv','homeNavLinks','membersNavLinks','breadCrumbDiv','headerDiv','dochits', 'infoadvdiv');
  allDivs.add('collapseLogoDiv', 'collapseFACDiv', 'hideMenuDiv', 'collapseDiv', 'showMenuDiv');
  commonDiv = document.getElementById('common_q');
  headerDiv = document.getElementById('headerDiv');

  ClearDocViewGlobals();

  if(top.isPopWin)
    isFixedWidth = false;

  var topState = new CookieObj('topState');//used to retrive saved state info
  if( !top.opener && topState.get() )
  {
    if(topState.CurrentStateFunc != '')
      eval(topState.CurrentStateFunc+"();");
  }

  if(top.content && top.content.Sync)
    top.content.Sync();
  else
  {
    SetBlank();
    TopResize();
  }
  if(Site=="SCHOOL") document.getElementById('freeTrial').innerHTML = "Register Here";
  if(GetCookie("GroupID")=="2"||GetCookie("GroupID")=="9") try{HideE('LoislawStoreLink')}catch(e){}//CR 5106
}


function SetBlank()
{
  if(init && (CurrentStateFunc != SetBlank))
  {
    allDivs.hideAll();
    CurrentStateFunc = SetBlank;
  }
}
SetBlank.name = 'SetBlank';

function SetNotLoggedIn()
{
  if( init && (CurrentStateFunc != SetNotLoggedIn))
  {
    CurrentStateFunc = SetNotLoggedIn;
    allDivs['main'].style.width = '100%';
    isFixedWidth = true;
    

    if( allDivs['bannerleftdiv'].innerHTML == '' )
    {
      allDivs['bannerleftdiv'].innerHTML = "<img src='http://image.loislaw.com/prosite/misc/banner_left.jpg'>";
      allDivs['bannerrightdiv'].innerHTML = "<img src='http://image.loislaw.com/prosite/misc/banner_right.jpg'>";
    }

   	allDivs['logodiv'].innerHTML = '<a href="http://www.wolterskluwer.com" target="_blank"><img src="http://image.loislaw.com/prosite/logos/wk_legal.png" border="0" title="Click here to view the Wolters Kluwer website."></a>';

    allDivs.hideAll();
    allDivs.show('Main', 'ancillaryHomeDiv', 'logoDiv', 'homeNavLinksDiv', 'homeNavLinks', 'bannerDiv', 'bannerLeftDiv','bannerRightDiv' );
    
    GetE('Home').style.width='770px'
  	allDivs['bannerdiv'].style.width="770px";
  	GetE('LoisLogoDiv').style.paddingTop="10px";
  	allDivs.get('bannerDiv').style.height="58px";
  }
}
SetNotLoggedIn.name = 'SetNotLoggedIn';

function SetLoggedIn()
{
  if( init && (CurrentStateFunc != SetLoggedIn))
  {
    CurrentStateFunc = SetLoggedIn;
    allDivs['main'].style.width = '100%';
    isFixedWidth = false;
    
    if( allDivs['logodiv'].innerHTML == '' )
			allDivs['logodiv'].innerHTML = '<div style="float:left;width:150px"><a href="/index.htm" target="_top"><img src="http://image.loislaw.com/prosite/logos/wk_legal.png" border="0" title="Click here to view the Wolters Kluwer website."></a></div>';
		if( allDivs['productdiv'] && allDivs['productdiv'].innerHTML == '' )
		{
			allDivs['productdiv'].innerHTML = "<div style='padding-left:2px;float:left'><span style='color:#000000;font-size:12px;font-weight:700' id='userNameSpan'>" + userName + "</span></div>";
			allDivs['productdiv'].innerHTML += "<div style='padding-left:2px;'><br><span style='color:#027fc2;font-size:14px;font-weight:700;vertical-align:top' id='userProductSpan'>" + userProduct + "</span></div>";
		}
		if( allDivs['bannerleftdiv'].innerHTML == '' )
    {
      allDivs['bannerleftdiv'].innerHTML = "<img src='http://image.loislaw.com/prosite/misc/banner_left.jpg'>";
      allDivs['bannerrightdiv'].innerHTML = "<img src='http://image.loislaw.com/prosite/misc/banner_right.jpg'>";
      if(is.safari)
      {
        allDivs['bannerleftdiv'].style.height='135';
        allDivs['bannerrightdiv'].style.height='135';
      }
    }

    allDivs.hideAll();
    allDivs['breadcrumbdiv'].innerHTML = '';
    allDivs.show('Main', 'ancillaryMembersDiv', 'logoDiv', 'membersNavLinks', 'breadCrumbDiv', 'FACDiv', 'hideMenuDiv', 'productdiv', 'statelogodiv', 'bannerDiv', 'bannerRight' );

    GetE('Home').style.width='100%'
  	allDivs['bannerdiv'].style.width="100%";
  	GetE('LoisLogoDiv').style.paddingTop="30px";
  	allDivs.get('bannerDiv').style.height="25px";
  	var trlogo = GetE('trlogo');trlogo.style.width="103px";
  }
}
SetLoggedIn.name = 'SetLoggedIn';

function SetPopWin()
{
  if( init && (CurrentStateFunc != SetPopWin) )
  {
    CurrentStateFunc = SetPopWin;
    allDivs.get('main').style.width = '100%';
    isFixedWidth = false;
    
    //<!--table <tr> are 1px tall even when contents are invisable-->
    var tranc = document.getElementById('tranc');tranc.style.visibility = 'hidden';tranc.style.display = 'none';
    var trlogo = document.getElementById('trlogo');trlogo.style.visibility = 'hidden';trlogo.style.display = 'none';

    allDivs.hideAll();
    allDivs.show('Main', 'breadCrumbDiv', 'headerDiv' );
  }
}
SetPopWin.name = 'SetPopWin';

function TopResize()
{
  if(typeof allDivs.get('Main').offsetHeight!='undefined')
  	ResizeTopFrameRows(allDivs.get('Main').offsetHeight);

  if(gSpans.length && hitButtons ) CurrentUpDown();
}

window.onresize = TopResize; //Auto resize

function CheckWebsiteOutage(){
  var doc;
  var level;
  try{ GetRequest("/siteoutage.htm", false, DisplayErrorMessages); }catch(e){}

  function DisplayErrorMessages(doc){
    try{
	    HideE("OutageTD");
	    if(doc && doc != ''){
	      var level = (doc.match(/errorLevel=([0-9]+)/i)||new Array(2))[1];
	      if(parseInt(level) > 0){
		      var content = GetFrameById("content");
	        if(content.location.pathname.match(/doors.htp/i)){
		        var OutageDiv = GetE("OutageDiv", content);
	          OutageDiv.innerHTML = doc;
	          var sevleveldiv  = GetE("sev"+level, content);
	          var sevlevelbody  = GetE("sev"+level+"Body", content);
 	          ShowE(sevlevelbody);
 	          ShowE(OutageDiv);
 	          ShowE(sevleveldiv);
 	          sevleveldiv.onclick = null;
	          sevleveldiv.style.cursor = "default";

	        } else{ //top frame
	          GetE("OutageDiv").innerHTML = doc;
	          GetE("OutageDiv").style.cursor = "pointer";
	          ShowE("sev"+level);
	          ShowE("OutageTD");
	        }
	      }
      }
      TopResize();
  	}catch(e){}
  }
}

function openOutageWindow(div,head,body,width,height){
  var myWin,doc;
  PopUpTitle = head;
  myWin = window.open('','copywin','width='+(width||'350')+',height='+(height||'310')+',menubar=0,toolbar=0status=0,scrollbars=1,resizable=1');
  doc = myWin.document;
  doc.open("text/html");
  doc.write('<html><head><link rel="stylesheet" type="text/css" href="/css/lois.css">'+
    '<title>'+head.replace(/<[^>]*>/g,'')+'</title>'+
    '</head>' +
    '<body style="text-align:center;cursor:default">' +
    '<div class="weboutage">' +
    '<div style="font-weight:bold;padding-bottom:15px">' + head + '</div>' +
    '<span id="sev1Body" style="padding:2px;text-align:left;color:#000000;">'+ body + '</span></div>' +
    '<div style="margin:0px auto;text-align:center"><span class="button" onclick="top.close();">&nbsp;Close&nbsp;</div>' +
    '</body></html>'
  );
  doc.close();
}

function ToppSync(toppId, _caller)
{
  if(!init)   return;
  if(_caller) caller = _caller;
  else caller = window;

  toppId = toppId.toLowerCase();

  if(toppId == 'wait' || toppId == 'noaction') return;

  //common main window default actions
  ToolTip.init();  //must recall this function to destroy the old tooltip DIV, since we re-write here with each change
  commonDiv.innerHTML  = '&nbsp;Common Questions&nbsp;';
  var SetStateFunc   = SetLoggedIn;
  var SetHitsDivFunc = HideDocHitsDiv;
  var SetBCrumbFunc  = BuildBreadCrumbs;
  allDivs.hide('infoadv');
  if( top.isPopWin )
  {
    SetStateFunc  = SetPopWin;
    top.document.title = caller.document.title;
  }

  switch( toppId )
  {
    case 'trialsign':
    case ''://do nothing
      if( !top.isPopWin ) SetStateFunc = NullFunc;
      if( isFixedWidth ) SetBCrumbFunc = NullFunc;
      break;

    case 'blank':
      SetStateFunc = SetBlank;
      break;

    case 'licagree':
      SetStateFunc = SetNotLoggedIn;
      SetHitsDivFunc = SetBCrumbFunc = NullFunc;
      break;
    
    case 'home':
      SetStateFunc = SetNotLoggedIn;
      SetBCrumbFunc = NullFunc;
      break;
    
    //do common default actions
    case 'start':
    case 'type':
    case 'typebook':
    case 'juris':
    case 'jurisbook':
    case 'treat':
    case 'treatbook':
      break;

    case 'search':
      commonDiv.innerHTML = "&nbsp;Expert Search Tips&nbsp;";
    case 'result':
      gPrevnextRes = new Object();
      break;
    
    case 'gcresult':
      if( caller && caller.PageHeader ) {
        allDivs.show( 'headerDiv' );
        headerDiv.innerHTML = caller.PageHeader();
      }
      break;
      
    case 'nobreadcrumbs':
      SetStateFunc = SetBlank;
      SetBCrumbFunc = NullFunc;
      break;

    case 'redocview'://---docviews
    case 'docview':
    case 'lwhitview':
    case 'lwdocvue':
      SetHitsDivFunc = CreateDocHitsDiv;
      allDivs.hide('headerDiv');//Hide GC header CR 5677
      break;          
    
    case 'blank' :
      toppId = 'none';
      break;

    default:
      alert("ERROR: Unknown toppId='ToppSync('"+ toppId +"', '"+ caller.location.href +")" );
  }
  SetStateFunc();
  SetBCrumbFunc(toppId,caller);
  SetHitsDivFunc(caller);

  //CheckWebsiteOutage();
  TopResize();
  CurrentState = toppId;
  
  if(Site=="MPS") { DisableFeaturesForPrison(); }
  if(isCinLawUser)
	{
    document.getElementById('MySavedSearchesSpan').style.visibility='hidden';
    document.getElementById('MySavedSearchesSpan').style.display='none';
 	}
 	    //ownership show/hides
    try{
      window.MyProducts = top.MyProducts;
      if( !MyProducts.HasBookDataType('CASELAW') ){
        allDivs.hide('FACDiv');
      }
    }catch(e){};//alert(e.description);} 	
}
function NullFunc(){};

function CurrentUpDown()
{
  var t = caller.document.body.scrollTop;       //doc y pos of top of current view
  var b = t + caller.document.body.clientHeight;//ch is current height of client frame window
  var on  = 'button';
  var off = 'bottomButtonInactive';
  hitButtons['pt'].className = ( t != 0 )? on : off; //page top
  hitButtons['pb'].className = ( caller['docHeight'] > b )? on : off;//page bottom
  var fhit = 0;
  var lhit = caller['docHeight'];
  if(gSpans.length)
  {
    fhit = gSpans[0]['ypos'];
    lhit = gSpans[gSpans.length-1]['ypos'];
  }
  hitButtons['up'].className = ( fhit < t )? on : off; //up hit
  hitButtons['dn'].className = ( lhit > b )? on : off; //down hit
  hitButtons['fh'].className = ((fhit < t ) || (fhit > b ) )? on : off; //first hit
  hitButtons['lh'].className = ((lhit < t ) || (lhit > b ) )? on : off; //last hit
}

function ChangeDocHitsDiv(url)
{
  //find element to scroll to...
  var dy = caller.document.body.scrollTop;   //doc y pos of top of current view, relative to top of doc
  var ch = caller.document.body.clientHeight;//ch is current height of client frame window
  var e;
  var pos = -0.5;
  switch(url)
  {
    //case 'pr''nr''pd''nd': disable();//turn off buttons when new doc is requested
    case 'pagetop':
    case 'pagebottom': caller.location.hash = url; break;
    case 'first': e = gSpans[0]; break;
    case 'last': e = gSpans[gSpans.length-1]; break;
    case 'up':
      //pos = -0.1; 
      for( var t=0; t < gSpans.length; t++)
      {
        if(gSpans[t]['ypos'] < dy ) e = gSpans[t];
        else break;
      }
      break;
    case 'dn':
      //pos = -0.9;
      for( var t=gSpans.length-1; t >= 0 ; t--)
      {
        if(gSpans[t]['ypos'] > (dy + ch))  e = gSpans[t];
        else  break;
      }
      break;
    default: e = caller.document.getElementById(url);
  }

	//if dochits span is hidden then we need to decrease the clientHeight so that the first hit is centered on the screen.
	if(document.getElementById('dochits').style.visibility=='hidden')
		ch -= 61;
  //scroll to the found element if e is not within the current view
  if(e && ((e['ypos']<dy) || (e['ypos']>(dy + ch - 25))) )//or lower than 25 px from bottom
  {
    e.scrollIntoView();//put at window top
    if( (e['ypos'] - (ch*pos)) < (caller.document.body.scrollTop + ch - 25 ) )//move to window center if possible
      caller.scrollBy(0,(ch*pos));
  }

  //no longer have to rewrite these every time... move them to hard coded AHTML at the bottom of the page
  var str = '';

  if(gPrevnextRes['prev'])//change href to call this func, so we can disable the buttons
    str += "&nbsp;<span id=pr class='button' onclick=\"javascript:caller.location.href='"+gPrevnextRes['prev'].href+"';\" "+MOToolTip('Previous document in result list')+">&nbsp;"+gPrevnextRes['prev'].text+"&nbsp;</span>&nbsp;"; else str += "&nbsp;<span class='bottomButtonInactive' "+MOToolTip('Previous document in result list')+">&nbsp;Prev. Result&nbsp;</span>&nbsp;";
  if(gPrevnext['prev'])
    str += "&nbsp;<span id=pd class='button' onclick=\"javascript:caller.location.href='"+gPrevnext['prev'].href+"';\" "+MOToolTip('Previous document in database' )+">&nbsp;"+gPrevnext['prev'].text+"&nbsp;</span>&nbsp;"; else str += "&nbsp;<span class='bottomButtonInactive' "+MOToolTip('Previous document in database' )+">&nbsp;Prev. Doc&nbsp;</span>&nbsp;";

  str += "&nbsp;<span id=pt class='button' onclick=\"javascript:ChangeDocHitsDiv('pagetop');\" "+MOToolTip('Top of Document')+">&nbsp;|&lt;&nbsp;</span>&nbsp;";

  if(gSpans.length == 0)
  {
    str += "&nbsp;<span id=td class='bottomButtonInactive' "+MOToolTip('First hit')+">&nbsp;&lt;&lt;&nbsp;</span>";
    str += "&nbsp;<span id=up class='bottomButtonInactive' "+MOToolTip('Previous hit(s)')+">&nbsp;&lt;&nbsp;</span>";
    str += "&nbsp;<span id=dn class='bottomButtonInactive' "+MOToolTip('Next hit(s)')+">&nbsp;&gt;&nbsp;</span>";
    str += "&nbsp;<span id=bd class='bottomButtonInactive' "+MOToolTip('Last hit')+">&nbsp;&gt;&gt;&nbsp;</span>&nbsp;";
  }
  else
  {
    str += "&nbsp;<span id=fh class='button' onclick=\"javascript:ChangeDocHitsDiv('first');\" "+MOToolTip('First hit')+">&nbsp;&lt;&lt;&nbsp;</span>";
    str += "&nbsp;<span id=up class='button' onclick=\"javascript:ChangeDocHitsDiv('up');\" "+MOToolTip('Previous hit(s)')+">&nbsp;&lt;&nbsp;</span>";
    str += "&nbsp;<span id=dn class='button' onclick=\"javascript:ChangeDocHitsDiv('dn');\" "+MOToolTip('Next hit(s)')+">&nbsp;&gt;&nbsp;</span>";
    str += "&nbsp;<span id=lh class='button' onclick=\"javascript:ChangeDocHitsDiv('last');\" "+MOToolTip('Last hit')+">&nbsp;&gt;&gt;&nbsp;</span>&nbsp;";
  }
  str += "&nbsp;<span id=pb class='button' onclick=\"javascript:ChangeDocHitsDiv('pagebottom');\" "+MOToolTip('Bottom of document')+">&nbsp;&gt;|&nbsp;</span>&nbsp;";


  if(gPrevnext['next'])
    str += "&nbsp;<span id=nd class='button' onclick=\"javascript:caller.location.href='"+gPrevnext['next'].href+"';\" "+MOToolTip('Next document in database')+">&nbsp;"+gPrevnext['next'].text+"&nbsp;</span>&nbsp;"; else str += "&nbsp;<span class='bottomButtonInactive' "+MOToolTip('Next document in database')+">&nbsp;Next Doc&nbsp;</span>&nbsp;";

  if(gPrevnextRes['next'])
    str += "&nbsp;<span id=nr class='button' onclick=\"javascript:caller.location.href='"+gPrevnextRes['next'].href+"';\" "+MOToolTip('Next document in result list')+">&nbsp;"+gPrevnextRes['next'].text+"&nbsp;</span>&nbsp;"; else str += "&nbsp;<span class='bottomButtonInactive' "+MOToolTip('Next document in result list')+">&nbsp;Next Result&nbsp;</span>&nbsp;";
  
  //add DocFields Jumpto here
  //str += "<span style='position:absolute;right:3px;'>"+DocFieldsGetHTML()+"</span>";
  str += DocFieldsGetHTML();
      
  allDivs.get('dochits').innerHTML = str;
  
  hitButtons = new elementCollection();
  hitButtons.add( 'fh','up','dn','lh', 'pt', 'pb', 'pr', 'pd', 'nr', 'nd' );
  if(gSpans.length && hitButtons ) CurrentUpDown();
}


var gSpans;
var gPrevnext;
var gPrevnextRes = new Object();
gDocFieldsOptions = "";
function ClearDocViewGlobals()
{
  hitButtons = null;
  allDivs.get('dochits').innerHTML = '';
  gSpans = new Array();
  gPrevnext = new Object();
  gPrevnextRes = new Object();
  gDocFieldsOptions = "";
}

function CreateDocHitsDiv(caller)
{
  ClearDocViewGlobals();

  //get search hit elements
  var spans;
  if(caller.document.all)// is IE
    spans = caller.document.all.tags('span');
  else // is NS
    spans = caller.document.getElementsByTagName('span');
  for( var t=0; t < spans.length; t++)
  {
    if( spans[t].id.match(/^hit\d+/i) )
    {
      spans[t]['ypos'] = GetElementY(spans[t]);//get y pos from top
      gSpans[gSpans.length] = spans[t];
    }
  }
  if( caller.QueryPrevDocUrl )
  {
    gPrevnext['prev'] = new Object();
    gPrevnext['prev']['href'] = caller.QueryPrevDocUrl();
    gPrevnext['prev']['text'] = 'Prev. Doc';
  }
  if( caller.QueryNextDocUrl )
  {
    gPrevnext['next'] = new Object();
    gPrevnext['next']['href'] = caller.QueryNextDocUrl();
    gPrevnext['next']['text'] = 'Next Doc';
  }
    
  if( caller.QueryPrevResultDocUrl )
  {
    gPrevnextRes['prev'] = new Object();
    gPrevnextRes['prev']['href'] = caller.QueryPrevResultDocUrl();
    gPrevnextRes['prev']['text'] = 'Prev. Result';
  }
  if( caller.QueryNextResultDocUrl )
  {
    gPrevnextRes['next'] = new Object();
    gPrevnextRes['next']['href'] = caller.QueryNextResultDocUrl();
    gPrevnextRes['next']['text'] = 'Next Result';
  }
  
  if(caller.DocFields){
    for(var o in caller.DocFields){
      var section = ((document.all)?caller.document.all.tags(o)[0]:caller.document.getElementsByTagName(o)[0]);
      if( ! section ){ //remove from list, the tag is not in the doc
        delete caller.DocFields[o];//don;t really need to do this, but...
      }else{
        if(o.match(/^GB$/i))gDocFieldsOptions += "<option value='"+o+"'>Jump To...</option>";
        else{
          gDocFieldsOptions += "<option value='"+o+"'>"+caller.DocFields[o]+"</option>";
          section.title = caller.DocFields[o];//FFx shows hover title, IE ignores. Also, FFx can style and select, IE won't.  //NOTES: For IE, the DOM parses LGML tags as singles, eg <OC> is not matched with the closing </OC> tage, they are inserted into the DOM as separate tages: <OC/> and </OC/>.  So, IE does allow styling and titles and such for LGML tags, but each tag has no display, like a <a name=x /> tag.
          try{ section.nextSibling.title = caller.DocFields[o]; }catch(e){}//IE kludge: works for all but nextSibleing = Text node
        }
      }      
    }
    if( gDocFieldsOptions.length > 1 ){
      gDocFieldsOptions = '<select class="dvSelect" onchange="DocFieldJumpTo(this.value)" >'
       + gDocFieldsOptions +'</select>';
    }
  }

  var b = caller.document.getElementById('Main');
  if(b) caller['docHeight'] = b.offsetHeight;
  ChangeDocHitsDiv('hit1');
  ShowDocHitsDiv();
  if(gSpans.length && hitButtons ) caller.onscroll = CurrentUpDown;
}
function DocFieldJumpTo(tag){
  var section = ((document.all)?caller.document.all.tags(tag)[0]:caller.document.getElementsByTagName(tag)[0]);
  section.scrollIntoView();//put at window top - works for FFx & IE7
}
function DocFieldsGetHTML(){
  return gDocFieldsOptions;
}

function ShowDocHitsDiv()  
{
  allDivs.show('dochits');
}
function HideDocHitsDiv()
{
  ClearDocViewGlobals();
  allDivs.hide('dochits');
}

function ExtractBreadCrumbs(bc) //for saving-loading favorites links
{
  bCrumbs = new BCS;
  var crumbs = bc.split("|"); //for each bc
  for( var b = 0; b < crumbs.length; b++ )
  {
    var newBC = new Object();
    var pairs = crumbs[b].split('\\'); //foreach object
    for(var i = 0; i < pairs.length; i++)
    {
      var nv = pairs[i].split(';');
      newBC[nv[0].toLowerCase()] = unescape(nv[1]); 
    }
    bCrumbs.insert(newBC); 
  }
}
function SaveBreadCrumbs() //for saving-loading favorites links
{
  var str = "topbchtml=";
  for(var i = 0; i < bCrumbs.count; i++)
  {
    for(var o in bCrumbs.bcs[i] )
    {
      if( o && o.match(/url|path|text|query/) )
        str += o +";"+ escape(bCrumbs.bcs[i][o]) +"\\";
    }
    str = str.replace(/\\$/,"") + "|";
  }
  return str.replace(/\|$/,"");
}
function AppendBreadCrumbs(url) //for saving-loading favorites links
{
  var host = url.replace(/^([^:]+:\/\/[^\/]+)\/.*/,"$1");
  var path = url.replace(/^[^:]+:\/\/[^\/]+(\/.*)/,"$1");
  if(path.match(/^\/pns\//)) host += "/pns/index.htp?content=";
  else  host += "/index.htm?content=";
  if( path.match(/\?/) )
    return host + path + "&" + SaveBreadCrumbs();
  return host + path + "?" + SaveBreadCrumbs();
}
function LoadBreadCrumbsStr(win) //for saving-loading favorites links
{
  var w = (win)?win:window;
  var pairs = GetSearchPairs(w);
  if(pairs['topbchtml'])
  {
    ExtractBreadCrumbs(pairs['topbchtml']);
    return true;
  }
  return false;
}
function BuildBreadCrumbs(topid, caller)
{
  var bchtml = "";
  //if(! LoadBreadCrumbsStr(caller) ) //for loading favorites links
  //{
   if( topid == 'none' ) { allDivs['breadcrumbdiv'].innerHTML = ''; return; }
   if( !bCrumbs.count && !top.isPopWin )//always have a start page 
   {
     var start = new Object();
     start.url = '/pns/start.htp';
     start.text = 'Start Page';
     start.path = start.url;
     bCrumbs.insert(start); 
   }
   bCrumbs.insert(new BC(caller));
  //}
  bchtml += "<div style='padding:3px;'>";
  for(var i = 0; i < bCrumbs.count; i++)
  {
    if(bCrumbs.bcs[i].path.match(/^\/pns\/start\.htp/i)) //start link is always active
      bchtml += bCrumbs.getLink(i);
    else if( i == (bCrumbs.count - 1))//last link
      bchtml += bCrumbs.getLinkCurrent(i)
    else
      bchtml += bCrumbs.getLink(i);
  }
  bchtml += "</div>" + GeckoSpaceStr();//ns doesn't auto pad the bottom
  allDivs['breadcrumbdiv'].innerHTML = bchtml;//this is where we might want to do nice delete[] for all DHTML objects...
}
//---------------------------------------  
function BC(caller)
{
  this.caller= caller;
  this.url   = caller.location.href;
  this.path  = caller.location.pathname.toLowerCase();
  this.query = (caller.NVPairs || caller.location.search); //var search = (NVPairs || location.search);
  this.NVPairs = GetSearchPairs(caller);//can also find POST data if NVPairs is defined in the calling template
  //used in BCS.getLink(i) calls
  if( !this.path.match(/.htp$/) || this.query.length < 2048 ){//use GET for .htm or short .htp queries 
    this.method = "GET";
    if(caller.location.search.length == 0 && this.query.length != 0){//incase the orignal was a short post 
      this.url += "?"+this.query;
    }
  }//otherwise use POST for this.method
  this.text = '';//fill in descending default order
  if( this.text == '' ) this.text = caller.document.title;
  if( this.text == '' ) this.text = top.defaultStatus;
  if( this.text == '' ) this.text = this.path;//page has no title!
}

//---------------------------------------
function BCS()
{
  this.count = 0;
  this.bcs = new Array();
  
  this.insert = function(bc)
  {
    bc.path = bc.path.replace(/\/\//g,"/");//server treats consec slashes as single slash
    if( ! this.replace(bc) )
    {
      this.bcs[this.count] = bc;
      this.count++;
    }
    this.RemoveSWASErrors(bc);
  }
  this.replace = function(bc)
  {
    for(var i=0; i < this.count; i++)
    { 
      if( this.bcs[i] && bc.path == this.bcs[i].path )
      {
        if( ! this.CheckSWASReplace(bc, this.bcs[i] ) ) //for SWAS 
          continue;
        if( bc.path.match(/tcresult\.htp/i) && bc.text != this.bcs[i].text ) //for toc breadcrumbs
          continue;
        this.bcs[i] = bc;
        this.CheckSetNewSearch(i);//add special case to clear saved user search terms
        this.check
        this.count = i + 1;
        this.bcs = this.bcs.slice(0,this.count);  //remove forward crumbs
        return true;
      }
    }
    return false;
  }
  this.CheckSWASReplace = function(newBC, oldBC)
  {
    //Different SWAS pages have same path, must check query string (but ignore respage and hidesummary)
    if(newBC.path.match(/result\.htp/i) && prevSearches.length > 0){
      var cnt = GetSearchPairs(caller)["swascnt"];
      if(cnt){      //SWAS result page
        //newBC.text = "SWAS #" + cnt + " " + caller.document.title;

        if(newBC.query.replace(/&resstart=[^&]*|&respage=[^&]*|&hidesummary=[^&]*/gi,"")
        == oldBC.query.replace(/&resstart=[^&]*|&respage=[^&]*|&hidesummary=[^&]*/gi,"")
        )
          prevSearches.length = cnt; //been here before, replace & truncate prevSearches
        else
          return false; //different (or new) SWAS page, don't replace //continue;
      }
      else{   //non-SWAS result page, dump SWAS
        prevSearches.length = 0;
        SearchParamsObj["prevSrcQuery"]="";
      }
    }
    if(newBC.path.match(/doclink\.htp/i) && GetSearchPairs(caller)["isresult"] == 1){
      return false;
    }
    return true; //replace
  }
  this.RemoveSWASErrors = function(bc)
  {
    //if new bc is a result page, remove searchswas (error) pages
    if(bc.path.match(/result\.htp/i)){
      for(var t=0; t < this.count; t++){
        if( this.bcs[t].path.match(/searchswas\.htp/i) ){
          this.bcs.splice(t,1);
          this.count--;
        }
      }
    }
  }
  this.CheckSetNewSearch = function(i)
  {
    SearchParamsObj["boolOldSearch"] = false;
    for(var t=i+1; t < this.count; t++)
    {
      //see if search.htp is in forward breadcrumbs to be deleted, if so, clear saved user search terms
      if( this.bcs[t].path.match(/search\.htp/i) ){
        SearchParamsObj["boolNewSearch"]=true;
        prevSearches.length=0;
      }
      //see if result.htp is in forward breadcrumbs, if so, clear old search error messages
      if( this.bcs[t].path.match(/result\.htp/i) )
        SearchParamsObj["boolOldSearch"] = true;
    }
  }
  this.getHref = function(i)
  {
    return this.bcs[i].url;
  }
  this.getPath = function(i)
  {
    return this.bcs[i].path;
  }  
  this.getQuery = function(i)
  {
    return this.bcs[i].query;
  }
  this.getNVPairs = function(i)
  {
    return this.bcs[i].NVPairs;
  }      
  this.getText = function(i)
  {
    return this.bcs[i].text;
  }
  this.getLink = function(i)
  {
    if(this.count > i){ 
      var html = "";
      if( this.bcs[i].method == "GET" ){
        html = "<span class='menuitemcurrent' style='padding:0px;padding-top:4px;'>&gt;</span>"
        +"<span class='menuitemactive'>"
        +"<a href=\""+this.getHref(i)+"\" target=content "+MOStatus(this.getText(i))+">"
        +"<span class='menuitemactive'>" +this.getText(i)+"</span></a></span>";
      }else{
        //change to javascript form submit: this.bcs[i].form.submit(); -- also may need to delete[] all the forms from the DOM during replace
        //NOTE: we can swithc off query.length > 2048 for POST actions, all others can still be GET
        //Also, we can;t do POST to htm pages
        var html = '<span class="menuitemcurrent" style="padding:0px;padding-top:4px;">&gt;</span>'
          +'<form id="BC'+i+'" name="BC'+i+'" method="POST" action="'+this.getPath(i)+'" target="content" style="display:none;">';
        var pairs = this.getNVPairs(i);
        for(var p in pairs){
          if(p.length)
            html += '<input type="text" name="'+p+'" value="'+ (pairs[p]).replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/&/g,"&amp;").replace(/\"/g,"&quot;").replace(/\'/g,"&#39;") +'">'; //XMLEscape
        }
        html += '</form><span class="menuitemactive" onclick="document.BC'+i+'.submit();">' +this.getText(i)+'</span>';
      }
      //alert(html);
      return html;
    }
    return '';
  }
  this.getLinkCurrent = function(i)
  {
    if(this.count > i)
      return "<span class='menuitemcurrent' style='padding-bottom:0px;padding-top:4px;'>"+ GetBullet() + " " +this.getText(i)+"</span>";
      //return "<span class='menuitemcurrent' style='padding-bottom:0px;padding-top:4px;'><span style='color:red;font-size:25px;line-height:5%;'>&bull;</span>"+ " " +this.getText(i)+"</span>";
    return '';
  }
  this.getLinkDisabled = function(i)
  {
    if(this.count > i)
      return "<span class='menuitemdisabled'>&gt;" +this.getText(i)+"</span>";
    return '';
  }
}

//---------------------------------------
function WriteSchoolLink()
{
  if( Site != 'SCHOOL' )
		document.write(" |&nbsp;<a href='http://www.loislawschool.com?linkid=menu_llawschool' target='_top' "+MOStatus('Loislawschool')+">&nbsp;Loislawschool</a>");
}
//---------------------------------------

function CollapseTopFrame(collapse)
{
	var isDochitsVisible = document.getElementById('dochits').style.visibility;
	allDivs.hideAll();
  if(collapse=="hide")
  {
    if(isDochitsVisible=='visible')
      allDivs.show('Main', 'collapseDiv', 'breadCrumbDiv', 'collapseDiv', 'collapseLogoDiv', 'collapseFACDiv', 'showMenuDiv', 'dochits' );
    else
    	allDivs.show('Main', 'collapseDiv', 'breadCrumbDiv', 'collapseDiv', 'collapseLogoDiv', 'collapseFACDiv', 'showMenuDiv');
  }
	else
	{
	  if(isDochitsVisible=='visible')
	  	allDivs.show('Main', 'ancillaryMembersDiv', 'logoDiv', 'membersNavLinks', 'breadCrumbDiv', 'FACDiv', 'hideMenuDiv', 'dochits', 'productdiv', 'statelogodiv' );
	  else
	  	allDivs.show('Main', 'ancillaryMembersDiv', 'logoDiv', 'membersNavLinks', 'breadCrumbDiv', 'FACDiv', 'hideMenuDiv', 'productdiv', 'statelogodiv' );
	}
	TopResize();
}

function GoHome(linkid)
{
  var url;
  if( top.topp.UserDeclineLicAgree ){ //CR 1800
  	parent.top.document.location.href='/?logout=true';
  }
  else if( typeof infoAdvIsOpen != 'undefined' && infoAdvIsOpen==true )
  	parent.top.location.href = "/";
	else{
		url = "/?ShowHomePage=true";
		if(linkid!="" && typeof linkid != "undefined")
		  url += "&linkid=" + linkid;
		parent.top.document.location.href = url;
	}
}

function DisableFeaturesForPrison()
{
  var membersNavLinksDiv, retval;
  membersNavLinksDiv = document.getElementById('membersNavLinks');
  retval = "<a href=\"javascript:openSavedSearchWindow();\" onmouseover=\"return SetStatus('My Saved Searches');\" onmouseout=\"return ResetStatus('');\">&nbsp;My Saved Searches&nbsp;</a>&nbsp;&nbsp;";
  retval += "<a href=\"javascript:openCQWindow()\" onmouseover=\"return SetStatus('Common Questions');\" onmouseout=\"return ResetStatus('');\" id=\"common_q\">&nbsp;";
  if(CurrentState=="search")
    retval += "Expert Search Tips&nbsp;</a>&nbsp;&nbsp;";
  else
    retval += "Common Questions&nbsp;</a>&nbsp;&nbsp;";
  retval += "<a href=\"/pns/logout.htp\" target='content' onmouseover=\"return SetStatus('Logout from Loislaw');\" onmouseout=\"return ResetStatus('');\">&nbsp;Log Out&nbsp;</a>&nbsp;&nbsp;";
  membersNavLinksDiv.innerHTML = retval;

  allDivs.hide('ancillaryMembersDiv');
  allDivs.hide('hideMenuDiv');
  //allDivs.hide('membersNavLinks');
}

function SetUserName(n)
{
  userName = n;
  var userNameSpan = document.getElementById('userNameSpan');
  userNameSpan.innerHTML = n;
  allDivs['productdiv'].style.width="150px";
}

function SetUserProduct(p)
{
  userProduct = p;
  var userProductSpan = document.getElementById('userProductSpan');
  if(userProductSpan) userProductSpan.innerHTML = p;
}

function SetStateLogoImg(imageName)
{
	stateLogoImg = "<img src='http://image.loislaw.com/prosite/misc/" + imageName + "' border='0'>";
  allDivs['statelogodiv'].innerHTML = stateLogoImg;
}

