<!--

// 카페생성 스크립트
cafeMemo = function(){
	this.docXML;				// XML데이터 return 값
	this.callback = null;		// XML결과 return함수
	this.httpRequest = null;	// httpRequest객체
	this.ListArea = document.getElementById("ListArea");

	// httpRequest 객체 생성 함수
	cafeMemo.prototype.getXMLHttpRequest = function() {
		if (window.ActiveXObject) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e1) { return null; }
			}
		} else if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else {
			return null;
		}
	}	//	end getXMLHttpRequest function
	
	// httpRequest send 함수
	cafeMemo.prototype.sendRequest = function(url, params, callback, method) {
		this.callback = callback;

		this.httpRequest = this.getXMLHttpRequest();
		var httpMethod = method ? method : 'GET';
		if (httpMethod != 'GET' && httpMethod != 'POST') {
			httpMethod = 'GET';
		}
		var httpParams = (params == null || params == '') ? null : params;
		var httpUrl = url;
		if (httpMethod == 'GET' && httpParams != null) {
			httpUrl = httpUrl + "?" + httpParams;
		}
		this.httpRequest.open(httpMethod, httpUrl, true);
		this.httpRequest.setRequestHeader(
			'Content-Type', 'application/x-www-form-urlencoded');
		
		var request = this;
		this.httpRequest.onreadystatechange = function() {
			request.onStateChange.call(request);
		}
		this.httpRequest.send(httpMethod == 'POST' ? httpParams : null);	
	}	// end sendRequest function

	// httpRequest return 함수
	cafeMemo.prototype.onStateChange = function() {
		this.callback(this.httpRequest);
	}	// end onStateChange end	

	// XML결과
	cafeMemo.prototype.resultXML = function(){
		if(this.httpRequest.readyState == 4){
			if(this.httpRequest.status == 200){

				//alert(this.httpRequest.responseText);
				this.docXML = this.httpRequest.responseXML;
				code = this.docXML.getElementsByTagName("code").item(0).firstChild.nodeValue;	// 결과코드

				// 결과 실행
				switch (code){
					case 'ErrorMsg':
						message = this.docXML.getElementsByTagName("message").item(0).firstChild.nodeValue;	// 리턴메시지
						alert(message);
						break;

					case 'memoLoad':
						this.resetMemo();
						break;

					case 'idCheck':
						
						break;

					default:
						alert("결과코드 없음");
						break;
				}
			}
		}
	}	// end resultXML function

	cafeMemo.prototype.resetMemo = function(){
		document.memoForm.reset();
		this.removeTable();
		this.createList();
		this.createPaging();
	}

	// 리스트삭제
	cafeMemo.prototype.removeTable = function(){
		totalList = this.ListArea.childNodes.length;
		for(i = 0; i < totalList; i++){
			this.ListArea.removeChild(this.ListArea.childNodes[0]);
		}
	}
	
	// 리스트생성
	cafeMemo.prototype.createList = function() {
		totalList = this.docXML.getElementsByTagName("cafeMemo").length;
		this.CID = this.docXML.getElementsByTagName("CID").item(0).firstChild.nodeValue;
		objParam = this.docXML.getElementsByTagName("param").item(0);

		this.pageCode = objParam.getAttribute("pageCode");
		this.listBlock = objParam.getAttribute("listBlock");
		this.page = objParam.getAttribute("page");

		if(totalList > 0){
			for(j = 0; j < totalList; j++){
				memoObj = this.docXML.getElementsByTagName("cafeMemo").item(j);
				content = memoObj.firstChild.nodeValue;			// 회원num
				memberID = memoObj.getAttribute('memberID');	// id
				name = memoObj.getAttribute('name');			// 이름
				num = memoObj.getAttribute('num');	// 내용
				regDate = memoObj.getAttribute('regDate');	// 등록일
				icon = memoObj.getAttribute('icon');	// 등록일
				tmpNum = memoObj.getAttribute('tmpNum');		// 

				htmlTR = document.createElement("TR");
				htmlTR.setAttribute('height', '22');
				this.ListArea.appendChild(htmlTR);
								
				// 이름(아이디)
				htmlTD = document.createElement("TD");
				htmlTD.setAttribute('align', 'center');
				htmlTD.className = "td_bot4";
				htmlTD.setAttribute("width", 100);
				htmlTD.setAttribute("height", 25);
				htmlTD.setAttribute("align", "center");
				//this.createEvent(memberID, "info");
				htmlTR.appendChild(htmlTD);

				img =document.createElement("img");
				img.setAttribute('src', '../images/icon/'+icon+'.gif');
				img.setAttribute('align', 'absmiddle');
				//htmlTD.appendChild(img);

				txtNode = document.createTextNode(name+"("+memberID+")");
				htmlTD.appendChild(txtNode);

				// 바 
				htmlTD = document.createElement("TD");
				htmlTD.setAttribute('align', 'center');
				htmlTD.className = "td_bot4";
				htmlTR.appendChild(htmlTD);

				img =document.createElement("img");
				img.setAttribute('src', '../images/sub/bar02.gif');
				img.setAttribute('align', 'absmiddle');
				htmlTD.setAttribute("width", 13);
				htmlTD.appendChild(img);

				// 내용
				htmlTD = document.createElement("TD");
				htmlTD.setAttribute('align', 'left');
				htmlTD.className = "td_bot4";
				htmlTR.appendChild(htmlTD);

				txtNode = document.createTextNode(content);
				htmlTD.appendChild(txtNode);
				txtNode = document.createTextNode("("+regDate+")");
				htmlTD.appendChild(txtNode);

				// 등록일
				htmlTD = document.createElement("TD");
				htmlTD.setAttribute('align', 'center');
				htmlTD.className = "td_bot4";
				this.createEvent(num, content, name, icon);				
				htmlTR.appendChild(htmlTD);
				img =document.createElement("img");
				img.setAttribute('src', '../images/button/btn_del3.gif');
				img.setAttribute('align', 'absmiddle');

				htmlTD.appendChild(img);

			}
		} else {
			htmlTR = document.createElement("TR");
			htmlTR.setAttribute('height', '22');
			this.ListArea.appendChild(htmlTR);
			

			htmlTD = document.createElement("TD");
			htmlTD.setAttribute('align', 'center');
			htmlTD.setAttribute('colspan', 8, 0);
			htmlTD.className = "td_bot4";
			htmlTR.appendChild(htmlTD);

			txtNode = document.createTextNode("등록된 글이 없습니다.");
			htmlTD.appendChild(txtNode);
		}
	}

	cafeMemo.prototype.createEvent = function(num, content, name, icon){
		htmlTD.onclick = function() {cafeMemo.setEvent(num, content, name, icon);};
		htmlTD.style.cursor = "pointer";
	}

	cafeMemo.prototype.setEvent = function(num, content, name, icon){
		memoForm.name.value = name;
		memoForm.content.value = content;
		memoForm.num.value = num;
//		if(icon == "boy2"){
//			memoForm.icon[0].checked = true;
//		} else {
//			memoForm.icon[1].checked = true;
//		}

		document.getElementById("btnArea1").style.display = "none";
		document.getElementById("btnArea2").style.display = "block";
	}

	cafeMemo.prototype.cancelMemo = function(){
		document.getElementById("btnArea1").style.display = "block";
		document.getElementById("btnArea2").style.display = "none";

		memoForm.reset();
	}

	// 페이징
	cafeMemo.prototype.createPaging = function(){
		var my_page;
		
		pagingObj = this.docXML.getElementsByTagName("paging").item(0);

		page = pagingObj.firstChild.nodeValue;						// 현재페이지
		total_page = pagingObj.getAttribute('total_page');			// 전체페이지
		total_block = pagingObj.getAttribute('total_block');		// 전체 페이지 블럭
		block = pagingObj.getAttribute('block');					// 현재 페이지 블럭
		first_page = pagingObj.getAttribute('first_page');			// 첫번재 페이지
		last_page = pagingObj.getAttribute('last_page');			// 마지막 페이지
		prev_page = pagingObj.getAttribute('prev_page');			// 이전 페이지
		next_page = pagingObj.getAttribute('next_page');			// 다음 페이지
	

		// 이전페이지
		if(block > 1){
			my_page = first_page;
			prevnav = "<a onclick=\"cafeMemo.requestXML('memoLoad', '"+this.CID+"', '','"+my_page+"');\" style='cursor:pointer'><img src='../images/button/btn_pre.gif' align='absbottom' border='0'>이전</a>&nbsp;&nbsp;";
		} else {
			prevnav = "";
		}
		b = "";

		for(direct_page = parseInt(first_page)+1; direct_page <= last_page; direct_page++){
			if(page == direct_page){
				b += "<strong><font color=\"#F8452B\">["+direct_page+"]</font></strong>";
			}else{
				b += " [<a onclick=\"cafeMemo.requestXML('memoLoad', '"+this.CID+"','', '"+direct_page+"');\" style='cursor:pointer'>"+direct_page+"</a>] ";
			}
		}


		// 다음페이지
		if(block < total_block){
			my_page = parseInt(last_page)+1;
			nextnav = "&nbsp;&nbsp;<a onclick=\"cafeMemo.requestXML('memoLoad', '"+this.CID+"','', '"+my_page+"');\" style='cursor:pointer'>다음<img src=\"../images/button/btn_next.gif\" border=\"0\" align=\"absmiddle\" /></a>";
		} else {
			nextnav = "";
		}
		document.getElementById("pagingArea").innerHTML =  prevnav + b + nextnav;
	}

	// 쪽지저장
	cafeMemo.prototype.requestXML = function(action, CID, pageCode, page) {
		form = document.memoForm;

		params = "&CID="+CID;
		params += "&pageCode="+pageCode;
		params += "&page="+page;
		params += "&action="+action;

		if(action == "delete"){
			if(!confirm("삭제하시겠습니까?")){
				return false;
			}
		}

		if(action == "write" || action == "modify" || action == "delete"){
			if(trim(form.name.value) == ""){
				alert("이름을 입력하세요.");
				form.name.focus();
				return false;
			}

			if(trim(form.content.value) == ""){
				alert("내용을 입력하세요.");
				form.content.focus();
				return false;
			}

			if(trim(form.password.value) == ""){
				alert("비밀번호를 입력하세요.");
				form.content.focus();
				return false;
			}
			params += "&password="+form.password.value;
			params += "&name="+form.name.value;
			params += "&content="+form.content.value;	
//			if(form.icon[0].checked){
//				params += "&icon="+form.icon[0].value;
//			} else {
//				params += "&icon="+form.icon[1].value;
//			}
			if(action == "modify" || action == "delete"){
				params += "&num="+form.num.value;
			}
		}

		this.sendRequest("/core/xml/cafe/cafeMemo.xml.html", params, this.resultXML, "POST");
	}	


	
}	// end cafeMemo Class

//-->
