String.prototype.trim = function() {
       return this.replace(/^\s+|\s+$/g,"");
}
  
String.prototype.ltrim = function() {
       return this.replace(/^\s+/,"");   
}
   
String.prototype.rtrim = function() {
       return this.replace(/\s+$/,"");   
}


function bytes(str) {
	var len = 0;
	str = this != window ? this : str;
	for (j = 0; j < str.length; j++) {
		var chr = str.charAt(j);
		len += (chr.charCodeAt() > 128) ? 2 : 1;
	}
	return len;
}

function onKeyEnter(func){
	if(event.keyCode == 13){		 
		eval(func); 
		event.returnValue=false;
	} else {
		return false;
	}
}


function onKeyEsc(func){
	if(event.keyCode == 13){		 
		eval(func); 
		event.returnValue=false;
	} else {
		return false;
	}
}


function maxByte(msg,size,obj){
	
	var getlength = bytes(obj.value);
	if(getlength == 0){
		alert(msg+"을 입력 하셔야 합니다.");
		return false;
	}
	if(size != '0'){
		if(getlength > size){
			alert(msg+" 은(는) "+size+"바이트를 초과 할수 없습니다.");
			return false;
		}
	}
	
	return true;
}




/**
 * 사용법 <div id=objTxtDiv> </div> 응답 받은 html 이 보여질 부분이다.
 */
function ajax(Url, objTxtDiv) {
	var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	var resultSetHTML;
	xmlRequest.open("POST", Url, false);
	xmlRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8;");
	
	xmlRequest.send(null);
	resultSetHTML = xmlRequest.ResponseText;
	var resultSetobj = document.getElementById(objTxtDiv);
	resultSetobj.innerHTML = resultSetHTML;
}


/*
  *Ajax에서 POST방식의 처리를 위해 입력 form의 데이터를 추출한다.
  *@author ivz@naver.com
*/
function commonFormPost(frmObj) {
	var str = "";
	var elm;
	var endName = "";
	for (i = 0, k = frmObj.length; i < k; i++) {
		elm = frmObj[i];
		switch (elm.type) {
		  case "text":
		  case "hidden":
		  case "password":
		  case "textarea":
		  case "select-one":
			str += elm.name + "=" + escape(elm.value) + "&";
			break;
		  case "select-multiple":
			sElm = elm.options;
			str += elm.name + "=";
			for (x = 0, z = sElm.length; x < z; x++) {
				if (sElm[x].selected) {
					str += escape(sElm[x].value) + ",";
				}
			}
			str = str.substr(0, str.length - 1) + "&";
			break;
		  case "radio":
			if (elm.checked) {
				str += elm.name + "=" + escape(elm.value) + "&";
			}
			break;
		  case "checkbox":
			if (elm.checked) {
				if (elm.name == endName) {
					if (str.lastIndexOf("&") == str.length - 1) {
						str = str.substr(0, str.length - 1);
					}
					str += "," + escape(elm.value);
				} else {
					str += elm.name + "=" + escape(elm.value);
				}
				str += "&";
				endName = elm.name;
			}
			break;
		}
	}

	return str.substr(0, str.length - 1);
}

/*
  *Ajax에서 POST방식의 처리를 위해 입력 form의 데이터를 추출한다.
  *@author ivz@naver.com
*/
function jqueryForm(frmObj) {
	var str = "";
	var elm;
	var endName = "";
	for (i = 0, k = frmObj.length; i < k; i++) {
		elm = frmObj[i];
		switch (elm.type) {
		  case "text":
		  	str += elm.name + "=" + encodeURI(elm.value) + "&";
			break;
		  case "hidden":
		  	
		  	str += elm.name + "=" + encodeURI(elm.value) + "&";
			break;
		  case "password":
		  	
		  	str += elm.name + "=" + encodeURI(elm.value) + "&";
			break;
			
		  
		  case "textarea":
		  
		  	
		  	str += elm.name + "=" + encodeURI(elm.value) + "&";
			break;
			
		  case "select-one":
			str += elm.name + "=" + escape(elm.value) + "&";
			break;
		  case "select-multiple":
			sElm = elm.options;
			str += elm.name + "=";
			for (x = 0, z = sElm.length; x < z; x++) {
				if (sElm[x].selected) {
					str += escape(sElm[x].value) + "&";
				}
			}
			str = str.substr(0, str.length - 1) + "&";
			break;
		  case "radio":
			if (elm.checked) {
				str += elm.name + "=" + escape(elm.value) + ":";
			}
			break;
		  case "checkbox":
			if (elm.checked) {
				if (elm.name == endName) {
					if (str.lastIndexOf("&") == str.length - 1) {
						str = str.substr(0, str.length - 1);
					}
					str += "&" + escape(elm.value);
				} else {
					str += elm.name + "=" + escape(elm.value);
				}
				str += "&";
				endName = elm.name;
			}
			break;
		}
	}
	return str.substr(0, str.length - 1);

}




function OpenWindow(nLink, nTarget, nWidth, nHeight, xPos, yPos) {
	if(typeof nLink == "object") url = nLink.href;
	else url = nLink;

	adjX = xPos ? xPos : (window.screen.width/2 - nWidth/2);
	adjY = yPos ? yPos : (window.screen.height/2 - nHeight/2 - 50);
	var qResult = window.open( url, nTarget, "width="+nWidth+", height="+nHeight+",left="+adjX+",top="+adjY+",toolbar=no,status=no,scrollbars=yes,resizable=yes");
	
	//var qResult = dhtmlwindow.open('box1', 'iframe',url,'',"width="+nWidth+", height="+nHeight+",left="+adjX+",top="+adjY+",toolbar=yes,status=yes,scrollbars=yes,resizable=yes");
	
	
	return qResult;
}

function OpenWindow2(nLink, nTarget, nWidth, nHeight, xPos, yPos) {
	if(typeof nLink == "object") url = nLink.href;
	else url = nLink;

	adjX = xPos ? xPos : (window.screen.width/2 - nWidth/2);
	adjY = yPos ? yPos : (window.screen.height/2 - nHeight/2 - 50);
	var qResult = window.open( url, nTarget, "width="+nWidth+", height="+nHeight+",left="+adjX+",top="+adjY+",toolbar=no,status=yes,scrollbars=yes,resizable=yes");
	
	//var qResult = dhtmlwindow.open('box1', 'iframe',url,'',"width="+nWidth+", height="+nHeight+",left="+adjX+",top="+adjY+",toolbar=no,status=no,scrollbars=yes,resizable=yes");
	
	
	return qResult;
}


function Countdown()
{
 var NowTime = new Date(g_DBNowTime.getTime() + (g_Timer * 1000));   
 var iGap =  Math.floor((g_LastTime.getTime() - NowTime.getTime())/(1000)); 
 var strLastTime="";

 if(iGap > 0) // 현재진행중이라면
 {
  strLastTime = FormatGap(iGap, "full");

  setTimeout("Countdown()",1000);
  g_Timer = g_Timer + 1;
 }
 else // 마감이라면...
 {
  strLastTime = "종료";
 }
  
 if(document.getElementById("hdivMessage") != "undefined")
 {
  document.getElementById("hdivMessage").innerHTML = strLastTime;
 }
} 

function FormatGap(iGap, format)
{
 var iGapTime = new Date(2000, 0, 1, 0, 0, iGap);
 var strLeftTime = "";

 if(format == "full")
 {
  if(iGapTime.getMonth() > 0 || iGapTime.getDate() > 1) strLeftTime =  "<span class='fc'>" +Math.floor(iGap/(60*60*24)) + "일 </span>";
   return strLeftTime + "<span class='fc'>" + iGapTime.getHours() + "시간 " + iGapTime.getMinutes() + "분 " + iGapTime.getSeconds() + "초 </span>";
 }
 else
 {
  return "<span class='fc'>" + iGapTime.getMinutes() + "분 " + iGapTime.getSeconds() + "초 </span>";
 }
} 


function setCookie(name,value,expiredays) 
  { 
    var todayDate = new Date(); //현재시간 구하고 
    todayDate.setDate( todayDate.getDate() + expiredays ); // 기간 설정하고 
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"  //쿠키 설정값    
    self.close(); 
  } 
 


//이미지 파일 체크 하기 
function checkFileSize(uploadImgObj){
    //
    var enableUploadFileExt=new Array("bmp","jpg","jpeg","gif","png");
    var uploadImgObjName = uploadImgObj.value;
    var startPoint = 0;
    var isImageFile = false;

    for(var i=uploadImgObjName.length-1; i>=0; i--) {
	    if(uploadImgObjName.charAt(i) == ".") {
            startPoint = i;
            break;
        }
    }
    var uploadImgObjExt = uploadImgObjName.substring(startPoint+1,uploadImgObjName.length);

    for(i=0; i<enableUploadFileExt.length; i++) {
        if(uploadImgObjExt.toLowerCase() == enableUploadFileExt[i]){
            isImageFile = true;
            break;
        }
    }
    if(!isImageFile){
        alert("이미지 파일이 아닙니다.");
        isImageFile = false;
    }

    return isImageFile;
    
}
