//document.domain = 'loislaw.com';
//--------------------
/*
//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');
}  
*/
function GetProperties( o )
{
  if(typeof(o) != 'object') return (typeof(o) +" = "+o+"\n");
  var ret = '';
  for(var n in o){ 
    ret += n +" = '"+o[n]+"'\n"; 
    if(typeof(o[n]) == 'object') 
      ret += GetProperties(o[n]); 
  }
  return ret;
}
//--------------------

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()
{
  if( is.nav )
  {
    //For Netscape:
    document.onkeypress = keyHandler;
  }
  if ( isIE )
    document.onkeypress=keyHandler;
}

//==============================================================
function keyHandler(e)
{
  if (isIE )
  {
    if (window.event.keyCode == 13 && !IsSyncState('bottom','wait') ) {
      FormSubmit();
      window.event.returnValue = false;
      return false;
    }
    else
      return true;
  }
  if (isNav)
  {
    if (e.which == 13 && !IsSyncState('bottom','wait'))
		{
		  FormSubmit();
			return false;
    }
    else { routeEvent(e); return true; }
  }
  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 MasterSync(toppId, bottomId, caller, title )
{
  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) && (parent.frames.length < 1))
  {
    if(top.location.pathname.match(/^\/pns/i) )
    	top.location.href = "/pns/index.htp?content=" + top.location.pathname + top.location.search;
		else
			top.location.href = "/index.htm?content=" + top.location.pathname + top.location.search;
	}
	if(window.focus) { window.focus(); }
}
function CheckUrl()
{
	if( location.search.match(/^\?content=/i) )
  {
    var contentUrl = location.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;
  var n = w.location.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 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 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 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 = 'headinga';
  var str = "<div id='Main' class='Main'><div class='"+cls+"' id='pageHeading'>"+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 get/set functions
function GetCookie( cookiename ) 
{
  if(!cookiename || cookiename == '') return '';
  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+1,index2));
}
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 + "=; 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
  //delete will reomve the whole cookie

  this.$name = name;
  this.$document = (doc)?doc:document;
  this.$expires = (hours)?(new Date((newDate()).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(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]] = unescape(a[i][1])
    return true; 
  }
  
  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 TestLoggedIn()
{ // test if user/browser is logged-in, returns true if currently logged-in
  var temp = GetCookie("LOISLAWID=");
  if(!temp || temp =='' || temp.match(/ABCDEF/i) )
    return false;
  else
    return true;
}
//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;
  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()
{
	var url = 'https://ecom.loislaw.com/freetrial/index.htp?target=';
	if( Site == 'SCHOOL' )
    	url += 'student.htm'
    else
    	url += 'trialpage.htp&access=FREETRIAL';
  popupNoFrameLink(url);
}
