/*==================================================*
 $Id: gkutil.js ver 20090624
 Copyright 20093 gk@techtrade.se
 http://www.techtrade.se/

 *==================================================*/



// insertAdjacentHTML simply isn't a supported function. Add this to your script: 
//
// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement() 
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk 
// Usage: include this code segment at the beginning of your document 
// before any other Javascript contents. 

if(typeof HTMLElement!="undefined" && ! HTMLElement.prototype.insertAdjacentElement){ 

  HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode) { 
    switch (where){ 
      case 'beforeBegin': 
        this.parentNode.insertBefore(parsedNode,this) 
        break; 
      case 'afterBegin': 
        this.insertBefore(parsedNode,this.firstChild); 
        break; 
      case 'beforeEnd': 
        this.appendChild(parsedNode); 
        break; 
      case 'afterEnd': 
        if (this.nextSibling) 
        this.parentNode.insertBefore(parsedNode,this.nextSibling); 
      else this.parentNode.appendChild(parsedNode); 
        break; 
    } 
  } 
  
  HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr) { 
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    var parsedHTML = r.createContextualFragment(htmlStr);
    this.insertAdjacentElement(where,parsedHTML)
  } 
  
  
  HTMLElement.prototype.insertAdjacentText = function (where,txtStr) { 
    var parsedText = document.createTextNode(txtStr) 
    this.insertAdjacentElement(where,parsedText) 
    } 

}

//  http://www.faqts.com/knowledge_base/view.phtml/aid/5756


var dbgWin = null;
// var dbgWin = open("<%=appMap%>includes/script-debug.asp", "dbgWinId", "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=650, height=600, top=50, left=50")

var debugLevel = 1;

var dbgMsgBuffer = '';   /* used before scriptDebug is parsed */

function dbgMsg(level, msg) {
  if (debugLevel >= level) {
    if (dbgWin == null) {
      var dbgdiv = document.getElementById('scriptDebug');
      var msg2 = msg + '\n';
      if (dbgdiv != null) {
        if (dbgMsgBuffer.length > 0) {
          msg2 = dbgMsgBuffer
          msg2 += '\n######################################';
          msg2 += '\n';
          msg2 += msg + '\n';
          dbgMsgBuffer = '';
        }
        if (typeof HTMLElement != "undefined"){           /* firefox */
          var parsedText = document.createTextNode(msg2) 
          dbgdiv.appendChild(parsedText); 
        } else {                                          /* IE */
          dbgdiv.insertAdjacentText('beforeEnd', msg2);
        }
      } else {
        dbgMsgBuffer += msg2;
      }
    } else {
      var dbgdiv = dbgWin.document.getElementById('scriptDebug');
      if (dbgdiv != null) {
        var dbgbody = dbgWin.document.body;
        var msg2 = msg + '\n';
/*
        msg2 = msg2 + 'dbgbody.scrollTop = ' + dbgbody.scrollTop + '\n';
        msg2 = msg2 + 'dbgbody.scrollHeight = ' + dbgbody.scrollHeight + '\n';
        msg2 = msg2 + 'dbgbody.clientHeight = ' + dbgbody.clientHeight + '\n';
*/
        if (typeof HTMLElement != "undefined"){           /* firefox */
          var parsedText = document.createTextNode(msg2) 
          dbgdiv.appendChild(parsedText); 
        } else {                                          /* IE */
          dbgdiv.insertAdjacentText('beforeEnd', msg2);
        }
        dbgbody.scrollTop = dbgbody.scrollHeight - dbgbody.clientHeight - 0
      }

    }
  }
}




// ---------------------------------------------------------------
// yet another version by John Middlemas Apr 16, 2009 10:01 AM
// http://haacked.com/archive/2006/04/06/StopTheWindow.OnloadMadness.aspx
//
// usage:
//   addWinOnLoad(myInitFunction);
// or to pass arguments
//   addWinOnLoad(function(){myInitFunction(arg1)});

var addWinOnLoadCounter = 0;

function addWinOnLoad(func) {
  addWinOnLoadCounter++;
  if(window.addEventListener && !window.opera) { 
    // Firefox 1.5+, Gecko/Mozilla 1.0.1+, Konqueror, Safari 3.0, Google Chrome
    window.addEventListener('load', func, false)
    dbgMsg(1, 'addWinOnLoad #' + addWinOnLoadCounter + ' addEventListener');
  } else if (window.attachEvent) {
    // Microsoft IE 5+, Opera 8.0+
    window.attachEvent('onload', func)
    dbgMsg(1, 'addWinOnLoad #' + addWinOnLoadCounter + ' attachEvent');
  } else { // Incomplete solution
    // Add func to any existing window.onload.
    // Any later inconsiderate window.onload can
    // overwrite the window.onload set here
//  alert('hejsan');
    var o=window.onload
    window.onload = function() { o ? o() : o;func() }
    dbgMsg(1, 'addWinOnLoad #' + addWinOnLoadCounter + ' onload');
  }
//  alert('hejsan');
  return
}


// ---------------------------------------------------------------
//
//   usage: addEvent(window, 'load', myInitFunction);

var addEventCounter = 0;

function addEvent(obj, evnt, func) {
  addEventCounter++;
  if(window.addEventListener) {                                 // Mozilla, Netscape, Firefox, Google Chrome
    obj.addEventListener(evnt, func, false);
    dbgMsg(1, 'addEvent #' + addEventCounter + ' addEventListener');
  } else {                                                      // IE
    obj.attachEvent('on' + evnt, func);
    dbgMsg(1, 'addEvent #' + addEventCounter + ' attachEvent');
  }
}




// ---------------------------------------------------------------
// adding flashing effect to SPAN elements
// by gk 2009-06-24 22:18
//
// usage:
//   <span class="flashing">slowly flashing text</span>
// ---------------------------------------------------------------

(function(){  /* block scope */

  /* some code with block scope variables */

  var flashTimer = null;
  var flashInterval = 50;              // in ms (default)
  var flashClassColl = new Array();    // flashing SPAN elements
  var foundFlashElements=0;
  var flash=0;                         // starting from black
  var flashStep=1;
  var dflash=flashStep;


  function doFlash(){
  //	flash+=dflash;
  //	dflash=(flash<0||flash>255)?-dflash:dflash;
  //	flash=Math.max(0,flash);
  //	flash=Math.min(255,flash);
  
  	flash+=dflash;
  	if (flash <= 8 )
    	flash+=dflash*4;
  	if (flash <= 0 ) {
  	  flash = 0;
  	  dflash = flashStep;
  	} else if (flash >= 15 ) {
  	  flash = 15;
  	  dflash = -flashStep;
  	}
  	
  //	flashClass.style.color="rgb("+flash+","+flash+","+flash+")";
  
  //var flashColor = flash*65536 + flash*256 + flash;                          //fungerar EJ i FF
  //var flashColor = "rgb(" + flash + ", " + flash + ", " + flash + ")";
  //  var flashColor = '#' + (flash*65536 + flash*256 + flash).toString(16);
  
  //var flashColorHex = '000000' + (flash*65536 + flash*256 + flash).toString(16);
  //var flashColor = '#' + flashColorHex.substr(flashColorHex.length - 6);
  
  //var flashHex = (((flash < 16) ? '0' : '') + flash.toString(16)).substr(0,1);
  //var flashHex = ((flash < 16) ? '0' : '') + flash.toString(16);
    var flashHex = flash.toString(16);
    var flashColor = '#' + flashHex + flashHex + flashHex;
  
  
  //  document.getElementById("flashElement1").style.color = flashColor;
  //  document.getElementById("orTotals").style.color = flashColor;
  //document.getElementById("flashElement1").style.textDecoration = 'blink';
  
  //window.status = 'flashColor = ' + flashColor;
    for (var i=0; i<flashClassColl.length; i++) {
      flashClassColl[i].style.color = flashColor;
    }
  
  }
  
  function initFlashClassColl(fInt) {
    if (fInt > 10) {
      flashInterval = fInt;
    }
    var aSpans = document.getElementsByTagName("SPAN");
  //for (elementx in aSpans) {
    for (var i=0;i<aSpans.length;i++) {
      var elementx = aSpans[i];
      if (elementx != null) {
        var cn = elementx.className;
        if (cn != null) {
          if ((' ' + cn + ' ').indexOf(' flashing ') > -1)  {
            flashClassColl[foundFlashElements++] = elementx;
            dbgMsg(1, 'adding flashing ' + foundFlashElements);
          }
        }
      }
    }
  
  /*  
   alert('initFlashClassColl()\n  aSpans.length=' + aSpans.length +
         '\n  foundFlashElements=' + foundFlashElements +
         '\n  flashClassColl.length=' + flashClassColl.length);
  */
    
    if (foundFlashElements > 0)  {
      flashTimer = setInterval(doFlash, flashInterval);
    }
  }
  
  
  
  //addOnloadEvent(initFlashClassColl);
  //addOnloadEvent(function(){initFlashClassColl(400)});
  
  //addWinOnLoad(initFlashClassColl);
  dbgMsg(1, 'calling addWinOnLoad(function(){initFlashClassColl(100)})');
  addWinOnLoad(function(){initFlashClassColl(100)});


}());




// ---------------------------------------------------------------
// adding blinking effect to DIV elements
// by gk 2011-03-04 15:12
//
// usage:
//   <div class="flashing">blinking background</div>
// ---------------------------------------------------------------

(function(){  /* block scope */

  /* some code with block scope variables */

  var flashTimer = null;
  var flashInterval = 50;              // in ms (default)
  var flashClassColl = new Array();    // flashing SPAN elements
  var flashBackColor = new Array();    // flashing SPAN elements
  var flashPosTop = new Array();    // flashing SPAN elements
  var flashPosLeft = new Array();    // flashing SPAN elements
  var foundFlashElements=0;
  var flash=0;                         // starting from black
  var flashStep=1;
  var flashBorderWidth=1;
  var dflash=flashStep;
  var flashPointer=0;
  var linkHover=-1;
  var blinkPhase=0;


  function doFlash(){
  //	flash+=dflash;
  //	dflash=(flash<0||flash>255)?-dflash:dflash;
  //	flash=Math.max(0,flash);
  //	flash=Math.min(255,flash);


    if (0) {
  
    	flash+=dflash;
    	if (flash <= 8 )
      	flash+=dflash*4;
    	if (flash <= 0 ) {
    	  flash = 0;
    	  dflash = flashStep;
    	} else if (flash >= 15 ) {
    	  flash = 15;
    	  dflash = -flashStep;
    	}
    	
    //	flashClass.style.color="rgb("+flash+","+flash+","+flash+")";
    
    //var flashColor = flash*65536 + flash*256 + flash;                          //fungerar EJ i FF
    //var flashColor = "rgb(" + flash + ", " + flash + ", " + flash + ")";
    //  var flashColor = '#' + (flash*65536 + flash*256 + flash).toString(16);
    
    //var flashColorHex = '000000' + (flash*65536 + flash*256 + flash).toString(16);
    //var flashColor = '#' + flashColorHex.substr(flashColorHex.length - 6);
    
    //var flashHex = (((flash < 16) ? '0' : '') + flash.toString(16)).substr(0,1);
    //var flashHex = ((flash < 16) ? '0' : '') + flash.toString(16);
      var flashHex = flash.toString(16);
      var flashColor = '#' + flashHex + flashHex + flashHex;
      var flashColor = '#' + 'F' + flashHex + flashHex;
    
    
    //  document.getElementById("flashElement1").style.color = flashColor;
    //  document.getElementById("orTotals").style.color = flashColor;
    //document.getElementById("flashElement1").style.textDecoration = 'blink';
    
    //window.status = 'flashColor = ' + flashColor;
      for (var i=0; i<flashClassColl.length; i++) {
  //    flashClassColl[i].style.color = flashColor;
        flashClassColl[i].style.backgroundColor = flashColor;
      }


            
    } else if (linkHover < -100) {

        if (blinkPhase == 0) {
          flashOff(linkHover)
        } else {
          flashOn(linkHover)
        }
        blinkPhase++;
        blinkPhase %= 2;

    } else if (foundFlashElements == 1 || linkHover > -1) {

        if (blinkPhase == 0) {
          flashOff(flashPointer)
        } else {
          flashOn(flashPointer)
        }
        blinkPhase++;
        blinkPhase %= 2;

    } else {

      flashOff(flashPointer)

      flashPointer++;
      flashPointer %= foundFlashElements;

      flashOn(flashPointer)


    }

  
  }

  function flashOff(i) {
    flashClassColl[i].style.backgroundColor = flashBackColor[i];
    flashClassColl[i].style.borderWidth = '0';
    flashClassColl[i].style.top = flashPosTop[i] + 'px';
    flashClassColl[i].style.left = flashPosLeft[i] + 'px';
  }

  function flashOn(i) {
    flashClassColl[i].style.backgroundColor = "#F00";
    flashClassColl[i].style.borderWidth = flashBorderWidth + 'px';
    flashClassColl[i].style.top = (flashPosTop[i] - flashBorderWidth) + 'px';
    flashClassColl[i].style.left = (flashPosLeft[i] - flashBorderWidth) + 'px';
  }


  function mapLinkMouseOver1(e) {
    if (typeof(e) == 'undefined') {
      e = window.event;           
      var s = e.srcElement;           
      dbgMsg(1, 'mapLinkMouseOver: e = false id = ' + 's.id');
    } else {
      var s = e.target;              
//    dbgMsg(1, 'mapLinkMouseOver: e = true id = ' + s.id);   // ok in FF, fail in IE
      dbgMsg(1, 'mapLinkMouseOver: e = true typeof(e) = ' + typeof(s));   // ok in FF, fail in IE
    }


  }


  function mapLinkMouseOver(e) {
    var msg = 'mapLinkMouseOver:';
    if (window.event) {                   // IE
      var s = window.event.srcElement;           
      msg += ' IE   ';
    } else {                              // other
      var s = e.target;              
      msg += ' other';
    }
//  msg += '  typeof(e) = ' + typeof(e) + '  typeof(s) = ' + typeof(s);
    msg += '  s.id = ' + s.id;
    dbgMsg (1, msg)


    var mapLinkId = s.id;
    var j = mapLinkId.indexOf('_');
    dbgMsg(1, 'j = ' + j);
    if (j > -1) {
      var nId = mapLinkId.substr(j);
      dbgMsg(1, 'nId = ' + nId);
      var mapMark = document.getElementById('mapMark' + nId);
      if (mapMark != null) {
        for (var i=0;i<flashClassColl.length;i++) {
          if (flashClassColl[i].id == 'mapMark' + nId) {
            flashOff(flashPointer)
            flashPointer = i;
            linkHover = i;
            break;
          }
        }

      }
    }

  }


  function mapLinkMouseOut() {
    if (linkHover > -1) {
      flashOff(linkHover);
      linkHover = -1;
    }
  }


  
  function initFlashClassColl(fInt) {
    if (fInt > 10) {
      flashInterval = fInt;
    }
    var aSpans = document.getElementsByTagName("DIV");
  //for (elementx in aSpans) {
    for (var i=0;i<aSpans.length;i++) {
      var elementx = aSpans[i];
      if (elementx != null) {
        var cn = elementx.className;
        if (cn != null) {
          if ((' ' + cn + ' ').indexOf(' blinking ') > -1)  {
            flashClassColl[foundFlashElements] = elementx;
            flashBackColor[foundFlashElements] = elementx.style.backgroundColor;
            flashPosTop[foundFlashElements] = parseInt(elementx.style.top);
            flashPosLeft[foundFlashElements] = parseInt(elementx.style.left);
            foundFlashElements++;
            dbgMsg(1, 'adding blinking ' + foundFlashElements);

            var mapMarkId = elementx.id;
            var j = mapMarkId.indexOf('_');
            dbgMsg(1, 'j = ' + j);
            if (j > -1) {
              var nId = mapMarkId.substr(j);
              dbgMsg(1, 'nId = ' + nId);
              var mapLink = document.getElementById('mapLink' + nId);
              if (mapLink != null) {
                addEvent(mapLink, 'mouseover', mapLinkMouseOver);
                addEvent(mapLink, 'mouseout', mapLinkMouseOut);

              }
            }


          }
        }
      }
    }
  
  /*  
   alert('initFlashClassColl()\n  aSpans.length=' + aSpans.length +
         '\n  foundFlashElements=' + foundFlashElements +
         '\n  flashClassColl.length=' + flashClassColl.length);
  */
    
    if (foundFlashElements > 0)  {
      flashTimer = setInterval(doFlash, flashInterval);
    }
  }
  
  
  
  //addOnloadEvent(initFlashClassColl);
  //addOnloadEvent(function(){initFlashClassColl(400)});
  
  //addWinOnLoad(initFlashClassColl);
  dbgMsg(1, 'calling addWinOnLoad(function(){initFlashClassColl(100)})');
  addWinOnLoad(function(){initFlashClassColl(250)});


}());








function script_onload() {
  var msg = '';

  msg += '\n[gkutil:script_onload begin]------------------------------------------------------\n'

  msg += GetScriptEngineInfo();

  msg += showLoadedScripts();

  msg += showLoadedStyleSheets();

  msg += showClientInformation();

  msg += showNavigator();
  
  msg += showAllCookies();

  msg += '[gkutil:script_onload end]------------------------------------------------------\n'
  
//  msg = msg + 'gksortImgDir = \'' + gksortImgDir + '\'';

  if (0) {
    msg += showDims(document.body);
    msg += showDims(document.getElementById('layoutTable'));
  
    msg += showDims(document.getElementById('layoutTableTopRow'));
    msg += showDims(document.getElementById('layoutTableTopTD'));
  }

  dbgMsg(1, msg);

}

function GetScriptEngineInfo() {
  var s = ''; // Build string with necessary info.
  s += '---------------------------\n'
//s += typeof(ScriptEngine) + '\n';
  s += 'ScriptEngine = ';
  if (typeof(ScriptEngine) == 'undefined') {
    s += 'undefined';
  } else {
    s += ScriptEngine() + ' Version ';
    s += ScriptEngineMajorVersion() + '.';
    s += ScriptEngineMinorVersion() + '.';
    s += ScriptEngineBuildVersion();
  }
  s += '\n'
//s += '---------------------------\n'
  return(s);
}



// show all Loaded Scripts.
function showLoadedScripts() {
  var msg = '';
  msg = msg + '---------------------------\n'
  var ds = document.scripts;
  if (ds != null) {
    msg = msg + 'loaded scripts\n';
    msg = msg + 'script (type id src)\n';
    for (var i=0; i<ds.length; i++) {
      msg = msg + '[' + (i + 0) + ']';
      if (ds[i].type)             msg = msg + '  type=' + ds[i].type
      if (ds[i].id)               msg = msg + '  id=' + ds[i].id
      if (ds[i].src)              msg = msg + '  src=' + ds[i].src
      msg = msg + '\n'
    }
  } else {
    msg = msg + 'no .scripts found\n'
  }
  return msg;
}

// show all Loaded StyleSheets.
function showLoadedStyleSheets() {
  var msg = '';
  msg = msg + '---------------------------\n'
  ds = document.styleSheets;
  if (ds != null) {
    msg = msg + 'loaded styleSheets\n';
    msg = msg + 'styleSheet (type id title href parentStyleSheet.href)\n';
    for (var i=0; i<ds.length; i++) {
      msg = msg + '[' + (i + 0) + ']'
      if (ds[i].type)             msg = msg + '  type=' + ds[i].type
      if (ds[i].id)               msg = msg + '  id=' + ds[i].id;
      if (ds[i].title)            msg = msg + '  title=' + ds[i].title;
      if (ds[i].href)             msg = msg + '  href=' + ds[i].href
      if (ds[i].parentStyleSheet) msg = msg + '  parentStyleSheet.href=' + ds[i].parentStyleSheet.href;
      msg = msg + '\n'
    }
  } else {
    msg = msg + 'no .styleSheets found\n'
  }

  return msg;
}


// Retrieve ClientInformation.
function showClientInformation() {
  var msg = '';
  msg = msg + '---------------------------\n'
  msg = msg + 'ClientInformation' + '\n';
//  if (typeof(window.clientInformation) != 'undefined') {
  if (window.clientInformation) {
    msg = msg + '  cookieEnabled = ' + window.clientInformation.cookieEnabled + '\n';
    msg = msg + '  javaEnabled() = ' + window.clientInformation.javaEnabled() + '\n';
  } else {
    msg = msg + '  window.clientInformation is not available\n';
  }
  return msg;
}


// Retrieve ClientInformation.
function showNavigator() {
  var msg = '';
  msg = msg + '---------------------------\n'
  msg = msg + 'Navigator' + '\n';

//http://www.w3schools.com/js/js_try_catch.asp
  try {

  //  if (typeof(window.clientInformation) != 'undefined') {
    if (window.navigator) {
      msg = msg + '  appCodeName = '     + window.navigator.appCodeName + '\n';
      msg = msg + '  appMinorVersion = ' + window.navigator.appMinorVersion + '\n';
      msg = msg + '  appName = '         + window.navigator.appName + '\n';
      msg = msg + '  appVersion = '      + window.navigator.appVersion + '\n';
      msg = msg + '  browserLanguage = ' + window.navigator.browserLanguage + '\n';
      msg = msg + '  cookieEnabled = '   + window.navigator.cookieEnabled + '\n';
      msg = msg + '  cpuClass = '        + window.navigator.cpuClass + '\n';
      msg = msg + '  onLine = '          + window.navigator.onLine + '\n';
      msg = msg + '  platform = '        + window.navigator.platform + '\n';
      msg = msg + '  systemLanguage = '  + window.navigator.systemLanguage + '\n';
      msg = msg + '  userAgent = '       + window.navigator.userAgent + '\n';
  

      msg = msg + '  typeof(javaEnabled) = '   + typeof(window.navigator.javaEnabled) + '\n';
      msg = msg + '  typeof(taintEnabled) = '   + typeof(window.navigator.taintEnabled) + '\n';
  
//    if (window.navigator.javaEnabled != null) {
      if (typeof(window.navigator.javaEnabled) != 'undefined') {
        msg = msg + '  javaEnabled() = '   + window.navigator.javaEnabled() + '\n';
      }
  
//    if (window.navigator.taintEnabled != null) {
    if (typeof(window.navigator.taintEnabled) != 'undefined') {
        msg = msg + '  taintEnabled() = '  + window.navigator.taintEnabled() + '\n';
      }

/*  

      msg = msg + '  javaEnabled() = '   + window.navigator.javaEnabled() + '\n';
      msg = msg + '  taintEnabled() = '  + window.navigator.taintEnabled() + '\n';
*/
      
      msg = msg + '  plugins.length = '  + window.navigator.plugins.length + '\n';
  
      pl = window.navigator.plugins;
      for (var i=0; i<pl.length; i++) {
        msg = msg + '[' + (i + 0) + ']'
        if (pl[i].name)             msg = msg + '  name=' + pl[i].name
        if (pl[i].type)             msg = msg + '  type=' + pl[i].type
        if (pl[i].title)            msg = msg + '  title=' + pl[i].title;
        if (pl[i].src)              msg = msg + '  src=' + pl[i].src
        if (pl[i].tagName)          msg = msg + '  tagName=' + pl[i].tagName
        
        msg = msg + '\n'
      }
  
  
    } else {
      msg = msg + '  window.navigator is not available\n';
    }

   } catch(errorObject) {
      msg += "\n**********************\n"
      msg += "There was an error on this page.\n\n"
      msg += "An internal programming error may keep\n"
      msg += "this page from displaying properly.\n"
      msg += "Click OK to continue.\n\n"
      msg += "Error number: " + (errorObject.number & 0xffff) + "\n"
      msg += "Description: " + errorObject.description + "\n"
      msg += "**********************\n\n"
//    alert(msg)
   }

  return msg;
}



// Retrieve the value of the cookie with the specified name.
function showAllCookies() {
  var msg = '';
  msg = msg + '---------------------------\n'
  if (document.cookie) {
    // cookies are name=value pairs separated by semicolon+space
    // value in an indexed cookie is keyName=keyValue pairs separated by ampersand
    var cookies = document.cookie.split("; ");
    msg = msg + 'Cookies [' + cookies.length + ']\n';

    for (var i=0; i < cookies.length; i++) {
      var eqSepIndex = cookies[i].indexOf("=");
      var cValLength = cookies[i].length - eqSepIndex + 1;
      var cValStart = eqSepIndex + 1;

      var cName = cookies[i].substring(0, eqSepIndex).replace(/\+/g, ' ')
      var cValue = cookies[i].substring(cValStart).replace(/\+/g, ' ')

      var haskeys = (cValue.indexOf("=") > -1);

      msg = msg + '[' + (i + 0) + ']  ';
      msg = msg + unescape(cName) + ' = ' + (haskeys?cValue:unescape(cValue)) + '\n';

      if (haskeys) {
        var sCrumb = cValue.split("&");
        for (var j=0; j < sCrumb.length; j++) {
          var aCrumb = sCrumb[j].split("=");
          msg = msg + '[' + i + '.' + j + ']  ';
          msg = msg + unescape(aCrumb[0]) + ' = ' + unescape(aCrumb[1]) + '\n';
        }
      }
    }

  } else {
    msg = msg + 'Cookies' + '\n';
    msg = msg + '  document.cookie is not available\n';
  }

  // a cookie with the requested name does not exist
  return msg;
}


function showDims(obj) {
  var msg = '';
  msg = msg + '---------------------------\n'
  msg = msg + 'showDims: ' + obj.tagName + '\n';


  msg = msg + '     offsetTop = ' + obj.offsetTop + '\n';          /* in parent */
  msg = msg + '  offsetHeight = ' + obj.offsetHeight + '\n';       /* in parent */
  msg = msg + '     clientTop = ' + obj.clientTop + '\n';          /* including padding, but not including margin, border, or scroll bar*/
  msg = msg + '  clientHeight = ' + obj.clientHeight + '\n';       /* including padding, but not including margin, border, or scroll bar*/
  msg = msg + '     scrollTop = ' + obj.scrollTop + '\n';          /* document  */
  msg = msg + '  scrollHeight = ' + obj.scrollHeight + '\n';       /* document  */

  msg = msg + '\n';
  msg = msg + '     style.top = ' + obj.style.top + '\n';             /*           */
  msg = msg + '  style.height = ' + obj.style.height + '\n';             /*           */
//msg = msg + '   style.width = ' + obj.style.width + '\n';             /*           */

  msg = msg + '    style.pixelTop = ' + obj.style.pixelTop + '\n';             /*           */
  msg = msg + ' style.pixelHeight = ' + obj.style.pixelHeight + '\n';             /*           */

//alert(msg);

  return msg;
}



dbgMsg(1, 'calling addWinOnLoad(script_onload)');
addWinOnLoad(script_onload);


/* ------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------ */

var showcoords=false;
var relCoords=false;
var posType=0;
var absCoordX=0;
var absCoordY=0;
var relZeroX=0;
var relZeroY=0;
var relCoordX=0;
var relCoordY=0;
var gkMoveElementObj = null;
var gkMoveElementStartX = 0;
var gkMoveElementStartY = 0;

function initShowCoords(scObjIn) {

  var scObj = null;
  
  scObj = document.body;

  if (scObj != null) {
//    showcoords = true;
    showcoords = false;
//    scObj.attachEvent("onmousemove", scObjMouseMove);
//    scObj.attachEvent("onmouseup", scObjMouseUp);

    dbgMsg(1, 'calling addEvent() * 3 mouse events');
    addEvent(scObj, 'mousedown', scObjMouseDown);
    addEvent(scObj, 'mousemove', scObjMouseMove);
    addEvent(scObj, 'mouseup', scObjMouseUp);

//    scObj.style.cursor = 'crosshair';
  }
}

function gkMoveElement() {
  gkMoveElementObj.style.pixelLeft = gkMoveElementStartX + relCoordX;
  gkMoveElementObj.style.pixelTop = gkMoveElementStartY + relCoordY;
}


function scObjMouseDown(e) {
  setMouseCoords(e);
  relZeroX=absCoordX;
  relZeroY=absCoordY;
  relCoordX = absCoordX - relZeroX;
  relCoordY = absCoordY - relZeroY;
  scObjShowCoords();
  if (gkMoveElementObj != null) {
    gkMoveElementStartX = gkMoveElementObj.style.pixelLeft;
    gkMoveElementStartY = gkMoveElementObj.style.pixelTop;
  }
}

function scObjMouseMove(e) {
  setMouseCoords(e);
  scObjShowCoords();
  if (gkMoveElementObj != null) {
    gkMoveElement();
    return false;
  }
}

function scObjMouseUp(e) {
  setMouseCoords(e);
  gkMoveElementObj = null;
  scObjShowCoords();
  e=e?e:window.event;
  if ((e.altKey) == 1 && e.button == 2) {             // e.ctrlKey & e.shiftKey
    showcoords = !showcoords;
    document.body.style.cursor = showcoords?'crosshair':'auto';
    window.status = 'showcoords = ' + (showcoords?'on':'off');
    window.event.cancelBubble = true;
    return false;
  }
//    window.status = 'mouseUp';

  
}

// } else if (document.documentElement && document.documentElement.scrollTop) {
    // IE 6 strict mode

// *********************************************************************
// http://www.quirksmode.org/js/events_properties.html
// 
// *********************************************************************
function setMouseCoords(e) {
	var x = 0;
	var y = 0;
	if (!e) var e = window.event;

	if (e.pageX || e.pageY) 	{                     // FF
		x = e.pageX;
		y = e.pageY;
		posType = 1;

	}	else if (e.clientX || e.clientY) 	{           // IE
		x  = e.clientX;
//	x += document.body.scrollLeft;
		x += document.documentElement.scrollLeft;

		y  = e.clientY;
//	y += document.body.scrollTop;
		y += document.documentElement.scrollTop;

    if (typeof document.body.style.maxHeight != "undefined") {
      // IE 7, mozilla, safari, opera 9
  		posType = 2;

    } else {
      // IE6, older browsers
  		x -= 2;
  		y -= 2;
  		posType = 3;
    }


	}
	// x and y contain the mouse position relative to the document
	// Do something with this information
  absCoordX = x;
  absCoordY = y;
  relCoordX = absCoordX - relZeroX;
  relCoordY = absCoordY - relZeroY;

}



function scObjShowCoords() {
  if (showcoords == true) {
    var m = '';

//  m += '  d.b.scrollTop = ' + document.body.scrollTop;
//  m += '  d.dE.scrollTop = ' + document.documentElement.scrollTop;
//  m += '  d.dE.scrollLeft = ' + document.documentElement.scrollLeft;


    m += '(' + posType + ')';
  
    m += ' abs: ';
    m += 'x = ' + absCoordX + '  ';
    m += 'y = ' + absCoordY;
  
    m += ' ref: ';
    m += 'x = ' + relZeroX + '  ';
    m += 'y = ' + relZeroY;
  
    m += ' rel: ';
    m += 'x = ' + ((relCoordX > -1) ? '+':'') + relCoordX + '  ';
    m += 'y = ' + ((relCoordY > -1) ? '+':'') + relCoordY;
  
  
  
  
    window.status = m;
  }
}

dbgMsg(1, 'calling addWinOnLoad(initShowCoords)');
addWinOnLoad(initShowCoords);



