
/***********************************************
 * Functions which will is used the community.
 *
 */



//
// recommand
//
function recommandBoard(target, masterId, boardNum, rowIndex, grade)
{
	var sendObj = new jsAjax();
	if (sendObj) {

		sendObj.send(checkRecommend, target, "mid=" + masterId + "&bid=" + boardNum + "&rid=" + rowIndex + "&grade=" + grade, "POST");
	}	
}

function checkRecommend(xmlHttp)
{
	if (xmlHttp.status == 200)
	{
		var xmlDoc = xmlHttp.responseXML;
		var statusObjs = xmlDoc.getElementsByTagName("status");
		
		if(statusObjs && statusObjs.length) {
			
			if (statusObjs[0].childNodes[0].nodeValue == "ok") {
				
				var retMsgObj = xmlDoc.getElementsByTagName("ret-desc");
				if(retMsgObj && retMsgObj.length) {

					var recomNum = retMsgObj[0].childNodes[0].nodeValue;

					var recomcntObj = document.getElementById("cmn_brd_view_recom");
					if (recomcntObj) {
					
						recomcntObj.innerHTML = recomNum;
					}				
					alert("Tank you!\nThis item was recommanded!");
				}

			}
			else {

				var retMsgObj = xmlDoc.getElementsByTagName("ret-desc");
				if(retMsgObj && retMsgObj.length) {

					alert(retMsgObj[0].childNodes[0].nodeValue);
				}
			}
		}

	}
}

function clearText()
{
	var txtObj = document.getElementById("cmn_brd_ct_input");
	if (txtObj) {
		txtObj.innerText = "";
		txtObj.onfocus = null;

		var btnObj = document.getElementById("cmn_brd_ct_button");
		if (btnObj) {
			txtObj.innerText = "";
			btnObj.onfocus = null;
		}
	}

	

}

function checkCommetInput(formObj)
{
	var memo = formObj.memo.value;
	if (memo.length == 0) {
		
		alert("Please! Input a comment.");
		formObj.memo.focus();
		return false;
	}
	return true;
}

function deleteComment(ct_num)
{
	if (confirm("Are you sure to delete this comment?")) {

		var f = document.ctDeleteForm;

		f.ctNum.value = ct_num;

		f.submit();
	}

}

function searchItem(f)
{
	if (f.kf.selectedIndex == -1) {
		alert("Sorry! you must select what to search.");
		return false;
	} 
	
	if ((f.kw.value.length > 1) && (f.kw.value.length < 13)) {
		f.submit();
	}
	else {
		alert("Sorry! The length of keyworad is grater then 2 and less then 12.");			
		f.kw.focus();
	}
}

function deleteBoard(f)
{
	if (confirm("A contents which was deleted will not be restored!\nAre you sure delte this item?")) {
		f.submit();
	}
}


function checkReply(target, masterId, boardNums)
{
	if (boardNums.length > 0 && masterId > 0) {
		var sendObj = new jsAjax();
		if (sendObj) {
			//alert(target + "?" + "mid=" + masterId + "&bids=" + boardNums);
			sendObj.send(showReplyStatus, target, "mid=" + masterId + "&bid=" + boardNums, "GET");
		}
	}

}

function showReplyStatus(xmlHttp)
{
	if (xmlHttp.status == 200) {
		var xmlDoc = xmlHttp.responseXML;
		var statusObjs = xmlDoc.getElementsByTagName("status");

	
		if(statusObjs && statusObjs.length) {
			
			if (statusObjs[0].childNodes[0].nodeValue == "ok") {
				
				var brdObjs = xmlDoc.getElementsByTagName("board");
				if(brdObjs && brdObjs.length > 0) {

					for (var i=0; i < brdObjs.length; i++) {
						var brdObj = brdObjs[i];
						var childs = brdObj.childNodes;

						var boardNum = 0;
						var replyCnt = 0;

						for (var j=0; j < childs.length; j++) {
							var o = childs[j];
							if (o.nodeType == 1) {
								if (o.nodeName == "boardnum") {
									boardNum = o.childNodes[0].nodeValue;
								}
								else if (o.nodeName == "replycnt") {
									replyCnt = o.childNodes[0].nodeValue;
								}
							}
						}
						
						if (boardNum > 0) {
							var imgObj = document.getElementById("repl_lamp_" + boardNum);
							if (imgObj && replyCnt > 1) {
								imgObj.src = "/images/community/CmnBul_06.gif";
							}
						}

					}
				}

			}
			else {

				var retMsgObj = xmlDoc.getElementsByTagName("ret-desc");
				if(retMsgObj && retMsgObj.length) {

					alert(retMsgObj[0].childNodes[0].nodeValue);
				}
			}
		}
	}
}
