String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

/* ID Çü½Ä¿¡ ¸Â´ÂÁö Ã¼Å©ÇÕ´Ï´Ù. */
String.prototype.isID = function() {
//	this.search(/^[A-Za-z0-9_-]{1,}$/)
	if( this.search(/^[A-Za-z0-9]{4,8}$/) < 0 || this.trim()=="" || 
		this.toLowerCase().indexOf("admin") > -1 || 
		this.toLowerCase().indexOf("admininistrator") > -1 || 
		this.toLowerCase().indexOf("webmaster") > -1 || 
		this.toLowerCase().indexOf("master") > -1 || 
		this.toLowerCase().indexOf("supervisor") > -1 || 
		this.toLowerCase().indexOf("superuser") > -1 || 
		this.toLowerCase().indexOf("manager") > -1) return false;
	else return true;
}

/* PassWord Çü½Ä¿¡ ¸Â´ÂÁö Ã¼Å©ÇÕ´Ï´Ù. */
String.prototype.isPW = function() {
	if( this.search(/^[A-Za-z0-9_\-\!@#]{4,8}$/) < 0 || this.trim()=="" ) return false;
	else return true;
}

/*ÄðÅ° Á¦Ç°½Ã¸®¾ó Çü½Ä*/
String.prototype.isPdCode1 = function() {
	if( this.search(/^[A-Za-z0-9]{6}$/) < 0 && this.trim()!="" ) return false;
	else return true;
}
String.prototype.isPdCode2 = function() {
	if( this.search(/^[A-Za-z0-9]{2}$/) < 0 && this.trim()!="" ) return false;
	else return true;
}

//String.prototype.isPdCode3 = function() {
//	if( this.search(/^[ZYXVzyxv][0-9]{8}$/) < 0 && this.trim()!="" ) return false;
//	else return true;
//}

String.prototype.isPdCode3 = function() {
	if( this.search(/^[A-Za-z0-9]{9}$/) < 0 && this.trim()!="" ) return false;
	else return true;
}

function checkFill() {
	if ( event.keyCode == 13 ) checkInput();
}

function pop( url, width, height, flag ) {
    if ( flag == "0" )
		window.open( url, "", "toolbar=0,menubar=0,scrollbars=no,resizable=no,width=" + width + ",height=" + height + ";");
    else 
		window.open( url, "", "toolbar=0,menubar=0,scrollbars=yes,resizable=no,width=" + width + ",height=" + height + ";");
}

function isNumeric( str ) {
    for ( var i = 0; i < str.length; i++ ) {
        if ( str.charAt( i ) < '0' || str.charAt( i ) > '9' )
            return false;
    }
    return true;
}

function isAlphaNumeric( str ) {
    for ( var i = 0; i < str.length; i++ ) {
        if ( !( str.charAt( i ) >= '0' && str.charAt( i ) <= '9' ) &&
                !( str.charAt( i ) >= 'a' && str.charAt( i ) <= 'z' ) &&
                !( str.charAt( i ) >= 'A' && str.charAt( i ) <= 'Z' ) )
            return false;
    }
    
    return true;
}

// TR Å¬¸¯½Ã »ö»óÁÖ´Â ½ºÅ©¸³Æ®
var oldTrId = "";
function trFocus(trId) {
    nowTrId= "tr" + trId;
	oldFocus=document.getElementById(oldTrId);
	nowFocus=document.getElementById(nowTrId);
	if (nowFocus) {
		if (oldFocus != nowFocus) {
			nowFocus.style.background = "#E9F9FE";
			if (oldFocus) {
				oldFocus.style.background = "#FFFFFF";
			}
		}
		oldTrId = nowTrId;
	}
}

function formatMoney( s ) {
    var str  = s.replace(/\D/g,"");    
    var len  = str.length;
    var tmp  = "";
    var tm2  = "";
    var i    = 0;
    
    while (str.charAt(i) == '0') i++;
    str = str.substring(i,len);
    len = str.length;
    if(len < 3) {
        return str;
    }
    else {
        var sit = len % 3;
        
        if (sit > 0) {
            tmp = tmp + str.substring(0,sit) + ',';
            len = len - sit;
        }
        
        while (len > 3) {
            tmp = tmp + str.substring(sit,sit+3) + ',';
            len = len - 3;
            sit = sit + 3;
        }
        
        tmp = tmp + str.substring(sit,sit+3) + tm2;
        str = tmp;
    }
    return str;
}

//ÀÔ·ÂÆû¿¡ Ç×»ó ¼ýÀÚ°ª¸¸À» ÀÔ·Â½ÃÅ°°Ô OnKeyPress ÀÌº¥Æ®¿¡¼­ È£Ãâ
function formatNumeric( s ) {
    var str  = s.replace(/\D/g,"");
    return str;
}

//ÀÌ¸ÞÀÏÀ¯È¿¼ºÃ¼Å©
function isEmail(Str) {
      var fooPat=/^[_a-zA-Z0-9]+([-+.][_a-zA-Z0-9]+)*@[_a-zA-Z0-9]+([-.][_a-zA-Z0-9]+)*\.[_a-zA-Z0-9]+([-.][_a-zA-Z0-9]+)*$/
      var matchArray=Str.match(fooPat)
      if (matchArray==null) {return false;}
      return true;
}

//³¯Â¥À¯È¿¼º Ã¼Å© ex) check_date("2004", "01", "12")
function check_date(Str_y,Str_m,Str_d) {
	var isleapyear = false;			//leapyear = À±³â
	var c_year,c_month,c_day;

	c_year = parseInt(Str_y);

	if(Str_m.charAt(0) == "0") {		//Caution : Everything is a String object!
		c_month = parseInt(Str_m.charAt(1));
	}
	else {
		c_month = parseInt(Str_m);
	}

	if(Str_d.charAt(0) == "0") {
		c_day = parseInt(Str_d.charAt(1));
	}
	else {
		c_day = parseInt(Str_d);
	}

	if ((c_year%4 == 0 && c_year%100 != 0) || c_year%400 == 0) {		//check leap year
		isleapyear = true;
	}

	if(
		//( isNaN(Str_d) || Str_d=="" ) ||
		((c_month==1 || c_month==3 || c_month==5 || c_month==7 || c_month==8 ||
			c_month==10 || c_month==12) && (c_day<1 || c_day>31)) || 
		((c_month==4 || c_month==6 || c_month==9 || c_month==11) && (c_day<1 || c_day>30)) ||
		(c_month==2 && isleapyear==false && (c_day<1 || c_day>28)) ||
		(c_month==2 && isleapyear==true && (c_day<1 || c_day>29)) ) {

		return false;
	}
	else {
		return true;
	}
}

//FormÀÇ ÅØ½ºÆ® ±æÀÌ °æ°í
function alertTxtLength(obj, len) {
	if(obj.value.length>len) {
		alert("ÅØ½ºÆ® ±æÀÌ°¡ ³Ê¹« ±é´Ï´Ù.");
		obj.focus();
		return false;
	}
	return true;
}

//ÀÚ·á½Ç ±Û¾²±â ¸·±â
function keyLock() {
	if(event.keyCode != null)
		event.returnValue=false;
}

/* ÀÔ·ÂµÈ °ªÀÌ ÁÖ¹Î ¹øÈ£ ÇüÅÂÀÎ °æ¿ì¿¡ true¸¦ ¸®ÅÏÇÑ´Ù. */
function isSSN(front, back) { 
	var birthday = front.value;
	var num = back.value;

	if(birthday.length != 6) {
		return false;
	}
	if(num.length != 7) {
		return false;
	}
	var hap = 0;
	for(var i=0; i < 6; i++) {
		var temp = birthday.charAt(i) * (i+2);
		hap += temp;
	}

	var n1 = num.charAt(0);
	var n2 = num.charAt(1);
	var n3 = num.charAt(2);
	var n4 = num.charAt(3);
	var n5 = num.charAt(4);
	var n6 = num.charAt(5);
	var n7 = num.charAt(6);

	hap += n1*8+n2*9+n3*2+n4*3+n5*4+n6*5;
	hap %= 11;
	hap = 11 - hap;
	hap %= 10;
	if(hap != n7)
		return false;
	return true;
}


//ÁÖ¹Îµî·Ï¹øÈ£ ÇüÅÂ¸¦ ¹Þ¾Æ¼­ ÇöÀçÀÏÀ» ±âÁØÀ¸·Î ¸¸ ³ªÀÌ¸¦ Ãâ·Â.
//ex) getAgeFromSSN("771111","1111111")
function getAgeFromSSN(ssn1, ssn2) {
	var now = new Date();
	var now_y = now.getFullYear();
	var now_m = now.getMonth() + 1;
	var now_d = now.getDate();
	var nowdate, age, birthdate;
	var gubun = eval(ssn2.substring(0,1));
	var birth_y = eval(ssn1.substring(0,2))

	if(now_m<10) now_m = "0"+now_m; else now_m = ""+now_m;
	if(now_d<10) now_d = "0"+now_d; else now_d = ""+now_d;

	if(gubun==3||gubun==4) birth_y = 2000+birth_y;
	else birth_y = 1900+birth_y;

	now_md = eval(""+now_m+now_d);
	birth_md = eval(ssn1.substring(2,6))
	
	age = eval(now_y-birth_y)-1;
	if(now_md-birth_md>=0) age = age + 1;	//¿À´Ã ³¯Â¥ ÀÌÈÄ·Î ³ªÀÌ Áõ°¡

	return age;
}


//ÀÌ¹ÌÁö Å©±âÁ¶Àý : width¿Í heightÀÇ MAX°ªÀ» ÁÖ°í, ¹þ¾î³¯ °æ¿ì º»·¡ÀÇ ºñÀ²À» À¯ÁöÇÏ¸é¼­ Ãà¼Ò.
//ex) <img src='....' onLoad='resizeimg(this, 300, 200)'>
function resizeimg(obj, desiredW, desiredH) {
	var imgW = eval(obj).width;
	var imgH = eval(obj).height;

	if(imgW>desiredW || imgH>desiredH) {
		if(imgH>=imgW) {
			if(((desiredH*imgW)/imgH)>desiredW){
				obj.height = (desiredW*imgH) / imgW;
				obj.width = desiredW;
			}else{
				obj.height = desiredH;
				obj.width = (desiredH*imgW)/imgH;
			}
		}else{
			if(((desiredW*imgH)/imgW)>desiredH) {
				obj.height = desiredH;
				obj.width = (desiredH*imgW) / imgH;
			}else{
				obj.height = (desiredW*imgH) / imgW;
				obj.width = desiredW;
			}
		}
	}
}

//formÀÇ obj1ÀÇ ±æÀÌ°¡ numÀÌ µÇ¸é obj2¿¡ Æ÷Ä¿½º
//ex) <input type="text" name="ssn1" onKeyPress="fnNext(this, 6, document.frm.ssn2);">
function fnNext(obj1, num, obj2) {
	if (obj1.value.length >= num) {
		obj2.focus ();
	}
}

//loginÃ¢ pop-up
function pop_login() {
	var winPosLeft = (screen.width - 400) / 2;
	var winPosTop = (screen.height - 450) / 2;

	window.open("/common/login.asp", "qoolqee_loginpop", "width=370,height=270,top="+winPosTop+",left="+winPosLeft+"location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

//loginÃ¢ pop-up
function pop_event_login() {
	var winPosLeft = (screen.width - 400) / 2;
	var winPosTop = (screen.height - 400) / 2;

	window.open("/common/login_event.asp", "qoolqee_loginpop", "width=370,height=270,top="+winPosTop+",left="+winPosLeft+"location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

//loginÃ¢ pop-up
function pop2( url, width, height, flag ) {
	var winPosLeft = (screen.width - 400) / 2;
	var winPosTop = (screen.height - 400) / 2;

	window.open(url, "", "width="+ width +",height="+height+",top="+winPosTop+",left="+winPosLeft+"location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function openWin(url,name,scroll,resize,weight,height)
{
	var winl = (screen.width - weight) / 2;
	var wint = (screen.height -height) / 2;
	winprops = 'height='+height+',width='+weight+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize;
	win = window.open(url, name, winprops)

	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

