/*
common.js
(c)2007 PHCreative.com All Rights reserved.
Author:JC
Date:07/05/2007
Desc: Commonly used Javascript functions.
*/

function Element_GetXPos(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}
//
function Element_GetYPos(obj)
{
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ViewSource(objWindow) {
//objWindow.location = "view-source:" + objWindow.location.href 
//window.open("view-source:" + objWindow.location.href );
window.open( '', 'SourceWindow', '' ).document.write( '<textarea cols=80 rows=20>' + objWindow.document.body.parentNode.innerHTML + '</textarea>' )
}

var _flashids = 0;

function SquirtFlash(moviepath, width, height, id, onmouseover, onmouseout)
{
	var objectId = "";

	if(id == null || "" == id)
	{
		_flashids ++;
		objectId = "FlashObject_" + _flashids;
	}
	else
	{
		objectId = id;
	}

	if(onmouseover == null) var onmouseover = "";
	if(onmouseout == null) var onmouseout = "";

	document.write("<object onmouseout=\"" + onmouseout + "\" onmouseover=\"" + onmouseover + "\" id=\"" + objectId + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + width + "\" height=\"" + height + "\"> \n");
	document.write("	<param name=\"movie\" value=\"" + moviepath + "\"> \n");
	document.write("	<param name=\"quality\" value=\"high\"> \n");
	document.write("	<param name=\"wmode\" value=\"transparent\" > \n");
	document.write("	<embed wmode=\"transparent\" onmouseout=\"" + onmouseout + "\" onmouseover=\"" + onmouseover + "\" src=\"" + moviepath + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed> \n");
	document.write("</object> \n");
}

function SetImage(id, imageFile)
{
	var imgName = _sBasePath + "/res/builtin/" + imageFile;

	var objImage = document.getElementById(id); 
	objImage.src = imgName;

}

function OpenImage(filename, width, height)
{
	var objWindow = OpenWindow(filename, width, height, "ImageWindow");
}

function OpenWindow(url, width, height, name, fullwindow)
{
	var posy = (screen.availHeight / 2) - (height / 2);
	var posx = (screen.availWidth / 2) - (width / 2 ) ;
	var status = "resizable=yes,scrollbars=yes,status=yes";
	
	if(fullwindow)
	{
		status == "";
	}
	return window.open(url, name, "width=" + width + ",height=" + height + "," + status + ",top=" + posy + ",left=" + posx);
}