thlib = new thlibClass();
thlib.addEventHandler(window, "load", "init", thlib);
function thlibClass(){

  this.tlibDirectory ="/thlib/"
  this.utils = {};
  this.widgets ={};

  this.OS = "";
  this.OSTypes = ["Windows","Linux", "x11","Mac"];

  this.browser = "";
  this.broswerTypes = ["MSIE", "Mozilla", "Safari", "OmniWeb", "Opera", "WebTV", "iCab"];

  var Agent = navigator.userAgent.toLowerCase();
  for(var i=0; i < this.broswerTypes.length; i++){
    if(Agent.indexOf(this.broswerTypes[i].toLowerCase()) > -1){
      this.browser = this.broswerTypes[i];
      break;
    }
  }

  for(var i=0; i < this.OSTypes.length; i++){
    if(Agent.indexOf(this.OSTypes[i].toLowerCase()) > -1){
      this.OS = this.OSTypes[i];
      break;
    }
  }


  	/*==========================================================
    	init routines
  	===========================================================*/
	this.initList = new Array();
	this.initRan = false;

  	this.addToInitList = function(obj){
    	this.initList.push(obj);
  	}

	this.initRan = false;
  	this.init = function(){
		if(this.initRan == false){
     		while (this.initList.length > 0){
        		this.initList.shift().init()
      		}
      		this.initRan = true;
    	}
  	}



  this.msXmlhttpObjectID = null;
  this.getXmlhttpObject = function(){
    var xObj = null;
    try{ 
      xObj = new XMLHttpRequest(); 
    }catch(e){}
    if(!xObj){
      if(this.msXmlhttpObjectID){
        xObj = new ActiveXObject(this.msXmlhttpObjectID);
      }else{
        xObj = this.setMsXmlhttpObject();
      }
    }

    if(!xObj){
      // error 
    }

    return xObj;
  } // getXmlhttpObject


  this.msXmlhttpObjectIDs = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];	
  this.setMsXmlhttpObject = function(){
    var xObj = null;
    for(var idx=0; i< this.msXmlhttpObjectIDs.length; ++idx){
      var objID = this.msXmlhttpObjectIDs[idx];
      try{
        xObj = new ActiveXObject(objID);
      }catch(e){}
      if(xObj){
        this.msXmlhttpObjectID = objID;
        return  xObj;
      }
    }
    return null
  } // msXmlhttpObjectIDs

  
  this.postData = function(url, Data){
    var http = thlib.getXmlhttpObject();

    http.open('POST', url, false);
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(Data);

    var stat = http["status"];

    if(!Boolean((!stat)||((200 <= stat)&&(300 > stat))||(stat==304))){
      var err = Error("Unable to load " + url + " status:" + stat);
      err.status = http.status;
      err.responseText = http.responseText;
      throw err;
    }
    return http.responseText; // String
  } // getURL
  


  this.getURL = function(url, callback){
    var http = thlib.getXmlhttpObject();

    http.open('GET', url, false);
    http.send(null);

    var stat = http["status"];

    if(!Boolean((!stat)||((200 <= stat)&&(300 > stat))||(stat==304))){
      var err = Error("Unable to load " + url + " status:" + stat);
      err.status = http.status;
      err.responseText = http.responseText;
      throw err;
    }
    return http.responseText; // String
  } // getURL

  this.include = function(includeFileURI){
    var pathA = includeFileURI.split("/");
    var fileName =  pathA[pathA.length -1];
     var inClass = null;

    //strip off .js
    pathA[pathA.length -1] = fileName.substr(0,fileName.length - 3)

    try{
      inClass = eval(pathA.join("."))
    }catch(e){
      inClass = null;
    }

    if(! inClass ){

      //strip off  thlib
      pathA.shift();
      var URI = this.tlibDirectory + pathA.join("/") + ".js"

      var includeText = thlib.getURL(URI);
      eval(includeText);
    }
  }  // include
  
  	/*==========================================================
    	Extra DOM functions
  	===========================================================*/
	this.getElementsByClass = function(searchClass,startingNode,tag) {
		var classElements = new Array();
		if ( startingNode == null ){
			startingNode = document;
		}
		if ( tag == null ){
			tag = '*';
		}
		var els = startingNode.getElementsByTagName(tag);
		var elsLen = els.length;
	
		for (i = 0; i < elsLen; i++) {
			if ((els[i].className == searchClass)||(els[i]["class"] == searchClass)) {
				classElements.push(els[i]);
			}
		}
		return classElements;
	}
	

	this.getAttribute = function (ele, attribName){
    	var returnValue = "";
	
		try{
	  		returnValue  = ele.attributes[attribName].nodeValue ;
		}catch(err){
	  		try{
	    		returnValue  = eles.getAttribute(attribName).nodeValue ;
	  		}catch(err){}
    	}
		return returnValue;
  	}//  getAttribute	


  	this.addEventHandler = function(ele, eventType, fctName, parent, parms){
    	ele.thlThis = parent;
		if(parms == undefined){
      		if (ele.addEventListener) {
        		ele.addEventListener(eventType, function(event) { parent[fctName]() }, false);
      		}else{
        		ele.attachEvent ("on" + eventType,  function(event) { parent[fctName]() });
      		}
		}else{
      		if (ele.addEventListener) {
        		ele.addEventListener(eventType, function(event) { parent[fctName](parms) }, false);
     		 }else{
        		ele.attachEvent ("on" + eventType,  function(event) { parent[fctName](parms) });
      		}
		}
  	}
	
  	/*==========================================================
    	query Parameters
  	===========================================================*/
	//Class varibles
	this.queryParms = {};

	var query = window.location.search.substring(1);
	var parms = query.split('&');


	for (var i=0; i< parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = unescape(parms[i].substring(0,pos));
			var val =  unescape(parms[i].substring(pos+1));
			this.queryParms[key] = val;
		}
	}
	
  	/*==========================================================
    	cookie handling
  	===========================================================*/
	//Class varibles
	this.cookies = {};
	
	// load cookie object
	allCookies = document.cookie.split( ';' );
	tempCookie = '';
	cookieName = '';
	
	for ( i = 0; i < allCookies.length; i++ ){
		tempCookie = allCookies[i].split( '=' );
		cookieName = tempCookie[0].replace(/^\s+|\s+$/g, '');
		if ( tempCookie.length > 1 ){
			this.cookies[cookieName] = unescape( tempCookie[1].replace(/^\s+|\s+$/g, '') );
		}
		tempCookie = null;
		cookieName = '';
	}


	this.setCookie = function(name, value, expires, path, domain, secure) {
		var today = new Date();
		today.setTime( today.getTime() );

		if ( expires ){
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );

		document.cookie = name + "=" +escape( value ) +
			( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
			( ( path ) ? ";path=" + path : "" ) + 
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
		
		this.cookies[name] = value;
	}
	


  	/*==========================================================
    	serialize named pairs for URL or POST
  	===========================================================*/
	this.serializeNamedPairs = function( parms ) {
    	var s = [];
		
    	for ( var parnName in parms ){
      		s.push( encodeURIComponent(parnName) + "=" + encodeURIComponent( parms[parnName] ) );
		}
    		// Return the resulting serialization
    	return s.join("&").replace(/%20/g, "+");
    
  	}	

  /////////////////////////////////////////////////////////////
  this.createMethodReference = function(object, methodName){
    return function () {
        return object[methodName].apply(object, arguments);
    };
  };
  ////////////////////////////////////////////////////////////
}  //  end if thlibClass