/**
    * Research Trend Common
    * @author Stone
    * @version 1.00 2009.02.14
    * @encoding UTF-8
*/


		/**
		 * 삭제 Confirm
		 * @param url, pmt
		 */
		function Del(url, pmt){
			if(confirm("삭제하시겠습니까?")){
				location.href=url+"?"+pmt;
			}		
		}
		
		
		/**
		 * 새로운 날짜값이 현재 날짜를 넘어가는지 체크
		 * 넘어가면 true, 넘어가지 않으면 false
		 * @param recordDate
		 * @return
		 */
		function isOverToday(newDate) {
			if (!checkDateFormat(newDate)) {
				alert("날짜를 0000-00-00 형태로 입력해 주십시오");
				return true;
			}
			
			var arrDate		= newDate.split("-");
			var updateDate	= new Date(arrDate[0], arrDate[1] - 1, arrDate[2]);
			var today		= new Date();
			if (updateDate > today) {
				return true;
			} else {
				return false;
			}
		}
		
		
		/**
		 * 날짜 정규식 xxxx-xx-xx
		 * @param value
		 * @return
		 */
		function checkDateFormat(value) {
			
			var inputDate = value;
			var regex = /^\d{4}-\d{2}-\d{2}$/;
			
			if (!regex.test(inputDate)) {
			    return false;
			}
			
			return true;
		}
		

		/**
		 * 수정일 체크
		 * @param form
		 * @return
		 */		
		function updateFormCheck(form) {
			if (isEmpty(form.newUpdateDate)) {
				alert("수정일 입력해 주십시오");
				return false;
			}
			if (!checkDateFormat(form.newUpdateDate.value)) {
				alert("수정일을 0000-00-00 형태로 입력해 주십시오");
				form.newUpdateDate.value = "";
				form.newUpdateDate.focus();
				return false;
			}

			if (isOverToday(form.newUpdateDate.value)) {
				alert("현재날짜 이후로는 수정이 불가능합니다.");
				return false;
			}
			
			return true;

		}
		
		
		/**
		 * 밀리세컨드값을 날짜문자열로 변환후 Input Box 에 설정 
		 * @param timeInMillis
		 * @param inputId
		 * @return
		 */
		function setDateValue(timeInMillis, inputId) {
		 var input = document.getElementById(inputId);
		 input.value = transformDateOfMilli(timeInMillis);
		}

		/**
		 * 밀리세컨트값을 0000-00-00 형태로 반환
		 */
		function transformDateOfMilli(timeInMillis) {
		 var inputDate = new Date(new Number(timeInMillis));
		 var year  = inputDate.getFullYear();
		 var month  = ((inputDate.getMonth() + 1) < 10) ? "0" + (inputDate.getMonth() + 1) : (inputDate.getMonth() + 1); 
		 var day   = (inputDate.getDate() < 10) ? "0" + inputDate.getDate() : inputDate.getDate();
		 
		 return year + "-" + month + "-" + day;
		} 
		
		
		/**
		 * 인쇄
		 * @return
		 */
		function print(uri, param, value, width){
			var widthVal = 670;
			if (width) {
				widthVal = width;
			}
			var url = "/" + uri;
			var parameter = "?" + param + "=" + value;
			var option = "height=780,width=" + widthVal + ",top=0,left=0,scrollbars=yes, status=no,location=no, directories=no, toolbar=no, menubar=no";
			window.open(url + parameter, 'PRINT', option);
		}
		
		
		function subjectSubstring(title, max){	
			var strlen = parseInt(max);		
			var bylen = parseInt(0);
			
			var c_lenc = parseInt(title.length);
			
			try{
				if(c_lenc > max){
			    	if(c_lenc > max - 1 ) {
				    	strlen = 0;
				    	for (var x = 0 ; bylen < (max-1)*2 && strlen < c_lenc ; x++) {
					    	c_char = title.charAt(strlen);
					    	ch=c_char.charCodeAt();
					    	bylen++;
					    	strlen++;
					    	if (ch>255||(ch>64&&ch< 91)) bylen++;
				    	}
			    	}
			    	if (c_lenc > strlen) {
			    		title = title.substring(0, strlen) + "..";
			    	}
				}
			} catch(e){
				//alert("e:"+e);
			}
			
			document.write(title);
		}
		// 글자수의 Max값을 주어 넘어갔을경우 ..을 붙이고 값을 반환
		
		/*
		 *  obj가 처음 나오는 곳에서 문자열을 자른다.
		 */
		function indexOfString(str, obj) {
			if (str == null || str == "") return;
			if (obj == null || obj == "") return;
			
			var resultStr = str;
			
			var idx = str.indexOf(obj);
			if (idx != -1) {
				resultStr = str.substring(0, idx);
			}
			
			return resultStr;
			
		}
		
		function commentFormCheck(commentForm){	
			if (isEmpty(document.getElementById("commentContent"))) {
				alert("댓글 내용을 입력해 주세요.");
				commentForm.commentContent.focus();
				flag = false;
				return false; }
			
			return true;
		}
		// 댓글 등록 체크
		
		
		function commentLogCheck(){
			alert('로그인 후 이용하실 수 있습니다.');
			var referrer = location.href;
			location.href = "/insertUiulForm.chem?referrer=" + encodeURIComponent(referrer);
		}
	