var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

var topobj = null;
var top_prevobj = null;
var top_defaultobj = null;
var top_imgobj = null;
var topimg_src = null;
var gimg_src = null;

var top_timeset = null;
if( isNS4 ) document.captureEvents(Event.KEYPRESS);

function checkEnter( frm, mode )
{
	var pKey;

	if( isNS4 )
		pKey = e.which;
	else
		pKey = event.keyCode;

	if( pKey == 13 )
	{
		frm.submit();
	}
}

function id2obj( id )
{
	var obj = null;

	if( isDOM )
		obj = document.getElementById(id);
	else if( isIE4 )
		obj = document.all[id];
	else
		obj = document.layers[id];

	return( obj );
}

function id2opener_obj( id )
{
	var obj;

	if( isDOM )
		obj = opener.document.getElementById(id);
	else if( isIE4 )
		obj = opener.document.all[id];
	else
		obj = opener.document.layers[id];

	return( obj );
}

function ObjectDisp( str )
{
	document.write( str );
}


function open_win(url, winName, width, height, ckScroll, ckTool)
{
	var window_top = screen.height/2 -(height/2);
	var window_left =  screen.width/2 -(width/2);
	if(!ckTool){ckTool="no";}
	window.open(url,winName,'width='+ width +',height=' + height + ',scrollbars=' + ckScroll + ',toolbar=' + ckTool + ',top=' + window_top + ',left=' + window_left + '');
}

function ChkLength( chkfield, movefield, chklen )
{
	if( chkfield.value.length == chklen )
	{
		movefield.focus();
		movefield.select();
	}
}

function dispMenu( divid_set )
{
	if( top_timeset )
	{
		clearTimeout(top_timeset);
		top_timeset = null;
	}
	if( top_defaultobj )
		top_defaultobj.style.display='none';
	if(top_prevobj)
		top_prevobj.style.display='none';

	topobj=id2obj( divid_set );
	if(topobj)
	{
		topobj.style.display='block';
		top_prevobj=topobj;
	}
}

function realHidden( divid_set )
{
	topobj=id2obj( divid_set );
	if(topobj)
		topobj.style.display='none';

	if( top_defaultobj )
		top_defaultobj.style.display='block';
	if( top_imgobj && topimg_src )
		top_imgobj.src = topimg_src;
}

function hiddenMenu( divid_set )
{
	if( top_timeset )
	{
		clearTimeout(top_timeset);
		top_timeset = null;
	}
	top_timeset=setTimeout('realHidden(\'' + divid_set + '\')', 5000);

}

function clearMenu()
{
	if( top_timeset )
	{
		clearTimeout(top_timeset);
		top_timeset = null;
	}
}


var prevDispObj = null;
var prevThisObj = null;
function dispDetail( thisObj , dispObj)
{
	var obj = null;
	if( prevThisObj && prevThisObj != thisObj )
	{
		prevThisObj.style.color = '#FE8787';
		prevThisObj.style.fontWeight = 'normal';
	}

	obj = id2obj(dispObj);
	if( obj )
	{
		if( prevDispObj && prevDispObj != obj )
			prevDispObj.style.display = 'none';

		if( obj.style.display == 'none' )
		{
			thisObj.style.color = '#FFF288';
			thisObj.style.fontWeight = 'bold';
			obj.style.display = 'block';
			prevDispObj = obj;
			prevThisObj = thisObj;
		}
		else
		{
			thisObj.style.color = '#FE8787';
			thisObj.style.fontWeight = 'normal';
			obj.style.display = 'none';
			prevDispObj = null;
			prevThisObj = null;
		}
	}
}


function resizeFrame()
{
	var obj, b;

	obj = id2obj( 'NEED_RESIZE_IFRAME' );

	if( !obj || obj == 'undefined' || obj == 'null' )
		return;
	
	b = obj.document.body;

	if ( b.scrollHeight!=null && b.scrollHeight > 0 )
		obj.style.height = b.scrollHeight;
}

function __SetIframeResize( lowWidth, lowHeight )
{
	try	{
		var swidth, sheight;
		if( lowWidth > document.body.scrollWidth )
			swidth = lowWidth;
		else
			swidth = document.body.scrollWidth;
		if( lowHeight > document.body.scrollHeight )
			sheight = lowHeight;
		else
			sheight = document.body.scrollHeight;

		window.resizeTo(swidth, sheight);
		document.body.style.height = sheight;
	}
	catch(e) { }
}

var arr_Idx = new Array();
var gTimeSet = new Array();
//var gBannerVar = new Array();
function SetAllBanner( sec, pos, absIdx )
{
	var key;
	var i, selIdx, bannLen, btIdx, selIdx;
	var adTimeS = new Date();
	var aryBanner = new Array();
	var type, url, w, h, str, target;
	var obj, obj_id;

	key = 'b_'+ sec + '_' + pos;
	if(absIdx)
		obj_id = 'b' + sec + '_' + pos + '_' + absIdx;
	else
		obj_id = 'b' + sec + '_' + pos;

	if( !gBannerVar[key] )
		return;

	if( gTimeSet[key] )
	{
		window.clearTimeout( gTimeSet[key] );
		gTimeSet[key] = null;
	}


	bannLen = gBannerVar[key].length;

	if( bannLen <= 1 )
		return;

	if( !absIdx )
	{
		if( arr_Idx[key] )
		{
			btIdx = arr_Idx[key];
			if( btIdx >= bannLen )
			{ 
				btIdx = 1;
				selIdx = 1;
			}
			else
				selIdx = btIdx;
			
			btIdx++;
			arr_Idx[key] = btIdx;
		}
		else
		{
			if((bannLen - 1) > 0)
			{
				btIdx = adTimeS.getSeconds() % (bannLen - 1);
				selIdx = 1 + btIdx;
			}else
			{
				btIdx = 1;
				selIdx = 1;
			}
			btIdx++;
			arr_Idx[key] = btIdx;
		}
	}
	else
		selIdx = absIdx;

	aryBanner = gBannerVar[key][selIdx].split( '|' );

	if( aryBanner.length > 3 )
	{
		type = aryBanner[0];
		url = aryBanner[1];
		link = aryBanner[2];
		w = aryBanner[3];
		h = aryBanner[4];
		target = aryBanner[5];
		str = '';
		switch( type )
		{
		case '1' :
			//image
			if( target == '' )
				str = '<a href="' + link + '">';
			else
				str = '<a href="' + link + '" target="_blank">';
			str += '<img src="' + url + '" border=0 width="' + w + '" height="' + h + '"></a>';
			break;
		case '2' :
			//flash
			str='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH="' + w + '" HEIGHT="' + h + '">';
			str += '<PARAM NAME=movie VALUE="' + url + '">';
			str += '<PARAM NAME=quality VALUE=high>';
			str += '<PARAM name="wmode" value="transparent">';
			str += '<EMBED src="' + url + '" quality="high"  WIDTH="' + w + '" HEIGHT="' + h + '" swLiveConnect=true TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
			str += '</EMBED>';
			str += '</OBJECT>';
			break;
		default :
			return;
			break;
		}
	}
	else 
		return;

	obj = id2obj( obj_id );
	if( obj && str != '' )
	{
		obj.innerHTML = str;
	}

	if( !absIdx && bannLen > 2)
	{
		gTimeSet[key] = window.setTimeout('SetAllBanner(\'' + sec + '\', \'' + pos + '\')', 120000);
	}
}


