﻿//이미지 리사이징
function resizeImg(imgObj) {
	// 이미지 별도 로딩으로 원래 사이즈 추출
	var imgOriginal = new Image();
	imgOriginal.src = imgObj.src;
	// 가로와 세로 중 어느걸 기준으로 줄일지 결정
	var baseAxis;
	if ( (imgOriginal.width / imgObj.width) > (imgOriginal.height / imgObj.height) )
		baseAxis = 'width';
	else
	baseAxis = 'height';
	// 결정된 기준을 바탕으로 나머지 길이를 리사이징
	if (baseAxis == 'width') {
		imgObj.height = Math.round(imgOriginal.height * (imgObj.width / imgOriginal.width));
	} else { // baseAxis == 'height'
		imgObj.width = Math.round(imgOriginal.width *
		(imgObj.height / imgOriginal.height));
	}
}


//숫자만 입력
//숫자만 입력( style="ime-mode:disabled;" onKeypress="inputNumCheck();" 로 설정해야 함)
function inputNumCheck() {
	if(((event.keyCode<48) || (event.keyCode>57)) && (event.keyCode != 46)) {
        event.returnValue=false;
        }
}

// 영어만 입력받기 (대소문자)
// 나머지 글자 무시
function nr_eng(this_s,type){
	temp_value = this_s.value.toString();
	regexp = '';
	repexp = '';
	switch(type){
		case 'small':regexp = /[^a-z]/g;break;
		case 'big':regexp = /[^A-Z]/g;break;
		case 'all':regexp = /[^a-z]/i;break;
		default :regexp = /[^a-z]/i;break;
	}

	temp_value = temp_value.replace(regexp,repexp);
	this_s.value = temp_value;
}

// 영어만 입력받기 (소문자)
// 나머지 글자 무시
function nr_eng_small(this_s){
	nr_eng(this_s,'small');
}

// 영어만 입력받기 (대문자)
// 나머지 글자 무시
function nr_eng_big(this_s){
	nr_eng(this_s,'big');
}

// 전화번호 규격에 맞게 DDD-MM~M-XXXX
// 나머지 글자 무시
function nr_phone(this_s){ 
	temp_value = this_s.value.toString();
	temp_value = temp_value.replace(/[^0-9]/g,'');
	temp_value = temp_value.replace(/(0(?:2|[0-9]{2}))([0-9]+)([0-9]{4}$)/,"$1-$2-$3"); 
	this_s.value = temp_value;
} 

// 주민등록 번호 규격에 맞게 123456-1234567 //검증하지 않음.
// 나머지 글자 무시
function nr_jumin(this_s){ 
	temp_value = this_s.value.toString();
	temp_value = temp_value.replace(/[^0-9]/g,'');
	temp_value = temp_value.substr(0,13);
	temp_value = temp_value.replace(/([0-9]{6})([0-9]{7}$)/,"$1-$2"); 
	this_s.value = temp_value;
}

// 사업자 등록 번호 규격에 맞게 123-12-12345 //검증하지 않음.
// 나머지 글자 무시
function nr_company_num(this_s){ 
	temp_value = this_s.value.toString();
	temp_value = temp_value.replace(/[^0-9]/g,'');
	temp_value = temp_value.substr(0,10);
	temp_value = temp_value.replace(/([0-9]{3})([0-9]{2})([0-9]{5}$)/,"$1-$2-$3"); 
	this_s.value = temp_value;
}
//숫자 콤마찍기
function comma(x) {
		var txtNumber = '' + x;
		if (isNaN(txtNumber) || txtNumber == "") {
			alert("숫자만 입력 하세요");
		} else {
			var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
			var arrNumber = txtNumber.split('.');
			arrNumber[0] += '.';
			do {
				arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');
			} while (rxSplit.test(arrNumber[0]));

			if (arrNumber.length > 1)
				return arrNumber.join('');
			else
				return arrNumber[0].split('.')[0];
		}
	}
//Popup
function sendPopup(url,popName,size){
	window.open(url,popName,size);
}
//url
function gourl(addr){
	location.href= addr;
}

//부분인쇄부분
var initBody;

function beforePrint(){
	initBody = document.body.innerHTML; document.body.innerHTML = idPrint.innerHTML;
}

function afterPrint(){
	document.body.innerHTML = initBody;
}
function printArea() {
	window.print();
}
//window.onbeforeprint = beforePrint;
//window.onafterprint = afterPrint;
//부분인쇄 부분끝

//필드체크부분
//*중요* prototype.js가 있어야함.
function Chk(aq_value,aq_Msg){
		eval("var tpresent = Form.Element.present('" + aq_value + "');");

		if(!tpresent){
			alert(aq_Msg + " 입력해주세요.");
			Form.Element.activate(aq_value);
			return true;
		}
}

//DOM관련 항목
//************************************************************************************************
function DOMreset(elObject){
	if(elObject != null && elObject.hasChildNodes()){
		for(var i = 0; i<elObject.childNodes.length;i++){
			elObject.removeChild(elObject.firstChild);
		}
	}
}

function DOMcreateOptions(sel,_options){
	//_options는 select 리스트의 option에 사용된 문자열 배열
	//sel은 select 객체
	if(_options == null || _options.length == 0){
		return;
	}

	for(var i = 0;i<_options.length;i++){
		opt = document.createElement("option");
		opt.value = _options[i].C_Code;
		opt.appendChild(document.createTextNode(_options[i].C_Name));
		sel.appendChild(opt);
	}
}
//************************************************************************************************
//CHECKBOX ALL/ALLOUT
function Chkall(aqValue,aqAllName){
		var allNum = document.getElementsByName(aqValue);
		eval("var chkAll=$('" + aqAllName + "')");

		if(chkAll.checked){
			for(i = 0;i < allNum.length;i++){
				allNum[i].checked = true;
			}
		}else{
			for(i = 0;i < allNum.length;i++){
				allNum[i].checked = false;
			}
		}
	}

//************************************************************************************************
//사용법( onMouseOver="scriptcolorOver(this,'#E7E7E7')"  onMouseOut="scriptcolorOut(this)");
//마우스 오버시 tr에 색상주기
	function scriptcolorOver(aq_this,aq_color){
		aq_this.style.backgroundColor = aq_color;
	}

	function scriptcolorOut(aq_this){
		aq_this.style.backgroundColor = "";
	}
//************************************************************************************************
//엔터키 사용시 체크
function scriptEnter(){
			if(event.keyCode == 13){returnkeyCode(true);}else{returnkeyCode(false)};
}
//************************************************************************************************
/*
Creator : shj at xenosi.de

if(false == (birth = checkPersonalNo(주민번호))) 틀렸어요;
년 = birth[0];
월 = birth[1];
일 = birth[2];
if(birth[3]) 외국인;
*/

function checkPersonalNo(personal_no)
{
    personal_no = personal_no.replace(/[^\d]+/g, '');
    pattern = /^[0-9]{6}[1-8][0-9]{6}$/;

    if(!pattern.test(personal_no)) {
        return false;
    }
    var birth = new Array();
    birth[0] = personal_no.substr(0, 2);
    switch(personal_no.charAt(6)) {
    case '1':
    case '2':
        birth[0] = ('19' + birth[0]) * 1;
        birth[3] = false;
        break;
    case '3':
    case '4':
        birth[0] = ('20' + birth[0]) * 1;
        birth[3] = false;
        break;
    case '5':
    case '6':
        birth[0] = ('19' + birth[0]) * 1;
        birth[3] = true;
        break;
    case '7':
    case '8':
        birth[0] = ('20' + birth[0]) * 1;
        birth[3] = true;
        break;
    /*case '9': // 이렇게 늙은 사람은 있어도 안받아요. 위의 정규식에서 안받음.
    case '0':
        birth[0] = ('18' + birth[0]) * 1;
        birth[3] = true;
        break;*/
    }

    birth[1] = personal_no.substr(2, 2) * 1;
    birth[2] = personal_no.substr(4, 2) * 1;

    if(birth[1] < 1 || birth[1] > 12) {
        return false;
    }
    if(birth[2] < 1 || birth[2] > 31) {
        return false;
    }
    var check = 0;
    var mul = 2;

    if(birth[3]) {
        if(((personal_no.charAt(7) * 10 + personal_no.charAt(8)) % 2) != 0) {
            return false;
        }
    }
    for(i = 0; i < 12; i ++) {
        check += personal_no.charAt(i) * mul;
        mul ++;
        if(mul > 9) {
            mul = 2;
        }
    }

    check = 11 - (check % 11);

    if(check > 9) {
        check %= 10;
    }
    if(birth[3]) {
        check += 2;
        if(check > 9) {
            check %= 10;
        }
    }
    if(check != personal_no.charAt(12)) {
        return false;
    }
    return birth;
}


/*
License : Public Domain
*/


// 법인번호 체크
  function CheckBubin(obj, step) {
    var err = 0;

    if(step == "submit"){
        var objchar = eval("document.all."+ obj + "1");
        var objchar2 = eval("document.all."+ obj + "2");

        if(objchar.value.length != 6){
            alert("법인등록번호를 정확히 입력하여 주세요.");
            objchar.value = "";
            objchar.focus();
            return false;
        }
        if(objchar2.value.length != 7){
            alert("법인등록번호를 정확히 입력하여 주세요.");
            objchar2.value = "";
            objchar2.focus();
            return false;
        }

    }else if(step == "write"){
        var objchar = eval("document.all."+ obj.name.substring(0, obj.name.length - 1) + "1");
        var objchar2 = eval("document.all."+ obj.name.substring(0, obj.name.length - 1) + "2");
    }


    for(CB_i=0;CB_i<objchar2.value.length;CB_i++){
        var bubinnum=objchar2.value.charAt(CB_i);
        if (bubinnum < '0' || bubinnum > '9'){
            alert("법인등록번호는 숫자만 가능합니다.");
            objchar2.value = objchar2.value.substring(0, CB_i);;
            objchar2.focus();
            return false;
        }
    }

    if(objchar2.value) {
         if(objchar2.value.length == 7) {


            var fullbubin = objchar.value + objchar2.value;
            var hap = 0;
            var j = 0;

            for (CB_ii=0; CB_ii<12;CB_ii++){
                if(j < 1 || j > 2){j=1;}
                hap = hap + (parseInt(fullbubin.charAt(CB_ii)) * j);
                j++;
            }

            if ((10 - (hap%10))%10 != parseInt(fullbubin.charAt(12))){
                err=1;
            }

            if (err == 1){
                alert("올바른 법인등록번호가 아닙니다.");
                objchar.value = "";
                objchar2.value = "";
                objchar.focus();
                return false;
            }
        }
    }
    return true;
}

function libdel(fnc_idx,fnc_tablename,fnc_back,fnc_kind){
	var msg  = confirm("선택한 항목을 삭제하시겠습니까?");

	if(msg){
		if(fnc_kind == "m"){
			location.href = "/lib/manydel.php?idx=" + fnc_idx + "&tableName=" + fnc_tablename + "&back=" + escape(fnc_back);
		}else{
			location.href = "/lib/del.php?idx=" + fnc_idx + "&tableName=" + fnc_tablename + "&back=" + escape(fnc_back);
		}
	}
}

function boarddel(fnc_idx,fnc_tn,fnc_back){
	var msg  = confirm("선택한 항목을 삭제하시겠습니까?");

	if(msg){
		location.href = "/lib/boarddel.php?idx=" + fnc_idx + "&tn=" + fnc_tn + "&back=" + escape(fnc_back);
	};
}

function updatefn(aqidx,aqtn,aqcol){
	var msg  = confirm("선택한 항목을 삭제하시겠습니까?");

	if(msg){
		location.href = "/lib/dbupdate.php?idx=" + aqidx + "&tn=" + aqtn + "&col=" + escape(aqcol) + "&back=" + escape(fnc_back);
	}
}

//trim
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

function highslideclose(){
	hs.close();
}

function scriptTgl(paramdv){
	eval("$('" + paramdv + "').toggle()");
}
