var POPUP_CM = {
	open : function ( popup_key, width, height )
	{
		if ( getCookie( 'popup_cm' + popup_key ) != 'T' )
		{
			var obj = window.open( '/events/popup/popup_cm.jsp?pk_seq=' + popup_key, 'popup_cm' + popup_key,'width='+width+',height='+height+',scrollbars=no,resizable=yes') ;
			obj.focus() ;
		}
	},
	close : function( ckey )
	{
		setCookie( 'popup_cm' + ckey, 'T', 1 );
		window.close();
	}
}

function INNER_POP( url, x, y, w, h )
{
	this.ifrm = null ;
	this.pwin = null ;
	this.constructor = function ( url, x, y, w, h )
	{
		this.url = ( url  ) ? url : 'about:blank' ;
		this.x = ( x || parseInt( x ) == 0 ) ? x : 130 ;
		this.y = ( y || parseInt( y ) == 0  ) ? y : 40-10 ;
		this.w = ( w || parseInt( w ) == 0 ) ? w : 850 ;
		this.h = ( h || parseInt( h ) == 0 ) ? h : 600 ;
	}
	this.init = function ()
	{
		this.ifrm = document.createElement( 'IFRAME' ) ;
		this.ifrm.src = this.url ;
		this.ifrm.width = this.w ;
		this.ifrm.height = this.h ;
		this.ifrm.style.left = this.x ;
		this.ifrm.style.top = this.y ;
		this.ifrm.allowTransparency = 'true' ;
		this.ifrm.frameBorder = '0' ;
		this.ifrm.scrolling = 'no' ;
		this.ifrm.marginWidth = '0' ;
		this.ifrm.marginHeight = '0' ;
		this.ifrm.style.position = 'absolute' ;
		this.ifrm.style.zIndex = 10001 ;
		this.ifrm.style.display = 'none' ;
		//document.body.appendChild( this.ifrm ) ;
		document.getElementById( 'wrapper_div' ).appendChild( this.ifrm ) ;
	}
	this.on = function ( url )
	{
		if ( !this.ifrm ) this.init() ;
		if ( url ) this.ifrm.src = url ;
		this.ifrm.style.display = 'block' ;
	}
	this.off = function ()
	{
		this.ifrm.src = 'about:blank' ;
		this.ifrm.parentNode.removeChild( this.ifrm ) ;
		this.ifrm = null ;
	}
	this.close = function ()
	{
		this.ifrm.src = 'about:blank' ;
		this.ifrm.parentNode.removeChild( this.ifrm ) ;
		this.ifrm = null ;
	}
	this.pop = function ( url )
	{
		if ( url ) this.ifrm.src = url ;
		this.pwin = window.open( url, 'uf_menu_pop', 'status=yes,toolbars=no,width='+this.w+',height='+this.h+',resizable=no' ) ;
		this.pwin.focus() ;
	}
	this.constructor( url, x, y, w, h ) ;
}


function setCookie( name, value, expiredays ) 
{ 
        var todayDate = new Date(); 
        todayDate.setDate( todayDate.getDate() + expiredays ); 
        document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 

} // end of setCookie()

function getCookie( name )
{
        var nameOfCookie = name + "=";
        var x = 0;

        while ( x <= document.cookie.length )
        {
                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) 
		{
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                                endOfCookie = document.cookie.length;

                        return unescape( document.cookie.substring( y, endOfCookie ) );
                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 )
                        break;
        }

        return "";

} // end of getCookie()


/**
* ÀÔ·Â°ª¿¡ Æ¯Á¤ ¹®ÀÚ(chars)°¡ ÀÖ´ÂÁö Ã¼Å©
* Æ¯Á¤ ¹®ÀÚ¸¦ Çã¿ëÇÏÁö ¾ÊÀ¸·Á ÇÒ ¶§ »ç¿ë
* ex) if (containsChars(form.name,"!,*&^%$#@~;")) {
*         alert("ÀÌ¸§ ÇÊµå¿¡´Â Æ¯¼ö ¹®ÀÚ¸¦ »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.");
*     }
*/
function containsChars(input,chars) {
    for (var inx = 0; inx < input.value.length; inx++) {
       if (chars.indexOf(input.value.charAt(inx)) != -1)
           return true;
    }
    return false;
}
  
/**
* ÀÔ·Â°ªÀÌ Æ¯Á¤ ¹®ÀÚ(chars)¸¸À¸·Î µÇ¾îÀÖ´ÂÁö Ã¼Å©
* Æ¯Á¤ ¹®ÀÚ¸¸ Çã¿ëÇÏ·Á ÇÒ ¶§ »ç¿ë
* ex) if (!containsCharsOnly(form.blood,"ABO")) {
*         alert("Ç÷¾×Çü ÇÊµå¿¡´Â A,B,O ¹®ÀÚ¸¸ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.");
*     }
*/
function containsCharsOnly(input,chars) {
    for (var inx = 0; inx < input.value.length; inx++) {
       if (chars.indexOf(input.value.charAt(inx)) == -1)
           return false;
    }
    return true;
}
  
/**
* ÀÔ·Â°ªÀÌ ¾ËÆÄºªÀÎÁö Ã¼Å©
* ¾Æ·¡ isAlphabet() ºÎÅÍ isNumComma()±îÁöÀÇ ¸Þ¼Òµå°¡
* ÀÚÁÖ ¾²ÀÌ´Â °æ¿ì¿¡´Â var chars º¯¼ö¸¦ 
* global º¯¼ö·Î ¼±¾ðÇÏ°í »ç¿ëÇÏµµ·Ï ÇÑ´Ù.
* ex) var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
*     var lowercase = "abcdefghijklmnopqrstuvwxyz"; 
*     var number    = "0123456789";
*     function isAlphaNum(input) {
*         var chars = uppercase + lowercase + number;
*         return containsCharsOnly(input,chars);
*     }
*/
function isAlphabet(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}
  
/**
* ÀÔ·Â°ªÀÌ ¾ËÆÄºª ´ë¹®ÀÚÀÎÁö Ã¼Å©
*/
function isUpperCase(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    return containsCharsOnly(input,chars);
}
  
/**
* ÀÔ·Â°ªÀÌ ¾ËÆÄºª ¼Ò¹®ÀÚÀÎÁö Ã¼Å©
*/
function isLowerCase(input) {
    var chars = "abcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}
  
/**
* ÀÔ·Â°ª¿¡ ¼ýÀÚ¸¸ ÀÖ´ÂÁö Ã¼Å©
*/
function isNumber(input) {
    var chars = "0123456789";
    return containsCharsOnly(input,chars);
}
  
/**
* ÀÔ·Â°ªÀÌ ¾ËÆÄºª,¼ýÀÚ·Î µÇ¾îÀÖ´ÂÁö Ã¼Å©
*/
function isAlphaNum(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    return containsCharsOnly(input,chars);
}
  
/**
* ÀÔ·Â°ªÀÌ ¼ýÀÚ,´ë½Ã(-)·Î µÇ¾îÀÖ´ÂÁö Ã¼Å©
*/
function isNumDash(input) {
    var chars = "-0123456789";
    return containsCharsOnly(input,chars);
}
  
/**
* ÀÔ·Â°ªÀÌ ¼ýÀÚ,ÄÞ¸¶(,)·Î µÇ¾îÀÖ´ÂÁö Ã¼Å©
*/
function isNumComma(input) {
    var chars = ",0123456789";
    return containsCharsOnly(input,chars);
}
  
/**
* ÀÔ·Â°ªÀÌ »ç¿ëÀÚ°¡ Á¤ÀÇÇÑ Æ÷¸Ë Çü½ÄÀÎÁö Ã¼Å©
* ÀÚ¼¼ÇÑ format Çü½ÄÀº ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ `regular expression`À» ÂüÁ¶
*/
function isValidFormat(input,format) {
    if (input.value.search(format) != -1) {
        return true; //¿Ã¹Ù¸¥ Æ÷¸Ë Çü½Ä
    }
    return false;
}
  
/**
* ÀÔ·Â°ªÀÌ ÀÌ¸ÞÀÏ Çü½ÄÀÎÁö Ã¼Å©
* ex) if (!isValidEmail(form.email)) {
*         alert("¿Ã¹Ù¸¥ ÀÌ¸ÞÀÏ ÁÖ¼Ò°¡ ¾Æ´Õ´Ï´Ù.");
*     }
*/
function isValidEmail(input) {
//    var format = /^(\S+)@(\S+)\.([A-Za-z]+)$/;
    var format = /^((\w[\-\.])+)@((\w[\-\.])+)\.([A-Za-z]+)$/;
    return isValidFormat(input,format);
}
  
/**
* ÀÔ·Â°ªÀÌ ÀüÈ­¹øÈ£ Çü½Ä(¼ýÀÚ-¼ýÀÚ-¼ýÀÚ)ÀÎÁö Ã¼Å©
*/
function isValidPhone(input) {
    var format = /^(\d+)-(\d+)-(\d+)$/;
    return isValidFormat(input,format);
}
  
/**
* ÀÔ·Â°ªÀÇ ¹ÙÀÌÆ® ±æÀÌ¸¦ ¸®ÅÏ
* ex) if (getByteLength(form.title) > 100) {
*         alert("Á¦¸ñÀº ÇÑ±Û 50ÀÚ(¿µ¹® 100ÀÚ) ÀÌ»ó ÀÔ·ÂÇÒ ¼ö ¾ø½À´Ï´Ù.");
*     }
* Author : Wonyoung Lee
*/
function getByteLength(input) {
    var byteLength = 0;
    for (var inx = 0; inx < input.value.length; inx++) {
        var oneChar = escape(input.value.charAt(inx));
        if ( oneChar.length == 1 ) {
            byteLength ++;
        } else if (oneChar.indexOf("%u") != -1) {
            byteLength += 2;
        } else if (oneChar.indexOf("%") != -1) {
            byteLength += oneChar.length/3;
        }
    }
    return byteLength;
}
  
/**
* ÀÔ·Â°ª¿¡¼­ ÄÞ¸¶¸¦ ¾ø¾Ø´Ù.

*/
function removeComma(input) {
    return input.value.replace(/,/gi,"");
}
  
/**
* ¼±ÅÃµÈ ¶óµð¿À¹öÆ°ÀÌ ÀÖ´ÂÁö Ã¼Å©
*/
function hasCheckedRadio(input) {
    if (input.length > 1) {
        for (var inx = 0; inx < input.length; inx++) {
            if (input[inx].checked) return true;
        }
    } else {
        if (input.checked) return true;
    }
    return false;
}
  
/**
* ¼±ÅÃµÈ Ã¼Å©¹Ú½º°¡ ÀÖ´ÂÁö Ã¼Å©
*/
function hasCheckedBox(input) {
    return hasCheckedRadio(input);
}



function bprint_pop( url )
{
	if ( !url ) url = '/printing/bprint_step1_1.jsp';
	var obj = window.open( url, 'bprint_pop','width=900,height=660,scrollbars=yes,resizable=yes') ;
	obj.focus() ;
}
var AJ = {
	array2pstring : function ( array )
	{
		var pstring = '';
		for ( i in array )
		{
			pstring += i + '=' + encodeURIComponent( array[i] ) + '&' ;
		}
		pstring = pstring.substring( 0, pstring.length - 1 );
		return pstring;
	},
	req : function ( str_url, str_func, data_target, data_type, str_method, return_type )
	{
		var xmlHttpReq = this.get_XHR() ;
		var d = new Date() ;
		var nocache = 'uf' + d.getTime() ;
		var str_param = '';
		if ( data_type == 'dtype_form' )
		{
			var f = document.getElementsByName( data_target ).item(0) ;
			str_param = this.formData2QueryString( f ) ;
		}
		else if ( data_type == 'dtype_param' )
		{
			str_param = data_target ;
		}
		else if ( data_type == 'dtype_data' )
		{
			str_param = this.array2pstring( data_target ) ;
		}
		str_param += str_param ? '&' + nocache : nocache ;
		var str_param_get = '' ;
		var str_param_post = '' ;
		if ( str_method == 'rmethod_get' )
		{
			str_param_get = str_param ;
			xmlHttpReq.open( 'GET', str_url + '?' + str_param_get , true ) ;
		}
		else
		{
			str_param_post = str_param ;
			xmlHttpReq.open( 'POST', str_url, true ) ;
		}
		xmlHttpReq.setRequestHeader( 'Content-Type','application/x-www-form-urlencoded' );
		xmlHttpReq.setRequestHeader( 'Accept-Language','ko' );
		xmlHttpReq.onreadystatechange = function()
		{
			if ( xmlHttpReq.readyState == 4 )
			{
				if ( str_func ) AJ.res( xmlHttpReq, str_func, return_type );
			}
		}
		xmlHttpReq.send( str_param_post ) ;
	},
	res : function ( xmlHttpReq, str_func, return_type )
	{
		if ( !xmlHttpReq.responseText ) eval( str_func + '(  "" )' ) ;
		if ( return_type == 'response_xml' )
		{
			eval( str_func + '(xmlHttpReq.responseXML)' ) ;
		}
		else if ( return_type == 'response_text' )
		{
			eval( str_func + '(xmlHttpReq.responseText)' ) ;
		}
		else if ( return_type == 'response_data' )
		{
			//alert(xmlHttpReq.responseText);
			var data_result = new Array();
			var obj = xmlHttpReq.responseXML.getElementsByTagName( 'cat_aj_xml' )[0].childNodes ;
			for ( var cnt = 0, len = obj.length ; cnt < len ; cnt++ )
			{
				if ( obj[cnt].tagName ) data_result[ obj[cnt].tagName ] = obj[cnt].firstChild ? obj[cnt].firstChild.nodeValue : '' ;
			}
			eval( str_func + '(data_result)' ) ;
		}
	},
	get_XHR : function ()
	{
		var xmlHttpReq = false ;
		if ( window.XMLHttpRequest ) // Mozilla/Safari
		{
			xmlHttpReq = new XMLHttpRequest() ;
		}
		else if ( window.ActiveXObject ) // IE
		{
			xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP') ;
		}
		return xmlHttpReq ;
	},
	formData2QueryString : function ( docForm )
	{
		var strSubmitContent = '';
		var formElem;
		var strLastElemName = '';
		for (i = 0; i < docForm.elements.length; i++)
		{
			formElem = docForm.elements[i];
			switch (formElem.type)
			{
				// Text fields, hidden form elements
				case 'text':
				case 'hidden':
				case 'password':
				case 'textarea':
				case 'select-one':
					strSubmitContent += formElem.name + '=' + this.urlencode(formElem.value) + '&'
					strLastElemName = formElem.name
					break;
				// Radio buttons
				case 'radio':
					if (formElem.checked)
					{
						strSubmitContent += formElem.name + '=' + this.urlencode(formElem.value) + '&'
					}
					strLastElemName = formElem.name
					break;
				// Checkboxes
				case 'checkbox':
					if (formElem.checked)
					{
						strSubmitContent += formElem.name + '=' + this.urlencode(formElem.value) + '&'
						strLastElemName = formElem.name
						// Continuing multiple, same-name checkboxes
						/*
						if (formElem.name == strLastElemName)
						{
							// Strip of end ampersand if there is one
							if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1)
							{
								strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
							}
							// Append value as comma-delimited string
							strSubmitContent += ', ' + escape(formElem.value);
						}
						else
						{
							strSubmitContent += formElem.name + '=' + escape(formElem.value);
						}
						strSubmitContent += '&';
						strLastElemName = formElem.name ;
						*/
					}
					break;
			}
		}
		// Remove trailing separator
		strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
		return strSubmitContent;
	},
	urlencode : function ( str )
	{
		return encodeURIComponent( str ) ;
	}
}

/*****************  UI °ü·Ã *****************/
function UI_OPTBOX( _is_editable, _is_infinite )
{
	this.constructor = function ( _is_editable )
	{
		this.obj_opt_box = document.createElement( 'div' );
		this.obj_opt_box.style.margin = '0px';
		this.obj_opt_box.style.display = 'none';
		this.obj_opt_box.style.border = '1px solid red';
		this.opt_value = new Array();
		this.opt_html = new Array();
		this.obj_input = null;
		this.obj_input_index = null;
		this.obj_input_html = null;
		this.obj_input_value = null;
	}
	this.add_item_html = function ( value, html )
	{
		var next_index = this.opt_value.length;
		this.opt_value[next_index] = value;
		this.opt_html[next_index] = html;
		var obj = document.createElement( 'div' );
		obj.innerHTML = html;
		obj.style.cursor = 'pointer';
		var temp = this;
		obj.onmousedown = function ()
		{
			temp.set_current_input( next_index );
			temp.obj_opt_box.style.display = 'none';
		}
		this.obj_opt_box.appendChild( obj );
	}
	this.add_item_number = function ( start, end )
	{
		for ( var cnt = start ; cnt < end ; cnt++ )
		{
			this.add_item_html( cnt, cnt );
		}
	}
	this.select_init = function ( id )
	{
		this.get_current_input( id );
		var current_index = this.ivalue2oindex( this.obj_input_value.value );
		this.set_current_input( current_index );
	}
	this.select_expand = function ( id )
	{
		this.get_current_input( id );
		this.obj_input.appendChild( this.obj_opt_box );
		this.obj_opt_box.style.width = this.obj_input.style.width;
		var offset = this.cumulative_offset( this.obj_input );
		this.obj_opt_box.style.left = offset['left'];
		this.obj_opt_box.style.top = offset['top'];
		this.obj_opt_box.style.position = 'absolute';
		this.obj_opt_box.style.zIndex = 10000;
		this.obj_opt_box.style.display = 'block';
		var temp = this;
		var evt_func = function ()
		{
			if ( temp.obj_opt_box.parentNode ) temp.obj_opt_box.parentNode.removeChild( temp.obj_opt_box );
			temp.event_remove( document.body, 'onmouseup', evt_func );
		}
		this.event_add( document.body, 'onmousedown', evt_func );
	}
	this.select_down = function ( id )
	{
		this.get_current_input( id );
		var current_index = this.ivalue2oindex( this.obj_input_value.value );
		if ( current_index <= 0 ) return;
		this.set_current_input( --current_index );
	}
	this.select_up = function ( id )
	{
		this.get_current_input( id );
		var current_index = this.ivalue2oindex( this.obj_input_value.value );
		if ( _is_infinite )
			this.obj_input_value.value++;
		else if ( current_index >= (this.opt_value.length - 1) )
			return;
		else
			this.set_current_input( ++current_index );
	}
	this.check_number = function ( obj )
	{
		if ( obj.value == '' || !isNumber( obj ) ) obj.value = this.opt_value[0];
	}
	this.check_limit = function ( obj )
	{
		if ( obj.value > this.opt_value[this.opt_value.length-1] ) obj.value = this.opt_value[this.opt_value.length-1];
	}
	this.set_current_input = function ( index )
	{
		if ( _is_editable )
		{
			this.obj_input_value.value = this.opt_value[index];
		}
		else
		{
			this.obj_input_html.innerHTML = this.opt_html[index];
			this.obj_input_value.value = this.opt_value[index];
		}
	}
	this.get_current_input = function ( id )
	{
		if ( this.obj_opt_box.parentNode ) this.obj_opt_box.parentNode.removeChild( this.obj_opt_box );
		this.obj_input = document.getElementById( id );
		this.obj_input_html = document.getElementById( id + '_html' );
		this.obj_input_value = document.getElementById( id + '_value' );
	}
	this.ivalue2oindex = function ( ivalue )
	{
		for ( var cnt = 0 ; cnt < this.opt_value.length ; cnt++ )
		{
			if ( this.opt_value[cnt] == ivalue )
			{
				return cnt;
			}
		}
		return 0;
	}
	this.cumulative_offset = function ( obj )
	{
		var rtn_offset = new Array();
		rtn_offset['left'] = 0;
		rtn_offset['top'] = 0;
		var next_obj = obj.parentNode.parentNode;
		while( next_obj && next_obj.tagName != 'BODY' )
		{
			if ( next_obj.tagName == 'TR' || next_obj.tagName == 'TBODY')
			{
				next_obj = next_obj.parentNode;
				continue;
			}
//			alert(next_obj.tagName + ' ' + next_obj.offsetTop);
			rtn_offset['left'] += parseInt( next_obj.offsetLeft );
			rtn_offset['top'] += parseInt( next_obj.offsetTop );
			next_obj = next_obj.parentNode;
		}
		//alert(rtn_offset['top']);
		return rtn_offset;
	}
	this.event_add = function ( obj, evt_name, action )
	{
		if ( !obj ) return ;
		var is_ie = ( navigator.userAgent.indexOf('MSIE' ) > 0 ) ;
		var evt_name = ( is_ie ) ? evt_name : evt_name.substring( 2, evt_name.length ) ;
		if ( is_ie )
		{
			obj.attachEvent( evt_name, action ) ;
		}
		else
		{
			obj.addEventListener( evt_name, action, true ) ;
		}
	}
	this.event_remove = function ( obj, evt_name, action )
	{
		if ( !obj ) return ;
		var is_ie = ( navigator.userAgent.indexOf('MSIE' ) > 0 ) ;
		var evt_name = ( is_ie ) ? evt_name : evt_name.substring( 2, evt_name.length ) ;
		if ( is_ie )
		{
			obj.detachEvent( evt_name, action ) ;
		}
		else
		{
			obj.removeEventListener( evt_name, action, true ) ;
		}
	}
	this.constructor( _is_editable );
}

function str_element( target )
{
	var str_rtn = "" ;
	for ( i in target )
	{
		str_rtn += i + '=' + target[i] + '<br>\n';
	}
	return str_rtn ;
}


