//http://www.devarticles.com/c/a/JavaScript/Checking-Numbers-and-File-Extensions-with-jQuerys-Validator-Plugin/3/

var img_type_definition = {format:['jpg', 'gif'], message:'jpg, gif 파일만 등록 가능합니다.'};
var movie_type_definition = {format:['avi', 'wmv'], message:'wmv 또는 avi 파일만 등록 가능합니다.'};


function hangul() { 
	if((event.keyCode < 12592) || (event.keyCode > 12687)) {
		alert( "한글만 입력 가능합니다."); 
		event.returnValue = false
	} 
} 



var FORM_OBJECT = function( json_argument ) {
	this.form_id = json_argument.form_id?
			"#" + json_argument.form_id  :  "";

	this.submit_url = json_argument.submit_url?
			json_argument.submit_url  :  "";

	this.auto_submit = json_argument.auto_submit?json_argument.auto_submit  :  false;
	this.fn_execute = json_argument.fn_execute;

	this.init();
	this.register_event();
}


FORM_OBJECT.prototype = {
	init: function() {
		$(this.form_id).attr("action", this.submit_url);
		$(this.form_id).attr("method", "POST");
	},
	
	register_event: function() {

		if( this.auto_submit ) {
			$(this.form_id).bind("keypress", {it:this}, function(e) {
		        if(e.which == 13) {
		            e.data.it.execute();
		        }
		    });
		}
	}, 
	
	execute: function() {
		this.fn_execute();
	}

}





function show_image_layer(src, seq) {
    $.blockUI({ 
        message: $('img#' + seq), 
        css: { 
            top:  ($(window).height() - 500) /2 + 'px', 
            left: ($(window).width() - 500) /2 + 'px', 
            width: '500px' 
        } 
    }); 

    $('img#' + seq).one("click", function() {
         $.unblockUI();
    });
}



function go_back( message, url ) {
	if( message ) {
		if( confirm( message ) ) {
			if( url == null || url == undefined ) {
				history.go(-1);
			} else {
				location.href = url;
			}
		}
		return; 
	} else {
		history.go(-1);
	}
}











function validate_file_type( fileObject, permissibleDefinition ) {
	var file_name = fileObject.value;
	var valid = false;

	for( var i=0; i< permissibleDefinition.format.length; i++ ) {
		var perssibleType = permissibleDefinition.format[i];

		if( endsWith(file_name, perssibleType) ) {
			valid = true;
			break;
		}
	}

	if( !valid ) {
		fileObject.value = '';
		alert( permissibleDefinition.message );
	}
}







function endsWith(testString, endingString){
      if(endingString.length > testString.length) return false;
      return testString.indexOf(endingString)==(testString.length-endingString.length);
}




/**
 * Script Debugger 의 console.log()를 호출한다.
 * @param val
 * @return
 */
function debug( val ){
	if( typeof console == "undefined" ){
		//Nothing
	}else{
		console.log( val );
	}
}




/**
 * $.jGrowl( data.location.title + "이 수정되었습니다." , { header:"수정완료", sticky: false, life: g_jgrowl_life });
 **/
var g_jgrowl_life = 50000;


var G_DATE_PICKER_DEFAULT = {
		showOn: 'both',
		buttonImage: '/image/calendar.png',
		buttonImageOnly: true,
		dateFormat: 'yy-mm-dd',
		changeYear: true,
		changeMonth: true,
		showMonthAfterYear:true,
		closeText:'X',
		showButtonPanel:true
};



/*
 * created by jazzvm
 *
 * DEPENDENCY NOTE
 * jquery-1.3.x or higher
 */



//this function includes all necessary js files for the application
var scriptMenu;
function include(file)
{
	var existFile = scriptMenu[file];
	if( ! existFile  ){
		  var script  = document.createElement('script');
		  script.src  = file;
		  script.type = 'text/javascript';
		  script.defer = true;

		  document.getElementsByTagName('head').item(0).appendChild(script);

		  scriptMenu[file] = script;
	}
}

/* include any js files here */
//include('/js/myFile1.js');



/** Hide SideBar **/
function hideSidebar(){
	$(".container").removeClass("sideshow");
}
/** Show SideBar **/
function showSidebar(){
	$(".container").addClass("sideshow");
}




/**
 * =========================================================================================================
 * Object - Json - Array
 * =========================================================================================================
 */

function jsonConcat(o1, o2) {
	for (var key in o2) {
		o1[key] = o2[key];
	}
	return o1;
}




/* ================================================================ */
/* ======================= COMMON FUNCTIONS ======================= */
/* ================================================================ */


/*
 * FUNCTION NAME: [isEmpty]
 * PARAMS:
 * 		text: string
 * DESCRIPTION:
 * 		text 가 empty 인지를 체크
 * 		whitespace 문자열만 포함하는 경우 empty로 판단함
 * RETURN:
 * 		boolean
 * USAGE:
 * 		bool = isEmpty(some_text);
 */
function isEmpty(text) {
	if( text == null || text == undefined ) return true;
	
	for(var i=0 ; i<text.length ; i++) {
		var ch = text.charAt(i);
		if((ch != " ") && (ch != '\t'))
			return false;
	}
	return true;
}








/*
 * FUNCTION NAME: [isEmptyToAlert]
 * PARAMS:
 * 		field_name: 체크할 대상 필드 네임 (name, id)
 * 		alert_msg: field_name에 해당하는 object가 empty인 경우 alert 창에서 출력할 메시지
 * DESCRIPTION:
 * 		field_name에 해당하는 object를 검사하여, (검사 순서, getElementById -> getElementByNames)
 * 		object의 value attribue가 empty 인지를 체크
 * 		whitespace 문자열만 포함하는 경우 empty로 판단함
 * RETURN:
 * 		boolean
 * 			if empty: show alert message, set focut on requsted field, then true
 * 			if not  : return false
 * USAGE:
 * 		from_obj = $('#SELECT_OBJECT_ID1');
 * 		to_obj = $('#SELECT_OBJECT_ID2');
 * 		moveOptionsFrom(from_obj, to_obj);
 */
function isEmptyToAlert(field_name, alert_msg){
	var text = '';

	var obj;

	if (document.getElementById(field_name) != null) {
		obj = document.getElementById(field_name);
		text = obj.value;
	} else if(document.getElementsByName(field_name)[0] != null) {
		obj = document.getElementsByName(field_name)[0];
		text = obj.value;
	} else {
		alert("Fatal error: /" + field_name + "/ does not exist!");
		return true;
	}


	if( isEmpty(text) ) {
		alert( alert_msg );
		obj.focus();
	}

	return true;
}





/*
 * FUNCTION NAME: [isNumeric]
 * PARAMS:
 * 		text: string
 * DESCRIPTION:
 * 		text 가 number format 인지를 체크
 * RETURN:
 * 		boolean
 * USAGE:
 * 		bool = isNumeric(some_text);
 */
function isNumeric(text) {
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

    for (i = 0; i < text.length && IsNumber == true; i++) {
      Char = text.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
      }
    }
    return IsNumber;
}





/*
 * FUNCTION NAME: [isRadioSelected]
 * PARAMS:
 * 		input_attr_name: input element name
 * DESCRIPTION:
 * 		radio or radio group의 체크 여부를 검사
 * RETURN:
 * 		boolean
 * USAGE:
 * 		--- js ---
 * 		bool = isRadioSelected('hobby');
 * 		--- html ---
 * 		<input type='radio' name='hobby'> game
 * 		<input type='radio' name='hobby'> skiing
 * 		<input type='radio' name='hobby'> listening
 * 		...
 */
function isRadioSelected(input_attr_name){
	$( "input[type='radio'][name=' + input_attr_name + ']" ).each(
		function () {
			if( $(this).checked ) return true;
		}
	);
	return false;
}












/*
 * FUNCTION NAME: [trim]
 * DESCRIPTION:
 * 		truncate all white spaces
 * PARAMS:
 * 		str: a string to trim
 * RETURN:
 * 		string - trimmed string
 * USAGE:
 * 		--- js ---
 * 		trimmed_string = trim(text);
 */
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

/*
 * FUNCTION NAME: [ltrim]
 * DESCRIPTION:
 * 		truncate white spaces on the left side
 * PARAMS:
 * 		str: a string to trim
 * RETURN:
 * 		string - trimmed string
 * USAGE:
 * 		--- js ---
 * 		trimmed_string = ltrim(text);
 */
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

/*
 * FUNCTION NAME: [rtrim]
 * DESCRIPTION:
 * 		truncate white spaces on the right side
 * PARAMS:
 * 		str: a string to trim
 * RETURN:
 * 		string - trimmed string
 * USAGE:
 * 		--- js ---
 * 		trimmed_string = rtrim(text);
 */
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}





/*
 * FUNCTION NAME: [substringWithReplacement]
 * DESCRIPTION:
 * 		cut string with a given length and append replacement
 * PARAMS:
 * 		text: a string to cut
 * 		length: a trigger position to cut
 * 		str_replacement: a string to be appended once the input text is cut
 * RETURN:
 * 		text - string
 * USAGE:
 * 		--- js ---
 * 		var text = "hello jazzvm";
 * 		text = substringWithReplacement(text, 7, "world");
 * 		// should return 'hello world'
 */
function substringWithReplacement(text, length, str_replacement) {
	if( text == null || text.length < length) return text;
	return text.substring(text, length) + str_replacement;
}









/*
 * FUNCTION NAME: get_input_character_code
 *
 * PARAMS:
 * 		e: key event object
 *
 * DESCRIPTION:
 * 		key event를 통해 입력된 character code를 반환
 *
 * RETURN:
 * 		char - character code
 *
 * USAGE:
 * 		from_obj = $('#SELECT_OBJECT_ID1');
 * 		to_obj = $('#SELECT_OBJECT_ID2');
 * 		moveOptionsFrom(from_obj, to_obj);
 *
 *
 */

function get_input_character_code(e) {
	if(e && e.which) { //if which property of event object is supported (NN4)
		e = e
		var characterCode = e.which //character code is contained in NN4's which property
	} else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	return characterCode;
}



/*
 * FUNCTION NAME: moveOptionsFrom
 *
 * ARGUMENTS:
 * 		from: from select object
 * 		to: to select object
 *
 * RETURN:
 * 		void
 *
 * DESCRIPTION:
 * 		from select object에서 선택된 option(s)을 삭제하고
 * 		to select object의 option list에 추가
 *
 * USAGE:
 * 		from_obj = $('#SELECT_OBJECT_ID1');
 * 		to_obj = $('#SELECT_OBJECT_ID2');
 * 		moveOptionsFrom(from_obj, to_obj);
 *
 *
 */

function moveOptionsFrom(from, to)
{
	for(var i=from.options.length-1; i>=0; i--) {
		if( from.options[i].selected ) {
	    	var value = from.options[i].value;
	        var text  = from.options[i].value;

	        to.options[to.options.length] = new Option(text,value,false,false);
	        from.options[i]=null;
		}
	}
}










function wrong_char(text){
    if (text.length < 8)
        return true;
    if (text.charAt(0) == '@')
        return true;
    if (text.charAt(text.length - 1) == '@')
        return true;

    for (i = 0; i < text.length; i++) {
        var ch = text.charAt(i);
        if (ch == '@') {

            for (j = i + 2; j < text.length; j++) {
                var ch = text.charAt(j);
                if (ch == '.')
                    return false;
            }
        }
    }
    return true;
}



/*
 * created by joldo
 *
 * DEPENDENCY NOTE
 * jquery-1.3.x or higher
 *
 * Usage ::
 *
 * <script>
	var normalPopup = null;
	var subPopup = null;
	$(function() {
		normalPopup = MessageBox.makePopup( {title:"제목", sourceId:"contentsTarget",  style: MessageBox.STYLE_NORMAL } );
		subPopup = MessageBox.makePopup( {title:"제목", sourceId:"contentsTarget",  style: MessageBox.STYLE_SUB } );
	});

	function showContents(){
		normalPopup.show();
	}

	function showSubContents(){
		subPopup.show();
	}

	function showInfoContents(){
		var infos = "my infomation";
		MessageBox.show( {title:"제목", innerHtml:infos ,  style: MessageBox.STYLE_INFO } );
		MessageBox.show( {title:"제목2", innerHtml:infos ,  style: MessageBox.STYLE_INFO } );
		MessageBox.show( {title:"제목3", innerHtml:infos ,  style: MessageBox.STYLE_INFO } );
	}

	function showErrorContents(){
		var errors = "my errors";
		MessageBox.show( {title:"제목", innerHtml:errors ,  style: MessageBox.STYLE_ERROR } );
	}
	</script>
	<body>
		<!-- 팝업컨텐츠 -->
		<div id="contentsTarget" style="display: none;" >
        	<h3 >서브 타이틀 </h3>
			<table cellpadding="0" cellspacing="0" class="tableform tbl60">
                   <tbody>
                    	<tr>
                    		<th class="col10 lt" ><span class="required">시스템명</span></th>
                    		<td><input class="txt" type="text" id="title" name="title" size="17"></td>
                    		<th class="col10 lt" ><span class="required">오픈일자</span></th>
                    		<td>
                    			<input class="txt" type="text" id="openDate" name="openDate"  size="10" readonly />
                    		</td>
                    	</tr>
                    </tbody>
            </table>
		</div>
	</body>
 */
var MessageBox = function( option ){
	
	this.topElement = null;

	this.cache = true;
	if( option.cache != undefined ){
		this.cache = option.cache && true ;
	}

	this.id = "popup_"+option.sourceId;
	if( ! option.sourceId ){
		this.id = "popup_" + ((Math.round(Math.random() * 100000)) + 1);
	}
	this.zindex = option.zindex;

	this.title = option.title;
	this.style = option.style;


	this.innerHtml = option.innerHtml;


	this.sourceId = option.sourceId;

	this.closeText = option.closeText;

	

	this.init();
}

MessageBox.STYLE_NONE = 0;
MessageBox.STYLE_NORMAL = 1;
MessageBox.STYLE_SUB = 2;
MessageBox.STYLE_INFO = 3;
MessageBox.STYLE_ERROR = 4;


MessageBox.makePopup = function( option ){
	var box = new MessageBox(option);
	return box;
}


MessageBox.show = function( option ){
	option.cache = false;
	var box = new MessageBox(option);
	box.show();
}

MessageBox.prototype = {
		init : function(){
			var popupClass;
			var contentClass;
			var hasStyle = false;
			switch( this.style ){
				case MessageBox.STYLE_NORMAL:
					popupClass = "popupwindow";
					contentClass = "popupcontent";
					this.zindex = 100 ;
					this.cache = this.cache&&true;
					hasStyle = true;
					break;
				case MessageBox.STYLE_SUB:
					popupClass = "popupwindowsub";
					contentClass = "popupcontentsub";
					this.zindex = 200 ;
					this.cache = this.cache&&true;
					hasStyle = true;
					break;
				case MessageBox.STYLE_INFO:
					popupClass = "popupwindow_msg";
					contentClass = "popupcontent_msg";
					this.zindex = 999 ;
					this.cache = this.cache;
					hasStyle = true;
					break;
				case MessageBox.STYLE_ERROR:
					popupClass = "popupwindow_err";
					contentClass = "popupcontent_err";
					this.zindex = 999 ;
					this.cache = this.cache;
					hasStyle = true;
					break;
				default:
			}


			if( hasStyle  ){
				this.topElement = $( "<div id='"+this.id+"' class='"+popupClass+"' style='display: none;'><div class='"+contentClass+"'></div></div>" );
				$("body").append(this.topElement);

				/** 타이틀 **/
				if( this.title ){
					$(this.topElement).children("div").append( $("<h2 id='"+this.id+"_title'>"+this.title+"</h2>") );
				}

				/** 컨텐츠 삽입 **/
				if( this.innerHtml ){
					var cloned = ( $("<div></div>") );
					cloned.addClass("inner_content");
					cloned.css("display", "block" );
					$(cloned).html( this.innerHtml );
					$(this.topElement).children("div").append( cloned );
				}else{
					//var cloned = $("#"+this.sourceId).clone();
					var cloned = $("#"+this.sourceId);
					cloned.addClass("inner_content");
					cloned.css("display", "block" );
					$(this.topElement).children("div").append( cloned );
				}

	        	/** 닫기 버튼 **/
//	        	var closeText = this.closeText?closeText:"X";
//				var closeBtn = $("<input type='button' class='btn popupclose' value='"+closeText+"' />");
//				$(closeBtn).appendTo( this.topElement ) ;

//				$(closeBtn).bind( "click" , {src:this}, function(e){
//						var src = e.data.src;
//						src.hide();
//			    	}
//				);

			}else{
				if( this.innerHtml ){
					this.topElement = $( this.innerHtml );
					$("body").append(this.topElement);	
				}else{
					this.topElement = $("#"+this.sourceId);				
					$("body").append(this.topElement);
				}
				
			}


			this.createDivBackground();
		},
		showLayerWrapper : function(){

			var pos = this.position();

			$(this.topElement).css("position","absolute");
			$(this.topElement).css("z-index",this.zindex);
			$(this.topElement).css("left",pos[0] );
			$(this.topElement).css("top",pos[1] );
			this.topElement.show();
		},
		getDimension : function(){
			var widthWithScroll = document.documentElement.scrollWidth;
			var heightWithScroll = document.documentElement.scrollHeight+ 30;

			$("#"+ this.id + "_bg").css("width",widthWithScroll);
			$("#"+ this.id + "_bg").css("height",heightWithScroll);

		},
		/*
		 * DIV 투명한 검은색 배경을 보여준다.
		 */
		show : function(){

			this.getDimension();
			this.showLayerWrapper();

			$("#"+ this.id + "_bg").show();
			this.selectBoxControll('hide');
		},
		hide : function(){
			if( this.cache ){
				$("#"+ this.id + "_bg").hide();
				$(this.topElement).hide();
			}else{
				this.clear();
			}
			this.selectBoxControll('show');
		},
		clear : function(){
			$("#"+ this.id + "_bg").remove();
			$(this.topElement).remove();
		},
		/*
		 * body에 DIV 투명한 검은색 배경을 만든다.
		 */
		createDivBackground : function () {
			var createDiv = $("<div id='"+this.id+"_bg'></div>").appendTo("body");
			$(createDiv).css("display","none");
			$(createDiv).css("position","absolute");
			$(createDiv).css("filter","alpha(opacity=50)");
			$(createDiv).css("z-index", this.zindex-1 );
			$(createDiv).css("width","100%");
			$(createDiv).css("top","0");
			$(createDiv).css("left","0");
			$(createDiv).css("opacity","0.5");
			$(createDiv).css("background","#000000"); //주석풀것.
		},
		position : function(){
			var topWithScroll = document.documentElement.scrollTop;
			var clientWithWidth = document.documentElement.clientWidth;
			var clientWithHeight = document.documentElement.clientHeight;
			var layerWrapperObjWidth = $(this.topElement).width();
			var layerWrapperObjHeight = $(this.topElement).height();


			var pos = [];
			pos[0] = (clientWithWidth - layerWrapperObjWidth)/ 2;
			pos[1] = (clientWithHeight - layerWrapperObjHeight)/ 2 + (topWithScroll - 30);
			if(pos[0]<0){
				pos[0] = 0;
			}
			if(pos[1]<0){
				pos[1] = 0;
			}
			return pos;
		},
		setTitle:function( title ){
			this.title = title;
			$("#"+this.id+"_title").text(this.title)  ;
		},
		/*
		 * Select Box disable Controll
		 */
		selectBoxControll : function( type ){
			if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4){
				var selectBoxArray = $('[id^="mainCont"] select');
				selectBoxArray.each(function( i ){
					selectBoxArray[i].style.visibility = type == 'show' ? 'visible' : 'hidden';
				});
			}
		}
}


/**
 * dependency :: PopUp()
 */
var _loadingPopup = null;
function showLoading(){
    if( _loadingPopup == null ){
    	var str = "<div id='loadingPopup' style='display: none;'><img src='/global/images/loading.gif'></div>";
    	//TODO make bg
    	//TODO make loding
    	_loadingPopup  = MessageBox.makePopup( {innerHtml:str, style: MessageBox.STYLE_NONE, cache:true   } );
    }
    _loadingPopup.show();

}
function hideLoading(){
   	 if( _loadingPopup != undefined && _loadingPopup != null){
   		_loadingPopup.hide();
   	 }
}





/**
 *
 *
 * @param jsonData
 * @return
 *
 * Usage :
 *
 */
function processReferenceError( jsonData ){

	var errObj = jsonData.error_by_referenced;
	if( errObj ){
		var errContents = $("<tbody id='referenceList'></tbody>");

		var addReferenceError= function( type, codeVal, title, url ){
			var tr = $("<tr></tr>").appendTo( errContents );
			tr.append("<td>"+type+"</td>");
			tr.append("<th class='col10 lt' >"+ codeVal + "(" + title + ")" + "</th>");

			if( url ){
				tr.append("<td><a href='"+url+"'>이동</a>/<a href='"+url+"' target='_blank'>새창</a></td>");
			}else{
				tr.append("<td>&nbsp;</td>");
			}

		}


		/** 자산 참조 에러 **/
		if( errObj.refer_asset ){
			jQuery.each( errObj.refer_asset , function() {
				var url = "/location/list.do?seq=" + this.seq;
				addReferenceError( "자산", this.codeVal , this.title , url );
		    });
		}

		/** 시스템 참조 에러 **/
		if( errObj.refer_system ){
			jQuery.each( errObj.refer_system, function() {
				var url = "/location/list.do?seq=" + this.seq;
				addReferenceError( "시스템", this.codeVal , this.title , url );
		    });
		}

		/** 시스템 분류 참조 에러 **/
		if( errObj.refer_system_class ){
			jQuery.each( errObj.refer_system_class , function() {
				var url = "/location/list.do?seq=" + this.seq;
				addReferenceError( "시스템분류", this.codeVal , this.title , url );
		    });
		}

		/** 자산분류 참조 에러 **/
		if( errObj.refer_asset_class ){
			jQuery.each( errObj.refer_asset_class , function() {
				var url = "/assetClass/assetClassList.do";
				addReferenceError( "자산분류", this.codeVal , this.title , url );
		    });
		}

		/** 위치 참조 에러 **/
		if( errObj.refer_location ){
			jQuery.each( errObj.refer_location , function() {
				var url = "/location/list.do" ;
				addReferenceError( "위치", this.codeVal , this.title , url );
		    });
		}


		/** 부서 참조 에러 **/
		if( errObj.refer_department ){
			jQuery.each( errObj.refer_department , function() {
				var url = "/department/list.do" ;
				addReferenceError( "부서", this.codeVal , this.title , url );
		    });
		}


		var tmpWrapper = $("<div></div>");
		$(tmpWrapper).append( "<h3 >현재 데이터를 참조하는 데이터가 있습니다.</h3>" );

		var table =  $("<table cellpadding='0' cellspacing='0' class='tableform '></table>");
		$(table).append( errContents );
		$(tmpWrapper).append( table );

		return $(tmpWrapper).html();
	}else{
		return null;
	}
}







//TODO refactory
function showZipCodeSearch( targetElementId ){

	var div = $("<div id='zipcodeSearch' class='popupwindowsub' style='display:none; '></div>");
	$("body").append( div );

	var url = '/jsp/common/zipcode.jsp';
	$.ajax({
	    url: url,
	    type: 'GET',
	    dataType: 'text',
	    async: false ,
		data: { targetElementId : targetElementId},
	    error: function(e, a){
	    	alert(" failed while retrieving data");
	    },
	    success: function(response){
	    	$("#zipcodeSearch").html( response );
	    }
	});




	var topWithScroll = document.documentElement.scrollTop;
	var clientWithWidth = document.documentElement.clientWidth;
	var clientWithHeight = document.documentElement.clientHeight;
	var layerWrapperObjWidth = $(div).width();
	var layerWrapperObjHeight = $(div).height();

	var left = (clientWithWidth - layerWrapperObjWidth)/ 2;
	var top = (clientWithHeight - layerWrapperObjHeight)/ 2 + (topWithScroll - 30);
	if(left<0){
		left = 0;
	}
	if(top<0){
		top = 0;
	}
	$(div).css("position","absolute");
	$(div).css("z-index","9999");
	$(div).css("left",left );
	$(div).css("top",top );


	var closeBtn = $("<input type='button' class='btn popupclose' value='X' />");
	$(closeBtn).appendTo( div) ;

	$(closeBtn).bind( "click" , {src:div}, function(e){
			var src = e.data.src;
			$(src).remove();
    	}
	);


	$(div).show();

}

/**
 * input type ="hidden" 객체를 만들어 준다.
 * @param name
 * @param val
 * @return
 */
function createHiddenForm(name, val){
	var createInput = document.createElement('input');
	createInput.setAttribute('type', 'text');
	createInput.setAttribute('name', name);
	createInput.setAttribute('value', val);
	return createInput;
}

/**
 * textarea 객체를 만들어 준다.
 * @param name
 * @param val
 * @param cols
 * @param rows
 * @return
 */
function createHiddenTextareaForm(name, val, cols, rows){
	var createInput = document.createElement('textarea');
	createInput.setAttribute('class', 'txt');
	createInput.setAttribute('cols', cols);
	createInput.setAttribute('rows', rows);
	createInput.setAttribute('readonly', 'readonly');
	createInput.setAttribute('name', name);
	createInput.innerHTML = val;
	return createInput;
}

/*
 * input type='text' 빈공간을 없애준다.
 */
function checkEscape(srcElement){
      var objEv = srcElement;
      var numPattern = /[\s~!@\#$%^&*\()\-=+_'"\\|]/gi;
      if(numPattern.test(objEv.value)){
      objEv.value=objEv.value.replace(numPattern,"");
    }
}

/**
 * inputbox 에서 enterkey 클릭시 fnName를 호출한다.
 * 사용법 예) : onkeyPress="onKeyPressFormSubmit(event, 'formSubmit()')";
 * @param ev
 * @param fnName
 * @return
 */
function onKeyPressFormSubmit(ev, fnName){
	if(ev.keyCode == '13'){
		eval(fnName);
	}
}


/*
 * FUNCTION NAME: [onlyNum]
 * PARAMS:  		
 * DESCRIPTION:
 * 		input 에  number만 입력받게 한다.
 * 
 * USAGE:
 * 		<input type="text" style="ime-mode:disabled" onkeypress="return onlyNum(event);"  />
 */	
function onlyNum(e){	 
	 var key =  (window.event) ?  event.keyCode : e.which;
	 
	 if(!(key==0||key==8||key==9||key==13||key==46||key==144||(key>=48&&key<=57)||key==110||key==190)){
		  return false;
	 }
}
