/**
 * flashGame.js is the function included javascript functions for flash game pages in yoyo site.
*/
var arrFlashGame = new Array();
/**
 * function addFlashGame add flash game object into buffer.
 * @param - flashGame - Flash game object to be added.
*/
function addFlashGame(oFlashGame)
{ // add flash game object into buffer.
	var i = arrFlashGame.length;
	arrFlashGame[i] = oFlashGame;
} // End of function addFlashGame
/**
 * function getFlashGame return flash game object.
 * It return null while the flash game is not found.
 * @param - Integer - Flash game id.
 * @return - flashGame - Found flash game.
*/
function getFlashGame(iId)
{ // return flash game object.
	var oResult = null;
	if(arrFlashGame.length == 0) return oResult;
	for(var i = 0; i < arrFlashGame.length; i ++)
	{
		var oFlashGame = arrFlashGame[i];
		if(oFlashGame.intId != iId) continue;
		oResult = oFlashGame;
	}// End of for(var i = 0; i < arrFlashGame.length; i ++)
	if(oResult == null)
	{
		// Compose message.
		var strMsg = 'Flash game ID = ' + iId;
		strMsg += ' not found';
		setWinStatus(strMsg);
	} // End of if(oResult == null)
	return oResult;
} // End of function getFlashGame
/**
 * Class flashGrame keeps flash game information and provide function for the involved pages.
*/
function flashGame(iId)
{
	// Properties.
	this.intId = iId; // Id of the flash game.
	this.strTitle = ''; // Title of the game.
	this.strIcnOver = ''; // Icon for mouse over.
	this.strIcnOut = ''; // Icon for mouse out.
	this.strURL = ''; // URL to the actual game.
	this.oImg = null; // Image to show this game.
	
	// Methods
	this.setImg = flashGame_setFlashGameImg;
	this.onMouseOut = flashGame_onMouseOut;
	this.onMouseOver = flashGame_onMouseOver;
	this.ldImg = flashGame_ldImg;

}// End of function flashGame
/**
 * function flashGame::setImg set image for the flash game.
 * @param - IMG - Image in HTML page.
*/
function flashGame_setFlashGameImg(oImg)
{
	var bResult = false;
	if(oImg == null)
	{
		// Compose message.
		var sMsg = 'Pass-in null';
		sMsg += ' set link image terminated!';
		setWinStatus(sMsg);
		return bResult;
	}// End of if(oImg == null)
	if(typeof(oImg) == 'undefined')
	{
		// Compose message.
		var sMsg = 'Pass-in undefined object';
		sMsg += ' set link image terminated!';
		setWinStatus(sMsg);
		return bResult;
	}// End of if(typeof(oImg) == 'undefined')
	this.oImg = oImg;
	bResult = true;
	// Load the default icon.
	if(this.strIcnOut != '')
	{
		bResult = this.onMouseOut();
	} // End of if(this.strIcnOut != '')
	return bResult; 
}// End of function flashGame_setFlashGrameImg
/**
 * function flashGame::ldImg load link image.
 * @param - String - Image URL.
 * @return - Boolean - Flag indicate whether the process is run successfully.
*/
function flashGame_ldImg(strPath)
{ // set link image.
	var bResult = false;
	var oImg = this.oImg;
	if(oImg == null)
	{
		// Compose message.
		var strMsg = 'Link icon not set.';
		strMsg += ' ID = ' + this.intId;
		strMsg += ' TITLE = ' + this.strTitle;
		setWinStatus(strMsg);
		return bResult;
	}// End of if(oImg == null)
	if(typeof(oImg.src) == 'undefined')
	{
		// Compose message.
		var strMsg = 'Link icon is not valid IMG.';
		setWinStatus(strMsg);
		return bResult;
	}// End of if(typeof(oImg.src) == 'undefined')
	oImg.src = strPath;
	bResult = true;
	return bResult;
} // End of function flashGame_ldImg
/**
 * function flashGame::onMouseOut even for mouse move out.
*/
function flashGame_onMouseOut()
{ // even for mouse move out.
	
	var bResult = false;
	if(this.strIcnOut == '')
	{ 
		// Compose message.
		var strMsg = 'Default icon not set.';
		setWinStatus(strMsg);
		return bResult;
	} // End of if(this.strIcnOut == '')

	bResult = this.ldImg(this.strIcnOut);
	return bResult;
} // End of function flashGame_onMouseOut
/**
 * function flashGame::onMouseOver even for mouse move over.
*/
function flashGame_onMouseOver()
{ // even for mouse move over.
	
	var bResult = false;
	if(this.strIcnOver == '')
	{ 
		// Compose message.
		var strMsg = 'Hi-Light icon not set.';
		setWinStatus(strMsg);
		return bResult;
	} // End of if(this.strIcnOver == '')
	
	bResult = this.ldImg(this.strIcnOver);
	return bResult;
} // End of function flashGame_onMouseOver

/**
 * function getFlashImg return flash image by pass-in id.
 * It return null if the image not found.
 * @param - Integer - Flash id.
 * @return - IMG - Image object.
*/
function getFlashImg(i)
{ // return flash image by pass-in id.
	var strImgName = 'imgFlash' + i;
	var oResult = document.getElementById(strImgName);
	if(oResult == null)
	{// Cant get by id.
		// Try get it by name
		var arrElements = document.getElementsByName(strImgName);
		oResult = arrElements[0];
	}// End of if(oResult == null)
	return oResult;
} // End of function getFlashImg

/**
 * function trflash_onMouseOver even during mouse move over flash row.
 * The function should be set with ONMOUSEOVER even of flash tr.
 * @param - TR
 * @param - Integer - Flash id.
*/
function trflash_onMouseOver(oTR, i)
{ // even during mouse over flash row.
	// Keeps the original color.
	oTR.sOriBkColor = oTR.style.backgroundColor;
	// Change background color to hi-light color.
	tr_chColor(oTR, '#FFFF99');

	var oFlashGame = getFlashGame(i);
	if(oFlashGame == null) return;
	oFlashGame.onMouseOver();
} // End of function trflash_onMouseOver
/**
 * function trflash_onMouseOut even during mouse move out flash row.
 * The function should be set with ONMOUSEOUT even of flash tr.
 * @param - TR
 * @param - Integer - Flash id.
*/
function trflash_onMouseOut(oTR, i)
{ // even during mouse move out flash row.
	// Restore the background color.
	tr_chColor(oTR, oTR.sOriBkColor);

	var oFlashGame = getFlashGame(i);
	if(oFlashGame == null) return;
	oFlashGame.onMouseOut();
} // End of function trflash_onMouseOut
/**
 * function trflash_onClick even of click with flash row.
 * @param - TR
 * @param - Integer - Flash id.
*/
function trflash_onClick(oTR, i)
{ // even of click with flash row.
	var sOriBkColor = oTR.style.backgroundColor;
	// Change background color to click color.
	tr_chColor(oTR, '#FF0000');

	var oFlashGame = getFlashGame(i);
	if(oFlashGame != null)
	{
	}// End of if(oFlashGame != null)

	// Restore the background color.
	tr_chColor(oTR, sOriBkColor);
} // End of function trflash_onClick

/**
 * function trflash_onClick is the even of clicking flash game row.
 * @param - Integer - Flash game id.
*/
function trflash_onClick(intId)
{
	// Get id control.
	var oCtrl = getTransFieldCtrl('iFlashId');
	if(oCtrl == false) return; // id control not found terminate.
	// Backup id.
	var iOriId = oCtrl.value;
	oCtrl.value = intId;

	var oFrm= getTransFrm();
	if(oFrm == false) return; // Submit form not existed. Terminated.
	// Backup form information.
	var sOriTarget = oFrm.target;
	var sOriAction = oFrm.action;
	var sURL = 'yoyoflashGameDtl.php';
	oFrm.action = sURL;
	var sAttr = 'menubar = no, ';
	sAttr += ' location = no, ';
	sAttr += ' status = yes, ';
	sAttr += ' scrollbars = yes, ';
	sAttr += ' toolbar = no, ';
	sAttr += ' left =0, ';
	sAttr += ' top = 0, ';
	sAttr += ' width =800, ';
	sAttr += ' height = 600, ';
	sAttr += ' resizable = yes';
	var winOpen = window.open('', 'openningDailog',sAttr);
	oFrm.target = 'openningDailog';
	oFrm.submit();

	// Restore id.
	oCtrl.value = iOriId;
	
	// Restore form information.
	oFrm.target = sOriTarget;
	oFrm.action = sOriAction;
}// End of function trflash_onClick

function tr_chColor(oTR, strColor)
{ // change background color for tr
	oTR.style.backgroundColor = strColor;
} // End of function tr_chColor
