// Nov. 21/2003 - New script DIGESTS.JS handles summary link menu - csk
// Feb. 29/2004 - Summaries/Commentaries - production - mtm
// Mar. 03/2004 - New sources BCS9, BOP9, BSN9, FRAD, LAX9 - csk
// Apr. 27/2004 - Avoid JS error loading in single frame - mtm
// May  12/2004 - New source VAU9 - csk
// May  14/2004 - New source RDSD - mtm
// Oct. 14/2005 - Position persistence - mtm


// ******** General Summaries menu functions ********

function digests_general() // general digests creation function
{
if ("undefined" == typeof BRGET) BRGET="";
if ("undefined" == typeof DIGESTS) DIGESTS = "";
 top.numsum=0; // default no down arrow
 if ((DIGESTS) || (BRGET)){
   if (BRGET){
     top.makesumm = true; // set flag that have menu
     top.numsum = 1; // not necessarily down arrow
   } // if DRS summary
   if (DIGESTS){
     if (DIGESTS.length > 0){
       top.numsum = top.numsum + DIGESTS.length; // may have down arrow
       digests_table(); // create table in memory
     } // if making table
   } // if DIGESTS defined
   digests_properties(); // assign summenu properties
 } // have digests for this case
} // end digests_general

function digests_table() // Create digests table in memory
{
 summatrix = new Object(); // global object no var

 // ** Entries alphabetical by source id **

 summatrix['ACLN'] = "Alberta&nbsp;Case&nbsp;Locator";
 summatrix['ACWS'] = "All&nbsp;Canada&nbsp;Weekly&nbsp;Summaries";
 summatrix['ALLD'] = "Allen&nbsp;Securities&nbsp;Law&nbsp;NetLetter";
 summatrix['ALTD'] = "Alberta&nbsp;Decisions&nbsp;(Digests)";
 summatrix['BAB9'] = "Butterworths&nbsp;Aboriginal&nbsp;NetLetter";
 summatrix['BCD']  = "British&nbsp;Columbia&nbsp;"
                   + "Decisions&nbsp;(Digests)";
 summatrix['BCIR'] = "B.C.&nbsp;Labour&nbsp;Relations&nbsp;"
                   + "Board&nbsp;(Digests)";
 summatrix['BCLA'] = "B.C.&nbsp;Labour&nbsp;Arbitrations&nbsp;(Digests)";
 summatrix['BEC9'] = "Butterworths&nbsp;Economic&nbsp;Damages"
                   + "&nbsp;NetLetter";
 summatrix['BCS9'] = "Butterworths&nbsp;Construction"
                   + "&nbsp;NetLetter";
 summatrix['BEDD'] = "Brown&nbsp;Economic&nbsp;Damages&nbsp;NetLetter";
 summatrix['BEN9'] = "Butterworths&nbsp;Environmental&nbsp;NetLetter";
 summatrix['BHL9'] = "Butterworths&nbsp;Health&nbsp;Law&nbsp;NetLetter";
 summatrix['BHT9'] = "Butterworths&nbsp;Highway&nbsp;"
                   + "Traffic&nbsp;NetLetter";
 summatrix['BMN9'] = "Butterworths&nbsp;Municipal&nbsp;NetLetter";
 summatrix['BNCD'] = "Belzil&nbsp;NetLetter&nbsp;on&nbsp;"
                   + "Creditors'&nbsp;Rights";
 summatrix['BOP9'] = "Butterworths&nbsp;Ontario&nbsp;Civil"
                   + "&nbsp;Practice&nbsp;NetLetter";
 summatrix['BSN9'] = "Butterworths&nbsp;Sentencing&nbsp;NetLetter";
 summatrix['CALD'] = "Corbett&nbsp;Agricultural&nbsp;NetLetter";
 summatrix['CARD'] = "Carlson&nbsp;Personal&nbsp;Injury"
                   + "&nbsp;NetLetter";
 summatrix['CDNA'] = "Federico&nbsp;&&nbsp;Rondinelli"
                   + "&nbsp;DNA&nbsp;NetLetter";
 summatrix['CIMD'] = "Butterworths&nbsp;Immigration&nbsp;NetLetter";
 summatrix['CITD'] = "Butterworths&nbsp;Tax&nbsp;NetLetter";
 summatrix['CLAS'] = "Canadian&nbsp;Labour&nbsp;"
                   + "Arbitration&nbsp;Summaries";
 summatrix['COCD'] = "Lenczner&nbsp;Slaght&nbsp;Commercial"
                   + "&nbsp;Litigation&nbsp;NetLetter";
 summatrix['COID'] = "Cox&nbsp;Hanson&nbsp;Oil&nbsp;"
                   + "&&nbsp;Gas&nbsp;NetLetter";
 summatrix['CPAD'] = "Butterworths&nbsp;Patent&nbsp;NetLetter";
 summatrix['CPAS'] = "Canada&nbsp;Post&nbsp;Arbitration&nbsp;Summaries";
 summatrix['CRC']  = "Charter&nbsp;of&nbsp;Rights&nbsp;"
                   + "Cases&nbsp;(Digests)";
 summatrix['CRR']  = "Canadian&nbsp;Regulatory&nbsp;"
                   + "Reporter&nbsp;(Digests)";
 summatrix['CRWD'] = "Crown&nbsp;Weekly&nbsp;NetLetter";
 summatrix['CTMD'] = "Butterworths&nbsp;Copyright&nbsp;"
                   + "&&nbsp;Trademarks&nbsp;NetLetter";
 summatrix['FCAD'] = "Federal&nbsp;Court&nbsp;of&nbsp;"
                   + "Appeal&nbsp;Decisions&nbsp;(Digests)";
 summatrix['FRAD'] = "Siskinds&nbsp;Franchise&nbsp;Law&nbsp;NetLetter";
 summatrix['GLTC'] = "Gold&nbsp;Money&nbsp;Laundering&nbsp;Update";
 summatrix['GOLC'] = "Gold&nbsp;Criminal&nbsp;Law&nbsp;NetLetter";
 summatrix['HAD']  = "Handrigan's&nbsp;Atlantic&nbsp;NetLetter";
 summatrix['HARD'] = "Harper&nbsp;Insurance&nbsp;Law&nbsp;NetLetter";
 summatrix['HARL'] = "Harper&nbsp;Administrative&nbsp;"
                   + "Law&nbsp;NetLetter";
 summatrix['HLC']  = "Health&nbsp;Law&nbsp;Cases&nbsp;(Digests)";
 summatrix['HNND'] = "Handrigan's&nbsp;Newfoundland&nbsp;NetLetter";
 summatrix['HRND'] = "Butterworths&nbsp;Human&nbsp;"
                   + "Rights&nbsp;NetLetter";
 summatrix['KCAR'] = "Kapoor's&nbsp;Criminal&nbsp;Appeals&nbsp;Review";
 summatrix['KERK'] = "Kershman&nbsp;Bankruptcy&nbsp;and"
                   + "&nbsp;Insolvency&nbsp;NetLetter";
 summatrix['LAND'] = "Lancaster&nbsp;House&nbsp;Wrongful"
                   + "&nbsp;Dismissal&nbsp;NetLetter";
 summatrix['LAX9'] = "Labour&nbsp;Arbitration&nbsp;Xpress"
                   + "&nbsp;NetLetter";
 summatrix['LWDC'] = "The&nbsp;Lawyers&nbsp;Weekly";
 summatrix['LWDH'] = "The&nbsp;Lawyers&nbsp;Weekly";
 summatrix['MAND'] = "Manitoba&nbsp;Decisions&nbsp;(Digests)";
 summatrix['MPRO'] = "MacKenzie&nbsp;Professional&nbsp;"
                   + "Responsibility&nbsp;NetLetter";
 summatrix['MTBR'] = "McCarthy&nbsp;T\xE9trault&nbsp;"
                   + "Broadcasting&nbsp;Reporter&nbsp;(Digests)";
 summatrix['MTTE'] = "McCarthy&nbsp;T\xE9trault&nbsp;"
                   + "Telecom&nbsp;Reporter&nbsp;(Digests)";
 summatrix['NPLD'] = "Nelligan&nbsp;Labour&nbsp;Law&nbsp;NetLetter";
 summatrix['NPPD'] = "Nelligan&nbsp;Professional&nbsp;"
                   + "Liability&nbsp;NetLetter";
 summatrix['PCSD'] = "Payne's&nbsp;Child&nbsp;Support&nbsp;Digests";
 summatrix['PDDF'] = "Payne's&nbsp;Digests&nbsp;on&nbsp;Divorce&nbsp;"
                   + "&&nbsp;Family&nbsp;Law";
 summatrix['PIND'] = "Butterworths&nbsp;Personal&nbsp;"
                   + "Injury&nbsp;NetLetter";
 summatrix['RASP'] = "R\xE9sum\xE9s&nbsp;de&nbsp;sentences&nbsp;"
                   + "arbitrales&nbsp;SCP";
 summatrix['RDQ']  = "R\xE9sum\xE9s&nbsp;des&nbsp;d\xE9cisions"
                   + "&nbsp;qu\xE9b\xE9coises";
 summatrix['RDSD'] = "R\xE9sum\xE9s&nbsp;en&nbsp;droit&nbsp;criminel"
                   + "&nbsp;et&nbsp;p\xE9nal&nbsp;de&nbsp;Schneider"
                   + "&nbsp;&amp;&nbsp;Dubois";
 summatrix['RPID'] = "Robertson&nbsp;Personal&nbsp;"
                   + "Injury&nbsp;NetLetter";
 summatrix['SACL'] = "Sack&nbsp;Labour&nbsp;&&nbsp;"
                   + "Employment&nbsp;NetLetter";
 summatrix['SASD'] = "Saskatchewan&nbsp;Decisions&nbsp;(Digests)";
 summatrix['SCAD'] = "Siskinds&nbsp;Class&nbsp;Actions&nbsp;NetLetter";
 summatrix['SCCD'] = "Supreme&nbsp;Court&nbsp;of&nbsp;"
                   + "Canada&nbsp;Decisions&nbsp;(Digests)";
 summatrix['SFLD'] = "Syrtash&nbsp;Family&nbsp;Law&nbsp;NetLetter";
 summatrix['SRED'] = "Shibley&nbsp;Righton&nbsp;Education&nbsp;"
                   + "Law&nbsp;NetLetter";
 summatrix['VAU9'] = "Bulletin&nbsp;de&nbsp;droit&nbsp;"
                   + "criminel&nbsp;Vauclair";     
 summatrix['WCB']  = "Weekly&nbsp;Criminal&nbsp;Bulletin";
 summatrix['WLCD'] = "Charter&nbsp;of&nbsp;Rights&nbsp;"
                   + "Decisions&nbsp;(Digests)";
 summatrix['YCJD'] = "Butterworths&nbsp;Youth&nbsp;Criminal"
                   + "&nbsp;Justice&nbsp;NetLetter";

} // end digests_table

function digests_properties() // HTML properties for summenu
{
 var pt = parent.top;
 if (!pt) return;
 var ptr = pt.RIGHT;
 if (!ptr) return;	
 var rd = parent.top.RIGHT.document;
 var sm=MM_findObj("summenu",rd); // find DIV in DOM or ns4.x
 if (sm) {
    var z = digests_menu(); // compose summenu HTML string
    if (top.makesumm == true){
      if (parent.top.QLBrowser.ns4){
        top.nettab = 0;
        top.netmenu = 0;
        sm.onmouseout=net_hide_verify;
        sm.onmouseover=net_pass_down;
        var menulayer = rd.layers["summenu"];
        var md=menulayer.document;
        md.write(z); // ns4.x document write
        md.close(); // close or will append
      } // if ns4.x object
      else{
        sm.onmouseout=hide_menu;
        sm.onmouseover=set_in;
        sm.onmousemove=set_in;
        sm.innerHTML = z; // DOM document write
      } // else DOM object
    } // if making menu
 } // if summenu found
} // end digests_properties

function digests_menu() // make summenu for DOM or ns4.x
{
 var z = '<TABLE cellspacing=0 ';
 if (parent.top.QLBrowser.ns4){
   z += 'cellpadding=2 ';
 } // if ns4.x foible
 else{
   z += 'cellpadding=0 ';
 }
 z += 'border=0>';

 if (BRGET) { // BRGET is UCN of CCS summary
   z += '<TR><TD class="smenu"><A class="smenu" HREF="';
   z += CMDPFX + 'BRGET=' + BRGET + '" TARGET="_top"';
   if ("undefined" != typeof top.record_pos)
     z += ' onclick="top.record_pos();"';
   z +='>';
   z += 'Canadian&nbsp;Case&nbsp;Summaries</A></TD></TR>';
 } // if BRGET

 if ("undefined" != typeof summatrix) // if summary title matrix
 {
   for (i=0; i< DIGESTS.length; i++) {
     var e = DIGESTS[i]; // unparsed array string
     var sumindex = e.indexOf(','); // index of comma in string
     var a = e.slice(0,sumindex); // tabcode before comma, no validation
                                  // necessary
     a = a.replace(/\s+/g,'');    // strip blanks
     var b = e.slice(sumindex+1); // tabdoc after comma, no validation done
     var c = summatrix[a]; // tabstring from data structure
     if ("undefined" != typeof c){ // if found summary title string
       var d = digests_entry(a,b,c); // write table row HTML
       z += d; // add row to summenu
       if (top.makesumm != true){ // if this is first summary found
         top.makesumm = true; // set flag that making menu
       } // if flag not set yet
     } // if access code in summatrix
   } // for each DIGESTS element
 } // if summatrix defined
 z += '</TABLE>';
 return z;
} // end digests_menu

function digests_entry(tabcode,tabdoc,tabstring) // write each summenu entry
{
 var MYPFX = CMDPFX.replace(/QL002/ig,'QLCMD');
 var d = '<TR><TD class="smenu"><A class="smenu" HREF="';
 d += MYPFX + 'C=CS+' + tabcode + '+' + tabdoc;
 d += '" TARGET="_top"';
 if ("undefined" != typeof top.record_pos)
   d += ' onclick="top.record_pos();"';
 d +='>';
 d += tabstring + '</A></TD></TR>';
 return d; // add string to table build
} // end digests_entry


// ******** Shared Summaries and Commentaries menu functions ********

function MM_findObj(n, d) {  // find DIV in DOM or ns4.x
  var p,i,x;  if(!d) d=document;
   if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];
   for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
   x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
} // end MM_findobj

function get_anchor(doc,nm) // find anchor position in DOM or ns4.x
{
  l = doc.anchors.length;
  for (i=0; i<l; i++) { // open loop code
    if (doc.anchors[i].name == nm){ // open each anchor
     e = doc.anchors[i];
     if (document.layers) { // open ns 4.x code
       fy = e.y;
       fx = e.x;
     } // end ns 4.x code
     else { // open non-ns code
      fy = absy(e);
      fx = absx(e);
     } // end non-ns code
     e = new Object();
     e.fx = fx;
     e.fy = fy;
     return e;
     } // end each anchor
  } // end loop code
  return false;
}  // end get_anchor

function gb_check_hide(e) // green commands bar onmouseover, onmousemove
{
 var tc = "none"; // default className of mouse target in commands bar
 if (parent.top.COMMANDS.document.event)
  var ie_e = parent.top.COMMANDS.document.event;
 else
  var ie_e = null;

 var e = (e) ? e : ie_e ;
 if (e) {
  var trg=(e.target) ? e.target :
          ((e.srcElement) ? e.srcElement : null);
  if (trg) {
    tc = trg.className;
    while (!tc) {
      if (trg.parentNode) {
        trg = trg.parentNode;
        tc=trg.className;
      } // if parent node
      else
        tc = "Not a match";
    } // while tc undefined
  } // if found target trg
 } // if found event e
 else return;

 if (tc == "comtab"){ // commentaries style class
   var rd=parent.top.RIGHT.document;
   var sl = MM_findObj("summenu",rd);
   if (sl) { // summenu layer
     if (sl.style.visibility == "visible") {
       top.onmenu = ''; // digests flag to exit
       my_hide_menu(); // digests exit strategy
     } // summenu was visible
   } // summenu defined
 } // target class is comtab

 if (tc == "sumtab"){ // summaries style class
   var rd=parent.top.RIGHT.document;
   var cl = MM_findObj("commenu",rd);
   if (cl) { // commenu layer
     if (cl.style.visibility == "visible") {
       top.comonmenu=''; // commentaries flag to exit
       com_my_hide_menu() // commentaries exit strategy
     } // summenu was visible
   } // summenu defined
 } // target class is sumtab

} // end gb_check_hide


// ******** DOM Summaries menu functions ********

function show_menu() // DOM sumtab onmouseover
{
 var d=parent.top.RIGHT.document;
 var c = MM_findObj("summenu",d);
 if (c) {
  if (c.style.visibility != "visible") {
   var q=parent.top.COMMANDS.document;
   var e = get_anchor(q,"summaries");
   if (e) {
    var adjust = -1;
    if (top.QLBrowser.ie5mac) adjust = 2; // ie5mac prints right
    var fx = e.fx + adjust;

    var s=c.style;
    var addon="px"
    var showon="visible";

    top.onmenu = '1';

    var topscreen = d.body.scrollTop;

    s.top= topscreen + addon;
    s.left=fx + addon;
    s.visibility=showon;

    r = MM_findObj("sumtab",q);
    if (r) r.style.backgroundColor="blue";
   } // if found the anchor
  } // if not visible
 } // if summenu
} // end show_menu

function hide_menu(e) // summenu onmouseout
{
 var f = "none";
 var e = (e) ? e :((event) ? event : null);
 if (e) {
  var trg=(e.relatedTarget) ? e.relatedTarget :
          ((e.toElement) ? e.toElement : null);
  if (trg) {
    f = trg.className;
    while (!f) {
      if (trg.parentNode) {
        trg = trg.parentNode;
        f=trg.className;
      } // if parent node
      else
        f = "Not smenu";
    } // while f is undefined
    if (f == "smenu") return;
  } // if found target trg
 }  // if found event e
 else return;

 top.onmenu='';
 my_hide_menu();
} // end hide_menu

function set_in() // summenu onmouseover, onmousemove
{
  top.onmenu='1';
} // end set_in

function summaries_mm(e) // sumtab onmousemove
{
 f = "none";
 if (parent.top.COMMANDS.document.event)
  ie_e = parent.top.COMMANDS.document.event;
 else
  ie_e = null;

 e = (e) ? e : ie_e ;
 if (e) {
  y = (e.y) ? e.y : e.layerY ;
  if (y<1) {
   top.onmenu = '';
   my_hide_menu();
   return;
  } // if (y<1)
 } // if e
 show_menu();
} // end summaries_mm

function summaries_hide_menu(e) // sumtab onmouseout
{
 f = "none";
 if (parent.top.COMMANDS.document.event)
  ie_e = parent.top.COMMANDS.document.event;
 else
  ie_e = null;

 e = (e) ? e : ie_e ;
 if (e) {
  y = (e.y) ? e.y : e.layerY ;
   if (y < 1) {
     really_hide_menu();
     return;
   }
 }
 if (e) {
  var trg=(e.relatedTarget) ? e.relatedTarget :
          ((e.toElement) ? e.toElement : null);
  if (trg) {
    f = trg.className;
    while (!f) {
      if (trg.parentNode) {
        trg = trg.parentNode;
        f=trg.className;
      } // if parent node
      else
        f = "Not sumtab";
    } // while f undefined
  } // if found target trg
 } // if found event e
 else { return; }

 if (f == "sumtab") return; // no exit if same class
 top.onmenu = '';
 setTimeout("my_hide_menu();", 500);
} // end summaries_hide_menu

function my_hide_menu()
{
 if (top.onmenu)
  if (top.onmenu == '1')
    return;
 really_hide_menu();
} // end my_hide_menu

function really_hide_menu() // summaries final exit
{
 c = MM_findObj("summenu",parent.top.RIGHT.document);
 if (c) {
  if(c.style.visibility == "visible"){
   c.style.visibility = "hidden";
   r = MM_findObj("sumtab",parent.top.COMMANDS.document);
   if (r) r.style.backgroundColor="green";
  } // if visible
 } // if c
} // end really_hide_menu


// ******** Netscape 4.x Summaries menu functions ********

function net_show_test(e) // netscape 4.x sumtab onmouseover
{
 top.nettab = 1;
 if (top.netmenu == 1){
   top.netmenu = 0;
 } // came from below
 else{
   net_show_final();
 } // came from outside
} // net_show_test

function net_show_final() // netscape 4.x menu display
{
 var rd = parent.top.RIGHT.document;
 if (rd) var sl = rd.layers["summenu"]; else var sl= NULL;
 if (sl) {
   var ld=parent.top.COMMANDS.document.LNKS.document;

   if (ld) { // Have LNKS layer document
     var lda = ld.anchors;
     var ldal = lda.length;
     for (i=0; i<ldal; i++){ // anchor loop code
       if (lda[i].name == 'summaries'){ // open each anchor
         var m = lda[i];
       } // if summaries
     } // for each named anchor

     if (m) { // have summaries anchor
       if (!FR_INT){
	 ld.images['sumimage'].src = "../img/sumxeimage.gif"; // blue English
       }
       else{
	 ld.images['sumimage'].src = "../img/sumxfimage.gif"; // blue French
       }
       var fx = m.x; // capture x-position of anchor

       var showon = "show"
       var topscreen = parent.RIGHT.pageYOffset; // ns4.x way of doing it
       sl.top= topscreen;
       sl.left=fx;
       sl.visibility=showon;

     } // if found summaries anchor m
   } // if found LNKS layer document ld
 } // if found summenu layer sl
} // end net_show_final

function net_hide_test(e) // netscape 4.x sumtab onmouseout
{
 if (top.netmenu != 1){
   net_hide_final(); // going outside sumtab
 }
} // net_hide_test

function net_pass_down(e) // netscape 4.x summenu onmouseover
{
  top.nettab = 0; // came from above
  top.netmenu = 1; // have gone below
} // net_pass_down

function net_hide_verify(e) // netscape 4.x summenu onmouseout
{
 if (top.netmenu == 1){
   net_hide_final();
 } // going outside
} // net_hide_verify

function net_hide_final() // netscape 4.x confirmed summenu hide
{
 var rd = parent.top.RIGHT.document;
  if (rd) var m = rd.layers["summenu"]; else var m= NULL;
  if (m) { // ns4.x goes invisible
      var showoff = "hide"
      m.visibility=showoff;
      top.nettab = 0;
      top.netmenu = 0;
  } // if ns4.x summenu m

 var ld=parent.top.COMMANDS.document.LNKS.document;
  if (ld) { // Have LNKS layer document
    if (!FR_INT){
      ld.images['sumimage'].src = "../img/sumeimage.gif"; // green English
    }
    else {
      ld.images['sumimage'].src = "../img/sumfimage.gif"; // green French
    }
  } // if have LNKS document

} // net_hide_final

