
var onloadHandlers = new Array();
var isBodyLoaded = false;
var isDisplayDivHelpInfo = false;
var showHelpInfoTime = (new Date()).getTime();
function page_onload() {
	for (var index = 0; index < onloadHandlers.length; index++) {
		if (index > 0) {
			onloadHandlers[lnIndex]();
		}
	}
}
function getElementById(controlId) {
	var control = document.getElementById(controlId);
	if(control!=null)
		return control;
	else
		return getElementByName(controlId);
}
function getElementByName(controlName) {
	var control = document.getElementsByName(controlName);
	if(control.length > 0)
		return control[0];
	else 
		return null;
}
function showMessage(message) {
	alert(message);
}
function showException(exception) {
	showMessage(exception);
}
function appendQueryString(url, queryString) {
	var index = url.indexOf("?");
	if (queryString == "") {
		return url;
	}
	if (index >= 0) {
		return url + "&" + queryString;
	} else {
		return url + "?" + queryString;
	}
}
function SearchEvent() {
	func = SearchEvent.caller;
	while (func != null) {
		var arg0 = func.arguments[0];
		if (arg0) {
			if (arg0.constructor == MouseEvent) {
				return arg0;
			}
		}
		func = func.caller;
	}
	return null;
}
function OpenInsetPage(width, height, url, top, left) {
	showDiv("divInsetPage", width, height, top, left);
	var loInsertIFrame = getElementById("ifrmInsetPage");
	loInsertIFrame.src = appendQueryString(url, "time=" + new Date());
}


function showDiv(divId, width, height, top, left,notDisplay) {
	//Get Div left and Top
	if(typeof (notDisplay) == "undefined")
		notDisplay=false;
	var loInsertDiv = getElementById(divId);
	Drag.init(loInsertDiv);
	if (typeof (event) == "undefined") {
		evt = SearchEvent();
	} else {
		evt = event;
	}
	var lnLeft = 0;
	var lnTop = 0;
	var lnRightedge = document.body.clientWidth - evt.clientX;
	var lnBottomedge = document.body.clientHeight - evt.clientY;
	if (lnRightedge < width) {
		lnLeft = document.body.scrollLeft + evt.clientX - width - 10;
		if (lnLeft < 0) {
			lnLeft = document.body.scrollLeft + evt.clientX + 10;
		}
	} else {
		lnLeft = document.body.scrollLeft + evt.clientX + 10;
	}
	if (lnBottomedge < height) {
		lnTop = document.body.scrollTop + evt.clientY - height ;
		if (lnTop < 0) {
			lnTop = document.body.scrollTop + evt.clientY ;
		}
	} else {
		lnTop = document.body.scrollTop + evt.clientY ;
	}
	//Set Div Attribute	
	if(top!=null) lnTop = top;
	if(left!=null) lnLeft = left;
	if(!notDisplay)
		if(loInsertDiv.style.display!="") loInsertDiv.style.display = "";
	else
		loInsertDiv.style.display="none";
	if(loInsertDiv.style.left != lnLeft) loInsertDiv.style.left = lnLeft;
	if(loInsertDiv.style.top != lnTop)loInsertDiv.style.top = lnTop;
	if(loInsertDiv.style.height != height) loInsertDiv.style.height = height;
	if(loInsertDiv.style.width != width) loInsertDiv.style.width = width;
}

function closeInsetPage() {
	getElementById("divInsetPage").style.display = "none";
}
function resetInsetPageSize(width,height) {
	var loInsertDiv = window.parent.getElementById("divInsetPage");
	if (loInsertDiv != null) {
		if(width==null||height==null)
		{
			loInsertDiv.style.height = window.self.document.body.scrollHeight + 4;
			loInsertDiv.style.width = window.self.document.body.scrollWidth + 4;
		}else{
			loInsertDiv.style.height =height;
			loInsertDiv.style.width = width;
		}	
	}
	refreshInsetPageTitle();
}
function refreshInsetPageTitle(){
	var insetPageTitle = window.parent.getElementById("divInsetPageTitle");
	if (insetPageTitle != null) {
		if (window.self.getElementById("insetPageTitle") != null) {
			insetPageTitle.innerHTML = window.self.getElementById("insetPageTitle").value;
		} else {
			insetPageTitle.innerHTML = "&nbsp;";
		}
	}
}
// Application related
function toCreateElement() {
	var txtChangeAction = getElementById("changeAction");
	if (txtChangeAction != null && txtChangeAction.value == "Create") {
		return true;
	} else {
		return false;
	}
}
function setControlContent(controlId, innerHTML) {
	var control = getElementById(controlId);
	control.style.display = "none";
	control.innerHTML = innerHTML;
	control.style.display = "";
}
function getposOffset(overlay, offsettype) {
	var totaloffset = (offsettype == "left") ? overlay.offsetLeft : overlay.offsetTop;
	var parentEl = overlay.offsetParent;
	while (parentEl != null) {
		totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	return totaloffset;
}
function overlay(curobj, subobjstr, width, opt_position) {
	var subobj;
	if (subobjstr == null || subobjstr == "") {
		subobj = createOverDiv();
	} else {
		subobj = getElementById(subobjstr);
	}
	//subobj.onmouseout =  function(){overlayclose(subobj.id)};		
	subobj.setAttribute("className", "OverlayDiv");
	subobj.style.display = (subobj.style.display != "block") ? "block" : "none";
	var xpos = getposOffset(curobj, "left") + ((typeof opt_position != "undefined" && opt_position.indexOf("right") != -1) ? -(subobj.offsetWidth - curobj.offsetWidth) : 0);
	var ypos = getposOffset(curobj, "top") + curobj.offsetHeight;
	subobj.style.left = xpos + "px";
	subobj.style.top = ypos + "px";
	if (width != null) {
		subobj.style.width = width + "px";
	}
	return subobj;
}
function overlayclose(subobj) {
	getElementById(subobj).style.display = "none";
	if(getElementById("IfrmdivShim")!=null)
		getElementById("IfrmdivShim").style.display = "none";
}
function createOverDiv() {
	if (getElementById("divcontent") == null) {
		var obj = document.createElement("DIV");
		obj.setAttribute("id", "divcontent");
		document.body.appendChild(obj);
	}
	return getElementById("divcontent");
}
function overDivlayout(divsubobj) {	
	var IfrRef = getElementById("IfrmdivShim");
	if(IfrRef==null){
		var IfrRef = document.createElement("iframe");
			IfrRef.setAttribute("id", "IfrmdivShim");
			IfrRef.style.position="absolute";
			document.body.appendChild(IfrRef);
	}	
	IfrRef.style.display = divsubobj.style.display;
	IfrRef.style.width = divsubobj.offsetWidth;
	IfrRef.style.height = divsubobj.offsetHeight;
	IfrRef.style.top = divsubobj.style.top;
	IfrRef.style.left = divsubobj.style.left;
	IfrRef.style.zIndex = divsubobj.style.zIndex;	
}

function closeInsetPage(){
	getElementById('divInsetPage').style.display='none';
}

function writeLoadingInfo(controlId){
	var control = getElementById(controlId);
	writeLoadingInfoByObject(control);
}

function writeLoadingInfoByObject(control){
	if(control==null) return false;
	var loadingHtml ="<table align=\"center\" style=\"position:relative;z-index:100000\">"
	+ "<tr><td height=\"20px\"></td></tr>" 
	+ "<tr><td><img src=\"image/load.gif\"></td><td class=\"HighLightInfo\">loading...</td></tr>" 
	+ "</table>";
	control.innerHTML = loadingHtml;
}

function writeLoadingInfoCenter(controlId){
	var control = getElementById(controlId);
	if(control==null) return false;
	var loadingHtml ="<table width=\"100%\" align=\"center\">"
	+ "<tr><td height=\"30px\"></td></tr>" 
	+ "<tr><td width=\"100px\" align=\"right\"><img src=\"image/load.gif\"></td><td class=\"HighLightInfo\">loading...</td></tr>" 
	+ "</table>";
	control.innerHTML = loadingHtml;
}
	
function writeLoadingMsg(controlId,msg){
	var control = getElementById(controlId);
	if(control==null) return false;
	var loadingHtml ="<table align=\"center\">"
	+ "<tr><td height=\"20px\"></td></tr>" 
	+ "<tr><td><img src=\"image/load.gif\"></td><td class=\"HighLightInfo\">"+ msg + "</td></tr>" 
	+ "</table>";
	control.innerHTML = loadingHtml;
}

function setFunletProcessTime(action){
	sendHttpRequest("setFunletProcessTime.do?action=" + action + "&funletId=" + document.all("funletId").value);
}

function showCoinOriginalImage(individualCoinId, side){ 
	window.open("./showCoinImg.do?individualCoinId="+individualCoinId+"&side=" +side,"NewWin","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=640,height=500"); 
	return; 
}
function setControlAttribute(control,attributeName,value){
	if(attributeName=="innerText")
	{
		if (control.innerText!=null) {   
        	control.innerText =value;   
	    } else if(control.textContent){    
        	control.textContent =value;    
	    } 
	}else
		control[attributeName] = value;
}
function getControlAttribute(control,attributeName){
	var value;
	if(attributeName=="innerText")
	{
		if (control.innerText!=null) {   
        	value = control.innerText;   
	    } else if(control.textContent){    
        	value = control.textContent;    
	    } 
	}else
		value = control[attributeName];
	return value;
}

function resetCurrencyControl(control){
	if(control==null)
		return;
	else{
		if(navigator.userAgent.indexOf("MSIE")>0){
			control.onfocusout = function() {currencyTextBox_onfocusout(control);}
			control.onfocusin = function() {currencyTextBox_onfocusin(control);}
		}else{		
			control.onblur = function() {currencyTextBox_onfocusout(control);}
			control.onfocus = function() {currencyTextBox_onfocusin(control);}
		}
	}
}

function getFrameDocument(frame){
	if(frame.document)
		return frame.document;
	else
		return frame.contentDocument;
}
function getFrameElement(frame){
	if(frame.frameElement)
		return frame.frameElement;
	else
		return frame.contentWindow.frameElement;
}

function getBrowserType(){
	if(window.ActiveXObject)
		return "ie";
	else
		return "mozilla";
}
function doRight(e){
}

function showImages(obImage,reImage){
	if(obImage!=null&&reImage!=null){
		divImage.innerHTML = "<table><tr><td><img id=obverseSideImg src='" + obImage + "'/></td><td><img id=reverseSideImg src='" + reImage + "'/></td></tr></table>";
		showDiv("divImage",300,100);
	}
}

function hiddenImages() {
	divImage.style.display='none';
}

function showNotLogin(){
	if(getElementById("hidValidateUser").value == 'notLoginUser'){
		OpenInsetPage(450,250,"./notLogin.do");
		return false;					
	}else{
		return true;
	}
}

function showGoogleSearch(){
	getElementById("sbi").value=getElementById("qsbi").value;
	frmGoogleSearch.submit();
}

function showInteractiveHelp(hidHelpId,hidHelpLinkId,divWidth,divHeight){
	var hidHelpValue = getElementById(hidHelpId).value;
	var hidHelpLinkValue = getElementById(hidHelpLinkId).value;
	if(hidHelpValue!=null && hidHelpValue!="" && hidHelpLinkValue!=null && hidHelpLinkValue!=""){
		var divHelpHtml = "<table style='border-style:solid;border-width:1px; border-color: #808080; background-color: #FFFFEB;'><tr><td class='NormalInfo'>"+hidHelpValue+"&nbsp;<a target='_blank' href="+hidHelpLinkValue+"><fmt:message key='helpText' bundle='${uis}'/></a></td></tr></table>";
		
		getElementById("divHelpInfo").style.display='none';
		getElementById("divHelpInfo").innerHTML = divHelpHtml;
		var thisShowTime =  (new Date()).getTime();
		showHelpInfoTime = thisShowTime;
		
		showDiv("divHelpInfo",200,'',null,null,true);
		
		window.setTimeout(function(){showInteractiveHelpByEvent("divHelpInfo",thisShowTime)},1000);
		setDivHelpInfo(false);
	}
}

function showInteractiveHelpByEvent(divId,thisShowTime){
	if(thisShowTime==showHelpInfoTime)
		getElementById(divId).style.display="";
}

function hiddenHelpInfo() {
	isDisplayDivHelpInfo = true;
	window.setTimeout("hiddenDivHelpInfo();",1000); 
}

function hiddenDivHelpInfo() {
	if(isDisplayDivHelpInfo){
		divHelpInfo.style.display='none';
	}
}

function setDivHelpInfo(value) {
	isDisplayDivHelpInfo = value;
	window.setTimeout("hiddenDivHelpInfo();",1000); 
}

function changeButtonBg(button, image){
	button.style.backgroundImage = "url(./image/" + image + ")";
}

function changeTopMenuStyle(topMenu){
	if(topMenu.className!='TopMenuSelectedItem'){
		if(topMenu.className=='TopMenuItem'){
			topMenu.className='TopMenuMouseOverItem';
			topMenu.firstChild.className='TopMenuSelectedItemLink';
		}else{
			topMenu.className='TopMenuItem';
			topMenu.firstChild.className='TopMenuItemLink';
		}
	}
}

function showExceptions(displaySystemErrors){
	var index=0;
	var exceptionMsgs = getElementById("exceptionMsg"+index);
	while(exceptionMsgs!=null){
		if(displaySystemErrors)
			exceptionMsgs.style.display="";	
		else{
			if(exceptionMsgs.isSystemError=="1")
				exceptionMsgs.style.display ="none";
			else
				exceptionMsgs.style.display ="";
		}
		index++;
		exceptionMsgs = getElementById("exceptionMsg"+index);
	}
}
