// 에러 핸들러 설정, 에러발생시 errorHandler 함수가 자동 호출됨.
	dwr.engine.setErrorHandler(errorHandler);
	function errorHandler(msg)
	{
		alert(msg);
	};
/////////////////////////////////////////////////////////////////////////
	Object.extend(String.prototype,
	{
		nvl: function(defaultValue) 
		{
			if (this == null || this == "") {
				return defaultValue;
			} else {
				return this;
			} 
		},
		toNumber: function()
		{
    		var value = 0;
      		var index = this.indexOf("0");
      		if(index == 0) {
      			value = parseInt(this.substr(1, this.length));
      		} else {
      			value = parseInt(this.substr(0, this.length));
      		}
      		return value;  
      	},
      	// yyyy-MM-dd hh:mm:ss String to Date
      	toDate: function()
      	{
      		if (this == "") {
      			return null;
      		}
      		var dateArray = this.split(" ");	      		
      		var date = null;      		
      		if(dateArray.length == 2) {
      			var dateArray1 = dateArray[0].split("-");
      			var dateArray2 = dateArray[1].split(":");
      			date = new Date(dateArray1[0].toNumber(), dateArray1[1].toNumber()-1, dateArray1[2].toNumber(), 
      							dateArray2[0].toNumber(), dateArray2[1].toNumber(), dateArray2[2].toNumber());
      		} else {
      			var dateArray1 = this.split("-");
      			date = new Date(dateArray1[0].toNumber(), dateArray1[1].toNumber()-1, dateArray1[2].toNumber());
      		}
      		return date;
      	},
      	addBr: function()
      	{
      		return this.replace(/\r/gi,"<br>");
      	},
      	removeComma: function()
	  	{
	  		// 금액을 표시하는 숫자에서 콤마(,)를 삭제한다. ex)12,345,678 ---> 12345678
	  		return this.replace(/,/gi,"");
	  	},      	
	  	addComma: function()
	  	{
	  		// 사용자가 입력한 금액 숫자를 콤마 형식으로 변환한다. ex) 12345678 ---> 12,345,678
			if (this == null || this == "") {
				return "";
			}			
			var integerString = this;
			var decimalString = "";	
			if (integerString.indexOf(".") > 0)
			{
				var tempString = integerString;
				integerString = tempString.substring(0, tempString.indexOf("."));
				decimalString = tempString.substring(tempString.indexOf("."));
			}	
			integerString = integerString.removeComma();			
			/////////////////////////////////////////////////////////////////////
			var num = 0;
			fl = "";	
			if (isNaN(integerString)) { 
				return 0;
			}			
			if (integerString == 0) {
				return integerString;
			}			
			if (integerString<0) { 
				num = integerString*(-1);
				fl = "-";
			} else {
				num = integerString*1;
			}			
			var numString = new String(num);
			var temp = ""
			var co = 3;
			var length = numString.length;			
			while (length>0) {
				length = length-co;
				if (length<0) {
					co = length+co;
					length = 0;
				}
				temp = "," + numString.substr(length,co) + temp;
			}			
			return fl + temp.substr(1) + decimalString;
		},
		removeDash: function()
		{ 
		  	// 화면에 보이는 날짜 형식에서 대쉬(-)를 삭제한다. ex)2006-11-01 --> 20061101	
	  		return this.replace(/-/gi,"");
	  	},
	  	removeDot: function ()  
	  	{
	  		return this.replace(/\./gi,"");
	  	},
	  	toDateFormat: function()
	  	{
			// 20061101 ---> 2006-11-01  
			if(this != null && this != "") {
				return this.substring(0,4) + "-" + this.substring(4,6) + "-" + this.substring(6,8);
			} else {
				return "";
			}
		},
		toDateFormat: function(dateFormat, formatDate)
	  	{
			// yyyy-MM-dd hh:mm:ss ---> 2006-11-01 02:22:32
			var year = "";
			var month = "";
			var day = "";
			var hour = "";
			var minute = "";
			var second = "";
			var dateString = "";
			if(dateFormat.indexOf("yyyy")>-1){
				year = this.substring(dateFormat.indexOf("yyyy"),dateFormat.indexOf("yyyy")+4);
			}else if(dateFormat.indexOf("yy")>-1){
				year = this.substring(dateFormat.indexOf("yy"),dateFormat.indexOf("yy")+2);
			}
			if(dateFormat.indexOf("MM")>-1){
				month = this.substring(dateFormat.indexOf("MM"),dateFormat.indexOf("MM")+2);
			}
			if(dateFormat.indexOf("dd")>-1){
				day = this.substring(dateFormat.indexOf("dd"),dateFormat.indexOf("dd")+2);
			}
			if(dateFormat.indexOf("hh")>-1){
				hour = this.substring(dateFormat.indexOf("hh"),dateFormat.indexOf("hh")+2);
			}
			if(dateFormat.indexOf("mm")>-1){
				minute = this.substring(dateFormat.indexOf("mm"),dateFormat.indexOf("mm")+2);
			}
			if(dateFormat.indexOf("ss")>-1){
				second = this.substring(dateFormat.indexOf("ss"),dateFormat.indexOf("ss")+2);
			}

			if(dateFormat.indexOf("yyyy")>-1)
				dateString = formatDate.replace(/y{1,4}/g, year);
			else if(dateFormat.indexOf("yy")>-1)
				dateString = formatDate.replace(/yy/g, year);
				
				
			dateString = dateString.replace(/MM/g, month);
			dateString = dateString.replace(/dd/g, day);
			dateString = dateString.replace(/hh/g, hour);
			dateString = dateString.replace(/mm/g, minute);
			dateString = dateString.replace(/ss/g, second);
			
			return dateString;
		},
		nvlRet: function(defaultValue, retVal) 
		{
			if (this == null || this == "" || this == "null") {
				return retVal;
			} else {
				return this;
			}   
		}
  	});
  	Date.prototype.toFormatString = function(aFormat) 
  	{
  		var format = "yyyy-MM-dd hh:mm:ss";
  		if (this == null || this == "") {
  			return "";
  		}
  		if (aFormat != null) {
  			format = aFormat;
  		}
  		Date.MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  		Date.DAYS   = ["Sun", "Mon", "Tue", "Wed", "Tur", "Fri", "Sat"];  		
	    var day = this.getDate().toPaddedString(2);
    	var month = (this.getMonth()+1).toPaddedString(2);
    	var monthEng = Date.MONTHS[this.getMonth()];
    	var yearLong = this.getFullYear();

    	var yearShort = (parseInt(yearLong.toString().substring(3,4))).toPaddedString(2);
    	var year = format.indexOf("yyyy")>-1 ? yearLong : yearShort;
    	var hour = this.getHours().toPaddedString(2); 
    	var minute = this.getMinutes().toPaddedString(2); 
    	var second = this.getSeconds().toPaddedString(2);    	
    	var dateString = "";
    	if (format.indexOf("MM dd, yyyy") == 0) {
    		dateString = format.replace(/y{1,4}/g, year).replace(/MM/g, monthEng).replace(/dd/g, day);
    	} else {
    		dateString = format.replace(/dd/g, day).replace(/MM/g, month).replace(/y{1,4}/g, year);
    	}    	 
    	dateString = dateString.replace(/hh/g, hour).replace(/mm/g, minute).replace(/ss/g, second);
    	return dateString;   		
  	};
  	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	var Pagination = Class.create();
	Pagination.prototype = {			
		initialize: function(itemCount, pageCount, jsFunctionName, linkId, pageFlag)
		{
			this.itemCount = itemCount;
			if(pageCount != null) {
				this.pageCount = pageCount;
			} else {
				this.pageCount = 10;
			}
			this.jsFunctionName = jsFunctionName;
			this.linkId = linkId;
			this.pageFlag = pageFlag
		},		
	  	makeLink: function(totalCount, firstResult) 
	  	{
	  		var totalPage = this.getTotalPage(totalCount); 	  		
	  		var currentPage = this.getCurrentPage(firstResult);
	  		var basePage = Math.floor(this.getCurrentPage(firstResult) / this.pageCount);	  		
	  		var pageLinks = "";	  		
	  		var lastPageMod = (totalCount/this.pageCount);	  		
	  		if (this.pageFlag == "A") {
	  			var imgStyle = " style='margin:5px 4px 3px 4px;' align='absmiddle'";
	  		} else {
	  			var imgStyle = "";
	  		}	  		
	  		if(totalPage > basePage) 
	  		{
	  			// <<		  		
		  		pageLinks += " <a href='javascript:" + this.jsFunctionName + "(0);' class='move'><img src='../../images/btn/btn_prev01.gif' width='6' height='5' alt='first' border='0' " + imgStyle + " /></a>";
				// <
		  		if (basePage > 0) {
		  			var firstCount = (basePage-1) * this.pageCount * this.itemCount;
		  		} else {
		  			var firstCount = 0;		  			
		  		}		  		
		  		if (firstResult == 0) {
		  			pageLinks += " <a href='javascript:" + this.jsFunctionName + "(" + 0 + ");' class='move'><img src='../../images/btn/btn_prev02.gif' width='3' height='5' alt='preview' border='0' " + imgStyle + " /></a>";
		  		} else	{
			  		var prePageNum = firstResult - 10; 
			  		pageLinks += " <a href='javascript:" + this.jsFunctionName + "(" + prePageNum + ");' class='move'><img src='../../images/btn/btn_prev02.gif' width='3' height='5' alt='preview' border='0' " + imgStyle + " /></a>";		  			
		  		} 
	  			pageLinks += "<span class='list'>";	  					  		
		  		for(var i=1; i<=this.pageCount; i++) {
		  			var nextPage = (basePage * this.pageCount) + i;	  			
		  			if(nextPage > totalPage) {
		  				break;
		  			}
		  			var currentCount = (nextPage-1) * this.itemCount;		  			
		  			if(currentCount == firstResult) {
		  				pageLinks += "<span class='now'>" + nextPage + "</span>";
		  			} else	{
		  				pageLinks += "<a href='javascript:" + this.jsFunctionName + "(" + currentCount + ");'>" + (nextPage) + "</a>";
		  			}
		  		}
		  		pageLinks += "</span>";
		  		// >
		  		var endCount = (basePage+2) * this.pageCount * this.itemCount - this.itemCount;	
		  		var nextPageTmp = Math.floor((firstResult/this.pageCount)+1)
		  		if (totalPage == (nextPageTmp)) {
		  			var nextPageNum = firstResult;
		  			pageLinks += " <a href='javascript:" + this.jsFunctionName + "(" + nextPageNum + ");' class='move'><img src='../../images/btn/btn_next01.gif' width='3' height='5' alt='next' border='0' " + imgStyle + " /></a>";
		  		} else {
		  			var nextPageNum = firstResult + 10;
		  			pageLinks += " <a href='javascript:" + this.jsFunctionName + "(" + nextPageNum + ");' class='move'><img src='../../images/btn/btn_next01.gif' width='3' height='5' alt='next' border='0' " + imgStyle + " /></a>";
		  		}
		  		// >>
		  		pageLinks += " <a href='javascript:" + this.jsFunctionName + "(" + ((totalPage-1) * this.itemCount) + ");' class='move'><img src='../../images/btn/btn_next02.gif' width='6' height='5' alt='last' border='0' " + imgStyle + " /></a>";
	  		}
	  		$(this.linkId).update(pageLinks);
	  	},	  	
	  	getCurrentPage: function(firstResult) 
	  	{
	  		return Math.ceil(firstResult / this.itemCount);
	  	},	  	
	  	getTotalPage: function(totalCount) 
	  	{
			return Math.ceil(totalCount / this.itemCount);
	  	}
	};	
	/////////////////////////////////////////////////////////////////////////////////////////////////////
	var FormUtils =
	{	 	
		getInputValue: function(type, formId, id)
		{
			var valueList = new Array();
			var inputList = Form.getInputs(formId, type, id);
			for(var i=0; i<inputList.length; i++) {
				if(inputList[i].checked) {
					valueList[valueList.length] = inputList[i].value;				
				}
			}
			return valueList;
		},		
		setInputValue: function(type, formId, id, valueList)
		{		
			var inputList = Form.getInputs(formId, type, id);			
			if(inputList != null && valueList != null) {
				for(var i=0; i<inputList.length; i++) {
					for(var j=0; j<valueList.length; j++) {
						if(inputList[i].value == valueList[j]) {
							inputList[i].checked = "true";		
						}
					}
				}
			}
		},
		clearInputValue: function(type, formId, id)
		{
			var inputList = Form.getInputs(formId, type, id);
			for(var i=0; i<inputList.length; i++) {
				inputList[i].checked = "";
			}
		},		
		checkInputValueAll: function(type, formId, id)
		{
			var inputList = Form.getInputs(formId, type, id);
			for(var i=0; i<inputList.length; i++) {
				inputList[i].checked = "true";
			}
		},		
		buildInputs: function(id, type, values, names)
		{
			$(id).update("");
			if(values != null) {
				for(var i=0; i<values.length; i++) {
					var tmpHtml = "";
					if(type == "select") {
						tmpHtml += "<option value='" + values[i] + "'>" + names[i];
					} else if(type == "checkbox") {
						var checkboxId = id.substring(0, id.length-4);
						tmpHtml += "<input id='" + checkboxId + "' name='" + checkboxId + "' type='checkbox' value='" + values[i] + "'>" + names[i];
					}
					new Insertion.Bottom(id, tmpHtml);
				}
				if(type == "select") {
					$(id).selectedIndex = 0;
				}	
			}
		},		
		// select, checkbox 생성 ('form','select',arrVal, arrName, '선택');
		buildInputs2: function(id, type, values, names, strVal)
		{
			$(id).update("");
			if(values != null) {
				if(type == "select") {
					$(id).options.add(new Option(strVal, ""));
				}				
				for(var i=0; i<values.length; i++) {
					var tmpHtml = "";
					if(type == "select") {
						tmpHtml += "<option value='" + values[i] + "'>" + names[i];
					} else if(type == "checkbox") {
						var checkboxId = id.substring(0, id.length-4); // selectRelProduct -> selectRelPro
						tmpHtml += "<input id='" + checkboxId + "' name='" + checkboxId + "' type='checkbox' value='" + values[i] + "'>" + names[i];
					}
					new Insertion.Bottom(id, tmpHtml);
				}
				if(type == "select") {
					$(id).selectedIndex = 0;
				}					
			}
		},	
		checkTextAreaLength: function(id, length)
		{
			var value = $(id).value;
			if(value.length > length) {
				alert("최대길이를 초과하였습니다.");
				$(id).value = value.substring(0, length);
				return false;
			} else {
				return true;
			}
		}
	};	
	var SessionUtils =
	{
			getUserValue: function(obj)
			{
				if(obj != null && obj.name != null)
				{
					TransactionFacade.getSessionValue(obj.name,
							{
								callback:function(value2)
								{
									obj.value = value2;
								}
							});
				}
			},			
			setUserValue : function(key, value)
			{
				TransactionFacade.setSessionValue(key, value,
						{
							callback:function()
							{
							}
						});
			}
	}
	var WindowUtils =
	{
			openWindow: function(url, windowId, width, height, scrollYn)
			{
				var win = null;
				
				var leftPosition = (screen.width) ? (screen.width-width)/2 : 0;
				var topPosition = (screen.height) ? (screen.height-height)/2 : 0;				
				var settings = "height=" + height + ",width=" + width + ",top=" + topPosition + ",left=" + leftPosition + ",resizable=no, scrollbars=" + scrollYn;
		
				win = window.open(url, windowId, settings);
			}
	}
	var ExcelView = Class.create();
	ExcelView.prototype = 	
	{		
			initialize: function(sheetName, actionUrl)
			{
				this.sheetName = sheetName;
				this.hiddenDiv = document.createElement("div"); 
				this.hiddenDiv.style.display = "none"; 
				this.hiddenDiv.innerHTML = "<form name=\"excelForm\" id=\"excelForm\" method=\"post\" action=\"" + actionUrl + "\"></form>";
				document.body.appendChild(this.hiddenDiv); 
				new Insertion.Bottom("excelForm", "<input name=\"sheetName\" id=\"sheetName\" type=\"hidden\" value=\"" + this.sheetName + "\">");	
			},			
			addHeadValues: function(values)
			{
				for (var i=0; i<values.length; i++) {
					new Insertion.Bottom("excelForm", "<input name=\"excelHead\" id=\"excelHead\" type=\"hidden\" value=\"" + values[i] + "\">");			
				}	
			},		
			// rowIndex는 1부터 시작한다.
			addDataValues: function(values)
			{
				for (var i=0; i<values.length; i++) {
					var values2 = values[i];
					for (var j=0; j<values2.length; j++) {
						new Insertion.Bottom("excelForm", "<input name=\"excelRow" + (i+1) + "\" id=\"excelRow" + (i+1) + "\" type=\"hidden\" value=\"" + values2[j] + "\">");
					}
				}				
				new Insertion.Bottom("excelForm", "<input name=\"rowCount\" id=\"rowCount\" type=\"hidden\" value=\"" + values.length + "\">");
			},			
			download: function()
			{
				$("excelForm").submit();
				document.body.removeChild(this.hiddenDiv); 
			}
	};		
	var Conditions = Class.create();
	Conditions.prototype = {			
			initialize: function(isParenthesisValue, outerConjunctionValue)
			{
				this.conditionList = new Array();
				if(isParenthesisValue != null) {
					this.isParenthesis = isParenthesisValue;
				}
				if(outerConjunctionValue != null) {
					this.outerConjunction = outerConjunctionValue;
				}
			},	
			addCondition: function(name, operator, value, conjunction)
			{				
				this.conditionList[this.conditionList.length] = conjunction + " " + name.underscore() + " " + operator + " " + value ;
			},			
			toString: function()
			{
				var conditions = "";				
				if(this.isParenthesis) {
					conditions += this.outerConjunction + "(";
				}				
				for(var i=0; i<this.conditionList.length; i++) {
					conditions += this.conditionList[i] + " ";
				}				
				if(this.isParenthesis) {
					conditions += ")";
				}				
				return conditions;
			}
	};	
	var Orders = Class.create();
	Orders.prototype = {
			initialize: function()
			{
				this.orderList = new Array();
			},			
			addOrder: function(name, type, conjunction)
			{
				this.orderList[this.orderList.length] = conjunction + " " + name.underscore() + " " + type;
			},			
			toString: function()
			{
				var orders = " order by ";				
				for(var i=0; i<this.orderList.length; i++) {
					orders += this.orderList[i] + " ";
				}				
				return orders;
			}
	};
	// TMAX	//
	function popHelp(admMenuCd)
	{
		var pageUrl = getPageUrl();
		var url = "help.jsp?admMenuCd=" + admMenuCd + "&pageUrl=" + pageUrl;
		WindowUtils.openWindow(url, "helpWindow", "600", "400", "Y");
	}	
	function checkLogin(admIdx)
	{
		if(admIdx == "null") {
			alert("Please log in first.");
			top.location.href = "admin_index.jsp";
		}
	}
	function selfDownload(context, attachCdVal, parentIdxVal, idxVal)
	{	
		if (idxVal != null && idxVal != "") {
			self.location.href = context+"/file_download.do?attachCd="+attachCdVal+"&parentIdx="+parentIdxVal+"&idx="+idxVal;
		}
	}
	function relateDownload(context, attachCdVal, psCd, idxVal)
	{	
		if (idxVal != null && idxVal != "") {
			self.location.href = context+"/file_download.do?attachCd="+attachCdVal+"&psCd="+psCd+"&idx="+idxVal;
		}
	}	
	function checkMemLogin(memIdx)
	{
		if(memIdx == "" || memIdx == null) {
			if (location.pathname.indexOf("signin.jsp") == -1) {
				view("shadow01");
			} else {
				self.location = "/jsp/member/signin.jsp?menuCd=00REMP";
			}
		}
	}	
	function getDomain(val) 
	{		
		var currDomain = document.URL;
		currDomain = currDomain.split("//");
		currDomain = "http://" + currDomain[1].substr(0, currDomain[1].indexOf("/"));		
		return currDomain;
	}

