function getPageCoords() {
	var element = arguments[0];
	element = (typeof element=="object")? element :document.getElementById(element);
	var coords = {x: 0, y: 0};
	while (element) {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
		element = element.offsetParent;
	}
	return coords;
}

function urlEncode(str){
	str = escape(str);
	str = str.replace(/\+/g, "%2b");
	str = str.replace(/ /g, "+");
	return str;
}

function urlDecode(str){
	str = str.replace(/\+/g, " ");
	str = str.replace(/\%2[B,b]/g, "+");
	str = unescape(str);
	return str;
}

var _pw_l,_pw_t,_pw_z;
function popWin(url,n,w,h,o) {
	if (w>screen.availWidth-12) w=screen.availWidth-12;
	if (h>screen.availHeight-48) h=screen.availHeight-48;
	_pw_l=(screen.availWidth-w-12)/2;
	_pw_t=(screen.availHeight-h-48)/2;
	_pw_z=window.open(url,n,'width='+w+',height='+h+',left='+_pw_l+',top='+_pw_t+','+o);
}

function setStyle(elemId, styleHash){
	var elem = document.getElementById(elemId);
   for (var name in styleHash){
     value = styleHash[name];
     if (name == "opacity"){
		  var value = (value == 100) ? 99.999 : value;
		  elem.style.KHTMLOpacity = value/100;  // Safari<1.2, Konqueror
		  elem.style.MozOpacity = value/100; // Older Mozilla and Firefox
		  elem.style.opacity = value/100;  // Safari 1.2, newer Firefox and Mozilla, CSS3
			elem.style.filter = "alpha(opacity:"+value+")";  // IE/Win 
		}
		else elem.style[name] = value;
   }
}

function enableNavOpacity(){
	if (!(isMac && isFirefox)){
		var TOTAL_NAV_ITEMS = 13;
		var curNavItem;
		for (var i=1; i<=TOTAL_NAV_ITEMS; i++){
			curNavItem = "item" + i;
			if (document.getElementById(curNavItem)!=null) setStyle(curNavItem,{opacity:93});
		}
	}
}


//MP based functions
function toggleLayer() {
	var obj;
	if(typeof(arguments[0]) == 'string') {
		obj = document.getElementById(arguments[0]);
	}
	else {
		obj = arguments[0];
	}
	if (obj.style.display == "block") {
		obj.style.display = "none"
	} 
	else {obj.style.display = "block"}
}

function genRandNum(range,start){
    if (!start) start = 0;
    num = Math.floor(Math.random()*range) + start;
    return num;
}

function getRandArrVal(mArr){
    return(mArr[genRandNum(mArr.length)]);
}

function getTwoDigitValue(num) {
    if (num.length > 1) {
        return num;
    } else {
        return "0" + num;
    }
}

function resize_browser(){
	var	chromeHeight,
		chromeWidth,
		top,
		left,
		currHeight = 300,
		currWidth = 400;

	var width = parseInt(arguments[0]);
	var height = parseInt(arguments[1]);

	if(window.outerWidth && window.outerHeight){
		currWidth = window.outerWidth;
		currHeight = window.outerHeight;
	}
	else{
		window.resizeTo(currWidth,currHeight); //temp resize to get correct window size
	}
	//get chrome size
	var chromeWidth  = (typeof window.innerWidth == "number") 
						? window.innerWidth
						: (document.documentElement && document.documentElement.clientWidth) 
							? window.document.documentElement.clientWidth 
							: window.document.body.clientWidth;
	var chromeHeight = (typeof window.innerHeight == "number") 
						? window.innerHeight 
						: (document.documentElement && document.documentElement.clientHeight)
							? window.document.documentElement.clientHeight 
							: window.document.body.clientHeight;

	width = width + (currWidth-chromeWidth);
	height = height + (currHeight-chromeHeight);
	if( width > screen.availWidth ) { width = screen.availWidth; }
	if( height > screen.availHeight ) { height = screen.availHeight; }
	window.resizeTo( width, height );
	
	left = (screen.availWidth - width) / 2;
	top = (screen.availHeight - height) / 2;

	window.moveTo(left, top);

	//resize again for safari & IE7 bug
	window.resizeTo( width, height );
};

