// 전체 홈페이지에서 사용할 PATH관련 전역변수 선언
// 기존 방식에 대해 최소한의 수정 작업을 위해 모든 PATH는 닫힘도 표시해 주기로 한다.
// 예 ) CONTEXT = "/krm/", "/" WORK_PATH = "workgroup/", "/"
var CONTEXT = "/"
var CAFE_PATH = "/opencomm/"
var BLOG_PATH = "/blog/"

var WORK_PATH = "workgroup/"
window.name="KRM_SITE";

 var openAjax = {	// Ajax 통신
 		ts : null,
 		addText: function(){
			var timeStamp = (new Date()).getTime();
			openAjax.ts = timeStamp;
			return "<span id=\""+timeStamp+"\" style=\"display:block\"></span>";
 		},
		doDisplay: function(divID,url){
			var timeStamp = (new Date()).getTime();

			new Ajax.Request(url, {
				method: 'post',
				asynchronous: true,
				contentType: 'application/x-www-form-urlencoded',
				encoding: 'UTF-8',
				parameters: {'timeStamp':timeStamp},
				
				onLoading: function(xmlHttp){
					try{$(divID).focus();}catch(e){;}
				},
				onSuccess: function(xmlHttp){
					try{
						Element.hide('OA_LOADING');
						Element.hide('ARCHIVE_LOADING');
					}catch(e){;}

					openAjax.setResult(xmlHttp.responseText,divID);
				},
				on404: function(xmlHttp){
					alert(' Ajax Error Code 404 ');
				},
				on500: function (xmlHttp){
					//alert(' Ajax Error Code 500 ');
					document.body.innerHTML = xmlHttp.responseText;
				}
			});
		},
		doDisplayCall: function(url,fn){
			var timeStamp = (new Date()).getTime();

			new Ajax.Request(url, {
				method: 'post',
				asynchronous: true,
				contentType: 'application/x-www-form-urlencoded',
				encoding: 'UTF-8',
				parameters: {'timeStamp':timeStamp},

				onSuccess: function(xmlHttp){
					openAjax.setResultCall(xmlHttp.responseText,fn);
				},
				on404: function(xmlHttp){
					alert(' Ajax Error Code 404 ');
				},
				on500: function (xmlHttp){
					//alert(' Ajax Error Code 500 ');
					document.body.innerHTML = xmlHttp.responseText;
				}
			});
		},
		doAction: function(divID,url,formID){

			new Ajax.Request(url, {
				method: 'post',
				asynchronous: true,
				contentType: 'application/x-www-form-urlencoded',
				encoding: 'UTF-8',
				parameters: Form.serialize(formID),

				onSuccess: function(xmlHttp){
					openAjax.setResult(xmlHttp.responseText,divID);
				},
				on404: function(xmlHttp){
					alert(' Ajax Error Code 404 ');
				},
				on500: function (xmlHttp){
					//alert(' Ajax Error Code 500 ');
					document.body.innerHTML = xmlHttp.responseText;
				}
			});
		},
		doActionCall: function(url,formID,fn){
			new Ajax.Request(url, {
				method: 'post',
				asynchronous: true,
				contentType: 'application/x-www-form-urlencoded',
				encoding: 'UTF-8',
				parameters: Form.serialize(formID),

				onSuccess: function(xmlHttp){
					openAjax.setResultCall(xmlHttp.responseText,fn);
				},
				on404: function(xmlHttp){
					alert(' Ajax Error Code 404 ');
				},
				on500: function (xmlHttp){
					//alert(' Ajax Error Code 500 ');
					document.body.innerHTML = xmlHttp.responseText;
				}
			});
		},
		setResult: function(resText,divID){
			if($(divID)!=null){
				$(divID).innerHTML=resText;
				$(divID).show();
			}
			openAjax.setLocation();
		},
		setResultCall: function(resText,fn){
			fn(resText);
			openAjax.setLocation();
		},
		setResultObjCall: function(resText,fn,obj){
			fn(resText,obj);
			openAjax.setLocation();
		},
		setLocation: function(anchorName){
			//var timeStamp = (new Date()).getTime();
			//var loc = location.href.split('#');
			//if(anchorName!=null)timeStamp = anchorName;
			//location = "#"+timeStamp;
	
			//putHistoryData(timeStamp);
		}
	}
function addHistory(newLocation){
	var length = locArray.length==null?0:locArray.length;
	locArray[length] = newLocation;
}

function getHistory(index){
	return locArray[parseInt(index)-1];
}

function getHistorySize(){
	return (locArray.length==null?0:locArray.length);
}


function debug(msg){
	document.body.innerHTML = msg +document.body.innerHTML;
}

function min(a, b) {C
 	return ( a > b ) ? b : a;
}

function max(a, b) {
 	return ( a < b ) ? b : a;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function doKeySubmit(formName){
	if (event.keyCode==13) { document.getElementsByName(formName)[0].submit(); }
}

function doClickSubmit(formName){
	 document.getElementsByName(formName)[0].submit();
}

function openWindow(href,WinName,w,h,scroll,resize) {
	var PosLeft;
	var PosTop;

	PosLeft = (window.screen.width/2) - (w/2 + 10);
	PosTop = (window.screen.height/2) - (h/2 + 50);

//	scroll = 0;

	if(window.screen.width<w+10){
		PosLeft = 0;
		w = window.screen.width - 10;
		scroll = 1;
	}

	if(window.screen.height<h+60){
		PosTop = 0;
		if(window.screen.width>w+10){
			w +=15;
		}

		h = window.screen.height - 60;
		scroll = 1;
	}

	var winObj = window.open(href,WinName,"status=no, height=" + h + ",width=" + w + ", scrollbars=" + scroll + ",resizable=" + resize + ",left=" + PosLeft + ",top=" + PosTop + ",screenX=" + PosLeft + ",screenY=" + PosTop );
	try{
	winObj.onLoad = resizeWindowObj(winObj,w,h);
	}catch(e){;}
	winObj.focus();
	return winObj;
}

function openWindowBlank(href,WinName,w,h,scroll,resize) {
	var PosLeft;
	var PosTop;

	PosLeft = (window.screen.width/2) - (w/2 + 10);
	PosTop = (window.screen.height/2) - (h/2 + 50);

//	scroll = 0;

	if(window.screen.width<w+10){
		PosLeft = 0;
		w = window.screen.width - 10;
		scroll = 1;
	}

	if(window.screen.height<h+60){
		PosTop = 0;
		if(window.screen.width>w+10){
			w +=15;
		}

		h = window.screen.height - 60;
		scroll = 1;
	}

	var winObj = window.open(href,'_blank');
	try{
	winObj.onLoad = resizeWindowObj(winObj,w,h);
	}catch(e){;}
	winObj.focus();
	return winObj;
}

function resizeWindow(w,h) {
	appname = navigator.appName
	useragent = navigator.userAgent;

	if(appname == "Microsoft Internet Explorer") appname = "IE";
	win2000 = (useragent.indexOf('NT 5.0')>0);  //윈도우 2000 버전
	winxp = (useragent.indexOf('NT 5.1')>0);     //윈도우 xp 버전

	if(appname=="IE" && win2000){
		window.resizeTo(w,h);
	}else if (appname=="IE" && winxp){
		window.resizeTo(w,h + 50);
	}else{
		window.resizeTo(w,h);
	}
}

function resizeWindowObj(Obj,w,h) {
	appname = navigator.appName
	useragent = navigator.userAgent;

	if(appname == "Microsoft Internet Explorer") appname = "IE";
	win2000 = (useragent.indexOf('NT 5.0')>0);  //윈도우 2000 버전
	winxp = (useragent.indexOf('NT 5.1')>0);     //윈도우 xp 버전

	if(appname=="IE" && win2000){
		Obj.resizeTo(w,h);
	}else if (appname=="IE" && winxp){
		Obj.resizeTo(w,h + 50);
	}else{
		Obj.resizeTo(w,h);
	}
}
/**
function goPage(newUrl) {
	if(newUrl==null) location = location;
	else location = newUrl;
}
*/
function movePage(newUrl) {
	if(newUrl==null) location.reload();
	else location.reload(newUrl);
}

function trim(str) {
    var count = str.length;
    var len = count;
    var st = 0;

    while ( st < len) {
        if(str.substring(st,st+5) == "&nbsp"){
            return "";
        }
        st++;
    }
    st=0;
    while ((st < len) && (str.charAt(st) <= ' ')) {
        st++;
    }
    while ((st < len) && (str.charAt(len - 1) <= ' ')) {
        len--;
    }
    return ((st > 0) || (len < count)) ? str.substring(st, len) : str ;
}

function bytes() {
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
    return l;
}

function cut(len) {
    var str = this;
    var l = 0;
        for (var i=0; i<str.length; i++) {
            l += (str.charCodeAt(i) > 128) ? 2 : 1;
            if (l > len) return str.substring(0,i);
        }
    return str;
}

function resizeFrame2(frameid){
	try {
		nHeight = ( document.body.scrollHeight > parent.MAX_HEIGHT ) ? parent.MAX_HEIGHT : (( document.body.scrollHeight < parent.MIN_HEIGHT ) ? parent.MIN_HEIGHT : document.body.scrollHeight );
		parent.document.all[frameid].style.height = nHeight ;
	} catch(e) {
	}

}

function resizeFrame(frameid){
	try {
		parent.document.all[frameid].style.height = 300 ;
		parent.document.all[frameid].style.width =  '100%';
		nHeight = ( document.body.scrollHeight > parent.MAX_HEIGHT ) ? parent.MAX_HEIGHT : (( document.body.scrollHeight < parent.MIN_HEIGHT ) ? parent.MIN_HEIGHT : document.body.scrollHeight );
		nWidth = ( document.body.scrollWidth > parent.MAX_WIDTH ) ? parent.MAX_WIDTH : document.body.scrollWidth ;
		parent.document.all[frameid].style.height = nHeight ;
		parent.document.all[frameid].style.width =  nWidth;

	} catch(e) {
		;
	}
}


function resizeFrameH(frameid){
	try {
		parent.document.all[frameid].style.height = 600 ;
		parent.document.all[frameid].style.width =  '100%';
		nHeight = ( document.body.scrollHeight > parent.MAX_HEIGHT ) ? parent.MAX_HEIGHT : (( document.body.scrollHeight < parent.MIN_HEIGHT ) ? parent.MIN_HEIGHT : document.body.scrollHeight );
		nWidth = ( document.body.scrollWidth > parent.MAX_WIDTH ) ? parent.MAX_WIDTH : document.body.scrollWidth ;
		parent.document.all[frameid].style.height = nHeight+2 ;
		parent.document.all[frameid].style.width =  nWidth+2;

	} catch(e) {
		;
	}
}

function setParentValue(id,val){
	eval("parent.document.all."+id).innerHTML = val;
}

function formQuery(docForm) {
  return Form.serialize(docForm);
}

function makeTempDiv(divID){
	var timeStamp = (new Date()).getTime();
	var tmpDivID = "";
	if(divID!=null){
		tmpDivID=divID;
	}else{
		tmpDivID="tmp_"+timeStamp;
	}
	tempDiv = document.createElement("DIV");
	tempDiv.id=tmpDivID;
    tempDiv.style.display = "none";
    tempDiv.style.zIndex=10;
	tempDiv.style.position="absolute";
	tempDiv.style.top="25%";
	tempDiv.style.left="25%";
	tempDiv.innerHTML=" ";
    document.body.appendChild(tempDiv);
    return tmpDivID;
}

var makeDiv ={
	makeTempDiv : function(divID){
		var timeStamp = (new Date()).getTime();
		var tmpDivID = (divID!=null)?divID:"tmp_"+timeStamp;

		tempDiv = document.createElement("DIV");
		tempDiv.id=tmpDivID;
	    tempDiv.style.display = makeDiv.display;
	    tempDiv.style.zIndex=makeDiv.zIndex;
		tempDiv.style.position=makeDiv.position;
		tempDiv.style.top=makeDiv.top;
		tempDiv.style.left=makeDiv.left;
		tempDiv.innerHTML=makeDiv.innerHTML;
	    document.body.appendChild(tempDiv);
	    return tmpDivID;
	},
	makeTempDivObj : function(divID){
		var timeStamp = (new Date()).getTime();
		var tmpDivID = (divID!=null)?divID:"tmp_"+timeStamp;

		tempDiv = document.createElement("DIV");
		tempDiv.id=tmpDivID;
	    tempDiv.style.display = makeDiv.display;
	    tempDiv.style.zIndex=makeDiv.zIndex;
		tempDiv.style.position=makeDiv.position;
		tempDiv.style.top=makeDiv.top;
		tempDiv.style.left=makeDiv.left;
		tempDiv.innerHTML=makeDiv.innerHTML;
	    return tempDiv;
	},
	display:'none',
	zIndex:10,
	position:'absolute',
	top:'25%',
	left:'25%',
	innerHTML:' '
}

/*var makeDialog ={
	makeTempDialog : function(dialogID,divID){
		var timeStamp = (new Date()).getTime();
		var tmpDialogID = (dialogID!=null)?dialogID:"tmpD_"+timeStamp;
		var tmpDivID = (divID!=null)?divID:"tmp_"+timeStamp;

	    tempDialog = document.createElement("DIV");
		tempDialog.id =dialogID;
		tempDialog.dojoType ="dialog";
		tempDialog.bgColor ="gray";
		tempDialog.bgOpacity ="0.5";
		tempDialog.toggle ="fade";
		tempDialog.toggleDuration ="150";

		var newDiv = makeDiv.makeTempDivObj(divID);

		tempDialog.appendChild(newDiv);
	    document.body.appendChild(tempDialog);
	    return tmpDialogID;
	},
	display:'none',
	zIndex:10,
	position:'absolute',
	top:'25%',
	left:'25%',
	innerHTML:' '
}*/

function showFlash(swf, width, height)
{
    document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,24,0\" width=\""+width+"\" height=\""+height+"\" align=\"middle\">\n");
    document.write("<param name=\"movie\" value=\""+swf+"\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#FFFFFF\" /><param name=wmode value=\"transparent\">\n");
    document.write("<embed src=\""+swf+"\" width=\""+width+"\" height=\""+height+"\" align=\"middle\" quality=\"high\" bgcolor=\"#FFFFFF\" wmode=\"transparent\" name=\"skin_navigation\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n");
    document.write("</object>\n");
}

function getFlash(swf, width, height)
{
	var flashLink = "";
    flashLink+="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,24,0\" width=\""+width+"\" height=\""+height+"\" align=\"middle\">\n";
    flashLink+="<param name=\"movie\" value=\""+swf+"\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#FFFFFF\" /><param name=wmode value=\"transparent\">\n";
    flashLink+="<embed src=\""+swf+"\" width=\""+width+"\" height=\""+height+"\" align=\"middle\" quality=\"high\" bgcolor=\"#FFFFFF\" wmode=\"transparent\" name=\"skin_navigation\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
    flashLink+="</object>\n";
    return flashLink;
}

function getImage(src, width, height)
{
	var imageLink = "<img src=\""+src+"\" height="+height+"  width="+width+" border=0 align=absmiddle>";
    return imageLink;
}
function divLeft(el)
{
	return el.style.left;
}

function divTop(el)
{
	return el.style.top;
}


//-----------------------------------------------------------------------------
//배경을 선택하지못하게 한다.
//openDialog('dialog0','close_btn')
//<div dojoType="dialog" id="dialog0" bgColor="white" bgOpacity="0.5" toggle="fade" toggleDuration="100"></div>
//-----------------------------------------------------------------------------
/*function openDialog(dialogID,closeBTNID1,closeBTNID2){
	try{
		var dlg0 = dojo.widget.byId(dialogID);
		dlg0.setCloseControl($(closeBTNID1));
		dlg0.setCloseControl($(closeBTNID2));

		dlg0.show();
	}catch(ex){;}
}

function openDialogOneClose(dialogID,closeBTNID1){
	try{
		var dlg0 = dojo.widget.byId(dialogID);
		dlg0.setCloseControl($(closeBTNID1));

		dlg0.show();
	}catch(ex){;}
}
//-----------------------------------------------------------------------------
//배경 선택을 다시 할 수 있게한다. 사라지는 시간은 toggleDuration으로 결정된다.
//closeDialog('dialog0')
//<div dojoType="dialog" id="dialog0" bgColor="white" bgOpacity="0.5" toggle="fade" toggleDuration="100"></div>
//-----------------------------------------------------------------------------
function closeDialog(dialogID){
	try{
		var dlg0 = dojo.widget.byId(dialogID);
		dlg0.hide();
	}catch(ex){;}
}*/

/*--------------------------------------------------------------------------------*\
 *  JavaScript framework, version 2.0
 *
 *  Date : 2006. 08. 15.
 *  Copyright 1998-2007 by Vricks Studio All right reserved.
 *  @author Jeff Yang routine@vricks.com
 *  자주 쓰이는 스트링 관련 prototype관련 정리
\*--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------*\
 *  String prototype
\*--------------------------------------------------------------------------------*/
//-----------------------------------------------------------------------------
// 문자의 좌, 우 공백 제거
// @return : String
//-----------------------------------------------------------------------------
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//-----------------------------------------------------------------------------
// 문자의 좌 공백 제거
// @return : String
//-----------------------------------------------------------------------------
String.prototype.ltrim = function() {
    return this.replace(/(^\s*)/, "");
}
//-----------------------------------------------------------------------------
// 문자의 우 공백 제거
// @return : String
//-----------------------------------------------------------------------------
String.prototype.rtrim = function() {
    return this.replace(/(\s*$)/, "");
}
//-----------------------------------------------------------------------------
// 문자열의 byte 길이 반환
// @return : int
//-----------------------------------------------------------------------------
String.prototype.byte = function() {
    var cnt = 0;
    for (var i = 0; i < this.length; i++) {
        if (this.charCodeAt(i) > 127)
            cnt += 3;
        else
            cnt++;
    }
    return cnt;
}
//-----------------------------------------------------------------------------
// 정수형으로 변환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.int = function() {
    if(!isNaN(this)) {
        return parseInt(this);
    }
    else {
        return null;
    }
}
//-----------------------------------------------------------------------------
// 숫자만 가져 오기
// @return : String
//-----------------------------------------------------------------------------
String.prototype.num = function() {
    return (this.trim().replace(/[^0-9]/g, ""));
}
//-----------------------------------------------------------------------------
// 숫자에 3자리마다 , 를 찍어서 반환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.money = function() {
    var num = this.trim();
    while((/(-?[0-9]+)([0-9]{3})/).test(num)) {
        num = num.replace((/(-?[0-9]+)([0-9]{3})/), "$1,$2");
    }
    return num;
}
//-----------------------------------------------------------------------------
// 숫자의 자리수(cnt)에 맞도록 반환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.digits = function(cnt) {
    var digit = "";
    if (this.length < cnt) {
        for(var i = 0; i < cnt - this.length; i++) {
            digit += "0";
        }
    }
    return digit + this;
}
//-----------------------------------------------------------------------------
// " -> &#34; ' -> &#39;로 바꾸어서 반환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.quota = function() {
    return this.replace(/"/g, "&#34;").replace(/'/g, "&#39;");
}
//-----------------------------------------------------------------------------
// 파일 확장자만 가져오기
// @return : String
//-----------------------------------------------------------------------------
String.prototype.ext = function() {
    return (this.indexOf(".") < 0) ? 10 : 8;
}
//-----------------------------------------------------------------------------
// URL에서 파라메터 제거한 순수한 url 얻기
// @return : String
//-----------------------------------------------------------------------------
String.prototype.uri = function() {
    var arr = this.split("?");
    arr = arr[0].split("#");
    return arr[0];
}

/*---------------------------------------------------------------------------------*\
 *  각종 체크 함수들
\*---------------------------------------------------------------------------------*/
//-----------------------------------------------------------------------------
// 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.
// @return : String
//-----------------------------------------------------------------------------
String.prototype.meta = function() {
    var str = this;
    var result = ""
    for(var i = 0; i < str.length; i++) {
        if((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/).test(str.charAt(i))) {
            result += str.charAt(i).replace((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/), "\\$1");
        }
        else {
            result += str.charAt(i);
        }
    }
    return result;
}
//-----------------------------------------------------------------------------
// 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.
// @return : String
//-----------------------------------------------------------------------------
String.prototype.remove = function(pattern) {
    return (pattern == null) ? this : eval("this.replace(/[" + pattern.meta() + "]/g, \"\")");
}
//-----------------------------------------------------------------------------
// 최소 최대 길이인지 검증
// str.isLength(min [,max])
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isLength = function() {
    var min = arguments[0];
    var max = arguments[1] ? arguments[1] : null;
    var success = true;
    if(this.length < min) {
        success = false;
    }
    if(max && this.length > max) {
        success = false;
    }
    return success;
}
//-----------------------------------------------------------------------------
// 최소 최대 바이트인지 검증
// str.isByteLength(min [,max])
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isByteLength = function() {
    var min = arguments[0];
    var max = arguments[1] ? arguments[1] : null;
    var success = true;
    if(this.byte() < min) {
        success = false;
    }
    if(max && this.byte() > max) {
        success = false;
    }
    return success;
}
//-----------------------------------------------------------------------------
// 공백이나 널인지 확인
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isBlank = function() {
    var str = this.trim();
    for(var i = 0; i < str.length; i++) {
        if ((str.charAt(i) != "\t") && (str.charAt(i) != "\n") && (str.charAt(i)!="\r")) {
            return false;
        }
    }
    return true;
}
//-----------------------------------------------------------------------------
// 숫자로 구성되어 있는지 학인
// arguments[0] : 허용할 문자셋
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isNum = function() {
    return (/^[0-9]+$/).test(this.remove(arguments[0])) ? true : false;
}
//-----------------------------------------------------------------------------
// 영어만 허용 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isEng = function() {
    return (/^[a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;
}
//-----------------------------------------------------------------------------
// 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isEngNum = function() {
    return (/^[0-9a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;
}
//-----------------------------------------------------------------------------
// 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isNumEng = function() {
    return this.isEngNum(arguments[0]);
}
//-----------------------------------------------------------------------------
// 아이디 체크 영어와 숫자만 체크 첫글자는 영어로 시작 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isUserid = function() {
    return (/^[a-zA-z]{1}[0-9a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;
}
//-----------------------------------------------------------------------------
// 한글 체크 - arguments[0] : 추가 허용할 문자들
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isKor = function() {
    return (/^[가-힣]+$/).test(this.remove(arguments[0])) ? true : false;
}
//-----------------------------------------------------------------------------
// 주민번호 체크 - arguments[0] : 주민번호 구분자
// str.isJumin("-") : 구분자가 '-'일때
// XXXXXX-XXXXXXX
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isJumin = function() {
    var arg = arguments[0] ? arguments[0] : "";
    var jumin = eval("this.match(/[0-9]{2}[01]{1}[0-9]{1}[0123]{1}[0-9]{1}" + arg + "[1234]{1}[0-9]{6}$/)");
    if(jumin == null) {
        return false;
    }
    else {
        jumin = jumin.toString().num().toString();
    }
    // 생년월일 체크
    var birthYY = (parseInt(jumin.charAt(6)) == (1 ||2)) ? "19" : "20";
    birthYY += jumin.substr(0, 2);
    var birthMM = jumin.substr(2, 2) - 1;
    var birthDD = jumin.substr(4, 2);
    var birthDay = new Date(birthYY, birthMM, birthDD);
    if(birthDay.getYear() % 100 != jumin.substr(0,2) || birthDay.getMonth() != birthMM || birthDay.getDate() != birthDD) {
        return false;
    }
    var sum = 0;
    var num = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5]
    var last = parseInt(jumin.charAt(12));
    for(var i = 0; i < 12; i++) {
        sum += parseInt(jumin.charAt(i)) * num[i];
    }
    return ((11 - sum % 11) % 10 == last) ? true : false;
}
//-----------------------------------------------------------------------------
// 외국인 등록번호 체크 - arguments[0] : 등록번호 구분자
// XXXXXX-XXXXXXX
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isForeign = function() {
    var arg = arguments[0] ? arguments[0] : "";
    var jumin = eval("this.match(/[0-9]{2}[01]{1}[0-9]{1}[0123]{1}[0-9]{1}" + arg + "[5678]{1}[0-9]{1}[02468]{1}[0-9]{2}[6789]{1}[0-9]{1}$/)");
    if(jumin == null) {
        return false;
    }
    else {
        jumin = jumin.toString().num().toString();
    }
    // 생년월일 체크
    var birthYY = (parseInt(jumin.charAt(6)) == (5 || 6)) ? "19" : "20";
    birthYY += jumin.substr(0, 2);
    var birthMM = jumin.substr(2, 2) - 1;
    var birthDD = jumin.substr(4, 2);
    var birthDay = new Date(birthYY, birthMM, birthDD);
    if(birthDay.getYear() % 100 != jumin.substr(0,2) || birthDay.getMonth() != birthMM || birthDay.getDate() != birthDD) {
        return false;
    }
    if((parseInt(jumin.charAt(7)) * 10 + parseInt(jumin.charAt(8))) % 2 != 0) {
        return false;
    }
    var sum = 0;
    var num = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5]
    var last = parseInt(jumin.charAt(12));
    for(var i = 0; i < 12; i++) {
        sum += parseInt(jumin.charAt(i)) * num[i];
    }
    return (((11 - sum % 11) % 10) + 2 == last) ? true : false;
}
//-----------------------------------------------------------------------------
// 사업자번호 체크 - arguments[0] : 등록번호 구분자
// XX-XXX-XXXXX
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isBiznum = function() {
    var arg = arguments[0] ? arguments[0] : "";
    var biznum = eval("this.match(/[0-9]{3}" + arg + "[0-9]{2}" + arg + "[0-9]{5}$/)");
    if(biznum == null) {
        return false;
    }
    else {
        biznum = biznum.toString().num().toString();
    }
    var sum = parseInt(biznum.charAt(0));
    var num = [0, 3, 7, 1, 3, 7, 1, 3];
    for(var i = 1; i < 8; i++) sum += (parseInt(biznum.charAt(i)) * num[i]) % 10;
    sum += Math.floor(parseInt(parseInt(biznum.charAt(8))) * 5 / 10);
    sum += (parseInt(biznum.charAt(8)) * 5) % 10 + parseInt(biznum.charAt(9));
    return (sum % 10 == 0) ? true : false;
}
//-----------------------------------------------------------------------------
// 법인 등록번호 체크 - arguments[0] : 등록번호 구분자
// XXXXXX-XXXXXXX
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isCorpnum = function() {
    var arg = arguments[0] ? arguments[0] : "";
    var corpnum = eval("this.match(/[0-9]{6}" + arg + "[0-9]{7}$/)");
    if(corpnum == null) {
        return false;
    }
    else {
        corpnum = corpnum.toString().num().toString();
    }
    var sum = 0;
    var num = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
    var last = parseInt(corpnum.charAt(12));
    for(var i = 0; i < 12; i++) {
        sum += parseInt(corpnum.charAt(i)) * num[i];
    }
    return ((10 - sum % 10) % 10 == last) ? true : false;
}
//-----------------------------------------------------------------------------
// 이메일의 유효성을 체크
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isEmail = function() {
    return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim());
}
//-----------------------------------------------------------------------------
// 전화번호 체크 - arguments[0] : 전화번호 구분자
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isPhone = function() {
    var arg = arguments[0] ? arguments[0] : "";
    return eval("(/(02|0[3-9]{1}[0-9]{1})" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");
}
//-----------------------------------------------------------------------------
// 핸드폰번호 체크 - arguments[0] : 핸드폰 구분자
// @return : boolean
//-----------------------------------------------------------------------------
String.prototype.isMobile = function() {
    var arg = arguments[0] ? arguments[0] : "";
    return eval("(/01[016789]" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");
}

// Div 닫기
function closeDiv(sDiv)
{
	$(sDiv).style.display='none';
}

// Div 보여주기
function openDiv(sDiv)
{
	$(sDiv).show();
}

function byId(id){
	return document.getElementById(id);
}

function byName(name){
	return document.getElementsByName(name);
}

function resetValue(temp)
{
	temp.value = "";
}

function typeValue(temp)
{
	var sText = temp.value;

	if(sText.length < 2)
		temp.value = "스케줄을 입력해 주세요.";
}

// 팝업 띄우기 (가로, 세로, 제목, 주소)
function doPopupWindow(width, height, title, url)
{
  	var winPosLeft = (screen.width - width) / 2;
  	var winPosTop = (screen.height - height) / 2;

	var winOpt = "width=" + width + ",height=" + height + ",top=" + winPosTop + ",left=" + winPosLeft;

	window.open(url, title, winOpt + ",scrollbars=no");
}