
// 그림 이미지 비례 조정
   function func_adjustimage(target_img, w, h)
   {
      var newX;
      var newY;
      var newHeight;
      var newWidth;
      var maxWidth = w;
      var maxHeight = h;
      var newImg = new Image();
      newImg.src = target_img.src;
      imgw = newImg.width;
      imgh = newImg.height;
      if (imgw > maxWidth || imgh > maxHeight)
      {
         if (imgw/maxWidth > imgh/maxHeight)
         {
            if (imgw > maxWidth)
               newWidth = maxWidth;
            else
               newWidth = imgw;
            newHeight = Math.round((imgh * newWidth) / imgw);
         }
         else
         {
            if (imgh > maxHeight)
               newHeight = maxHeight;
            else
               newHeight = imgh;
            newWidth = Math.round((imgw * newHeight) / imgh);
         }
      }
      else
      {
         newWidth = imgw;
         newHeight = imgh;
      }
       newX = maxWidth / 2 - newWidth / 2;
       newY = maxHeight / 2 - newHeight / 2;
       target_img.onload = null;
       target_img.src = newImg.src;
       target_img.width = newWidth;
       target_img.height = newHeight;
   }
	 
/*
	+----------------------------------------------------------------------------------------------+
	| 기능   : 공용 스크립트                                                                       |
	| 파일명 : comm_func.js                                                                        |
	+----------------------------------------------------------------------------------------------+
*/
	var reAlphanumeric = /^[a-zA-Z0-9]+$/
/*
	+----------------------------------------------------------------------------------------------+
    | 빈 개체 체크 : isEmptyObj(개체)                                                              |
	+----------------------------------------------------------------------------------------------+
*/
    function isEmptyObj(para)
    {
        for (var i=0; i<isEmptyObj.arguments.length; i++)
        {
            if (typeof(isEmptyObj.arguments[i]) == "object" && isEmptyObj.arguments[i].value.length > 0)
            	return false;
        }

        return true;
    }

    function isEmpty(s)
    {
        if (s != null && s.length == 0)
        	return true;

        return false;
    }
/*
	+--------------------------------------------------------------------------------------+
	| 숫자만 입력 받기                                                                     |
	+--------------------------------------------------------------------------------------+
*/
	function onlyNumeric(obj)
	{
		if (/[\d]|\./.test(String.fromCharCode(event.keyCode)))
			return true;
		else
			return false;
	}
/*
	+--------------------------------------------------------------------------------------+
	| 숫자 관련 정규식                                                                     |
	+--------------------------------------------------------------------------------------+
*/
	function nr_num(this_s,type){ 
    /* 
    type 
    -> 'int' : 양의 정수 
    -> 'float' : 양의 실수 
    -> '-int' : 음의 정수 포함 
    -> '-int' : 음의 실수 포함 
    */ 
    temp_value = this_s.value.toString(); 
    regexp = /[^-\.0-9]/g; 
    repexp = ''; 
    temp_value = temp_value.replace(regexp,repexp); 
    regexp = ''; 
    repexp = ''; 
    switch(type){ 
        case 'int':     regexp = /[^0-9]/g; break; 
        case 'float':regexp = /^(-?)([0-9]*)(\.?)([^0-9]*)([0-9]*)([^0-9]*)/; break; 
        case '-int':    regexp = /^(-?)([0-9]*)([^0-9]*)([0-9]*)([^0-9]*)/;break; 
        case '-float':regexp = /^(-?)([0-9]*)(\.?)([^0-9]*)([0-9]*)([^0-9]*)/; break; 
        default : regexp = /[^0-9]/g; break; 
    } 
    switch(type){ 
        case 'int':repexp = '';break; 
        case 'float':repexp = '$2$3$5';break; 
        case '-int':    repexp = '$1$2$4';break; 
        case '-float':repexp = '$1$2$3$5'; break; 
        default : regexp = /[^0-9]/g; break; 
    } 
    temp_value = temp_value.replace(regexp,repexp); 
    this_s.value = temp_value; 
} 
/*
	+--------------------------------------------------------------------------------------+
	| 양의 정수만 입력받기                                                                 |
	+--------------------------------------------------------------------------------------+
*/
function nr_num_int(this_s){ 
    nr_num(this_s,'int'); 
} 
/*
	+--------------------------------------------------------------------------------------+
	| 양의 실수만 입력받기                                                                 |
	+--------------------------------------------------------------------------------------+
*/
function nr_num_float(this_s){ 
    nr_num(this_s,'float'); 
} 

/*
	+----------------------------------------------------------------------------------------------+
    | 팝업 윈도우 띄우기                                                                           |
	+----------------------------------------------------------------------------------------------+
*/
	function PopUpWindow(url, pid, pwidth, pheight, opt)
	{
	   var idwindow = window.open(url, pid, "width="+pwidth+", height="+pheight+", left="+((screen.availWidth-pwidth)/2)+", top="+(screen.availHeight-pheight)/2 + opt, scrollbars=yes);

	   if (idwindow)
			idwindow.focus();
	}
/*
	+----------------------------------------------------------------------------------------------+
    | Null Check                                                                                   |
	+----------------------------------------------------------------------------------------------+
*/
	function checkEmpty(obj, msg, emptyOk)
	{
		res = true;

		if (isEmptyObj(obj))
		{
			if (!emptyOk)
			{
				alert(msg);

				obj.focus();
			}

			res = emptyOk;
		}
		else if (Trim(obj.value) == "")
		{
			alert(msg);

			obj.focus();
			obj.select();

			res = false;
		}

		return res;
	}
/*
	+----------------------------------------------------------------------------------------------+
    | 왼쪽 공백 제거                                                                               |
	+----------------------------------------------------------------------------------------------+
*/
	function LTrim(obj)
	{
		var s = new String(obj);

		if (s.substr(0,1) == " ")
			return LTrim(s.substr(1));
		else
			return s;
	}
/*
	+----------------------------------------------------------------------------------------------+
    | 오른쪽 공백 제거                                                                             |
	+----------------------------------------------------------------------------------------------+
*/
	function RTrim(obj)
	{
		var s = new String(obj);

		if (s.substr(s.length-1, 1) == " ")
			return RTrim(s.substring(0, s.length-1));
		else
			return s;
	}
/*
	+----------------------------------------------------------------------------------------------+
    | 양쪽 공백 제거                                                                               |
	+----------------------------------------------------------------------------------------------+
*/
	function Trim(obj)
	{
		return LTrim(RTrim(obj));
	}
/*
	+----------------------------------------------------------------------------------------------+
    | 폼의 기본값 세팅                                                                             |
	+----------------------------------------------------------------------------------------------+
	| nLen   - form 요소의 갯수                                                                    |
	| d_val  - 각 요소의 default value 값 즉! 초기화하고자 하는값                                  |
	| f_type - form 요소의 타입(select, radio, checkbox...)                                        |
	+----------------------------------------------------------------------------------------------+
*/
	function setDefaultValue(f)
	{
		var nLen;
		var d_val;
		var f_type;

		for (var i = 0; i < f.elements.length; i++)
		{
			f_type  = f.elements[i].type.toUpperCase();
			d_val   = f.elements[i].d_val;

			if (d_val && f_type == "SELECT-ONE")														// Select 1 개일 경우
			{
				nLen = f.elements[i].options.length;

				for (var j = 0; j < nLen; j++)
				{
					if (f.elements[i].options[j].value == d_val)
						f.elements[i].options[j].selected = true;
				}
			}

			if (f_type == "SELECT-MULTIPLE")      													// Select 다중 선택
			{
				nLen = f.elements[i].options.length;

				for (var j = 0; j < nLen; j++)
				{
					if (f.elements[i].options[j].value == f.elements[i].options[j].d_val)
						f.elements[i].options[j].selected = true;
				}

			}

			if (d_val && (f_type == "RADIO" || f_type == "CHECKBOX"))
			{
				if (f.elements[i].value == d_val)
					f.elements[i].checked = true;
			}
		}

		return true;;
	}
