/*------------------------------------------------------------------- by gima --
|* document event¸¦ ¼³Á¤ÇÔ
|*............................................................................*/
function add_event( obj, type, func )
{
	if( obj.addEventListener ) obj.addEventListener( type, func, false ); else
	if( obj.attachEvent ) obj.attachEvent( 'on'+ type, func ); else
	obj['on'+ type] = func;
}

/*------------------------------------------------------------- by gima/v1.00 --
|* ÄíÅ°°ü·Ã ÇÔ¼ö
|*............................................................................*/
function setCookie( vari, value, days )
{
	var when = new Date();
	when.setDate( when.getDate() + days );	// ÀÏ¼ö ´õÇÔ
	when.setHours(0);	// Á¤ÇØÁø ³¯ÀÇ 0½Ã
	document.cookie = vari + "=" + value + ";path=/;expires=" + when.toGMTString() + ';';
}

function getCookie( vari )
{
	cookies = document.cookie + ";";

	if( ( pos = cookies.indexOf( vari + "=" ) ) == -1 )
		return false;

	spos = cookies.indexOf( "=" , pos );
	epos = cookies.indexOf( ";" , spos );
	return( cookies.substring( spos + 1 , epos ) );
}

/*------------------------------------------------- by gima/v1.00/c2008-08-22 --
|* Number Prototype: ¼ýÀÚ ¾Õ¿¡ length¸¸Å­ Á¦·Î(0)¸¦ ºÙ¿© ¹®ÀÚ¿­·Î ¸®ÅÏ
|* length °ªÀÌ ¾øÀ¸¸é 2 °¡ ±âº»
|*............................................................................*/
Number.prototype.zero = function( length )
{
	var value = this.toString();
	var length = typeof(length) == 'undefined' ? 2: length;

	for( var i = value.length; i < length; i++ )
		value = '0' + value;

	return value;
}

/*----------------------------------------------- by gima/ v1.00/ c2008-08-22 --
|* String Prototype: Word°¡ count¹øÂ° µîÀåÇÏ´Â index ¸®ÅÏ
|*............................................................................*/
String.prototype.countOf = function( word, count )
{
	var index = this.indexOf( word );
	for( var i = 1; i < count; i++ )
		index = this.indexOf( word, index + 1 );
	return index;
}

/*-------------------------------------------------------------- make by gima --
|* ÆË¾÷Ã¢ ¶ç¿ì±â
|*............................................................................*/
function mwin( url, name, xsize, ysize, scroll, top, left, resize, status )
{
	var option = 'toolbar=0,location=0,directories=0,menubar=0,copyhistory=0';
	option += ',status='    + ( status == null ? 1 : status );
	option += ',resizable=' + ( resize == null ? 0 : resize );
	option += ',scrollbars='+ ( scroll == null ? 1 : scroll );
	option += ',width='     + ( xsize = xsize == null ? 500 : xsize );
	option += ',height='    + ( ysize = ysize == null ? 400 : ysize );
	option += ',left='      + ( left == null ? ((screen.availWidth  - xsize) / 2) : left );
	option += ',top='       + ( top  == null ? ((screen.availHeight - ysize) / 2 - 15) : top );
	gimawin = window.open( url, name, option );
	gimawin.focus();
}

/*-------------------------------------------------------------- make by gima --
|* iframeÀ» µÑ·¯½Ñ <td>ÀÇ ³Êºñ/³ôÀÌ¸¦ iframeÀÇ ³Êºñ/³ôÀÌ¿¡ ¸ÂÃç¼­ ´ÃÀÓ
|* iframe ³»¿¡¼­ window.onload() ½Ã ¾Æ·¡ ÇÔ¼ö¸¦ È£ÃâÇÏ±â¸¸ ÇÏ¸é µÊ
|*............................................................................*/
function iframeResize( iframeID, marginHeight )
{
	if ( !iframeID )
		iframeID = 'subframe';
	var obj = parent.$(iframeID);
	//var obj = parent.document.all[ iframeID == null ? 'subframe' : iframeID ];

	if( !obj )
		return;

	try
	{
		obj.parentNode.width = document.body.scrollWidth;
		obj.parentNode.height = document.body.scrollHeight + (typeof(marginHeight) == 'undefined' ? 20 : marginHeight);
		//alert( obj.parentNode.width +' x '+ obj.parentNode.height );
	}
	catch(e)
	{
		//location.reload();
	}
}

/*------------------------------------------------------------- by gima/v1.01 --
|* valueÀÇ ¾Õ¿¡ Á¦·Î(0)¸¦ ³Ö¾î length ¸¸Å­ ±æÀÌ¸¦ ¸¸µë
|* ¸®ÅÏµÇ´Â °ªÀº ¹®ÀÚÀÓ¿¡ ÁÖÀÇ
|*............................................................................*/
function fillzero( value, length )
{
	value = value.toString();
	for( var i = value.length; i < length; i++ )
	value = '0' + value;
	return value;
}

/*------------------------------------------------------------------- by gima --
|* ÇØ´ç formÀÇ element °ªµéÀ» º¸¿©ÁÜ. submit ÇÏ±â Àü¿¡ °ª Ã¼Å©ÇÒ ¶§ À¯¿ë
|*............................................................................*/
function formview( aform )
{
	var str = '';
	for( var i = 0; i < aform.length; i++ )
		if( aform[i].name )
			str += aform[i].name +' = '+ aform[i].value +'\n';

	alert( str );
}

// ÇÃ·¹ÀÌ¾î
function aquaPlayer(param,c_gubun)
{
	var ua = navigator.userAgent;
	var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
	isMSIE7 = isMSIE && (ua.indexOf('MSIE 7') != -1);
	if(isMSIE7){
		var gWidth      = 925;
		var gHeight     = 735;
	}
	else {
		var gWidth      = 926;
		var gHeight     = 700;
	}

	if(c_gubun == '1')
	    window.open("/aqua_player/aquaplayer_hd_gs.php?"+param,'AquaPlayer','left=0, top=0, width=915, height=513, menubar=no, directories=no, resizable=no, status=no, scrollbars=no');
	else
		window.open("/aqua_player/aquaplayer.php?"+param,'AquaPlayer','left=0, top=0, width='+gWidth+', height='+gHeight+' menubar=no, directories=no, resizable=no, status=no, scrollbars=no');
    //window.open("/test/gima.studyhistory.php?"+param,'Aquatest','left=0, top=0, width=500, height=500, menubar=no, directories=no, resizable=no, status=no, scrollbars=auto');
}



// ÇÃ·¹ÀÌ¾î ½Å±Ô
function aquaPlayer_new(param)
{
	url = "/myedu/sparta/player.php?"+param;
	//alert(url);
	OpenPopupBrowser('','','',url);
	//window.open("/aqua_player/aquaplayer.php?"+param,'AquaPlayer','left=0, top=0, width='+gWidth+', height='+gHeight+' menubar=no, directories=no, resizable=no, status=no, scrollbars=no');
    //window.open("/test/gima.studyhistory.php?"+param,'Aquatest','left=0, top=0, width=500, height=500, menubar=no, directories=no, resizable=no, status=no, scrollbars=auto');
}

/**
 * radioChk::¶óµð¿À ¿¤¸®¸ÕÆ® °ª Ã¼Å©/Ã¼Å©¹Ú½º Ã¼Å©¿©ºÎ(disableÀº Á¦¿Ü)
 *
 * @access	public
 * @param	object 	 obj	: Ã¼Å©ÇÒ object
 *
 * @return	mixed
 *
 */
function radioChk(obj){
	if(typeof(obj.length) != "undefined"){
		for(var i=0;i<obj.length;i++){
			if(obj[i].checked == true && !obj[i].disabled){
				return obj[i].value;
			}
		}
	}
	else{
		if(obj.checked == true && !obj.disabled){
			return obj.value;
		}
	}
	return false;
}

/**
 * ¹è¿­·Î ³Ñ¾î¿Â Ã¼Å©¹Ú½º ÀüÃ¼¼±ÅÃ/ÇØÁ¦
 * @param {objName} Ã¼Å©¹Ú½º ¹è¿­
 * @param {chk} 	true/false
 * @return
 */
function checkBoxAllAct(objName,chk){
	var checkBoxArr = document.getElementsByName(objName);
	var i = 0;
	if(checkBoxArr){
		var max = checkBoxArr.length;
		for(i=0;i<max;i++){
			checkBoxArr[i].checked = chk;
		}
	}
}


/**
 * byte ¼ö ¹ÝÈ¯
 * @return number
 */
String.prototype.bytes = function() {
    for(var i = l = 0; i < this.length; i++) {
        l += (this.charCodeAt(i) > 127) ? 2 : 1;
	}
    return l;
}


/**
 * new lineÀ» br·Î
 * @return string
 */
String.prototype.nl2br = function() {
	return this.gsub('\n', '<br />');
}

/**
 * ¼ýÀÚ Ã¼Å©
 * @return boolean
 */
String.prototype.isNumber = function() {
	return /^[0-9]+$/.test(this);
}

/**
 * chk_byte :: ÃÖ´ë ¹ÙÀÌÆ® Ã¼Å©
 *
 * @access	public
 * @param	object 	 obj	: Ã¼Å©ÇÒ object
 * @param	int 	 max_len: ÃÖ´ë ¹ÙÀÌÆ® ¼ö
 * @param	string 	 view_id: ¹ÙÀÌÆ®¼ö ³ëÃâ id¸í
 *
 * @return	boolean
 *
 */
function chk_byte(obj, max_len, view_id){

	var len  	= obj.value.bytes();
	var sp_id	= $(view_id);
	if(sp_id){
		sp_id.innerHTML = len;
	}

	if(len>max_len){
		alert("ÃÖ´ë "+max_len+"byte(ÇÑ±Û"+(max_len/2)+"ÀÚ,¿µ¹®"+max_len+"ÀÚ) ±îÁö ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.");

		var value  = obj.value.substring(0);
		var bytes  = 0;
		var string = '';

		for(var i= 0; i<value.length; i++ ){
			var tmp = escape( value.charAt(i));
			if( tmp.length == 1 ) bytes++; else
			if( tmp.indexOf('%u') != -1 ) bytes += 2; else
			if( tmp.indexOf('%' ) != -1 ) bytes += tmp.length / 3;

			if(max_len && bytes <= max_len)
				string += obj.value.charAt(i);
		}
		obj.value = string;
		obj.focus();
		return false;
	}
	return true;
}

//- ex) <input type=text onkeyup='isKey_number(this)'>
function isKey_number( obj )
{
	if( !obj.value.match( /^[0-9]+$/ ) && obj.value != ""){
		obj.value = obj.value.replace( /[^0-9]+$/, "" );
		alert( '¼ýÀÚ¸¸ ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.' );
		return false;
	}
	return true;
}


/**
 * resizeFrame:: ¾ÆÀÌÇÁ·¹ÀÓ ¸®»çÀÌÂ¡
 *
 * @access	public
 * @param	object ifm_div: iframe ¾ÈÀÇ div(ÀüÃ¼ html °¨½Î´Â)
 * @param	object ifm_obj: iframe object
 *
 * @return	void
 *
 */
function resizeFrame(ifm_div, ifm_obj){
	if(ifm_div.offsetHeight == 0){

	}else{
		if(ifm_obj){
			pageheight = ifm_div.offsetHeight;
			ifm_obj.height = pageheight+"px";
		}
	}
}

function autoResize(i)
{
    var iframeHeight=(i).contentWindow.document.body.scrollHeight;
    (i).height=iframeHeight+20;
}

/*-------------------------------------------------------------- make by gima --
|* popup À©µµ¿ìÀÇ ³Êºñ/³ôÀÌ¸¦ ÀÚµ¿À¸·Î Á¶Àý
|* popup ³»¿¡¼­ window.onload() ½Ã ¾Æ·¡ ÇÔ¼ö¸¦ È£ÃâÇÏ±â¸¸ ÇÏ¸é µÊ
|*............................................................................*/
function popupResize()
{
	/*
	var marginHeight = 10;
	if( navigator.userAgent.indexOf( "SV1" ) > 0 ) marginHeight = 14; else
	if( navigator.userAgent.indexOf( "MSIE 7" ) > 0 ) marginHeight = 45; else
	if( navigator.userAgent.indexOf( "Gecko" ) > 0 &&
		navigator.userAgent.indexOf( "Firefox" ) <= 0 &&
		navigator.userAgent.indexOf( "Netscape" ) <= 0 ) marginHeight = 22; else
	if( navigator.userAgent.indexOf( "Firefox" ) > 0 ) marginHeight = 18; else
	if( navigator.userAgent.indexOf( "Netscape" ) > 0 ) marginHeight = -2;
	*/

	document.observe("dom:loaded", function()
	{
		try
		{

			var width = Math.min( document.body.scrollWidth + 10, screen.availWidth * 0.95 );
			var height = Math.min( document.body.scrollHeight + 70, screen.availHeight * 0.95 );

			if( height == screen.availHeight * 0.95 ){ //- ½ºÅ©·Ñ¹Ù°¡ »ý±â¸é
				document.body.scroll = 'auto';
				width = document.body.scrollWidth + 30;
				//alert(1);
			}

			//window.moveTo( (screen.availWidth - width) / 2, (screen.availHeight - height) / 2 );
			window.resizeTo( width, height );
			document.body.style.textAlign = 'center';

			if( !document.body.scrollWidth ){
				//alert(2);
				location.reload();
			}
		}
		catch(e)
		{
			location.reload();
			//alert(2);
		}
	} );
}

/**
 * ³¯Â¥ À¯È¿¼º È®ÀÎ
 * @param {dDate}		Ã¼Å©ÇÒ ³¯Â¥ °ª
 * @return boolean
*/
function isDateValidate(dDate)
{
	var isTrue = false;
	var lastDay;
	dDate = dDate.split("-").join("");

	if((dDate.length == 8) && dDate.isNumber()){
		var yyyy= eval(dDate.substring(0,4));
		var mm 	= eval(dDate.substring(4,6));
		var dd 	= eval(dDate.substring(6,8));

		var monthDD = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		lastDay = monthDD[mm-1];

		//À±³âÃ¼Å©
		if(mm ==2 &&(( yyyy % 4 == 0) && (yyyy % 100 != 0)) || (yyyy % 400 == 0)){
        	lastDay = 29;
        }
        if((yyyy >= 1901) && (yyyy <= 9999) && (mm >= 1) && (mm <= 12) && (dd >= 1) && (dd <= lastDay)){
			isTrue = true;
		}
	}
	return isTrue;
}

function image_auto_resize_inarea(this_s,width,height,view){
	//this_s¾ÈÀÇ ¸ðµç ÀÌ¹ÌÁö´Â ÀÚµ¿ ¸®»çÀÌÁî µÈ´Ù.
	//alert(this_s.childNodes.length);
	if(!view){view=true;}
	if(!this_s){return;}
	if(this_s.nodeType!=1){return;}
	for(var i=0,m=this_s.childNodes.length;i<m;i++){
		var ta = this_s.childNodes[i];

		if(ta.nodeName=='IMG'){
			image_auto_resize(ta,width,height);

			if(view){
				if(!ta.title){ta.title=ta.src;}
				if(!ta.onclick){
				ta.style.cursor='pointer';
				ta.onclick=function(){iwin(this.src);}
			}
			if(!ta.onload)
				ta.onload=function(){image_auto_resize(this,width,height);}
			if(!ta.onmouseover)
				ta.onmouseover=function(){image_auto_resize(this,width,height);}
			}
		}
		if(ta.childNodes.length>0){
			image_auto_resize_inarea(ta,width,height);
		}
	}
	return;

}

//	ÀÛ¼ºÀÏ : 2009-12-28, salrae
//	³»  ¿ë : iframe µîÀÇ height °è»ê(FF, IE °ø¿ë)
function getDocHeight(doc) {
	var docHt = 0, sh, oh;
	if (doc.height) {
		docHt = doc.height;
	}
	else if (doc.body) {
		if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
		if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
		if (sh && oh) docHt = Math.max(sh, oh);
	}
	return docHt;
}

//	ÀÛ¼ºÀÏ : 2010-01-11, salrae
//	³»  ¿ë : ±âÁ¸ »ç¿ëµÇ´ø ÇÃ·¡½¬ ÇÔ¼ö
function flush_swf(src,wid,hgt){
	flash_doc = '';
	flash_doc += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"  width="'+wid+'" height="'+hgt+'">';
	flash_doc += '<param name="movie" value="'+src+'">';
	flash_doc += '<param name="quality" value="high">';
	flash_doc += '<param name="wmode" value="transparent" />';
	flash_doc += '<embed src="'+src+'" wmode="transparent" quality=high width="'+wid+'" height="'+hgt+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	flash_doc += '<\/object>';
	document.write(flash_doc);
}


/*------------------------------------------------------------- by gima/v1.00 --
|* 
|*............................................................................*/
function set_bgcolor( object, color )
{
	object.defaultBgColor = object.style.backgroundColor;
	object.style.backgroundColor = color;

	if( object.onmouseout == null )
	{
		object.onmouseout = function()
		{
			object.style.backgroundColor = object.defaultBgColor;
		}
	}
}

//	@add
//	2010-05-18, salrae
//	trim, ltrim, rtrim
String.prototype.trim = function() {  
	return this.replace(/^\s+|\s+$/g,"");  
}  
     
String.prototype.ltrim = function() {  
	return this.replace(/^\s+/,"");     
}  
      
String.prototype.rtrim = function() {  
	return this.replace(/\s+$/,"");     
}