///////////////////
// externallinks.js

function ExternalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0;i<anchors.length;i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href")&&anchor.getAttribute("rel") == "external") anchor.target = "_blank";
  }
}


///////////////
// event.js

function attachEventListener(target, eventType, functionRef, capture) {
	if (typeof target.addEventListener != 'undefined') {
	   target.addEventListener(eventType, functionRef, capture);
	} else
	if (typeof target.attachEvent != 'undefined') {
	   target.attachEvent('on' + eventType, functionRef);
	} else {
	   return false;
	}
	return true;
}

function removeEventListener(target, eventType, functionRef, capture){
	if (target.removeEventListener){
	   target.removeEventListener(eventType, functionRef, capture);
	   return true;
	} else if (target.detachEvent){
	   var r = target.detachEvent("on"+eventType, functionRef);
	   return r;
	} else {
	   return false;
	}
}


///////////////
// textlimit.js

/**
 * TextLimit class v1.0
 * (c) 2007-02-13 Dominik Raœ
 */

if (typeof TextLimit == "undefined") var TextLimit = new Object();

TextLimit = function(id, maxChars) {

	if (!document.getElementById) { return; }

	this.timer = new Timer(this);

	this.CheckingInterval = 50;

	this.Interval = null;

	this.Listeners = new Array();

	this.TextID = id;
	this.maxChars = maxChars;

}

TextLimit.prototype = {

	SetCheckingInterval: function(time) {
          if (time>0) this.CheckingInterval=time;
	},

	SetMaxChars: function(maxChars) {
          if (time>maxChars) this.maxChars=maxChars;
	},

	getNew: function(){
	  var i = 0;
	  while (this.Listeners[i]) i++;
	  return i;
	},

	AddListener: function(id, text) {
          if (typeof id!='object') return;
          var i = this.getNew();
          this.Listeners[i]=new Array(id, text);
	},

	ClearListeners: function() {
          this.Listeners=new Array();
	},

        CheckListeners: function() {
	  var i = 0;
          while (this.Listeners[i]) {
            if (typeof this.Listeners[i][0]=='object') {

               var text=this.Listeners[i][1];

               // text length
               var regEx = new RegExp('%1', 'gi') ;
               text = text.replace(regEx, this.TextID.value.length);

               // free chars
               var regEx = new RegExp('%2', 'gi') ;
               text = text.replace(regEx, this.maxChars-this.TextID.value.length);

               // max chars
               var regEx = new RegExp('%3', 'gi') ;
               text = text.replace(regEx, this.maxChars);

               this.Listeners[i][0].value=text;

            }
            i++;
          }
        },

        CheckText: function() {
          if (this.TextID.value.length>this.maxChars) {
             this.TextID.value=this.TextID.value.substring(0, this.maxChars);
          }
          this.CheckListeners();
        },

	Start: function() {
          if (!document.getElementById) { return; }
          if (typeof this.TextID=='object') {
             if (this.Interval==null) this.Interval=this.timer.setInterval("CheckText", this.CheckingInterval);
          }
	},

	Stop: function() {
          if (!document.getElementById) { return; }
          if (this.Interval) this.timer.clearInterval(this.Interval);
	}

}


///////////////////
// timer.js

// The constructor should be called with
// the parent object (optional, defaults to window).

function Timer(){
    this.obj = (arguments.length)?arguments[0]:window;
    return this;
}

// The set functions should be called with:
// - The name of the object method (as a string) (required)
// - The millisecond delay (required)
// - Any number of extra arguments, which will all be
//   passed to the method when it is evaluated.

Timer.prototype.setInterval = function(func, msec){
    var i = Timer.getNew();
    var t = Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setInterval(t,msec);
    return i;
}
Timer.prototype.setTimeout = function(func, msec){
    var i = Timer.getNew();
    Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
    return i;
}

// The clear functions should be called with
// the return value from the equivalent set function.

Timer.prototype.clearInterval = function(i){
    if(!Timer.set[i]) return;
    window.clearInterval(Timer.set[i].timer);
    Timer.set[i] = null;
}
Timer.prototype.clearTimeout = function(i){
    if(!Timer.set[i]) return;
    window.clearTimeout(Timer.set[i].timer);
    Timer.set[i] = null;
}

// Private data

Timer.set = new Array();
Timer.buildCall = function(obj, i, args){
    var t = "";
    Timer.set[i] = new Array();
    if(obj != window){
        Timer.set[i].obj = obj;
        t = "Timer.set["+i+"].obj.";
    }
    t += args[0]+"(";
    if(args.length > 2){
        Timer.set[i][0] = args[2];
        t += "Timer.set["+i+"][0]";
        for(var j=1; (j+2)<args.length; j++){
            Timer.set[i][j] = args[j+2];
            t += ", Timer.set["+i+"]["+j+"]";
    }}
    t += ");";
    Timer.set[i].call = t;
    return t;
}
Timer.callOnce = function(i){
    if(!Timer.set[i]) return;
    eval(Timer.set[i].call);
    Timer.set[i] = null;
}
Timer.getNew = function(){
    var i = 0;
    while(Timer.set[i]) i++;
    return i;
}


//////////////
// showhide.js

function ShowHideDiv(div_id, span) {
  var _style=(span===true) ? 'inline' : 'block';
  var obj=document.getElementById(div_id);
  obj.style.display=(obj.style.display=='none') ? _style : 'none';
  return ((obj.style.display=='none') ? false : true);
}

function ShowDiv(div_id, span) {
  var _style=(span===true) ? 'inline' : 'block';
  document.getElementById(div_id).style.display=_style;
}

function HideDiv(div_id) {
  document.getElementById(div_id).style.display='none';
}

