/*
 * Creativyst(R) Multi-Color Fader:
 *
 *      (C) Copyright 2004 Creativyst, Inc.
 *            ALL RIGHTS RESERVED
 *
 * Use of this software in running applications, with
 * or without modification, is permitted provided
 * that the conditions published at:
 * www.creativyst.com/Prod/18/Scroller/BalScr.htm 
 * are met.
 *
 *    This software may not be redistributed
 *
 *     - This comment may not be removed -
 *
 * v1.0a
*/


/* Configurations:
 *  Set these general configuration variables to change
 *  how your scroller looks and acts.
 *
 *  See below for how to add static and/or dynamic content for display
 *
*/
var mcfWidth=170;
var mcfHeight=160;

var mcfFadedColor = "#CCCCFF";  // Text/Link color when faded OUT
                                //   (Normally set to the background color)
var mcfTextColor = "#000000";   // Text color when ON (faded IN)
var mcfLinkColor = "#0000FF";   // Link color when ON (faded IN)

var mcfFadeINIncr = 17;     // Amt to change color when fading IN
var mcfFadeOUTIncr=55;      // Amt to chng whn fading OUT (0 for instant)

var mcfFrameRate = 60;      // was 40
var mcfPauseDelay = 5000;   // or Maximum if mcfVaryPause
var mcfPauseMin = 3500;     // If mcfVaryPause
var mcfOUTPause = 0;        // 0 for no pause when faded OUT
var mcfVaryPause = 1;       // Vary pause based on msg length
var mcfMiddle = 1;          // 1 for vertical middle, 0 for top

var mcfUseBallistics = 1;    // (not used) 0 for linear movers



var mcfContent=new Array();  // don't change
mcfContent[0] = "";


/* Static Content:
 *  Fill elements of the mcfContent[] array with static messages you'd like
 *  to display on the scroller.  You can use the Multi-Color Fader to
 *  display only the static messages defined here, or you can include a static
 *  message or two to be displayed along with dynamic JSMsg feed data (see below).
 *
 *  Delete or comment out these array lines (but not the above declaration)
 *  if you don't want to display static messages.
 *
*/
// mcfContent[0] = "Display: <strong>Dynamic JSMsg feeds</strong> on your site with the Multi-Color Fader from Creativyst<CENTER><HR WIDTH=\"25%\"></center>";
// mcfContent[1] = 'Message pause can be set to vary with the length of each message displayed for random effects.\n';
// mcfContent[2] = "And did we mention it's <strong>JSMsg Ready<\/strong>?";
// mcfContent[3] = "<strong>JSMsg<\/strong> lets you display <strong><em>dynamic<\/em><\/strong> information from outside JSMsg feeds ...<P\/><UL><LI>Set <B>one<\/B> variable!<LI><strong>NO<\/strong> server-side scripting!<\/UL> :-)";




/* Dynamic Content (JSMsg feeds):
 *  JSMsgNS     
 *      Namespace of the JSMsg feed who's messages you'd
 *      like to display.  You must include the JSMsg
 *      link in a JavaScript <SCRIPT> tag ABOVE this
 *      script.
 *
 *      You may display messages from multiple JSMsg feeds
 *      by listing multiple namespaces in the JSMsgNS variable.
 *      e.g.  
 *
 *          JSMsgNS = "niq cvtnew"; 
 *
 *      Leave this set to JSMsgNS = ""; if you only need
 *      to display static messages from the above arrays.
 *
 *  JSMsgSeq
 *      Messages from muliple newsfeeds are normally interleaved
 *      but they can be sequential by setting the JSMsgSeq variable
 *      to 1
 *
*/
var JSMsgNS = "JsmInfo";
var JSMsgSeq = 0;


/* ==========================================================================
 * End of user configurable variables
 * ==========================================================================
*/

/* JSCpragma:StartCompress
*/






var bsOrgArray = new Array();
bsOrgArray[0] = "";



var mcfCur_i = 0;
var DOMObjC;
// var DOMObjL;
// var DOMObjR;
var IEObj;
var NS4xObj;
var BalIncr = mcfFadeINIncr;
var mcfBeenHere = 0; // for NS4.x
var mcfMousePaused = 0;
var MessagePaused = 0;
var MsgPauseNow = mcfPauseDelay;
var bsISRWaiting = 0;
var mcfSmallestContent = 0;
var mcfBiggestContent = 0;
var mcfBiggestDif = 0;

// var bsOrgArray = new Array();

var mcfState = 0;    // 0 faded-IN, 1=fadING-OUT, 2=faded-OUT, 3=fadING-IN

var Globi = 0;
var mcfMPCount = 0;
var mcfCritical = 0;

function mcfInitialize()
{
  var divobj;
  var cpyi;

  if(!mcfBeenHere) {
      /* good ol' NS4
      */
      mcfBeenHere = 1;
      setTimeout("mcfInitialize()", 1100);
      return;
  }
  else {

      mcfFadedColor = mcfFadedColor.toLowerCase();
      mcfTextColor = mcfTextColor.toLowerCase();
      mcfLinkColor =  mcfLinkColor.toLowerCase();

      for(cpyi = 0;cpyi < mcfContent.length;cpyi++) {
        bsOrgArray[cpyi] = mcfContent[cpyi];
      }
      if(!mcfOUTPause) {
        mcfOUTPause = 1;
      }


      /* Call to JSMsg Interface
       *  Your display array will be returned
       *  unchanged if no namespaces are listed.
       *  If you define namespaces in JSMsgNS their
       *  messages will be appended to the end of the
       *  array.   -D.J.Repici
      */
      if(!mcfContent[0]) {
        mcfContent.length = 0;
      }
      mcfContent = JSMsgIf(mcfContent, JSMsgNS, JSMsgSeq);
      mcfSizeContent();


      if(document.getElementById) { // DOM
            divobj = document.getElementById('ScrollerFrame');
            divobj.style.width = mcfWidth + 'px';
            divobj.style.height = mcfHeight + 'px';

            divobj = document.getElementById('mcfWindow');
            divobj.style.width = mcfWidth + 'px';
            divobj.style.height = mcfHeight + 'px';



            divobj = document.getElementById('mcfCWindow');
            divobj.style.width = mcfWidth + 'px';
            divobj.style.height = mcfHeight + 'px';
            divobj.style.zIndex = 1;
            divobj.style.color = mcfFadedColor;
            DOMObjC = divobj;

//            divobj = document.getElementById('mcfLLid');
//            divobj.style.width = mcfWidth + 'px';
//            divobj.style.height = mcfHeight + 'px';
//            divobj.style.zIndex = 2;
//            DOMObjL = divobj;

//            divobj = document.getElementById('mcfRLid');
//            divobj.style.width = mcfWidth + 'px';
//            divobj.style.height = mcfHeight + 'px';
//            divobj.style.zIndex = 3;
//            DOMObjR = divobj;


            /* Pull content up
            */
//            DOMObjL.style.top = '0px';
//            DOMObjR.style.top = (mcfHeight*(-1)) + 'px';
//            DOMObjC.style.top = ((mcfHeight*2) * (-1)) + 'px';

            DOMObjC.style.top =  '0px';

          // DOMObjC.innerHTML = mcfContent[mcfCur_i];
          // DOMObjC.style.color = "#000000";
          // alert("Hold-it");

            /* Position L(T) and R(B)
            */
            // tmp = (mcfWidth/2);
            // tmp = parseInt(tmp);

//            DOMObjL.style.left = ((mcfWidth)*(-1)) + 'px';
//            DOMObjR.style.left = (mcfWidth) + 'px';

            moverDOM();
      }
      else if(document.all) {
        ScrollerFrame.style.width = mcfWidth;
        IEObj=eval(mcfCWindow);
        IEObj.style.pixelTop=(mcfHeight * (-1));
//        IEObj.style.pixelTop=((mcfHeight*2) * (-1));
        moverIE();
      }

      else if(document.layers) {
        NS4xObj=document.mcfSlideWindow.document.mcfContentWindow;

//        NS4xObj=document.mcfSlideWindow.document.mcfTopLid;
//        NS4xObj.document.write(mcfContent[mcfCur_i]);
//        NS4xObj.document.close();
        moverNS4x();
      }

  } // end 'been here'

}

/*
 * Move a source color (cFrom) toward
 * a specified destination color (cTo)
 * by a specified amount.
 *
 * Return the new color.
 *
*/
function MoveColor(cFrom, cTo, myIncr)
{
    var i, cNew;
    var f = new Array();
    var t = new Array();
    var sFrom = new String();
    var sTo = new String();
    var dt, dt2, dt3;

    sFrom = cFrom;
    sTo = cTo;

    if(!sFrom) {
        sFrom = "#000000";
    }
    if(!sTo) {
        sTo = "#000000";
    }
    sFrom = NormalizeColorNotation(sFrom);
    sTo = NormalizeColorNotation(sTo);

    if(!myIncr) {
        // alert(sTo);
        return(sTo);
    }

    dt = sTo.substr(1,2);
    dt2 = sFrom.substr(1,2);
    dt3 = sFrom.substr(3,2);
    dt = sFrom.substr(5,2);

    
    t[0] = parseInt(sTo.substr(1,2),16);
    t[1] = parseInt(sTo.substr(3,2),16);
    t[2] = parseInt(sTo.substr(5,2),16);
    f[0] = parseInt(sFrom.substr(1,2),16);
    f[1] = parseInt(sFrom.substr(3,2),16);
    f[2] = parseInt(sFrom.substr(5,2),16);

//    alert("sFrom:" + sFrom + "  " + dt + dt2 + dt3 + "  t0t1t2f0f1f2:" + t[0] + t[1] + t[2] + f[0] + f[1] + f[2] + "   myIncr:" + myIncr);

    for(i = 0;i < 3;i++) {
        if(f[i] != t[i]) {
            if(f[i] > t[i]) {
                f[i] -= myIncr;
                f[i] = (f[i]<t[i]) ? t[i] : f[i];
            }
            else {
                f[i] += myIncr;
                f[i] = (f[i]>t[i]) ? t[i] : f[i];
            }
        }
    }


    for(i=0;i<3;i++) {
        f[i] = f[i].toString(16);
        while(f[i].length < 2) { f[i] = "0" + f[i]; }
    }
    // alert("f0f1f2:" + f[0] + f[1] + f[2] + "   myIncr:" + myIncr + " sTo:" + sTo);

    cNew = "#" + f[0] + f[1] + f[2];
    // alert("cnew:" + cNew + "  mcfState:" + mcfState);
    return(cNew);
}



/* There has GOT to be an easier
 * way to do this...
 *
*/
function NormalizeColorNotation(sParm)
{
    var tc,tr,tg,tb,sW, rv;
    var tmpAr = new Array();

    /* Normalize color notation
    */
    if(sParm.indexOf("rgb(") > -1) {
        tr = tg = tb = "";
        tmpAr = sParm.split(",");
        for(i = 0;i < tmpAr[0].length;i++) {
            tc = tmpAr[0].charAt(i);
            if(tc >= '0' && tc <= '9') {
                tr += tc;
            }
            tc = "";
            tc = tmpAr[2].charAt(i);
            if(tc >= '0' && tc <= '9') {
                tb += tc;
            }
        }
        tg = tmpAr[1];
        tr = parseInt(tr); tg = parseInt(tg); tb=parseInt(tb);
        sW = "#";
        tc = tr.toString(16);
        while(tc.length < 2) { tc = "0" + tc }
        sW += tc;
        tc = tg.toString(16);
        while(tc.length < 2) { tc = "0" + tc }
        sW += tc;
        tc = tb.toString(16);
        while(tc.length < 2) { tc = "0" + tc }
        sW += tc;
        rv = sW;
    }
    else {
        if(sParm.indexOf("#") == -1) {
            sParm = "#" + sParm;
        }
        rv = sParm;
    }
    return(rv);
}



function moverDOM()
{
  var reducer, tmp, tmpL, tmpR;
  var myDone, myTxtCol, myLnkCol;
  var tmpAr = new Array();

var Stmp;
Stmp = "";

//  var LPos = parseInt(DOMObjL.style.left);
//  var RPos = parseInt(DOMObjR.style.left);

  Globi++;

  if(!mcfState) { // faded-IN(paused)
    if(mcfMousePaused) {
        mcfMPCount++;
        if(mcfMPCount > 500) { // 25 seconds at 50 frame-rate
            mcfMousePaused = 0;
        }
        setTimeout("moverDOM()", mcfFrameRate);
        return;
    }
    mcfState = 1;
    setTimeout("moverDOM()", mcfFrameRate);
  }


  else if(mcfState == 1) { // fadING-OUT
    myTxtCol = NormalizeColorNotation(DOMObjC.style.color);
    myLnkCol = "";
    tmpAr.length = 0;
    tmpAr = DOMObjC.getElementsByTagName("a");
    myDone = 0;

    if(tmpAr && tmpAr.length) {
        myLnkCol = NormalizeColorNotation(tmpAr[0].style.color);
        if( (myLnkCol == mcfFadedColor) && (myTxtCol == mcfFadedColor) ) {
            myDone = 1;
        }
    }
    else {
        if(myTxtCol == mcfFadedColor) {
            myDone = 1;
        }
    }



    if(myDone) {
        mcfState = 2; // faded-OUT
        setTimeout("moverDOM()", mcfOUTPause);
        return;
    }
    else {
        DOMObjC.style.color = 
            MoveColor(  DOMObjC.style.color,
                mcfFadedColor,
                mcfFadeOUTIncr);

        if(tmpAr && tmpAr.length) {
            for(i = 0;i < tmpAr.length;i++) {
                tmpAr[i].style.color = 
                    MoveColor(  tmpAr[i].style.color,
                                mcfFadedColor,
                                mcfFadeOUTIncr);
            }
        }
        setTimeout("moverDOM()", mcfFrameRate);
        return;
    }        
  }

  else if(mcfState == 2) { // Faded-OUT(Paused)


      if(mcfCritical) {
          setTimeout("moverDOM()", mcfFrameRate);
      }

      if(mcfMiddle) {
          DOMObjC.innerHTML = 
            '<table height="100%"><tr><td>' + 
            mcfContent[mcfCur_i] + 
            '<\/td><\/tr><\/table>';
      }
      else {
          DOMObjC.innerHTML = mcfContent[mcfCur_i];
      }
      mcfState = 3;

      /* set start colors
      */
      tmpAr.length = 0;
      tmpAr = DOMObjC.getElementsByTagName("a");
      for(i = 0;i < tmpAr.length;i++) {
          // tmpAr[i].style.color = 
            tmp =  MoveColor(  tmpAr[i].style.color,
                          mcfFadedColor,
                          0);
            tmpAr[i].style.color = tmp;
//                          alert(tmp);
      }
      



/*
 *
      tmpR = RPos + mcfFadeINIncr;
      DOMObjR.style.left = tmpR + "px";
      tmpL = LPos  - mcfFadeINIncr;
      DOMObjL.style.left = tmpL + "px";
 *
 */
      setTimeout("moverDOM()", mcfFrameRate);
      return;
  }
  else if(mcfState == 3) { // fadING-IN

    myTxtCol = NormalizeColorNotation(DOMObjC.style.color);
    myLnkCol = "";
    tmpAr.length = 0;
    tmpAr = DOMObjC.getElementsByTagName("a");
    myDone = 0;

    if(tmpAr && tmpAr.length) {
        myLnkCol = NormalizeColorNotation(tmpAr[0].style.color);
        if( (myLnkCol == mcfLinkColor) && (myTxtCol == mcfTextColor) ) {
            myDone = 1;
        }
    }
    else {
        if(myTxtCol == mcfTextColor) {
            myDone = 1;
        }
    }

    // DEBUG
       // alert("mcfState:" + mcfState + "  myTxtCol:" + myTxtCol + " myLnkCol:" + myLnkCol + " myDone:" + myDone + " DOCstylecol:" + DOMObjC.style.color);

    if(myDone) {

        tmp = mcfGetOpenDelay();
        mcfCur_i++;
        if(mcfCur_i >= mcfContent.length) {
          mcfCur_i = 0;
        }

        mcfState = 0; // faded-IN
        setTimeout("moverDOM()", mcfPauseDelay);
        return;
    }
    else {
        DOMObjC.style.color = 
            MoveColor(  DOMObjC.style.color,
                mcfTextColor,
                mcfFadeINIncr);

        if(tmpAr && tmpAr.length) {
            for(i = 0;i < tmpAr.length;i++) {
                tmpAr[i].style.color = 
                    MoveColor(  tmpAr[i].style.color,
                                mcfLinkColor,
                                mcfFadeINIncr);
            }
        }
        setTimeout("moverDOM()", mcfFrameRate);
        return;
    }        
  }
}







/* Older IE (no DOM)
 *  Just rotate message
 *
*/
function moverIE()
{
  var tmp;

  if(mcfMiddle) {
      IEObj.innerHTML = 
        '<table height="100%"><tr><td>' + 
        mcfContent[mcfCur_i] + 
        '<\/td><\/tr><\/table>';
  }
  else {
      IEObj.innerHTML = mcfContent[mcfCur_i];
  }
  mcfCur_i++;
  if(mcfCur_i >= mcfContent.length) {
    mcfCur_i = 0;
  }

  mcfState = 0; // opened
  tmp = mcfGetOpenDelay();
  setTimeout("moverIE()", tmp);


 //  var myTop = parseInt(IEObj.style.pixelTop);
 // BallisticsProc(myTop);
/******
 *
  if (IEObj.style.pixelTop>=mcfFadeOUTIncr) {
      IEObj.style.pixelTop-=BalIncr;
      if(!mcfMousePaused && !MessagePaused) {
        bsISRWaiting++;
          setTimeout("moverIE()",mcfFrameRate);
      }
  }
  else{
      PauseTop();
  }
 *
 ***************/

}


/* Older NS (no DOM)
 *  Just rotate message
 *
*/
function moverNS4x()
{

  NS4xObj.document.write( mcfContent[mcfCur_i] );
  NS4xObj.document.close();

  mcfCur_i++;
  if(mcfCur_i >= mcfContent.length) {
    mcfCur_i = 0;
  }

  mcfState = 0; // opened
  tmp = mcfGetOpenDelay();
  setTimeout("moverNS4x()", tmp);


    // BallisticsProc(NS4xObj.top);
/**********
 *
    if(NS4xObj.top>=mcfFadeOUTIncr) {
      NS4xObj.top-=BalIncr;
      if(!mcfMousePaused && !MessagePaused) {
          bsISRWaiting++;
          setTimeout("moverNS4x()",mcfFrameRate);
      }
    }
    else{
      PauseTop();
    }
 *
 ********************/


}



function mcfGetOpenDelay()
{
    var tmp;
    var thisdif;

  if(mcfVaryPause) {
    thisdif = mcfContent[mcfCur_i].length  - mcfSmallestContent;

    tmp = thisdif / mcfBiggestDif;
    tmp = mcfPauseDelay * tmp;
    tmp = parseInt(tmp);

    if(tmp < mcfPauseMin) {
        tmp = mcfPauseMin;
    }

    return(tmp);
  }
  return(mcfPauseDelay);
}


function mcfSizeContent()
{
    var cpyi;

  /* Find smallest and largest
   * message size
  */
  mcfSmallestContent = 5000;
  mcfBiggestContent = 0;
  for(cpyi = 0;cpyi < mcfContent.length;cpyi++) {
    if(mcfContent[cpyi].length < mcfSmallestContent) {
        mcfSmallestContent = mcfContent[cpyi].length;
    }
    if(mcfContent[cpyi].length > mcfBiggestContent) {
        mcfBiggestContent = mcfContent[cpyi].length;
    }
  }
  mcfBiggestDif = mcfBiggestContent - mcfSmallestContent;
}

function mcfChangeFeeds(newJSMsgNS)
{
  mcfCritical = 1;
    mcfContent.length = 0;
    JSMsgNS = newJSMsgNS;
    mcfContent = JSMsgIf(mcfContent, JSMsgNS, JSMsgSeq);
    mcfSizeContent();
    mcfCur_i = 0;
  mcfCritical = 0;
}



 /*
  *
  *
function BallisticsProc(ThisTop)
{
  if(mcfUseBallistics &&
     BalIncr > 2  ) {
    if(ThisTop < (mcfHeight/7)) {
        BalIncr = mcfFadeOUTIncr - 1;
    }
    if(ThisTop < (mcfHeight/8) ) {
        BalIncr = mcfFadeOUTIncr - 3;
    }
    if(ThisTop < (mcfHeight/10) ) {
        BalIncr = mcfFadeOUTIncr - 7;
    }
    if(ThisTop < 8) {
        BalIncr = 1;
    }
    BalIncr = (BalIncr < 1 ? 1 : BalIncr);

  }

}
  *
  *
 */


 /*
  *
  *
function PauseTop()
{
    MessagePaused = 1;
    // alert("PauseTop()")
    setTimeout("ChangeContent()", MsgPauseNow);
}

function ChangeContent()
{

    MessagePaused = 0;
    MsgPauseNow = mcfPauseDelay;

    if(!mcfMousePaused) { 
        mcfCur_i++;
        if(mcfCur_i >= mcfContent.length) {
            mcfCur_i = 0;
        }

        if(document.getElementById) {
            DOMObj.innerHTML=mcfContent[mcfCur_i];
            DOMObj.style.top=mcfHeight + 'px';
            BalIncr = mcfFadeOUTIncr;
            moverDOM();
        }
        else if(document.all) {
            IEObj.style.pixelTop=mcfHeight
            IEObj.innerHTML=mcfContent[mcfCur_i] 
            BalIncr = mcfFadeOUTIncr;
            moverIE();
        }
        else {
            NS4xObj.document.write(mcfContent[mcfCur_i]);
            NS4xObj.document.close();
            NS4xObj.top=mcfHeight;
            BalIncr = mcfFadeOUTIncr;
            moverNS4x();
        }
    }
    else {
        MsgPauseNow = mcfFrameRate;
    }
}

  *
  *
 */



function MousePause()
{
    mcfMousePaused = 1;
}


function MouseStart()
{ 
    mcfMousePaused = 0; 
}




function RunScroller()
{
    var msg;

 msg = '';
 msg += '<div ID="ScrollerFrame" CLASS="ScrollerFrame">';

 if(!document.getElementById && !document.all) {
     msg += '<ilayer name="mcfSlideWindow" width="' + mcfWidth + '"; height="' + mcfHeight + '";>\n';
//       msg += '<layer name="mcfTopLid" width="' + mcfWidth + '"; height="' + mcfHeight + '"; onMouseover="MousePause();" onMouseout="MouseStart();">';
//       msg += '<\/layer>';
//       msg += '<layer name="mcfBotLid" width="' + mcfWidth + '"; onMouseover="MousePause();" onMouseout="MouseStart();">';
//       msg += '<\/layer>';
       msg += '<layer name="mcfContentWindow" width="' + mcfWidth + '"; onMouseover="MousePause();" onMouseout="MouseStart();">';
       msg += '<\/layer>';
     msg += '<\/ilayer>';
 }

 document.write(msg);

 if (document.getElementById || document.all) {

    document.write('<div id="mcfWindow" class="mcfWindow" style="position:relative;overflow:hidden;width:' +mcfWidth+ ';height:' +mcfHeight+ ';clip:rect(0 ' +mcfWidth+ ' ' +mcfHeight+ ' 0);" onMouseover="MousePause();" onMouseout="MouseStart();">');
//      document.write('<div id="mcfLLid" class="mcfLLid" style="position:relative;height:0;width:' +mcfWidth+ ';"><\/div>');
//      document.write('<div id="mcfRLid" class="mcfRLid" style="position:relative;height:0;width:' +mcfWidth+ ';"><\/div>');
      document.write('<div id="mcfCWindow" class="mcfCWindow" style="position:relative;"><\/div>');
//      document.write('<div id="mcfHider" class="mcfHider" style="position:relative;height:0;width:' +mcfWidth+ ';"><\/div>');
    document.write('<\/div>');
 }
 
  document.write('<\/div>');

  mcfInitialize();
}





/* =========================================
 * =========================================
*/
/*
 * JSMsg Client Interface Code
 *
 * (C) Copyright 2003 - 2004 Creativyst, Inc.
 *            creatvisyt.com
 *         ALL RIGHTS RESERVED
 *
 * Developers may use the following
 * JSMsg client interface functions
 * freely in their code, modified or
 * unmodified as long as this entire
 * comment is included and intact.
 *
*/

/*
 * JSMsgIf() (Interface function):
 *
 *  This function takes an array of messages
 *  to display.  If there are no JSMsg
 *  namespaces defined it will return
 *  the array unchanged.  Otherwise
 *  it will append the entries from the
 *  JSMsg feeds on to whatever is already
 *  in the array.
 *
 *  msgAr   Message array to be appended
 *          with messages from the feeds
 *          (for use by the scroller app).
 *
 *  myNs    String containing namespaces for
 *          each JSMsg feed you want to display
 *          messages from.  Leave "" to simply
 *          return your array without additions.
 *
 *  mySeq   Messages from multiple JSMsg files
 *          are normally interleaved. Set this
 *          to 1 to present each JSMsg file
 *          end-to-end.
 *
 *  Example call:
 *
 *      JSMsgNs = "ciq cvs"; // namespaces setting var
 *      JSMsgSeq = 0;        // sequence setting var    
 *      myArray = JSMsgIf(myArray,JSMsgNs,JSMsgSeq);
 *
*/
function JSMsgIf(msgAr, myNs, mySeq)
{
    var TotNS,LongestNS;
    var NSAr = new Array();
    var i,j,k,o;

    if(!myNs) {
        myNs = "";
    }
    if(!mySeq) {
        mySeq = 0;
    }

    /* get the offset
    */
    o = msgAr.length;

    if(myNs) {
        NSAr = myNs.split(" ");
        TotNS = NSAr.length;

        /* Get longest length
        */
        LongestNS = 0;
        j = 0;
        for(i = 0;i < TotNS;i++) {
            j = jsmMetaMsg(NSAr[i], "MetaCount");
            if(j > LongestNS) {
                LongestNS = j;
            }
        }
        if(!j) {
            return(msgAr);
        }

        /* Interleave unless
         * mySeq is set
        */
        k = o; // offset
        if(mySeq) {
            for(j = 0;j < TotNS;j++) {
                for(i = 0;i < LongestNS;i++) {
                    if(jsmMetaMsg(NSAr[j],"MetaCount") <= i) {
                        continue;
                    }
                    msgAr[k] = jsmGetN(NSAr[j], "LinkTitle", i);
                    if(!msgAr[k]) { // no linktitle, use body
                        msgAr[k] = jsmGetN(NSAr[j], "Body", i);
                        msgAr[k] += "<BR>&nbsp;&nbsp;&nbsp;-";
                        t = jsmGetN(NSAr[j], "Attrib",i);
                        if(t.length > 17) {
                            t = t.substr(0,14);
                            t += "...";
                        }
                        msgAr[k] += t;
                    }
                    msgAr[k] = msgAr[k].replace(/&amp;/g, "&");
                    msgAr[k] = msgAr[k].replace(/&apos;/g, "\'");
                    k++;
                }
            }
        }
        else {
            for(j = 0;j < LongestNS;j++) {
                for(i = 0;i < TotNS;i++) {
                    if(jsmMetaMsg(NSAr[i],"MetaCount") <= j) {
                        continue;
                    }
                    msgAr[k] = jsmGetN(NSAr[i], "LinkTitle", j);
                    if(!msgAr[k]) { // no linktitle, use body
                        msgAr[k] = jsmGetN(NSAr[i], "Body", j);
                        msgAr[k] += "<BR>&nbsp;&nbsp;&nbsp;-";
                        t = jsmGetN(NSAr[i], "Attrib",j);
                        if(t.length > 17) {
                            t = t.substr(0,14);
                            t += "...";
                        }
                        msgAr[k] += t;
                    }
                    msgAr[k] = msgAr[k].replace(/&amp;/g, "&");
                    msgAr[k] = msgAr[k].replace(/&apos;/g, "\'");
                    k++;
                }
            }
        }
    }

    return(msgAr);
}




function jsmGetN(ns,MsgPart,number)
{
    var rv, c, er;

    c = "rv = " + ns + ".GetN('" + MsgPart + "'," + number + ");";
    er = eval(c);

    return(rv);
}


function jsmGet(ns,MsgPart,offset)
{
    var rv, c, er;

    c = "rv = " + ns + ".Get('" + MsgPart + "'," + offset + ");";
    er = eval(c);

    return(rv);
}


function jsmGetDay(ns,MsgPart)
{
    var rv, c, er;

    c = "rv = " + ns + ".GetDay('" + MsgPart + "');";
    er = eval(c);

    return(rv);
}


function jsmMetaMsg(ns,MsgPart)
{
    var rv, c, er;

    c = "rv = " + ns + ".MetaMsg('" + MsgPart + "');";
    er = eval(c);

    return(rv);
}


/*
 * Comment this out if you want to move the script
 * to the <HEAD> section or call it externally
*/
// RunScroller();


