var isie = document.all && !window.opera;
 
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 && getCurrentStyle(o.offsetParent,'position')!='absolute') {
		oParent = o.offsetParent;
		oTop += oParent.offsetTop;
		o = oParent;
	}
	return oTop;
}
function getAbsLeft(o) {
	oLeft = o.offsetLeft;
	while(o.offsetParent!=null && getCurrentStyle(o.offsetParent,'position')!='absolute') {
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft;
		o = oParent;
	}
	return oLeft;
}

function getCurrentStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}


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 arrayIndexOf(arr, elt /*, from*/){
    if(arr instanceof 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(arr instanceof Object){
		for(key in arr){
			if(arr[key] == elt) return key;
		}
    }
    return -1;
}

// checks for a positive integer (or 0)
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;
	}
}

function attachEventHandler(elem,type,listener){
	if(elem.attachEvent){
		elem.attachEvent("on" + type, listener);
	}else if(elem.addEventListener){
		elem.addEventListener(type, listener, false);
	}
}

function releaseEventHandler(elem,type,listener){
	if(elem.attachEvent){
		elem.detachEvent("on" + type, listener);
	}else if(elem.addEventListener){
		elem.removeEventListener(type, listener, false);
	}
}

function getRandomCode(){
	var string = Math.round(Math.random() * 100000000);
	return '?' + string;
}
