/* Website Template Control
 * Copyright (C) 2005 by Henrique Abdalla <teike@users.sourceforge.net>
 *
 * Website Template Control is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * Website Template Control is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Website Template Control; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/* Homepage: http://webtemco.sourceforge.net/
 * At project homepage https://sourceforge.net/projects/webtemco/
 *  you can report bugs and send comments :)
 *
 * Read WebTemCo.txt and html template files for instructions
 */


/*
 * Variables created inside tags have this prefix:
 *  WTC+tagname+Varname ex.: WTCdivContent, WTCtableMenu
 */

/*
 * Specific usage functions and variables that depend on other
 * functions and variables shall be used with caution.
 * They all begin with a '_' ex.: _delayTimeStep()
 * And have some comment saying how they must be used.
 */

// GLOBAL VARIABLES
var g_strProjectName = "Website Template Control";

var g_strVersion="0.200.1";

var g_strMenuAreaId = "";

var g_sourceTDCurrentPageLink = null;

var g_aTDsource = new Array();

var g_nCountTmp         = "0";

var g_sourceTD_MenuItem = null;

var g_bDEBUG              = false; //@@@!!! release =false
var g_bDEBUGexitMsgPopup  = false; //@@@!!! release =false

var g_IFrameDEBUG         = null;
var g_nDebugEntryCount    = 0;

var g_IFrameData                   = null;
var g_strIFrameDataURL             = "about:blank";

var g_bLoadingLink = false;

var g_astrEval=new Array();

var g_timeoutAreaContentMouseOverOut = null;
var g_timeoutMenuShrinkExpand    = null;
var g_timeoutExecuteArrayTimeout = null;
var g_timeoutTableRefreshTrick   = null;
var g_timeoutMenuBlink           = null;
var g_timeoutSetupClickShow      = null;
var g_timeoutFIFDWM = null;
var g_intervalSPFIE = null;

// miliseconds
var g_timeoutDelayTime = null;
var g_nDelayTimeTotal  = 0;
var g_nDelayTimeSum    = 0;
var g_nDelayTimeStep   = 0;
var g_strDelayTimeEval = "";
var g_divDelayTimeShow = null;

var g_buttonLoadStop = null;

var g_strURLmenu     = "menu.html";
var g_strURLindex    = "index.html";

var g_strPlatform         = "";
var g_strBrowserName      = "";
var g_strBrowserNameShort = "";

var g_bWebTemCoStarted = false;

var g_bMenuItemColorAltBg = false;

var g_strMenuHTML = "";

var g_strMainValidateHTMLdata = "";

var g_bForceExit=false;

var g_nSetupColorsToShow=100;
var g_bSetupColorsToShow=true; //1st time

var g_bDeveloperControls=false;

var g_bMenuColorsUserSet=false;

var g_nVariableShowColorAsTableIDadd = 0;

var g_astrURLparams = new Array();

var g_strPath = "";
var g_strMenuFilePathName = "menu.html";

var g_bLocalBrowsing = false;

var g_atableColors = null;

var g_bCookieSeeAll = false;

var g_nSubmenuCount = 0;

var g_tdSubmenuOpened = null;

var g_aelSPFIE          = new Array();
var g_anSPFIEoffsetLeft = new Array();
var g_anSPFIEoffsetTop  = new Array();

var g_bAreaContentIsMainMenuItem = false;

var g_strLoadURL="";

var g_strMeURLbasePath="";

var g_strFirefoxLink='<a href="http://www.mozilla.org/products/firefox/">Firefox</a>';

var g_eltdColorSelected = null;

var g_nProgressCount = 0;

var g_timeoutProgressHide = null;

var g_bShowProgress = false;

var g_astrDebug = new Array();

var g_strLastLocation = "";
var g_bLastLocationRemember = false;

var g_bParameterLoadURL  = false;
var g_bAreaContentLoaded = false;

var g_astrHTMLEscapeCharEntRef = null;

var g_windowTemp = null;

var g_strMenuNameColorFg    ="";
var g_strMenuNameColorBg    ="";
var g_strMenuColorBg        =""; //background table boundaries color
var g_strMenuLinkColorFg    =""; //foreground to 'relative' links (the ones that don't use the <a> tag)
var g_strMenuLinkColorBg    ="";
var g_strMenuLinkColorAltFg =""; //foreground to 'relative' links (the ones that don't use the <a> tag)
var g_strMenuLinkColorAltBg =""; //Alternate bg link color
var g_strMenuSubmenuColorFg ="";
var g_strMenuSubmenuColorBg ="";
var g_strMenuFreeCellColorFg="";
var g_strMenuFreeCellColorBg="";

// Menu highlight colors
var g_strMenuHighlightColorFg   = "#FFFFFF";
var g_strMenuHighlightColorBg   = "#996633";
var g_strMenuCurrentLinkColorBg = "#666600";
var g_strMenuCurrentLinkColorFg = "#FFFFFF";

var g_bMenuItemOptionsSetByUser=false;
var g_strMenuItemOptionsTitle = "Browse Options&Opções de Navegação";
var g_strMenuItemOptionsId="";

var g_strMenuItemPBJ="Powered by Javascript&Modo Javascript";

var g_nMenuShrinkedTextShowTimesUserAlready=0;

// Enable or disable loading of bottom.html file?
var g_bLoadAreaBottom = true; //@@@ rever

var g_strCookieID="WebTemCo";

// DEBUG defaults
var g_bDEBUG_EntriesLogAlways = false; //@@@!!! false; //if false, won't log in case debug mode (checkbox) is off
var g_bDEBUG_Big              = false; //@@@!!! false;

// Show Menu/Content/Bottom area default WebTemCo documentation data?
var g_bShowWebTemCoDocumentation = false;
// Enable delay time in miliseconds before continue loading website
// Usefull to stop loading so WebTemCo documentation can be read
var g_nDelayBeforeLoadingWebsite = 3000;

var g_bCookieEnabled=true; //@@@!!! true

var g_bAreaTopAllowUserHide = false;
var g_bAreaContentTopAllowUserHide = false;
var g_bAreaContentBottomAllowUserHide = false;
var g_bAreaBottomAllowUserHide = false;

var g_bAreaTopUseHTMLfile = false; //if true set: id="WTCidAreaTop", onload="parent.WTCloadTop()" at top.html
var g_bAreaContentTopUseHTMLfile = false; //if true set: id="WTCidAreaContentTop", onload="parent.WTCloadContentTop()" at contenttop.html
var g_bAreaContentBottomUseHTMLfile = false; //if true set: id="WTCidAreaContentBottom", onload="parent.WTCloadContentBottom()" at contentbottom.html
var g_bAreaBottomUseHTMLfile = false; //if true set: id="WTCidAreaBottom", onload="parent.WTCloadBottom()" at bottom.html

var g_strAreaTopOnClick=''; // must be a function like funcName(event), so here will be set as: ='funcName'
var g_strAreaContentTopOnClick='';
var g_strAreaContentBottomOnClick='';
var g_strAreaBottomOnClick='';

var g_bMenuFloatingDockedChangeAllow=true;

// =========================== now it uses GUI to setup =================================
//var g_astrWebsiteSetup=new Array(); //must be declared at Dynamic Setup file

var g_strWebsiteTitle="";
var g_strLanguage="en"; //"en","pt_br"
// style index.html
var g_bEnable_IEworkaroundWidthPerc=true; //set to false if you are using fixed (not Percentual) TableMain width
var g_strTableMainStyle = "width: 100%; height: 100%";
var g_strMainBodyStyle  = "";
var g_strCSS = //colors: Black,Silver,Gray,White,Maroon,Red,Purple,Fuschia,Green,Lime,Olive,Yellow,Navy,Blue,Teal,Aqua
  //default will work for all website links as default
  'a:link   {color:    blue;} '+ 
  'a:visited{color: #6147A8;} '+
  'a:active {color: #1C28F4;} '+
  'a:hover  {color:     red;} '+
  //menu specific, used at non relative links (adjust also to the ones at FreeCell)
  'a.cCSSMenuLink:link   {color:  blue;} '+ 
  'a.cCSSMenuLink:visited{color:  navy;} '+
  'a.cCSSMenuLink:active {color: olive;} '+
  'a.cCSSMenuLink:hover  {color:   red;} '+
  '';
// to setup this variable, just go to preferences homepage, setup the color scheme you want and copy it to here.
var g_strColorScheme="10A3D6.000000.BFFFF4.000000.DFFFF2.000000.7FFFF8.266664.3AE144.000000.C8F5B6.000000.C3D6FE.BFFFF4.1C28F4";
var g_strImgMenuMini = "WebTemCoMenuMini.gif";
var g_strMenuShrinkedInnerHTML = "M<br>e<br>n<br>u";
var g_bMenuUseHTMLfile   = false;
/* Free table cell after menu entries and before menu 'automatic(internal) entries footer'
 * you can load here logotipo, host link, etc, anything you want :). This cell will resize
 * as larger/shorter content html files get loaded.
 */
var g_strMenuFreeCellStyle    ="vertical-align: bottom; text-align: center;";
var g_strMenuFreeCellInnerHTML='<small>(Free Cell) Setup <b>Menu Area</b> data at <a class="cCSSMenuLink" href="WebTemCoSetupDynamic.js">Setup file</a></small>';
var g_strMenuShrinkedStyle = "color: rgb(255,255,255); background-color: rgb(0,0,0); text-align: left;";
var g_astrMenuEntries = new Array()
 g_astrMenuEntries.push("N:MenuName.gif; p:options;")
 g_astrMenuEntries.push("l:MainExample.html; n:Main; p:contentMain")
 g_astrMenuEntries.push("l:WebTemCo.txt; n:Docs; p:loadTop;")
 g_astrMenuEntries.push("")
 g_astrMenuEntries.push("n:Content Examples; p:startSubMenu")
 g_astrMenuEntries.push("L:ContentExample.html" )
 g_astrMenuEntries.push("L:ContentExample2.html")
 g_astrMenuEntries.push("L:ContentExample3.html; p:endSubMenu;")
 g_astrMenuEntries.push("")
 //non relative links will be automatically adjusted to load on the top, replacing current homepage
 g_astrMenuEntries.push("l:http://webtemco.sourceforge.net/; n:Website Template Control") 
// Menu Shrinking
var g_bMenuFloating=true;
var g_bMenuFloatingMini=false;

var g_strAreaMenu="left";

var g_nMenuWidth = 100; //100 points
var g_nMenuTimeBeforeExpand=200;  //miliseconds
var g_nMenuTimeBeforeShrink=2000; //miliseconds
var g_nMenuShrinkedTextShowTimes = 3; //to each user

var g_bAreaTopShow = true;
var g_bAreaContentTopShow = true;
var g_bAreaContentBottomShow = true;
var g_bAreaBottomShow = true;

var g_strAreaTopStyle='color: rgb(255,255,255); background-color: rgb(150,150,0); vertical-align: middle; text-align: center;';
var g_strAreaContentTopStyle='color: rgb(255,255,255); background-color: rgb(150,100,0); vertical-align: middle; text-align: center;';
var g_strAreaContentBottomStyle='color: rgb(255,255,255); background-color: rgb(0,150,100); vertical-align: middle; text-align: center;';
var g_strAreaBottomStyle='color: rgb(255,255,255); background-color: rgb(0,150,150); vertical-align: middle; text-align: center;';

var g_strAreaTopInnerHTML='<small>Setup <b>Top Area</b> data at <a href="WebTemCoSetupDynamic.js">WebTemCoSetupDynamic.js</a></small>';
var g_strAreaContentTopInnerHTML='<small>Setup <b>Top Content Area</b> data at <a href="WebTemCoSetupDynamic.js">WebTemCoSetupDynamic.js</a></small>';
var g_strAreaContentBottomInnerHTML='<small>Setup <b>Content Bottom Area</b> data at <a href="WebTemCoSetupDynamic.js">WebTemCoSetupDynamic.js</a></small>';
var g_strAreaBottomInnerHTML='<small>Setup <b>Bottom Area</b> data at <a href="WebTemCoSetupDynamic.js">WebTemCoSetupDynamic.js</a></small>';


//var g_innerHTMLdocumentation = "";
function testInfo(){
  /* Characters that can be used as token delimiter (split()) while having 'data' escaped properly :)
   * ex.: "link;name;loadTop" or "int;float;"
   */
   // alert(escape("`~! #$%^& ()  = \\|[{]};:'\",< > ?  \b  \f\n\r\t\v"));
   // not escaped: "   @     *  -_ +              . / \a  \e          "
 //*/
}

function trim_str(str){
  if(!str)return "";
  str=""+str;

  return str.replace(/^\s+/,"").replace(/\s+$/,"");
}

function linkToPrettyName_str(str){
  str=trim_str(str);

  // removes path and extension
  str=str.split("/").reverse()[0].split(".")[0];

  var strLower=str.toLowerCase();
  var strNew = "";

  var bPrevIsNum=false;
  var bCurrentIsNum=false;
  for(n=0;n<str.length;n++){
    // char to num/symbol to char space
    bPrevIsNum=bCurrentIsNum;

    bCurrentIsNum=false;
    if(""+parseInt(str.charAt(n)) == str.charAt(n)){
      bCurrentIsNum=true;
    }
    
    if(bPrevIsNum && bCurrentIsNum){
      strNew+=str.charAt(n);
      continue;
    }
    
    if(bPrevIsNum != bCurrentIsNum){
      strNew+=" "+str.charAt(n);
      continue;
    }
    
    // upper to lower case space
    if(n==0){
      strNew+=str.charAt(n);
      continue;
    }

    if(str.charAt(n) != strLower.charAt(n)){
      strNew+=" ";
    }

    strNew+=str.charAt(n);
  }

  return strNew;
}

function menuItemHTML_str(strMenuEntryScript){
  funcCallerNameIN(strMenuEntryScript);

  strMenuEntryScript=trim_str(strMenuEntryScript);
  debugMsg(strMenuEntryScript.charAt(0)+"/"+strMenuEntryScript);

  // Overhide <tr><td>...</td></tr> table cell creation
  if(strMenuEntryScript.charAt(0)=="O"){
    return strMenuEntryScript.substr(2);
  }

  if(strMenuEntryScript=="p:DoNotSave;")
    strMenuEntryScript="";
  if(strMenuEntryScript=="" || strMenuEntryScript.charAt(0)=="H")
    return "<tr><td>"+strMenuEntryScript.substr(2)+"</td></tr>";

  var astr = strMenuEntryScript.split(";");

  var str_l="";
  var str_lc="";

  var str_n="";
  var str_N="";
  var str_fc="";

  var str_f="";
  var str_b="";
  var str_B="";
  
  var str_w="";
  var str_h="";
  
  var str_t="";

  var str_id="";

  var str_textalign="text-align: left;";

  var str_txtextra ="<small>";
  var str_txtextrac="</small>";
  
  var strSubmenu="";

  var strLink="";
  
  var bFreeCell=false;
  
  var bMenuItemOptions=false;
  
  var str = "";
  while(astr.length>0){
    // Syntax: " <one letter type>:value"
    str=astr.shift();
    str=trim_str(str);
    strValue=str.substr(2) // "?:...";
    switch(str.charAt(0)){
      case "l": //link
      case "L": //link
        strLink=strValue;
       
        str_l='<a class="cCSSMenuLink" href="'+strValue+'">';
        str_lc="</a>";
       
        if(str.charAt(0) == "L"){
          astr.push("n:"+linkToPrettyName_str(strValue));
        }
        if(g_bMenuItemColorAltBg){
          if(g_strMenuLinkColorAltFg!="")astr.unshift("f:"+g_strMenuLinkColorAltFg);
        }else{
          if(g_strMenuLinkColorFg   !="")astr.unshift("f:"+g_strMenuLinkColorFg);
        }
        
        //menuitem (TD) background color
        var strColorBg = (g_bMenuItemColorAltBg ? g_strMenuLinkColorAltBg : g_strMenuLinkColorBg);
        if(g_strMenuLinkColorAltBg != "")g_bMenuItemColorAltBg = !g_bMenuItemColorAltBg;
        if(strColorBg              != "")astr.unshift("b:"+strColorBg);
        break;
      case "n": 
        str_n=strValue;
        break;
      case "N":
        str_N='<img src="'+strValue+'">';
        break;
      case "f": 
        str_f="color: "+strValue+";";
        break;
      case "b": 
        str_b="background-color: "+strValue+";";
        break;
      case "B": 
        str_B="background-image: url("+strValue+");"
        break;
      case "t": 
        str_t='title="'+escapeToHTML_str(strValue)+'"';
        break;
      case "p": 
        switch(strValue){
          case "DoNotSave":
            // keep this one, usefull to clean menu entries before saving dynamic file
            break;
          case "options":
            bMenuItemOptions=true;
            if(g_strMenuNameColorFg!="")astr.unshift("f:"+g_strMenuNameColorFg);
            if(g_strMenuNameColorBg!="")astr.unshift("b:"+g_strMenuNameColorBg);
            str_txtextra =str_txtextra+"<b>";
            str_txtextrac="</b>"+str_txtextrac;
            break;
          case "contentMain":
            str_id="WTCidMenuItemMain";
            break;
          case "highlightBypass":
            str_id="WTCidMenuItemForceHighlightBypass";
            break;
          case "loadTop":
            str_id="WTCidMenuItemForceLoadTop";
            break;
          case "startSubMenu":
            //unshift allows user to setup specific colors
            if(g_strMenuSubmenuColorFg != "")astr.unshift("f:"+g_strMenuSubmenuColorFg) ;
            if(g_strMenuSubmenuColorBg != "")astr.unshift("b:"+g_strMenuSubmenuColorBg);
            str_textalign = "text-align: center;";
            str_txtextra += "<b>";
            str_txtextrac = "</b>"+str_txtextrac;
            strSubmenu="open";
            break;
          case "endSubMenu":
            strSubmenu="close";
            break;
          case "freeCell":
            bFreeCell=true;
            str_id="WTCidMenuFreeCell";
            str_w="width: 100%;";
            str_h="height:100%;";
            str_f="color: "+g_strMenuFreeCellColorFg+";";
            str_b="background-color: "+g_strMenuFreeCellColorBg+";";
            str_fc=g_strMenuFreeCellInnerHTML;
            strSubmenu="";
            break;
          default:
            exitMsg("invalid property: \""+strValue+"\" strMenuEntryScript["+strMenuEntryScript+"] see setup file for details.");
            break;
        }
        break;
    }
  }

  if(str_n==""){
    str_n=strLink.split(".")[0];
  }
  
  var strCellStyle = str_textalign+str_f+str_b+str_B+str_w+str_h+(bFreeCell?g_strMenuFreeCellStyle:"");
  
  var strText = str_l + str_txtextra + str_N + multiLang_str(str_n) + str_fc + str_txtextrac + str_lc;
  
  var strSubmenuOpenClose = "";
  var strMenuItemClose = "</td></tr>";
  if(strSubmenu == "open"){
    var strId="WTCsubmenu";
    
    var strSubmenuId = strId + g_nSubmenuCount;
    //var strSubmenuId = strId + (bMenuItemOptions?"Options":g_nSubmenuCount);
    
    //executeArrayTimeout1("elGet_el(\""+strSubmenuId+"\").WTCsubmenuId=new String(\""+strSubmenuId+"\")");
    
    str_id = strId+":"+g_nSubmenuCount;
    //str_id = strId+":"+(bMenuItemOptions?"Options":g_nSubmenuCount);
    
    strSubmenuOpenClose =
      '<table id="'+strSubmenuId+'" style="width: '+g_nMenuWidth+'px;"><tbody>'+
      '<tr><td id="'+str_id+'" '+str_t+' style="'+strCellStyle+' display: none;">'+strText+'</td></tr>'; //1st cell is equal to the submenu one
    
    // setup dynamic submenu values
    executeArrayTimeout1('submenuName(elGet_el("'+strSubmenuId+'"),true)');
    
    executeArrayTimeout1('elStyle("'+strSubmenuId+'",'+
      '"position: '+browserCompat_str("fixed","absolute")+'; '+
      ' left: '+g_nMenuWidth+'; '+
      ' top: 0; display: none;")');
    
    executeArrayTimeout1("tableCellsDivisionLine(elGet_el(\""+strSubmenuId+"\"),2)");
    
    strMenuItemClose = "";
    
    //if(!bMenuItemOptions)
    g_nSubmenuCount++;
    
  }else if(strSubmenu == "close"){
    strSubmenuOpenClose="</tbody></table>";
  }
  
//  var strMenuItemOpen = '<tr><td id="'+str_id+'" style="'+strCellStyle+(bMenuItemOptions?' visibility: hidden; ':'')+'">';
  if(bMenuItemOptions)
    g_strMenuItemOptionsId=str_id;

  var strMenuItemOpen = '<tr><td id="'+str_id+'" '+str_t+' '+' style="'+strCellStyle+'">';
//  var strMenuItemOpen = '<tr><td id="'+str_id+'" style="'+ (bMenuItemOptions ? "" : strCellStyle) +'">';
//  var strMenuItemOpen = '<tr><td id="'+str_id+'" style="'+strCellStyle+'">';

  var strRet=
    strMenuItemOpen+ 
    strText+
    strSubmenuOpenClose+
    strMenuItemClose; //HTML
  
  funcCallerNameOUT(strRet);
  return strRet;
}

function browserCompat_str(strDefault,strIE){
  if(g_strBrowserNameShort == "IE"){
    return strIE;
  }
  return strDefault;
}

function multiLang_str(str){
  var astr=str.split("&");
  var strEn=astr[0];
  var strPtBr=astr[1];
  if(g_strLanguage == "en"){
    return strEn;
  }
  if(g_strLanguage == "pt_br"){
    if(strPtBr && !strIsBlank_b(strPtBr))
      return strPtBr;
  }
  
  return strEn;
}

function ptpx2n(str){
  var str = new String(str);
  str = str.split("px")[0];
  str = str.split("pt")[0];
  return str;
}

function SPFIEadd(strElId){
  // to IE simulate position fixed
  var el = elGet_el(strElId);
  g_aelSPFIE         .push(                   el              );
  g_anSPFIEoffsetLeft.push( new Number(ptpx2n(el.style.left)) );
  g_anSPFIEoffsetTop .push( new Number(ptpx2n(el.style.top )) );
}

function SimulatePosFixedOnIE(){
  if(!browserId_b("IE"))
    return;
  
  /* On IE, when element has absolute position, this means absolute relatively to its parent
   * so a child table set to have top=100, this will be relatively to parent table, if parent is top=50, 
   * real child top will be 150.
   * This means only parent menu table needs to be updated.
   */
  var nScrollTop  = new Number(document.body.scrollTop );
  var nScrollLeft = new Number(document.body.scrollLeft);

  for(var n=0; n<g_aelSPFIE.length; n++){
    g_aelSPFIE[n].style.top =(nScrollTop  + g_anSPFIEoffsetTop [n])+'px';
    g_aelSPFIE[n].style.left=(nScrollLeft + g_anSPFIEoffsetLeft[n])+'px';
  }

  if(!g_intervalSPFIE){ //begin interval
    g_intervalSPFIE = setInterval("SimulatePosFixedOnIE()",1);
  }
}

function menuOptionsEntriesUserSet(bInternal,bRemoveToSaveAtDynamicFile){
  for(var n=0; n<g_astrMenuEntries.length; n++){
    var astr = g_astrMenuEntries[n].split(";")
    for(var n1=0; n1<astr.length; n1++){
      if( trim_str(astr[n1].split(":")[0]) == "p" ){
        if( trim_str(astr[n1].split(":")[1]) == "DoNotSave" ){
          if(bRemoveToSaveAtDynamicFile){
            g_astrMenuEntries.splice(n,1);n--;//n-- as only removed
          }
        }
        if( trim_str(astr[n1].split(":")[1]) == "options" ){
          if(bRemoveToSaveAtDynamicFile){
            // remove startSubMenu property before saving
            var astr1=g_astrMenuEntries[n].split(";");
            for(var n2=0;n2<astr1.length;n2++){
              if(trim_str(astr1[n2]) == "p:startSubMenu"){
                astr1.splice(n2,1);
              }
            }
            g_astrMenuEntries.splice(n,1,astr1.join(";"));
          }else{
            var astr2=g_astrMenuEntries[n].split(";");
			astr2.push("p:startSubMenu");
            g_astrMenuEntries.splice(n,1,astr2.join(";"));
            g_astrMenuEntries.splice(n+1,0,
              "p:DoNotSave; l:WebTemCoPref.html;  n:"+multiLang_str("Preferences&Preferências" )+";",
              "p:DoNotSave; l:menu.html;          n:"+multiLang_str("Plain HTML&HTML Simples"                    )+";",
              "p:DoNotSave; l:index.html;         n:"+multiLang_str(g_strMenuItemPBJ)+"; p:endSubMenu;",
              "p:DoNotSave;");
            if(!bInternal)
              g_bMenuItemOptionsSetByUser=true;
            return;
          }
        }
      }
    }
  }
}

function menuEndingEntriesAppend(){
  funcCallerNameIN();
  
  g_astrMenuEntries.push("p:DoNotSave;");
  
  if(!g_bMenuItemOptionsSetByUser){
    g_astrMenuEntries.push("p:DoNotSave; n:"+g_strMenuItemOptionsTitle+"; p:options;");
    menuOptionsEntriesUserSet(true);
  }
  
  //g_astrMenuEntries.push("O:<tr><td id=\"WTCidMenuFreeCell\" style=\"width: 100%; height:100%; "+g_strMenuFreeCellStyle+"\">"+g_strMenuFreeCellInnerHTML+'</td></tr>');
  g_astrMenuEntries.push("p:DoNotSave; p:freeCell;");
  
  funcCallerNameOUT();
}

function prepareAreaMenu(){
  Progress("Prepare Area Menu");

  funcCallerNameIN(g_strMenuAreaId);
  
  // table width = g_nMenuWidth to stop shaking when dynamic text "Browse Mode" changes
  var strId = "WTCtableMenuBoundary";
  g_strMenuHTML=
    "<table id=\""+strId+"\" style=\"width: "+g_nMenuWidth+"px; height: 100%; background-color: "+g_strMenuColorBg+";\" >"+
      "<tbody>"+
        "<tr>"+
          "<td style=\"width: 100%; height: 100%;\">"+
            "<table id=\"WTCtableMenu\" style=\"width: 100%; height: 100%; vertical-align: top;\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" rules=\"all\" >"+
              "<tbody>";

  // Menu entries to HTML
  menuOptionsEntriesUserSet();
  menuEndingEntriesAppend();
  for(var nCurrent=0; nCurrent<g_astrMenuEntries.length; nCurrent++){
    g_strMenuHTML += menuItemHTML_str(g_astrMenuEntries[nCurrent]);
  }

  g_strMenuHTML=g_strMenuHTML+
              "</tbody>"+
            "</table>"+
          "</td>"+
        "</tr>"+
      "</tbody>"+
    "</table>";
  
  executeArrayTimeout1('elStyle("'+strId+'","position: '+browserCompat_str("fixed","absolute")+'; left: 0; top: 0;")');
  executeArrayTimeout1("SPFIEadd(\""+strId+"\")"); 
  
  debugBig(g_strMenuHTML);

  document.getElementById(g_strMenuAreaId).innerHTML = g_strMenuHTML;
  menuWork();

  funcCallerNameOUT();
}

function Progress(strInfo,bBegin){
  if(!g_bShowProgress)return;
  
  if(bBegin)
    g_nProgressCount=0;
  elGet_el("WTCdivProgress").style.display="";
  elGet_el("WTCdivProgress").innerHTML="<small>Progress ["+g_nProgressCount+"] "+strInfo+"</small>";
  g_nProgressCount++;
  
  ProgressHide();
}

function ProgressHide(bHideNow){
  if(bHideNow){
    elGet_el("WTCdivProgress").style.display="none";
    return;
  }
  
  clearTimeout(g_timeoutProgressHide);
  g_timeoutProgressHide = setTimeout("ProgressHide(true)",2000);
}

function checkLocalBrowsing(){
  funcCallerNameIN();

  var strLocation = (new String(window.location)).split("?")[0];
  var strCmp="file://";
  if(strLocation.indexOf(strCmp)==0){
    var astr=strLocation.substr(strCmp.length).split("/");
    astr.pop(); //removes index.html
    if(g_strPlatform=="Win32"){
      debugMsg("Win32 filename");
      g_strPath=astr.join("\\").substr(1)+"\\";  //removes leading "/"
      g_strMenuFilePathName=g_strPath+g_strMenuFilePathName;
    }else{ //Unix
      debugMsg("Unix filename");
      g_strPath=astr.join("/")+"/";
      g_strMenuFilePathName=g_strPath+g_strMenuFilePathName;
    }
    debugMsg(g_strMenuFilePathName);
    g_bLocalBrowsing=true;
  }

  funcCallerNameOUT();
}

function tableTrTd_str(str,strTdStyle){
  return '<tr>'+tableTd_str(str,strTdStyle)+'</tr>';
}

function tableTd_str(str,strTdStyle){
  if(strIsBlank_b(str))
    return '<td></td>';
  
  if(strTdStyle)
    strTdStyle='style="'+strTdStyle+'"'
  else
    strTdStyle="";
  
  return '<td '+strTdStyle+'>'+str+'</td>';
}

// Called from preferences homepage
function WTCsetupPrepareFillIFrameDataWithMenu(){
  g_bCookieEnabled=false;
  executeArrayTimeout1('setIFrameDataURL_b(getTDUrlLink_str(document.getElementById("WTCidMenuItemMain"),true))');
  executeArrayTimeout1('prepareFillIFrameDataWithMenu2()');
}

function prepareFillIFrameDataWithMenu2(){
  if(!g_bAreaContentIsMainMenuItem){
    g_timeoutFIFDWM = setTimeout('prepareFillIFrameDataWithMenu2()',1000);
    return;
  }
 
  fillIFrameDataWithMenu();
}

function fillIFrameDataWithMenu(){
  // prepare menu as non floating
  var el = document.getElementById(g_strMenuAreaId)
  el.innerHTML = g_strMenuHTML;  
  elShow(null,true,el);
  
  // disable shrinked menu area
  menuShrinkedGet_el().innerHTML="";
  elShow(null,false,menuShrinkedGet_el());

  // remove options submenu inside-table
  el = document.getElementById(g_strMenuItemOptionsId.split(":").join(""))
  el.parentNode.removeChild(el);
  
  // set menuname as link to index.html
  el = document.getElementById(g_strMenuItemOptionsId)
  el.innerHTML = '<a title="Use this link to browse in Javascript mode" href="index.html">'+el.innerHTML+'</a>';  
  
  //WorkWindowOpen(g_strMenuFilePathName,"windowTempOnload");
  WorkWindowOpen(null,"windowTempOnload");
}

function windowTempOnload(){
  if(g_windowTemp){
    // highlight main homepage
    menuItemHighlight("WTCidMenuItemMain");
    
    var strGenInfo=
      '<!-- "'+g_strProjectName+'" '+g_strVersion+
      " dynamically generated Plain HTML file at "+(new Date()).toString()+" -->";
    debugMsg(strGenInfo);
    
    g_windowTemp.document.write(escapeToHTML_str(
      '<html><body style="'+window.document.body.style.cssText+'" '+
        'text="'      +window.document.body.text   +'" '+
        'bgcolor="'   +window.document.body.bgColor+'" '+
        'background=' +'url("'+window.document.body.background+'") '+
        'alink="'     +window.document.body.aLink+'" '+
        'link="'      +window.document.body.link +'" '+
        'vlink="'     +window.document.body.vLink+'" >'+
        strGenInfo+escapeToHTML_str(document.body.innerHTML,true)+
      '</body></html>'
    ));
    
    window.location.replace("index.html"); //restores normal state
  }
}

function IFreameDataReset(){
  g_IFrameData.document.body.innerHTML = "";
  elStyle(null,"color: rgb(255,255,255); background-color: rgb(0,0,0); background-image:;",
    g_IFrameData.document.body);
  g_IFrameData.document.body.background="";
}

function elGet_el(strId){
  return document.getElementById(strId);
}

function elHTML(strId,strHTML){
  var el = elGet_el(strId);
  if(!el)exitMsg("element with id=\""+strId+"\" not found!");
  el.innerHTML=strHTML;
}

function escapeToHTML_str(strHTML, bDoubleEscapeEscapedOnly){
  if(!strHTML || strHTML=="")return "";

  var strRet=""
  var strChar=""
  for(var n=0;n<strHTML.length;n++){
    strChar=strHTML.substr(n,1);
    if(bDoubleEscapeEscapedOnly){
        if(strChar == "&"){
          // works like this: "&gt;" -> "&<span>gt;</span>" so "&gt;" will be displayed instead of ">"
          strRet+="&amp;";
          var nEnd = strHTML.indexOf(";",n);
          if(nEnd != -1){
            if(nEnd - n <= 4){
              //strRet+="<span>";
              strRet+=strHTML.substr(n+1,nEnd-n);
              //strRet+="</span>";
              n=nEnd; //skip to nEnd (after gathered chars, loop 'for' will make it == nEnd+1)
            }
          }
        }else{
          strRet+=strChar;
        }
    }else{
      strRet+=HTMLEscapeTranslate_str(strChar);
    }
  }
  
  return strRet;
}

function HTMLEscapeTranslationTableSet(){
  //Character entity references in HTML 4
  //Array.splice used to decrease javascript code size
  
  //This array uses much more memory, but to translate is EXTREMELY FASTER.
  g_astrHTMLEscapeCharEntRef = new Array(9830+1);
  
  g_astrHTMLEscapeCharEntRef[34]="quot";
  g_astrHTMLEscapeCharEntRef[38]="amp";
  g_astrHTMLEscapeCharEntRef[60]="lt";
  g_astrHTMLEscapeCharEntRef[62]="gt";
  
  g_astrHTMLEscapeCharEntRef.splice(160,96,
    "nbsp","iexcl","cent","pound","curren","yen","brvbar","sect","uml","copy","ordf","laquo",
    "not","shy","reg","macr","deg","plusmn","sup2","sup3","acute","micro","para","middot","cedil",
    "sup1","ordm","raquo","frac14","frac12","frac34","iquest","Agrave","Aacute","Acirc","Atilde",
    "Auml","Aring","AElig","Ccedil","Egrave","Eacute","Ecirc","Euml","Igrave","Iacute","Icirc",
    "Iuml","ETH","Ntilde","Ograve","Oacute","Ocirc","Otilde","Ouml","times","Oslash","Ugrave",
    "Uacute","Ucirc","Uuml","Yacute","THORN","szlig","agrave","aacute","acirc","atilde","auml",
    "aring","aelig","ccedil","egrave","eacute","ecirc","euml","igrave","iacute","icirc","iuml",
    "eth","ntilde","ograve","oacute","ocirc","otilde","ouml","divide","oslash","ugrave","uacute",
    "ucirc","uuml","yacute","thorn","yuml");
  
  g_astrHTMLEscapeCharEntRef.splice(160,8,"OElig","oelig","Scaron","scaron","Yuml","fnof","circ","tilde");
  
  g_astrHTMLEscapeCharEntRef.splice(160,17,
    "Alpha","Beta","Gamma","Delta","Epsilon","Zeta","Eta","Theta","Iota","Kappa","Lambda","Mu",
    "Nu","Xi","Omicron","Pi","Rho");
  
  g_astrHTMLEscapeCharEntRef.splice(160,7,"Sigma","Tau","Upsilon","Phi","Chi","Psi","Omega");
  
  g_astrHTMLEscapeCharEntRef.splice(160,25,
    "alpha","beta","gamma","delta","epsilon","zeta","eta","theta","iota","kappa","lambda","mu",
    "nu","xi","omicron","pi","rho","sigmaf","sigma","tau","upsilon","phi","chi","psi","omega");
  
  g_astrHTMLEscapeCharEntRef[977]="thetasym";
  g_astrHTMLEscapeCharEntRef[978]="upsih";
  g_astrHTMLEscapeCharEntRef[982]="piv";
  g_astrHTMLEscapeCharEntRef[8194]="ensp";
  g_astrHTMLEscapeCharEntRef[8195]="emsp";
  g_astrHTMLEscapeCharEntRef[8201]="thinsp";
  g_astrHTMLEscapeCharEntRef[8204]="zwnj";
  g_astrHTMLEscapeCharEntRef[8205]="zwj";
  g_astrHTMLEscapeCharEntRef[8206]="lrm";
  g_astrHTMLEscapeCharEntRef[8207]="rlm";
  g_astrHTMLEscapeCharEntRef[8211]="ndash";
  g_astrHTMLEscapeCharEntRef[8212]="mdash";
  g_astrHTMLEscapeCharEntRef[8216]="lsquo";
  g_astrHTMLEscapeCharEntRef[8217]="rsquo";
  g_astrHTMLEscapeCharEntRef[8218]="sbquo";
  g_astrHTMLEscapeCharEntRef[8220]="ldquo";
  g_astrHTMLEscapeCharEntRef[8221]="rdquo";
  g_astrHTMLEscapeCharEntRef[8222]="bdquo";
  g_astrHTMLEscapeCharEntRef[8224]="dagger";
  g_astrHTMLEscapeCharEntRef[8225]="Dagger";
  g_astrHTMLEscapeCharEntRef[8226]="bull";
  g_astrHTMLEscapeCharEntRef[8230]="hellip";
  g_astrHTMLEscapeCharEntRef[8240]="permil";
  g_astrHTMLEscapeCharEntRef[8242]="prime";
  g_astrHTMLEscapeCharEntRef[8243]="Prime";
  g_astrHTMLEscapeCharEntRef[8249]="lsaquo";
  g_astrHTMLEscapeCharEntRef[8250]="rsaquo";
  g_astrHTMLEscapeCharEntRef[8254]="oline";
  g_astrHTMLEscapeCharEntRef[8260]="frasl";
  g_astrHTMLEscapeCharEntRef[8364]="euro";
  g_astrHTMLEscapeCharEntRef[8465]="image";
  g_astrHTMLEscapeCharEntRef[8472]="weierp";
  g_astrHTMLEscapeCharEntRef[8476]="real";
  g_astrHTMLEscapeCharEntRef[8482]="trade";
  g_astrHTMLEscapeCharEntRef[8501]="alefsym";
  g_astrHTMLEscapeCharEntRef[8592]="larr";
  g_astrHTMLEscapeCharEntRef[8593]="uarr";
  g_astrHTMLEscapeCharEntRef[8594]="rarr";
  g_astrHTMLEscapeCharEntRef[8595]="darr";
  g_astrHTMLEscapeCharEntRef[8596]="harr";
  g_astrHTMLEscapeCharEntRef[8629]="crarr";
  g_astrHTMLEscapeCharEntRef[8656]="lArr";
  g_astrHTMLEscapeCharEntRef[8657]="uArr";
  g_astrHTMLEscapeCharEntRef[8658]="rArr";
  g_astrHTMLEscapeCharEntRef[8659]="dArr";
  g_astrHTMLEscapeCharEntRef[8660]="hArr";
  g_astrHTMLEscapeCharEntRef[8704]="forall";
  g_astrHTMLEscapeCharEntRef[8706]="part";
  g_astrHTMLEscapeCharEntRef[8707]="exist";
  g_astrHTMLEscapeCharEntRef[8709]="empty";
  g_astrHTMLEscapeCharEntRef[8711]="nabla";
  g_astrHTMLEscapeCharEntRef[8712]="isin";
  g_astrHTMLEscapeCharEntRef[8713]="notin";
  g_astrHTMLEscapeCharEntRef[8715]="ni";
  g_astrHTMLEscapeCharEntRef[8719]="prod";
  g_astrHTMLEscapeCharEntRef[8721]="sum";
  g_astrHTMLEscapeCharEntRef[8722]="minus";
  g_astrHTMLEscapeCharEntRef[8727]="lowast";
  g_astrHTMLEscapeCharEntRef[8730]="radic";
  g_astrHTMLEscapeCharEntRef[8733]="prop";
  g_astrHTMLEscapeCharEntRef[8734]="infin";
  g_astrHTMLEscapeCharEntRef[8736]="ang";
  g_astrHTMLEscapeCharEntRef[8743]="and";
  g_astrHTMLEscapeCharEntRef[8744]="or";
  g_astrHTMLEscapeCharEntRef[8745]="cap";
  g_astrHTMLEscapeCharEntRef[8746]="cup";
  g_astrHTMLEscapeCharEntRef[8747]="int";
  g_astrHTMLEscapeCharEntRef[8756]="there4";
  g_astrHTMLEscapeCharEntRef[8764]="sim";
  g_astrHTMLEscapeCharEntRef[8773]="cong";
  g_astrHTMLEscapeCharEntRef[8776]="asymp";
  g_astrHTMLEscapeCharEntRef[8800]="ne";
  g_astrHTMLEscapeCharEntRef[8801]="equiv";
  g_astrHTMLEscapeCharEntRef[8804]="le";
  g_astrHTMLEscapeCharEntRef[8805]="ge";
  g_astrHTMLEscapeCharEntRef[8834]="sub";
  g_astrHTMLEscapeCharEntRef[8835]="sup";
  g_astrHTMLEscapeCharEntRef[8836]="nsub";
  g_astrHTMLEscapeCharEntRef[8838]="sube";
  g_astrHTMLEscapeCharEntRef[8839]="supe";
  g_astrHTMLEscapeCharEntRef[8853]="oplus";
  g_astrHTMLEscapeCharEntRef[8855]="otimes";
  g_astrHTMLEscapeCharEntRef[8869]="perp";
  g_astrHTMLEscapeCharEntRef[8901]="sdot";
  g_astrHTMLEscapeCharEntRef[8968]="lceil";
  g_astrHTMLEscapeCharEntRef[8969]="rceil";
  g_astrHTMLEscapeCharEntRef[8970]="lfloor";
  g_astrHTMLEscapeCharEntRef[8971]="rfloor";
  g_astrHTMLEscapeCharEntRef[9001]="lang";
  g_astrHTMLEscapeCharEntRef[9002]="rang";
  g_astrHTMLEscapeCharEntRef[9674]="loz";
  g_astrHTMLEscapeCharEntRef[9824]="spades";
  g_astrHTMLEscapeCharEntRef[9827]="clubs";
  g_astrHTMLEscapeCharEntRef[9829]="hearts";
  g_astrHTMLEscapeCharEntRef[9830]="diams";
}

function HTMLEscapeTranslate_str(strChar,nCharCode){
  if(!nCharCode)
    nCharCode=strChar.charCodeAt(0);
  
  var str = g_astrHTMLEscapeCharEntRef[nCharCode];
  
  if(strIsBlank_b(str)){
    if(!strChar || strChar == ""){ //do not use strIsBlank_b() that trims spaces
      debugMsg("HTML Character Entity Reference code not found: "+nCharCode,false,false,false,true); //bNoEscape=true will avoid recursion
      return "";
    }else{
      return strChar; //return w/o translating
    }
  }
  
  return "&"+str+";";
}

function prepareArea_strExec(strId,bShow,strAreaStyle,strHTML,bUseHTMLfile,strHTMLfile,eventOnClick){
  funcCallerNameIN(strId+","+bShow+","+strAreaStyle+","+strHTML+","+bUseHTMLfile+","+strHTMLfile+","+eventOnClick);

  Progress("Adjust Area "+strId);
  
  elShow(strId,bShow);
  elStyle(strId,strAreaStyle);
  if(bShow){
    if(bUseHTMLfile){ // -> file.html -> parent.WTCload...();    
      var strExec="setIFrameDataURL_b(\""+strHTMLfile+"\")";
      funcCallerNameOUT(strExec);
      return strExec; //to add to exec loop
    }
    elHTML(strId,strHTML);
    if(eventOnClick && eventOnClick!="")
      eval("elGet_el(\""+strId+"\").onclick="+eventOnClick);
  }

  funcCallerNameOUT();
  return "";
}

function clearIntervals(){
  clearTimeout(g_timeoutDelayTime          );
  clearTimeout(g_timeoutExecuteArrayTimeout);
  clearTimeout(g_timeoutTableRefreshTrick  );
  clearTimeout(g_timeoutMenuBlink          );
  clearTimeout(g_timeoutSetupClickShow     );
  clearTimeout(g_timeoutMenuShrinkExpand   );
  clearTimeout(g_timeoutAreaContentMouseOverOut);
  clearTimeout(g_timeoutFIFDWM );
  clearTimeout(g_timeoutProgressHide);
  
  clearInterval(g_intervalSPFIE);
  
  if(g_bForceExit)
    g_astrEval=new Array(); //just for safety
}

// OBS.:
function funcShowObservation(){
  // Always declare variables with 'var' before of them ex.: var str = "a"
  str="a";
  test1(str); //or: test1()
  debugMsg(str); // it shows "c" instead of "a"
  return null;
  //exitMsg("Just performed a test, execution aborted.");
}
function test1(str1){
  str1="b";
  str="c";
}


// 

function buttonLoadStop(){
  if(g_timeoutDelayTime){
    delayTimeStopReset();
    g_buttonLoadStop.innerHTML="Click me again<br>to continue<br>loading<br>Website.";
  }else{
    g_buttonLoadStop.style.display="none";
    continueLoading2();
  }
}

function delayTimeStopReset(){
  //onclick="window.stop()"
  clearTimeout(g_timeoutDelayTime);
  g_timeoutDelayTime = null;
  g_nDelayTimeTotal  = 0;
  g_nDelayTimeSum    = 0;
  g_nDelayTimeStep   = 0;
  g_strDelayTimeEval = "";
  g_divDelayTimeShow = null;
}

function _delayTimeStep(){ //@@@!!! shall only be called from delayTime()
/*@@@!!! Not really needed code. Commented for IE compatibility.
  srcCaller=_delayTimeStep.caller;
  if(srcCaller){
    strCaller=srcCaller.toString().split("(")[0];
    if(strCaller != "delayTime"){
      exitMsg("caller["+strCaller+"()].\n"+
        "_delayTimeStep() shall only be called from delayTime()\n"+
        "that will properly setup its delay time control variables!");
    }
  }
*/  

  g_nDelayTimeSum+=g_nDelayTimeStep;

  if(g_divDelayTimeShow){
//    g_divDelayTimeShow.innerHTML=(g_nDelayTimeSum/1000)+"s("+(g_nDelayTimeTotal/1000)+"s)";
    g_divDelayTimeShow.innerHTML = ((g_nDelayTimeTotal-g_nDelayTimeSum)/1000)+"s";
  }

  // If there is remaining time to delay, set a new timeout
  if(g_nDelayTimeSum < g_nDelayTimeTotal){
    var nTimeRemain = g_nDelayTimeTotal - g_nDelayTimeSum;

    var nTimeStep=((nTimeRemain > g_nDelayTimeStep) ? g_nDelayTimeStep : nTimeRemain); //use the lesser

    g_timeoutDelayTime=setTimeout("_delayTimeStep()",nTimeStep);
  }else{
    g_buttonLoadStop.style.display="none";
    setTimeout(g_strDelayTimeEval,0);
    delayTimeStopReset();
  }
}

function delayTime(nTimeTotal,nTimeStep,strEval,strDivDelayTimeShow){
  g_nDelayTimeTotal  = nTimeTotal; //total delay time
  g_nDelayTimeStep   = nTimeStep;  //time step til reach total time
  g_strDelayTimeEval = strEval;
  if(strDivDelayTimeShow){
    g_divDelayTimeShow=document.getElementById(strDivDelayTimeShow);
    if(g_divDelayTimeShow)
      g_divDelayTimeShow.innerHTML = (g_nDelayTimeTotal/1000)+"s";
  }

  g_timeoutDelayTime=setTimeout("_delayTimeStep()",g_nDelayTimeStep);
}

function styleAdjustKind_str(strStyle){
  funcCallerNameIN(strStyle);

  if(!strStyle || strStyle=="")return "";
  
  var str=strStyle;
  str=str.toLowerCase();
  str=trim_str(str);
  
  var strReturn=""
  var astr = str.split("-"); // ex.: background-color
  for(var n=0;n<astr.length;n++){
    if(n==0)
      strReturn+=astr[n]; //ex.: background
    else{
      //strReturn+=astr[n].charAt(0).toUpperCase()+astr[n].substr(1); //ex.: backgroundColor
      strReturn+=(new String(astr[n].charAt(0))).toUpperCase()+astr[n].substr(1); //ex.: backgroundColor
    }
  }
  
  funcCallerNameOUT(strReturn);
  return strReturn;
}

function styleParseSet(el,strStyles){
  funcCallerNameIN((el?el.id:strEval_el)+","+strStyles);

  strStyles=trim_str(strStyles);
  var bClean = strStyles == "clean";
  if(bClean){
    strStyles=trim_str(el.style.cssText);
  }
  
  var aStyles  = strStyles.split(";");
  var strStyle = "";
  var strEval  = "";
  var strEvals = "";
  for(var n=0;n<aStyles.length;n++){
    strStyle = styleAdjustKind_str( aStyles[n].split(":")[0] );
    strValue = trim_str           ( aStyles[n].split(":")[1] );
    if(strStyle!=""){
      strEval="el.style."+strStyle+"=\""+(bClean?"":strValue)+"\"";
      debugMsg(strEval);
      eval(strEval);
      debugMsg("OK");
    }
    strEvals+=strEval+"\n";
  }
  
  funcCallerNameOUT();
}

function elStyle(strElId,strStyle,el){
  funcCallerNameIN(strElId+","+strStyle+","+el);
  
    if(!el)
      el=document.getElementById(strElId)
    if(!el)
      exitMsg("invalid element id \""+strElId+"\"");
  
  styleParseSet(el,strStyle);

  funcCallerNameOUT();
}

function in10_b(varCompare,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9){
  var a = new Array();
  var v = null;
  for(var n=0;n<10;n++){
    eval("v=v"+n);
    
    if(!v)
      break;
    
    a.push(v);
  }
  
  return in_b(varCompare,a);
}

function in_b(varCompare,astrVarsValues){ //usage: in_b("cmpThis",new Array("a","b","cmpThis"))
  funcCallerNameIN(""+varCompare+"{"+astrVarsValues.join(",")+"}");

  for(var n=0;n<astrVarsValues.length;n++){
    //if(new String(astrVarsValues[n]) == new String(varCompare)) //not work!
    if(""+astrVarsValues[n] == ""+varCompare){
      funcCallerNameOUT("true");
      return true
    }
  }

  funcCallerNameOUT("false");
  return false
}

function tableColumnRemove(strElId,el){
  if(!el)
    el=document.getElementById(strElId);
  if(!el)
    exitMsg("invalid element id \""+strElId+"\"");
  
  while(el.tagName!="TD"){
    el=el.parentNode;
  }
  
  var elTR   =el  .parentNode;
  
  elTR.removeChild(el);
}

function elShow(strElId,bShow,el){
  funcCallerNameIN(strElId+","+bShow+","+el);

  if(!el)
    el=document.getElementById(strElId)
  if(!el)
    exitMsg("invalid element id \""+strElId+"\"");
  
  if( in_b("WTCidAreaContentBottom",new Array(strElId,el.id)) ){ //specific case
    //TD>TR>TBODY>TABLE>TD
    el=el.parentNode;
    while(el.tagName!="TD"){
      el=el.parentNode;
    }
    
    if(!el)
      exitMsg("unable to find parent TD for \""+strElId+"\"");
  }
  
  /*
  if(strElId=="WTCidAreaTop" || strElId=="WTCidAreaContentTop"){
    //default is visible
    //         TD TR         TBODY                  TD TR          (remove the row)
    if(!bShow) el.parentNode.parentNode.removeChild(el.parentNode);
    //if(!bShow) el.parentNode.parentNode.parentNode.deleteRow(0);
  }else 
  */
  el.style.display=(bShow?"":"none");

  funcCallerNameOUT();
}

function hideTD(varEvent){
  var el=(varEvent?getEventSource(varEvent):src);
  if(!el)
    exitMsg("invalid el");
  
  while(el.tagName!="TD"){
    el=el.parentNode;
  }
  
  if(!el)
    exitMsg("unable to find parent TD");

  elShow(null,false,el);
}

function hideMe(varEvent,src){
  var source=(varEvent?getEventSource(varEvent):src);
  if(!source)
    exitMsg("invalid source");
  elShow(null,false,source);
}

function parseInt_n(strNum){
  // works also with hexa values (hexa to int)(hexaToInt)
  strNum=trim_str(strNum);
  var n=parseInt(strNum);
  if( (""+n) == strVal(strNum) )
    return n;
  
  debugMsg("Unable to parse strNum["+strNum+"] to integer.");
  return null;
}

function isInteger_b(strNum){
  return (""+parseInt(strNum)) == strVal(strNum);
}

function IsIE_b(){
  return browserId_b("IE");
}

function frGet_fr(strFrameName){
  return window.frames[strFrameName];
}

function debugMsg   (strMsg,bSkipCallerName,bFirstTime,bHighLight,bNoEscape){
  debugMsg_el(strMsg,bSkipCallerName,bFirstTime,bHighLight,bNoEscape);
}
var _b_debugMsg_FirstTime = true;
function debugMsg_el(strMsg,bSkipCallerName,bFirstTime,bHighLight,bNoEscape){
  if(g_bDEBUG || g_bDEBUG_EntriesLogAlways){
    
    // FirstTime is required to prevent a persistent last line identical to 1st one :/
    if(_b_debugMsg_FirstTime){
      _b_debugMsg_FirstTime=false;
      debugMsg_el("",true,true);
    }
    
    var strFuncCallerName = ( bSkipCallerName ? "" : callerFuncName_str(debugMsg.caller)+": " );
    
    strMsg=g_nDebugEntryCount+": "+strFuncCallerName+strMsg.replace(/\n/g,"");
    g_nDebugEntryCount++;
    
    var strMsgOk = (bNoEscape?strMsg:escapeToHTML_str(strMsg));
    
    var elTemp = frGet_fr("WTCiframenameDebug").document.getElementById("WTCtxtTemp");
    if(bHighLight)
      elStyle(null,"background-color: rgb(243, 51, 36);",elTemp);
    elTemp.innerHTML=(bFirstTime?"":strMsgOk+"<br>");
    elTemp.parentNode.appendChild(elTemp.parentNode.firstChild.cloneNode(true));
    
    g_IFrameDEBUG.scrollBy(0,100); //always show the last entries.
    
    return elTemp; //should be the new node created with cloneNode()
  }
  
  return null;
}

function undefined_str(){
  return (g_strBrowserNameShort=="IE" ? "UNDEFINED" : "undefined");
}

function callerFuncName_str(varCaller){
  if(!varCaller)return "{null caller}";
  return varCaller.toString().replace(/\n/g,"").split("{")[0];
}

function exit(){
  if(g_bDEBUG)alert("CALLER TO exit():\n"+callerFuncName_str(exit.caller));
  // btw, this mess the javascript_console :-/, filter out by ignoring entries with "varForceErrorToExitOOOOOOOOOO"
  var varForceErrorToExitOOOOOOOOOO=null; //ending 'OOOOOOOOOO' is a 'visual' highlight :)
  varForceErrorToExitOOOOOOOOOO.dummy; // illegal instruction that will abort (exit) javascript execution :-/
}

function exitMsg(strMsg,bVisitorsCanSeeThePopup){
  g_bForceExit=true;
  clearIntervals();
  if(strMsg){ // if 'undefined' does a silent 'exit' (error), only readable at javaconsole
    var str=
      "Caller: "+callerFuncName_str(exitMsg.caller)+"\n"+//.toString().replace(/\n/g,"").split("{")[0]+"\n"+
      "Error: "+strMsg;
    debugMsg(str,false,false,true);
    if(g_bDEBUGexitMsgPopup || bVisitorsCanSeeThePopup)
      alert(str);
  }
  exit();
}

function getEventSource(varEvent){
  //Compatibility Function
  if(!varEvent)varEvent=window.event;
  if(!varEvent){
    exitMsg("Unable to dethermine valid 'event' variable");
  }
  // Mozilla(s)
  eventSource=varEvent.target;
  if(eventSource) return eventSource;
  // Internet Explorer
  eventSource=varEvent.srcElement;
  if(eventSource) return eventSource;

  exitMsg("Unable to dethermine valid 'eventSource' variable, may be a browser limitation.\n"+
    "Try browsing homepage in Plain HTML mode: menu.html",true);
}

function findChildRecursive_source(source,strTagName){
  if(!source)
    exitMsg("invalid null source");
  if(!strTagName || strTagName=="")
    exitMsg("invalid strTagName");

  var nCurrent=0;
  var aChildNodes=source.childNodes;
  var sourceChildCurrent=null;
  var sourceChildTemp=null;
  while(aChildNodes[nCurrent]){
    sourceChildCurrent=aChildNodes[nCurrent];
    if(sourceChildCurrent.tagName == strVal(strTagName)){
      break;
    }
    if(sourceChildCurrent.childNodes[0]){
      sourceChildTemp=findChildRecursive_source(sourceChildCurrent,strTagName);
      if(sourceChildTemp){
        sourceChildCurrent=sourceChildTemp;
        break;
      }
    }
    // if last child is not the one, stop.
    if(nCurrent == aChildNodes.length-1){
      return null;
    }
    nCurrent++;
  }

  return sourceChildCurrent;
}

function findChild(source,varTagName,nIndex){
  if(!nIndex)nIndex=0;

  var aChildNodes=source.childNodes;

  var nNodeCount=aChildNodes.length;

  var nCountIndex=0;
  for(var nCurrent=0;nCurrent<nNodeCount;nCurrent++){
    var sourceChild=aChildNodes[nCurrent];

    if( !sourceChild )
      exitMsg("child node invalid variable");

    if( sourceChild.tagName == varTagName ){
      if( nIndex == nCountIndex )
        break;
      nCountIndex++;
    }
  }

  if( nIndex > nCountIndex )
    return null;

  return sourceChild;
}

function getTDUrlLink_str(sourceTD,bOnlyFilename){
  funcCallerNameIN();

  // IE 'bug?' workaround, happens when menu text is selected with mouse
  if(IsIE_b() && !sourceTD.WTCstrLink) {
    return ""; //exit();
  }
  
  var strLink = bOnlyFilename ? sourceTD.WTCstrLink.split("/").reverse()[0] : sourceTD.WTCstrLink;

  funcCallerNameOUT();
  return strLink;
}

function getMenuItemUrlLink_str(sourceTBODY,nIndex){
  funcCallerNameIN();

  var sourceTR    = findChild(sourceTBODY,"TR"   ,nIndex);if(!sourceTR   )return undefined_str(); //"undefined";
  var sourceTD    = findChild(sourceTR   ,"TD"          );if(!sourceTD   )return undefined_str(); //"undefined";

  g_sourceTD_MenuItem = sourceTD;

  var strLink = getTDUrlLink_str(sourceTD);

  funcCallerNameOUT();
  return strLink;
}

function findTD(source){
  funcCallerNameIN(source);
  if(!source)return null;

  if( (source.tagName == "TR") || (source.tagName == "TABLE") )
    return null;

  var astrTags = new Array()
  while(source){
    //astrTags.push(source.tagName)
    if(source.tagName == "TD")
      break;
    source=source.parentNode;
  }
  if(!source)
    exitMsg("HTML code miss TD tag ["+astrTags.join("/")+"]?");

  funcCallerNameOUT();
  return source;
}

function getTD(varEvent){
 funcCallerNameIN();
 var source = findTD( getEventSource(varEvent) );
 funcCallerNameOUT();
 return source;
}

function submenuIdGet_str(str){
  str = str.split(":").join("");
  return str;
}

function matchId_b(strVar,strId,nId){
  var astr = strVar.split(":");
  
  if( strVal(astr[0]) == strVal(strId) ){
    if(!nId){
      return true;
    }else{
      if( astr[1] == nId)
        return true;
    }
  }
  
  return false;
}

function WTCeventMenuItemMouseOver(varEvent){ 
  clearTimeout(g_timeoutAreaContentMouseOverOut);

  if(g_bLoadingLink)return;
  funcCallerNameIN();

  //divDebug(g_nCountTmp++);
  var sourceTD=getTD(varEvent);
  if(!sourceTD)return null;

  sourceTD.style.cursor='default'

  /*
  if( matchId_b(sourceTD.id,"WTCsubmenu") ){
    submenuShow(sourceTD);
    return;
  }
  */
  
  // Highlight
  if(sourceTD.WTCbHighlightBypass)
    return;
 
  window.status=sourceTD.WTCstrLink;
  
  if(sourceTD == g_sourceTDCurrentPageLink)return;

  sourceTD.style.color          =g_strMenuHighlightColorFg;
  sourceTD.style.backgroundColor=g_strMenuHighlightColorBg;
/*
  if(sourceTD.style.backgroundColor != g_strMenuHighlightColorBg){
    g_nTableCellBackgroundColorHoverBkp=sourceTD.style.backgroundColor;
    sourceTD.style.backgroundColor=g_strMenuHighlightColorBg;
  }
*/
  funcCallerNameOUT();
} 

function WTCeventMenuItemMouseOut(varEvent){ 
  if(g_bMenuFloating){
    g_timeoutAreaContentMouseOverOut=setTimeout("menuExpandShrink(false)",g_nMenuTimeBeforeShrink);
  }

  if(g_bLoadingLink)return;
  funcCallerNameIN();

//  if(g_nTableCellBackgroundColorHoverBkp){
  var sourceTD=getTD(varEvent);
  if(!sourceTD)return null;

  window.status="";
  
  /*
  if( matchId_b(sourceTD.id,"WTCsubmenu") ){
    submenuHide(sourceTD);
    return;
  }
  */
  
  // Highlight
  if(sourceTD.WTCbHighlightBypass)
    return null;
  
  if(sourceTD == g_sourceTDCurrentPageLink)return;

  sourceTD.style.color          =sourceTD.WTCnFgColorBkp;
  sourceTD.style.backgroundColor=sourceTD.WTCnBgColorBkp;
//    sourceTD.style.backgroundColor=g_nTableCellBackgroundColorHoverBkp;
//    g_nTableCellBackgroundColorHoverBkp=null;
//  }
  funcCallerNameOUT();
}

function funcCallerNameIN(_strExtra){
  // DEBUG Pourpose: use at beggining of other functions 
  if(!g_bDEBUG_EntriesLogAlways){
    if(!g_bDEBUG)
      return;
  }

  var strExtra=new String(_strExtra);
  if(_strExtra)
    strExtra="["+strExtra+"]";
  else
    strExtra="";

  var strFuncCallerName = funcCallerNameIN.caller.toString().replace(/\n/g,"").split("{")[0];

/*
  var strLast = g_astrFuncCallerName[g_astrFuncCallerName.length-1];
  if( strLast == strFuncCallerName ){
    divDebug(strLast+" OK");
    g_astrFuncCallerName.pop();
    return;
  }
 
  g_astrFuncCallerName.push(strFuncCallerName);
*/
  debugMsg(strFuncCallerName+strExtra+" try...",true);
  return;
}

function funcCallerNameOUT(_strExtra){
  // DEBUG Pourpose: use at end of other functions 
  if(!g_bDEBUG_EntriesLogAlways){
    if(!g_bDEBUG)
      return;
  }
  
  var strExtra=new String(_strExtra);
  if(_strExtra)
    strExtra="["+strExtra+"]";
  else
    strExtra="";

  var strFuncCallerName = funcCallerNameOUT.caller.toString().replace(/\n/g,"").split("{")[0];

  debugMsg(strFuncCallerName+strExtra+" OK",true);
  return;
}

function setIFrameDataURL_b(strURL){
  funcCallerNameIN(strURL);
  
  var strLocation = new String(g_IFrameData.location); //(new String(g_IFrameData.location)).split("?")[0];
  strLocation = strLocation.split("/").reverse()[0]; //match ending of location
  if(strVal(strLocation) == strVal(strURL) && g_sourceTDCurrentPageLink)
    return true;

  // Content homepages must have: <body onLoad="parent.WTCloadContent()" ...> that will automatically execute after replace() 'thread?'
  // Only after javascript event complete execution, strURL will be loaded.
  // This means that only the last call to replace() will be loaded.
  g_IFrameData.location.replace(strURL) ;
  g_bAreaContentLoaded = false;
  g_strIFrameDataURL = strURL;
  document.getElementById("WTCdivIFrameDataURL").innerHTML=g_strIFrameDataURL;

  funcCallerNameOUT(strURL);
  return false;
}

function loadIFrameDataFillIdWhere_1_b(strIdWhere,strIFrameDataIdValidate,strMsg,bCleanDivValidateInnerHTML){
  funcCallerNameIN(strIdWhere+","+strIFrameDataIdValidate+","+strMsg+","+bCleanDivValidateInnerHTML);

  //validation, ensure .html have been loaded at frameData
  if( strIFrameDataIdValidate && !g_IFrameData.document.getElementById(strIFrameDataIdValidate) ){
    exitMsg(strMsg+": PROBLEM: URL["+g_strIFrameDataURL+"] validation["+strIFrameDataIdValidate+"] FAILED!",true);
  }

  funcCallerNameOUT(strMsg);
  return true;
}

function findElement_el(elBase,strTagName,strEvalTrue){
  var aElement = elBase.getElementsByTagName(strTagName);
  for(var n=0; n<aElement.length; n++){
    if(eval("aElement[n]"+strEvalTrue))
      return aElement[n];
  }
}

function bodyToStyle(windowSrc,elTarget){
    elTarget.style.color           = windowSrc.document.body.text;
    elTarget.style.backgroundColor = windowSrc.document.body.bgColor;
    elTarget.style.backgroundImage = 'url("'+windowSrc.document.body.background+'")';
    //elTarget.style.active          = windowSrc.document.body.aLink;
    //elTarget.style.link            = windowSrc.document.body.link;
    //elTarget.style.visited         = windowSrc.document.body.vLink;
    elStyle(null,windowSrc.document.body.style.cssText,elTarget);
}

function loadIFrameDataFillIdWhere_2_b(strIdWhere,strIFrameDataIdValidate,strMsg,bCleanDivValidateInnerHTML){
  funcCallerNameIN(strIdWhere+","+strIFrameDataIdValidate+","+strMsg+","+bCleanDivValidateInnerHTML);

  var sourceWhere=document.getElementById(strIdWhere);
  if(sourceWhere){
    var srcDivData = g_IFrameData.document.getElementById("WTCdivData");
    sourceWhere.innerHTML = (srcDivData ? srcDivData : g_IFrameData.document.body).innerHTML;
    bodyToStyle(g_IFrameData,sourceWhere);
  }else{
    exitMsg("strIdWhere ["+strIdWhere+"] not found!");
  }

  var srcDivValidate = null;
  if(strIFrameDataIdValidate)
    srcDivValidate = document.getElementById(strIFrameDataIdValidate);
  if(srcDivValidate && bCleanDivValidateInnerHTML){
    var srcDivValidate = document.getElementById(strIFrameDataIdValidate);
    // If user specified a region to use as data with WTCdivData, the validation div will probably have already been excluded.
    if(srcDivValidate){ 
      srcDivValidate.innerHTML='';
      if(g_strBrowserNameShort=="IE"){
        elShow(null,false,srcDivValidate)
      }
    }
  }

  funcCallerNameOUT(strMsg);
  return true;
}

function shortTitleURL_str(strURL){
  var nHalf=30;
  if(strURL.length > nHalf*2)
    return strURL.substr(0,nHalf)+"..."+strURL.substr(strURL.length-nHalf,strURL.length-1);

  return strURL;
}

function intToHexa_str(n,nSize){
  funcCallerNameIN(n);
  
  var nValue=n; //parseInt_n(n);
  
  var strHexa="";
  var strHexaSymb="0123456789ABCDEF";
  
  while(nValue>0){
    nRem=nValue%16;
    strHexa=strHexaSymb.charAt(nRem)+strHexa;
    nValue-=nRem;
    //nValue=Math.floor(nValue/16);
    nValue=nValue/16; //floor should not be needed.
  }
  
  var nDiff=nSize-strHexa.length;
  if( nDiff > 0 ){
    while(nDiff>0){
      strHexa="0"+strHexa;
      nDiff--;
    }
  }
  
  return "0x"+strHexa;
}

function intToRGB_str(n){
  var strRet=hexaStrToRGB_str(intToHexa_str(n,6));
  return strRet;
}

function RGBorCSStoArray_an(strRGBCSS){
  var an = new Array();
  
  var nR=0;     var nG=0;     var nB=0;
  an.push(nR);  an.push(nG);  an.push(nB);

  if(!strRGBCSS || strRGBCSS==""){
    debugMsg("invalid strRGBCSS");
    return an;
  }

  strRGBCSS=trim_str(strRGBCSS);
  if(strRGBCSS.charAt(0)=="#"){
    nR=parseInt_n(strRGBCSS.substr(1,2));
    nG=parseInt_n(strRGBCSS.substr(3,2));
    nB=parseInt_n(strRGBCSS.substr(5,2));
  }else{
    if(strRGBCSS.substr(0,4).toLowerCase() != "rgb("){
      debugMsg("invalid strRGBCSS["+strRGBCSS+"]");
      return an;
    }
    strRGBCSS=strRGBCSS.substr(4); //removes "rgb("
    strRGBCSS=strRGBCSS.substr(0,strRGBCSS.length-1); //removes ")"
    var astr = strRGBCSS.split(",");
    nR=parseInt_n(astr[0]);
    nG=parseInt_n(astr[1]);
    nB=parseInt_n(astr[2]);
  }
  
  an[0]=nR;  an[1]=nG;  an[2]=nB;
  
  return an;
}

function RGBnegative_str(strRGB){
  var an=RGBorCSStoArray_an(strRGB);
  return "rgb("+ (255-an[0]) +","+ (255-an[1]) +","+ (255-an[2]) +")";
}

function RGBbestContrast_str(strRGB){
  var an=RGBorCSStoArray_an(strRGB);
  
  var nDist   = 100;
  var nMiddle = 255/2;
  var nBegin  = nDist;
  var nEnd    = 255-nDist;
  var nAddSub = nEnd-nBegin;
  
  var nNR = 255 - an[0];
  if(an[0] > nBegin  && an[0] <= nMiddle) nNR+=nAddSub;
  if(an[0] > nMiddle && an[0] <  nEnd   ) nNR-=nAddSub;

  var nNG = 255 - an[1];
  if(an[1] > nBegin  && an[1] <= nMiddle) nNG+=nAddSub;
  if(an[1] > nMiddle && an[1] <  nEnd   ) nNG-=nAddSub;

  var nNB = 255 - an[2];
  if(an[2] > nBegin  && an[2] <= nMiddle) nNB+=nAddSub;
  if(an[2] > nMiddle && an[2] <  nEnd   ) nNB-=nAddSub;

  return "rgb("+nNR+","+nNG+","+nNB+")";
}

function RGBtoCSS_str(strRGB){
  funcCallerNameIN(strRGB);
  if(!strRGB || strRGB==""){
    debugMsg("invalid strRGB");
    return "#000000";
  }
  strRGB=trim_str(strRGB);
  if(strRGB.charAt(0)=="#"){
    debugMsg("already CSS");
    return strRGB;
  }
  if(strRGB.substr(0,4).toLowerCase() != "rgb("){
    debugMsg("invalid strRGB["+strRGB+"]");
    return "#000000";
  }
  strRGB=strRGB.substr(4); //removes "rgb("
  strRGB=strRGB.substr(0,strRGB.length-1); //removes ")"

  // eval R*G*B decimal values multiplied. removes 0x from hexa.
  var astrRGB=strRGB.split(",");
  var nValue=parseInt(astrRGB[0])*256*256 + parseInt(astrRGB[1])*256 + parseInt(astrRGB[2]);
  var str = "#"+intToHexa_str(nValue,6).substr(2);
  funcCallerNameOUT(str);
  return str;
}

function hexaStrToRGB_str(strHexa){ //ex.: "#FF3D41" "0xAB576F" "#F3D" "0x3FC"
  funcCallerNameIN(strHexa);
  
  var str = trim_str(strHexa);
  
  if(str.charAt(0) =="#")
    str=str.substr(1); //CSS
  else if(str.substr(0,2)=="0x")
    str=str.substr(2); //Hexa
  else{
    debugMsg("invalid hexa string: "+str);
    return "";
  }
  
  if( !in_b(str.length,new Array(3,6)) ){ //str.length!=3 && str.length!=6){ 
    debugMsg("invalid length: "+str.length+"["+str+"]");
    return ""; //invalid
  }
  var nSize=str.length/3;
  var strRet="rgb("+
    parseInt(str.substr(0,nSize),16)+","+
    parseInt(str.substr(2,nSize),16)+","+
    parseInt(str.substr(4,nSize),16)+")";
  
  funcCallerNameOUT(strRet);
  return strRet;
}

function intToHexaFF_str(n){ //0-255
  funcCallerNameIN(n);
  
  if(!n)
    return "0x00";
  if(parseInt_n(n)==null)
    return "0x00";
  if(n>255)
    return "0xFF";
  if(n<0)
    return "0x00";
  
  var strHexAlg="0123456789ABCDEF";
  var nPosHigh=Math.floor(n/16);
  var strRet="0x"+strHexAlg.charAt(nPosHigh)+strHexAlg.charAt(n%16);
  
  funcCallerNameOUT(strRet+","+n/16);
  return strRet;
}

function debugMode(bDebugMode){
  g_bDEBUG=bDebugMode;
}

function titleColor_str(strColor){
  return strColor+" == "+(strColor=="" ? "" : RGBtoCSS_str(strColor));
}

function WTCeventColorClick(event,elTD){
  if(!elTD && !event)return; //skip in case nothing selected
  
  var el = (elTD ? elTD : getTD(event));
  
  var elColorCurrent=document.getElementById("WTCidColorCurrent");
  if(elColorCurrent){
    //elColorCurrent.style.color          =el.style.color;
    elColorCurrent.style.backgroundColor=el.style.backgroundColor;
    document.getElementById("WTCidColorCurrentValue").innerHTML=titleColor_str(el.style.backgroundColor); //el.style.backgroundColor+"/"+RGBtoCSS_str(el.style.backgroundColor);
  }

  // clean previous
  var elPrev = g_eltdColorSelected;
  g_eltdColorSelected = el;
  if(elPrev && elPrev != g_eltdColorSelected)
    WTCeventColorOut(null,elPrev);
}

function WTCeventColorOver(event,elTD){
  if(!elTD && !event)return; //skip in case nothing selected
    
  var el = (elTD ? elTD : getTD(event));
  
  el.innerHTML="&oplus;";
  
  if(!el.WTCnegativeColor)
    el.WTCnegativeColor=RGBbestContrast_str(el.style.color);
  
  el.style.color=el.WTCnegativeColor;
}

function WTCeventColorOut(event,elTD){
  if(!elTD && !event)return; //skip in case nothing selected
    
  var el = (elTD ? elTD : getTD(event));
  
  if(el == g_eltdColorSelected){
    el.innerHTML="&otimes;";
    return;
  }
  
  el.innerHTML="__";
  el.style.color=el.style.backgroundColor;
}

function tableColors_str(nNumberOfColorsToShow,nColsForce){
  if(g_atableColors){
    // if not changed, return stored table. faster :)
    if(g_atableColors[0]==nNumberOfColorsToShow)
      if(g_atableColors[1]==nColsForce)
        return g_atableColors[2];
  }

  g_atableColors = new Array();

  g_atableColors.push(nNumberOfColorsToShow);
  g_atableColors.push(nColsForce);

  funcCallerNameIN();
  
  if(!nNumberOfColorsToShow)
    nNumberOfColorsToShow=20;
  var nColorMaxValue=0xFFFFFF;
  var nStep=Math.floor(nColorMaxValue/nNumberOfColorsToShow);
  
  var strTable='<table border="0" cellpadding="0" cellspacing="0" onclick="WTCeventColorClick(event)" onmouseover="WTCeventColorOver(event)" onmouseout="WTCeventColorOut(event)" style="cursor: default; text-align: center; vertical-align: middle;"><tbody>';

  var anColor=new Array();
  //for(var n=0;n<nColorMaxValue;n+=nStep){
  nColor=0;
  for(var n=0;n<nNumberOfColorsToShow;n++){
    if(n==nNumberOfColorsToShow-1)
      nColor=0xFFFFFF;
    anColor.push(nColor);
    nColor+=nStep;
  }

  var nCols=0;
  if(!nColsForce){
    //empty items to form a perfect square
    var nRemainder=anColor.length%nNumberOfColorsToShow;
    for(var n=0;n<nRemainder;n++){
      anColor.push();
    }
    nCols=Math.floor( anColor.length/Math.sqrt(nNumberOfColorsToShow) );
  }else{
    nCols=nColsForce
  }
  
//alert(nCols+"/"+nStep+"/"+anColor.length+"/"+nRemainder+"/"+nColorMaxValue);  
  
  var bOpenTR=false;
  var nColCount=0;
  var strColor="";
  for(var n=0;n<anColor.length;n++){
    if(nColCount==0){
      strTable+="<tr>";
      bOpenTR=true;
    }
    
    if(anColor[n]!=null){
      strColor=intToRGB_str(anColor[n]);
      strTable+='<td title="'+titleColor_str(strColor)+'" style="background-color: '+strColor+'; color: '+strColor+'; ">__</td>';
//      strTable+="<td>"+hexaStrToRGB_str(intToHexa_str(anColor[n]))+"</td>";
    }else{
      strTable+="<td></td>";
    }
    
    if(nColCount==nCols-1){
      strTable+="</tr>";
      bOpenTR=false;
    }
    
    nColCount++;
    
    if(nColCount>=nCols){
      nColCount=0;
    }
  }
  if(bOpenTR) //safety
    strTable+="</tr>"
  strTable+"</table></tbody>";
  
  strTable+='<table border="1" cellpadding="0" cellspacing="0"><tbody><tr>'+
    '<td id="WTCidColorCurrent">'+
      '<span style="color: rgb(255, 255, 255);">Current</span>'+
      '<span style="color: rgb(0,0,0);">Color</span></td>'+
    '<td id="WTCidColorCurrentValue" style="color: rgb(255, 255, 255); background-color: rgb(0,0,0);">'+
      '_</td>'+
    '</tr></tbody></table>';
  
  g_atableColors.push(strTable);

  funcCallerNameOUT();
  return strTable;
}

function adjustTitleColor_str(strTitle,strForeBack,strColor){
  funcCallerNameIN(strTitle+","+strForeBack+","+strColor);

  var strFB=strForeBack.charAt(0); //f or b
  var strToken="   <>   "
  var astr=strTitle.split(strToken);

  //adjust array size
  if(astr.length==1){
    if(strTitle.charAt(1)=="f" && strFB=="b"){
      astr.push("");
    }
    if(strTitle.charAt(1)=="b" && strFB=="f"){
      astr.push("");
      astr.reverse();
    }
  }
  var n=0;
  debugMsg("astr.length="+astr.length);
  if(astr.length==2){
    if(strFB=="b"){ //(f) ... (b) ...
      n=1;
    }
  }
  astr[n]="("+strFB+") "+titleColor_str(strColor);
  
  funcCallerNameOUT();
  return astr.join(strToken);
}

function variableSetColor(event){ //onclick
  funcCallerNameIN()
  var elTD=getTD(event);
  if(elTD){
    var elToSet       =document.getElementById(elTD.WTCsetToId);
    var elColorCurrent=document.getElementById("WTCidColorCurrent");
    var strForeBack=(elTD.WTCforeBack=="fore"?"color":"backgroundColor");
    debugMsg(elTD.WTCsetToId+","+elTD.WTCforeBack+","+elColorCurrent+","+elColorCurrent.style.backgroundColor+","+elTD.WTCevalVarName);
//alert(elTD.WTCsetToId+","+elTD.WTCforeBack+","+elColorCurrent+","+elColorCurrent.style.backgroundColor+","+elTD.WTCevalVarName);
    if(elToSet && elColorCurrent){
      // show color
      eval("elToSet.style."+strForeBack+"=elColorCurrent.style.backgroundColor");
      
      // adjust title
      elToSet.title=adjustTitleColor_str(elToSet.title,elTD.WTCforeBack,elColorCurrent.style.backgroundColor);
      
      // set variable
      eval(elTD.WTCevalVarName+"=elColorCurrent.style.backgroundColor");
      g_bMenuColorsUserSet=true; //one change will allow saving of all
      cookieSave();
      ColorSchemeShow();
    }
  }
  funcCallerNameOUT()
}

function variableShowColorAsTable_str(evalVarNameFg,evalVarNameBg,strHTMLDescription){
  g_nVariableShowColorAsTableIDadd++;
  funcCallerNameIN(g_nVariableShowColorAsTableIDadd+","+evalVarNameFg+"="+eval(evalVarNameFg)+","+evalVarNameBg+"="+eval(evalVarNameBg));
  if(!evalVarNameFg && !evalVarNameBg){
    exitMsg("var Fg or Bg must not be null.");
  }
  // the middle underline is important to distinguish from the other cells IDs
  var strIdShow="WTC_"+g_nVariableShowColorAsTableIDadd+"_"+(evalVarNameFg?evalVarNameFg:"")+"_"+(evalVarNameBg?evalVarNameBg:"");
  //var strColorFg=(evalVarNameFg?eval(evalVarNameFg):"");
  //var strColorBg=(evalVarNameBg?eval(evalVarNameBg):"");
  var strIdFg=(evalVarNameFg ? "WTC_"+g_nVariableShowColorAsTableIDadd+"_"+evalVarNameFg : null);
  var strIdBg=(evalVarNameBg ? "WTC_"+g_nVariableShowColorAsTableIDadd+"_"+evalVarNameBg : null);
  var strTable=
    "<tt><table border=\"1\"><tbody><tr>"+
      (evalVarNameFg?
      "<td id=\""+strIdFg+"\" title=\"Click to set Foreground to chosen color.\" "+
        "onclick=\"variableSetColor(event)\" style=\"color:rgb(255,255,255)\">":"<td style=\"color:rgb(0,0,0)\">")+
        "Fg</td>"+
      (evalVarNameBg?
      "<td id=\""+strIdBg+"\" title=\"Click to set Background to chosen color.\" "+
        "onclick=\"variableSetColor(event)\" style=\"color:rgb(255,255,255)\">":"<td style=\"color:rgb(0,0,0)\">")+
        "Bg</td>"+
      "<td id=\""+strIdShow+"\" "+
        "style=\""+(evalVarNameFg?"color:            "+eval(evalVarNameFg)+"; ":"")+
                   (evalVarNameBg?"background-color: "+eval(evalVarNameBg)+"; ":"")+"\">"+
        strHTMLDescription+"</td>"+
    "</tr></tbody></table></tt>";
  
  executeArrayTimeout1("_variableShowColorAsTableContinue("+
    (evalVarNameFg ? "\""+evalVarNameFg+"\",\""+strIdFg+"\"" : "null,null")+","+
    (evalVarNameBg ? "\""+evalVarNameBg+"\",\""+strIdBg+"\"" : "null,null")+","+
    "\""+strIdShow+"\")");
  
  funcCallerNameOUT();
  return strTable;
}

function _variableShowColorAsTableContinue(evalVarNameFg,idFg,evalVarNameBg,idBg,strIdShow){
  // setup TD elements internally into javascript memory (create variables)
  if(evalVarNameFg && evalVarNameFg!=""){
    var elFg=elGet_el(idFg);
    if(!elFg)exitMsg("invalid el ["+idFg+"]");
    elFg.WTCsetToId    =strIdShow    ;
    elFg.WTCforeBack   ="fore"       ;
    elFg.WTCevalVarName=evalVarNameFg;

    var el = elGet_el(strIdShow);
    if(!el)exitMsg("invalid el ["+strIdShow+"]");
    el.title=adjustTitleColor_str(el.title,"fore",el.style.color);
  }
  
  if(evalVarNameBg && evalVarNameBg!=""){
    var elBg=elGet_el(idBg);
    if(!elBg)exitMsg("invalid el ["+idBg+"]");
    elBg.WTCsetToId    =strIdShow    ;
    elBg.WTCforeBack   ="back"       ;
    elBg.WTCevalVarName=evalVarNameBg;

    var el = elGet_el(strIdShow);
    if(!el)exitMsg("invalid el ["+strIdShow+"]");
    el.title=adjustTitleColor_str(el.title,"back",el.style.backgroundColor);
  }
}

function resetCurrentMenuItem(){
  g_sourceTDCurrentPageLink=null;
  g_bAreaContentIsMainMenuItem=false;
  menuColorsRestore();
  setIFrameDataURL_b("about:blank"); // clears g_IFrameData as content area will be filled up here
}

function isFreeCellArea_b(source){
  while(source && source.id!="WTCidMenuFreeCell"){
    source=source.parentNode;
  }
  return source != null;
}

function tableCellsDivisionLine(source,nBorderSize){
  // Cells division line :)
  if(!nBorderSize)
    nBorderSize=1;
  
  if(nBorderSize != -1)
    source.border=nBorderSize;
  
  if(g_strBrowserNameShort=="IE"){
    source.style.borderCollapse="collapse";
    source.borderColor="rgb(100,100,100)";
    source.frame="hsides";
  }else{
    source.rules="all";
  }
}

function menuWork(){
  funcCallerNameIN();

  // Clean Menu bottom example
  var srcExample=document.getElementById("WTCdivMenuBottomExample");
  if(srcExample)srcExample.innerHTML="";
  
  var source=elGet_el("WTCtableMenu"); //document.getElementById("WTCtableMenu");

  // Adjust table Menu events
  source.onclick    =WTCeventMenuItemClick // "WTCmenuClick(event)";
  source.onmouseover=WTCeventMenuItemMouseOver;
  source.onmouseout =WTCeventMenuItemMouseOut;

  tableCellsDivisionLine(source,-1);

  var sourceTD;
  var sourceA;

  var sourceTDpbj; //powered by javascript
  var sourceTDphl; //plain html

  var strLocalFilePrefix="file://";

  var astrAhref=new Array();
  var strAhref="";
  var strApath="";
  var strAfileName="";

  // Location Path
  var strLocation=(new String(window.location)).split("?")[0];
  // local tests, remove "file://"
  if(strVal(strLocation.substr(0,strLocalFilePrefix.length)) == strVal(strLocalFilePrefix))
    strLocation=strLocation.substr(strLocalFilePrefix.length,strLocation.length);
  var astrLocation=strLocation.split("/");
  astrLocation.pop();
  var strLocationPath=astrLocation.join("/");

  var nBgColorPbj=-1;

  var nBgColorPhl=-1;
  
  var bSubMenu=false;
  var bMenuName=false;
  
  var aTD = source.getElementsByTagName("TD");
  for(var nCurrent=0; nCurrent<aTD.length; nCurrent++){
    sourceTD = aTD[nCurrent];
    
    // will highlight tho store no link
    bSubMenu=false;
    if( matchId_b(sourceTD.id,"WTCsubmenu") )
      bSubMenu=true;
    
    bMenuName=false;
    if( sourceTD.id==g_strMenuItemOptionsId )
      bMenuName=true;
    
    if( sourceTD.id == "WTCidMenuItemForceHighlightBypass" || 
        //matchId_b(sourceTD.id,"WTCsubmenu")                || 
        isFreeCellArea_b(sourceTD) 
    ){
      sourceTD.WTCbHighlightBypass=true;
      continue;
    }
    // only 1st link (only one link per TD)
    sourceA=sourceTD.getElementsByTagName("A")[0];
    if(!sourceA && !bSubMenu && !bMenuName){
      sourceTD.WTCbHighlightBypass=true;
      if(sourceTD.innerHTML==""){
        // Auto adjust blank separator
        if(g_strBrowserNameShort=="IE"){
          sourceTD.innerHTML='<div style="height: 2px;"><small><small><small></small></small></small></div>';
        }else{
          sourceTD.innerHTML='<div style="height: 2px;"></div>';
        }
      }
      continue;
    }else{
      // stored inside TD
      sourceTD.WTCbHighlightBypass=false;
      sourceTD.WTCnFgColorBkp=sourceTD.style.color;
      sourceTD.WTCnBgColorBkp=sourceTD.style.backgroundColor;
      if(!bSubMenu && !bMenuName)
        sourceTD.WTCstrLink       =new String(sourceA.href);
      //sourceTD.title              =shortTitleURL_str(new String(sourceA.href));
      
      g_aTDsource.push(sourceTD);
    }

    if(bSubMenu || bMenuName)
      continue;
    
    strAhref=sourceA.href;
    // local tests, remove "file://"
    if(strVal(strAhref.substr(0,strLocalFilePrefix.length)) == strVal(strLocalFilePrefix))
      strAhref=strAhref.substr(strLocalFilePrefix.length,strAhref.length);
    astrAhref=strAhref.split("/");
    strAfileName=astrAhref.pop();
    strApath=astrAhref.join("/");

    // Is relative?
    if(strVal(strLocationPath) == strVal(strApath)){
      if(sourceTD.id == "WTCidMenuItemForceLoadTop"){ // load top setup by user
        sourceTD.WTCbMenuItemForceLoadTop=true;
      }
      else  // browsing mode: index.html is javascript. menu.html is plain HTML
      if(strAfileName=="index.html" || strAfileName=="menu.html"){
        sourceTD.WTCbMenuItemForceLoadTop=true;
        // BgColor to exchange
        if(strAfileName=="index.html"){
          g_strURLindex = sourceTD.WTCstrLink;
          sourceTDpbj   = sourceTD;
          nBgColorPbj   = sourceTD.style.backgroundColor;
        }
        if(strAfileName=="menu.html"){
          g_strURLmenu = sourceTD.WTCstrLink;
          sourceTDphl  = sourceTD;
          nBgColorPhl  = sourceTD.style.backgroundColor;
        }
      }else{
        sourceTD.WTCbMenuItemForceLoadTop=false;
        sourceA.parentNode.innerHTML=sourceA.innerHTML; // Remove Link property
      }
    }else{
      // Take care of external links
      // url is not relative, default load top
      sourceTD.WTCbMenuItemForceLoadTop=true;
    }

    //// no need for items with enabled <A> links
    //if(sourceTD.WTCbMenuItemForceLoadTop)
    //  sourceTD.title="";
  }

  /*
  // set default hightligh color into pbj browsing mode after both TDs have been found
  if(sourceTDpbj && sourceTDphl){
    sourceTDpbj.style.backgroundColor = nBgColorPhl;
    sourceTDpbj.WTCnBgColorBkp  = sourceTDpbj.style.backgroundColor;

    sourceTDphl.style.backgroundColor = nBgColorPbj;
    sourceTDphl.WTCnBgColorBkp  = sourceTDphl.style.backgroundColor;
  }
  */
  
  if(window.WTCuserFuncAdjustMenu){
    WTCuserFuncAdjustMenu();
  }
  
  funcCallerNameOUT();
}

function menuColorsRestore(){
  for( var nCurrent=0; nCurrent < g_aTDsource.length; nCurrent++ ){
    g_aTDsource[nCurrent].style.color          =g_aTDsource[nCurrent].WTCnFgColorBkp;
    g_aTDsource[nCurrent].style.backgroundColor=g_aTDsource[nCurrent].WTCnBgColorBkp;
  }
}

function SubmenuClose(bCleanCurrent){
  if(g_tdSubmenuOpened){
    g_tdSubmenuOpened.style.display="none";
  }
  if(bCleanCurrent)
    g_tdSubmenuOpened = null;
}

function WTCeventMenuItemClick(varEvent,elTD){
  funcCallerNameIN();

  var sourceTD=(elTD ? elTD : getTD(varEvent));
  if(!sourceTD)
    return null;
  
    if(sourceTD.WTCbHighlightBypass)
      return null;
    
    // Load URL
    if(g_sourceTDCurrentPageLink==sourceTD)
      return; //skip current //@@@??? could allow reload?
    
    var bMenuName = sourceTD.id == g_strMenuItemOptionsId;
    
    if( matchId_b(sourceTD.id,"WTCsubmenu") || bMenuName ){
      SubmenuClose();
      
      var elSubmenu = elGet_el(submenuIdGet_str(sourceTD.id));
      //var elSubmenu = elGet_el( (bMenuName ? "WTCsubmenuOptions" : submenuIdGet_str(sourceTD.id)) );
      if( g_tdSubmenuOpened == elSubmenu ){
        //if(g_bMenuFloating){// && bMenuName){
        //  elGet_el("WTCsubmenu:Options").style.display="none";
        //}
        g_tdSubmenuOpened = null;
        menuHighlightCurrentPageLink(); //mostly to clean the menu item that is just being closed
        return;
      }
      //if(g_bMenuFloating && bMenuName){
      //  elGet_el("WTCsubmenu:Options").style.display="";
      //}
      elSubmenu.style.display="";
      g_tdSubmenuOpened = elSubmenu;
      if(!g_bMenuFloating){
        // when menu is docked and all submenus are closed, when a submenu is opened, it increases the height of the menu by the size of the internal submenu, WEIRD...
        if(g_strBrowserNameShort!="IE"){
          executeArrayTimeout1("_tableRefreshTrick(0)");
          executeArrayTimeout1("_tableRefreshTrick(1)");
        }
      }
      return;
    }
    
    if(sourceTD.WTCbMenuItemForceLoadTop){ // load top
      menuHighlightCurrentPageLink();
  //    window.location.replace(sourceTD.WTCstrLink); //load a new URL over current location that is index.html
      window.location.assign(sourceTD.WTCstrLink); //load a new URL over current location that is index.html
    }else{ // relative
      g_bParameterLoadURL = false;
      setIFrameDataURL_b(getTDUrlLink_str(sourceTD,true));
      
      g_sourceTDCurrentPageLink=sourceTD;
      
      g_bLoadingLink=true;
    }

  if(g_bMenuFloating)
    menuExpandShrink(false);

  funcCallerNameOUT();
  // when this function exits, strURL will be loaded
}

function _tableRefreshTrick(n){
  if(n==0){
    document.getElementById("WTCtableMain").style.display="block";
  }else if(n==1){
    document.getElementById("WTCtableMain").style.display="";
  }
}

function menuItemHighlight(strElId,el){
  if(!el)
    el=document.getElementById(strElId);
  
  el.style.color          =g_strMenuCurrentLinkColorFg;
  el.style.backgroundColor=g_strMenuCurrentLinkColorBg;
}

function menuHighlightCurrentPageLink(){
  menuColorsRestore();
  if(g_sourceTDCurrentPageLink)
    menuItemHighlight(null,g_sourceTDCurrentPageLink);
}

function checkBoxReadSet_b(sourceINPUT,bForceMode){
  if(!sourceINPUT)
    exitMsg("null sourceINPUT");

  if(sourceINPUT.tagName != "INPUT"){
    exitMsg("expecting an "+ (sourceINPUT.type!="checkbox"?"checkbox":"") +" input field");
  }

  if(bForceMode==null)
    return sourceINPUT.checked; //read
  else
    return sourceINPUT.checked=bForceMode; //set
}

function WTCeventDebugMode(varEvent){ 
  debugShowElements(checkBoxReadSet_b(getEventSource(varEvent)));
}

function debugBig(str){
  if(!g_bDEBUG_Big)return;

  if(!str){
    str=document.body.innerHTML;
    g_bDEBUG_Big = false; //to happen only once
  }

  var strFuncCallerName = debugBig.caller.toString().replace(/\n/g,"").split("{")[0];

  var w=window.open();
  if(w)
    w.document.write(strFuncCallerName+"<br><br>"+escapeToHTML_str(str));
}

function prepareLoadContent(){
  funcCallerNameIN();

  // prepare load Content
  // Content Start (main)
  g_sourceTDCurrentPageLink=document.getElementById("WTCidMenuItemMain");
  if(!g_sourceTDCurrentPageLink){
    exitMsg("Missing main menu item with id=\"WTCidMenuItemMain\"");
  }
  setIFrameDataURL_b(getTDUrlLink_str(g_sourceTDCurrentPageLink,true)) // -> 'main'.html -> parent.WTCloadContent();

  funcCallerNameOUT();
}

function WTCloadMenu(){
  var astrExecute = new Array();
  astrExecute.push("_WTCloadMenu_1()");
  astrExecute.push("_WTCloadMenu_2()");

  executeArrayTimeout(astrExecute);
}

function _WTCloadMenu_1(){
  refreshGlobals();

  // fill menu area
  loadIFrameDataFillIdWhere_1_b(g_strMenuAreaId,"WTCidValidateTableMenu","Menu",true);
}

function _WTCloadMenu_2(){
  // fill menu area
  loadIFrameDataFillIdWhere_2_b(g_strMenuAreaId,"WTCidValidateTableMenu","Menu",true);

  menuWork();

  if(g_bLoadAreaBottom){
    // prepare load Bottom
    // 1st Content html will be loaded after bottom at WTCloadBottom()
    setIFrameDataURL_b("bottom.html"); // -> bottom.html -> parent.WTCloadBottom()
  }else{
    document.getElementById("WTCidAreaBottom").innerHTML=""; //clean bottom area
    prepareLoadContent();
  }
}

function executeArrayTimeout1(strEval){
  executeArrayTimeout(new Array(strEval));
}

function executeArrayTimeout(astrEval){
  if(astrEval){
    g_astrEval=g_astrEval.concat(astrEval); // add to existing execution list 
    g_timeoutExecuteArrayTimeout = setTimeout("executeArrayTimeout()",0);
    return
  }

  if(g_astrEval.length){
    var strEval=g_astrEval.shift();
    debugMsg("Execute Array Timeout Loop: "+strEval);
    eval(strEval);
  }else{
    return;
  }

  // execute as soon as possible
  g_timeoutExecuteArrayTimeout = setTimeout("executeArrayTimeout()",0);
}

function WTCloadTop(){
  WTCloadTopBottom("Top");
}

function WTCloadContentTop(){
  WTCloadTopBottom("ContentTop");
}

function WTCloadContentBottom(){
  WTCloadTopBottom("ContentBottom");
}

function WTCloadBottom(){
  WTCloadTopBottom("Bottom");
}

function WTCloadTopBottom(str){
  var astrExecute = new Array();
  astrExecute.push("_WTCloadTopBottom_1(\""+str+"\")");
  astrExecute.push("_WTCloadTopBottom_2(\""+str+"\")");

  executeArrayTimeout(astrExecute);
}

function _WTCloadTopBottom_1(str){
  refreshGlobals();

  // fill bottom area
  loadIFrameDataFillIdWhere_1_b("WTCidArea"+str,null,str);
}

function _WTCloadTopBottom_2(str){
  loadIFrameDataFillIdWhere_2_b("WTCidArea"+str,null,str);
  
  prepareLoadContent();
}

function debugAlert(str,bNow){
  g_astrDebug.push("ENTRY: "+str);
  if(bNow){
    alert(g_astrDebug.join("\n"));
    g_astrDebug.splice(0,g_astrDebug.length);
  }
}

function RefreshMenuAndGlobalsBasedOnCurrentContent(){
  var strCurrentLink = (new String(g_IFrameData.location)).split("/").reverse()[0];
  var strIFDataLocation = (new String(g_IFrameData.location));
//    g_sourceTDCurrentPageLink == document.getElementById("WTCidMenuItemMain");
  
  // SetBoolAreaContentIsMainMenuItem
  g_bAreaContentIsMainMenuItem = 
    strCurrentLink == getTDUrlLink_str(document.getElementById("WTCidMenuItemMain"),true);

  for( var nCurrent=0; nCurrent < g_aTDsource.length; nCurrent++ ){
    //debugAlert(strIFDataLocation+" <"+strIFDataLocation.length+"==="+(g_aTDsource[nCurrent].WTCstrLink?g_aTDsource[nCurrent].WTCstrLink.length:0)+"> "+g_aTDsource[nCurrent].WTCstrLink, nCurrent==g_aTDsource.length-1);
    if(strVal(g_aTDsource[nCurrent].WTCstrLink)==strVal(strIFDataLocation)){
      g_sourceTDCurrentPageLink=g_aTDsource[nCurrent];
      menuHighlightCurrentPageLink();
      break;
    }
  }
  
  if(strVal(strCurrentLink) != "WebTemCoPref.html"){
    g_strLastLocation = strCurrentLink.replace(/\//g,"+");
    cookieSave();
  }
  
  g_bAreaContentLoaded = true;
}

function WTCloadContent(bProp){
  // while at IFrameData, some elements must be changed before they are 'copyed' to AreaContent
  if(g_IFrameData.WTCuserFuncAreaContentOnLoadBefore){
    g_IFrameData.WTCuserFuncAreaContentOnLoadBefore();
  }
  
  storeContentDivValidateHTML();
  var astrExecute = new Array();
  astrExecute.push("_WTCloadContent_1()");
  astrExecute.push("_WTCloadContent_2()");
  
  if(bProp){
    g_bSetupColorsToShow=true;
    WebMasterSetupInit();
    astrExecute.push("WTCsetupUserPreferences()");
  }
  
  if(g_strBrowserNameShort!="IE"){
    astrExecute.push("_tableRefreshTrick(0)");
    astrExecute.push("_tableRefreshTrick(1)");
  }
  
  astrExecute.push("RefreshMenuAndGlobalsBasedOnCurrentContent()");

  executeArrayTimeout(astrExecute);
}

function _WTCloadContent_1(){
  refreshGlobals();
  // to easy content homepages adjustment, ignore almost useless WTCidValidateContent
  loadIFrameDataFillIdWhere_1_b("WTCidAreaContent",null/*"WTCidValidateContent"*/,"Content",true);
}

function _WTCloadContent_2(){
  loadIFrameDataFillIdWhere_2_b("WTCidAreaContent","WTCidValidateContent","Content",true);
  if(g_IFrameData.WTCuserFuncAreaContentOnLoadAfter){
    g_IFrameData.WTCuserFuncAreaContentOnLoadAfter();
  }

  menuHighlightCurrentPageLink();
  g_bLoadingLink=false;
  cookieSave(); //current menu item will be starting one next time user load website
}

function storeContentDivValidateHTML(){
  // stores first valid validation div
  if(g_strMainValidateHTMLdata == ""){
    var elIFameValidate = g_IFrameData.document.getElementById("WTCidValidateContent");
    if(elIFameValidate){
      g_strMainValidateHTMLdata = elIFameValidate.innerHTML;
    }
  }
}

function refreshGlobals(){
  Progress("Refresh Globals");
  
  //seems to be needed when the menu or content page is loaded o.O
  var b = g_IFrameDEBUG == null;
  g_IFrameDEBUG  = frGet_fr("WTCiframenameDebug");
  g_IFrameDEBUG.document.body.style.color="rgb(255,255,255)";
  g_IFrameDEBUG.document.body.style.backgroundColor="rgb(85,0,0)";
  if(b){
    g_IFrameDEBUG.document.body.innerHTML=
      '<small>'+
        '<span id="WTCtxtTemp">dummy</span>'+
      '</small>';
  }
  g_IFrameData   = frGet_fr("WTCiframenameData");
}

function removeElement(varWindowFrom,strElementTagName,strElementId){
  var element  = null;
  var aElement = varWindowFrom.document.getElementsByTagName(strElementTagName);
  for(var n=0; n<aElement.length; n++){
    element=aElement[n];
    if(strElementId){
      if(element.id != strElementId)
        continue;
    }
    element.parentNode.removeChild(element);
  }
}

function strIsBlank_b(str){
  if(!str)return true;
  if(trim_str(str)=="")return true;
  return false;
}

function debugShowElements(bShow,bBypassCookieSave){
  g_bDEBUG=bShow;

  elShow("WTCdivIFrameDataTitle",g_bDEBUG);
  elShow("WTCdivIFrameDataURL"  ,g_bDEBUG);
  elShow("WTCiframeData"        ,g_bDEBUG);
  elShow("WTCdivIFrameData"     ,g_bDEBUG);
  elShow("WTCdivDebug"          ,g_bDEBUG);
  
  if(!bBypassCookieSave)
    cookieSave();
}

function cookieReset(strCookieId,bJustClear){
  funcCallerNameIN(strCookieId+","+bJustClear);

  if(!g_bCookieEnabled){
    debugMsg("cookies disabled");
    return;
  }

  if(!strCookieId)
    strCookieId=g_strCookieID;
  
  debugMsg("Reseting cookie.");
  document.cookie=strCookieId+'=';
  if(!bJustClear)
    cookieSave();

  funcCallerNameOUT();
}

function cookieValidate_b(strValue,strType,varMin,varMax){
  funcCallerNameIN(strValue+","+strType+","+varMin+","+varMax);
  
  //bypass empty means 'keep default'
  if(strValue && strValue!=""){
    switch(strType){
      case "bool":
        if(strValue != "0" && strValue != "1"){
          debugMsg("not bool");
          return false;
        }
        break;
      case "int":
        var n=parseInt(strValue);
        if(""+n   != strValue){debugMsg("not int"      );return false;}
        if(varMin && n<varMin){debugMsg("int is less than min"   );return false;}
        if(varMax && n>varMax){debugMsg("int is greater than max");return false;}
        break;
      case "hexa":
        var strHexa="0123456789ABCDEF";
        for(var n=0;n<strValue.length;n++){
          if( !strHexa.match(strValue.charAt(n).toUpperCase()) ){
            debugMsg("not hexa");
            return false;
          }
        }
        break;
      case "str":
        return true;
        break;
      default:
        debugMsg("invalid type");
        return false;
        break;
    }
  }

  funcCallerNameOUT();
  return true;
}

function strVal(str){
  if(!str)return null;
  //return (new String(str)).value;
  return (new String(str)).toString();
}

function cookieRetrive_str(_strCookieId,bOnlyValue){
  funcCallerNameIN(_strCookieId+","+bOnlyValue);
  
  var strCookieId=_strCookieId;
  if(!strCookieId)
    strCookieId=g_strCookieID;
  
  var str=document.cookie;
  var astr=str.split(";");
  var strCookieIdFound="";
  var strCookie="";
  for(var n=0;n<astr.length;n++){
    strCookie=trim_str( astr[n] );
    strCookieIdFound = trim_str( strCookie.split("=")[0] );
    debugMsg('"'+strCookieIdFound+'","'+strCookieId+'"');
    if(strVal(strCookieIdFound)==strVal(strCookieId)){
      funcCallerNameOUT( strCookie );
      if(bOnlyValue){
        var strFullValue=strCookie.substr(strCookieId.length+1); //+1 to skip '=' ex.: 'CookieId='
        debugMsg(strCookieId+","+strCookieId.length+","+strFullValue);
        return strFullValue;
      }else{
        return strCookie;
      }
    }
  }

  funcCallerNameOUT("not found");
  return null;
}

function ColorSchemeSet(strScheme){
  var astr = strScheme.split(".");
  for(var n=0;n<astr.length;n++){
    var strValue=astr[n]; //blank strValue means transparent color
    switch(n){
      case  0: g_strMenuColorBg           ="#"+strValue;break;
      case  1: g_strMenuLinkColorFg       ="#"+strValue;break;
      case  2: g_strMenuLinkColorBg       ="#"+strValue;break;
      case  3: g_strMenuLinkColorAltFg    ="#"+strValue;break;
      case  4: g_strMenuLinkColorAltBg    ="#"+strValue;break;
      case  5: g_strMenuSubmenuColorFg    ="#"+strValue;break;
      case  6: g_strMenuSubmenuColorBg    ="#"+strValue;break;
      case  7: g_strMenuHighlightColorFg  ="#"+strValue;break;
      case  8: g_strMenuHighlightColorBg  ="#"+strValue;break;
      case  9: g_strMenuCurrentLinkColorFg="#"+strValue;break;
      case 10: g_strMenuCurrentLinkColorBg="#"+strValue;break;
      case 11: g_strMenuFreeCellColorFg   ="#"+strValue;break;
      case 12: g_strMenuFreeCellColorBg   ="#"+strValue;break;
      case 13: g_strMenuNameColorFg       ="#"+strValue;break;
      case 14: g_strMenuNameColorBg       ="#"+strValue;break;
    }
  }
}

function ColorSchemeMake_str(){
  var str=
    RGBtoCSS_str(g_strMenuColorBg           ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuLinkColorFg       ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuLinkColorBg       ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuLinkColorAltFg    ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuLinkColorAltBg    ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuSubmenuColorFg    ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuSubmenuColorBg    ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuHighlightColorFg  ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuHighlightColorBg  ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuCurrentLinkColorFg).substr(1)+"."+
    RGBtoCSS_str(g_strMenuCurrentLinkColorBg).substr(1)+"."+
    RGBtoCSS_str(g_strMenuFreeCellColorFg   ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuFreeCellColorBg   ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuNameColorFg       ).substr(1)+"."+
    RGBtoCSS_str(g_strMenuNameColorBg       ).substr(1);
  return str;
}

function cookieVarToIDValue_str(){
  /* Rules: ID from "0" to "9", from "A" to "Z" ex.: 0= C= 3B= 0A2= ...
     never reuse IDs! a removed item will be ignored from old cookie this way.*/
  var str=""+g_strVersion+
    "&0="+(g_strAreaMenu=="left"   ?"0":"1")+
    //"&1="+(g_bAreaTopShow          ?"1":"0")+
    //"&2="+(g_bAreaContentTopShow   ?"1":"0")+
    //"&3="+(g_bAreaContentBottomShow?"1":"0")+
    //"&4="+(g_bAreaBottomShow       ?"1":"0")+
  /*
    "&5="+RGBtoCSS_str(g_strMenuColorBg           ).substr(1) +
    "&6="+RGBtoCSS_str(g_strMenuLinkColorFg    ).substr(1) +
    "&7="+RGBtoCSS_str(g_strMenuLinkColorBg       ).substr(1) +
    "&8="+RGBtoCSS_str(g_strMenuLinkColorBgAlt    ).substr(1) +
    "&9="+RGBtoCSS_str(g_strMenuSubmenuColorFg    ).substr(1) +
    "&A="+RGBtoCSS_str(g_strMenuSubmenuColorBg    ).substr(1) +
    "&B="+RGBtoCSS_str(g_strMenuHighlightColorBg  ).substr(1) +
    "&C="+RGBtoCSS_str(g_strMenuCurrentLinkColorBg).substr(1) +
  */
    "&D="+(g_bMenuFloating         ?"1":"0")+
    "&E="+(g_bMenuFloatingMini     ?"1":"0")+
    "&F="+escape(g_strLastLocation)+
    "&G="+(g_bLastLocationRemember ?"1":"0")+
    "&H="+ColorSchemeMake_str()+
    "&I="+g_nMenuShrinkedTextShowTimesUserAlready+
	"&J="+g_strLanguage+
    "";
  return str;
}

function cookieIDValueSetVar_b(astr){
  var str="";
  var strValue="";
  
  try{
    // previous cookies had not the structure quality from v0.200 on
    if( parseFloat(astr[0]) < 0.200 )
	  return false;
  }catch(e){
    debugMsg("error on converting cookie version ["+astr[0]+"]");
  }
  
  for(var n=1;n<astr.length;n++){
    str=astr[n];
    strValue=str.split("=")[1]
    
    if(strIsBlank_b(strValue))
      continue;
    
    try{
      /* Rules: ID from "0" to "9", from "A" to "Z" ex.: 0= C= 3B= 0A2= ...
         never reuse IDs! a removed item will be ignored from old cookie this way.*/
      switch(str.split("=")[0]){
        case "0": g_strAreaMenu           =(parseInt(strValue)==0?"left":"right"); break;
        //case "1": g_bAreaTopShow          =(strValue == 1); break;
        //case "2": g_bAreaContentTopShow   =(strValue == 1); break;
        //case "3": g_bAreaContentBottomShow=(strValue == 1); break;
        //case "4": g_bAreaBottomShow       =(strValue == 1); break;
        case "D": g_bMenuFloating         =(strValue == 1); break;
        case "E": g_bMenuFloatingMini     =(strValue == 1); break;
        case "F": g_strLastLocation       =unescape(strValue);
        case "G": g_bLastLocationRemember =(strValue == 1); break;
        case "H": ColorSchemeSet(strValue); break;
        case "I": g_nMenuShrinkedTextShowTimesUserAlready = parseInt(strValue)+1;break;
        case "J": g_strLanguage = strValue; break;
        default:
          debugMsg("skipping invalid cookie ID=Value ["+str+"]");
          break;
      }
    }catch(e){
      debugMsg("error on converting cookie ID=Value ["+str+"], skipping this entry");
    }
  }
  return true;
}

function cookieLoad_b(strValidatePasted,_strCookieId,bSkipFixCookie){
  Progress("Load Cookie");

  var nTempDebug=0; //alert(nTempDebug++);
  
  if(!g_bCookieEnabled){
    debugMsg("cookies disabled");
    return true; //return true to bypass any possible messages on loading failure
  }

  funcCallerNameIN(strValidatePasted+","+_strCookieId);

  var strCookieId=g_strCookieID;
  if(_strCookieId && _strCookieId!="")
    strCookieId=_strCookieId;
  
  if(strCookieId!=""){
    try{
      debugMsg("prepare cookie var");
      var bCookiePasted=false;
      var strCookie=cookieRetrive_str(strCookieId,true);
      if(strValidatePasted){
        strCookie=strValidatePasted;
        bCookiePasted=true;
      }
      
      debugMsg("cookie is null?");
      if(!strCookie){
        debugMsg("invalid cookie");
        if(!bCookiePasted)
          if(!bSkipFixCookie)
            cookieReset(strCookieId);
        return false;
      }
      
      debugMsg("cookie to array of values");
      var astr = unescape(strCookie).split("&");
      if( astr.length==0 ){
        if(!bCookiePasted)
          if(!bSkipFixCookie)
            cookieReset(strCookieId);
        return false;
      }
      
      if(!cookieIDValueSetVar_b(astr))
	    cookieReset(strCookieId);
    }catch(e){
      if(!bCookiePasted)
        if(!bSkipFixCookie)
          cookieReset(strCookieId);
      debugMsg("error on interpreting cookie");
      return false;
    }
  }

  funcCallerNameOUT();
  return true;
}

function cookieSave(_strCookieId){
  if(!g_bCookieEnabled){
    debugMsg("cookies disabled");
    return;
  }

  var strCookieId=g_strCookieID;
  if(_strCookieId && _strCookieId!="")
    strCookieId=_strCookieId;
  
  if(strCookieId!=""){
    var strCookie=strCookieId+'='+cookieVarToIDValue_str();
    debugMsg(strCookie);
    
    var dtExpires=new Date();
    dtExpires.setDate(365);
    
    document.cookie=strCookie+"; expires="+dtExpires;
  }
}

function doNothing(){
}

function continueLoading1(){
  //if(g_innerHTMLdocumentation=="")
  //  g_innerHTMLdocumentation = document.getElementById("WTCidAreaContent").innerHTML;

  //setIFrameDataURL_b("about:blank");

  refreshGlobals();
  cookieLoad_b();
  
  
  /*========== AFTER COOKIE ==========*/
  // Adjust DEBUG control checkbox event
  
  // Menu Side
  Progress("Menu Side");
  if(g_strAreaMenu=="left"){
    g_strMenuAreaId="WTCidAreaMenuLeft";
    tableColumnRemove("WTCidAreaMenuRight");
    tableColumnRemove("WTCtdMenuShrinkedRight");
  }
  if(g_strAreaMenu=="right"){
    g_strMenuAreaId="WTCidAreaMenuRight";
    tableColumnRemove("WTCidAreaMenuLeft");
    tableColumnRemove("WTCtdMenuShrinkedLeft");
  }
  if(g_strMenuAreaId==""){
    exitMsg("WebMaster: Invalid menu area, check at setup file for g_strAreaMenu = \"left\" or \"right\"");
  }
  
  Progress("Debug Controls");
  
  Progress("Debug Controls");
  debugShowElements(g_bDEBUG);
  
  // delay loading
  Progress("Continue Loading");
  if(g_bShowWebTemCoDocumentation && g_nDelayBeforeLoadingWebsite > 0){
    delayTime(g_nDelayBeforeLoadingWebsite,1000,"continueLoading2()","WTCdivDelayContinueLoading");
  }else{
    executeArrayTimeout1("continueLoading2()");
  }
}

function continueLoading2(){
  refreshGlobals();

  //g_buttonLoadStop.style.display="none";
  Progress("Adjust Menu");
  
  if(g_bMenuUseHTMLfile){
    /* It works this way:
    *  this index.html onload=function()       prepare to load Menu
    *  Menu            onload=WTCloadMenu()    prepare to load Bottom
    *  Top             onload=WTCloadTop()  
    *  ContentTop      onload=WTCloadContentTop()  
    *  ContentBottom   onload=WTCloadContentBottom()  
    *  Bottom          onload=WTCloadBottom()  
    *  Main Content    onload=WTCloadContent() loads Content html and fills Content area.
    */
    setIFrameDataURL_b("menu.html"); // -> menu.html   -> parent.WTCloadMenu();
    // when this function exits, menu.html will be loaded
  }else{
    prepareAreaMenu();
    
    // TOP
    var aExec = new Array();
    aExec.push(
      prepareArea_strExec(
        "WTCidAreaTop",
        g_bAreaTopShow,
        g_strAreaTopStyle,
        g_strAreaTopInnerHTML,
        g_bAreaTopUseHTMLfile,
        "top.html",
        g_strAreaTopOnClick
      )
    );
    
    // CONTENT TOP
    aExec.push(
      prepareArea_strExec(
        "WTCidAreaContentTop",
        g_bAreaContentTopShow,
        g_strAreaContentTopStyle,
        g_strAreaContentTopInnerHTML,
        g_bAreaContentTopUseHTMLfile,
        "contenttop.html",
        g_strAreaContentTopOnClick
      )
    );
    
    // CONTENT BOTTOM
    aExec.push(
      prepareArea_strExec(
        "WTCidAreaContentBottom",
        g_bAreaContentBottomShow,
        g_strAreaContentBottomStyle,
        g_strAreaContentBottomInnerHTML,
        g_bAreaContentBottomUseHTMLfile,
        "contentbottom.html",
        g_strAreaContentBottomOnClick
      )
    );
    
    // BOTTOM
    aExec.push(
      prepareArea_strExec(
        "WTCidAreaBottom",
        g_bAreaBottomShow,
        g_strAreaBottomStyle,
        g_strAreaBottomInnerHTML,
        g_bAreaBottomUseHTMLfile,
        "bottom.html",
        g_strAreaBottomOnClick
      )
    );
    
    if(aExec.length>0)
      executeArrayTimeout(aExec);
    
    menuShrinkedPrepare();

    menuAreasIEworkaround();
    
    document.getElementById("WTCidAreaContent").onmouseover=WTCareaContentMouseOver; 
    document.getElementById("WTCidAreaContent").onmouseout =WTCareaContentMouseOut ; 
    
    executeArrayTimeout1("WTCmenuFloating()"); //must be executed after menu internal dynamic adjustments are made in this same way
    
    // grant it will be shown just in case of weird things may happen
    Progress("Show All");
    document.getElementById("WTCtableMain").style.display=""; 

    Progress("Load 1st Content");
    if(g_bLastLocationRemember && !strIsBlank_b(g_strLastLocation) && strIsBlank_b(g_strLoadURL))
      g_strLoadURL = g_strLastLocation.replace(/\+/,"/");
    if(g_strLoadURL!="")
      WTCloadURLatAreaContent(g_strLoadURL);
    else
      executeArrayTimeout1("prepareLoadContent()");
    // when this function exits, Main content will be loaded
  }
}

function WTCareaContentMouseOver(event){
}

function WTCareaContentMouseOut(event){
}

function submenuName(el,bShow){
  // submenu name (1st item) //@@@??? check id == "WTCsubmenu:"+strId.split("WTCsubmenu")[1]
  var elN=el.getElementsByTagName("TD")[0];
  elN.style.display=(bShow?"":"none");
}

function submenuFloating(){
  var el=null;
  var n=0;
  //var n=-1;
  var strId="WTCsubmenu"+n;
  //var strId="WTCsubmenu"+"Options";
  
  //document.getElementById("WTCsubmenu:Options").style.visibility=(g_bMenuFloating?"hidden":"visible");
  /*
  el = document.getElementById("WTCsubmenu:Options");
  el.style.display=(g_bMenuFloating?"none":"");
  el.style.position=(g_bMenuFloating?browserCompat_str("fixed","absolute"):"");
  
  el = document.getElementById("WTCsubmenuOptions" );
  el.style.position=(g_bMenuFloating?browserCompat_str("fixed","absolute"):"");
  submenuName(el,g_bMenuFloating);
  document.getElementById("WTCText_WTCsubmenu:Options").style.display=(g_bMenuFloating?"none":"");
  */
  
  while(el = document.getElementById(strId)){
    el.style.position=(g_bMenuFloating?browserCompat_str("fixed","absolute"):"");
    
    submenuName(el,g_bMenuFloating);
    
    n++;
    strId="WTCsubmenu"+n;
  }
}

function WTCmenuFloating(event){
  if(event){
    g_bMenuFloating = checkBoxReadSet_b(getEventSource(event));
  }
  
  menuAreasIEworkaround();
  
  SubmenuClose(true);
  
  var el = document.getElementById("WTCtableMenuBoundary");
  el.style.position=(g_bMenuFloating?browserCompat_str("fixed","absolute"):"");
  el.style.height  =(g_bMenuFloating?"":"100%");
  
  submenuFloating();
  
  menuExpandShrink(!g_bMenuFloating);
}

function menuExpandAuto(bMouseOver){
  if(!g_bMenuFloating)
    return;

  if(!bMouseOver){
    clearTimeout(g_timeoutMenuShrinkExpand);
    return;
  }
  
  var strOrWait=(g_bMenuFloating ? multiLang_str(" or wait& ou aguarde") : "");
  window.status=multiLang_str("Click"+strOrWait+" to Expand&Clique"+strOrWait+" para Expandir");

  g_timeoutMenuShrinkExpand=setTimeout("menuExpandShrink(true)",g_nMenuTimeBeforeExpand);
}

function menuShrinkedGet_el(){
  return document.getElementById( (g_strAreaMenu=="left" ? "WTCtdMenuShrinkedLeft" : "WTCtdMenuShrinkedRight") );
}

function menuShrinkedPrepare(){
  var el = menuShrinkedGet_el();

  //var strOrWait=(g_bMenuFloating ? multiLang_str(" or wait"," ou aguarde") : "");
  //el.title=multiLang_str("Click"+strOrWait+" to Expand","Clique"+strOrWait+" para Expandir");
  
  var strId = "WTCidMenuShrinked";
  var bMenuFloatingMini = g_bMenuFloatingMini && (g_nMenuShrinkedTextShowTimesUserAlready>g_nMenuShrinkedTextShowTimes);
  var strMenu=(bMenuFloatingMini?
    '<img src="'+g_strImgMenuMini+'">':
    (strIsBlank_b(g_strMenuShrinkedInnerHTML)?
      '<small><b>M<br>e<br>n<br>u</b></small>':
      g_strMenuShrinkedInnerHTML)
  );
  el.innerHTML=
    "<div id=\""+strId+"\" style=\"position: "+browserCompat_str("fixed","absolute")+"; cursor: default; top: 0; left: 0; "+
      (bMenuFloatingMini?"":g_strMenuShrinkedStyle)+" \" "+
      "onclick=\"menuExpandShrink(true)\" "+
      "onmouseover=\"menuExpandAuto(true)\" "+
      "onmouseout=\"menuExpandAuto(false)\" >"+
      strMenu+
    "</div>";
  
  executeArrayTimeout1("SPFIEadd(\""+strId+"\")"); 
}

function IEworkaroundWidthPerc(nPerc){ // style="width: 100%" -> style="width: expression(IEworkaroundWidthPerc(100))"
  if(!IsIE_b()){
    msgExit("this function must only bugfix IE");
  }
  if(!g_bEnable_IEworkaroundWidthPerc)return "";
  //alert(self.innerWidth+"/"+document.body.clientWidth);
  return document.body.clientWidth * (nPerc/100) -20 -(g_bMenuFloating?0:g_nMenuWidth);
}

function menuAreasIEworkaround(){
  if(IsIE_b()){
	
    var str=(g_bMenuFloating?"absolute":"");
    if(g_strAreaMenu=="left"){
      document.getElementById("WTCtdMenuShrinkedLeft" ).style.position=str;
      document.getElementById("WTCidAreaMenuLeft" ).style.position=str;
	}else{
      document.getElementById("WTCtdMenuShrinkedRight").style.position=str;
      document.getElementById("WTCidAreaMenuRight").style.position=str;
	}
	
    //document.getElementById("WTCtdMenuShrinkedRight").style.display="none";
    //document.getElementById("WTCidAreaMenuRight").style.display="none";
  }
}

function menuExpandShrink(bExpand){
  if(!g_bMenuFloatingDockedChangeAllow)
    return;

  // prevents double expanding after having clicked to expand
  clearTimeout(g_timeoutMenuShrinkExpand);

  var elMenuShrinked = menuShrinkedGet_el();
  var elMenu         = document.getElementById( g_strMenuAreaId );

  if(bExpand){
    elMenuShrinked.style.display="none";
    elMenu        .style.display=""    ;
  }else{
    elMenuShrinked.style.display="";
    elMenu        .style.display="none"    ;
  }

  //if(g_IFrameData.WTCuserFuncOnMenuExpandShrink){
  //  g_IFrameData.WTCuserFuncOnMenuExpandShrink(bExpand);
  //}
}

function debugTest(){
  funcCallerNameIN();
  var strDbg=prompt("DEBUG test, enter nID;value ex.: 0;0xFFFFFF")
  if(!strDbg || strDbg=="")return;
  debugMsg(""+strDbg);
  var n = strDbg.indexOf(";");
  var nId = parseInt_n(strDbg.substr(0,n));
  var varValue=strDbg.substr(n+1);
  debugMsg(nId+";"+varValue);
  switch(nId){
    case 0: //OK
      alert(intToRGB_str(varValue));
      break;
    case 1: //OK
      var strHexa="0123456789ABCDEF";
      for(var n=0;n<varValue.length;n++){
        if( !strHexa.match(varValue.charAt(n).toUpperCase()) ){
          alert("letter ["+varValue.charAt(n)+"] didnt match");
        }
      }
      break;
    case 2: //OK
      alert("CSS:"+RGBtoCSS_str(varValue));
      break;
    case 3: //OK
      alert("Hexa:"+intToHexa_str(varValue));
      break;
    case 4: //OK
      document.getElementById("WTC_6__g_strMenuColorBg").style.backgroundColor=varValue;
      break;
    case 5: //Cause Error Test Handler  //OK
      var dummy=null;
      dummy.dummy;
    case 6: //OK
      var wnd = window.showModelessDialog("about:blank");
      wnd.document.body.innerHTML="abc<br>def";
      break;
    case 7: //OK
      g_strLastLocation=varValue;
      cookieSave();
      break;
    case 8:
      var str = debugMsg_el("/"+varValue,false,false,true,true).innerHTML;
      alert(str.split("/")[1].charCodeAt(0));
      break;
    case 9:
      alert(HTMLEscapeTranslate_str(null,varValue));
      break;
  }
  funcCallerNameOUT();
}

function URLparameters_str(){ 
  //ex.: .../index.html?cookie=off&menu=2&test=123
  funcCallerNameIN();

  var str = new String(window.location.href);
  debugMsg(str);
  var nPos=str.indexOf("?");
  if(nPos!=-1){
    var strParams=str.substr(nPos+1);
    var strUnescape=new String(unescape(strParams));
    g_astrURLparams = strUnescape.split("&");
  }
  debugMsg(g_astrURLparams.length);
  
  var strParam="";
  var strOpt="";
  var strValue="";
  while(strParam=g_astrURLparams.pop()){
    strOpt  =strParam.split("=")[0]
    strValue=strParam.split("=")[1]
    switch(strOpt){
      case "cookie":
        if(strValue=="clean"){
          document.cookie=g_strCookieID+'=';
          debugMsg("cookie cleaned");
        }
        if(strValue=="off"){
          g_bCookieEnabled=false;
          debugMsg("cookie off");
        }
        if(strValue=="restore"){
          CookieRestoreBackup_b();
          debugMsg("cookie restore backup");
        }
        break;
      case "load":
        g_bParameterLoadURL=true;
        g_strLoadURL=strValue;
        break;
      case "debug":
        debugShowElements(true);
        break;
      case "progress":
        g_bShowProgress=true;
        break;
      case "lang":
        g_strLanguage=strValue;
        break;
    }
  }

  funcCallerNameOUT();
}

function browserId_b(strId){
  if(strVal(g_strBrowserNameShort) == strVal(strId)){
    return true;
  }
  return false;
}

function validateRelativeURL_b(){
  
}

function CookieRestoreBackup_b(){
  if( !cookieLoad_b(null,g_strCookieID+"Bkp",true) ){
    alert("Occurred a problem while loading backup cookie.\n"+
          "Tho, it can be overwritten by cliking 'backup'\n"+
          "at user preferences.");
    return false;
  }
  return true;
}

function WTCloadURLatAreaContent(strURL){
  //only allowed relative url
  // ":" means a 'protocol?' so a full URL is being used. //@@@??? better use "://" ?
  if( strURL.indexOf(":") != -1 && strURL.substr(0,g_strMeURLbasePath.length) != g_strMeURLbasePath ){
    document.getElementById("WTCidAreaContent").innerHTML="<small>"+
      escapeToHTML_str(g_strMeURLbasePath+"\nPROBLEM, URL: "+strURL+"\nmust be relative.")+
      "<small>";
    strURL = strURL.substr(g_strMeURLbasePath.length);
    return;
  }
  
  executeArrayTimeout1("resetCurrentMenuItem()");
  executeArrayTimeout1('setIFrameDataURL_b("'+strURL+'")');
}

function WTCsetup(varEvent,el){
  funcCallerNameIN();
  
  var bRefresh = true;
  var bSaveCookie = true;
  elEventSource=(el?el:getEventSource(varEvent));
  var strId =(""+elEventSource.id).split(":")[0];
  var strId2=(""+elEventSource.id).split(":")[1];
  switch(strId){
    case "WTCsetupWebsiteTitle":
      g_strWebsiteTitle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strWebsiteTitle","str");
      break;
    case "WTCsetupImgMenuMini":
      g_strImgMenuMini=elEventSource.value;
      WebMasterSetupAdjustArray("g_strImgMenuMini","str");
      break;
    case "WTCsetupMenuFreeCellStyle":
      g_strMenuFreeCellStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strMenuFreeCellStyle","str");
      break;
    case "WTCsetupMenuFreeCellInnerHTML":
      g_strMenuFreeCellInnerHTML=elEventSource.value;
      WebMasterSetupAdjustArray("g_strMenuFreeCellInnerHTML","str");
      break;
    case "WTCsetupMenuShrinkedStyle":
      g_strMenuShrinkedStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strMenuShrinkedStyle","str");
      break;
    case "WTCsetupWebsiteLanguage":
      g_strLanguage=elEventSource.value;
      WebMasterSetupAdjustArray("g_strLanguage","str");
      break;

    case "WTCsetupAreaTopStyle":
      g_strAreaTopStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaTopStyle","str");
      break;
    case "WTCsetupAreaContentTopStyle":
      g_strAreaContentTopStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaContentTopStyle","str");
      break;
    case "WTCsetupAreaContentBottomStyle":
      g_strAreaContentBottomStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaContentBottomStyle","str");
      break;
    case "WTCsetupAreaBottomStyle":
      g_strAreaBottomStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaBottomStyle","str");
      break;
    
    case "WTCsetupAreaTopInnerHTML":
      g_strAreaTopInnerHTML=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaTopInnerHTML","str");
      break;
    case "WTCsetupAreaContentTopInnerHTML":
      g_strAreaContentTopInnerHTML=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaContentTopInnerHTML","str");
      break;
    case "WTCsetupAreaContentBottomInnerHTML":
      g_strAreaContentBottomInnerHTML=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaContentBottomInnerHTML","str");
      break;
    case "WTCsetupAreaBottomInnerHTML":
      g_strAreaBottomInnerHTML=elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaBottomInnerHTML","str");
      break;
    
    case "WTCsetupMenuWidth":
      g_nMenuWidth=elEventSource.value;
      WebMasterSetupAdjustArray("g_nMenuWidth","n");
      break;
    case "WTCsetupMenuTimeBeforeExpand":
      g_nMenuTimeBeforeExpand=elEventSource.value;
      WebMasterSetupAdjustArray("g_nMenuTimeBeforeExpand","n");
      break;
    case "WTCsetupMenuTimeBeforeShrink":
      g_nMenuTimeBeforeShrink=elEventSource.value;
      WebMasterSetupAdjustArray("g_nMenuTimeBeforeShrink","n");
      break;
    case "WTCsetupMenuShrinkedTextShowTimes":
      g_nMenuShrinkedTextShowTimes=elEventSource.value;
      WebMasterSetupAdjustArray("g_nMenuShrinkedTextShowTimes","n");
      break;
    
    case "WTCsetupMenuEntries":
      g_astrMenuEntries=(""+elEventSource.value).split("\n");
      WebMasterSetupAdjustArray("g_astrMenuEntries","array");
      break;
    case "WTCsetupColorScheme":
      g_strColorScheme=elEventSource.value;
      WebMasterSetupAdjustArray("g_strColorScheme","str");
      break;
    case "WTCsetupCSS":
      g_strCSS=(""+elEventSource.value).split("}\n").join("} ");
      WebMasterSetupAdjustArray("g_strCSS","str");
      break;
    case "WTCsetupTableMainStyle":
      g_strTableMainStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strTableMainStyle","str");
      break;
    case "WTCsetupMainBodyStyle":
      g_strMainBodyStyle=elEventSource.value;
      WebMasterSetupAdjustArray("g_strMainBodyStyle","str");
      break;
    case "WTCsetupGenerateSetupFile":
      WebMasterSetupGenerateFile();
      break;
    case "WTCsetupCookieSeeAll":
      g_bCookieSeeAll=!g_bCookieSeeAll;
      break;
    case "WTCsetupCookieReset":
      if( confirm("Reset preferences to defaults and reload Website?") ){
        cookieReset(null,true);
        //window.location.reload();
        //window.location.assign("index.html");
        window.location.replace("index.html"); //refreshes better than reload()
        return;
      }
      break;
    case "WTCsetupCookieCopy"  :
      prompt( "Copy it.", cookieRetrive_str(g_strCookieID,true) );
      break;
    case "WTCsetupCookiePaste" :
      var str=prompt("Paste a Website Template Control compatible (version 0.103 up) cookie:","");
      if(str && str!="")
        if( !cookieLoad_b(str,null,true) )
          alert("Unable to validate pasted cookie.");
      break;
    case "WTCsetupCookieRefresh" :
      break;
    case "WTCsetupCookieBackup"  :
      cookieSave(g_strCookieID+"Bkp");
      break;
    case "WTCsetupCookieRestore" :
      if( confirm("Restore previously backuped preferences?") ){
        if( !CookieRestoreBackup_b() ){
          bSaveCookie=false;
        }
        // autosave cookie at end of this func.
      }
      break;
    
    case "WTCsetupDeveloperControls":
      g_bDeveloperControls=!g_bDeveloperControls;
      checkBoxReadSet_b(elEventSource,g_bDeveloperControls);
      break;
    case "WTCsetupDebugTest":
      debugTest();
      bRefresh=false;
      break;
    case "WTCsetupMenuSide" :
      g_strAreaMenu = elEventSource.value;
      WebMasterSetupAdjustArray("g_strAreaMenu","str");
      break;
    case "WTCsetupImgMenuMini" :
      g_strImgMenuMini = elEventSource.value;
      WebMasterSetupAdjustArray("g_strImgMenuMini","str");
      break;
    case "WTCsetupImgMenuMiniTEXT" :
      g_strMenuShrinkedInnerHTML = elEventSource.value;
      WebMasterSetupAdjustArray("g_strMenuShrinkedInnerHTML","str");
      break;
    case "WTCsetupAreaTopDisplay"          :
      g_bAreaTopShow=!g_bAreaTopShow;
      checkBoxReadSet_b(elEventSource,g_bAreaTopShow);
      elShow("WTCidAreaTop",g_bAreaTopShow);
      WebMasterSetupAdjustArray("g_bAreaTopShow","b");
      break;
    case "WTCsetupAreaContentTopDisplay"   :
      g_bAreaContentTopShow=!g_bAreaContentTopShow;
      checkBoxReadSet_b(elEventSource,g_bAreaContentTopShow);
      elShow("WTCidAreaContentTop",g_bAreaContentTopShow);
      WebMasterSetupAdjustArray("g_bAreaContentTopShow","b");
      break;
    case "WTCsetupAreaContentBottomDisplay":
      g_bAreaContentBottomShow=!g_bAreaContentBottomShow;
      checkBoxReadSet_b(elEventSource,g_bAreaContentBottomShow);
      elShow("WTCidAreaContentBottom",g_bAreaContentBottomShow);
      WebMasterSetupAdjustArray("g_bAreaContentBottomShow","b");
      break;
    case "WTCsetupAreaBottomDisplay"       :
      g_bAreaBottomShow=!g_bAreaBottomShow;
      checkBoxReadSet_b(elEventSource,g_bAreaBottomShow);
      elShow("WTCidAreaBottom",g_bAreaBottomShow);
      WebMasterSetupAdjustArray("g_bAreaBottomShow","b");
      break;
    
    case "WTCsetupColorsToShow": //"WTCsetupColorsToShowSet": 
      var n=parseInt_n(document.getElementById("WTCsetupColorsToShow").value);
      if(n){
        g_nSetupColorsToShow=n;
        g_bSetupColorsToShow=true;
      }
      break;
      
    case "WTCinputcbMenuFloating": 
      WTCmenuFloating(varEvent)
      WebMasterSetupAdjustArray("g_bMenuFloating","b");
      break;
    case "WTCinputcbMenuFloatingMini": 
      g_bMenuFloatingMini=!g_bMenuFloatingMini;
      WebMasterSetupAdjustArray("g_bMenuFloatingMini","b");
      break;
    
    case "WTCinputcbRememberLastVisitedLink": 
      g_bLastLocationRemember=!g_bLastLocationRemember;
      checkBoxReadSet_b(elEventSource,g_bLastLocationRemember);
      break;
  }

  WebMasterSetupCommitToWebsite();
  
  if(bSaveCookie)
    cookieSave();
  if(bRefresh)
    WTCsetupUserPreferences();
  
  funcCallerNameOUT(elEventSource.id);
}

function cookieShow_str(){
  //(g_bCookieSeeAll ? (new String(document.cookie)).split("&").join(" & ").split(";").join(";<br>")+'<br>' :
  var astr    = (""+cookieRetrive_str(g_strCookieID      )).split("&");
  for(var n=0;n<astr.length;n++){
    if(astr[n].charAt(0)=="H"){
      astr[n]=astr[n].split(".").join(" ");
      break;
    }
  }
  
  var astrBkp = (""+cookieRetrive_str(g_strCookieID+"Bkp")).split("&");
  for(var n=0;n<astr.length;n++){
    if(!strIsBlank_b(astrBkp[n]) && astrBkp[n].charAt(0)=="H"){
      astrBkp[n]=astrBkp[n].split(".").join(" ");
      break;
    }
  }
  //);
  return astr.join(" & ")+"<br>"+astrBkp.join(" & ")+"<br>";
}

function ColorSchemeShow(){
  elGet_el("WTCdivColorScheme").innerHTML=
    '<table border="1"><tbody>'+
      '<tr>'+ 
      '<td><input id="WTCsetupColorScheme" value="'+ColorSchemeMake_str()+'" size="60" type="text"></td></tr>'+
    '</tbody></table>';
}

function WTCsetupKeyEnter(event){
  var e=(document.all?window.event:event);
  if(e.keyCode==13){
    WTCsetup(event);
  }
}

function WTCsetupUserPreferences(){
  funcCallerNameIN();

  var nTestTemp=0; //alert(nTestTemp++);
  var el = null;
  var bShow = false;
  
  g_nVariableShowColorAsTableIDadd=0;
  
  elGet_el("WTCaPropHPPrjName"    ).innerHTML = g_strProjectName;
  elGet_el("WTCspanPropHPVersion" ).innerHTML = g_strVersion;
  elGet_el("WTCaPropHPFirefoxLink").href      = g_strFirefoxLink;
  elGet_el("WTCdivPropHPNoticeToWebmaster").style.display = (g_bLocalBrowsing?"":"none");
  
  el = elGet_el("WTCiPropHPPathFileMenu")
  el.href = g_strMenuFilePathName;
  el.innerHTML = g_strMenuFilePathName;

  // cookie
  //el = elGet_el("WTCsetupCookieSeeAll")
  //el.style.display = (g_bDeveloperControls?"":"none");
  //el.innerHTML     = (g_bCookieSeeAll ? "Only WebTemCo" : "See All")

  elGet_el("WTCdivPropHPCookieValue").innerHTML=cookieShow_str();
  
  elGet_el("WTCsetupDynamicSetupFile").value=g_strPath+"WebTemCoSetupDynamic.js";
  
  // Website Title
  el = elGet_el("WTCsetupWebsiteTitle");
  el.value=g_strWebsiteTitle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  // language
  el = elGet_el("WTCsetupWebsiteLanguage:"+g_strLanguage);
  el.checked=true;
  
  el = elGet_el("WTCsetupTableMainStyle");
  el.value=g_strTableMainStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupMainBodyStyle");
  el.value=g_strMainBodyStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupCSS");
  el.value=(escape(g_strCSS).indexOf(escape("\n"))==-1 ? //@@@ does escape to \n and compare is working?
    g_strCSS.split("} ").join("}\n") : g_strCSS);
  el.onblur=WTCsetup;
  
  // areas
  el = elGet_el("WTCsetupAreaTopDisplay");
  el.checked       = g_bAreaTopShow;

  el = elGet_el("WTCsetupAreaContentTopDisplay");
  el.checked       = g_bAreaContentTopShow;
  
  el = elGet_el("WTCsetupAreaContentBottomDisplay");
  el.checked       = g_bAreaContentBottomShow;
  
  el = elGet_el("WTCsetupAreaBottomDisplay");
  el.checked       = g_bAreaBottomShow;

  // menu
  el = elGet_el("WTCsetupMenuSide:"+g_strAreaMenu);
  el.checked=true;
  
  el = elGet_el("WTCsetupImgMenuMini");
  el.value=g_strImgMenuMini;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupImgMenuMiniIMG");
  el.src=g_strImgMenuMini;

  el = elGet_el("WTCsetupImgMenuMiniTEXT");
  el.value=g_strMenuShrinkedInnerHTML;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupMenuFreeCellStyle");
  el.value=g_strMenuFreeCellStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupMenuFreeCellInnerHTML");
  el.value=g_strMenuFreeCellInnerHTML;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupMenuShrinkedStyle");
  el.value=g_strMenuShrinkedStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupAreaTopStyle");
  el.value=g_strAreaTopStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupAreaContentTopStyle");
  el.value=g_strAreaContentTopStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupAreaContentBottomStyle");
  el.value=g_strAreaContentBottomStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupAreaBottomStyle");
  el.value=g_strAreaBottomStyle;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupAreaTopInnerHTML");
  el.value=g_strAreaTopInnerHTML;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupAreaContentTopInnerHTML");
  el.value=g_strAreaContentTopInnerHTML;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupAreaContentBottomInnerHTML");
  el.value=g_strAreaContentBottomInnerHTML;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupAreaBottomInnerHTML");
  el.value=g_strAreaBottomInnerHTML;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCsetupMenuEntries");
  el.value=g_astrMenuEntries.join('\n');
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupMenuWidth");
  el.value=g_nMenuWidth;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupMenuTimeBeforeExpand");
  el.value=g_nMenuTimeBeforeExpand;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupMenuTimeBeforeShrink");
  el.value=g_nMenuTimeBeforeShrink;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;

  el = elGet_el("WTCsetupMenuShrinkedTextShowTimes");
  el.value=g_nMenuShrinkedTextShowTimes;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup;
  
  el = elGet_el("WTCinputcbMenuFloating");
  el.style.display = ( g_bMenuFloatingDockedChangeAllow?"":"none");
  elGet_el("WTCinputcbMenuFloatingTxt").style.display = (g_bMenuFloatingDockedChangeAllow?"":"none");
  el.checked       = g_bMenuFloating;
  
  el = elGet_el("WTCimgMenuMini");
  el.style.display = ( g_bMenuFloatingDockedChangeAllow?"":"none");
  el.src = g_strImgMenuMini;

  el = elGet_el("WTCinputcbMenuFloatingMini");
  el.style.display = ( g_bMenuFloatingDockedChangeAllow?"":"none");
  elGet_el("WTCinputcbMenuFloatingMiniTxt").style.display = (g_bMenuFloatingDockedChangeAllow?"":"none");
  el.checked       = g_bMenuFloatingMini;
  
  el = elGet_el("WTCinputcbRememberLastVisitedLink");
  el.checked       = g_bLastLocationRemember;
  
  // colors
  ColorSchemeShow();
  
  el = elGet_el("WTCsetupColorsToShow");
  el.value=g_nSetupColorsToShow;
  el.onkeydown=WTCsetupKeyEnter;
  el.onblur=WTCsetup
  if(g_bSetupColorsToShow){
    elGet_el("WTCdivPropHPColors").innerHTML=tableColors_str(g_nSetupColorsToShow,25);
    g_bSetupColorsToShow=false;
  }
  
  elGet_el("WTCdivPropHPColorsOpt").innerHTML=
    variableShowColorAsTable_str("g_strMenuHighlightColorFg"  ,"g_strMenuHighlightColorBg"  ,"Menu Highlight")+
    variableShowColorAsTable_str("g_strMenuCurrentLinkColorFg","g_strMenuCurrentLinkColorBg","Menu Current Link");
  
  elGet_el("WTCdivPropHPColorsOptReqReload").innerHTML=
    variableShowColorAsTable_str("g_strMenuNameColorFg","g_strMenuNameColorBg",multiLang_str(g_strMenuItemOptionsTitle))+
    variableShowColorAsTable_str("g_strMenuSubmenuColorFg","g_strMenuSubmenuColorBg","<b>SubMenu</b>")+
    variableShowColorAsTable_str("g_strMenuLinkColorFg","g_strMenuLinkColorBg"   ,"Menu Relative Link")+
    variableShowColorAsTable_str("g_strMenuLinkColorAltFg","g_strMenuLinkColorAltBg","Menu Relative Link (Alternate Bg)")+
    variableShowColorAsTable_str("g_strMenuFreeCellColorFg","g_strMenuFreeCellColorBg","Menu Free Cell")+
    variableShowColorAsTable_str(null,"g_strMenuColorBg","Menu Background");

  el = elGet_el("WTCsetupColorScheme");
  el.value = g_strColorScheme;
  //el.onchange = WTCsetup; //doesnt work
  
  // debug
  el = elGet_el("WTCcbDebug")
  el.onclick=WTCeventDebugMode;
  checkBoxReadSet_b(el,g_bDEBUG);
  
  elGet_el("WTCsetupDeveloperControls").checked=g_bDeveloperControls;
  
  el = elGet_el("WTCsetupDebugTest")
  el.innerHTML     = (g_bDeveloperControls?"Begin Debug Test":"");
  el.style.display = (g_bDeveloperControls?"":"none");
  
  if(g_strBrowserNameShort!="IE"){
    executeArrayTimeout1("_tableRefreshTrick(0)");
    executeArrayTimeout1("_tableRefreshTrick(1)");
  }
  
/*  
  if(g_strBrowserNameShort!="IE"){
    var astrExecute = new Array();
    astrExecute.push("_tableRefreshTrick(0)");
    astrExecute.push("_tableRefreshTrick(1)");
    executeArrayTimeout(astrExecute);
  }
*/  
  funcCallerNameOUT();
}

function WebMasterSetupFindVar_n(strVarName){
  var strVar="";
  for(var n=0;n<g_astrWebsiteSetup.length;n++){
    strVar  =g_astrWebsiteSetup[n].split(":")[1].split("=")[0];
    if(strVar==strVarName){
      return n;
    }
  }
  return -1;
}

function WebMasterSetupAdjustArray(strVarName,strType,bJustBeforeSavingDynamicSetupFile){
  // update var=value
  var strEval=strVarName;
  var strBefore="";
  var strAfter="";
  if(strType=="str" || strType=="array"){
    strBefore="'";
    strAfter="'";
  }
  var strTemp="";
  if(strType=="array"){
    var astrBkp=null;
    if(bJustBeforeSavingDynamicSetupFile && strVarName=="g_astrMenuEntries"){
      astrBkp=g_astrMenuEntries;
      // Menu Options submenu entries Remove From MenuEntries
      menuOptionsEntriesUserSet(false,true);
    }
    var astrTemp=eval(strVarName);
    if(bJustBeforeSavingDynamicSetupFile && strVarName=="g_astrMenuEntries"){
      g_astrMenuEntries=astrBkp;
    }
    for(var n=0;n<astrTemp.length;n++){
      if(n>0)
        strTemp+="&";
      strTemp+=escape(astrTemp[n]);
    }
    strEval="strTemp"
  }
  if(strType=="b"){
    strEval='('+strVarName+' ? "true" : "false")';
  }
  //var strVarValue=strVarName+"="+strBefore+escape(""+eval(strVarName))+strAfter;
  var strVarValue=strType+":"+strVarName+"="+strBefore+eval(strEval)+strAfter;
  var n=WebMasterSetupFindVar_n(strVarName);
  if(n==-1){
    g_astrWebsiteSetup.push(strVarValue);
  }else{
    g_astrWebsiteSetup.splice(n,1,strVarValue);
  }
}

function WebMasterSetupInit(){
  WebMasterSetupAdjustArray("g_strWebsiteTitle","str");
  WebMasterSetupAdjustArray("g_strLanguage","str");
  WebMasterSetupAdjustArray("g_strTableMainStyle","str");
  WebMasterSetupAdjustArray("g_strMainBodyStyle","str");
  WebMasterSetupAdjustArray("g_strCSS","str");
  WebMasterSetupAdjustArray("g_strColorScheme","str");
  WebMasterSetupAdjustArray("g_strAreaMenu","str");
  WebMasterSetupAdjustArray("g_strImgMenuMini","str");
  WebMasterSetupAdjustArray("g_strMenuShrinkedInnerHTML","str");
  WebMasterSetupAdjustArray("g_strMenuFreeCellStyle","str");
  WebMasterSetupAdjustArray("g_strMenuFreeCellInnerHTML","str");
  WebMasterSetupAdjustArray("g_strMenuShrinkedStyle","str");
  WebMasterSetupAdjustArray("g_astrMenuEntries","array");
  WebMasterSetupAdjustArray("g_bMenuFloating","b");
  WebMasterSetupAdjustArray("g_bMenuFloatingMini","b");
  WebMasterSetupAdjustArray("g_nMenuWidth","n");
  WebMasterSetupAdjustArray("g_nMenuTimeBeforeExpand","n");
  WebMasterSetupAdjustArray("g_nMenuTimeBeforeShrink","n");
  WebMasterSetupAdjustArray("g_nMenuShrinkedTextShowTimes","n");
  WebMasterSetupAdjustArray("g_bAreaTopShow","b");
  WebMasterSetupAdjustArray("g_bAreaContentTopShow","b");
  WebMasterSetupAdjustArray("g_bAreaContentBottomShow","b");
  WebMasterSetupAdjustArray("g_bAreaBottomShow","b");
  WebMasterSetupAdjustArray("g_strAreaTopStyle","str");
  WebMasterSetupAdjustArray("g_strAreaContentTopStyle","str");
  WebMasterSetupAdjustArray("g_strAreaContentBottomStyle","str");
  WebMasterSetupAdjustArray("g_strAreaBottomStyle","str");
  WebMasterSetupAdjustArray("g_strAreaTopInnerHTML","str");
  WebMasterSetupAdjustArray("g_strAreaContentTopInnerHTML","str");
  WebMasterSetupAdjustArray("g_strAreaContentBottomInnerHTML","str");
  WebMasterSetupAdjustArray("g_strAreaBottomInnerHTML","str");
}

function WebMasterSetupCommitToWebsite(){
  var str="";
  var strType="";
  for(var n=0; n<g_astrWebsiteSetup.length; n++){
    //eval(g_astrWebsiteSetup[n].split("=")[0]+"="+unescape(g_astrWebsiteSetup[n].split("=")[1]));
    strType=g_astrWebsiteSetup[n].split(":")[0];
    str    =g_astrWebsiteSetup[n].split(":").slice(1).join(":");
    switch(strType){
      case "str":
        eval(str.split("\n").join(" "));
        break;
      case "array":
        var strVarName=str.split("=")[0];
        str=str.split("=").slice(1).join("=");
        eval('str='+str); // will remove ' from begin and end
        var astr=str.split("&");
        eval(strVarName+'=new Array()');
        for(var n1=0; n1<astr.length; n1++){
          eval(strVarName+'.push(\''+unescape(astr[n1])+'\')');
        }
        break;
      case "n":
      case "b":
        eval(str);
        break;
    }
  }
  
  document.title=g_strWebsiteTitle;
  
  //g_strLanguage
  
  g_bEnable_IEworkaroundWidthPerc = 
    GetValueFromCSS_str(g_strTableMainStyle,"width").indexOf("%")!=-1;
  
  if( !strIsBlank_b(g_strTableMainStyle) ){
    elStyle("WTCtableMain",g_strTableMainStyle);
  }
  
  if( !strIsBlank_b(g_strMainBodyStyle) ){
    elStyle(null,g_strMainBodyStyle,document.body);
  }
  
  document.getElementById("WTCdivCSS").innerHTML='<style TYPE="text/css">'+g_strCSS+'</style>'
  
  ColorSchemeSet(g_strColorScheme);
  
  //g_strAreaMenu
  //g_strImgMenuMini
  //g_strMenuShrinkedInnerHTML
  //g_strMenuFreeCellStyle
  //g_strMenuFreeCellInnerHTML
  //g_strMenuShrinkedStyle
  //g_astrMenuEntries
  //g_bMenuFloating
  //g_bMenuFloatingMini
  //g_nMenuWidth
  //g_nMenuTimeBeforeExpand
  //g_nMenuTimeBeforeShrink
  //g_nMenuShrinkedTextShowTimes
  //g_bAreaTopShow
  //g_bAreaContentTopShow
  //g_bAreaContentBottomShow
  //g_bAreaBottomShow
  //g_strAreaTopStyle
  //g_strAreaContentTopStyle
  //g_strAreaContentBottomStyle
  //g_strAreaBottomStyle
  //g_strAreaTopInnerHTML
  //g_strAreaContentTopInnerHTML
  //g_strAreaContentBottomInnerHTML
  //g_strAreaBottomInnerHTML
}

function GetValueFromCSS_str(strCSS,strVar){
  var n = strCSS.toUpperCase().indexOf(strVar.toUpperCase());
  if(n==-1)
    return "";
  // ex.: "width: 100%; height: 100%;"
  return strCSS.substr(n).split(":")[1].split(";")[0];
}

function WorkWindowOpen(strFileName,strOnloadFuncName){
  // firefox 1.5 gave error msg with "file://" so a slash was added.
  strFileName="file:///"+(strFileName?strFileName:g_strPath+"_dummy.html");
  g_windowTemp=window.open(strFileName,"_blank",
    "channelmode=no,directories=no,fullscreen=no,height=200,width="+screen.width+",left=0,top=100,"+
    "location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=yes");
  
  eval('g_windowTemp.onload='+strOnloadFuncName);
}

function WebMasterSetupGenerateFile(){
  // not automatically handled fields:
  WTCsetup(null,elGet_el("WTCsetupColorScheme"));
  
  //WorkWindowOpen(g_strPath+"WebTemCoSetupDynamic.js","WebMasterSetupGenerateFileOnLoad");
  WorkWindowOpen(null,"WebMasterSetupGenerateFileOnLoad");
}

function WebMasterSetupGenerateFileOnLoad(){
  if(g_windowTemp){
    var strWrite='<pre>';
    strWrite+=escapeToHTML_str(
      '// "'+g_strProjectName+'" version '+g_strVersion+' dynamically generated Website setup file'+
        ' at '+(new Date()).toString()
    )+'<br><br>';
    
    // clean menu entries that must not be saved (internal automatic ones);
    WebMasterSetupAdjustArray("g_astrMenuEntries","array",true);
    
    var str="";
    strWrite+=escapeToHTML_str(  'var g_astrWebsiteSetup=new Array();' )+'<br>';
    for(var n=0;n<g_astrWebsiteSetup.length;n++){
      strWrite+='&nbsp;'+escapeToHTML_str(
        //'g_astrWebsiteSetup.push(\''+g_astrWebsiteSetup[n].split("'").join("\\'")+'\');' 
        'g_astrWebsiteSetup.push(\''+g_astrWebsiteSetup[n].split("=")[0]+'='+
          g_astrWebsiteSetup[n].split("=").slice(1).join("=").split("'").join("\\'")+'\');' 
      )+'<br>';
    }
    g_windowTemp.document.write(strWrite+'</pre>');
//    var str=
//      'var g_astrWebsiteSetup=new Array();'+
//      'g_astrWebsiteSetup.push(\''+g_astrWebsiteSetup.join('\');g_astrWebsiteSetup.push(\'')+'\');';
//    g_windowTemp.document.write(escapeToHTML_str( str ));
  }
}

/*================================ ADD FUNCTIONS ABOVE HERE ===============================*/
/* ANJUTA IDE 2.0.1 integration under Linux:
 * To have functions symbols recognized by Anjuta IDE, this kind of functions 
 * declarations, must come at the end, they wont show up in the symbols list but 
 * they wont stop that list to be properly shown :).
 * Create new project then: rm main.cc; ln .../WebTemCo.js main.cc
 */
onload=function(){
  testInfo();

  g_bWebTemCoStarted=true;

  /*========= INTERNALS ========*/
  HTMLEscapeTranslationTableSet();
  refreshGlobals();
  URLparameters_str();
  
  Progress("Setup Internals",true);
  debugMsg("Begin");
  
  var astr = (new String(window.location)).split("?")[0].split("/");
  astr.pop();
  g_strMeURLbasePath = astr.join("/")+"/";

  /* To edit in mozilla composer, index.html can't be loaded with iframe.
   * This was giving too many trouble: 
   *   document.getElementById("WTCidDivIFrameData").innerHTML="<iframe id=\"WTCiframeData\" src=\"about:blank\" name=\"WTCiframenameData\"></iframe>";
   * Just comment iframe before loading on composer.
   */

  //document.getElementById("WTCidVersion").title=g_strProjectName+" "+g_strVersion; //not needed, user preferences page show that already
  g_strURLmenu =document.getElementById("WTCaMenu" ).href;
  g_strURLindex=document.getElementById("WTCaIndex").href;
  
  g_strPlatform=window.navigator.platform;

  g_strBrowserName=window.navigator.appName;
  switch(g_strBrowserName){
    case "Microsoft Internet Explorer": g_strBrowserNameShort="IE"; break;
  }

  SimulatePosFixedOnIE();

  //index.html setup events (none)
  
  if( browserId_b("IE") ){
    document.getElementById("WTCtdContentAreas").style.width="0%";
  }

  checkLocalBrowsing();

  /*========= SETUP FILE ========*/
  Progress("Setup File");
  WebMasterSetupCommitToWebsite();

  if(!g_bShowWebTemCoDocumentation){
    document.getElementById("WTCidAreaMenuLeft"     ).innerHTML="";
    document.getElementById("WTCidAreaMenuRight"    ).innerHTML="";
    document.getElementById("WTCidAreaTop"          ).innerHTML="";
    document.getElementById("WTCidAreaContentTop"   ).innerHTML="";
    document.getElementById("WTCidAreaContent"      ).innerHTML="";
    document.getElementById("WTCidAreaContentBottom").innerHTML="";
    document.getElementById("WTCidAreaBottom"       ).innerHTML="";
  }//else{
  //  document.getElementById("WTCidAreaContent").innerHTML = g_innerHTMLdocumentation;
  // }
   
  if(g_bShowWebTemCoDocumentation){
    // Adjust 'stop loading button' event
    g_buttonLoadStop = document.getElementById("WTCbtnLoadStop");
    if(g_buttonLoadStop){
      g_buttonLoadStop.onclick=buttonLoadStop;
    }
  }

  /* When another website is loaded and then user at click "back" browser button,
   * if the last page loaded at IFrameData is the main content homepage, it wont be reloaded
   * and so wont execute onload() event that fill up content area.
   * By setting it to "about:blank", the main content is forced to be reloaded :)
   */
  setIFrameDataURL_b("about:blank"); 

  executeArrayTimeout1("continueLoading1()");
}

onunload=function(){
  clearIntervals();
//  setIFrameDataURL_b("about:blank");
}

onerror=function(){
  // happens if fail on loading a document or an image
  clearIntervals();
  
  // if webmaster removes a relative homepage, this will take care to send visitor to main homepage.
  if(!g_bParameterLoadURL     && !g_bAreaContentLoaded && 
      g_bLastLocationRemember && !strIsBlank_b(g_strLastLocation)
    ){
    g_strLastLocation="";
    cookieSave();
    window.location.replace("index.html");
    return;
  }
  
  if(g_bWebTemCoStarted){ //this prevents other scripts errors to be shown here.
    debugBig();

    if(!g_bForceExit){
      //g_IFrameData.location.replace("about:blank"); //doesnt work.
      
      var elDest=document.body;
      var el = document.getElementById("WTCidAreaContent");
      if(el)elDest=el;
      
      elStyle(null,"color: rgb(0,0,0); background-color: rgb(255,255,255);",elDest);
      
      elDest.innerHTML="JAVASCRIPT PROBLEM<br>"+
        "<br>"+
        "<b>Limpe o Cache do seu navegador! Clean the cache of your browser!</b><br>"+
        "<br>"+
        "Click here to jump directly to Preferences:<br>"+
        "<a href=\""+g_strURLindex+"?load=WebTemCoPref.html\">"+g_strURLindex+"?load=WebTemCoPref.html</a><br>"+
        "<br>"+
        "Click here to restore cookie backup:<br>"+
        "<a href=\""+g_strURLindex+"?cookie=restore\">"+g_strURLindex+"?cookie=restore</a><br>"+
        "<br>"+
        "Click here to clean cookie and retry:<br>"+
        "<a href=\""+g_strURLindex+"?cookie=clean\">"+g_strURLindex+"?cookie=clean</a><br>"+
        "<br>"+
        "Click here to retry with cookies disabled:<br>"+
        "<a href=\""+g_strURLindex+"?cookie=off\">"+g_strURLindex+"?cookie=off</a><br>"+
        "<br>"+
        "Browse in Plain HTML mode at this URL:<br>"+
        "<a href=\""+g_strURLmenu+"\">"+g_strURLmenu+"</a><br>"+
        "<br>"+
        "Browse with "+g_strFirefoxLink+".<br>"+
        "<br>"+
        "Debug cookie: <br>"+
        '<input value="'+cookieRetrive_str(g_strCookieID)+'" size="80" type="text"><br>';
      
      window.scrollTo(0,10000); //scroll to end of page
      window.stop();
    
/*
    if( confirm("May be a cookie["+document.cookie+"] problem, clean it and reload?") ){
      document.cookie=g_strCookieID+'=';
      window.location.reload();
    }
*/
    }
  }
}

