//////////////////////////////////////////////////////////////////
////////  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 ////////
//////////////////////////////////////////////////////////////////
//// FLCore.js - common JavaScript objects used by other FL*.js //
//// functionality is xtended by other FL*.js modules ////////////
//// Last modified 16 March 2008 ce //////////////////////////////
//////////////////////////////////////////////////////////////////

//============== Initialise Some Common Objects ===============================
  // some constants
  var on = true;
  var enabled = true;
  var yes = true;
  var off = false;
  var disabled = false;
  var no = false;

  var optionsSeperator = ";";      // seperator must be an escapable non-alphanumeric
                                   // character. Use of \ as a seperator has not been tested
  var itemsSeperator = ",";        // seperator must be an escapable non-alphanumeric
                                   // character. Use of \ as a seperator has not been tested

  var defaultDateSeperator = "-";  // default seperators for date/time values
  var defaultTimeSeperator = ":";

  var xhtpRequestObj = false;         // XML Http object

  //============ Assign custom methods to appropriate objects ===============
    Array.prototype.getIndex = Array_getIndex;
    Array.prototype.replace = Array_replace;
    Array.prototype.shuffle = Array_shuffle;
    Array.prototype.sortAlpha = Array_sortAlpha;
    Array.prototype.trimNulls = Array_trimNulls;

    Boolean.prototype.toAnswer = Boolean_toAnswer;
    Boolean.prototype.transform = String_transform;

    Number.prototype.trim = String_trim;

    String.prototype.transform = String_transform;
    String.prototype.trim = String_trim;
  //=========================================================================

  //============ Store cgi name/values in array object ======================
    var queryStrings = new Array();
    var searchString = unescape(window.location.search.substring(1));
    var namevaluePairs = searchString.split("&");
    var namevalueSplit;
    for (var cnt = 0; cnt < namevaluePairs.length; cnt++) {
      namevalueSplit = namevaluePairs[cnt].split("=");
      queryStrings[cnt] = {name:deNullify(namevalueSplit[0]), value:deNullify(namevalueSplit[1])}; }
  //=========================================================================
//=============================================================================


//============== Define prototyped functions ==================================
  //=============== Find index of array item ================================
    function Array_getIndex(itemValue,options) {
      var thisArray = this;
      var caseSensitive = doesKeyExist(options,"matchcase");
      var currValue;
      var itemIndex = -1;
      if (!caseSensitive && isNaN(itemValue)) {
        itemValue = itemValue.toLowerCase(); }
      for (var cnt1 = 0; cnt1 < thisArray.length; cnt1++) {
        currValue = thisArray[cnt1];
        if (!caseSensitive && isNaN(currValue)) {
          currValue = currValue.toLowerCase(); }
        if (currValue == itemValue) {
          itemIndex = cnt1;
          break; }}

      return(itemIndex); }
  //=========================================================================

  //=============== Replace all instances of one item with a new value ======
    function Array_replace(oldItemValue,newItemValue,options) {
      var thisArray = this;
      var caseSensitive = doesKeyExist(options,"matchcase");
      var currValue;
      for (var cnt1 = 0; cnt1 < thisArray.length; cnt1++) {
        currValue = thisArray[cnt1];
        if (!caseSensitive && isNaN(currValue)) {
          currValue = currValue.toLowerCase(); }
        if (currValue == oldItemValue) {
          thisArray[cnt1] = newItemValue; }}

      return(thisArray); }
  //=========================================================================

  //=============== Shuffle the array items =================================
    function Array_shuffle(shuffleRate) {
      var thisArray = this;
      var arrayLength = thisArray.length;
      if (arrayLength > 1) {
        var randomIndex1 = 0, randomIndex2 = 0;
        var tempVar;
        if (isNaN(shuffleRate) || shuffleRate < 1) {
          shuffleRate = 1; }
        if (shuffleRate > 20) {
          shuffleRate = 20; }
        for (var cnt2 = 0; cnt2 < shuffleRate; cnt2++) {
          for (var cnt1 = 0; cnt1 < arrayLength; cnt1++) {
            randomIndex1 = parseInt(Math.random()*arrayLength);
            do {
              randomIndex2 = parseInt(Math.random()*arrayLength); }
            while (randomIndex1 == randomIndex2)
            tempVar = thisArray[randomIndex1];
            thisArray[randomIndex1] = thisArray[randomIndex2];
            thisArray[randomIndex2] = tempVar; }}}

      return(thisArray); }
  //=========================================================================

  //=============== Sorts the array alphanumerically ========================
    function Array_sortAlpha_compareNumbers(a, b) {
      return a - b; }

    function Array_sortAlpha(reverseOrder) {
      var thisArray = this;
      thisArray = thisArray.sort(Array_sortAlpha_compareNumbers);

      return(thisArray); }
  //=========================================================================

  //=============== Removes all null elements ===============================
    function Array_trimNulls() {
      var thisArray = this;
      for (var cnt1 = thisArray.length; cnt1 >= 0; cnt1--) {
        if (thisArray[cnt1] == null) {
          thisArray.splice(cnt1,1); }}

      return(thisArray); }
  //=========================================================================

  //=============== Convert boolean to friendly text ========================
    function Boolean_toAnswer(options) {
      var thisBool = this;
      var answerType = getValueForKey(options,"type");
      var caseSetting = getValueForKey(options,"case");
      var thisAnswer = "";

      switch (answerType) {
        case "yesno":
          thisAnswer = (thisBool == true) ? "yes" : "no";
          break;
        case "onoff":
          thisAnswer = (thisBool == true) ? "on" : "off";
          break;
        case "endisabled":
          thisAnswer = (thisBool == true) ? "enabled" : "disabled";
          break;
        case "actdeact":
          thisAnswer = (thisBool == true) ? "activated" : "deactivated";
          break;
        default:
          thisAnswer = (thisBool == true) ? "true" : "false"; }
          
      if (caseSetting != "") {
        thisAnswer = thisAnswer.transform(caseSetting); }

      return(thisAnswer); }
  //=========================================================================

  //============ Perform transformations on string object ===================
    function String_transform(options) {
      var stringValue = String(this);
      if (!options || options == "" || options == " ") {
        return(stringValue); }
      options = String(options);

      if (doesKeyExist(options,"default") && stringValue == "") {
        stringValue = getValueForKey(options,"default"); }

      if (doesKeyExist(options,/esq/i)) {
        stringValue = stringValue.replace(/'/g,"\'\'"); }
      if (doesKeyExist(options,/edq/i)) {
        stringValue = stringValue.replace(/"/g,"\"\""); }
      if (doesKeyExist(options,/xsq/i)) {
        stringValue = stringValue.replace(/'/g,"\\\'"); }
      if (doesKeyExist(options,/xdq/i)) {
        stringValue = stringValue.replace(/"/g,"\\\""); }
      if (doesKeyExist(options,/xddq/i)) {
        stringValue = stringValue.replace(/"/g,"\\\\\""); }
      if (doesKeyExist(options,/xnb/i)) {
        stringValue = stringValue.replace(/\r\n/g,"\\n");
        stringValue = stringValue.replace(/\n/g,"\\n"); }
      if (doesKeyExist(options,/filter/i) && stringValue.filter) {
        filterVar = getValueForKey("filter");
        stringValue = stringValue.filter(filterVar); }
      if (doesKeyExist(options,/trim/i)) {
        trimVar = getValueForKey("trim");
        stringValue = stringValue.trim(trimVar); }
      if (doesKeyExist(options,"remove")) {
        remChar = getValueForKey(options,"remove");
        switch (remChar) {
          case "lnBrk":
            remVar = /\r|\n/g;
            break;
          default:
            remVar = new RegExp(remChar,"g"); }
        stringValue = stringValue.replace(remVar,""); }
      if (doesKeyExist(options,/lc|lowercase/i)) {
        stringValue = stringValue.toLowerCase(); }
      if (doesKeyExist(options,/uc|uppercase/i)) {
        stringValue = stringValue.toUpperCase(); }
      if (doesKeyExist(options,/ic|invert case/i) && stringValue.toInvertedCase) {
        stringValue = stringValue.toInvertedCase(); }
      if (doesKeyExist(options,/tc|cc|capitalise|caps|title/i) && stringValue.toTitleCase) {
        stringValue = stringValue.toTitleCase(); }
      if (doesKeyExist(options,/sc|sentence/i) && stringValue.toSentenceCase) {
        stringValue = stringValue.toSentenceCase(); }
      if (doesKeyExist(options,"xCharOnly") && stringValue.toHTML) {
        stringValue = charToHTML(stringValue,"xCharOnly"); }
      if (doesKeyExist(options,"esc")) {
        escChar = getValueForKey(options,"esc");
        if (escChar == "") {
          stringValue = escape(stringValue); }
         else {
          escRE = new RegExp(escChar,"g");
          stringValue = stringValue.replace(escRE,escChar+escChar); }}
      if (doesKeyExist(options,"unesc")) {
        unescChar = getValueForKey(options,"unesc");
        if (unescChar == "") {
          stringValue = unescape(stringValue); }
         else {
          unescRE = new RegExp(unescChar+unescChar,"g");
          stringValue = stringValue.replace(unescRE,unescChar); }}
      if (doesKeyExist(options,"find") && doesKeyExist(options,"replace")) {
        findValue = new RegExp(getValueForKey(options,"find"),"gi");
        repValue = getValueForKey(options,"replace");
        stringValue = stringValue.replace(findValue, repValue); }
      if (doesKeyExist(options,"normaliseList") && stringValue != "") {
        var listType = getValueForKey(options,"listType","string");
        var quoteChr = "";
        if (listType == "string") {
          quoteChr = "'"; }
        if (stringValue.substr(0,1) == "[") {
          stringValue = stringValue.substr(1); }
        if (stringValue.substr(stringValue.length-1,1) == "]") {
          stringValue = stringValue.substr(0,stringValue.length-1); }
        stringValue = quoteChr + stringValue.replace(/\]\[/g,quoteChr + "," + quoteChr) + quoteChr; }
      if (doesKeyExist(options,"split")) {
        splitChar = getValueForKey(options,"split");
        stringValue = stringValue.split(splitChar); }
      if (doesKeyExist(options,"bool")) {
        if (stringValue.search(/^(1|enabled|on|true|yes)$/i) > -1) {
          stringValue = true; }
         else {
          stringValue = false; }}
      if (doesKeyExist(options,"formatAsNumber") && stringValue.formatAsNumber) {
        formatOptions = getValueForKey(options,"formatAsNumber");
        stringValue = stringValue.formatAsNumber(formatOptions); }
      if (doesKeyExist(options,"formatAsDate") && stringValue.formatAsDate) {
        formatOptions = getValueForKey(options,"formatAsDate");
        stringValue = stringValue.formatAsDate(formatOptions); }
      if (doesKeyExist(options,"num")) {
        if (stringValue.toNumber) {
          stringValue = stringValue.toNumber(); }
         else {
          stringValue = parseInt(stringValue); }}
      if (doesKeyExist(options,"date") || doesKeyExist(options,"datetime") || doesKeyExist(options,"time")) {
        stringValue = new Date(stringValue); }

      return(stringValue); }
  //=========================================================================

  //============ Trim characters around strings =============================
    function String_trim(charsToTrim) {
      var stringToTrim = this.toString();
      var trimmedString = "";
      if (!charsToTrim || charsToTrim == "") {
        charsToTrim = " "; }

      if (charsToTrim.exec) {
        // if charsToTrim is a RegExp object, trim() removes all characters NOT equal to charsToTrim from either side of stringToTrim
        var reversedStringToTrim = reverseString(stringToTrim);
        var realStart = 0;
        var realEnd = stringToTrim.length;

        if (realEnd > 0) {
          realStart = stringToTrim.search(charsToTrim);
          realEnd = stringToTrim.length-reversedStringToTrim.search(charsToTrim);
          trimmedString = stringToTrim.substring(realStart, realEnd); }}

       else {

        var cttLength = charsToTrim.length;
        while (stringToTrim.substr(0,cttLength) == charsToTrim) {
          stringToTrim = stringToTrim.substr(cttLength); }
        while (stringToTrim.substr(stringToTrim.length-cttLength) == charsToTrim) {
          stringToTrim = stringToTrim.substr(0,stringToTrim.length-cttLength); }
        trimmedString = stringToTrim; }

      return(trimmedString.toString()); }
  //=========================================================================
//=============================================================================


//============== Define common functions/classes ==============================
  //============ Define CGI name/value related functions ====================
    //============ Retrieve index for cgi name ============================
      function getIndexForCGI(cgiName) {
        cgiName = deNullify(cgiName,"lc");
        var cgiIndex = -1;

        for (var cnt = 0; cnt < queryStrings.length; cnt++) {
          if (queryStrings[cnt].name == cgiName) {
            cgiIndex = cnt;
            break; }}

        return(cgiIndex); }
    //=====================================================================

    //============ Retrieve values from query posts =======================
      function retrieveCGI(cgiName,options) {
        if (!cgiName || cgiName == "") {
          return(false); }
        if (!options) {
          options = " "; }
        var cgiValue = "";

        cgiName = cgiName.split("|");
        for (var cnt = 0; cnt < queryStrings.length; cnt++) {
          for (var cnt2 = cgiName.length-1; cnt2 >= 0; cnt2--) {
            if (queryStrings[cnt].name == cgiName[cnt2]) {
              cgiValue += queryStrings[cnt].value;
              break; }}}

        cgiValue = deNullify(cgiValue, options);

        return(cgiValue); }
    //=====================================================================
  //=========================================================================

  //============ Generic multiple alternate object handler ==================
  function Try() {
    var returnObject = false;
    for (var cntArgs=0; cntArgs < arguments.length; cntArgs++) {
      try {
        returnObject = eval(arguments[cntArgs]);
        break; }
      catch(e) {}}
    return(returnObject); }
  //=========================================================================

  //============ Define XML POST functions ==================================
    //============ Submit form information via POST =======================
      function xhtpRequest(url, cgiString, responseFunction) {
        xhtpRequestObj = false;
        if (!responseFunction || typeof(responseFunction) != "function") {
          responseFunction = xhtpResponse; }
        xhtpRequestObj = Try("new XMLHttpRequest()","new ActiveXObject(\"Msxml2.XMLHTTP\")","new ActiveXObject(\"Microsoft.XMLHTTP\")");
        if (!xhtpRequestObj) {
          window.alert("Cannot create XMLHTTP instance");
          return(false); }

        cgiString = cgiString.trim("&");
        xhtpRequestObj.onreadystatechange = responseFunction;
        xhtpRequestObj.open("POST", url, true);
        xhtpRequestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhtpRequestObj.setRequestHeader("Content-length", cgiString.length);
        xhtpRequestObj.setRequestHeader("Connection", "close");
        xhtpRequestObj.send(cgiString); }
    //=====================================================================

    //============ Retrieve data processed from previous POST request =====
      function xhtpResponse() {
        var responseString = "";
        if (xhtpRequestObj.readyState == 4 && xhtpRequestObj.status == 200) {
          responseString = xhtpRequestObj.responseText;
          xhtpRequestObj.close(); }
        return(responseString); }
    //=====================================================================
  //=========================================================================

  //============ Define key/value related functions =========================
    //============ Check if key/s exists in an options string =============
      function doesKeyExist(namevaluesString,keyNames,optSep) {
        if (!namevaluesString || !keyNames) {
          return(false); }
        namevaluesString = String(namevaluesString);
        var sepChr = optionsSeperator;
        if (optSep && optSep != "") {
          sepChr = optSep; }
        var keyPos = -1;
        var keyFound = false;
        if (keyNames.exec) {
          keyNames = keyNames.source;
          keyNames = keyNames.replace(/\^/g,"");
          keyNames = keyNames.replace(/\|/g,sepChr); }
        keyNames = keyNames.split(sepChr);
        var keyList = "";
        for (var cntKeyList = 0; cntKeyList < keyNames.length; cntKeyList++) {
          keyList += "|^" + keyNames[cntKeyList] + sepChr + "|" + sepChr+keyNames[cntKeyList] + sepChr +
            "|^" + keyNames[cntKeyList] + "=|" + sepChr+keyNames[cntKeyList] + "=" +
            "|^" + keyNames[cntKeyList] + "$|" + sepChr+keyNames[cntKeyList] + "$"; }
        var searchString = new RegExp(keyList.substr(1));
        keyPos = namevaluesString.search(searchString);

        if (keyPos > -1) {
          keyFound = true; }

        return(keyFound); }
    //=====================================================================

    //============ Retrieve key and value from options string =============
      function getValueForKey(namevaluesString,keyName,defaultValue,options,optSep) {
        if (!namevaluesString) {
          namevaluesString = ""; }
        if (!keyName) {
          keyName = ""; }
        namevaluesString = String(namevaluesString);
        keyName = String(keyName);

        if (!options) {
          options = " "; }
        var sepChr = optionsSeperator;
        if (optSep && optSep != "") {
          sepChr = optSep; }

        if (!defaultValue) {
          defaultValue = ""; }
         else {
          defaultValue = String(defaultValue); }
        var valueForKey = "undefined";

        if (sepChr == escape(sepChr)) {
          return(false); /* invalid seperator in use */ }

        if (sepChr == "\\") {
          sepChr = "\\\\"; }
        var escapedSeperator = new RegExp(sepChr + "{2}|\\\\" + sepChr,"g");
        var newString = namevaluesString.replace(escapedSeperator,escape(sepChr));

        var keyPos = namevaluesString.indexOf(sepChr + keyName + "=");
        if (keyPos == -1) {
          keyPos = namevaluesString.indexOf(keyName+"=");
          if (keyPos > 0) {
            keyPos = -1; }}
         else {
          keyPos += sepChr.length; }

        if (keyPos > -1) {
          var valuePos = keyPos + keyName.length + 1;
          newString = namevaluesString.substring(valuePos);
          if (sepChr == "\\\\") {
            sepChr = "\\"; }
          var valuePosEnd = newString.indexOf(sepChr);
          if (valuePosEnd == -1)
            valuePosEnd = newString.length;
          valueForKey = unescape(newString.substring(0,valuePosEnd)); }

        if (valueForKey == "undefined" || valueForKey == "null" || valueForKey == "")
          valueForKey = defaultValue;

        if (options.trim() != "") {
          valueForKey = valueForKey.transform(options); }

        return(valueForKey); }
    //=====================================================================

    //============ Remove a key and its value from an options string ======
      function removeKey(namevaluesString,keyName,optSep) {
        if (!namevaluesString) {
          return(""); }
        if (!keyName) {
          return(namevaluesString); }
        namevaluesString = String(namevaluesString);
        keyName = String(keyName);
        var returnString = namevaluesString;
        var keyPos = namevaluesString.indexOf(keyName+"=");
        var sepChr = optionsSeperator;
        if (optSep && optSep != "") {
          sepChr = optSep; }

        if (keyPos > -1) {
          var valuePos = keyPos + keyName.length + 1;
          var frontString = "";
          if (keyPos > 0) {
            namevaluesString.substring(0,keyPos-1); }
          var backString = "";
          var newString = namevaluesString.substring(valuePos);
          if (sepChr == "\\") {
            sepChr = "\\\\"; }
          var escapedSeperator = new RegExp(sepChr + "{2}|\\\\" + sepChr,"g");
          newString = newString.replace(escapedSeperator,escape(sepChr));
          if (sepChr == "\\\\") {
            sepChr = "\\"; }
          valuePosEnd = newString.indexOf(sepChr);
          if (valuePosEnd == -1) {
            valuePosEnd = newString.length; }
           else {
            backString = unescape(newString.substring(valuePosEnd+1)); }
          returnString = frontString + backString; }

        return(returnString); }
    //=====================================================================

    //============ Replace key value or remove key from options string ====
      function updateKeyValue(namevaluesString,keyName,newValue,optSep) {
        namevaluesString = String(namevaluesString);
        keyName = String(keyName);
        keyName += "=";
        var returnString = "";
        var keyPos = namevaluesString.indexOf(keyName);
        var sepChr = optionsSeperator;
        if (optSep && optSep != "") {
          sepChr = optSep; }

        var stringSection1 = namevaluesString;
        var stringSection2 = "";
        if (!newValue) {
          keyName = ""; }
         else {
          newValue = String(newValue); }
        if (sepChr == escape(sepChr)) {
          return(false); /* invalid seperator in use */ }

        if (keyPos > -1) {
          var valuePos = keyPos + keyName.length;
          stringSection1 = namevaluesString.substring(0,keyPos);
          stringSection2 = namevaluesString.substring(valuePos);
          if (sepChr == "\\") {
            sepChr = "\\\\"; }
          var escapedSeperator = new RegExp(sepChr + "{2}|\\\\" + sepChr,"g");
          stringSection2 = stringSection2.replace(escapedSeperator,escape(sepChr));
          if (sepChr == "\\\\") {
            sepChr = "\\"; }
          valuePosEnd = stringSection2.indexOf(sepChr);
          if (valuePosEnd == -1) {
            stringSection2 = ""; }
           else {
            stringSection2 = stringSection2.substring(valuePosEnd); }
          if (keyName != "") {
            keyName += newValue}}
         else {
          stringSection2 = sepChr + keyName + newValue;
          keyName = ""; }

        returnString = stringSection1 + keyName + stringSection2;

        return(returnString); }
    //=====================================================================
  //=========================================================================

  //============ Define item set related functions ==========================
    //============ define item class ======================================
      function itemSet() {
        this.set = "";
        this.add = addItemToSet;
        this.itemPos = getPosForItem;
        this.remove = removeItemFromSet; }
    //=====================================================================

    //============ check set for item =====================================
      function isItemInSet(itemSet,itemValue,options) {
        if (itemSet.set) {
          return(inList(itemValue,itemSet.set,options)); }
         else {
          return(false); }}
    //=====================================================================

    //============ add item to set ========================================
      function addItemToSet(itemValue,options) {
        var setString = this.set;
        if (itemValue && itemValue != "") {
          setString += itemsSeperator + itemValue; }
        setString = setString.trim(itemsSeperator);
        this.set = setString; }
    //=====================================================================

    //============ find position of an item in a set ======================
      function getPosForItem(itemValue,options) {
        var setString = this.set;
        setString = setString.split(itemsSeperator);
        return(setString.getIndex(itemValue,options)); }
    //=====================================================================

    //============ remove item from set ===================================
      function removeItemFromSet(itemValue,options) {
        var setString = this.set;
        if (!options) {
          options = ""; }
        var caseSensitive = doesKeyExist(options,"matchcase");
        setString = itemsSeperator + setString + itemsSeperator;
        var tempSet = setString;
        if (caseSensitive) {
          itemValue = itemValue.toLowerCase();
          tempSet = setString.toLowerCase(); }
        var itemPos = tempSet.indexOf(itemsSeperator + itemValue + itemsSeperator);
        if (itemPos > -1) {
          var itemLength = itemsSeperator.length + itemValue.length + itemsSeperator.length;
          var itemSet1 = "", itemSet2 = "";
          if (itemPos > 0) {
            itemSet1 = setString.substr(0,itemPos); }
          if ((itemPos + itemLength) < setString.length) {
            itemSet2 = setString.substr(itemPos+itemLength-1); }
          setString = itemSet1 + itemSet2;
          setString = setString.trim(itemsSeperator); }
        this.set = setString; }
    //=====================================================================
  //=========================================================================

  //============ Convert null/undefined string to empty string ==============
    function deNullify(stringToCheck,options) {
      if (!stringToCheck) {
        stringToCheck = ""; }
      stringToCheck = stringToCheck.toString();
      if (!options) {
        options = " "; }
      var defaultText = getValueForKey(options,"default");
      var noEscape = doesKeyExist(options,"noEsc");

      if (!noEscape) {
        stringToCheck = unescape(stringToCheck); }
      stringToCheck = stringToCheck.trim();
      if (stringToCheck == "null" || stringToCheck == "undefined" || stringToCheck == "") {
        stringToCheck = defaultText; }

      stringToCheck = stringToCheck.transform(options);

      return(stringToCheck); }
  //=========================================================================

  //============ Return specific portions of a uri ============================
    function getDomain(uriString,uriPart) {
      var sepPos = -1;
      if (!uriString) {
        uriString = ""; }
      if (!uriPart) {
        uriPart = ""; }
      switch (uriPart) {
        case "hrefonly":
          sepPos = uriString.indexOf("#");
          if (sepPos > -1) {
            uriString = uriString.substr(0,sepPos); }
          sepPos = uriString.indexOf("?");
          if (sepPos > -1) {
            uriString = uriString.substr(0,sepPos); }
          break;
        default:
          sepPos = uriString.indexOf("://"); // locate protocol's index
          if (sepPos > -1) {
            uriString = uriString.substr(sepPos+3); }
          uriString = uriString.trim("/"); }
      return(uriString); }
  //=========================================================================

  //============ Check if a variable is equal to one of a list of items =====
    function inList(itemToCheck,checkList,options) {
      var checkList = checkList.split(itemsSeperator);
      if (checkList.getIndex(itemToCheck,options) > -1) {
        return(true); }
       else {
        return(false); }}
  //=========================================================================

  //============ Check if a location is a valid web image file ==============
    function isImagefile(locationString) {
      var returnValue;
      locationString = String(locationString);
      if (!locationString || locationString == "") {
        returnValue = false; }
       else {
        var extPos = locationString.lastIndexOf(".");
        var extString = locationString.substr(extPos+1);
        extString = extString.trim(/\w/);
        var validExtensions = new Array('gif','ico','jpe','jpeg','jpg','png');
        if (validExtensions.getIndex(extString) > -1) {
          returnValue = true; }
         else {
          returnValue = false; }}
      return(returnValue); }
  //=========================================================================

  //============ Check if a location is a valid webfile =====================
    function isWebfile(locationString) {
      var returnValue;
      if (!locationString || locationString == "") {
        returnValue = false; }
       else {
        var extPos = locationString.lastIndexOf(".");
        var extString = locationString.substr(extPos+1);
        extString = extString.trim(/\w/);
        var validExtensions = new Array('asa','asax','asp','aspx','cfm','css','hta','htm','html','htt','inc','js','php','php3','php4','phtml','shtml','vbs','xml');
        if (validExtensions.getIndex(extString) > -1) {
          returnValue = true; }
         else {
          returnValue = false; }}
      return(returnValue); }
  //=========================================================================

  //============ Stall processing for number of milliseconds ================
    function stallScript(delay) {
      if (!delay || isNaN(delay)) {
        delay = 100; }
      window.setTimeout("return(true)",delay); }
  //=========================================================================

  //============ Reverse string text ========================================
    function reverseString(textToReverse) {
      textToReverse = String(textToReverse);
      if (textToReverse.reversed) {
        textToReverse = textToReverse.reversed(); }
      return(textToReverse); }
  //=========================================================================

  //============ Convert number or text to boolean equivalent ===============
    function toBoolean(nonBoolObject) {
      var thisBool = false;
      if (nonBoolObject) {
        if (isNaN(nonBoolObject)) {
          nonBoolObject = String(nonBoolObject);
          nonBoolObject = nonBoolObject.toLowerCase();
          var trueText = new Array("yes","on","enabled","activated","true");
          for (var cntB = 0; cntB < trueText.length; cntB++) {
            if (nonBoolObject == trueText[cntB]) {
              thisBool = true; }}}
         else {
          if (nonBoolObject > 0) {
            thisBool = true; }}}

      return(thisBool); }
  //=========================================================================

  //============ Add leading zeros to a number ==============================
  // rudimentary function that does not require FLNum to be loaded
    function zeroFormat(numValue,options) {
      var numericString = numValue.toString();
      if (!options) {
        options = ""; }
      var leadingZeros = getValueForKey(options,"lead",2,"num");
      var trailingZeros = getValueForKey(options,"trail",0,"num");
      if (numValue.formatAsNumber) {
        numValue = numValue.formatAsNumber(options); }
       else {
        numValue = String(numValue);
        var integerPart = numValue;
        var decimalPart = "";
        var decimalPos = numericString.lastIndexOf(".");
        var zeroString = "0000000000";
        if (decimalPos > -1) {
          integerPart = numericString.substr(0,decimalPos);
          decimalPart = numericString.substr(decimalPos+1); }
        if (leadingZeros > 0 && integerPart.length < leadingZeros) {
          integerPart = zeroString.substr(0,leadingZeros-integerPart.length) + integerPart; }
        numValue = integerPart;
        if (decimalPart != "" && trailingZeros > 0) {
          numValue += "." + decimalPart; }}

      return(numValue); }
  //=========================================================================
//=============================================================================


//============== Define imported functions/classes ============================
  //============ Encode/Decode strings ======================================
  // original script written by Mike McGrath <mike_mcgrath@lineone.net>
  //    Web Site:  http://website.lineone.net/~mike_mcgrath/
  function encodeToNum(strValue) {
    var num_out = "";
    if (!strValue || strValue == "") {
      return(false); }
    str_in = escape(strValue);
    for(i = 0; i < str_in.length; i++) {
      num_out += str_in.charCodeAt(i) - 23; }
    return(num_out); }

  function decodeFromNum(numValue) {
    var str_out = "";
    if (!numValue || isNaN(numValue)) {
      return(false); }
    num_out = numValue;
    for(i = 0; i < num_out.length; i += 2) {
      num_in = parseInt(num_out.substr(i,[2])) + 23;
      num_in = unescape('%' + num_in.toString(16));
      str_out += num_in; }
    return(unescape(str_out)); }
  //=========================================================================
//=============================================================================
