//////////////////////////////////////////////////////////////////
////////  Hey, you, this file (and all other FL* products) ///////
//////  was conceived and created by Shad-O in Shadow ////////////
////  If you get your grubby paws on it, note that it's use //////
////////   falls under the terms of the  /////////////////////////
///// GNU Library General Public License (www.gnu.org) ///////////
/////// This is the Shad-O on Reality's high /////////////////////
/////// /FLI.begins.za.net/ ///////// jais@bluebottle.com ////////
//////////////////////////////////////////////////////////////////
//// FLWin.js - JavaScript window element specific functions /////
//// requires xbStyle components and FLCore.js ///////////////////
//// Last modified 24 July 2008 ce ///////////////////////////////
//////////////////////////////////////////////////////////////////

//=============== Initialise Some Common Objects ==============================
  var disabledButtons = "";         // define buttons that should be disabled
  var defaultStatusText = "";       // the default text to show in the browser status bar
  var defaultDetailedText = "";     // the default text to show in infoPanels if they exist
  var defaultInfoTitle = "";        // the default text to show as infoPanel titles
  var statusPanelFrozen = false;    // the state of the infoPanel

  // fade related objects
  var objectFadeTO = 0;             // fading call timeout ID
  var objectFadeOpacity = 0;        // current opacity of object
  var objectFadeSpeed = 20;         // fading speed
//=============================================================================


//=============== Define Common functions/classes =============================
  //============= Add a site to the browser's bookmarks =====================
  function addBookmark(bkmURI, bkmTitle, bkmDesc, bkmKeywords) {
//    if (window.external && window.external.AddFavorite) {
      window.external.AddFavorite(bkmURI,bkmTitle); /*}
     else {
      window.alert("Sorry, this feature currently only works for Internet Explorer's Favorites."); }*/}
  //=========================================================================
      
  //=========== Cross-browser getSelection ==================================
  function whatisSelected() {
    var selectedHTML = "";
    var selectObj;
    if (document.getSelection) { selectObj = document.getSelection(); }
     else if (window.getSelection) { selectObj = window.getSelection(); }
     else if (document.selection) { selectObj = document.selection; }
    selectedHTML = (selectObj.toString) ? selectObj.toString() : selectObj.createRange().text;
    return(selectedHTML); }
  //=========================================================================

  //=============== Change form element status ==============================
  function changeFormState(formObject, inputType, reqState) {
    if (!isNaN(formObject) && document.forms) {
      formObject = document.forms[formObject]; }
    if (!inputType || inputType == "") {
      inputType = "button|submit"; }
    inputType = inputType.replace(/hidden/gi,"");
    if (formObject.elements) {
      formElements = formObject.elements;
      searchRE = new RegExp(inputType,"i");
      for (var cnt = 0; cnt < formElements.length; cnt++) {
        if (formElements[cnt].type.search(searchRE) > -1 ||
            (inputType == "all" && formElements[cnt].type != "hidden")) {
          formElements[cnt].disabled = !reqState; }}}}
  //=========================================================================

  //=============== Simpler changing of form element status =================
  function disableInput(elemObject) {
    elemObject.disabled = true; }

  function enableInput(elemObject) {
    elemObject.disabled = false; }
  //=========================================================================

  //=============== Change images ===========================================
  function changeImages() {
    if (document.images) {
      for (var i = 0; i < arguments.length; i += 2) {
        if (disabledButtons != "all" && document[arguments[i]].src &&
            disabledButtons.indexOf("[" + arguments[i] + "]") == -1) {
          document[arguments[i]].src = eval(arguments[i+1] + ".src"); }}}}
  //=========================================================================

  //=============== Object fading functions =================================
  function doFade(objectID,velocity,initialOpacity,finalOpacity) {
    if (objectID.setOpacity) {
      objectFadeOpacity += velocity;
      objectFadeOpacity = (objectFadeOpacity>finalOpacity)?finalOpacity:objectFadeOpacity;
      objectFadeOpacity = (objectFadeOpacity<initialOpacity)?initialOpacity:objectFadeOpacity;
      objectID.setOpacity(objectFadeOpacity);
      // the code below will create a slow down effect to the fading
//      opacityDif = Math.ceil((100-objectFadeOpacity)/velocity); // abs(velocity) must be >= 2
//      objectFadeOpacity += opacityDif;
      if ((objectFadeOpacity <= initialOpacity || objectFadeOpacity >= finalOpacity) && objectFadeTO != 0) {
        clearInterval(objectFadeTO);
        objectFadeTO = 0; }}}

  function fadeObject(objectID,velocity,initialOpacity,finalOpacity) {
    if (!initialOpacity || isNaN(initialOpacity) || initialOpacity < 0) {
      initialOpacity = 0; }
    if (!finalOpacity || isNaN(finalOpacity) || finalOpacity > 100) {
      finalOpacity = 100; }
    if (!velocity || isNaN(velocity)) {
      velocity = objectFadeSpeed; }
    objectFadeOpacity = (velocity>0)?initialOpacity:finalOpacity;
    objectFadeTO = window.setInterval(doFade,75,objectID,velocity,initialOpacity,finalOpacity); }
  //=========================================================================

  //=============== Define text fading functions ============================
    // initialise objects
    var tkrMsgList = new Array();        // array of messages for tickers
    var tkrFadeStep = new Array(0,0,0);
    var tickerPanel = null;
    var tkrFadeRate = 80;
    var tkrHoldTime = 10000;
    var tkrStartColor = new Array(255,255,255);    // RGB value to start fade
    var tkrEndColor = new Array(0,0,0);      // RGB value to end fade
    var tkrFadeSteps = 25;
    var tkrFadeID = 0;
    var tkrDoingFade = false;
    var tkrAutoNext = true;
    var tkrAutoOut = true;
    var tkrReverseMode = false;
    var currTkrStep = 1;
    var currTkrMsg = 0;
    var tkrCurrMsg = "";

    //============= Fade text from one color to another ===================
    function fadeText() {
      if (!tickerPanel.setInnerHTML) {
        return(false); }

       else {

        if (tkrCurrMsg == "") {
          tkrCurrMsg = tkrMsgList[currTkrMsg];
          tkrReverseMode = true;
          currTkrStep = 0; }
        var continueFade = true;
        var fadeInterval = tkrFadeRate;

        if (tkrReverseMode) {
          // set fade out color
          txtColorR = tkrEndColor[0];
          txtColorG = tkrEndColor[1];
          txtColorB = tkrEndColor[2];

          if (currTkrStep == 0) {
            txtColorR = tkrStartColor[0];
            txtColorG = tkrStartColor[1];
            txtColorB = tkrStartColor[2];
            tkrReverseMode = false;
            
            if (tkrAutoNext) {
              currTkrMsg++;
              if (currTkrMsg >= tkrMsgList.length) {
                currTkrMsg = 0; }
              if (tkrMsgList[currTkrMsg] != null) {
                tkrCurrMsg = tkrMsgList[currTkrMsg]; }}
            tickerPanel.setInnerHTML(tkrCurrMsg);
            tkrDoingFade = tkrAutoNext;
            continueFade = tkrDoingFade; }
           else {
            for (var tkrcnt1 = tkrFadeSteps; tkrcnt1 >= currTkrStep; tkrcnt1--) {
              txtColorR += tkrFadeStep[0];
              txtColorG += tkrFadeStep[1];
              txtColorB += tkrFadeStep[2]; }
            currTkrStep--; }}
         else {
          // set fade in color
          txtColorR = tkrStartColor[0];
          txtColorG = tkrStartColor[1];
          txtColorB = tkrStartColor[2];

          if (currTkrStep == tkrFadeSteps) {
            txtColorR = tkrEndColor[0];
            txtColorG = tkrEndColor[1];
            txtColorB = tkrEndColor[2];
            tkrReverseMode = true;
            fadeInterval = tkrHoldTime;
            continueFade = tkrAutoOut; }
           else {
            for (var tkrcnt2 = 0; tkrcnt2 < currTkrStep; tkrcnt2++) {
              txtColorR -= tkrFadeStep[0];
              txtColorG -= tkrFadeStep[1];
              txtColorB -= tkrFadeStep[2]; }}
            currTkrStep++; }

        tickerPanel.setColor("rgb(" + txtColorR + "," + txtColorG + "," + txtColorB + ")");
        if (continueFade) {
          setTimeout("fadeText()", fadeInterval); }
         else {
          tkrDoingFade = false; }
        return(true); }}
    //=====================================================================

    //============= Initiate the fading ===================================
    function startFade(xbStyleObject) {  // tickerPanel must be an xbStyle
      if (!xbStyleObject.setInnerHTML || tkrDoingFade) {
        return(false); }

       else {
        tickerPanel = xbStyleObject;

        // calculate colour steps;
        tkrFadeStep[0] = parseInt((tkrStartColor[0] - tkrEndColor[0]) / tkrFadeSteps);
        tkrFadeStep[1] = parseInt((tkrStartColor[1] - tkrEndColor[1]) / tkrFadeSteps);
        tkrFadeStep[2] = parseInt((tkrStartColor[2] - tkrEndColor[2]) / tkrFadeSteps);

        tkrDoingFade = true;
        setTimeout("fadeText()", tkrFadeRate);
        return(true); }}
    //=====================================================================

    //============= Fade message in and stop fade function ================
    function fadeIn(xbStyleObject) {
      if (tkrReverseMode) {
        tkrAutoNext = true; }
       else if (tkrDoingFade) {
        tkrReverseMode = true;
        tkrAutoNext = true; }
       else {
        tkrAutoOut = false; }
      startFade(xbStyleObject);}
    //=====================================================================

    //============= Fade message out and stop fade function ===============
    function fadeOut(xbStyleObject) {
      tkrReverseMode = true;
      tkrAutoNext = false;
      startFade(xbStyleObject); }
    //=====================================================================

    //============= End fading (last message is faded out) ================
    function endFade() {
      tkrDoingFade = false; }
    //=====================================================================
  //=========================================================================

  //=============== Define container sizing functions =======================
    // initialise objects
    var divPanel = null;
    var divResizeRate = 80;
    var divHoldTime = 10000;
    var divStartHeight = 0;
    var divCurrHeight = 0;
    var divEndHeight = 320;
    var divStartWidth = 0;
    var divCurrWidth = 0;
    var divEndWidth = 320;
    var divResizeSteps = 25;
    var divResizeID = 0;
    var divDoingResize = false;
    var divResizeStep = 1;

    //============= Initiate expansion of a container element =================
    function startDivResize(xbStyleObject,options) {
      if (!xbStyleObject.setWidth || !xbStyleObject.setHeight || divDoingResize) {
        return(false); }

       else {

        divPanel = xbStyleObject;
        divCurrWidth = divStartWidth;
        divCurrHeight = divStartHeight;

        divDoingResize = true;
        setTimeout("resizeDiv(\"" + options + "\")", divResizeRate);
        return(true); }}
    //=====================================================================

    //============= Fade message in and stop fade function ================
    function resizeDiv(options) {
      if (!divPanel.setWidth || !divPanel.setHeight) {
        return(false); }

       else {
        var stopResize = false;

        if (!options) {
          options = ""; }

        switch (options) {
          case "heightOnly":
            divCurrHeight += divResizeStep;
            if ((divResizeStep > 0 && divCurrHeight >= divEndHeight) ||
                (divResizeStep < 0 && divCurrHeight <= divEndHeight)) {
              divCurrHeight = divEndHeight
              stopResize = true; }
            divPanel.setHeight(divCurrHeight);
            break;
          case "widthOnly":
            divCurrWidth += divResizeStep;
            if ((divResizeStep > 0 && divCurrWidth >= divEndWidth) ||
                (divResizeStep < 0 && divCurrWidth <= divEndWidth)) {
              stopResize = true;
              divCurrWidth = divEndWidth }
            divPanel.setWidth(divCurrWidth);
          default:
            if (divCurrHeight < divEndHeight) {
              divCurrHeight += divResizeStep; }
            if (divCurrWidth < divEndWidth) {
              divCurrWidth += divResizeStep; }
            if (divCurrWidth >= divEndWidth && divCurrHeight >= divEndHeight) {
              divCurrWidth = divEndWidth
              divCurrHeight = divEndHeight
              stopResize = true; }
            divPanel.setHeight(divCurrHeight);
            divPanel.setWidth(divCurrWidth); }
        
        if (!stopResize) {
          setTimeout("resizeDiv(\"" + options + "\")", divResizeRate); }
         else {
          divDoingResize = false; }
        return(true); }}
    //=====================================================================

    //============= Expand height of a container ==========================
    function expandDivHeight(xbStyleObject,startHeight,endHeight,resizeStep) {
      if (!isNaN(startHeight) && startHeight >= 0) {
        divStartHeight = startHeight; }
      if (!isNaN(endHeight) && endHeight >= 0) {
        divEndHeight = endHeight; }
      if (!isNaN(resizeStep) && resizeStep > 0) {
        divResizeStep = resizeStep; }
       else {
        divResizeStep = 1; }
      if (divEndHeight < divStartHeight) {
        startHeight = divStartHeight;
        divStartHeight = divEndHeight;
        divEndHeight = startHeight; }
      startDivResize(xbStyleObject,"heightOnly"); }
    //=====================================================================

    //============= Expand width of a container ==========================
    function expandDivWidth(xbStyleObject,startWidth,endWidth,resizeStep) {
      if (!isNaN(startWidth) && startWidth >= 0) {
        divStartWidth = startWidth; }
      if (!isNaN(endWidth) && endWidth >= 0) {
        divEndWidth = endWidth; }
      if (!isNaN(resizeStep) && resizeStep > 0) {
        divResizeStep = resizeStep; }
       else {
        divResizeStep = 1; }
      if (divEndWidth < divStartWidth) {
        startWidth = divStartWidth;
        divStartWidth = divEndWidth;
        divEndWidth = startWidth; }
      startDivResize(xbStyleObject,"widthOnly"); }
    //=====================================================================

    //============= Expand container's width & height =====================
    function expandDiv(xbStyleObject,startWidth,startHeight,endWidth,endHeight,direction,resizeStep) {
      if (!isNaN(startWidth) && startWidth >= 0) {
        divStartWidth = startWidth; }
      if (!isNaN(startHeight) && startHeight >= 0) {
        divStartHeight = startHeight; }
      if (!isNaN(endWidth) && endWidth >= 0) {
        divEndWidth = endWidth; }
      if (!isNaN(endHeight) && endHeight >= 0) {
        divEndHeight = endHeight; }
      if (!isNaN(resizeStep) && resizeStep > 0) {
        divResizeStep = resizeStep; }
       else {
        divResizeStep = 1; }
      if (divEndHeight < divStartHeight) {
        startHeight = divStartHeight;
        divStartHeight = divEndHeight;
        divEndHeight = startHeight; }
      if (divEndWidth < divStartWidth) {
        startWidth = divStartWidth;
        divStartWidth = divEndWidth;
        divEndWidth = startWidth; }
      startDivResize(xbStyleObject,direction); }
    //=====================================================================

    //============= Shrink height of a container ==========================
    function shrinkDivHeight(xbStyleObject,startHeight,endHeight,resizeStep) {
      if (!isNaN(startHeight) && startHeight >= 0) {
        divStartHeight = startHeight; }
      if (!isNaN(endHeight) && endHeight >= 0) {
        divEndHeight = endHeight; }
      if (!isNaN(resizeStep) && resizeStep < 0) {
        divResizeStep = resizeStep; }
       else {
        divResizeStep = -1; }
      if (divEndHeight > divStartHeight) {
        startHeight = divStartHeight;
        divStartHeight = divEndHeight;
        divEndHeight = startHeight; }
      startDivResize(xbStyleObject,"heightOnly"); }
    //=====================================================================

    //============= Shrink width of a container ==========================
    function shrinkDivWidth(xbStyleObject,startWidth,endWidth,resizeStep) {
      if (!isNaN(startWidth) && startWidth >= 0) {
        divStartWidth = startWidth; }
      if (!isNaN(endWidth) && endWidth >= 0) {
        divEndWidth = endWidth; }
      if (!isNaN(resizeStep) && resizeStep < 0) {
        divResizeStep = resizeStep; }
       else {
        divResizeStep = -1; }
      if (divEndWidth > divStartWidth) {
        startWidth = divStartWidth;
        divStartWidth = divEndWidth;
        divEndWidth = startWidth; }
      startDivResize(xbStyleObject,"widthOnly"); }
    //=====================================================================
  //=========================================================================

  //=============== Popup windows ===========================================
    // initialise variables
    var popWin = null;    // use this when referring to pop-up window
    var winCount = 0;
    var winName = "popWin";

    function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop) {
      var d_winLeft = 20;  // default, pixels from screen left to window left
      var d_winTop = 20;   // default, pixels from screen top to window top
      winName = "popWin" + (winCount++); //unique name for each pop-up window
      closePopWin();           // close any previously opened pop-up window
      if (openPopWin.arguments.length >= 4) { // any additional features?
        winFeatures = "," + winFeatures; }
      else {
        winFeatures = ""; }
      if (openPopWin.arguments.length == 6) { // location specified
        winFeatures += getLocation(winWidth, winHeight, winLeft, winTop); }
      else {
        winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop); }
      popWin = window.open(winURL, winName, "width=" + winWidth
               + ",height=" + winHeight + winFeatures); }

    function closePopWin() {    // close pop-up window if it is open
      if (navigator.appName != "Microsoft Internet Explorer"
          || parseInt(navigator.appVersion) >=4 ) { //do not close if early IE
        if (popWin != null) {
          if (!popWin.closed) {
            popWin.close(); }}}}

    function popmsg(hdr,heading,msg){
      var htmlCode =
        '<HTML><HEAD><TITLE>'
      + hdr
      + '</TITLE></HEAD>'
      + '<BODY BGCOLOR="white"><CENTER>'
      + '<TABLE CELLPADDING=0 HEIGHT=65>'
      + '<TR><TD><B><H3><FONT FACE="Verdana">'
      + heading
      + '</FONT></H3></B></TD></TR>'
      + '<TR><TD  VALIGN="middle">'
      + '<FONT SIZE=2 COLOR="Blue" FACE="Verdana">'
      + msg
      + '</FONT>'
      + '</TD></TR>'
      + '</TABLE>'
      + '<FORM><INPUT TYPE="button" '
      + 'VALUE="&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;" '
      + 'onClick="self.close()">'
      + '</CENTER></BODY></HTML>'

      openPopWin("", 450, 250, "",  "cen", "cen");
      popWin.document.write(htmlCode);
      popWin.document.close(); }

    function getLocation(winWidth, winHeight, winLeft, winTop) {
      var winLocation = "";
      if (winLeft < 0) {
        winLeft = screen.width - winWidth + winLeft; }
      if (winTop < 0) {
        winTop = screen.height - winHeight + winTop; }
      if (winTop == "cen") {
        winTop = (screen.height - winHeight)/2 - 20; }
      if (winLeft == "cen") {
        winLeft = (screen.width - winWidth)/2; }
      if (winLeft>0 & winTop>0) {
        winLocation =  ",screenX=" + winLeft + ",left=" + winLeft
                    + ",screenY=" + winTop + ",top=" + winTop; }
      else {
        winLocation = ""; }
      return(winLocation); }
  //=========================================================================
//=============================================================================

//=============== Define status and info display functions ====================
  //=============== Set the status hint =====================================
  function setStatusMain(detailedInfo,overrideFreeze) {
    if (overrideFreeze || !statusPanelFrozen) {
      if (!detailedInfo) {
        detailedInfo = ""; }
      if (window.statusPanel && window.statusPanel.setInnerHTML) {
        statusPanel.setInnerHTML(detailedInfo); }
      if (window.statusPanel1 && window.statusPanel1.setInnerHTML) {
        statusPanel1.setInnerHTML(detailedInfo); }
      if (window.statusPanel2 && window.statusPanel2.setInnerHTML) {
        statusPanel2.setInnerHTML(detailedInfo); }
      return(true); }
     else {
      return(false); }}
  //=========================================================================

  //=============== Set the status hint =====================================
  function setStatus(infoTitle,statusInfo,detailedInfo,overrideFreeze) {
    if (!statusInfo) {
      statusInfo = ""; }
    if (!detailedInfo || detailedInfo == "") {
      detailedInfo = statusInfo; }
    window.status = stripTags(statusInfo);
    if (infoTitle && infoTitle != "") {
      detailedInfo = "<h1 class=\"panel\">" + infoTitle + "<\/h1>" + detailedInfo; }
    return(setStatusMain(detailedInfo,overrideFreeze) && true); }
  //=========================================================================

  //=============== Clear the status hint ===================================
  function clearStatus(overrideFreeze) {
    return(setStatus(defaultInfoTitle,defaultStatusText,defaultDetailedText,overrideFreeze)); }
  //=========================================================================

  //=============== Pseudo function to set the status hint ==================
  function showInfo(infoTitle,statusInfo,detailedInfo,overrideFreeze) {
    return(setStatus(infoTitle,statusInfo,detailedInfo,overrideFreeze) && true); }
  //=========================================================================

  //=============== Pseudo function to clear the status hint ================
  function clearInfo(overrideFreeze) {
    return(clearStatus(overrideFreeze)); }
  //=========================================================================

  //=============== Set the default status hint =============================
  function setDefaultStatus(defaultText) {
    defaultStatusText = defaultText;
    window.defaultStatus = stripTags(defaultText); }
  //=========================================================================

  //=============== Set the default detailed text ===========================
  function setDefaultDetails(defaultText) {
    defaultDetailedText = defaultText; }
  //=========================================================================

  //=============== Freeze the status panels ================================
  function freezeStatusPanel() {
    statusPanelFrozen = true; }
  //=========================================================================

  //=============== Thaw the status panels ==================================
  function thawStatusPanel() {
    statusPanelFrozen = false; }
  //=========================================================================
//=============================================================================

//=============== Define imported functions/classes ===========================
  //=============== Define Zooming Link functions ===========================
  /* Zooming link script by Paul Anderson, copyright 2001 CNET Builder.com.
     May be freely used with attribution. Not for resale. All rights reserved.
     
     updated: 06 Mar 2006 by Shad-O
     update: Now uses xbStyle functions for greater browser compatibility */

  // Initialise variables
  var maxW,maxH,fromX,fromY,toX,toY,adjX,adjY,zBox,zStep=0,zLink,zNew;

  function initialiseZoom() {
    if (!zBox) {
      if (document.layers) {
        document.write("<layer id=\"zBoxDiv\" position=\"absolute\"></layer>"); }
       else {
        document.write("<div id=\"zBoxDiv\" style=\"position:absolute\"></div>"); }
      zBox = new xbStyle(xbGetElementById("zBoxDiv")); }}

  function zoomBox(evt,zlink,maxw,maxh,tox,toy) {
    if (!evt || !evt.type) {
      return(false); }
    if (arguments.length > 2) {
      zNew=1; }
    scrollH = (window.pageYOffset!=null) ? window.pageYOffset:document.body.scrollTop;
    maxW = maxw ? maxw:window.innerWidth ? innerWidth:document.body.clientWidth;
    maxH = maxh ? maxh:window.innerHeight ? innerHeight:document.body.clientHeight;

    toX = tox ? tox:0;
    toY = (toy ? toy:0) + scrollH;
    fromX = evt.pageX ? evt.pageX:evt.clientX;
    fromY = (evt.pageY ? evt.pageY:evt.clientY) +( document.all ? scrollH:0);
    adjX = toX + evt.screenX - fromX;
    adjY = toY + evt.screenY - fromY;
    zLink=zlink;
    doZoom();
    return(true); }

  function doZoom() {
    zStep += 1;
    zPct = (10-zStep)/10;
    zBox.moveTo(toX+zPct*(fromX-toX),toY+zPct*(fromY-toY));
    zBox.setBorder("2px solid #999999");
    zBox.setWidth(maxW*(1-zPct));
    zBox.setHeight(maxH*(1-zPct));
    zBox.setVisibility("visible");
    if (zStep < 10) {
      setTimeout("doZoom("+fromX+","+fromY+","+toX+","+toY+")",30); }
     else {
      zBox.moveTo(0,0);
      zBox.setWidth(1);
      zBox.setHeight(1);
      zBox.setVisibility("hidden");
      zStep=0;
      if (zLink && !zNew) {
        location.href=zLink.href; }
       else {
        if (zLink && zNew) {
          var w = window.open(zLink.href,'','width='+maxW+',height='+maxH+',left='+adjX+',top='+adjY+',scrollbars,resizable');
          zNew=null; }}}}
  //=========================================================================
//=============================================================================
