
function trim(stringToTrim) {
	if(!stringToTrim || stringToTrim.length==0) return stringToTrim;
	return (stringToTrim+"").replace(/^\s+|\s+$/g,"");
}

function getAbsTop(o) {
	oTop = o.offsetTop;
	while(o.offsetParent!=null) {
		oParent = o.offsetParent;
		oTop += oParent.offsetTop;
		o = oParent;
	}
	return oTop;
}
function getAbsLeft(o) {
	oLeft = o.offsetLeft;
	while(o.offsetParent!=null) {
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft;
		o = oParent;
	}
	return oLeft;
}

function isParentOf(parent,child){
	if(!parent || !child) return false;
	if(parent == child) return true;
	if(child.parentNode){
		while(child = child.parentNode){
			if(parent == child) return true;			
		}
	}
	return false;
}

function indexOf(arr, elt /*, from*/){
    if(typeof(arr) == 'Array'){
		var len = arr.Length;
		var from = Number(arguments[2]) || 0;
		from = (from < 0)?Math.ceil(from):Math.floor(from);
		if (from < 0) from += len;
		for (; from < len; from++){
			if (from in arr && arr[from] === elt) return from;
		}
    }else if(typeof(arr) == 'object'){
		for(key in arr){
			if(arr[key] == elt) return key;
		}
    }
    return -1;
}

function isnumeric(val){
	var check = /^[\d]+$/;
	return check.test(trim(val));
}

function basename(path, suffix) { 
    var b = path.replace(/^.*[\/\\]/g, '');    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }    
    return b;
}

function MousePosition(e){
	this.posX = 0;
	this.posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY){
		this.posx = e.pageX;
		this.posy = e.pageY;
	}
	else if (e.clientX || e.clientY){
		this.posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - document.documentElement.clientLeft;
		this.posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop - document.documentElement.clientTop;
	}
}

/*
Useful Event Manager, stolen from http://v3.thewatchmakerproject.com
Usage: to add an event, simply use Event.add(object,eventtype(without the on),function(name or code));
	   ro remove an event, use Event.remove(object,eventtype(without the on),function(name or code));
*/
var Event = {
	add: function(obj,type,fn) {
		if(typeof(obj) == 'string') obj = document.getElementById(obj);
		if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn](window.event); }
			obj.attachEvent('on'+type,obj[type+fn]);
		} else
		obj.addEventListener(type,fn,false);
	},
	remove: function(obj,type,fn) {
		if(typeof(obj) == 'string') obj = document.getElementById(obj);
		if (obj.detachEvent) {
			obj.detachEvent('on'+type,obj[type+fn]);
			obj[type+fn] = null;
		} else
		obj.removeEventListener(type,fn,false);
	}
}

 
 
