String.prototype.trim = function() {
	a = this.replace(/^\s+/, ''); return a.replace(/\s+$/, '');
};
function $(idname){
	if (document.getElementById){ return document.getElementById(idname); } 
	else if (document.all) { return document.all[idname];} 
	else if (document.layers) {	return document.layers[idname];	}
	else { return null; }
};
function $$(idname){
	return document.frames?document.frames[idname]:$(idname).contentWindow;
}
function $t(parentobj, tag){
	if (typeof parentobj.getElementsByTagName != 'undefined') {return parentobj.getElementsByTagName(tag);}
	else if (parentobj.all && parentobj.all.tags){return parentobj.all.tags(tag);}
	else {return null;}
};
function $x(parentobj, tag) {
	var tags = $t(parentobj, tag);
	return tags[0].firstChild.nodeValue;
}
function $c(s){
	return document.createElement(s);
};
function is_null(val){
	return (val == "" || val == null || val == "undefined");
};
function str_len(key){
	var l=escape(key),len; 
	len=l.length-(l.length-l.replace(/\%u/g,"u").length)*4;
	l=l.replace(/\%u/g,"uu");
	len=len-(l.length-l.replace(/\%/g,"").length)*2;
	return len;
};

var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;
var uniqnum_counter = (new Date).getTime();
var is_regexp = (window.RegExp) ? true : false;
var gidname = '';

function exist(s)
{
	return $(s)!=null;
}

function myInnerHTML(idname, html)
{
	if (exist(idname))
	{
		$(idname).innerHTML = html;
	}
}

function dialog()
{
	var titile = 'EasyChannel.HK 提示';
	var width = 350;
	var height = 120;
	var sFunc = '<input id="dialogOk" type="button" value=" 確 定 " onclick="new dialog().reset();" style="width:80px;height:26px;line-height:22px;font-size:13px;"/> <input id="dialogCancel" type="button" value=" 取 消" onclick="new dialog().reset();" style="width:80px;height:26px;line-height:22px;font-size:13px;"/>';
	var sClose = '<input type="image" id="dialogBoxClose" onclick="new dialog().reset();" src="/images/v2_l_gb1.gif" border="0" width="10" height="10" align="absmiddle" />';
	var sBody = '\
		<table id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="6" width="100%">\
			<tr height="10"><td colspan="4"></td></tr>\
			<tr><td colspan="4" align="center">\
			<div id="dialogMsgDiv" style="text-align:center"><div id="dialogMsg" style="font-size:14px;line-height:180%;color:#118ab7;font-weight:bold;">&nbsp;</div></div>\
			</td></tr>\
			<tr><td id="dialogFunc" colspan="4" align="center">' + sFunc + '</td></tr>\
			<tr height="5"><td colspan="4" align="center"></td></tr>\
		</table>\
	';

	var sBox = '\
		<div id="dialogBox" style="border:1px solid #1e4775;display:none;z-index:9999;width:'+width+'px;">\
		<table width="100%" border="0" cellpadding="0" cellspacing="0">\
			<tr height="24" bgcolor="#54dc5a">\
				<td>\
					<table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#54dc5a;  height:25px; border-top:1px solid #65f36b;">\
						<tr>\
							<td width="6" height="24"></td>\
							<td id="dialogBoxTitle" style="color:#fff;font-size:12px;font-weight:bold;">&nbsp;</td>\
							<td id="dialogClose" width="20" align="right" valign="middle">\
								' + sClose + '\
							</td>\
							<td width="6"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr id="dialogHeight" style="height:' + height + '" valign="top">\
				<td id="dialogBody" bgcolor="#ffffff">' + sBody + '</td>\
			</tr>\
		</table></div><div id="dialogBoxShadow" style="display:none;z-index:9998;"></div>\
	';
	var sIfram = '\
		<iframe id="dialogIframBG" name="dialogIframBG" frameborder="0" marginheight="0" marginwidth="0" hspace="0" vspace="0" scrolling="no" style="position:absolute;z-index:9997;display:none;"></iframe>\
	';
	
	var sBG = '\
		<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;"></div>\
	';

	this.show = function()
	{
		this.middle('dialogBox');
		if ($('dialogIframBG'))
		{
			$('dialogIframBG').style.top = $('dialogBox').style.top;
			$('dialogIframBG').style.left = $('dialogBox').style.left;
			$('dialogIframBG').style.width = $('dialogBox').offsetWidth;
			$('dialogIframBG').style.height = $('dialogBox').offsetHeight;
			$('dialogIframBG').style.display = 'block';
		}
		if (!is_opera) {
			this.shadow();
		}
	}

	this.reset = function()
	{
		this.close();
		_set_id_focus();
	}
	
	this.resets = function(parentobj, _sName)
	{
		this.close();
		try {parentobj._sName.submit();}catch (e){}
	}

	this.close = function()
	{
		if (window.removeEventListener) 
		{
			window.removeEventListener('resize', this.event_b, false);
			window.removeEventListener('scroll', this.event_b, false);
	    } 
	    else if (window.detachEvent) 
	    {
	    	try {
	        	window.detachEvent('onresize', this.event_b);
	        	window.detachEvent('onscroll', this.event_b);
	      	} catch (e) {}
	    }	    
		if ($('dialogIframBG')) {
			$('dialogIframBG').style.display = 'none';
		}
		$('dialogBox').style.display='none';
		$('dialogBoxBG').style.display='none';
		$('dialogBoxShadow').style.display = "none";
		myInnerHTML('dialogBody', sBody);				
	}
	this.html = function(_sHtml)
	{
		myInnerHTML('dialogBody', _sHtml);
		this.show();
	}

	this.init = function()
	{
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		if (!is_opera) {
			oDiv.innerHTML = sBG + sIfram + sBox;
		} else {
			oDiv.innerHTML = sBG + sBox;
		}
		document.body.appendChild(oDiv);
		$('dialogBoxBG').style.height = document.body.scrollHeight;		
	}

	this.button = function(_sId, _sFuc)
	{
		if($(_sId)) {
			$(_sId).style.display = '';
			if($(_sId).addEventListener) {
				if($(_sId).act) {
					$(_sId).removeEventListener('click', function(){eval($(_sId).act)}, false);
				}
				$(_sId).act = _sFuc;
				$(_sId).addEventListener('click', function(){eval(_sFuc)}, false);
			} else {
				if($(_sId).act) {
					$(_sId).detachEvent('onclick', function(){eval($(_sId).act)});
				}
				$(_sId).act = _sFuc;
				$(_sId).attachEvent('onclick', function(){eval(_sFuc)});
			}
		}
	}

	this.shadow = function()
	{
		var oDialog = $('dialogBox');
		this.event_b_show();
		if (window.attachEvent)
		{
			window.attachEvent('onresize', this.event_b);
			window.attachEvent('onscroll', this.event_b);
		}
		else
		{
			window.addEventListener('resize', this.event_b, false);
			window.addEventListener('scroll', this.event_b, false);
		}
	}
	
	this.event_b = function()
	{
		var oShadow = $('dialogBoxShadow');
		
		if (oShadow.style.display != "none")
		{		
			oShadow['style']['position'] = "absolute";
			oShadow['style']['display']	= "";		
			oShadow['style']['opacity']	= "0.2";
			oShadow['style']['filter'] = "alpha(opacity=20)";
			oShadow['style']['background']	= "#000";
			var sClientWidth = parent ? parent.document.body.offsetWidth : document.body.offsetWidth;
			var sClientHeight = parent ? parent.document.body.offsetHeight : document.body.offsetHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
			oShadow['style']['top'] = '0';
			oShadow['style']['left'] = '0';
			oShadow['style']['width'] = sClientWidth;
			oShadow['style']['height'] = sClientHeight + sScrollTop;
		}
	}
	
	this.event_b_show = function(e)
	{
		var oShadow = $('dialogBoxShadow');
		oShadow['style']['position'] = "absolute";
		oShadow['style']['display']	= "";		
		oShadow['style']['opacity']	= "0.2";
		oShadow['style']['filter'] = "alpha(opacity=20)";
		oShadow['style']['background']	= "#000";
		var sClientWidth = parent ? parent.document.body.offsetWidth : document.body.offsetWidth;
		var sClientHeight = parent ? parent.document.body.offsetHeight : document.body.offsetHeight;
		var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		oShadow['style']['top'] = '0';
		oShadow['style']['left'] = '0';
		oShadow['style']['width'] = sClientWidth;
		oShadow['style']['height'] = sClientHeight + sScrollTop;
	}

	this.open = function(_sUrl, _sMode, _sClose)
	{		
		this.show();
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			var openIframe = "<iframe width='100%' height='100%' name='iframe_parent' id='iframe_parent' src='" + _sUrl + "' frameborder='0' scrolling='" + _sMode + "'></iframe>";
			myInnerHTML('dialogBody', openIframe);
		}
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};
	}

	this.event = function(_sMsg, _sOk, _sCancel, _sClose)
	{
		myInnerHTML('dialogFunc', sFunc);
		myInnerHTML('dialogClose', sClose);
		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){};
		$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};

		_sOk && _sOk != "" ? this.button('dialogOk', _sOk) : $('dialogOk').style.display = 'none';
		_sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = 'none';
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};

		this.show();
	}

	this.set = function(_oAttr, _sVal)
	{
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		var oHeight = $('dialogHeight');

		if(!is_null(_sVal)) {
			switch(_oAttr)
			{
				case 'title':
					myInnerHTML('dialogBoxTitle', _sVal);
					break;
				case 'width':
					oDialog['style']['width'] = _sVal;
					break;
				case 'height':
					oHeight['style']['height'] = _sVal;
					break;
			}
		}
		this.middle('dialogBox');
		oShadow['style']['top'] = oDialog.offsetTop + 6;
		oShadow['style']['left'] = oDialog.offsetLeft + 6;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}

	this.middle = function(_sId)
	{
		try {
			var aIframe = parent.document.getElementById("iframe_parent");
		} catch (e){}
		if (aIframe) {
			var sClientWidth = aIframe.offsetWidth;
			var sClientHeight = aIframe.offsetHeight;
			var sScrollTop = 0;
		} else {
			var sClientWidth = parent ? parent.document.body.clientWidth : document.body.clientWidth;
			var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		}
		var sleft = (document.body.clientWidth / 2) - ($(_sId).offsetWidth / 2);
		var iTop = -80 + (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
		var sTop = iTop > 0 ? iTop : (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
		$(_sId)['style']['display'] = '';
		$(_sId)['style']['position'] = "absolute";
		$(_sId)['style']['left'] = sleft;
		$(_sId)['style']['top'] = sTop;
	}
}


function openWindow(_sUrl, _sWidth, _sHeight, _sTitle, _sClickNo, _sScroll)
{
	var oEdit = new dialog();
	oEdit.init('yes');
	oEdit.set('title', _sTitle ? _sTitle : "EasyChannel.HK 提示" );
	oEdit.set('width', _sWidth);
	oEdit.set('height', _sHeight);
	oEdit.open(_sUrl, _sScroll != "yes" ? 'no' : 'yes', _sClickNo);
}
