/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/

//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).
//also modified by KLB, NIC-TN 9/2006
//base class moved to prototype.lite.js file from moo.fx file

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

Function.prototype.bindAsEventListener = function(object) {
var __method = this;
	return function(event) {
		__method.call(object, event || window.event);
	}
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

if (!window.Element) var Element = new Object();

Object.extend(Element, {
	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var hasClass = false;
		element.className.split(' ').each(function(cn){
			if (cn == className) hasClass = true;
		});
		return hasClass;
	},

	addClassName: function(element, className) {
		element = $(element);
		Element.removeClassName(element, className);
		element.className += ' ' + className;
	},
  
	removeClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var newClassName = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName += ' ';
				newClassName += cn;
			}
		});
		element.className = newClassName;
	},

	cleanWhitespace: function(element) {
		element = $(element);
		$c(element.childNodes).each(function(node){
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
		});
	},

	find: function(element, what) {
		element = $(element)[what];
		while (element.nodeType != 1) element = element[what];
		return element;
	}
});

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
};

document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = [];
	$c(children).each(function(child){
		if (Element.hasClassName(child, className)) elements.push(child);
	});  
	return elements;
}

//useful array functions
Array.prototype.iterate = function(func){
	for(var i=0;i<this.length;i++) func(this[i], i);
}
if (!Array.prototype.each) Array.prototype.each = Array.prototype.iterate;

function $c(array){
	var nArray = [];
	for (var i=0;i<array.length;i++) nArray.push(array[i]);
	return nArray;
}


//begin code FROM moo.fx
//moved to this file for easier access accross apps
var fx = new Object();
//base
fx.Base = function(){};
fx.Base.prototype = {
	setOptions: function(options) {
	this.options = {
		duration: 300,
		onComplete: '',
		transition: fx.sinoidal
	}
	Object.extend(this.options, options || {});
	},

	step: function() {
		var time  = (new Date).getTime();
		if (time >= this.options.duration+this.startTime) {
			this.now = this.to;
			clearInterval (this.timer);
			this.timer = null;
			if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10);
		}
		else {
			var Tpos = (time - this.startTime) / (this.options.duration);
			this.now = this.options.transition(Tpos) * (this.to-this.from) + this.from;
		}
		this.increase();
	},

	custom: function(from, to) {
		if (this.timer != null) return;
		this.from = from;
		this.to = to;
		this.startTime = (new Date).getTime();
		this.timer = setInterval (this.step.bind(this), 13);
	},

	hide: function() {
		this.now = 0;
		this.increase();
	},

	clearTimer: function() {
		clearInterval(this.timer);
		this.timer = null;
	}
}

//tool tips
//class added by KLB
//uncomment code below for Opacity fade effect (uses moo.fx.js)
fx.ToolTip = Class.create();
fx.ToolTip.prototype = {
	initialize: function(togglers, elements) {
		this.elements = elements;
		/*this.fxa = [];
		elements.each(function(el, i){
			this.fxa[i] = new fx.Opacity(el);
			//this.fxa[i].toggle();
		}.bind(this));*/

		togglers.each(function(tog, i){
							   
			elements[i].style.display = "none"; //hide on init
			elements[i].style.position = "absolute"; //position all near the trigger
			
			tog.onmouseover = function(){
				elements[i].style.display = "block";
				//this.showHideFade(elements[i]);
			}.bind(this);
			
			tog.onmouseout = function(){
				elements[i].style.display = "none";
				//this.showHideFade(elements[i]);
			}.bind(this);
		}.bind(this));
	}/*,

	showHideFade: function(toFade){
		this.elements.each(function(el, j){
			if (el == toFade) setTimeout(function(){this.clearAndToggle(toFade, j);}.bind(this));
		}.bind(this));
	},

	clearAndToggle: function(el, i){
		this.fxa[i].clearTimer();
		this.fxa[i].toggle();
	}*/
}

//initializes Tool Tips
//this function must be called from an onload event
function setToolTips() {
	var toggles = document.getElementsByClassName('tipTrigger'); //links/containers you mouse over
	var tips = document.getElementsByClassName('tipContent'); //containers that fade in and out
	
	var myTips = new fx.ToolTip(
	  toggles, tips
	);
}

//popUps
//class added by KLB
fx.PopUps = Class.create();
fx.PopUps.prototype = {
	initialize: function(togglers) {
		togglers.each(function(tog, i){
			tog.onclick = function(){
				var popup = window.open(tog.href, 'popup', 'resizable=yes,scrollbars=yes,toolbar=no,location=no,width=725,height=500');
				popup.focus();
				return false;
			}.bind(this);
		}.bind(this));
	}
}

//initializes popUps
//this function must be called from an onload event
function setPopUps() {
	var popLinks = document.getElementsByClassName('popTrigger'); 
		
	for (i=0;i<popLinks.length;i++) {
		
		var myPopUps = new fx.PopUps(
			popLinks
		);
		
	}//end for
}//end function

fx.navPopUps = Class.create();
fx.navPopUps.prototype = {
	initialize: function(togglers) {
		togglers.each(function(tog, i){
			tog.onclick = function(){
				var navpopup = window.open(tog.href, 'navpopup', 'resizable=yes,scrollbars=yes,toolbar=yes,location=yes,menubar=yes,width=700,height=500');
				navpopup.focus();
				return false;
			}.bind(this);
		}.bind(this));
	}
}

//initializes popUps
//this function must be called from an onload event
function setNavPopUps() {
	var navPopLinks = document.getElementsByClassName('navpop'); 
		
	for (i=0;i<navPopLinks.length;i++) {
		
		var myNavPopUps = new fx.navPopUps(
			navPopLinks
		);
		
	}//end for
}//end function



//icoHelp
//class added by KLB
fx.IcoHelp = Class.create();
fx.IcoHelp.prototype = {
	initialize: function(togglers, elements) {
		this.elements = elements;

		togglers.each(function(tog, i){
							   
			elements[i].style.display = "none"; //hide on init
			
			tog.onclick = function(){
				if (elements[i].style.display == "none") {
					elements[i].style.display = "block";
				} else {
					elements[i].style.display = "none";
				}
				
				return false;
				
			}.bind(this);
			
		}.bind(this));
	}
}

//this function must be called from an onload event
function setIcoHelp() {
	var helpLinks = document.getElementsByClassName('helpTrigger'); 
	var helpInfo = document.getElementsByClassName('helpContent'); //containers that fade in and out
		
	for (i=0;i<helpLinks.length;i++) {
		
		var myIcoHelp = new fx.IcoHelp(
			helpLinks, helpInfo
		);
		
	}//end for
}//end function

function jtrim(strText) {

	var lenString  = strText.length;
	var trimString = "";
	var i = 0;

	//this loop takes care of leading spaces
	for(i=0;i<lenString;i++) {
		if(strText.substring(i,i+1) != " ") {
			trimString = strText.substr(i);
			i = lenString;
		}
	}
	
	//this loop takes care of trailing spaces
	i = trimString.length;
	for(i=trimString.length;i>0;i--) {
		if(trimString.substring(i,i-1) != " ") {
			trimString = trimString.substr(0,i);
			i = 0;
		}
	}
	
	return trimString;
}

function trim() {
	var inputs = document.getElementsByTagName('input');
	for (i=0;i<inputs.length;i++) {
		inputs[i].value = jtrim(inputs[i].value);
	};
}