//document.domain = 'loislaw.com';

//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{
		if(!w) w = window;
		var win = ((w.opener)?w.opener.top:top);
	  if(win.opener)
	  	return GetTopMainWindow(win);
	  return win;
	}catch(e){return top;}
}

function GetFrames(win){ //return a flat array of named frames (note:duplicates overwrite previous named frame)
	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);
	return MyFrames;
}
var MyFrames = GetFrames();
function GetFrameById(name){ return MyFrames[String(name).toLowerCase()]; }
function GetFrameByName(name){ return MyFrames[String(name).toLowerCase()]; }
var myWin;
if(top.topp){ myWin = top.topp; } else { myWin = window; }
var is = new Is();
var isIE   =(navigator.appName == "Microsoft Internet Explorer");
var isNav  =(navigator.appName == "Netscape");
var agt    = navigator.userAgent.toLowerCase();
var notMac =(agt.indexOf('macintosh') == -1 && agt.indexOf('ppc') == -1 && agt.indexOf('68k') == -1);

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://signup.loislawschool.com") >= 0){
	Site = "SIGNUP";
} 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.notMac = (agt.indexOf('Macintosh') == -1 && agt.indexOf('PPC') == -1 && agt.indexOf('68K') == -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 && el.onclick != "" ){ el.onclick(); }
		else if( el.form && el.form.onsubmit != "" ){ el.form.onsubmit(); }
		else if( el.form ){ el.form.submit(); }
		else if( FormOne && FormOne.onsubmit != "" ){ FormOne.onsubmit(); }
		else if( FormOne ){ 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");
}
/*----------------------------------
 Functions for posting sales leads data to SalesForce.com.

  1. Search content document for User entered
  info from signup forms (during onunload event)

  2. If data is found, populate a hidden SalesForce
     form:
      * do some data mapping (FNAME -> first_name, etc.

  3. If signup is accepted by the cust.dll (look for thankyou response)
     POST the hidden form to SalesForce.com
----------------------------------*/
var debugStr = ""
var campaign_id = "";
//-----------------------------------
function FindSalesForceData(doc)
{try{

  if(!doc || !doc.body ) doc = document;

  for( var f=0; f < doc.forms.length; f++ ) //for each form in doc
  {
    //Skip the SalesForce form & also skip the LawSchool Trial form.  We don't want Students inserted into SalesForce.
    if(doc.forms[f].name.match(/salesforce/i) || 
      (doc.forms[f].elements["SFACTION"] && doc.forms[f].elements["SFACTION"].value=="NOSUBMIT"))
    { continue; }
    for( var i=0; i < doc.forms[f].elements.length; i++) //for each input
    {
      //Map our form names to SalesForce.com form names
      var input = doc.forms[f].elements[i];
      switch( input.name.toUpperCase() )
      { //do switch or match on i.name, or just look for our standard from inputs

        case 'TITLE': if(input.checked){SetSalesFormValue('salutation', input.value);} break;
        case 'ECOM_FIRSTNAME': SetSalesFormValue('first_name', input.value); break;
        case 'ECOM_LASTNAME': SetSalesFormValue('last_name', input.value); break;
        case 'ECOM_USERNAME': SetSalesFormValue('00N30000000xXBk', input.value); break;
        case '---': SetSalesFormValue('title', input.value); break;
        case 'ECOM_COMPANY': SetSalesFormValue('company', input.value); break;
        case '--website': SetSalesFormValue('URL', input.value); break;
        case 'ECOM_EMAIL': SetSalesFormValue('email', input.value); break;
        case 'ECOM_PHONE': SetSalesFormValue('phone', input.value); break;
        case 'PHONE2': SetSalesFormValue('mobile', input.value); break;
        case 'FAX': SetSalesFormValue('fax', input.value); break;
        case '---': SetSalesFormValue('description', input.value); break;
        case 'ECOM_STREET1': SetSalesFormValue('street', input.value); break;
        case 'ECOM_STREET1': SetSalesFormValueAppend('street', input.value); break;
        case 'ECOM_CITY': SetSalesFormValue('city', input.value); break;
        case 'ECOM_STATE': SetSalesFormValue('state', input.value); break;
        case 'ECOM_COUNTRYCODE': SetSalesFormValue('country', input.value); break;
        case 'ECOM_POSTALCODE': SetSalesFormValue('zip', input.value); break;
        case 'MARKET_STR_STUDENT_YEAR': SetSalesFormValue('00N30000000wpG7', input.value); break;
        case 'MARKET_STR_FIRM_SIZE': SetSalesFormValue('employees', input.value); break;
        case 'SOURCE': SetSalesFormValue('lead_source', input.value); break;
        case 'OTHSOURCE': SetSalesFormValueAppend('lead_source', input.value); break;
        case 'CUSTOMER_INTERESTS': SetSalesFormValue('00N30000000wpfa', input.value); break
        case 'TRAN_PROMOCODE':
          campaign_id = LookupCampaignId(input.value);
          SetSalesFormValue("Campaign_ID",campaign_id);
          break;
        case '--practicearea': SetSalesFormValue('00N30000000wpe8', input.value); break;
        case '--companytype': SetSalesFormValue('00N30000000wzyr', input.value); break;
        case '--industry': SetSalesFormValue('industry', input.value); break;
        case '--currentVendor': SetSalesFormValue('00N30000000wzpB', input.value); break;

        default: break;
      }
    }
  }
  if(myWin==window){ //submit PRP user info to SF
    SubmitSalesForceData();
  }
  //debug
 }catch(e){}
}
//-----------------------------------
function SetSalesFormValue(name,value)
{try{
  var salesforce;
  salesforce = myWin.frames['ifsalesforce'].document.forms['salesforce'];
  salesforce.elements[name].value = value;
  debugStr += name +" = "+ value +"\n";
 }catch(e){}
}
//-----------------------------------
function SetSalesFormValueAppend(name,value)
{try{
  var salesforce;
  salesforce = myWin.frames['ifsalesforce'].document.forms['salesforce'];
  salesforce.elements[name].value += ((salesforce.elements[name].value)?"\n":"") + (value)?value:"";
  debugStr += name +" = "+ value +"\n";
 }catch(e){}
}
//-----------------------------------
function SubmitSalesForceData() //called in MasterSYnc() by anypage that has a title of "Thank you"
{try{
  var salesforce;
  salesforce = myWin.frames['ifsalesforce'].document.forms['salesforce'];

  if(salesforce.elements['first_name'].value == "" ) return; //don't submit if page didn't gather data

  debugStr = ""; //DEBUGING
  getStr = salesforce.action;
  for( var i=0; i < salesforce.elements.length; i++)
  {
    debugStr += salesforce.elements[i].name +" = "+ salesforce.elements[i].value +"\n"; //DEBUGING
    getStr += "&"+ salesforce.elements[i].name +"="+ escape(salesforce.elements[i].value);

  }
  myWin.frames['ifsalesforce'].document.location.href = getStr;
  salesforce.elements['first_name'].value = ""; //so we don't resend the post during onUnload
 }catch(e){}
}

//-----------------------------------
window.onunload = FindSalesForceData; //all pages search their forms
//-----------------------------------
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);
 try{
  if(caller.document.title.match(/Thank You/i))
     SubmitSalesForceData();
 }catch(e){}
}

function GetContentFrame( defContentPage )//called by frames pages to get content url
{
  var contentUrl = defContentPage;
  if( location.search.match(/^\?content=/i) )
    contentUrl = location.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)
{
	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 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 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,"&quot;").replace(/\'/g,"&apos;"); }

//-----------------------------
// 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 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';
  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 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 + "=; 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
  //delete 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(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;
    //alert(cookie);
    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(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;
}

// Google Analytics Functions //CR 3256,3269,3273,3296,3755
function Get_uacct(){
  var uacct;
  if(location.href.match(/ecom.loislaw/i)){
    uacct = "UA-677459-1";
  }
  if(location.href.match(/loislawschool/i)){
    uacct = "UA-677459-2";
  } else if(location.href.match(/http:\/\/loislaw/i) || location.href.match(/www.loislaw.com/i) ||
            location.href.match(/www2.loislaw.com/i) || location.href.match(/pita.com/i)){
    uacct = "UA-677459-1";
  }
  else
    uacct = "UA-677459-4"; //Google testing profile
  return uacct;
}
// Google Analytics Functions //CR 3256,3269,3273,3296
function GetDomain(){return ((location.host.match(/loislawschool/i))?"loislawschool.com":"loislaw.com");}
function ImportGoogleUrchin()
{
  if( location.pathname.match(/top.htm|bottom.htm/i)){ return; }
  if(top==self){ return; }//CR 3296
  var head = document.getElementsByTagName('head').item(0);
  var s = document.createElement("SCRIPT");
  s.src = "https://ssl.google-analytics.com/urchin.js"
  s.type = "text/javascript";
  if(navigator.userAgent.match(/opera/i))
    addEvent(window, "load", GUCallBack );//opera
  else{
    addEvent(s, "load", GUCallBack ); //moz
    s.onreadystatechange = function(){if(s.readyState=="loaded"||s.readyState=="complete") GUCallBack();}; //ie
  }
  head.appendChild(s);
  function GUCallBack(){
	  _uacct = Get_uacct();
	  _udn = GetDomain();
	  if(!location.search.match(/OLDURL=\/pns\/setuname\.htp/i)){
      urchinTracker( location.pathname.toLowerCase() );
    }
	}
}
addEvent(window, "load", ImportGoogleUrchin );
//-----------------------------------
function LookupCampaignId(promo){
  switch(promo.toLowerCase()){
    case 'aca01': return "70140000000GrsE"; break;
    case 'aca02': return "70140000000GrsJ"; break;
    case 'anl02': return "70140000000GrsO"; break;
    case 'any01': return "70140000000Grs9"; break;
    case 'any02': return "70140000000GrzM"; break;
    case 'any03': return "70140000000Gs03"; break;
    case 'any04': return "70140000000Gs04"; break;
    case 'any05': return "70140000000Gs05"; break;
    case 'aspen1': return "70140000000Grsa"; break;
    case 'atx03': return "70140000000GrzN"; break;
    case 'atx012': return "70140000000Grs4"; break;
    case 'bkws': return "70140000000Grsg"; break;
    case 'brws': return "70140000000Grsc"; break;
    case 'cca01': return "70140000000Grrz"; break;
    case 'cil01': return "70140000000Grrl"; break;
    case 'cny01': return "70140000000Grrq"; break;
    case 'ctx01': return "70140000000Grru"; break;
    case 'ddws': return "70140000000Grsd"; break;
    case 'elws': return "70140000000Grsh"; break;
    case 'evws': return "70140000000Grse"; break;
    case 'flws': return "70140000000Grsi"; break;
    case 'fna01': return "70140000000GqTE"; break;
    case 'fna02': return "70140000000Gqoa"; break;
    case 'fna03': return "70140000000Grrf"; break;
    case 'fna04': return "70140000000Grrg"; break;
    case 'fna05': return "70140000000GsrR"; break;
    case 'fna06': return "70140000000GsrS"; break;
    case 'fna20': return "70140000000Gt5s"; break;
    case 'fna21': return "70140000000Gt5x"; break;
    case 'fny01': return "70140000000GrzK"; break;
    case 'ftl01': return "70140000000Grqr"; break;
    case 'ftl02': return "70140000000GsiP"; break;
    case 'ftl03': return "70140000000GsiU"; break;
    case 'ftl04': return "70140000000GsiZ"; break;
    case 'ftl05': return "70140000000GsiV"; break;
    case 'ftl06': return "70140000000Gsia"; break;
    case 'ftl07': return "70140000000GsJK"; break;
    case 'ftl08': return "70140000000GsJP"; break;
    case 'ftl09': return "70140000000GsJZ"; break;
    case 'ftl10': return "70140000000GsJe"; break;
    case 'ftl11': return "70140000000GsJf"; break;
    case 'ftl12': return "70140000000GsiK"; break;
    case 'ftl13': return "70140000000Gssj"; break;
    case 'ftl14': return "70140000000Gt5n"; break;
    case 'ftx01': return "70140000000GqT8"; break;
    case 'ftx02': return "70140000000GqTD"; break;
    case 'ftx03': return "70140000000GrzL"; break;
    case 'gca01': return "70140000000Grrp"; break;
    case 'glws': return "70140000000Grsf"; break;
    case 'gpcdemocode': return "70140000000GrsW"; break;
    case 'googlenews': return "70140000000Gsi5"; break;
    case 'googleweb': return "70140000000GsiA"; break;
    case 'judge02': return "70140000000Grsk"; break;
    case 'la06': return "70140000000Grso"; break;
    case 'lldemo': return "70140000000Grr1"; break;
    case 'llprp': return "70140000000Gsi6"; break;
    case 'llsftrial': return "70140000000Grr6"; break;
    case 'llws': return "70140000000Grsj"; break;
    case 'ls61': return "70140000000GrsT"; break;
    case 'ls62': return "70140000000GrsU"; break;
    case 'lsfl': return "70140000000GrsV"; break;
    case 'megalaw1': return "70140000000GrsZ"; break;
    case 'morelaw1': return "70140000000Grsb"; break;
    case 'nyadvsrnysba': return "70140000000Grsl"; break;
    case 'nyfamily': return "70140000000Grsm"; break;
    case 'oneday': return "70140000000GrsY"; break;
    case 'other_referrer': return "70140000000GsiF"; break;
    case 'pressroom': return "70140000000GrsX"; break;
    case 'taj9': return "70140000000Grsp"; break;
    case 'wibartrial': return "70140000000Grsn"; break;
    case 'wup01': return "70140000000Grqw"; break;
    default: return promo; break;
  }
}
//-----------------------------------

//-----------------------
//Debugging functions
//-----------------------
function DebugWindow(s){//write messages to a singlton debug window
  var message = "<p>"+ document.location.pathname +" : "+s +"</p>";
  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 )
{
  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;
}
//--------------------
/*
//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');
}  
*/
//--------------------
