String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll = function(str1, str2){
	var temp_str = "";

	if (this.trim() != "" && str1 != str2){
		temp_str = this.trim();

		while (temp_str.indexOf(str1) > -1){
			temp_str = temp_str.replace(str1, str2);
		}
	}

	return temp_str;
}

//@ 쿠키관련
/**
 * setCookie( "is_end", "done" , 1); -> 쿠키보관일 : 하루

 * if (getCookie( "is_end" ) == "done") {
 *		alert('쿠키가 만료되었습니다.');
 * }
 **/
function setCookie(name, value, expiredays){
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function getCookie(uName) {
	var flag = document.cookie.indexOf(uName+'=');
	if (flag != -1) { 
		flag += uName.length + 1
		end = document.cookie.indexOf(';', flag) 
		if (end == -1) end = document.cookie.length
		return unescape(document.cookie.substring(flag, end))
	}
}

function deleteCookie( cookieName ){
	var expireDate = new Date();

	//어제 날짜를 쿠키 소멸 날짜로 설정한다.
	expireDate.setDate( expireDate.getDate() - 1 );
	document.cookie = cookieName + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";
}



function winpopup(str, idx, sno, tp, lf, wd, ht, sc) {
	if ( getCookie(str) != "done" ) { 
		noticeWindow = window.open('/popup/popup.asp?idx='+idx,'popup'+idx,'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=' + sc + ',resizable=no,width=' + wd + ',height=' + ht + ',top=' + tp + ',left=' + lf); 
        if (noticeWindow) 
        {
            noticeWindow.opener = self; 
            noticeWindow.window.moveTo(400*sno+sno*10, 0);
            noticeWindow.focus();
        }
	}
}

function newPopup(href,width,height,top,left) {
	window.open(href, "", "toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=no, scrollbars=no, width="+width+", height="+height+",top="+top+",left="+left);
}

//@ 문자열에 체크
function isValid(VType, sBuf){
	var	numbers	= "1234567890";
	var	chars	= "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";

	if(VType == "NumOnly") var	charnum	= numbers;
	if(VType == "NumChar") var	charnum	= numbers + chars;

	for ( var i=0; i<sBuf.length; i++ ) {
		if (charnum.indexOf(sBuf.charAt(i)) < 0) {
			return false;
		}
	}
	return true;
}



//@ 이메일 유효성 검사
function checkEmail(Email){
	//email 체크
	var strEmail = Email;
    var i;
    var strCheck1 = false;
    var strCheck2 = false;
	var iEmailLen = strEmail.length
	
	if (iEmailLen > 0) {
		// strEmail 에 '.@', '@.' 이 있는 경우 에러메시지.
		// strEmail의 맨앞 또는 맨뒤에  '@', '.' 이 있는 경우 에러메시지.
		if ((strEmail.indexOf(".@") != -1) || (strEmail.indexOf("@.") != -1) ||
			(strEmail.substring(0,1) == ".") || (strEmail.substring(0,1) == "@") ||
			(strEmail.substring(iEmailLen-1,iEmailLen) == ".") || (strEmail.substring(iEmailLen-1,iEmailLen) == "@"))
		{	
			return false;
		}
	    for ( i=0; i<iEmailLen; i++ ) {
	        if ( (strEmail.substring(i,i+1) == ".") || (strEmail.substring(i,i+1) == "-") || (strEmail.substring(i,i+1) == "_") ||
				((strEmail.substring(i,i+1) >= "0") && (strEmail.substring(i,i+1) <= "9")) ||
				((strEmail.substring(i,i+1) >= "@") && (strEmail.substring(i,i+1) <= "Z")) ||
				((strEmail.substring(i,i+1) >= "a") && (strEmail.substring(i,i+1) <= "z")) ) {
	                if (strEmail.substring(i,i+1) == ".")
						strCheck1 = true;
	                if (strEmail.substring(i,i+1) == "@")
						strCheck2 = true;
	        }
	        else {
				return false;
	        }
	    }
	
	    if ((strCheck1 == false) || (strCheck2 == false)) {
			return false;
	    }
		return true;
	} else{
		return false;
	}
	
}



//@ 주민번호 체크
function ChksocialidNum(socialid, socialid1) {
    var sum = 0;

    sum += socialid.charAt(0)*2;
    sum += socialid.charAt(1)*3;
    sum += socialid.charAt(2)*4;
    sum += socialid.charAt(3)*5;
    sum += socialid.charAt(4)*6;
    sum += socialid.charAt(5)*7;
	    
    sum += socialid1.charAt(0)*8;
    sum += socialid1.charAt(1)*9;
    sum += socialid1.charAt(2)*2;
    sum += socialid1.charAt(3)*3;
    sum += socialid1.charAt(4)*4;
    sum += socialid1.charAt(5)*5;

    check = (11 - sum % 11) % 10;

    if (socialid1.charAt(6) != check || (socialid.length != 6 && socialid1.length != 7))
    {
        return false;
    }
	    
    if(!(socialid1.charAt(0) == '1' || socialid1.charAt(0)  == '2' ||
		 socialid1.charAt(0) == '3' || socialid1.charAt(0) == '4'))
    {
    	return false;
    }

   return true;
}


//@ 글자 자르기
function strInsertBr(str, cnt) 
{
	var tmp = "";
	for (var i=0; i<str.length; i++) 
	{
		tmp += str.substr(i,1);
		if (i % cnt == cnt-1) tmp += "<br>";
	}
	return tmp;
}

//@ 리스트 타이틀 글자 자르기
function strCut(str, cnt) 
{
	var tmp = "";
	if (str.length > cnt)
	{
		tmp = str.substr(0,cnt) + '...';
	}
	else
	{
		tmp = str;
	}
	return tmp;
}

//@ 글자 자르기
function strCut2(str, cnt) 
{
	var tmp = "";
	if (str.length > cnt)
	{
		tmp = str.substr(0,cnt);
	}
	else
	{
		tmp = str;
	}
	return tmp;
}

//@ 날짜 앞 10자리 자르기
function dateCut(strDate)
{
	var tmp = "";
	if (strDate!=''&&strDate!=null)
	{
		tmp = strDate.substr(0,10);
	}
	else
	{
		tmp = '';
	}
	return tmp;
}
/* Event : 페이지 이동 버튼 클릭   */
function h_goPage(page)
{
	p_page = page;
	this.location.href = "?" + getBoardParam() + "&page="+p_page;
}
function getBoardParam()
	{

		loc = location.search.replace("?","").split("&");
		Param = "";
		getParamList = "board_id,cate_uid,keyword,search1,search2,search3";
		getParamList = getParamList.split(",");

		for(i=0;i<loc.length;i++)
		{
			key   = loc[i].split("=")[0];
			value = loc[i].split("=")[1];

			for(j=0;j < getParamList.length; j++)
			{
				if( key == getParamList[j] && value.length != 0 ) Param += "&" + key + "=" + value;
			}
		}

		if(key == "content_uid") p_content_uid = value;

		Param = Param.replace("&","");

		return Param;
	}
