/**
@ program			: javascript ui framework;
@ auth				: thhh2¢â 
@ desc				: °øÅëÀÚ¹Ù½ºÅ©¸³Æ®
**/
//¸µÅ©Á¡¼¶¾ø¾Ö±â..
function jsBlur(){ 
	if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=jsBlur; 

var th = { 

	actionfrm : "actionfrm",
	popupfrm : "popupfrm",
	checkfrm : 1, 

	// return object 
	$:function(id) { 
		if (typeof(id) !="object") return document.getElementById(id); 
		else return (id); 
	},
	$$:function(id) {
		if (typeof(id) !="object") return document.getElementsByName(id); 
		else return (id); 
	}, 
	Msg:function(types){
		switch(types){
			case "delete" : 
				return "»èÁ¦ÇÏ½Ã¸é º¹±¸ÇÒ ¼ö ¾ø½À´Ï´Ù.\n»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?";
				break; 
			case "leave" :
				return "Å»ÅðÇÏ½Ã¸é "; 
				break;
			case "error " :
				return "¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù."; 
				break; 
			case "form" :
				return "ÀÌ¹ÌÀü¼ÛÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·ÁÁÖ¼¼¿ä.";
				break; 
		}
	}, 
	
	English:function(){
	}, 

	Go : function(code, subp) {
		if (code!=null) {
			var url = "";
			if (arguments[2]) { url = arguments[2]; } 
			this.Url("/menucode.asp?code="+ code + "&subp="+subp + url, ""); 
//			window.location.href = "/menucode.asp?code="+ code + "&subp="+subp + url; 
		}
	},
	Back:function(){ window.history.go(-1);},
	Url : function(url, t){ 
		if (t=="blank") {
			window.open(url); 
		} else {
			window.location.href=url; 
		}
	},
	Reload : function() {
		window.location.reload();
	},
	Home : function() {
		this.Url("/menucode.asp?code=main&subp=00", ""); 
//		window.location.href="/menucode.asp?code=main&subp=00"; 
	},
	Open : function(url, name, features) {
		if (url) {
//			var contwin ="";
//			var contwin = name; 
//			if (contwin!=null && contwin.closed==false) { contwin.close(); }
			var contwin = window.open(url,name,features);
			if (contwin==null) {
				alert("Â÷´ÜµÈ ÆË¾÷Ã¢À» Çã¿ëÇØÁÖ¼¼¿ä.");
			} else {
				contwin.focus(); 
			}
			
		}
	},
	Close : function() { opener = self;  self.close(); },
	CloseToday : function(popid) { 
		var nowdate = new Date();
		// ¿À´ÃÀÚÁ¤±îÁö¸¸ ¶ç¿ò
		var time = 1440 - (nowdate.getHours()*60+nowdate.getMinutes());
		this.setCookie(popid, "none", time);
		this.Close();
	}, 
	ModalCheck:function(){ if (window.showModalDialog && document.all) return true; else return false; }, 
	Modal : function (url, name, width, height, status) { 
		if (this.ModalCheck()) {
			window.showModalDialog(url, window, "dialogWidth:"+ width +"px ; dialogHeight:"+ height +"px;status:"+ status +";"); 
		} else {
			this.Open(url, name, "width="+ width +",height="+ height +", status="+status+",resizable=no,modal=yes,dependent=yes"); 
//			window.open(url, name, "width="+ width +",height="+ height +", status="+status+",resizable=no,modal=yes,dependent=yes");
		}		
	},
	ModalResize : function() {
		if (this.ModalCheck()) {
			var dw = window.dialogWidth;
			while (isNaN(dw))  {
			  dw = dw.substr(0,dw.length-1);
			}

			difw = dw - document.body.clientWidth;
			window.dialogWidth = document.body.scrollWidth+difw+'px';

			var dh = window.dialogHeight;
			while (isNaN(dh)) {
			  dh = dh.substr(0,dh.length-1);
			}
			difh = dh - document.body.clientHeight;
			window.dialogHeight = document.body.scrollHeight+difh+'px';
//			window.resizeTo(100,100);
		} else {
//			window.resizeTo(document.body.clientWidth, document.body.clientHeight); 
		}


	},
	Error : function (e) {alert(e+"\n"+e.description); }, 
	Regular : function(chk, frm, msg) {
		var strValue = frm.value;
		var blnExp = false; 
		switch (chk) {
			case "id" : 
				if (frm.value.match(/[A-Za-z0-9]{4,15}\w*/g)!=strValue){break;}
				blnExp = true;
			case "email" :
				if (frm.value.match(/[\w\-]+\@[\w\-]+(\.[\w\-]+)+/g)!=strValue){break;}
				blnExp = true;
			case "number" :
				if (frm.value.match(/\d+/g)!=strValue){ break;}
				blnExp = true;
			case "phone" :
				if (frm.value.match(/[0-9]{2,3}\-[0-9]{3,4}\-[0-9]{4}/g)!=strValue){break;}
				blnExp = true;
			case "mphone" :		
				if (frm.value.match(/01[016789]\-[0-9]{3,4}\-[0-9]{4}/g)!=strValue){ break;}
				blnExp = true;
			case "date" :
				if (frm.value.match(/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/g)!=strValue){break;}
				blnExp = true;
			case "homepage" :
				if (frm.value.match(/\w+:\/\/[^#]*/g)!=strValue){		break;}
				blnExp = true;
			case "checked" : 
				if (typeof(frm)=="object"){
					if (typeof(frm.length)=="undefined"){
						if (frm.checked) { blnExp = true; }
					}
					else{
						for (i = 0 ; i < frm.length; i++){
							if (frm[i].checked){	blnExp = true;		}
						}
					}
				}
				
				break;
			case "selected" :
				if (frm.value==""){ break ;}
				blnExp = true;
				
			case "idn1" :
				if (frm.value.match(/[0-9]{6}/g)!=strValue){ break; }
				blnExp = true;
			case "idn2" :
				if (frm.value.match(/[0-9]{7}/g)!=strValue){break; }
				blnExp = true;
			case "company" :
				if (frm.value.match(/[0-9]{3}\-[0-9]{2}\-[0-9]{5}/g)!=strValue){break;}
				blnExp = true;	
			default : //°ø¹éÃ¼Å©;
				if (frm.value.match(/\S/)==null){break;}
				blnExp = true;
		}
		
		if (!blnExp){ if (msg) alert(msg);if ((chk!="checked")&&(chk!="selected")){frm.focus();};	return false;	}
		else{return true;}
	},

	// get operating system;
	getOs : function() { return window.navigator.appVersion.split(";")[2];}, 
	// get brower version; 
	getBrower : function(){ return navigator.userAgent.toUpperCase();},
	getXY:function(el) {
		var parent = null;
		var pos = [];
		var box;

		if (el.getBoundingClientRect) { // IE
			box = el.getBoundingClientRect();
			var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
			var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;

			return [box.left + scrollLeft, box.top + scrollTop];
		} else if (document.getBoxObjectFor) { // gecko
			box = document.getBoxObjectFor(el);
			pos = [box.x, box.y];
			return pos; 
		} else { // safari/opera
			pos = [el.offsetLeft, el.offsetTop];
			parent = el.offsetParent;
			if (parent != el) {
				while (parent) {
				   pos[0] += parent.offsetLeft;
				   pos[1] += parent.offsetTop;
				   parent = parent.offsetParent;
				}
			}

			// opera & (safari absolute) incorrectly account for body offsetTop
			var ua = navigator.userAgent.toLowerCase();
			if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && this.getStyle(el, 'position') == 'absolute' ) ) {
				pos[1] -= document.body.offsetTop;
			}
			return pos; 
		}
	},
	isIE:function(){
		var n = navigator.appName; 
		if (n=="Microsoft Internet Explorer") { return true; } else { return false; }
	},
	ShowHide : function(o, action) { o.style.display=action; }, 
	ShowHideyn : function(o) { return (o.style.display=="none") ? false : true; }, 
	ShowHideArray : function(o, num) {
		try {
			var obj = th.$$(o); 

			if (obj.length==null) {
				(this.ShowHideyn(obj)) ? this.ShowHide(obj, "none") : this.ShowHide(obj,"block"); 
			} else {
				for (i=0; i<obj.length; i++) {
					if (i==num) {
						(this.ShowHideyn(obj[num])) ? this.ShowHide(obj[num], "none") : this.ShowHide(obj[num],"block"); 
					} else {
						this.ShowHide(obj[i], "none"); 
					}
				}
			}
		}
		catch (e) {
			this.Error(e); 
		}
	},

	Toggle : function(id) { 
		this.$(id).style.display=(this.getStyle(this.$(id), "display")=="none") ? "inline":"none"; 
	},
	
	getStyle : function(obj, att) {
		return obj.style[att]; 
	},

	Trim : function(str){
		return str.replace(/S/g, ""); 
	}, 


	Flash : function(url, width, height, strparam) {
		var wmode = "transparent";
		var id = "";
		var quality = "high";
		var menu = "false";
		var allowScriptAccess = "sameDomain";

		var flash='';
		flash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ width +'" height="'+ height +'"> ';
		flash += '<param name="movie" value="'+ url +'">';
		flash += '<param name="quality" value="'+ quality +'">';
		flash += '<param name="menu" value="'+ menu +'">';
		flash += '<param name="wmode" value="'+ wmode +'">';
		flash += '<param name="FlashVars" value="'+ strparam +'">';
		flash += '<embed src="'+ url +'" quality="'+ quality +'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'" wmode="transparent"></embed> ';
		flash += '</object>';

		document.write(flash);
	}, 
	
	Embed : function(url, width, height) {
		var object='';
		object='<embed src="'+url+'" width="'+width+'" height="'+height+'" align="baseline" border="0" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=media&sba=plugin&" name="MediaPlayer" showcontrols="1" showpositioncontrols="0" showaudiocontrols="1" showtracker="1" showdisplay="0" showstatusbar="1" autosize="0" showgotobar="0" showcaptioning="0" autostart="1" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" enablecontextmenu="1" clicktoplay="0" invokeurls="1" defaultframe="datawindow"></embed>';
		document.write(object); 
	}, 


	ImageResize:function(imgid, sizew) {
		var img = document.images(imgid); 
		if (img) {
			if (img.length==null){
				imgwidth = img.width ; imgheight = img.height;
				if (sizew < imgwidth){
					imgW = sizew; 
					imgH = parseInt((sizew/imgwidth) * imgheight);
				}
				else{
					imgW = imgwidth ;
					imgH = imgheight;
				}
				img.width = imgW;
				img.height = imgH;		
			}
			else{
				for (i = 0 ; i < img.length; i++) {
					imgwidth = img[i].width ; imgheight = img[i].height;
					if (sizew < imgwidth){
						imgW = sizew; 
						imgH = parseInt((sizew/imgwidth) * imgheight);
					}
					else{
						imgW = imgwidth ;
						imgH = imgheight;
					}
					img[i].width = imgW;
					img[i].height = imgH;
				}
			}
		}
	},

	
	setCookie : function(name, value, expiredays) {
		var todayDate = new Date();
		todayDate.setTime(todayDate.getTime() + (1000*60*parseInt(expiredays)) );
		document.cookie = name +"="+escape(value)+";path=/; expires=" + todayDate.toGMTString() + ";" ;			
	},

	getCookie : function(name) {
		var nameOfCookie = name + "="; 
		var x = 0; 
		while ( x <= document.cookie.length ) { 
				 var y = (x+nameOfCookie.length); 
				 if ( document.cookie.substring( x, y ) == nameOfCookie ) { 
					   if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 ) 
								endOfCookie = document.cookie.length; 
					   return unescape( document.cookie.substring( y, endOfCookie ) ); 
				 } 
				 x = document.cookie.indexOf( " ", x ) + 1; 
				 if ( x == 0 ) 
					   break; 
		} 
		return ""; 
	},
	

	// check
	CheckAll2 : function(f) {
		var chkvalue = document.all.item(f);

		if (chkvalue) {
			var chklen = chkvalue.length;
		
			if (chklen==null || chklen==""){
				if(chkvalue.checked) { chkvalue.checked=false; }
				else { 
					if (chkvalue.disabled==false) { chkvalue.checked=true; } 
				}
			}
			else{
				for(i=0;i<chklen;i++){
					if(chkvalue[i].type=='checkbox'){
						if(chkvalue[i].checked) { chkvalue[i].checked=false; }
						else {
							if (chkvalue[i].disabled==false) { chkvalue[i].checked=true; } 
							// chkvalue[i].checked=true; 
						}
					}
				}
			}
		}
	},
	
	// check
	CheckAll : function(f) {
		var chkvalue = document.all.item(f);
		var allCheck = document.all.item('allCheck');

		if (chkvalue) {
			var chklen = chkvalue.length;
		
			if (chklen==null || chklen==""){
				if(allCheck.checked) { chkvalue.checked=false; }
				else { 
					if (allCheck.disabled==false) { chkvalue.checked=true; } 
				}
			}
			else{
				for(i=0;i<chklen;i++){
					if(chkvalue[i].type=='checkbox'){
						if(allCheck.checked) { chkvalue[i].checked=true; }
						else {
							if (allCheck.disabled==false) { chkvalue[i].checked=false; } 
							// chkvalue[i].checked=true; 
						}
					}
				}
			}
		}
	},

	// checkbox value; 
	CheckValue : function(f, msg) {
		var v="" , msg ;
		var chkvalue = document.all.item(f);
		var chklen = chkvalue.length;
		
		if (chklen==null || chklen==""){
			if (chkvalue.checked){
				v=chkvalue.value+",";
			}
		}
		else{
			for(i=0;i<chklen;i++){
				if(chkvalue[i].type=='checkbox'){
					if(chkvalue[i].checked) { 
						v=chkvalue[i].value+","+v
					}
				} else {
					v = chkvalue[i].value +  "," + v
				}
			}
		}
		
		if (v==""){	alert(msg); return false;}
		else{return v;}
	}, 

	// checked value; 
	CheckedValue:function(frm) {
		try { 
			var returnvalue;

			if (typeof(frm)=="object"){
				if (typeof(frm.length)=="undefined"){
					if (frm.checked) { returnvalue = frm.value; }

				}
				else{
					for (i = 0 ; i < frm.length; i++){
						if (frm[i].checked){ returnvalue = frm[i].value; }
					}
				}
			}

			return returnvalue;

		}
		catch (e) {
			this.Error(e);
		}
	}, 

	Lower:function(s) { return s.toLowerCase(); }, 
	Upper:function(s) { return s.toUpperCase(); },

	ResizeFrame:function(name){
		try {
			var frame = parent.th.$(name); 
			if (frame) {
				frame.style.height = 0; 
				frame.style.height = document.body.scrollHeight;
			}
		}
		catch (e) { this.Error(e); }

	},
	ByteCheck:function(input,id,length){
		var obj = this.$(id); 
		var j=0;
		for(var i=0;i<input.value.length;i++) {
			val=escape(input.value.charAt(i)).length;
			if(val== 6) { j++; }
			else{ j++; }
		}
		
		obj.innerHTML = j;
		if(j > length) {
			alert(length+'ÀÚ ÀÌÇÏ·Î ÇØÁÖ¼¼¿ä!   '); return false;
		} 
		else {  return true;  }
	}, 
	
	Zoom:function(url) {
		this.Open('/common/zoom.asp?name='+url,'','directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=400,height=400');
	}, 
	ContentsDivide:function(f, strValue) {
		var limit = 102399; 
		var temp = ""; 
		while (strValue.length > 0 ) {
			temp = document.createElement("TEXTAREA"); 
			temp.name = "contents1";
			temp.value = strValue.substr(0, limit); 
			f.appendChild(temp); 
			strValue = strValue.substr(limit); 
		}

		temp = document.createElement("TEXTAREA");
		temp.name = "contents1"; 
		temp.value = strValue; 
		f.appendChild(temp); 
	},
	
	Leftmenu:function(code){
		if (code > 0){
			var obj_img = document.all["leftnavi"+code] ;
			var img_name = obj_img.name;
			obj_img.src = "/images/"+imgfolder+"/"+img_name+"_over_"+ code +".gif";
			this.LeftmenuTr(code);
		}
	},
	
	LeftmenuTr:function(code){
		if (code > 0){
			var obj_tr = document.all["leftnavi"+ code +"_tr"]; 
			if (typeof(obj_tr)=="object") {
				if (obj_tr.style.display=="none") {
					obj_tr.style.display = "block";
				}
			}
		}
	},
	
	LeftmenuSub:function(code,subp){
		try {
			if (code > 0){
				var obj_img = document.all["leftnavi"+code+subp] ;
				var img_name = obj_img.name;
				obj_img.src = "/images/"+imgfolder+"/"+img_name+"_over_"+ subp +".gif";
			}			
		}
		catch (e) {
		}
	},




	ChangeFocus:function(val,len,nextfrm){
		if( val.length == len) nextfrm.focus();
	},

	Onlynum:function(){
		if((event.keyCode<48)||(event.keyCode>57))
		event.returnValue=false;
	},
	
	Nokey:function(evt){
		try {
			if (window.event) { event.returnValue=false; } else { evt.preventDefault(); } 
		}
		catch (e) {
			th.Error(e);
		}
	},
	

	GoLogin:function(){
		var strparameter = window.location.search; 
		if (strparameter.length>0) {
			if (strparameter.indexOf("returl" , 0) > 0){
				window.location.reload();
			}
			else {
				window.location.href="/v1/etc/login.asp?returl="+escape(window.location.pathname+window.location.search);
			}
		}
		else {
			window.location.href="/v1/etc/login.asp?returl="+escape(window.location.pathname+window.location.search);
		}

		return;
	},
	GoLogout:function(){
		var strparameter = window.location.search; 
		var tmp = ""; 
		if (strparameter.length>0) {
			tmp = escape(window.location.pathname+window.location.search);
		} 
		window.location.href="/common/logout.asp?returl="+tmp;
	},
	NeedLogin:function(){
		alert("·Î±×ÀÎÀÌ ÇÊ¿äÇÑ ¼­ºñ½º ÀÔ´Ï´Ù.\n·Î±×ÀÎ ÈÄ ÀÌ¿ëÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.");
		window.location.href="/v1/etc/login.asp?returl="+escape(window.location.pathname+window.location.search);
		return;
	}, 
	
	// ³¯Â¥ºñ±³, ¾ÕµÚ
	IsDate:function(sdate,edate){
		if (sdate.indexOf("-")>0) {
			split_sdate = sdate.split("-"); 
			syear = split_sdate[0]; 
			smonth = Number(split_sdate[1]); 
			sday = Number(split_sdate[2]); 
		} 
		if (edate.indexOf("-")>0) {
			split_edate = edate.split("-"); 
			eyear = split_edate[0]; 
			emonth = Number(split_edate[1]); 
			eday = Number(split_edate[2]); 
		} 

		var start_date = new Date(syear,smonth-1,sday);
		var end_date = new Date(eyear,emonth-1,eday);

		var start_date = new Date(Date.parse(start_date));
		var end_date = new Date(Date.parse(end_date));
		
		if (start_date > end_date){
			return false;
		}
		else {
			return true;
		}
	},

	
	GoPrint:function(){
		var obj = th.$("printHTML");
		if (obj!=null){
			this.Open('/popup/popup_print.asp','printpopup','width=743, height=550,scrollbars=yes');
		}
		else{ alert("ÀÎ¼âÇÒ ³»¿ëÀÌ ¾ø½À´Ï´Ù."); }
	},
	StatusBar:function(){
		window.status = "¿Ï·á";
		return true;
	},

	Matches:function(re, text) {
		var results = new Array() ;
		var arr = re.exec(text)
		while(arr != null) {
			var match = new this.Match() ;
			match.Text = arr[0] ;
			for (var i=1; i<arr.length; i++) {
				match.Groups[i-1] = arr[i] ;
			}
			results[results.length] = match ;
			arr = re.exec(text) ; 
		}
		return results ;
	},
	Match:function(){
		this.Text = null ;
		this.Groups = new Array() ;
	},
	ReadOnly:function(frm, color) {
		try {
			var f = document.forms[frm];
			for (var i=0; i<f.length; i++) {
				if (typeof(f[i])=="object") {
					if (f[i].type=="text" || f[i].type=="select-one" || f[i].type=="textarea" ) {
						f[i].readOnly = true; 
						f[i].style.backgroundColor=color; 
					} 
					if (f[i].type=="radio" || f[i].type=="select-one") {
						f[i].disabled = true; 
					} 
				}
			}

		}
		catch (e) {
			th.Error(e); 
		}
	}
};




if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN); 
document.onmouseover = th.StatusBar;
document.onmouseout = th.StatusBar;
document.onclick = th.StatusBar;
document.onmousedown = th.StatusBar;

//DESIGN¿¡ ÇÊ¿äÇÑ ½ºÅ©¸³Æ®
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}