/**
 * Å¬·¡½º¸í : MyLib()
 * ±â    ´É : Àü¹ÝÀûÀ¸·Î »ç¿ëµÇ´Â ÇÔ¼ö/¸Þ¼­µå
 * ÀÛ ¼º ÀÏ : 2007.05.08, ÀÌÁö¹Ìµð¾î, Á¤¿ø±¤
 *
 */

MyLib = function () {
	this.TopDir = "";
	this.IsChecked = false;

	// °´Ã¼ °¡Á®¿À±â
	this.Object = function (id) {
		if (document.getElementById && document.getElementById(id)) {
			return document.getElementById(id);
		} else if (document.getElementByName && document.getElementByName(id)) {
			return document.getElementByName(id);
		} else if (document.all && document.all(id)) {
			return document.all(id);
		} else if (document.layers && document.layers[id]) {
			return document.layers[id];
		} else {
			return false;
		}
	}

	// Ã¼Å©¹Ú½º ¸ðµÎ¼±ÅÃ
	this.All = function (frm, isobj) {
		if (isobj == true) {
			if (this.IsChecked == false) {
				for (var i = 0; i <= frm; i++) {
					if (this.Object("A_" + i).checked == true) {
						continue;
					} else {
						this.Object("A_" + i).checked = true;
					}
				}

				this.IsChecked = true;
			} else {
				for (var i = 0; i <= frm; i++) {
					if (this.Object("A_" + i).checked == true) {
						this.Object("A_" + i).checked = false;
					} else {
						continue;
					}
				}

				this.IsChecked = false;
			}
			return false;
		} else {
			if (this.IsChecked == false) {
				for (i = 0; i < frm.length; i++) {
					if (frm[i].type == "checkbox") {
						if (frm[i].checked == true) {
							continue;
						} else {
							frm[i].checked = true;
						}
					}
				}

				this.IsChecked = true;
			} else {
				for (i = 0; i < frm.length; i++) {
					if (frm[i].type == "checkbox") {
						if (frm[i].checked == true) {
							frm[i].checked = false;
						} else {
							continue;
						}
					}
				}

				this.IsChecked = false;
			}
		}
	}

	// »õÃ¢¶ç¿ì±â
	this.WinOpen = function (url, wname, width, height, scrl) {
		var winl = (screen.width - width) / 2;
		var wint = (screen.height - height) / 2;

		if (typeof scrl == "undefined") {
			var scroll = "no";
		} else {
			var scroll = scrl;
		}

		return window.open(url, wname, "left=" + winl + ", top=" + wint + ", scrollbars=" + scroll + ", status=yes, resizable=no, width=" + width + ", height=" + height);
	}


	// »õÃ¢¶ç¿ì±â(À§Ä¡Á¶Àý)
	this.WinOpenMove = function (url, wname, width, height, winl, wint, scrl) {
		if (typeof scrl == "undefined") {
			var scroll = "no";
		} else {
			var scroll = scrl;
		}

		return window.open(url, wname, "left=" + winl + ", top=" + wint + ", scrollbars=" + scroll + ", status=yes, resizable=no, width=" + width + ", height=" + height);
	}


	// »õÃ¢¶ç¿ì±â
	this.WinOpenTarget = function (url, wname) {

		return window.open(url, wname);
	}


	// Æ÷Ä¿½º ÀÌµ¿
	this.MoveFocus = function (num, fromform, toform) {
		
		var str = fromform.value.length;

		if (str == num) {
			toform.focus();
		}
	}



	// ÀÔ·Â°ªÀÌ ¼ýÀÚ·Î µÇ¾îÀÖ´ÂÁöCheck
	this.isNumOnly = function (val) {
		var pattern = /^[_0-9]$/;
		return (pattern.test(val)) ? true : false;
	}


	// ÁÖ¹Îµî·Ï¹øÈ£ Ã¼Å©
	this.JuminChk = function(ju, min){
		var chk		=0;

		for(i=0; i<=5; i++)
			chk=chk+((i%8+2)*parseInt(ju.substring(i, i+1)));

		for(i=6; i<=11; i++)
			chk=chk+((i%8+2)*parseInt(min.substring(i-6, i-5)));

		chk=(11-(chk%11))%10;

		if(chk!=min.substring(6, 7)){
			return false;
		}else{
			return true;
		}
	}

	// ÀÌ¸ÞÀÏ Ã¼Å©
	this.Email = function (val) {
		var pattern = /^[_a-zA-Z0-9-\.\_]+@[\.a-zA-Z0-9-]+\.[a-zA-Z]+$/;
		return (pattern.test(val)) ? true : false;
	}


	// ÀÌ¸ÞÀÏ ¼¿·ºÆ®¹Ú½º
	this.EmailChange = function (str) {
			if(str != '') {
				$('email2').readOnly		=true;
				$('email2').value			=str;
			} else {
				$('email2').readOnly		=false;
				$('email2').value			="";
				$('email2').focus();
			}
	}
	

	// ¹®ÀÚ¿­ ±æÀÌ
	this.Length = function (str) {
		var len = 0;
		var tmp = null;
		var i = 0;

		while (i < str.length) {
			tmp = str.charAt(i);

			if (escape(tmp).length > 4) {
				len += 2;
			} else if (tmp != "\r") {
				len++;
			}

			i++;
		}

		return len;
	}

	// °ø¹éÀÔ·Â ºÒ°¡
	this.PressBlank = function () {
		if (event.keyCode == 32) {
			event.returnValue = false;
		}
	}

	// ¼ýÀÚ¸¸ ÀÔ·Â
	this.PressNumber = function () {
		if (event.keyCode < 48 || event.keyCode > 57) {
			event.returnValue = false;
		}
	}

	// ¼ýÀÚ¸¸ ÀÔ·Â ÄÞ¸¶Âï±â
	this.NumChk = function (num) {
		num = new String(num);
		num = num.replace(/,/gi, "");
		return this.NumCheck(num);
	}
	this.NumCheck = function (num) {
		var sign = "";

		if (isNaN(num)) {
			alert("¼ýÀÚ¸¸ ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù.");
			return 0;
		}

		if (num == 0) {
			return num;
		}

		if (num < 0) {
			num = num * (-1);
			sign = "-";
		} else{
			num = num * 1;
		}

		num = new String(num);

		var temp = "";
		var pos = 3;
		var num_len = num.length;

		while (num_len > 0) {
			num_len = num_len - pos;
			if (num_len < 0) {
				pos = num_len + pos;
				num_len = 0;
			}
			temp = "," + num.substr(num_len, pos) + temp;
		}
		return sign + temp.substr(1);
	}

	// ¼ýÀÚ¸¸ ÀÔ·Â ÄÞ¸¶ ¾øÀ½
	this.NumberChk = function (num) {
		num = new String(num);
		num = num.replace(/,/gi, "");
		return this.NumberCheck(num);
	}
	this.NumberCheck = function (num) {
		var sign = "";

		if (isNaN(num)) {
			alert("¼ýÀÚ¸¸ ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù.");
			return 1;
		}

		if (num == 0) {
			return "";
		}

		if (num < 0) {
			num = num * (-1);
			sign = "-";
		} else{
			num = num * 1;
		}

		return num;
	}

	// ´ë¹®ÀÚ -> ¼Ò¹®ÀÚ
	this.ToLower = function (str) {
		return str.toLowerCase();
	}

	// ¼Ò¹®ÀÚ -> ´ë¹®ÀÚ
	this.ToUpper = function (str) {
		return str.toUpperCase();
	}

	// ¹è¿­¾È¿¡ °ªÀÌ ÀÖ´ÂÁö Ã¼Å©
	this.InArray = function (val, arr) {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i] == val) {
				return true;
			}
		}

		return false;
	}

	// ¶óµð¿À¹öÆ° Ã¼Å©¿©ºÎ
	this.Radio = function (frm, act, val) {
		switch (act) {
			// Ã¼Å©°ª ±¸ÇÏ±â
			case 1 :
				if (frm.length > 0) {
					for (var i = 0; i < frm.length; i++) {
						if (frm[i].checked == true) {
							return frm[i].value;
						}
					}
				} else {
					if (frm.checked == true) {
						return frm.value;
					}
				}

			// ÇØ´ç À§Ä¡¿¡ Æ÷Ä¿½º
			case 2 :
				if (frm.length > 0) {
					for (var i = 0; i < frm.length; i++) {
						if (frm[i].value == val) {
							frm[i].checked = true;
							break;
						}
					}
				} else {
					if (frm.value == val) {
						frm.checked = true;
					}
				}

			// Ã¼Å©¿©ºÎ
			default :
				if (frm.length > 0) {
					for (var i = 0; i < frm.length; i++) {
						if (frm[i].checked == true) {
							return true;
						}
					}
				} else {
					if (frm.checked == true) {
						return true;
					}
				}

				return false;
		}
	}

	// ¼Ò¼ýÁ¡ ÀÚ¸´¼ö ¸ÂÃß±â
	this.Round = function (num, pos) {
		var posV = Math.pow(10, (pos ? pos : 2));

		return Math.round(num * posV) / posV;
	}

	// ¹®ÀÚ¿­ ¹Ýº¹Ã¼Å©
	this.Repetition = function (str, lmt) {
		if (str.length < 1) {
			return;
		}

		for (var i = 0; i < str.length; i++) {
			var rpt = str.substr(i, 1);
			var key = "";
			for (var j = 0; j < lmt; j++) {
				key += rpt;
			}
			var chk = str.indexOf(key);
			if (chk < 0) {
				continue;
			} else {
				return true;
				break;
			}
		}

		return false;
	}

	// ÄíÅ°°ª Á¦¾î
	this.Cookies = function (name, value, expire) {
		if (typeof value != "undefined" && typeof expire != "undefined") {
			var day = new Date();
			day.setDate(day.getDate() + expire);
			document.cookie = name + "=" + escape(value) + "; path=/; expires=" + day.toGMTString() + ";";
		} else {
			var org = document.cookie;
			var dlm = name + "=";
			var x = 0;
			var y = 0;
			var z = 0;

			while (x <= org.length) {
				y = x + dlm.length;

				if (org.substring(x, y) == dlm) {
					if ((z = org.indexOf(";", y)) == -1) {
						z = org.length;
					}

					return org.substring(y, z);
				}

				x = org.indexOf(" ", x) + 1;

				if (x == 0) {
					break;
				}
			}

			return "";
		}
	}

	// ³¯Â¥¸ñ·Ï (³â)
	this.YearList = function (y) {
		day = new Date();

		if (typeof y == "undefined") {
			var yy = day.getFullYear();
		} else if (y == "") {
			var yy = 0;
		} else {
			var yy = parseInt(y);
		}

		for (var i = day.getFullYear() + 1; i >= 2008; i--) {
			document.write("<option value='" + i + "'" + (i == yy ? " selected" : "") + "> " + i + " ³â </option>");
		}
	}

	// ³¯Â¥¸ñ·Ï (¿ù)
	this.MonthList = function (m) {
		day = new Date();

		if (typeof m == "undefined") {
			var mm = day.getMonth() + 1;
		} else if (m == "") {
			var mm = 0;
		} else {
			var mm = (m.substr(0, 1) == "0") ? parseInt(m.substr(1, m.length)) : parseInt(m);
		}

		for (var i = 1; i <= 12; i++) {
			var n = (i < 10 ? "0" : "") + i;

			document.write("<option value='" + n + "'" + (i == mm ? " selected" : "") + "> " + n + " ¿ù </option>");
		}
	}

	// ³¯Â¥¸ñ·Ï (ÀÏ)
	this.DayList = function (y, m, d) {
		day = new Date();

		if (typeof y == "undefined") {
			var yy = day.getFullYear();
		} else if (y == "") {
			var yy = 0;
		} else {
			var yy = parseInt(y);
		}

		if (typeof m == "undefined") {
			var mm = day.getMonth() + 1;
		} else if (m == "") {
			var mm = 0;
		} else {
			var mm = (m.substr(0, 1) == "0") ? parseInt(m.substr(1, m.length)) : parseInt(m);
		}

		if (typeof d == "undefined") {
			var dd = day.getDate();
		} else if (d == "") {
			var dd = 0;
		} else {
			var dd = (d.substr(0, 1) == "0") ? parseInt(d.substr(1, d.length)) : parseInt(d);
		}

		for (var i = 1; i <= this.EndDate(yy, mm); i++) {
			var n = (i < 10 ? "0" : "") + i;

			document.write("<option value='" + n + "'" + (i == dd ? " selected" : "") + "> " + n + " ÀÏ </option>");
		}
	}

	// ³¯Â¥¸ñ·Ï (½Ã)
	this.HourList = function (h) {
		for (var i = 0; i <= 23; i++) {
			var n = (i < 10 ? "0" : "") + i;

			document.write("<option value='" + n + "'" + (n == h ? " selected" : "") + "> " + n + " ½Ã </option>");
		}
	}

	// ³¯Â¥¸ñ·Ï (ºÐ)
	this.MinuteList = function (m) {
		for (var i = 0; i <= 59; i++) {
			var n = (i < 10 ? "0" : "") + i;

			document.write("<option value='" + n + "'" + (n == m ? " selected" : "") + "> " + n + " ºÐ </option>");
		}
	}

	// À±³â ±¸ÇÏ±â
	this.LeapYear = function (y) {
		if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0 && y % 4000 != 0)) {
			return true;
		} else {
			return false;
		}
	}

	// ÇØ´ç ¿ùÀÇ ¸¶Áö¸· ³¯Â¥
	this.EndDate = function (y, m) {
		var edate = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

		if (m == 2) {
			if (this.LeapYear(y) == true) {
				return 29;
			} else {
				return 28;
			}
		} else {
			return edate[m];
		}
	}

	// ¸ñ·Ï ¹Ù²Ù±â
	this.ChgDate = function (sel, y, m) {
		if (typeof y == "undefined" && typeof m == "undefined") {
			for (var i = 1; i <= 12; i++) {
				var n = (i < 10 ? "0" : "") + i;

				sel.options[i] = new Option(n, n);
			}
		} else {
			var mm = (m.substr(0, 1) == "0") ? parseInt(m.substr(1, m.length)) : parseInt(m);
			var ed = this.EndDate(y, mm);

			for (var i = sel.length - 1; i > 0; i--) {
				sel.options[i] = null;
			}

			for (var i = 1; i <= ed; i++) {
				var n = (i < 10 ? "0" : "") + i;

				sel.options[i] = new Option(n, n);
			}
		}
	}

	// ÁÂ/¿ì °ø¹éÁ¦°Å
	this.Trim = function (str) {
		return str.replace(/(^\s*)|(\s*$)/gi, "");
	}

	// ·¹ÀÌ¾î ¸Þ½ÃÁö
	this.ShowMessage = function (obj, value, message, type) {
		this.Object(obj).style.posTop = event.clientY + document.body.scrollTop;

		if (/^[0-9]+$/.test(type)) {
			this.Object(obj).style.posLeft = type;
		} else if (type == "left") {
			this.Object(obj).style.posLeft = event.clientX - parseInt(this.Object(obj).style.width.replace(/PX/, ""));
		} else if (type == "center") {
			this.Object(obj).style.posLeft = event.clientX - parseInt(this.Object(obj).style.width.replace(/PX/, "")) / 2;
		} else {
			this.Object(obj).style.posLeft = event.clientX;
		}

		this.Object(obj).innerHTML = message;

		if (value) {
			this.Object(obj).style.display = "";
		} else {
			this.Object(obj).style.display = "none";
		}
	}

	// ÀÌ¹ÌÁö È®´ë
	this.imgOpen = function (imgPath) {
		poto = new Image();
		poto.src = (imgPath);
		if((poto.width!=0) && (poto.height!=0)) {
			this.imgWinOpen(imgPath, poto.width, poto.height);
		}
	}	

	this.imgWinOpen = function (imgPath, Width, Height) {
		var winHandle = window.open("" ,"windowName","toolbar=no,scrollbars=no,resizable=no, top=200, left=200 ,width=" + Width + ",height=" + Height)
		if(winHandle != null) {
			var htmlString = "<html><head><title>¿øº»ÀÌ¹ÌÁö</title></head>" 
			htmlString += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
			htmlString += "<a href=javascript:window.close()><img src=" + imgPath + " border=0 alt=ÀÌ¹ÌÁöÅ¬¸¯:È­¸é´Ý±â></a>"
			htmlString += "</body></html>"
			winHandle.document.open()
			winHandle.document.write(htmlString)
			winHandle.document.close()
		} 
		if(winHandle != null) winHandle.focus()
			return winHandle
	}


	// ÀÌ¹ÌÁö È®´ë ¹× ÇÁ¸°Æ®
	this.imgOpenPrint = function (imgPath){
		
		poto = new Image();
		poto.src = (imgPath);
		if((poto.width!=0) && (poto.height!=0)) {

			var imgHeight = poto.height + 50
			var url = "/AntiManagerF/PharmInfo/pharmMap.asp?img="+imgPath
			
			this.WinOpen(url, "¾à±¹Áöµµ", poto.width, imgHeight,'');

		}
	}



	// ÀÌµ¿
	this.Link = function (url, msg) {
		if (typeof msg != "undefined") {
			if (confirm(msg) == true) {
				location.href = url;
			}
		} else {
			location.href = url;
		}
	}

	// »èÁ¦ CONFIRM MESSAGE
	this.DelConfirm = function(){
			if(confirm("Á¤¸» »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")){
					return true;
			}else{
					return false;
			}
	}

	// Byte »çÀÌÁî 
	this.StrSizeChk = function(strId){
		var sum = 0;
		var form=eval(strId);
		for(var i=0; i < form.value.length; i++) {
			if( form.value.charCodeAt(i)<200)
				sum+=1;//¿µ¾î³ª ¼ýÀÚµéÀÏ¶§..
			else 
				sum+=2;//ÇÑ±ÛÀÌ³ª Æ¯¼ö¹®ÀÚ µéÀÏ¶§..
		 }
		 return sum
	}

	// Loading Image
	this.LoadingImg = function(ldiv, ty){
			var str = "<div style='text-align: center;padding: 30px;'><img src='/admin/images/loading.gif'/></div>"

			$(ldiv).update(str);
	}


	this.bgImg = function (obj , url){
		if(obj.value==""){
			obj.style.backgroundImage="url("+ url +")";
		}
	}


	this.bgImgDel = function (obj){
		obj.style.backgroundImage="url(none)";
	}


	//·¹ÀÌ¾î °ü·Ã
	this.popupLayer = function (s,w,h)	{
		
		if (!w) w = "350";
		if (!h) h = "200";

		var myW;
		var myH;
		if (parseInt(navigator.appVersion)>3){
			if(navigator.appName=="Netscape"){ //³×½ºÄÉÀÌÇÁ, »çÆÄ¸®, ÆÄÀÌ¾îÆø½º
				myW = window.innerWidth-16;
				myH = window.innerHeight+500;
			}
			if(navigator.appName.indexOf("Microsoft")!=-1) { //ÀÎÅÍ³Ý ÀÍ½ºÇÃ·Î·¯
				myW = document.documentElement.offsetWidth-20;
				myH =screen.height+200;
			}
		}
		
		//var myW = screen.width;
		//var myH = screen.height+100;			
		var bodyW, bodyH;

		//bodyW = "840";
		//bodyH = "1147";

		bodyW = myW;
		bodyH = myH;

		var obj = document.createElement("div");
		with (obj.style){
			position = "absolute";
			left = "0px";
			top = "0px";
			zIndex=100;
			width = bodyW+"px";
			height = bodyH+"px";
			backgroundColor = "#FFFFFF";
			filter = "Alpha(Opacity=20);opacity:0;";
			opacity = "0";
		}
		obj.id = "objPopupLayerBg";
		document.body.appendChild(obj);

		var obj = document.createElement("div");
		with (obj.style){
			position = "absolute";
			left= (bodyW - w)/2 +"px"
			top = (bodyH - h)/2 +"px"
			zIndex=100;
			width = w+"px";
			height = h+"px";
			backgroundColor = "#000000";
			border = "0px solid #000000";
		}
		obj.id = "objPopupLayer";
		document.body.appendChild(obj);	

		var ifrm = document.createElement("iframe");
		with (ifrm.style){
			width = w +"px";
			height = h +"px";		
		}
		ifrm.frameBorder = 0;
		ifrm.scrolling="no";;
		
		obj.appendChild(ifrm);
		ifrm.src = s;
	}

}

var MyLib = new MyLib();



gotoPG = function(seq, pg, ac) {
	var frm = document.sForm;
	frm.p.value		= pg;
	frm.seq.value	= seq;
	frm.action		= ac;
	frm.submit();
}


gotoLogin = function(pgUrl) {

	alert("·Î±×ÀÎ ÈÄ ÀÌ¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.");
	window.location.href=pgUrl;
}
