//document.domain = 'loislaw.com';

var EStore = "estore.loislaw.com";
var EStoreHttps = "https://";
var EStoreHttp  = "http://";
switch(location.hostname.toLowerCase()){
  case 'www.loislaw.com': break;
  case 'www.loislawschool.com': break;
  case 'appl002.loislaw.com': EStore = "appl002.loislaw.com:81";EStoreHttp="http://"; EStoreHttps="http://";break;
  case 'stage.loislaw.com': EStore = "stage.loislaw.com";EStoreHttp="https://"; EStoreHttps="https://";break;
  case 'wwwdino.loislaw.com': EStore = "estoredino.loislaw.com";EStoreHttp="http://"; EStoreHttps="http://";break;
  case 'dino.loislaw.com': EStore = "estoredino.loislaw.com"; break;
  case 'nasrvri95320.loislaw.com': break;
  case 'wwwtest.loislaw.com': break;
  default: if(location.hostname.toLowerCase().match(/www/)) EStore = location.hostname.replace(/www/i,"estore");
}
var EStoreHost       = EStoreHttps + EStore;
var EStoreHostHttp   = EStoreHttp  + EStore;
var DebugEstoreHost  = EStoreHost;

//var DebugEstoreHost = "https://estore.loislaw.com";
//var DebugEstoreHost = "http://estoredino.loislaw.com";
//var EStoreHost = ((typeof DebugEstoreHost!='undefined')?DebugEstoreHost:"https://estore.loislaw.com");
addEvent(window, "onload", SetDebugEstoreHost);
addEvent(window, "onload", SetAllLinkStatus);

//CR 5678,5692 - Workaround fix for numerous references to top.opener when top.opener is a 3rd party window (widget host)
try{ if( top && top.opener ) top.opener.LLW658ba8cafa794bbb931380e55d581386 = null; }catch(e){ top.opener = null; }
try{ if( window.opener ) window.opener.LLW658ba8cafa794bbb931380e55d581386 = null; }catch(e){ window.opener = null; }

/*
    The global object JSON contains two methods.

    JSON.stringify(value) takes a JavaScript value and produces a JSON text.
    The value must not be cyclical.

    JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
    throw a 'JSONError' exception if there is an error.
*/
var JSON = {
    copyright: '(c)2005 JSON.org',
    license: 'http://www.crockford.com/JSON/license.html',
/*
    Stringify a JavaScript value, producing a JSON text.
*/
    stringify: function (v) {
        var a = [];

/*
    Emit a string.
*/
        function e(s) {
            a[a.length] = s;
        }

/*
    Convert a value.
*/
        function g(x) {
            var c, i, l, v;

            switch (typeof x) {
            case 'object':
                if (x) {
                    if (x instanceof Array) {
                        e('[');
                        l = a.length;
                        for (i = 0; i < x.length; i += 1) {
                            v = x[i];
                            if (typeof v != 'undefined' &&
                                    typeof v != 'function') {
                                if (l < a.length) {
                                    e(',');
                                }
                                g(v);
                            }
                        }
                        e(']');
                        return;
                    } else if (x instanceof Date) {
                        e('new Date('+x.valueOf()+')');
                        return;
                    } else if (typeof x.valueOf == 'function') {
                        e('{');
                        l = a.length;
                        for (i in x) {
                            v = x[i];
                            if (typeof v != 'undefined' &&
                                    typeof v != 'function' &&
                                    (!v || typeof v != 'object' ||
                                        typeof v.valueOf == 'function')) {
                                if (l < a.length) {
                                    e(',');
                                }
                                g(i);
                                e(':');
                                g(v);
                            }
                        }
                        return e('}');
                    }
                }
                e('null');
                return;
            case 'number':
                e(isFinite(x) ? +x : 'null');
                return;
            case 'string':
                l = x.length;
                e('"');
                for (i = 0; i < l; i += 1) {
                    c = x.charAt(i);
                    if (c >= ' ') {
                        if (c == '\\' || c == '"') {
                            e('\\');
                        }
                        e(c);
                    } else {
                        switch (c) {
                        case '\b':
                            e('\\b');
                            break;
                        case '\f':
                            e('\\f');
                            break;
                        case '\n':
                            e('\\n');
                            break;
                        case '\r':
                            e('\\r');
                            break;
                        case '\t':
                            e('\\t');
                            break;
                        default:
                            c = c.charCodeAt();
                            e('\\u00' + Math.floor(c / 16).toString(16) +
                                (c % 16).toString(16));
                        }
                    }
                }
                e('"');
                return;
            case 'boolean':
                e(String(x));
                return;
            default:
                e('null');
                return;
            }
        }
        g(v);
        return a.join('');
    },
/*
    Parse a JSON text, producing a JavaScript value.
*/
    parse: function (text) {
        //return (/^(\s+|[,:{}\[\]]|"(\\["\\\/bfnrtu]|[^\x00-\x1f"\\]+)*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null)+$/.test(text)) &&
        //    eval('(' + text + ')');
        return (/^(\s+|[,:{}\[\]]|"(\\["\\\/bfnrtu]|[^\x00-\x1f"\\]+)*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null|new Date\(\d+\))+$/.test(text)) &&
            eval('(' + text + ')');            
    }
};



//Cross-Browser Event Handlers
function addEvent(obj, evType, fn, useCapture){
  if(typeof obj == 'object' && typeof fn == 'function' && typeof evType == 'string' ){
    evType = evType.replace(/^on/i,"").toLowerCase();
    if (obj.addEventListener){
      obj.addEventListener(evType, fn, useCapture);
      return true;
    }else if (obj.attachEvent){
      return obj.attachEvent("on"+evType, fn);
    }
  }
  return false;//Handler could not be attached
}

function removeEvent(obj, evType, fn, useCapture){
  if(typeof obj == 'object' && typeof fn == 'function' && typeof evType == 'string' ){
    evType = evType.replace(/^on/i,"").toLowerCase();
    if (obj.removeEventListener){
      obj.removeEventListener(evType, fn, useCapture);
      return true;
    }else if (obj.detachEvent){
      return obj.detachEvent("on"+evType, fn);
    }
  }
  return false;//Handler could not be attached
}


function GetTopMainWindow(w){//get Main top-most window for stashing global or singlton objects
  try{ //BUG NOTE: Firefox doesn't supply w.opener for rightclick context menu "Open in new Window"
    if(!w) w = window;
    var win = ((w.opener)?w.opener.top:top);
    if(win.opener)
      return GetTopMainWindow(win);
    //test for read/write permissions: we can find top win from other domains, but not access it's properties
    win._GetTopMainWindow_test = new Object(); delete win._GetTopMainWindow_test;
    return win;
  }catch(e){return top;}
}
//Need to fixt this for non-owning opernet windows (eg, widget deployments
function GetFrames(win){ //return a flat array of named frames (note:duplicates overwrite previous named frame)
try{
  if(!win) win = top;
  var MyFrames = new Object();
  function CollectFrameObjects(win,MyFrames){
    var name = win.id = win.name = (win.id||win.name);
    MyFrames[String(name).toLowerCase()] = win;
    for(var i=0; i< win.frames.length; i++){
      CollectFrameObjects(win.frames[i],MyFrames);
    }
  }
  CollectFrameObjects(win,MyFrames);
}catch(e){}
  return MyFrames;
}
var MyFrames = GetFrames();
function GetFrameById(name){ try{return MyFrames[String(name).toLowerCase()];}catch(e){return null;} }
function GetFrameByName(name){ try{return MyFrames[String(name).toLowerCase()];}catch(e){return null;} }

var is = new Is();
var isIE   =(navigator.appName == "Microsoft Internet Explorer");
var isNav  =(navigator.appName == "Netscape");
var agt    = navigator.userAgent.toLowerCase();

var Site = "MAIN";
if( top.location.href.indexOf("loislawschool.com") >= 0 ){
  Site = "SCHOOL";
} else if( top.location.href.indexOf("mps.loislaw.com") >= 0){
  Site = "MPS";
} else if( top.location.href.indexOf("loislawps.com") >= 0){
  Site = "MPS";
} else if( top.location.href.indexOf("http://production.loislaw.com") >= 0){
  Site = "PROD";  
} else if( top.location.href.indexOf("http://ecom.loislawschool.com") >= 0){
  Site = "SIGNUP";
}
function GetHomeDirURL()
{
  var home  = top.location.hostname;
  var path  = top.location.pathname;
  if(path.match(/^\/advsrnysba/) ){ home += '/advsrnysba';}
  else if(path.match(/^\/nysba/) ){ home += '/nysba';}
  else if(path.match(/^\/fhfl/) ) { home += '/fhfl';}
  else if(path.match(/^\/bhba/) ) { home += '/bhba';}
  else if(path.match(/^\/judlib/) || home.match(/online.aspenpublishers.com/))
    home = 'online.aspenpublishers.com/judlib';

  return "http://"+ home +"/";
}
function Is() {
  var agt=navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('aol')==-1));
  this.navonly = (this.nav && ((agt.indexOf(';nav') != -1) || (agt.indexOf('; nav') != -1)) )
  this.nav2 = (this.nav && (this.major == 2));
  this.nav3 = (this.nav && (this.major == 3));
  this.nav4 = (this.nav && (this.major == 4));
  this.nav406 = (this.nav && (this.minor == 4.06))
  this.nav407 = (this.nav && (this.minor == 4.07))
  this.nav408 = (this.nav && (this.minor == 4.08))
  this.nav4up = (this.nav && (this.major >= 4));
  this.nav6 = (this.nav && (this.major == 5));
  this.nav6up = (this.nav && (this.major >= 5))
  this.ie   = (agt.indexOf('msie') != -1);
  this.ie3  = (this.ie && (this.major < 4));
  this.ie4  = (this.ie && (this.major == 4) && (agt.indexOf('msie 5')==-1) );
  this.ie4up  = (this.ie  && (this.major >= 4));
  this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf('msie 5')!=-1) );
  this.ie501 = (this.ie && (this.major == 4) && (agt.indexOf('msie 5.01')!=-1) );
  this.ie55  = (this.ie && (this.major == 4) && (agt.indexOf('msie 5.5')!=-1) );
  this.ie5up = (this.ie && (this.major >= 5));
  /*
  we count the AOL version based on the IE component because sometimes AOL n.x == IE (n-1).x
  i've actually seen AOL 4 with an IE 3 component and AOL 3 with an IE 4 component before.
  since the IE component is the web page displayer, we set our variables based on it and hope they coincide.
  */
  this.aol   = (agt.indexOf('aol') != -1);
  this.aol3  = (this.aol && this.ie3);
  this.aol4  = (this.aol && this.ie4);
  this.aol5 = (this.aol && (this.ie5 || this.ie501));
  this.aol6 = (this.aol && this.ie55); /* what's in a version number anyway? */
  this.opera = (agt.indexOf('opera') != -1);
  this.opera3 = (this.opera && (this.major == 3) );
  this.opera4 = (this.opera && (this.major == 4) );
  this.webtv = (agt.indexOf('webtv') != -1);
  this.safari = (agt.indexOf('safari') != -1 && agt.indexOf('macintosh') != -1);
  this.iemac = (agt.indexOf('mac_powerpc') != -1 && agt.indexOf('msie 5.23') != -1);
}

//----------------------------------
//function SetKeyHandlerVariables()
//----------------------------------
function SetKeyHandlerVariables()
{
  addEvent(document,"onkeypress",SubmitSearchKey);
}
function SetSubmitEnterKey(){
  addEvent(document,"onkeypress",SubmitEnterKey);
}
function SubmitSearchKey(e){
  if(!IsSyncState('bottom','wait')){
    SubmitEnterKey(e);
  }
}
function SubmitEnterKey(e){
  e = (e||window.event);
  var key = (e.which||e.keyCode);
  if( key == 13 ){ //find which element has focus, submit it's parent form, submit default form, or do nothing
    var el = (e.srcElement||e.target);
    if( el.onclick && typeof(el.onclick)=="function" ){ el.onclick(); }
    else if( el.form && typeof(el.form.onsubmit)=="function" ){ 
	    el.form.onsubmit();
      if(el.form.onsubmit.toString().match(/cmAlter/)) el.form.submit(); //coremetrics hijacked onsubmit, but does't call submit!
    }
    else if( el.form ){ el.form.submit(); }
    else if( document.FormOne && typeof(document.FormOne.onsubmit)=="function" ){ document.FormOne.onsubmit(); }
    else if( document.FormOne ){ document.FormOne.submit(); }
    else return true; //didn't find a form method to submit
    return (e.which)?e.preventDefault():false;
  }
  return true;
}


//==============================================================
function openWin(url,w,h)
{
  if( Site == "MPS" )
    window.open(url, "newWin", "toolbar=no,width="+w+",height="+h+",status=no,scrollbars=yes,resizable=yes,menubar=no");
  else
    window.open(url, "newWin", "toolbar=yes,width="+w+",height="+h+",status=yes,scrollbars=yes,resizable=yes,menubar=yes,location=yes");
}
function GiveFocus(a,reload){ 
  //USAGE: <a target="mywin" onclick="return GiveFocus(this)">
  //If alink named target window is already open and out of focus, 
  //Browser default is to reload the target but not bring into focus.
  //This function creates a global reference so focus
  //can be restored whenever the link is clicked (with/wout reload href)
  if(a.target){
    if(top[a.target]){ //change to GetTopMainWindow()
      try{ 
        top[a.target].focus();
        if(reload) return true;
        return false;
      }catch(e){}
    }
    try{ 
      top[a.target] = window.open(a.href, a.target);
      top[a.target].focus();
      return false;
    }catch(e){}
  }
  return true;  
}

//Tracking Functions
function NewGUID(){
  function S4(){ return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }
  return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()).toUpperCase();
}
var cdomain = (location.host.replace(/^.*\.([^.]+\.[^.]+$)/,"$1")||location.host).toLowerCase();
var SessionTracker = new CookieObj("LLTrack", null, 100000, "/", cdomain);
if(!SessionTracker.get()){
  SessionTracker['tguid'] = NewGUID();
  SessionTracker.set();
}

function MasterSync(toppId, bottomId, caller, title )
{
  try { document.execCommand("BackgroundImageCache",false,true); } catch(e) {};
  
  if(title && title != '')
    SetDefStatus(title);
  else
    SetDefStatus();
  if( top.topp && top.topp.ToppSync )
    top.topp.ToppSync(toppId, caller);
  if( top.bottom && top.bottom.BottomSync )
    top.bottom.BottomSync(bottomId, caller);
  if(top==self)//CR3517 && parent.frames.length<1) //reload into framed env
  {
    var search = ((typeof(top.NVPairs)!='undefined')?top.NVPairs: top.location.search);
    var ppairs = GetCookie("loginpost"); //get login post pairs...NOTE: loginpost cookie CAN'T BE DELETED is set by estore.signinlois page!
    if(ppairs)
    {
      DelCookie( "loginpost" );
      //search = ppairs;
    }
    if(top.location.pathname.match(/^\/pns/i) ){
      var curl = "/pns/index.htp?content=" + top.location.pathname +"&"+ search.replace(/^\?/,""). //CR 3121
      replace(/&username=[^&]*/gi,"").replace(/&password=[^&]*/gi,"").replace(/%20/g,"+");  //CR 3390;
      top.location.href = curl;
    }
    //else{
    //  top.location.href = "/index.htm?content=" + top.location.pathname + search.replace(/^\?/,"&");  //CR 3121
    //}
  }
  DelCookie( "loginpost" );//make sure we ditch this, we only need it one time after login page
  if(window.focus) { window.focus(); }
}

function GetContentFrame( defContentPage )//called by frames pages to get content url
{
  var search = ((typeof(NVPairs)!='undefined')?NVPairs: location.search);
  var contentUrl = defContentPage;
  if( search.match(/^\?content=/i) )
    contentUrl = search.replace(/^\?content=/i,"");
    if(!contentUrl.match(/\?/))//backward compat w/ extern links
      contentUrl = contentUrl.replace(/&/,"?");  //CR 3121
  return contentUrl;
}
function CheckUrl()//called by frames page (depreciated)
{
  var search = ((typeof(NVPairs)!='undefined')?NVPairs: location.search);
  if( search.match(/^\?content=/i) )
  {
    var contentUrl = search.replace(/^\?content=/i,"");
    if( parent.content.location.href != contentUrl )
    {
      parent.content.location.href=contentUrl;
    }
  }
}
function GetSearchPairs(win)
{
  var pairs = new Object();
  var w = (win && win.location)?win:window;
  //look for HTP generated POST pairs object first, if not found, use location.search
  var search = ((typeof(w.NVPairs)!='undefined')?w.NVPairs: w.location.search);
  var n = search.replace(/^\?/,"").split("&");
  for(var i=0; i < n.length; i++)
  {
    var nv = n[i].split("=");
    pairs[nv[0].toLowerCase()] = unescape( ((nv[1])?nv[1]:"") );
  }
  return pairs;
}
function GetSearchPairsLength(pairs){
  var cnt = 0;
  if(pairs){
    for(var o in pairs){ if(o) cnt++;}
  }
  return cnt;
}

function GetSyncState( winName )
{
  if( window.parent[winName] && window.parent[winName].CurrentState )
    return window.parent[winName].CurrentState;
  return 'unknown';
}
function IsSyncState( winName, checkStr )
{
  var state = GetSyncState( winName );
  if( state.toLowerCase() == checkStr.toLowerCase() )
    return true;
  return false;
}

//Window Status Functions
function SetDefStatus( message )
{
  if(message && message != '')
    top.defaultStatus = message;
  else if(parent.content)
  {
    var c = parent.content;

    if(c.document.title != '')
    {
      top.defaultStatus = c.document.title;
    }
    else
      top.defaultStatus = document.title
  }
  self.status = top.defaultStatus;
  return true;
}
function SetDebugEstoreHost(){//for dev environments
	if( typeof DebugEstoreHost == 'string' && DebugEstoreHost.length ){
	  var e;
	  for(var i=0; i < document.links.length; i++){
	    e = document.links[i];
	    if(e.href && e.href.match(/^https?:\/\/estore.loislaw.com/)){
		    e.href = e.href.replace(/^https?:\/\/estore.loislaw.com(:\d+){0,1}/, DebugEstoreHost);
	    }
	  }
	  for(var i=0; i < document.forms.length; i++){
	    e = document.forms[i];
	    if(e.action && e.action.match(/^https?:\/\/estore.loislaw.com/i)){
		    e.action = e.action.replace(/^https?:\/\/estore.loislaw.com(:\d+){0,1}/i, DebugEstoreHost);
	    }
	  }
	  //add onclick replacements
	  //for jsfunction replacements, use: EStoreHost (defined at top of this file)
  }
}
function SetAllLinkStatus(){
  var link;
  for(var i=0; i < document.links.length; i++){
    link = document.links[i];
    addEvent(link,"onmouseover",SetStatusLink);
    addEvent(link,"onmouseout",ResetStatus);
  }//can do the same for span class=button
}
function SetStatusLink(evt){
  var theLink = (evt.srcElement||evt.rangeParent.parentNode); //IE||NS
  return SetStatus( (theLink.title||theLink.innerHTML) );  
}
function SetStatus( message )
{
  self.status = (message && message.replace)?message.replace(/<\/{0,1}[^>]+>/gi,""):""; //html markup
  return true;
}
function ResetStatus()
{
  self.status = top.defaultStatus;
  return true;
}
function MOStatus(message)
{
  if(!message || message == '')
    message = top.defaultStatus;

  message = message.replace(/(\'|\")/g,'');
  return "onmouseover=\"return SetStatus('"+message+"');\" onmouseout=\"return ResetStatus();\"";
}

function MOToolTip(message)
{
  if(!message || message == '')
    return "";

  return "onmouseover=\"doToolTip( event, '"+message+"' ); return true;\" onmouseout=\"hideTip()\"";
}


function ClientWidth()
{
  var x;
  if( isIE || is.iemac )
    x = document.body.clientWidth;
  else
    x = window.innerWidth;
  return x;
}

function ClientHeight()
{
  var x;
  if( isIE || is.iemac ){
    x = document.body.clientHeight;
  }else{
    x = window.innerHeight;
  }
  return x;
}

var MaxWidth;
var MinWidth;
var MainDiv;

function SetResize( wid, fix )
{
  if( !fix )
    fix = false;
  if( wid )
    MaxWidth = wid;
  else
    MaxWidth = 770;
    
  MainDiv = document.getElementById('Main');
  if( MainDiv ){
    if( fix ){
      MainDiv.style.width = (MaxWidth+ 'px');
    } else{
      Resize();
      window.onresize = Resize;
    }
  }
}
function Resize()
{
  var  MainDiv = document.getElementById('Main');
  if( MainDiv ){
    var width = ClientWidth();
    if( width > MaxWidth )
      MainDiv.style.width = (MaxWidth+ 'px');
    else
      MainDiv.style.width = '99%';
  }
}
function SetMinMaxResize( min, max )
{ //inputs:
  // min or max param == 0? no respective limit is set
  // min==max && neither == 0? set a constant fixed width MainDiv
  // max != 0? div will resize if window is smaller and stay fixed at max if larger
  // min != 0? div will resize if window is larger and stay fixed at min if smaller

  //add error check for non-numeric params

  MainDiv = document.getElementById('Main');
  if( MainDiv )
  {
    window.onresize = function()
    {
      var width = ClientWidth();
      if((max > 0)&&(width > max))
        MainDiv.style.width = '' + max + 'px';
      else if((min > 0)&&(width < min))
      {
        MainDiv.style.width = '' + min + 'px';
      }
      else
        MainDiv.style.width = '100%';
    }
    window.onresize();//set the width
  }
}

function LoisEscape(input_str)
{
  input_str = escape(input_str);
  return input_str.replace(/%20/g,"+");
}

function LoisUnescape(input_str)
{
  input_str.replace(/"+"/g,"%20");
  return unescape(input_str);
}
function XMLEscape(s){ return s.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/&/g,"&amp;").replace(/\"/g,"&quot;").replace(/\'/g,"&apos;"); }
function AttrEscape(s){return s.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/&/g,"&amp;").replace(/\"/g,"&quot;").replace(/\'/g,"&#39;"); } //for <tag attribute=""> values.  IE does not recognize &apos; but all browsers convert &#39; into the correct char

//-----------------------------
// UI Display functions
//-----------------------------
// optional "win" param allows access to elements in other docs or windows. default = self
function GetE(str, win){ if(str && str.nodeType && str.nodeType==1 )return str; return GetDoc(win).getElementById(str); }
function HideE(str, win){ e = GetE(str, GetDoc(win)); if(e){e.style.visibility="hidden"; e.style.display="none";}}
function ShowE(str, win){ e = GetE(str, GetDoc(win)); if(e){e.style.visibility="visible"; e.style.display="block";}}
function HideSpan(str, win){ HideE(str,win); }
function ShowSpan(str, win){ e = GetE(str, GetDoc(win)); if(e){e.style.visibility="visible"; e.style.display="inline";}}
function HideEin(str, win){ e = GetE(str, GetDoc(win)); if(e){e.style.visibility="hidden";  }}// do not remove for layout
function ShowEin(str, win){ e = GetE(str, GetDoc(win)); if(e){e.style.visibility="visible"; }}// do not remove for layout
function ToggleE(str, win){ e = GetE(str, GetDoc(win)); if(e){if(e.style.visibility=="hidden")ShowE(str,win);else HideE(str,win);}}
function ToggleSpan(str, win){ e = GetE(str, GetDoc(win)); if(e){if(e.style.visibility=="hidden")ShowSpan(str,win);else HideE(str,win);}}
function ToggleEin(str, win){ e = GetE(str, GetDoc(win)); if(e){if(e.style.visibility=="hidden")ShowEin(str,win);else HideEin(str,win);}}
function GetDoc(win){ return (win&&win.document)? win.document : window.document; }
//
function CreateStyleTag( str, win )//write and parse a new <style></style> tag
{
  var d = GetDoc(win);
  var s = d.createElement('style');
  s.setAttribute('type', 'text/css');
  if(s.styleSheet)   { s.styleSheet.cssText = str; }//IE
  else{ s.appendChild( d.createTextNode(str) ); }//the world
  (d.getElementsByTagName('head')[0] ).appendChild(s);
}
function CreateScriptTag( str, win )//write and parse a new <script></script> tag
{
  var d = GetDoc(win);
  var s = d.createElement('script');
  s.setAttribute('type', 'text/javascript');
  if(s.text)   { s.text = str; }//IE
  else{ s.appendChild( d.createTextNode(str) ); }//the world
  (d.getElementsByTagName('head')[0] ).appendChild(s);
}
//-----------------------------
// DHTML form functions
//-----------------------------
function GetSelected(e)
{
  for(var i=0; i < e.options.length; i++)
    if( e.options[i].selected ) 
      return e.options[i].value;
  return "";
}
function SetSelected(e, val)
{
  val = new RegExp(val, "i");
  for(var i=0; i < e.options.length; i++){
    if( e.options[i].value.match(val) ){
      e.options[i].selected = true;
      return;
     }
  }
}
//------------------------
function GetChecked(radioObj) {
  for(var i = 0;radioObj && i < radioObj.length; i++){
    if(radioObj[i].checked){
      return radioObj[i].value;
    }
  }
  if(radioObj && radioObj.checked)
      return radioObj.value;
  return "";
}
function SetChecked(radioObj, newValue) {
  if(typeof radioObj.length != 'undefined'){
    for(var i = 0; i < radioObj.length; i++) {
      radioObj[i].checked = false;
      if(radioObj[i].value == newValue.toString())
        radioObj[i].checked = true;
    }
  }else if(radioObj && radioObj.value){
    radioObj.checked = (radioObj.value == newValue.toString());
  }
}

function WriteHeader( t, cls )
{
  if( !t || t == '') t = document.title;
  if( !t || t == '') t = top.defaultStatus;
  if( !t || t == '') t = document.location.pathname;//keep until live
  if( !cls || cls == '') cls = 'headerpink';
  if(GetE("pageHeading")){
    GetE("pageHeading").className = cls;
    GetE("pageHeading").innerHTML = t;
  } else{
    var str = "<div id='Main' class='Main'><div class='"+cls+"' id='pageHeading' style='text-align:center'>"+t+"</div><hr>";
    document.write( str );
  }
}

function WriteFooter()
{
  if( is.nav )
    document.write( "<div id='spacer' class='spacer' style='height:1px'></div><hr></div>" );
  else
    document.write( "<hr></div>" );
}

function GeckoSpace( ht )
{
  if( !ht ){
    if( is.nav )
      document.write( "<div id='spacer' class='spacer' style='height:1px'></div>\n" );
    return;
  }
  if( is.nav )
    document.write( "<div id='spacer' class='spacer' style='height:"+(ht+5)+"px'></div>\n" );
  else
    document.write( "<div id='spacer' class='spacer' style='height:"+(ht)+"px'></div>\n" );
}

function GeckoSpaceStr( ht )
{
  var str = '';
  if( !ht ){
    if( is.nav )
      str = "<div id='spacer' class='spacer' style='height:1px'></div>\n";
    return str;
  }
  if( is.nav )
    str = "<div id='spacer' class='spacer' style='height:"+(ht+5)+"px'></div>\n";
  else
    str = "<div id='spacer' class='spacer' style='height:"+(ht)+"px'></div>\n";
  
  return str;
}

//-----------------------------
// Cookie functions
//-----------------------------
function GetCookieNEW( cookiename ) 
{
  if(!cookiename || cookiename == '') return '';
  var Cookie = document.cookie.match( new RegExp(cookiename+"=([^;]*);","gi") );
  if(Cookie && Cookie[1] ){//it might be in there more than once
	  return unescape(Cookie[1]);
  }
  return '';
}
function GetCookie( cookiename ) //GetCookie() only returns the first cookie instance...
{
  if(!cookiename || cookiename == '') return '';
  cookiename += ((cookiename.match(/=$/))?"":"=");//append trailing=sign
  var cookiestring=""+document.cookie;
  var index1=cookiestring.indexOf(cookiename);
  if (index1==-1) return ''; 
  var index2=cookiestring.indexOf(';',index1);
  if (index2==-1) index2=cookiestring.length; 
  return unescape(cookiestring.substring(index1+cookiename.length,index2));
}
function SetCookie( name, value ){ Setcookie( name, value ); }
function Setcookie( name, value )
{
  if( name && name != '' && name != 'undefined')
    document.cookie = name +"="+ escape(value) +"; path=/;";
}
function DelCookie( name )
{
  if( name && name != '' && name != 'undefined')
    document.cookie = name + "=; path=/; expires=Fri, 28 Dec 1962 23:59:59 GMT;";
}

//multivalue cookie objects
function CookieObj(name, doc, hours, path, domain, secure)
{ 
  //add properties to a new CookieObj: add,get,set name value pairs
  //new will create a new cookie obj
  //set will save it to browser
  //get will get and load saved properties
  //del will reomve the whole cookie

  this.$name = name;
  this.$document = (doc)?doc:document;
  this.$expires = (hours)?(new Date((new Date()).getTime() + hours*3600000)):null;
  this.$path   = (path)?path:null;
  this.$domain = (domain)?domain:null;
  this.$secure = (secure)?true:false;

  this.set = function()//returns true on success
  {
    var cookieval = '';
    for(var p in this)
    { //only new instance defined properties get stored
      if((p.charAt(0) != '$') && (typeof(this[p]) != 'function'))
      {
        if(cookieval != '') cookieval += "&";
        cookieval += p +':'+ escape(JSON.stringify(this[p]));
      }
    }
    var cookie = this.$name +'='+ cookieval;
    if(this.$expires) cookie += '; expires='+ this.$expires.toGMTString();
    if(this.$path)    cookie += '; path='+ this.$path;
    if(this.$domain)  cookie += '; domain='+ this.$domain;
    if(this.$secure)  cookie += '; secure';
    if(cookie.length >= 4096) return false;
    this.$document.cookie = cookie;
    return true;
  }

  this.get = function()//returns true on success
  {
    var cookiestring=""+this.$document.cookie;
    var index1=cookiestring.indexOf(this.$name);
    if (index1==-1) return false; 
    var index2=cookiestring.indexOf(';',index1);
    if (index2==-1) index2=cookiestring.length; 
    var cookieval = cookiestring.substring(index1+this.$name.length+1,index2);
    var a = cookieval.split('&');//get name value pairs
    for(var i=0; i< a.length; i++)//split each pair
      a[i] = a[i].split(':');
    for(var i=0; i< a.length; i++)//create prop=value for this instance
      this[a[i][0]] = JSON.parse(unescape(a[i][1]));
    return true; 
  }
  
  this.clear = this.del = function()
  {
    var cookie = this.$name  + '=; expires=Fri, 28-Dec-1962 00:00:00 GMT';
    if(this.$path)    cookie += '; path='+ this.$path;
    if(this.$domain)  cookie += '; domain='+ this.$domain;
    this.$document.cookie = cookie;
    return true;
  }
}


//-----------------------------
// user info functions
//-----------------------------
function DoSignOut(returl){
	LLGlobal.UserContext = NewUserContext();
	location.href = EStoreHost +"/signoutlois.aspx?ReturnURL=http://"+escape(location.hostname)+"/snp/logout.htp?"+escape((returl||""));
}
function TestLoggedInE() 
{ // test if user/browser is logged-in, returns true if currently logged-in
  if( GetCookie("LOISLAWEID").length == 36 ) //need to test for LOISLAWEID cookie
    return ( LLGlobal && LLGlobal.UserContext && LLGlobal.UserContext.LOISLAWEID && LLGlobal.UserContext.LOISLAWEID.length == 36 );
  return false;
  //if( GetCookie("LOISLAWEID").length == 36 ) return true;
  //return false;
}
function TestLoggedIn() //need to actually read LOISLAWID cookie
{ // test if user/browser is logged-in, returns true if currently logged-in
  if( GetCookie("LOISLAWID").length == 36 ) //need to test for LOISLAWID cookie
    return ( LLGlobal && LLGlobal.UserContext && LLGlobal.UserContext.LOISLAWID && LLGlobal.UserContext.LOISLAWID.length == 36 );
  return false;
  //if( GetCookie("LOISLAWID").length == 36 ) return true;
  //return false;
}
//use cookie to store and retrieve user display name
var UserDispNameCookie = 'LOISLAWUDN';
function SetUserDisplayName( name )
{
  if( TestLoggedIn())
    Setcookie(UserDispNameCookie,name);
}
function GetUserDisplayName()
{
  if( TestLoggedIn())
    return GetCookie(UserDispNameCookie);
  return '';
}



/*********************************************************************************
SlamLeft() is used to realign content to the left if the page is viewed
from both the secure and non-secure areas of the website.  See the Contact Us
and Help pages for usage.
*********************************************************************************/
function SlamLeft()
{
  if(top.topp && top.topp.isFixedWidth)
  {
    var body = document.body;
    var main = document.getElementById('Main');
    main.style.margin='0';
    body.style.textAlign='left';
  }
}

//-----------------------------------
// Main-Frame resizing functions
//-----------------------------------
function GetDefMainFrameRowsAry()
{ //returns array containg default row sizes
  //the defaults must be set on the frame page
  var ret = new Array(3);
  ret[0] = top.defRowsTopp;
  ret[1] = top.defRowsContent;
  ret[2] = top.defRowsBottom;
  return ret;
}
function GetCurrentMainFrameRowsAry()
{ //returns an array, so caller can manipulate individually
  var str = top.document.getElementById("mainframe").rows;
  return str.split(',');
}

function ResizeMainFrameRows(str)
{ //set the whole frame set at once, defaults to default setting
  if(!str || str == '')
    str = top.defRowsTopp +","+ top.defRowsContent +","+ top.defRowsBottom;
  top.document.getElementById("mainframe").rows = str;
}
function ResizeTopFrameRows(v) //defaults to default setting
{ 
  if(v=='undefined' || (''+v) == '')//zero is valid, no param = default
    v = top.defRowsTopp;
  if(top.document.getElementById("mainframe") && v){
    var str = top.document.getElementById("mainframe").rows;
    var framerows = str.split(',');
    top.document.getElementById("mainframe").rows = v +","+ framerows[1] +","+ framerows[2];
  }
}
function ResizeContentFrameRows(v) //defaults to default setting
{  
  if(v=='undefined' || (''+v) == '')
    v = top.defRowsContent;
  var str = top.document.getElementById("mainframe").rows;
  var framerows = str.split(',');
  top.document.getElementById("mainframe").rows = framerows[0] + ","+ v +","+framerows[2];
}
function ResizeBottomFrameRows(v) //defaults to default setting
{
  if(v=='undefined' || (''+v) == '')
    v = top.defRowsBottom;
  var str = top.document.getElementById("mainframe").rows;
  var framerows = str.split(',');
  top.document.getElementById("mainframe").rows = framerows[0] + ","+framerows[1]+","+ v;
}

//----------------
function gotoSignupForm(linkid)
{
  var url = 'https://ecom.loislaw.com/freetrial/index.htp?target=';
  if( Site == 'SCHOOL' ){
    url += 'lawschool/student.htm';
    if(linkid!="" && typeof linkid != "undefined"){ url += "?linkid="+linkid; }
 } else{
    url += 'demo/trialpage.htp&access=LLDEMO';
    if(linkid!="" && typeof linkid != "undefined"){ url += "&linkid="+linkid };
  }
  popupNoFrameLink(url);
}

function GotoPRPForm(promo,linkid){
  var url = "https://ecom.loislaw.com/ecomgpc/signup.htp?";
  if(top.document.location.search.match(/promo=/i)){
    var n = top.document.location.search.split("&");
    var pairs = new Object();
    for(var i=0; i < n.length; i++)
    {
      var nv = n[i].split("=");
      pairs[nv[0].toLowerCase()] = unescape( ((nv[1])?nv[1]:"") );
    }
    var p = pairs["promo"];
    url += "promo=" + p;
  } else if(promo && promo!=""){
    url += "promo=" + promo;
  }
  if(linkid && linkid!=""){
    url += "&linkid=" + linkid;
  }
  top.document.location.href=url;
}

//------------------------------------
// LLGlobal
// Create a Singleton persistent global Object, accessible to all windows and frames
// This happens even before "onload" is called
// USAGE:  LLGlobal.mything = mything; [also see InitGlobals() below]
//------------------------------------
GetSettings();//initialize the global Settings object
function GetSettings() //As each win calls GetSettings(), it will get the lastest LLGlobal data.
{
  //--------------------
  // Local functions
  //--------------------
  function PropagateGlobals(win){  //local recursive function
    //add-update globals object in all child windows
    for(var f = 0; f < win.frames.length; f++){
      if(!win.frames[f].LLGlobal || win.frames[f].LLGlobal != win.LLGlobal ){
        win.frames[f].LLGlobal = win.LLGlobal;
      }
      PropagateGlobals(win.frames[f]);
    }
  }
  function InitSettings(){
    //convenience: initalize deep or custom objects here if not already declared, 
    //to save lots of testing for the objects in the code.
    if(typeof LLGlobal.UserContext != 'object' ){
	    LLGlobal.UserContext = NewUserContext();
		}
		LLGlobal.Delete = function(){ //removes cookie and deletes the object (works for ffox)
	    //if( LLGlobal && LLGlobal.del() )
	    //  delete LLGlobal;
	    //add a flag to object that tells all other windows to not reset the cookie
	    //also, add function in CookieObj .Init() that removes/resets all user added properties from itself
    }
  
  }
  function SaveSettings() //save cookie stored objects (auto called during window.onunload)
  {
    LLGlobal.set();
  }
  function ReadSettings() //read cookie stored objects
  {
    LLGlobal.get();
  }
  function DeleteSettings() //read cookie stored objects
  {
    LLGlobal.del();
    delete LLGlobal;
  }  
  //--------------------
  // Main function code
  //--------------------
  //start at (main) top window, owner of the global object
  var win = GetTopMainWindow();
  if(!win.LLGlobal){ //not loaded in top or top has been re-freshed //(name, doc, hours, path, domain, secure)
    //win.LLGlobal = new CookieObj('LLGlobal', null, 1, "/"); //get previous settings from cookie into top
    win.LLGlobal = new CookieObj('LLGlobal', null, null, "/"); //get previous settings from cookie into top
    //add: ?
    //-> memory globals non-cookie (good for child windows) (forgotten if full-refresh or offsite)
    //-> session globals cookie (good for re-load or off site )(forgotten if close all or open new browser instance), 
    //-> persistent globals file cookie (good for all of above, close all and new browsers),
    //     setting 'hours' will create a file coookie.  That allows new browser instances to pick up user sessions,
    //     as well as navigating offsite and coming back can remember state.
    //     However, this makes it hard for different browser instances to run under differnt user accounts (different LLGlobal data)
    //-> add sub-domain cookie, and keep both cookies in sync 
    win.LLGlobal.get();  //load data
    PropagateGlobals(win);//assign to all windows
  }else{  //top has valid object, assign to local var.
     window.LLGlobal = win.LLGlobal; 
  }
  InitSettings();
  
  //as each frame updates the LLGlobal object, all other frames automatically have current data.
  //this call here assures that the saved cookie is updated with the most current state
  //preventing the need to repeatedly call LLGlobal.set() in the working code.
  addEvent(window, "unload", SaveSettings, false);
}

function NewUserContext()//user context object - store info about this user
{
	var a = arguments;
  var _uc = {
	  userDisplayName : (a[0]||""),
    userOverRide: (a[1]||false),
    WSRet : (a[2]||-1),
    WSIDC : (a[3]||""),
    WSRem : (a[4]||""),
    startPage:(a[5]||"/pns/start.htp"),
    FullName:(a[6]||""),
    UserLink:(a[7]||""),
    LOISLAWID:(a[8]||""),
    LOISLAWEID:(a[9]||"")
  };
	return _uc;
}

//Returns a deep copy of an object
function CopyObject(o){
	if( typeof o == 'object' ){
		var res = new Object();
		for(var p in o){
			if(typeof o[p] != 'object' )
				res[p] = o[p];
			else
			  res[p] = CopyObject(o[p]);
		}
		return res;//return new object
	}
	return o;//not an object
}
function CopyObject2(o){
	return JSON.parse( JSON.stringify(o) ) ;
}
//Used for subclass-superclass inheritance
function Inherit(subclass, superclass) {
    var c = function() {};
    c.prototype = superclass.prototype;
    subclass.prototype = new c();
}
/*Then define a Subclass like this:
function Subclass(initialValue) {
    Superclass.call(this, initialValue);
}
Inherit(Subclass, Superclass);
*/

//-----------------------
//Debugging functions
//-----------------------
function throwE(e, args){ //append call stack to exception. USAGE: catch(e){ throwE(e,arguments); }
  if(args.callee.toString) {
    (/function\s+([\w\d]+)\s*\(([^\)]*)/i).test(args.callee.toString());
    e.description = "["+RegExp.$1+"] "+e.description;
  }
  throw(e);
}
function DebugWindow(s){//write messages to a singlton debug window
  var message = "<pre style='font-size:12px;'>-----------------<br><b>"+ document.location.pathname +" : "+ s +"</b>\n<br>-----------------</pre>\n";
  var win = GetTopMainWindow();
  try{win.gDebugWin.document.body.innerHTML += message;}
  catch(e){ 
    win.gDebugWin =  window.open("","DebugWindow");
    win.gDebugWin.document.title = "DebugWindow";
    win.gDebugWin.document.body.innerHTML += message;
  }
  try{win.gDebugWin.scrollBy(0,win.gDebugWin.document.body.offsetHeight);}catch(e){}
}
function GetProperties( o, depth ) //o:object, depth: optional recursion limit
{ 
  var indent = ((typeof arguments[2]=='undefined')?"":arguments[2]) + ".";//level indent char
  var ret = "";
  if(typeof(o) != 'object') 
    ret += indent + typeof(o) +" = '"+o+"'\n";
  else{
    for(var n in o){ 
      ret += indent + n +" = '"+o[n]+"'\n"; 
      if( typeof(o[n]) == 'object' ){
        if(typeof depth =='undefined' || depth == null ) 
          ret +=  GetProperties( o[n], null, indent );
        else if( --depth > -1 )
          ret +=  GetProperties( o[n], depth, indent );
      }
    }
  }
  return ret;
}
function ToggleDiv(d,a){
  var div = document.getElementById(d);
  var updownarrow = document.getElementById(a);
  if(div.style.visibility=="" || div.style.visibility=="hidden")
  {
    ShowE(div);
    updownarrow.src="http://image.loislaw.com/prosite/ui/arrow_open2.png";
  }
  else{
    HideE(div);
    updownarrow.src="http://image.loislaw.com/prosite/ui/arrow_closed2.png";
  }
}

//--------------------
/*
//JS Error loggin functions almost finished
//window.onerror = LoisOnError;
function JSErrors()
{
  this.str = '';
  this.add = function(_str){ //var n = new Date(); this.str += "[" + n.getHours() +":"+ n.getMinutes() + ":" + n.getSeconds() +"]"; 
    this.str += _str; }
  this.show = function(){ alert(this.str) }
  this.clear = function(){ this.str = ''; }
}
if(top && typeof(top.gErrors) != 'object' )
{ 
  top.gErrors = new JSErrors();
}
gErrors = top.gErrors;

function LoisOnError(emess, url, line)
{
  var n = navigator;
  var frame = "\ntop win = " + top.location.href;
  for(var i=0; i < top.frames.length; i++)
    frame +=  "\n"+ top.frames[i].name +'='+ top.frames[i].location.href;
  var mess = ""+
  "\nError message="+ emess +
  "\nError script="+ url +
  "\nError line="+ line +
  "\nCalling script="+ document.location.href +
  "\nuserAgent="+ n.userAgent +
  "\nappName="+ n.appName +
  "\nappVersion="+ n.appVersion +
  "\nplatform="+ n.platform +
  "\nFrameState="+ frame +
  "\nUserName="+ GetUserDisplayName();
  JSErrLog( mess );
  return true;
  //return false;
}
function JSErrReport()//Show JS Error page to customer
{ 
  var str = 'JSErrReport() : \n';
  for(var i=0; i < arguments.length; i++)//note: variable number param list
    str += GetProperties( arguments[i] );
  gErrors.add(str);
  gErrors.show();
  str = str.replace(/\n/g,"|");
  str = LoisEscape(str);
  if(top.content) top.content.document.location.href = '/errmess/jserror.htm?'+str;
  else top.document.location.href = '/errmess/jserror.htm';
} 
function JSErrLog()//Don't show JS Error page to customer
{ //note: variable number param list
  var str = 'JSErrLog() : \n';
  for(var i=0; i < arguments.length; i++)
    str += GetProperties( arguments[i] );
  gErrors.add(str);
  gErrors.show();
  str = str.replace(/\n/g,"|");
  str = LoisEscape(str);
  var ew = window.open( '/errmess/jserrorlog.htp?'+str, 'ewin', 'width=50,height=50');
}  
*/
//--------------------
