

/************************************************************************************************Util*/
function inUtil() {

		/************************************************************************************************String*/
		/**
		 * @brief 		ÁÂ¿ì °ø¹é Á¦°Å
		 */
		this.trim = function(pStr) {
				return (pStr || "").replace( /^\s+|\s+$/g, "" );
		}


		/**
		 * @brief 		E-mail ÁÖ¼Ò Ã¼Å©
		 * @param			pStr		¹®ÀÚ¿­
		 * @return		Àß¸øµÈ E-mail ÁÖ¼Ò¸é true ¹ÝÈ¯
		 */
		this.IsEmail = function(pStr) {
			if (pStr.search(/^([\w-]{2,})\@{1}([\w-]{1,})\.{1}([\w-]{2,3})/) == -1) {
				return false;
			} else {
				return true;
			}
		}

		/**
		 * @brief 		¿µ¹® Á¡°Ë
		 * @param			pStr		¹®ÀÚ¿­
		 * @return		¿µ¹®ÀÌ ¾Æ´Ï¸é true ¹ÝÈ¯
		 */
		this.IsEng = function(pStr) {
			if (pStr.search(/[^A-Za-z]/) != -1) {
				return true;
			} else {
				return false;
			}
		}

		/**
		 * @brief 		¿µ¹®,¼ýÀÚ Á¡°Ë
		 * @param			pStr		¹®ÀÚ¿­
		 * @return		¿µ¹®,¼ýÀÚ°¡ ¾Æ´Ï¸é true ¹ÝÈ¯
		 */
		this.IsEngNum = function(pStr) {
			if (pStr.search(/[^A-Za-z0-9]/) != -1) {
				return true;
			} else {
				return false;
			}
		}

		/**
		 * @brief 		¿µ¹®ÆÄÀÏ¸í(¿µ¹®,¼ýÀÚ, ¾ð´õ¹Ù, ÇÏÀÌÇÂ) Á¡°Ë
		 * @param			pStr		¹®ÀÚ¿­
		 * @return		¿µ¹®ÆÄÀÏ¸í(¿µ¹®,¼ýÀÚ, ¾ð´õ¹Ù, ÇÏÀÌÇÂ)ÀÌ ¾Æ´Ï¸é False ¹ÝÈ¯
		 */
		this.IsEngFN = function(pStr) {
			if (pStr.search(/[^A-Za-z0-9_\-]/) != -1) {
				return true;
			} else {
				return false;
			}
		}


		/**
		 * @brief 		ÇÑ±Û Á¡°Ë
		 * @param			pStr		¹®ÀÚ¿­
		 * @return		ÇÑ±ÛÀÌ ¾Æ´Ï¸é true ¹ÝÈ¯
		 */
		this.IsHangul = function(pStr) {
		     for (var i = 0; i < pStr.length; i++)  {
		         if (pStr.charCodeAt(i) != 32 && (pStr.charCodeAt(i) < 44032 || pStr.charCodeAt(i) > 55203))
		             return false;
		     }
		     return true;
		}

		/**
		 * @brief 		Æ¯¼ö ¹®ÀÚ ¼ÒÀ¯ ¿©ºÎ
			 * @param			pStr		¹®ÀÚ¿­
		 * @return		Æ¯¼ö ¹®ÀÚ°¡ ÀÖÀ» °æ¿ì true ¹ÝÈ¯
		 */
		this.hasSpecialChar = function(pStr) {
			if (pStr.search(/[!@~#$%^&*_+=`<>?\\/\{}'\"]/) != -1) {
				return true;
			} else {
				return false;
			}
		}


		/**
		 * @brief 		ÅëÈ­Çü Á¡°Ë
			 * @param			pStr		¹®ÀÚ¿­
		 * @return		ÅëÈ­ÇüÀÌ ¾Æ´Ï¸é true ¹ÝÈ¯
		 */
		this.IsCurrency = function(pStr) {
			return isNaN(pStr.replaceAll(",", ""));
		}



		/************************************************************************************************Date*/
		/**
		 * @brief 		Compare two date strings to see which is greater.
		 * @return		1 if date1 is greater than date2
		 *						0 if date2 is greater than date1 of if they are the same
		 *						-1 if either of the dates is in an invalid format
		 */
		this.CompareDates = function(pDate1,pDateformat1,pDate2,pDateformat2) {
			var d1 = this.GetDateFromFormat(pDate1,pDateformat1);
			var d2 = this.GetDateFromFormat(pDate2,pDateformat2);

			if (d1==0 || d2==0) {
				return -1;
			}
			else if (d1 >= d2) {
				return 1;
			}

			return 0;
		}


		// ------------------------------------------------------------------
		// Utility functions for parsing in GetDateFromFormat()
		// ------------------------------------------------------------------
		this._getInt = function(str,i,minlength,maxlength) {
			for (x=maxlength; x>=minlength; x--) {
				var token = str.substring(i,i+x);
				if (token.length < minlength) {
					return null;
				}
				if (isNaN(token)) {
					return token;
				}
			}
			return null;
		}

		/**
		 * @brief 		GetDateFromFormat( date_string , format_string )
		 *
		 *						This function takes a date string and a format string. It matches
		 *						If the date string matches the format string, it returns the
		 *						getTime() of the date. If it does not match, it returns 0.
		 *
		 *						This function uses the same format strings as the
		 *						java.text.SimpleDateFormat class, with minor exceptions.
		 *
		 *						The format string consists of the following abbreviations:
		 *
		 *						Field        | Full Form          | Short Form
		 *						-------------+--------------------+-----------------------
		 *						Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
		 *						Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
		 *						Day of Month | dd (2 digits)      | d (1 or 2 digits)
		 *						Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
		 *						Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
		 *						Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
		 *						Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
		 *						Minute       | mm (2 digits)      | m (1 or 2 digits)
		 *						Second       | ss (2 digits)      | s (1 or 2 digits)
		 *						AM/PM        | a                  |
		 *
		 *						Examples:
		 *						 "MMM d, y" matches: January 01, 2000
		 *						                     Dec 1, 1900
		 *						                     Nov 20, 00
		 *						 "m/d/yy"   matches: 01/20/00
		 *						                     9/2/00
		 *						 "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
		 *
		 * @param			val
		 * @param			format
		 * @return		date
		**/
		this.GetDateFromFormat = function(val,format) {
			var MONTH_NAMES = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

			var date_split=val.split("/");
			/*if(date_split[0].length<2)
			{
				date_split[0]="0"+date_split[0];
			}
			if(date_split[1].length<2)
			{
				date_split[1]="0"+date_split[1];
			}
			val = date_split[0] + "/" + date_split[1] + "/" + date_split[2];*/
			val = val+"";
			format = format+"";
			var i_val = 0;
			var i_format = 0;
			var c = "";
			var token = "";
			var token2= "";
			var x,y;
			var now   = new Date();
			var year  = now.getYear();
			var month = now.getMonth()+1;
			var date  = now.getDate();
			var hh    = now.getHours();
			var mm    = now.getMinutes();
			var ss    = now.getSeconds();
			var ampm  = "";

			while (i_format < format.length) {
				// Get next token from format string
				c = format.charAt(i_format);
				token = "";
				while ((format.charAt(i_format) == c) && (i_format < format.length)) {
					token += format.charAt(i_format);
					i_format++;
				}
				// Extract contents of value based on format token
				if (token=="yyyy" || token=="yy" || token=="y") {
					if (token=="yyyy") { x=4;y=4; }// 4-digit year
					if (token=="yy")   { x=2;y=2; }// 2-digit year
					if (token=="y")    { x=2;y=4; }// 2-or-4-digit year
					year = _getInt(val,i_val,x,y);
					if (year == null) { return 0; }
					i_val += year.length;
					if (year.length == 2) {
						if (year > 70) {
							year = 1900+(year-0);
						}
						else {
							year = 2000+(year-0);
						}
					}
				}
				else if (token=="MMM"){// Month name
					month = 0;
					for (var i=0; i<MONTH_NAMES.length; i++) {
						var month_name = MONTH_NAMES[i];
						if (val.substring(i_val,i_val+month_name.length).toLowerCase() == month_name.toLowerCase()) {
							month = i+1;
							if (month>12) { month -= 12; }
							i_val += month_name.length;
							break;
						}
					}
					if (month == 0) { return 0; }
					if ((month < 1) || (month>12)) { return 0; }
					// TODO: Process Month Name
				}
				else if (token=="MM" || token=="M") {
					x=token.length; y=2;
					month = _getInt(val,i_val,x,y);
					if (month == null) { return 0; }
					if ((month < 1) || (month > 12)) { return 0; }
					i_val += month.length;
				}
				else if (token=="dd" || token=="d") {
					x=token.length; y=2;
					date = _getInt(val,i_val,x,y);
					if (date == null) { return 0; }
					if ((date < 1) || (date>31)) { return 0; }
					i_val += date.length;
				}
				else if (token=="hh" || token=="h") {
					x=token.length; y=2;
					hh = _getInt(val,i_val,x,y);
					if (hh == null) { return 0; }
					if ((hh < 1) || (hh > 12)) { return 0; }
					i_val += hh.length;
					hh--;
				}
				else if (token=="HH" || token=="H") {
					x=token.length; y=2;
					hh = _getInt(val,i_val,x,y);
					if (hh == null) { return 0; }
					if ((hh < 0) || (hh > 23)) { return 0; }
					i_val += hh.length;
				}
				else if (token=="KK" || token=="K") {
					x=token.length; y=2;
					hh = _getInt(val,i_val,x,y);
					if (hh == null) { return 0; }
					if ((hh < 0) || (hh > 11)) { return 0; }
					i_val += hh.length;
				}
				else if (token=="kk" || token=="k") {
					x=token.length; y=2;
					hh = _getInt(val,i_val,x,y);
					if (hh == null) { return 0; }
					if ((hh < 1) || (hh > 24)) { return 0; }
					i_val += hh.length;
					h--;
				}
				else if (token=="mm" || token=="m") {
					x=token.length; y=2;
					mm = _getInt(val,i_val,x,y);
					if (mm == null) { return 0; }
					if ((mm < 0) || (mm > 59)) { return 0; }
					i_val += mm.length;
				}
				else if (token=="ss" || token=="s") {
					x=token.length; y=2;
					ss = _getInt(val,i_val,x,y);
					if (ss == null) { return 0; }
					if ((ss < 0) || (ss > 59)) { return 0; }
					i_val += ss.length;
				}
				else if (token=="a") {
					if (val.substring(i_val,i_val+2).toLowerCase() == "am") {
						ampm = "AM";
					}
					else if (val.substring(i_val,i_val+2).toLowerCase() == "pm") {
						ampm = "PM";
					}
					else {
						return 0;
					}
				}
				else {
					if (val.substring(i_val,i_val+token.length) != token) {
						return 0;
					}
					else {
						i_val += token.length;
					}
				}
			}
			// If there are any trailing characters left in the value, it doesn't match
			if (i_val != val.length) {
				return 0;
			}
			// Is date valid for month?
			if (month == 2) {
				// Check for leap year
				if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) { // leap year
					if (date > 29){ return false; }
				}
				else {
					if (date > 28) { return false; }
				}
			}
			if ((month==4)||(month==6)||(month==9)||(month==11)) {
				if (date > 30) { return false; }
			}
			// Correct hours value
			if (hh<12 && ampm=="PM") {
				hh+=12;
			}
			else if (hh>11 && ampm=="AM") {
				hh-=12;
			}
			var newdate = new Date(year,month-1,date,hh,mm,ss);
			return newdate.getTime();
		}


		/************************************************************************************************Window*/
		/**
		 * @brief 		¸ð´ÞÃ¢ ¶ç¿ì±â
		 * @param			pEle			DOM ¿ä¼Ò¸í : ¸ð´ÞÃ¢ ¹ÝÈ¯ °ªÀ» ¹ÞÀ» Æû ¿ä¼Ò
		 * @param			pUrl			Ã¢ ÁÖ¼Ò
		 * @param			pWidth		Ã¢ Æø
		 * @param			pHeight		Ã¢ ³ôÀÌ
		 * @return		¸ð´ÞÃ¢ ¹ÝÈ¯°ª
		 */
		this.OpenModal = function(pEle, pUrl, pWidth, pHeight) {
			var oModal = new Object();
			oModal.opener = self;

			var vRetVal = window.showModalDialog(pUrl, oModal,"dialogwidth:"+pWidth+"px;dialogheight:"+(pHeight+20)+"px;center:yes;status=no; help=no; scroll=yes; unadorned:yes; edge;sunken; dialogHide:yes;resizable:yes;");

			if(typeof(pEle) == "object") {
				if(typeof(vRetVal) != "undefined")
				{
					pEle.value = vRetVal
				}
			}
			return vRetVal;
		}

		/**
		 * @brief 		»õÃ¢ ¶ç¿ì±â
		 * @param			pUrl			Ã¢ ÁÖ¼Ò
		 * @param			pWinName	Ã¢ ÀÌ¸§
		 * @param			pWidth		Ã¢ Æø
		 * @param			pHeight		Ã¢ ³ôÀÌ
		 */
		this.OpenNewWin = function(pUrl, pWinName, pWidth, pHeight) {
			var win = window.open(pUrl, pWinName, "scrollbars=no,status=no,toolbar=no,resizable=yes,location=no,menu=no,width=" + pWidth + ",height=" + pHeight);

			if(win == null){
				alert("ÆË¾÷Â÷´ÜÀ» ÇØÁ¦ÇØÁÖ¼¼¿ä!");
			} else{
				win.focus();
			}
			return;
		}

		/**
		 * @brief 		ÇÑ°¡¿îµ¥ »õÃ¢ ¶ç¿ì±â (no srollable)
		 * @param			pUrl			Ã¢ ÁÖ¼Ò
		 * @param			pWinName	Ã¢ ÀÌ¸§
		 * @param			pWidth		Ã¢ Æø
		 * @param			pHeight		Ã¢ ³ôÀÌ
		 */
		this.OpenNewWinCenter = function(pUrl, pWinName, pWidth, pHeight) {
			var win = window.open(pUrl, pWinName, "scrollbars=no,status=no,toolbar=no,resizable=yes,location=no,menu=no,width=" + pWidth + ",height=" + pHeight + ",top=" + this.GetScreenCenterTopPos(pHeight) + ",left=" + this.GetScreenCenterLeftPos(pWidth));

			if(win == null){
				alert("ÆË¾÷Â÷´ÜÀ» ÇØÁ¦ÇØÁÖ¼¼¿ä!");
			} else{
				win.focus();
			}
			return;
		}

		/**
		 * @brief 		ÇÑ°¡¿îµ¥ »õÃ¢ ¶ç¿ì±â (srollable)
		 * @param			pUrl			Ã¢ ÁÖ¼Ò
		 * @param			pWinName	Ã¢ ÀÌ¸§
		 * @param			pWidth		Ã¢ Æø
		 * @param			pHeight		Ã¢ ³ôÀÌ
		 */
		this.OpenNewWinCenterScroll = function(pUrl, pWinName, pWidth, pHeight) {
			var win = window.open(pUrl, pWinName, "scrollbars=yes,status=no,toolbar=no,resizable=yes,location=no,menu=no,width=" + pWidth + ",height=" + pHeight + ",top=" + this.GetScreenCenterTopPos(pHeight) + ",left=" + this.GetScreenCenterLeftPos(pWidth));

			if(win == null){
				alert("ÆË¾÷Â÷´ÜÀ» ÇØÁ¦ÇØÁÖ¼¼¿ä!");
			} else{
				win.focus();
			}
			return;
		}

		/**
		 * @brief 		ÃÖ´ëÇÑ Å« »õÃ¢ ¶ç¿ì±â (no srollable)
		 * @param			pUrl			Ã¢ ÁÖ¼Ò
		 * @param			pWinName	Ã¢ ÀÌ¸§
		 */
		this.OpenWinFull = function(pUrl, pWinName) {
			var pWidth = window.screen.availWidth;
			var pHeight = window.screen.availHeight;

	    var win = window.open(pUrl, pWinName, "left=0,top=0,width="+pWidth+",height="+pHeight+",status=no,help=no,resizable=yes");
			if(win == null){
				alert("ÆË¾÷Â÷´ÜÀ» ÇØÁ¦ÇØÁÖ¼¼¿ä!");
			} else{
				win.focus();
			}
			return;
		}

		/**
		 * @brief 		ÃÖ´ëÇÑ Å« »õÃ¢ ¶ç¿ì±â (srollable)
		 * @param			pUrl			Ã¢ ÁÖ¼Ò
		 * @param			pWinName	Ã¢ ÀÌ¸§
		 */
		this.OpenWinFullScroll = function(pUrl, pWinName) {
			var pWidth = window.screen.availWidth;
			var pHeight = window.screen.availHeight;

	    var win = window.open(pUrl, pWinName, "left=0,top=0,width="+pWidth+",height="+pHeight+",status=no,help=no,resizable=yes,scrollbars=yes");
			if(win == null){
				alert("ÆË¾÷Â÷´ÜÀ» ÇØÁ¦ÇØÁÖ¼¼¿ä!");
			} else{
				win.focus();
			}
	    return;
		}

		/**
		 * @brief 		ÇØ»óµµ °¡¿îµ¥ X ÁÂÇ¥ ±¸ÇÏ±â
		 * @param			pWidth		Ã¢ Æø
		 * @return		Ã¢ ÆøÀ» °í·ÁÇÑ left ÁÂÇ¥ ¹ÝÈ¯
		 */
		this.GetScreenCenterLeftPos = function(pWidth){
			var left = window.screen .availWidth  - pWidth;
			left = left < 2 ? 0 : left/2
			return left;
		}
		/**
		 * @brief 		ÇØ»óµµ °¡¿îµ¥ Y ÁÂÇ¥ ±¸ÇÏ±â
		 * @param			pHeight		Ã¢ ³ôÀÌ
		 * @return		Ã¢ ÆøÀ» °í·ÁÇÑ top ÁÂÇ¥ ¹ÝÈ¯
		 */
		this.GetScreenCenterTopPos = function(pHeight){
			var top = window.screen .availHeight  - pHeight ;
			top = top < 2 ? 0 : top/2
			return top;
		}
		/**
		 * @brief 		ºê¶ó¿ìÀú °¡¿îµ¥ X ÁÂÇ¥ ±¸ÇÏ±â
		 * @param			pWidth		°´Ã¼ ³ôÀÌ (·¹ÀÌ¾î, ÀÌ¹ÌÁö µîµî)
		 * @return		°´Ã¼ ÆøÀ» °í·ÁÇÑ left ÁÂÇ¥ ¹ÝÈ¯
		 */
		this.GetBodyCenterLeftPos = function(pWidth){
			var left = document.body.clientWidth  - pWidth;
			left = left < 2 ? 0 : left/2
			return document.body.scrollLeft + left;
		}
		/**
		 * @brief 		ºê¶ó¿ìÀú °¡¿îµ¥ Y ÁÂÇ¥ ±¸ÇÏ±â
		 * @param			pHeight		°´Ã¼ ³ôÀÌ (·¹ÀÌ¾î, ÀÌ¹ÌÁö µîµî)
		 * @return		°´Ã¼ ³ôÀÌÀ» °í·ÁÇÑ top ÁÂÇ¥ ¹ÝÈ¯
		 */
		this.GetBodyCenterTopPos = function(pHeight){
			var top = document.body.clientHeight - pHeight ;
			top = top < 2 ? 0 : top/2
			return document.body.scrollTop + top;
		}
		/**
		 * @brief 		ÇÏÀ§ iframeÃ¢¿¡¼­ º» ºê¶ó¿ìÀú °¡¿îµ¥ X ÁÂÇ¥ ±¸ÇÏ±â
		 * @param			pWidth		iFrame Æø
		 * @return		°´Ã¼ ÆøÀ» °í·ÁÇÑ left ÁÂÇ¥ ¹ÝÈ¯
		 */
		this.GetParentBodyCenterLeftPos = function(pWidth){
			var left = parent.document.body.clientWidth  - pWidth;
			left = left < 2 ? 0 : left/2
			return parent.document.body.scrollLeft + left;
		}
		/**
		 * @brief 		ÇÏÀ§ iframeÃ¢¿¡¼­ º» ºê¶ó¿ìÀú °¡¿îµ¥ X ÁÂÇ¥ ±¸ÇÏ±â
		 * @param			pHeight		iFrame ³ôÀÌ
		 * @return		°´Ã¼ ³ôÀÌÀ» °í·ÁÇÑ top ÁÂÇ¥ ¹ÝÈ¯
		 */
		this.GetParentBodyCenterTopPos = function(pHeight){
			var top = parent.document.body.clientHeight - pHeight ;
			top = top < 2 ? 0 : top/2
			return parent.document.body.scrollTop + top;
		}
};


