/* tooltip examples specific scripting */

/* var sNavTst = '<b>Need some browser data</b><br>';
 for (var x in navigator)
   sNavTst+=x+'=>'+navigator[x]+'<br>'*/

 if (!window.genLoad)
   window.genLoad = genLoad
 if(!window.pageLoad)
   genLoad()

  w.pageLoad.loaders.exampleLoad = loadExample;

function loadExample()
{
   doc.title = doc.title.replace(/_version_/i,settings.ttversion);
//   $('navVersion').innerHTML=sNavTst

   settings.loadAllTxt(
   {  testing:'this text is one of the jsTxt collection in this script',
      firstExample:'this is how the declaration of the first box looks like:\n\
                   &lt;p id="main" style="[style declarations]"\n\
                   tt=1 ttxtid="saywhat" ttc="help" ttw=450\n\
      ttHover="green" ttNodelay=1 ttHeader="&lt;i>S A Y&nbsp;&nbsp;  W H A T ?&lt;/i>">',
      var1:'variant 1:<br>tTxtJs=var1<br>ttc=pointer<br>ttUseStyle=dotline_grey<br>tthover=RGB(93,152,46)',
      var2:'variant2:<br>tTxtJs=var2<br>ttc=crosshair<br>ttUseStyle=dotline_red',
      var3:'variant 3:<br>tTxtJs=var3<br>ttc=help<br>ttUseStyle=invert<br>tthover=red',
      var4:'variant 4:<br>tTxtJs=var4<br>ttc=help<br>ttUseStyle=blockdot',
      nesttest:'testing a <span tt=1 ttxt="this one is nested within a nested tip" \
                ttc="help" ttbgc="#F0F0F0" ttUseStyle="dotline_red">nested</span> tooltip\n\
                testing a nested tooltip\n\
                testing a nested tooltip\n\
                testing a nested tooltip\n\
                testing a nested tooltip\n\
                testing a <span ttNoBreak=1 ttbgc="#FFFFA0" tt=1 ttStatic=1 ttxt="and here is another \
                <span tt=1 ttxt=\'nice huh?\' ttc=\'help\' ttbgc=\'#FFF\' ttUseStyle=\'invert\'>\
                little nest</span>" ttHeader="Beep!" ttUseStyle="solidline_red" \
                ttc="pointer">nested</span> tooltip\n\
                testing a nested tooltip',
      changeLog:getChangeLog(settings.ttversion),
      ieSelectText:'for IE version < 7 measures have to be taken to hide the &lt;select> element behind\
                    the tooltip. By the way: it\'s possible to apply a tooltip to a &lt;select>\
                    element, but the result is that the &lt;select> itself doesn\'t work anymore in\
                    a <i>Mozilla</i> browser. Don\'t we all LOVE our browserquirks?',
      tooltipDownload:'3 files, zipped:\n\
                        <b>tooltip3.js</b>: the basic scripting\n\
                        <b>tooltipexample3.js</b>: the example specific scripting\n\
                        <b>tooltip3.html</b>: the html\n',
      IE7Problem:'IE 7 has it\'s own problems: first the tooltip text is displayed badly, ragged with \
                  or without the clearType setting checked.\nSecond, after zooming the tips are \
                  way off the position they should be (dependent on the mouse event). If anyone \
                  knows a hack for one or both of these problems, please don\'t hesitate \
                  to mail me your solution @ \
                  <a href="mailto:renzo.kooi@gmail.com">renzo.kooi@gmail.com</a>. Thanks!<br><br>\
                  Found out that the ragged font display is caused by the alpha filter. \
                  IE7 <i>still</i> doesn\'t support opacity!<br>Anyway: this problem is solved now',
       uitlegAttr:'Een attribuut is een aanwijzing voor het internetprogramma over kenmerken \
                   van het html-element. Zo wordt bijvoorbeeld in de <span tt=1 ttxt="de onderdelen \
                   van een html-pagina worden met tags in de tekst gemarkeerd. Een tag is \
                   bijvoorbeeld &amp;lt;i> (<i>i</i>talic, cursief) of &amp;lt;b> (<b>b</b>old, \
                   vetgedrukt)" ttc="help" ttusestyle="dotline_red">tag</span> voor een tabel \
                   (&lt;table>) de breedte van zo\'n tabel aangegeven met het attribuut \
                   <i>width</i> => &lt;table width="550">'
    }   );
}

//testFunction checkbox
function returnCBTest()
{
 
 var self=arguments[0]||null,
     baseTxt ='Can we do checkboxes too? Ofcourse!<br>_chkmssg_<br>(this tooltip is persistent)';

 if (self){
  var evt=arguments[1];
  self.hideInfo();
  self.showInfo(evt);
  return;
 }

 return $('ch1').checked?baseTxt.replace(/_chkmssg_/i,'this box is now <b>checked</b>')
                        :baseTxt.replace(/_chkmssg_/i,'this box is now <b>unchecked</b>');
}

//some tests return text from function
function testJsFn()
{
  return 'this text is returned by me (me being: function [testJsFn])'
}

function returnMyAttributes()
{ 
  var Ela=this.attributes,retVal='';
   for (var i=0;i<Ela.length;i++)
    if (Ela[i].nodeName.match(/tt/i))
     retVal += (retVal==''?'':'<br>')+Ela[i].nodeName+'='+getAttrValue(this,Ela[i].nodeName)
  return retVal
}


//changeLog for tt3
function getChangeLog()
{ if (arguments[0])
    version = arguments[0]
   else
    version = settings.ttversion;

  return 'Links: <span style="color:red;cursor:pointer;-cursor:hand" \
 onclick="cTxt(\'id:uitleg\',\'topline\',\'Gebruiksaanwijzing\')" \
 title="klik voor gebruiksaanwijzing">terug gebruiksaanwijzing</span>\
 | <span style="color:red;cursor:pointer;-cursor:hand" \
 onclick="cTxt(\'id:explain\',\'topline\',\'User instructions\')" \
 title="click for user instructions">back to user instructions</span>\
 <pre style="font:9pt courier new">\
 tooltip library NICon/RK\n\
 ----------------------------------------------------------------\n\
 version '+version+'\n\
 date first 2006/07/05\n\
 if you want to use your own onload-handlers,\n\
 call this script in the page BODY\n\n\
 to do: retrieve tooltip text with ajax from server source\n\
 ----------------------------------------------------------------\n\
 20060925::include styling scriptwise\n\
 20061023::iframe src changed for use in SSL environment\n\
         ::cursor attribute added  \n\
 20061101::getAttrValue reworked for compatibility IE<6\n\
 20061107::added attributes\n\
           -ttNoOpa (no opacity)\n\
           -ttHeader (use value for header in tooltip)\n\
         ::removed attribute\n\
           -ttUseInner (buggy w/html inside element)\n\
         ::close link in header w/ttStatic\n\
         ::resize w/tooltip too heigh for viewport\n\
           and replace w/tooltip left side beyond zero      \n\
 20061109::added moveAttributes functionality: if \n\
           element w/tt activated contains children\n\
           the tooltip attributes are moved to the\n\
           last child en handlers are set accordingly.\n\
           Means one can set tooltips on a top level\n\
           element (like &lt;li>) where the innerHTML contains\n\
           formatting elements\n\
         ::added attribute ttHover \n\
           -value "[color]" where color = any html color \n\
            eg #EEE, #c0c0c0, red, green, or RGB(xxx,yyy,zzz) etc.\n\
 20061110::added attributes\n\
           -ttPersist: a tooltip with this attribute is \n\
            always active (overrides bUseTt=false)\n\
           -ttDescend: searches for most inner element and moves tt\n\
            to the found element\n\
 20061113::removed id change tt-elements. Interferes with \n\
            other element handlers and there\'s no need for\n\
            it anymore.\n\
         ::streamlined addHandlers\n\
           -elements with handlers in place are not\n\
            considered \n\
         ::added function changeTtTxt \n\
           -change tooltip text for ttStatic elements\n\
            to do IE-positioning\n\
 20061114::reworked ttDescend\n\
         ::added global ttContnr to be able to narrow\n\
           down tooltip use to one element and all elems\n\
           beyond that in the document *removed again\n\
         ::added the possibility to change text in static tooltip\n\
           from js-function [TxtFromJs]\n\
         ::added function reSize to be used after textchange\n\
 20061115::removed ttEL and added function [ttAddLoaders]\n\
           -no need to specify elements anymore, script checks\n\
            all elements in the doc and adds tooltip functionality\n\
            when applicable.\n\
          ::redo function reSize (better positioning after textchange)\n\
          ::changed tooltip dimensioning (width values max 12.5% of\n\
            actual screen width) and more accurate sizing of the \n\
            box itself\n\
          ::restore original text color after hover\n\
            (w/ttHovercolor set)\n\
 20061116::added function [getTtStyles]\n\
           -with classes tooltip/tooltipHeader/tooltipParagraph defined\n\
            in CSS those classes are used to build the tooltip. If \n\
            [one of] the classes are not present, a default style is\n\
            used\n\
          ::added exceptions for opera (9 beta: no stylesheets \n\
            enumeration, 9.02: not resolvable bad rendering of tooltip\n\
            font (buggy screen redrawal after innerHTML-change?))\n\
          ::added attributes:\n\
            -ttxtjs: add text from the predefined jsTxt collection \n\
             (see function TxtFromJs for text declarations)\n\
            -ttxtjsfn: add text from a javascript function\n\
             run a function that returns text for the tooltip. This\n\
             previsions Ajax functionality ;~)\n\
 20061117::major version change: now at 3.0\n\
           -static tooltips can contain tooltips, which can contain\n\
            tooltips, which ... ad infinitum. Tooltip properties, \n\
            methods and necessary objects are *all* bound to the \n\
            element containing the tooltip specifications.\n\
         ::added attributes:\n\
           -ttBGC: replace current background color with this value\n\
           -ttNestParent: if you want to nest tooltips within a text\n\
            that itself contains a tooltip, you have to specify the\n\
            id of the top level element\n\
 20061118::resolved a hoax of  boxwidth problems w/IE6\n\
         ::added tooltip on static box header\n\
 20061119::resolved a hoax of  problems w/IE6 && selectbox in html\n\
           document.\n\
         ::added INITS() constructor, which is used for all script-\n\
           settings. When tooltip-script is loaded, the settings are\n\
           usable from the [settings] object which is provided.\n\
           at runtime\n\
         ::added language independent functionallity. Set language\n\
           from within the object settings.\n\
 20061122::disregarded the iframe solution for select-elements (SE),\n\
           due to problems with multiple iframes in IE7.\n\
           Script now checks if SE overlaps the current tooltip and \n\
           hides the SE if so.\n\
           This only happens for IE version<7. User has a choice to \n\
           disable this via INITS() ie settings.hideSelects (t/f).\n\
         ::Lates OPERA still a NO GO. It renders the tooltip fonts \n\
           badly and doesn\'t always resizes the tooltip like expected.\n\
           For better font rendering OPERA9.02 beta is advised.\n\
         ::IE7 can do, but it doesn\'t render the tooltip font like\n\
           one should expect (no cleartype, even if cleartype is\n\
           explicitly set in the browsers options).n\
 20061124::added attribute ttxtURL: load text from a URL within the\n\
           current domain.\n\
         ::IE7 additional problem: positioning goes astray after\n\
           zooming the screen. IE is a bitch.\
           </pre>'
}

//genericPageLoader
function genLoad()
{
  if (!window.w){
   w=window;
   doc=document;
   rand = Math.random;
   rnd  =Math.round }

  if (!w.pageLoad){
   w._start = function() {
     this.loaders = new Object();
      if (!_start._init){
        var self = this;
        _start.prototype.execPageLoad = function() 
                                        { for (var fn in self.loaders) {
                                           if ((typeof self.loaders[fn]).match(/funct/i))
                                             self.loaders[fn]();
                                          }
                                        };
        _start.prototype.guid = function() {
           var sKey = '',isKey = '',aRanges = new Array('50,5','65,25','65,25');
             for (var i=0;i<arguments[0];i++)
             {
               var aRange  = String(aRanges[rnd(rand()*2)]).split(',');
               isKey      += String(aRanges[rnd(rand()*2)])+',';
               sKey       += String.fromCharCode(rnd(parseInt(aRange[0])+
                                         (rand()*parseInt(aRange[1])))) 
             }
           return sKey
        }
       } 
      _start._init=true
     };
    w.pageLoad = new _start();
     if (w.onload && !String(w.onload).match(/pageLoad\.exe/i))
      w.pageLoad.loaders['load'+pageLoad.guid(5)] = w.onload;
    w.onload=w.pageLoad.execPageLoad;
   } 
 }

function checkTtOO()
{
  var oBttn = $('onoffbttn');
  oBttn.innerHTML = bUseTt?'switch off tooltips':'switch on tooltips';
  return 'Switch all tooltips (except persistent ones) on/off.<br>At the moment tooltips are switched: '
          +(bUseTt?' <b>ON</b>':' <b>OFF</b>')
}

function resetLan()
{
  settings.LN.isEnglish?
   settings.LN=setLanguage('NL'):settings.LN=setLanguage('EN');

  if (arguments[1]&&arguments[2]&&arguments[1].showInfo){
   var evt=arguments[2]||window.event;
   arguments[1].hideInfo();
   arguments[1].showInfo(evt);
  }

  bIE?document.getElementsByTagName('body')[0].focus():arguments[1].blur();
}

function ttxtShowLanguage()
{ 
  return !settings.LN.isEnglish ?
    'Huidige taal (van een aantal script-meldingen) is Nederlands<br>(click to switch to English)' : 
    'current language (for a number of script notifications) is English<br>(klik om naar Nederlands over te schakelen)';
}

function loadInWin()
{
  return settings.LN.LoadURLInNewWin || 'no text?';
}

function getCloseMssg()
{
 return settings.LN.CloseBoxMessage;
}
