﻿<!--
var isSubmit = false;

function CheckForm(SrCommentFrom) {

if (!isSubmit) {

	if (isField(SrCommentFrom.comment_view.value) == "") {
		alert("No comment. Please write.");
		SrCommentFrom.comment_view.focus();
		return false;
	}

	isSubmit = true;
	return true;
	}

else {
	alert("Registering. Please wait a moment.");
	return;
	}
}


function isField(keyword) {
	var st_num,key_len;
	st_num = keyword.indexOf(" ");
	while (st_num != -1){
		keyword = keyword.replace(" ", "");
		st_num  = keyword.indexOf(" ");
	}
	key_len=keyword.length;
	return key_len;
}

function GrowChar(length_limit, seq)
{
	var comment='';
	comment = eval("document.SrCommentFrom.comment_"+seq);
	var form = document.SrCommentFrom;
	var length = calculate_msglen(comment.value);
	var textlimit = document.getElementById("textlimit");
	textlimit.innerHTML = length;
	if (length > length_limit) {
		alert("Max " + length_limit + "byte. Exceeded letters will be deleted automatically.");
		comment.value = comment.value.replace(/\r\n$/, "");
		comment.value = assert_msglen(comment.value, length_limit);
/*
	} else if (length == length_limit) {
		form.comment.value = form.comment.value.replace(/\r\n$/, "");
*/
	}
}

function calculate_msglen(message)
{
	var nbytes = 0;

	for (i=0; i<message.length; i++) {
		var ch = message.charAt(i);
		if(escape(ch).length > 4) {
			nbytes += 2;
		} else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				nbytes += 1;
			}
		} else if (ch == '<' || ch == '>') {
			nbytes += 4;
		} else {
			nbytes += 1;
		}
	}

	return nbytes;
}

function assert_msglen(message, maximum)
{
	var inc = 0;
	var nbytes = 0;
	var msg = "";
	var msglen = message.length;

	for (i=0; i<msglen; i++) {
		var ch = message.charAt(i);
		if (escape(ch).length > 4) {
			inc = 2;
		} else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				inc = 1;
			}
		} else if (ch == '<' || ch == '>') {
			inc = 4;
		} else {
			inc = 1;
		}
		if ((nbytes + inc) > maximum) {
			break;
		}
		nbytes += inc;
		msg += ch;
	}

	var textlimit = document.getElementById("textlimit");
	textlimit.innerHTML = nbytes;
	return msg;
}

function GoSrMemCharCng()
{
	yesorder = confirm("You can write comment after you change writer into character name. Change?")

	if ( yesorder == true )
		UserCharCng();
}

function StopLimitExcess()
{
	alert("You can not write more comment, because the limitation is exceeded.");
}

function GoRcLogin(returnURL)
{
	yesorder = confirm("추천을 하시려면 로그인이 필요합니다.\n\n로그인을 하시겠습니까?")

	if ( yesorder == true )
		top.location.href = "/member/SR_Login.asp?path="+returnURL;
}

function ShowReply(obj,idx) {
	var showobj = obj+idx;
	var ho = eval('document.getElementById(\''+showobj+'\')');
	//var sImg_up = "reply_" + idx + "_imgup";
	//var sImg_down = "reply_" + idx + "_imgdown";

	if (ho.style.display == "none") {
		ho.style.display = "block";
		//eval(sImg_up).style.display = ""
		//eval(sImg_down).style.display = "none";
	}
	else {
		ho.style.display = "none";
		//eval(sImg_up).style.display = "none";
		//eval(sImg_down).style.display = ""
	}
	try {
		window.syncHeight("showBody");
	}
	catch ( err ) {
	// do noting
	}
}


var isSubmit2 = false;

function CheckForm2(flag) {

	var SrCommentFrom = eval("document.SrCommentFrom"+flag);

	var comment_view = eval("SrCommentFrom.comment_view"+flag);

	if (!isSubmit2) {

		if (isField(comment_view.value) == "") {
			alert("\n꼬릿말이 비어 있습니다. 내용을 입력해 주세요.");
			comment_view.focus();
			return false;
		}

		isSubmit2 = true;
		return true;
		}

	else {
		alert("등록 중입니다. 잠시 기다리세요.");
		return;
		}
}

function GrowCharRe(length_limit, seq, flag)
{
	var SrCommentFrom = eval("document.SrCommentFrom"+flag);

	var comment = eval("SrCommentFrom.comment_"+seq+flag);

	var textlimit = eval("textlimit"+flag);

	var length = calculate_msglenRe(comment.value);
	textlimit.innerHTML = length;

	if (length > length_limit) {
		alert("최대 " + length_limit + "byte입니다.\n\n초과된 글자는 자동으로 삭제됩니다.");
		comment.value = comment.value.replace(/\r\n$/, "");
		comment.value = assert_msglenRe(comment.value, length_limit, flag);
	}
}

function calculate_msglenRe(message)
{
	var nbytes = 0;

	for (i=0; i<message.length; i++) {
		var ch = message.charAt(i);
		if(escape(ch).length > 4) {
			nbytes += 2;
		} else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				nbytes += 1;
			}
		} else if (ch == '<' || ch == '>') {
			nbytes += 4;
		} else {
			nbytes += 1;
		}
	}

	return nbytes;
}

function assert_msglenRe(message, maximum, flag)
{
	var inc = 0;
	var nbytes = 0;
	var msg = "";
	var msglen = message.length;
	var textlimit = eval("textlimit"+flag);

	for (i=0; i<msglen; i++) {
		var ch = message.charAt(i);
		if (escape(ch).length > 4) {
			inc = 2;
		} else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				inc = 1;
			}
		} else if (ch == '<' || ch == '>') {
			inc = 4;
		} else {
			inc = 1;
		}
		if ((nbytes + inc) > maximum) {
			break;
		}
		nbytes += inc;
		msg += ch;
	}
	textlimit.innerHTML = nbytes;
	return msg;
}



// 실크 선물 메세지
function GrowChar_SilkGiftMsg(length_limit)
{
	var comment='';
	comment = eval("document.regform.GiftMsg");

	var form = document.regform;

	var length = calculate_msglen(comment.value);

	var textlimit = document.getElementById("textlimit");
	textlimit.innerHTML = length;
	if (length > length_limit) {
		alert("최대 " + length_limit + "byte입니다.\n\n초과된 글자는 자동으로 삭제됩니다.");
		comment.value = comment.value.replace(/\r\n$/, "");
		comment.value = assert_msglen(comment.value, length_limit);
	}
}
//-->