/*************************************************

  www.curc.ca :: CURC
  000b-script/00a.default-utils.js
  common utility scripts
  2005 :: v050607 rev080310

 *************************************************/


//.....  AUTORUN/ONLOAD SCRIPT:
//.....  autoRun() executes all functions contained in autorunList$ UPON LOAD;
//.....  add functions by appending them to autorunList$ [ie autorunList$ += 'newFunction();'];
//.....  window.onload is over-ridden by body.onload, therefor if you use body.onload,
//.....     include your functions as arguments to runthis()
//.....       example: <body onload="runthis('self.focus();');">
//.....       example will execute self.focus(), followed by everything
//.....       in the autoRun list;


  // set autoRun to run on load:
    window.onload = autoRun;
    var autorunList$ = (autorunList$)? autorunList$ : '';

  // the autoRun script:
    function autoRun()
      {
      eval(autorunList$)
      }

  // alternate script for page-level inclusion [use: onload="runthis(funct1(); funct2(); ...;)" ]:
    function runthis(function$)
      {
      eval(function$)
      autoRun()
      }



//.....  DE-CLOAKING SCRIPT:
//.....  script runs onload;
//.....  searches document for span.ecloak nodes;
//.....  replaces span.ecloak.innerHTML with standard html markup <a href>;
//.....  script is invisible to non-scripted browsers;
//.....  if script fails or is ignored, then hard-coded human-readable address remains:

  // check if autorunList$ exists and has value:
    var autorunList$ = (autorunList$)? autorunList$ : '';
  // add cloaker() to autorunList$ for autoRun() [see defaults.js]:
    autorunList$ += 'cloaker();'

  function cloaker()
    {
      var spanslist$$ = document.getElementsByTagName('span');
      var regex$$ = new Array(/<!--[^>]*-->/gi,/[ ]*\[at\][ ]*/gi,/[ ]*\[dot\][ ]*/gi);
      var swap$$ = new Array('','@','.');
      var whitespace = /[ ]/g;

    for(var i=0; i<spanslist$$.length; i++)
      {
      if(spanslist$$[i].className.indexOf('ecloak')>(-1) && spanslist$$[i].innerHTML.indexOf('[at]') > (-1))
        {

      // capture cloaked textnode:
        var oldcode = spanslist$$[i].innerHTML;

      // split out query$ to preserve:
        var querysplit$$ = oldcode.split('(');
        var query$ = (querysplit$$[1])? querysplit$$[1].replace(/[")]/g,'') : '';
        query$ = query$.replace(/[ ]*=[ ]*/g,'=');

if(spanslist$$[i].parentNode.id == 'disclosure')
  {
  var uri = document.location.href;
  var underscore$ = '%0A[2] (please leave these lines in your message)%0A%0A%0A';
  var body$ = 'body=[1] mssgRefUri = ' + uri + underscore$;
  query$ += (query$)? '&' + body$ + '&subject=':'?' + body$;
  }

        query$ = escape(query$);


      // remove comments && swap out placeholder tokens:
        for(ii=0; ii<regex$$.length; ii++)
          {
          querysplit$$[0] = querysplit$$[0].replace(regex$$[ii],swap$$[ii]);
          }

      // split out link$:
        var linksplit$$ = querysplit$$[0].split(':');
        var thelink = (linksplit$$[1])? linksplit$$[0] : linksplit$$[0].replace(whitespace,'');

      // assemble href:
        var theaddr = (linksplit$$[1])? linksplit$$[1].replace(whitespace,'') : linksplit$$[0].replace(whitespace,'');
        if(query$) theaddr += ('?' + query$);


      // assemble replacement node:
        var newcode = '<a h';
          newcode += 'ref="mai';
          newcode += 'lto:' + theaddr + '">' + thelink + '<\/';
          newcode += 'a>';
        var newclass = spanslist$$[i].className.replace('ecloak','eplain');

      // update textnode:
        spanslist$$[i].innerHTML = newcode;

      // update class:
        spanslist$$[i].className = newclass;

        }
      }
    }




//***** general functions:  ***********************


//... for [more] precisely sizing containing element to window height:

function setheight(thiselement,windowreduction)
  {
  if(!windowreduction || windowreduction != 0) var windowreduction = 10;
    /* ----------------------------------------------
    |  windowreduction is the size (in px) to crop   |
    |  from the browser's current window height in   |
    |  order to allow for template, etc.             |
     ---------------------------------------------- */
  var htmlObj = document.getElementsByTagName('html')[0];
  var thisObj = document.getElementById(thiselement);
  thisObj.style.height = (htmlObj.clientHeight - windowreduction)+'px';
  if(navigator.appName.indexOf('Microsoft')>-1) thisObj.style.height = (htmlObj.clientHeight - windowreduction)+'px';
//alert('height adjusted to '+(htmlObj.clientHeight-windowreduction));
  }


// .......... Soft Dog WebWorks : webmanager.curc [at] thesoftdog [dot] com .......... //
