/*
¡Ú Blibrary Global WebScript Library - zProject [Cross-Browser DHTML Javascript Library]

¡Ú Test Browser : IE 4.0 + / NS 4.7 + / Mozilla 0.9 + /  Opera 7.0 +
 */


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

¡Ú SCRIPT ±âº» ¸ðµâ

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

/* ********************************
	[±âÅ¸1]ºê¶ó¿ìÁ® ÆÇº°
******************************** */
function BrowserInit() {
	if (document.layers) {
		// Nets...
		Browser=1;
	} else if (document.all) {
		// Ex 4.0
		Browser=2;
	} else if (document.getElementById) {
		// Ex 5.0 < ~
		Browser=3;
	}
	return Browser;
}
var zBrowser=BrowserInit(); // ºê¶ó¿ìÁ® ½ÃÀÛ

function Id(id) {
	if (zBrowser==1) {
		_return=document.id;
	} else if (zBrowser==2) {
		_return=eval("document.all."+id);
	} else if (zBrowser==3) {
		_return=document.getElementById(id);
	}
	return _return;
}

function IdStyle(id) {
	if (zBrowser==1) {
		_return=document.id;
	} else if (zBrowser==2) {
		_return=eval("document.all."+id+".style");
	} else if (zBrowser==3) {
		_return=document.getElementById(id).style;
	}
	return _return;
}

/* ********************************
	[±âÅ¸1]ÄíÅ°ÀúÀå
******************************** */
function SetCookie(name, value, expiredays,path) { 
	var todayDate = new Date(); 
	todayDate.setDate(todayDate.getDate() + expiredays); 
	document.cookie = name + "=" + escape(value) + "; path="+path+"; expires=" + todayDate.toGMTString() + ";" 
} 
/* ********************************
	[±âÅ¸1]ÄíÅ°Ãâ·Â
******************************** */
function GetCookie(name) {
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1)
			end = dc.length;
			return unescape(dc.substring(begin, end));
		}
	}
	return "";
}

/* ********************************
	[±âÅ¸1]URL Parsing
******************************** */
// EX) 
// var q=new Array();
// q=GJ_UrlParsing('http://ilzzang.net/index.html?db=ilzzang&a1=0&a2=cc'); 
// q[db] = 'ilzzang';
// q[a1] = '0';
// q[a2] = 'cc';
String.prototype.UrlParsing = function(url) {
	url = (this != window) ? this : url;
	var	_SplitUrl=url.split('?');
	var	_SplitQuery=_SplitUrl[1].split('&');
	var _return=new Array();

	for (i=0;i<_SplitQuery.length;i++){
		_key_value= _SplitQuery[i].split('=');
		_key=_key_value[0];
		_value=_key_value[1];
		_return[_key]=_value;
	}
	return _return;
}

function UrlParsing(url) {
	var	_SplitUrl=url.split('?');
	var	_SplitQuery=_SplitUrl[1].split('&');
	var _return=new Array();

	for (i=0;i<_SplitQuery.length;i++){
		_key_value= _SplitQuery[i].split('=');
		_key=_key_value[0];
		_value=_key_value[1];
		_return[_key]=_value;
	}
	return _return;
}

function GetImageSize(imgsrc) {
	var _img=new Image();
	var _return=new Array();
	_img.src=imgsrc;
	_return[0]=_img.width;
	_return[1]=_img.height;
	return _return;
}

/* ********************************
	[±âÅ¸1]»õÃ¢ ¶Ù¿ì±â
******************************** */
function OpenWindow(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';

	if (left=='' || top==''){
		window.open(url, name, 'width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
	}else{
		window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
	}
}

/* ********************************
	[Æû]ÆûÃ¼Å©
******************************** */
// EX) 
// var q=GJ_ValueCheck('CheckNum','x12345')
// q=false;

/* - ¼ýÀÚ - */
var CheckNum =/^[0-9]+$/; 
/* - ¾ÆÀÌµð - */
var CheckId = /^[a-zA-Z]{1}[a-zA-Z0-9_-]{4,15}$/; 
/* - ÀÌ¸ÞÀÏ - */
var CheckMail =/^[_a-zA-Z0-9-]+@[._a-zA-Z0-9-]+.[a-zA-Z]+$/; 
/* - È¨ÆäÀÌÁö - */
var CheckHomepage =/^http:\/\/[.a-zA-Z0-9-]+.[a-zA-Z]+$/; 
/* - URL - */
var CheckHost =/^[a-zA-Z-]+$/; 
/* - ¿ÀÁ÷ÇÑ±Û - */
var CheckHangulOnly =/^[°¡-ÆR]*$/; 
/* - ÇÑ±Û&¿µ¹® - */
var CheckHangulEng =/[°¡-ÆRa-zA-Z]/;
/* - ¿ÀÁ÷ ¿µ¹® - */
var CheckEng =/^[a-zA-Z]+$/;
/* - ÆÄÀÏ ¿µ¹® - */
var CheckFile =/^[._a-zA-Z0-9-]+$/;


String.prototype.ValueCheck = function(option,cvalue) {
	cvalue = (this != window) ? this : cvalue;
	patten = eval(option);
	if (!patten.test(cvalue)) return false; else return true;
}
function ValueCheck(option,cvalue) {patten = eval(option);if (!patten.test(cvalue)) {return false;}}
function FormCheck(e) {
	var i,t=0;
	for (i=0;i<e.elements.length; i++) {
		if (e.elements[i].getAttribute("required") != null) { 
			if (e.elements[i].type == "text" || e.elements[i].type == "password" || e.elements[i].type == "textarea"){ 
				if (2 > e.elements[i].value.length) {
					if(e.elements[i].errmsg_required) errmsg=e.elements[i].errmsg_required; else errmsg=e.elements[i].errmsg;
					alert(errmsg);
					e.elements[i].focus();
					return false;
				}
			} // end if text 
		}
		if (e.elements[i].getAttribute("option") != null && e.elements[i].value.length > 0){ 
			if(ValueCheck(e.elements[i].option,e.elements[i].value)==false){
				if(e.elements[i].errmsg_option) {
					errmsg=e.elements[i].errmsg_option; 
					alert (errmsg);
				}else{
					errmsg=e.elements[i].errmsg;
					alert (errmsg+" Ç×¸ñÀÇ Çü½ÄÀÌ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù");
				}
				e.elements[i].focus();
				return false;
			}
		} // end if option
	} // end for
}
/* ********************************
	[¼öÄ¡] 3ÀÚ¸®¾¿,...
******************************** */
String.prototype.NumFormat = function(nvalue) {
	nvalue = (this != window) ? this : nvalue;
	var tmp = '',number = '',cutlen = 3, comma = ',', i;
	len = nvalue.length;
	mod = (len % cutlen);
	k = cutlen - mod;
	for (i=0; i<nvalue.length; i++) {
		number = number + nvalue.charAt(i);
		if (i < nvalue.length - 1) {
			k++;
			if ((k % cutlen) == 0) {number = number + comma;k = 0;}
		}
	}
	return number;
}
/*
function GJ_NumFormat(nvalue) {
	var tmp = '',number = '',cutlen = 3, comma = ',', i;
	len = nvalue.length;
	mod = (len % cutlen);
	k = cutlen - mod;
	for (i=0; i<nvalue.length; i++) {
		number = number + nvalue.charAt(i);
		if (i < nvalue.length - 1) {
			k++;
			if ((k % cutlen) == 0) {number = number + comma;k = 0;}
		}
	}
	return number;
}

*/


/* ********************************
	[Æû] ÇöÀç Æ÷Ä¿½º¿¡ »öÄ¥ÇÏ±â
******************************** */
String.prototype.NumFormat = function(nvalue) {
	nvalue = (this != window) ? this : nvalue;
	var tmp = '',number = '',cutlen = 3, comma = ',', i;
	len = nvalue.length;
	mod = (len % cutlen);
	k = cutlen - mod;
	for (i=0; i<nvalue.length; i++) {
		number = number + nvalue.charAt(i);
		if (i < nvalue.length - 1) {
			k++;
			if ((k % cutlen) == 0) {number = number + comma;k = 0;}
		}
	}
	return number;
}


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

¡Ú SCRIPT GLobal ÀÀ¿ë1

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

/* ********************************
	IFRAME AUTO SIZING 
******************************** */
// reSize´Â ´Ã¾î³ª¾ßÇÒ Main°Ý ÆäÀÌÁöÀÇ ÇØ´ç IFRAME 
// EX) onresize="reSize('leftmenu')"
function ReSize(name) {
	ename=eval(name);
	var ParentFrame=ename.document.body;
	var ContentFrame=document.all[name];
	ContentFrame.style.height = ParentFrame.scrollHeight + (ParentFrame.offsetHeight - ParentFrame.clientHeight);
	ContentFrame.style.width = ParentFrame.scrollWidth + (ParentFrame.offsetWidth - ParentFrame.clientWidth);
}

// setTimeReSize ÇØ´ç ÄÁÅÙÃ÷ 
// EX) <body onload="setTimeReSize('leftmenu',1)">
function SetTimeReSize(name,time) {
	setTimeout("parent.ReSize('"+name+"')",time);
}

/* ********************************
*  ÆÄÀÏ »çÀÌÁî º¯È¯
******************************** */
String.prototype.NumFixed = function(n,nvalue) {
	nvalue = (this != window) ? this : nvalue;
	var s=String(nvalue).split('.');
	var sosu=String(s[1]).split('');
	var sosujum="";
	if(sosu.length<n) n=sosu.length;
	for(i=0;i<n;i++) {sosujum=sosujum+sosu[i];}
	if(s[1])	return s[0]+"."+sosujum; else 	return nvalue;
}
function ByteToMb (size) {
	if(!size || size==0) { return "0 Byte";}else{
		if(size<1024) return size+" Byte";
		else if(size>1024 && size<1024*1024) return new String(size/1024).NumFixed(1)+" KB";
		else return new String(size/(1024*1024)).NumFixed(1)+" MB";
	}
}	
/* ********************************
	ºê¶ó¿ìÀú¸¦ ¸ð´ÏÀÇ Áß°£¿¡ ¹èÄ¡ 
******************************** */
function BrowserAlignCenter() {
	if (zBrowser==1) {
		var sinist = screen.width / 2 - outerWidth / 2;
		var toppo = screen.height / 2 - outerHeight / 2;
	}else{
		var sinist = screen.width / 2 - document.body.offsetWidth / 2;
		var toppo = -75 + screen.height / 2 - document.body.offsetHeight / 2;
	}

	self.moveTo(sinist, toppo);
}
 
/* ********************************
	»õÃ¢ ¶Ù¿ì±â
******************************** */
function GJ_NewWindow(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';

	if (left=='' || top==''){window.open(url, name, 'width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);}
	else{window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);}
} 

/* ********************************
	ÆË¾÷ ¶Ù¿ì±â
******************************** */
function Popup(url,left,top,width,height,flag) {
	if (flag == 0) GJ_NewWindow('',url,left,top,width,height,0,0,0,0,0)
	else if (flag == 1) GJ_NewWindow('',url,left,top,width,height,0,0,0,1,0)
}

/* ********************************
	ÀÌ¹ÌÁö »çÀÌÁî °íÁ¤ÇÏ±â
******************************** */
function LargeImgSizeFix(domain,width_limit_size) {
	var _img=new Image();
	ImgElements=document.getElementsByTagName("img");
	for(var i=0;i<ImgElements.length;i++) {
		_size=GetImageSize(ImgElements[i].src);
		image_width_size=_size[0];
		if(ImgElements[i].src.indexOf(domain)>-1 && image_width_size > width_limit_size) {
			ImgElements[i].width=width_limit_size;
		}
	}
}

/* ********************************
	¿µ¿ª ÇÏÀÌ¶óÀÌÆ®
******************************** */
// <span class='s1'><span class='s2'>~~~~~TEXT ¿µ¿ª ~~~~~~ </span></sapn>
// <script>GJ_HiliteStyle('s1','s2',"precincts","<b>","</b>");</script>
function HiliteStyle(poss_start,poss_end,keyword,styleChange1,styleChange2) {
	var poss1 = document.body.createTextRange();
	var poss2 = document.body.createTextRange();
	array_keyword = keyword.split("  ");

	for (i=0;i<array_keyword.length;i++) {
		poss1.moveToElementText(document.all(poss_start));
		poss2.moveToElementText(document.all(poss_end));
		if (array_keyword[i] != "") {
			while (poss1.findText(array_keyword[i]) && poss2.inRange(poss1) != false) poss1.pasteHTML(styleChange1+array_keyword[i]+styleChange2);
		}
	}
}

/* ********************************
* ¿µ¿ª & º¹»ç
******************************** */
function SelectPartCopy(s){
	var doc = document.body.createTextRange();
	var s = document.getElementById(s);
	doc.moveToElementText(s);
	doc.select();
	doc.execCommand('copy');
	alert('Å¬¸³º¸µå¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù.');
}
function SelectContentsCopy(s) {
	result = window.clipboardData.setData("Text",document.getElementById(s).innerText);
	if (result) alert('Å¬¸³º¸µå¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù.');
}
function InputFormCopy(formname,name,msg){
	var doc = eval("document."+formname+"."+name+".createTextRange();");
	eval("document."+formname+"."+name+".select();");
	doc.execCommand('copy');
	if(msg) alert(msg);
}

/* ********************************
* Áñ°ÜÃ£±â Ãß°¡
******************************** */
function AddFavorite(url,contents){if (Ie && url) window.external.AddFavorite(url, unescape(contents));}

/* ********************************
	[Æû] 
******************************** */
// EX)
// <form name=babo>
// <input type=text name=#1 chgColor=black chgFont=white><br>
// <input type=text name=#2 chgColor=red chgFont=white><br>
// <input type=text name=#3 chgColor=yellow chgFont=white><br>
// </form>
// <script>GJA_InputBoxFocusColor('babo','#CCCCCC','red');</script>
function InputBoxFocusColor(name,bgcolor,fontcolor) {
	var _FormEle = document.forms[name].elements;
	for (i=0;i<_FormEle.length;i++){
			if (_FormEle[i].type == 'text' || _FormEle[i].type == 'textarea') {
					_FormEle[i].onfocus = function() {
						 this.style.backgroundColor=this.chgColor;
						 this.style.color=this.chgFont;
					}
					_FormEle[i].onblur = function() {
						 this.style.backgroundColor=bgcolor;
						 this.style.color=fontcolor;
					}
				_FormEle[i].style.backgroundColor=bgcolor;
			}
	}
}

/* ********************************
* [Æû]Textarea Row ¼ö ±¸ÇÏ±â
******************************** */
function GetTextAreaRowNum(id) {
	var _id = id.createTextRange();
	return _id.boundingHeight/15;
}

/* ********************************
* [Æû]ÀÚµ¿ SELECT
******************************** */
function CategoryLoading(sel, targetstr) {
	var index = sel.selectedIndex;
	if (sel.options[index].value != '') {
		var frameobj;
		if ((frameobj = eval(targetstr)) != null) frameobj.location = sel.options[index].value;  
	}
}


