var MM_FlashCanPlay = false;

function popUp(popURL, popName, popLeft, popTop, popWidth, popHeight, popOptions) {
	screenWidth = screen.width - 16;
	screenHeight = screen.height - 96;
	if (popWidth > screenWidth) popWidth = screenWidth;
	if (popHeight > screenHeight) popHeight = screenHeight;
//	alert(screenWidth + ' x ' + screenHeight);
	if ((popLeft == 0)&&(popTop == 0)) {
	 	popLeft = (screenWidth) ? (screenWidth-popWidth)/2 : 0;
		popTop = (screenHeight) ? (screenHeight-popHeight)/2 : 0;
		if ((popWidth == 0)&&(popHeight == 0)) {
			popWidth = screenWidth;
			popHeight = screenHeight;
		}
	}
	var options = "width=" + (popWidth+16) + ",height=" + (popHeight+32) + ",left=" + popLeft + ",top=" + popTop;
	if (popOptions) {
		options = options + "," + popOptions;
	} else {
		options = options + ",scrollbars=yes,resizable=yes";
	}
	newWindow = window.open(popURL, popName, options);
//	alert(popLeft + ' x ' + popTop + ' x ' + popWidth + ' x ' + popHeight);
}

function setOffset(obj, lyr, offX, offY) {
	var newX = getOffsetLeft(obj);
	var newY = getOffsetTop(obj);
	if (offX) newX = newX + offX;
	if (offY) newY = newY + offY;
	
	var x = document.getElementById(lyr);

	if (x.style.width) {
		var overWidth = parseInt(x.style.width);
		var overHeight = parseInt(x.style.height);
	} else if (x.width) {
		var overWidth = parseInt(x.width);
		var overHeight = parseInt(x.height);
	}
	
	if (window.innerWidth) {
		var maxWidth = parseInt(window.innerWidth) - 24;
		var maxHeight = parseInt(window.innerHeight) - 16;
	} else if (parent.document.body.offsetWidth) {
		var maxWidth = parseInt(parent.document.body.offsetWidth) - 24;
		var maxHeight = parseInt(parent.document.body.offsetHeight) - 16;
	}
	
	if ((overWidth != '')&&(overHeight != '')&&(maxWidth != '')&&(maxHeight != '')) {
		if ((newX + overWidth) > maxWidth) newX = maxWidth - overWidth;
		if ((newY + overHeight) > maxHeight) newY = maxHeight - overHeight;
		if (newX < 0) newX = 0;
		if (newY < 0) newY = 0;
	}
	
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
	x.style.visibility = 'visible';
}

/*
function setOffset(obj, lyr, offX, offY) {
	var newX = getOffsetLeft(obj);
	var newY = getOffsetTop(obj);
	if (offX) newX = newX + offX;
	if (offY) newY = newY + offY;
	var x = document.getElementById(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
	x.style.visibility = 'visible';
}
*/
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	
	if (mOffsetParent.offsetParent) {
		while(mOffsetParent){
			mOffsetTop += mOffsetParent.offsetTop;
			mOffsetParent = mOffsetParent.offsetParent;
		}
	} else if (mOffsetParent.y) {
		mOffsetTop += mOffsetParent.y;
	}
	
	return mOffsetTop;
}

function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	
	if (mOffsetParent.offsetParent) {
		while(mOffsetParent) {
			mOffsetLeft += mOffsetParent.offsetLeft;
			mOffsetParent = mOffsetParent.offsetParent;
		}
	} else if (mOffsetParent.x) {
		mOffsetTop += mOffsetParent.x;
	}
	
	return mOffsetLeft;
}

function switchDisplay(objID) {
	var obj = document.getElementById(objID);
	if (obj.style.display == 'none') {
		obj.style.display = '';
	} else {
		obj.style.display = 'none';
	}
}

function flashInsert(flashContent, noFlashContent) {
	var MM_contentVersion = 6;
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	
	if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i) {
				if (isNaN(parseInt(words[i]))) continue;
				var MM_PluginVersion = words[i]; 
			}
		MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
		
	} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + MM_contentVersion + '")))\n');
		document.write('</scr' + 'ipt\> \n');
	} 
	
	document.write('<script type="text/javascript">\n');
	document.write('if ( MM_FlashCanPlay ) {\n');
	document.write('	document.write(\'' + flashContent + '\');\n');
	document.write('} else {\n');
	document.write('	document.write(\'' + noFlashContent + '\');\n');
	document.write('}\n');
	document.write('</script>\n');
}
