//<script language="javascript">
/*=============================================================================
 WebSolvers Framework Library
 Copyright 2003, WebSolvers, Inc., All Rights Reserved.

 Library 
 Cross-Browser/Platform common library

 Revision History:
 6-26-03 Created

 Public Functions:
  cint(num)   - Casts a variable to an integer.
  cdbl(num)   - Casts a variable to a floating point.
  cnum(num)   - Casts a variable to etiher an int or float depending
            on the contents.
            
  processDHTML(id) - start dhtml code processing on the element and its children.

 Public Object:
  dhtml     - Provides basic cross/browser code base for other functions
  
=============================================================================

 The WebSolvers Framework Library may be used and/or modified by anyone owning
 the original work as it was incorporated into an original development project
 so long as this copyright notice and the comments above remain intact.

 By using this code you agree to indemnify WebSolvers, Inc. from any liability
 that might arise from its use.

 This code may not be sold exclusively or as a part of other code without prior
 written consent and is expressly forbidden.

 Obtain permission before redistributing this software over the Internet or
 in any other medium. In all cases the copyright and header must remain intact.
============================================================================= */

function cint(num) {
  var cmp = '-0123456789,';
  var cmp2 = ',';
  if(!num && num != 0)
    return NaN;
    
  if(cmp.diff(num.toString()).length)
    return NaN;
  else
    return parseInt(cmp2.diff(num.toString()), 10);
}

function cdbl(num) {
  var cmp = '-0123456789.,$';
  var cmp2 = '$,';
  var per = num.toString().indexOf('%');

  if(!num && num != 0)
    return NaN;

  if(per > -1) {
    num = num.toString().substr(0, per) + num.toString().substr(per+1);
  }
  
  if(cmp.diff(num.toString()).length)
    return NaN;
  else if(per > -1)
    return parseFloat(cmp2.diff(num.toString()))/100;
  else
    return parseFloat(cmp2.diff(num.toString()));
}

function cnum(num) {
  var cmp = ".$%";

  if(!num && num != 0)
    return NaN;

  if(cmp.diff(num.toString()).length)
    return cdbl(num);
  else
    return cint(num);
}

if (typeof((new String()).trim) == "undefined") {
  String.prototype.trim = function(lr) {
    var start=0; end=this.length;

    if(lr != 0)
      while((this.substring(start, start+1) == ' ') && (start < end))
        start++;
        
    if(!lr)
      while((this.substring(end-1, end) == ' ') && (end > start))
        end--;
    
    return this.substring(start, end);
  }
  
  String.prototype.ltrim = function anonymous() { return this.trim(1); };
  String.prototype.rtrim = function anonymous() { return this.trim(0); };
}

if (typeof((new String()).diff) == "undefined") {
  String.prototype.diff = function (compare, lc) {
    var diff = "";
    var cmp = this, cmp2 = compare;
    if(lc) {
      cmp = this.toLowerCase();
      cmp2 = compare.toLowerCase();
    }
  
    for(var i = 0; i < cmp2.length; i++)
      if(!lc && cmp.indexOf(cmp2.substr(i, 1)) == -1)
        diff += compare.substr(i, 1);
  
    return diff;
  }
}

if (typeof((new String()).toNumber) == "undefined") {
  String.prototype.toNumber = function() {
    return cnum(this);
  }
}

//--- Some version of IE for the mac forgot how to push.
if (typeof((new Array()).push) == "undefined") {
 Array.prototype.push = function() {
    for (var i = 0 ; i < arguments.length ; i++) {
      this[this.length] = arguments[i];
    }
  }
}

//--- Some version of IE for the mac forgot how to pop as well.
if (typeof((new Array()).pop) == "undefined") {
 Array.prototype.pop = function() {
    var res = this[0];
        
    for(var i = 1 ; i < arguments.length; i++) {
      this[i-1] = this[i];
    }
    this.length--;
        
    return res;
  }
}

//--- indexOf is so usefull, why did they not include it?.
if (typeof((new Array()).indexOf) == "undefined") {
 Array.prototype.indexOf = function(search,lc) {
    var idx = -1;
          
    for(idx = 0; idx < this.length; idx++) {
      if(lc && this[idx].toString().toLowerCase() == search.toString().toLowerCase())
        return idx;
      else if(this[idx] == search)
        return idx;
    }
          
    return -1;
  }
}

//======================================================================================
//              Basic DHTML Setup and compatability
//======================================================================================

function writeDHTML(src) {
  alert("writeDHTML is no longer supported! Please fix your code!");
}

//This is just a stub for backwards compatability it is no longer used.
//Except to initialize special dhmtl elements manually instead of every
//element of that type. 
function initDHTML(elem, doc) {
  alert("initDHTML is no longer supported! Please fix your code!");
}
//This is the new way to run DHTML code
//This works around the body.onLoad and
//large document problems by forcing
//the dhtml code to only parse
//certain sections.
function processDHTML() {
  var i = 0;
  var elm = null;
  var strID = "";
  for(i = 0 ; i < processDHTML.arguments.length; i++) {
    strID = processDHTML.arguments[i];
    if(strID && strID.nodeType)
      elm = strID;
    else if(strID && strID.length)
      elm = document.getElementById(strID);

    if(dhtml._DOM && elm)
      dhtml._procElem(elm, document);
  }
}

function debugObj(obj, nw, level, padd) {
  var so = '' + obj;
  var h = '', i = "";
  if(!padd)
    padd="";
    
  if(so.substr(0, 7) == '[object') {
    h = padd+so.substr(8, so.length-9) + " {\n";
    if(level > 0) {
      for(i in obj) {
        try {
          h += padd + i + ': ' + debugObj(obj[i], 0, level - 1, padd+"\t") + "\n";
        } catch(e) {
          h += padd + i + ': ' + e + "\n";
        }
      }
    }
    h += padd+"}\n";
  } else {
    h = obj;
  }

  if(nw) {
    var w = window.open();
    if(!w)
      w = window;
    w.document.open();
    w.document.write("<pre>" + h + "</pre>");
    w.document.close();
  } else if(nw != 0)
    alert(h);
  else
    return h;
}

function dhtml() {
  var i = 0, strArgs = "";
  
  for(i = 0; i < dhtml.arguments.length; i++) {
    strArgs += ",dhtml.arguments[" + i + "]";
  }
  
  if(strArgs && strArgs.length) {
    eval("processDHTML("+strArgs.substring(1,strArgs.length)+");");
  }
  
  return this._toValue();
}

dhtml._init = function() {
  var win = window;
  var dhtmlIdx=0;
  
  if(this.__inited)
    return;

  this.__inited = 1;

  //cannot virully propigate becase of XSS security, so we limit to ourselves.
  while(win.dhtml && win.parent != win && win.document.domain == win.parent.document.domain)
    win = win.parent;

  this._rootWin = win;
  this._rootDoc = win.document;
  if(!this._rootDoc.parentWindow)
    this._rootDoc.parentWindow = this._rootWin;
  this._experimental = false;

  if(!this.sharedPath)
    this.sharedPath = "";
  if(!this.compMode)
    this.compMode = 0;
  
  if(window.navigator) {
    if(navigator.platform.indexOf("Mac") > -1)
      this._mac = true;
    else if(navigator.platform.indexOf("nix") > -1)
      this._unix = true;
    else
      this._windows = true;
  }

  if(document.all) {
    this._dhtml = true;
    this._DOM = true;
    this._IE = true;

    if((dhtmlIdx = navigator.appVersion.indexOf("MSIE ")) > -1) {
      dhtmlIdx = navigator.appVersion.substr(dhtmlIdx + 5, 5).split(".");
      this._major = parseInt(dhtmlIdx[0]);
      this._minor = parseInt(dhtmlIdx[1]);
    } else {
      this._major = 4;
      this._minor = 0;
    }

  } else if(document.getElementById) {
    this._DOM = true;
    this._W3C = true;

    if(navigator.product == "Gecko") {
      this._mozilla = true;
      this._major = 1
      this._minor = parseInt(navigator.productSub);
    } else {
      this._major = 0;
      this._minor = 0;
    }

  } else if(document.layers) {
    this._dhtml = true;
    this._NN4 = true;

    this._major = 4;
    this._minor = 0;

  } else if(document.images) {
    this._dhtml = true;
    this._basic = true;
    this._major = 3;
    this._minor = 0;

  }

  this._dhtmlID = new Array();
  this._basic = new Array();
  this._doc = new Array();
  this._docInit = new Array();
  this._norm = new Array();
  this._quick = null;
  
  this._filterTags = new Array("*");
  this._filterHtmlTags = new Array("DIV", "SPAN", "A", "IMG");

  //DHTML in IE4.5 for the mac is borked so I won't go there.
  if(this._mac && this._IE && this._major < 5) {
    this._dhtml = false;
    this._DOM = false;
    this._W3C = false;
    this._basic = false;
    
    return;
  }

  //the dhtml code no longer does onload, you must manually instanciate it now!  
};

dhtml._resync = function() {
  this._init();

  this.rootWin = this._rootWin;
  this.rootDoc = this._rootDoc;
  
  this.dhtml = this._dhtml;
  this.DOM = this._DOM;
  this.W3C = this._W3C;
  this.mozilla = this._mozilla;
  this.IE = this._IE;
  this.NN4 = this._NN4;
  this.unix = this._unix;
  this.windows = this._windows;
  this.mac = this._mac;
  this.major = this._major;
  this.minor = this._minor;

  this.toString = this._toString;
  this.toValue = this._toValue;

  this.checkVersion = this._checkVersion;

  this.normDoc = this._normDoc;
  this.normalize = this._normalize;
  this.quickNorm = this._quickNorm;

  this.addDHTML = this.addTag = this._addDHTML;
  this.addHTML = this._addHTML;
  this.addBasicInit = this._addBasicInit;
  this.runBasic = this._runBasic;
  this.addDocInit = this._addDocInit;
  this.addNormDoc = this._addNormDoc;
  this.addNorm = this._addNorm;
  this.process = this._Process;
  this.grepTags = this._grepTags;
  this.grepAttributes = this._grepAttributes;
  this.setType = this._setType;

  this.procAlign = this._procAlign;
  
  this.getKeycode = this._getKeycode;
};

dhtml._toString = function() {
  this._resync();

  return "["+
      (this._dhtml ? 'DHTML' : '') +
      (this._ie ? ' Internet Explorer' : '') +
      (this._mozilla ? ' Gecko Based' : '') +
      (this._NN4 ? ' Netscape Navigator' : '') +
      ' Browser'+
      ' ' + this._major + '.' + this._minor +
      (this._windows ? ' on Windows' : '') +
      (this._mac ? ' on Mac' : '') +
      (this._unix ? ' on *nix' : '') +
      (this._DOM ? ' supports DOM' : '') +
      (this._W3C ? ' supports W3C' : '') +
    "]";
};

dhtml._toValue = function() {
  this._resync();

  return this._dhtml;
};

dhtml._getKeycode = function(e) {
  this._resync();

  if(!e && event)
    e = event;

  return (e.which ? e.which : e.keyCode);
}

dhtml._addDHTML = function(tag, func, bfunc, prefunc, block) {
  var idx = 0;
  this._dhtmlID.length;

  this._resync();

  this._dhtmlID[idx = this._dhtmlID.length] = tag;
  this._dhtmlID['dhtml_' + tag] = new tagObject(tag, func, bfunc, prefunc, block);
}

function tagObject(tag, func, bfunc, prefunc, block) {
  this.name = tag;
  this.proc = func;
  this.basic = bfunc;
  this.init = prefunc;
  this.block = block;
}

dhtml._setType = function(elem, init) {
  var i = 0;
  var cmd = "";

  this._resync();

  elem._dhtmlInit = init;
  if(arguments.length > 2) {
    for(i = 2; i < arguments.length; i++)
      cmd += ", arguments["+i+"]";
    cmd = "elem._dhtmlInit(" + cmd.substr(1) + ");"; 
    eval(cmd);
  } else
    elem._dhtmlInit();
}

dhtml._procElem = function(elm, doc) {
  var aryStack = new Array();
  var dhtml = null;
  var i = 0;
  var idx = 0;

  this._resync();
  this._procDhtml(elm, doc);

  elm = elm.firstChild;

// We use an internal while loop with a stack instead of
// recursion to help minimize overhead  
  while(aryStack.length || elm) {
    this._procDhtml(elm, doc);
    
    if(elm.firstChild) {
      aryStack.push(elm);
      elm = elm.firstChild;
    } else
      elm = elm.nextSibling;
    
    while(!elm && aryStack.length) {
      elm = aryStack.pop().nextSibling;
    }
  }
}

dhtml._procDhtml = function(elm, doc) {
  var i = 0;
  var dhtml = null;

  if(elm.nodeType != 1)
    return;

  if(elm.__procd)
    return;

  this.normDoc(doc);

  this.normalize(elm, doc);
  dhtml = elm.getAttribute("dhtml")
  if(dhtml)
    dhtml = dhtml.toUpperCase().trim().replace(',', ' ').split(' ');
  else
    dhtml = new Array();
  
  dhtml.push(elm.nodeName);
  
  for(i = 0; i < dhtml.length; i++) {
    if(this._dhtmlID.indexOf(dhtml[i]) > -1) {
      var tag = this._dhtmlID['dhtml_'+dhtml[i]];
      elm = tag.proc(elm, doc);
    }
  }
  elm.__procd = 1;
  
  return elm;
}

dhtml._addNormDoc = function(func) {
  this._resync();

  if(!func)
    return;
    
  this._doc[this._doc.length] = func;
}

dhtml._normDoc = function(doc) {
  var i;
  
  this._resync();

  if(!doc)
    return null;

  if(doc._dhtmlNorm)
    return doc;

  doc._dhtmlNorm = 1;

  doc.root = this.rootDoc;

  for(i = 0; i < this._doc.length; i++) {
    this._doc[i](doc);
  }
    
  return doc;
}

dhtml._addNorm = function(func) {
  this._resync();

  if(!func)
    return;
    
  this._norm[this._norm.length] = func;
}

dhtml._normalize = function(elem, doc) {
  var i;
  
  this._resync();

  if(!elem)
    return null;

  if(elem.nodeType == 3)
    return elem;

  if(elem._dhtmlNorm)
    return elem;

  elem._dhtmlNorm = 1;

  if(!doc)
    doc = this.rootDoc;

  if(elem._layer)
    elem.nodeType = 1;

  if(!elem.document)
    elem.document = doc;
  else
    this.normDoc(elem.document);
    
  for(i = 0; i < this._norm.length; i++)
    this._norm[i](elem);
  
  return elem;
}

dhtml._quickNorm = function(elem, doc) {
  var i;
  
  this._resync();

  if(!elem)
    return null;

  if(elem._dhtmlNorm || elem._qdhtmlNorm)
    return elem;

  elem._qdhtmlNorm = 1;

  if(!doc)
    doc = this.rootDoc;

  if(elem._layer)
    elem.nodeType = 1;
  if(!elem.document)
    elem.document = doc;
  else
    this.normDoc(elem.document);
    
  if(this._quick)
    this._quick(elem, doc);
  
  return elem;
}

dhtml._addDocInit = function(func) {
  this._resync();

  if(!func)
    return;
    
  this._docInit[this._docInit.length] = func;
}

dhtml._procAlign = function(align) {
  var i = parseInt(align);

  this._resync();

  if(isNaN(i)) {
    i = -1;
    if(align && align.length) {
      switch(align.substring(0, 1).toLowerCase()) {
      case "c":
      case "m":
        i = 0;
        break;
      case "r":
      case "b":
      case "d":
      case "v":
        i = 1;
        break;
      }
    }
  } else if(i < -1)
    i = -1;
  else if (i > 1)
    i = 1;

  return i;
}

dhtml._resync();