// JavaScript Document


//Just get some easy variables to check for firefox or IE because they have different code in some cases
var isFF;
var isFirefox=isFF=( navigator.appName != null && navigator.appName.indexOf( "Firefox" ) != -1 );
var isIE = ( navigator.appName != null && (navigator.appName.indexOf( "Microsoft Internet Explorer" ) != -1 ));

var mousex, mousey;

if(isIE) document.onmousemove=function (){ mousex=event.x; mousey=event.y;}
else if(isFF) window.onmousemove=function(e){mousex=e.pageX;mousey=e.pageY;}

if(isIE){
	var getEventX=function(){return event.x;}
	var getEventY=function(){return event.y;}
	var getEventSource=function(){return event.srcElement;}
}else if(isFF){
	var getEventX=function(e){return e.pageX;}
	var getEventY=function(e){return e.pageY;}
	var getEventSource=function(e){return e.target;}
}

function findPosX(obj) {
	var curleft = 0;
	var objorig=obj;
	if(!obj) return 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft||0;
			curleft -= obj.pageX||0;
		} while((obj = obj.offsetParent)!=null);
	}
	obj=objorig;
	while((obj=obj.parentNode)!=null)
		curleft-=obj.scrollLeft||0;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	var objorig=obj;
	if (obj.offsetParent) {
		do {
		//	if (obj.style && (obj.style.position.toLowerCase()=='absolute')||(obj.style.position.toLowerCase()=='relative'))  break;
			curtop += obj.offsetTop||0;
			curtop -= obj.pageY||0;
		} while((obj = obj.offsetParent)!=null);
	}
	obj=objorig;
	while((obj=obj.parentNode)!=null)
		curtop-=obj.scrollTop||0;
	return curtop;
}

function findAllChildren(node,arr){
	if(!node) return null;
	if(!arr) arr=new Array();
	arr.push(node);
	var c;
	if(node.childNodes)
		for(c in node.childNodes)
			if(node.childNodes[c].tagName)
				findAllChildren(node.childNodes[c],arr)
				
	return arr;
}

function parentForm(child){
	if(!child || !child.parentNode || !child.parentNode.tagName) return null;
	if(child.parentNode.tagName.toLowerCase()=='form') return child.parentNode;
	return parentForm(child.parentNode);
}

function assocLength(assoc){
	var count=0;
	for(var c in assoc)
		count++;
	return count;
}

function setEvent(elem,type,func){
	elem=elem||window;
	if(isIE) elem.attachEvent("on"+type,func);
	else if(isFF) return elem.addEventListener(type,func,false);
//	alert(elem+"\n\n"+type+"\n\n"+func);
}

function remEvent(elem,type,fPointer){
	if(isIE) elem.detachEvent(type,fPointer);
	else if(isFF) elem.removeEventListener(type,fPointer,false);
}

String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
String.prototype.rtrim = function() {return this.replace(/\s+$/,"");}
function isArray(obj){return obj && obj.constructor == Array;}
function isObject(obj){return obj && obj.constructor == Object;}
function isString(obj){return obj && obj.constructor == String;}

function toPX(elem,property){
	if(elem && elem.parentNode && elem.parentNode.style && elem.parentNode.style.display=='block') metrics=getBlockMetrics(elem.parentNode);
	else metrics=bodyMetrics;
	if(!elem) return 'Invalid Element';
	if(!elem.style[property]) return 'Invalid style property: '+jsonStringify(property)+"="+jsonStringify(elem.style[property]);
	window.status=elem.style[property];
	var pArr=elem.style[property].match(/^([\d\.]+)(em|%|cm|mm|ex|in|pt|pc|px)$/);
	if(!isArray(pArr) || !pArr.length) return 'Invalid style property format';
	var ret;
	if(pArr[2]=='%'){
		switch(property){
		case 'height':
		case 'top':
			ret=Number(pArr[1])*metrics.pxPer['vp'];
			break;
		default:
			ret=Number(pArr[1])*metrics.pxPer['hp'];
			break;
		}
	}else{
		ret=Number(pArr[1])*metrics.pxPer[pArr[2]];
	}
	return ret;
}

function Clone(o){
	for(var i in o)
		this[i]=o[i];
}

function encURI(str){
	return encodeURIComponent(decodeURIComponent(str));
}

var bodyMetrics;
//setEvent(document.body,'load',function(){bodyMetrics=getBlockMetrics(document.body);});
