<!--

// 카페생성 스크립트
cafeMain = function(){
	this.docXML;				// XML데이터 return 값
	this.callback = null;		// XML결과 return함수
	this.httpRequest = null;	// httpRequest객체
	this.rankArea = document.getElementById("rankArea");
	this.pageArea = document.getElementById("pageArea");
	this.rankArray = new Array();
	this.cidArray = new Array();
	this.page = 1;

	// httpRequest 객체 생성 함수
	cafeMain.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 함수
	cafeMain.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 함수
	cafeMain.prototype.onStateChange = function() {
		this.callback(this.httpRequest);
	}	// end onStateChange end	

	// XML결과
	cafeMain.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 'rankLoad':
						this.createArray();
						if(document.getElementById("cafeList") != null){ 
							this.requestXML('cafeList', '1');
						}
						break;

					case 'cafeList':
						this.cafeList();
						objPaging = this.docXML.getElementsByTagName("paging").item(0);
						totalPage = objPaging.getAttribute('totalPage');
						listBlock = objPaging.getAttribute('listBlock');
						this.page = objPaging.firstChild.nodeValue;
						if(parseInt(this.page) > 1){
							document.getElementById("cafeListPre").style.display = "block";
						} else {
							document.getElementById("cafeListPre").style.display = "none";
						}

						if(parseInt(this.page) < parseInt(totalPage)){
							document.getElementById("cafeListNext").style.display = "block";
						} else {
							document.getElementById("cafeListNext").style.display = "none";
						}
						break;

					default:
						alert("결과코드 없음");
						break;
				}
			}
		}
	}	// end resultXML function

	
	// 리스트생성
	cafeMain.prototype.createArray = function() {
		totalList = this.docXML.getElementsByTagName("cafeInfo").length;

		page = Math.floor(totalList / 10);
		if(totalList % 10 > 0){
		  page++;
		}

			if(totalList > 0){

				for(j = 0; j < totalList; j++){
			  cafeObj = this.docXML.getElementsByTagName("cafeInfo").item(j);
			  cafeTitle = cafeObj.firstChild.nodeValue;			// 카페아이디

			  cnt = cafeObj.getAttribute('cnt');	// cnt
			  CID = cafeObj.getAttribute('CID');
			  this.cidArray[j] = CID;	
			  this.rankArray[j] = cafeTitle;			// cnt

		  }
		}
		var tmp = "";
		this.pageArea.innerHTML = "";
		for(a = 1; a<= page; a++){
				param = a -1;
				tmp +="<a href='#' onclick='cafeMain.getArray("+param+")'>" +a+"</a> | ";
		}
		this.pageArea.innerHTML = tmp;
		cafeMain.getArray(0);
	}


	cafeMain.prototype.getArray = function(page){
		totalList = this.rankArea.childNodes.length;
		for(i = 0; i < totalList; i++){
			this.rankArea.removeChild(this.rankArea.childNodes[0]);
		}

		tmp = page * 10;
		for(i = tmp; i< 10 * (page +1) ; i++){
		  htmlTR = document.createElement("TR");
		  htmlTR.setAttribute('height', '20');
		  this.rankArea.appendChild(htmlTR);

		  if(this.rankArray[i]){
			htmlTD = document.createElement("TD");
			htmlTD.setAttribute("style", "padding-left:5px;");
			htmlTD.setAttribute('align', 'left');
			htmlTD.setAttribute('height', '20');
			htmlTD.className = "small";
			htmlTR.appendChild(htmlTD);
			txtNode = document.createTextNode( i+1 +"위 ");
			htmlTD.appendChild(txtNode);

			htmlTD = document.createElement("TD");
			htmlTD.setAttribute("style", "padding-left:5px;");
			htmlTD.setAttribute('align', 'left');
			htmlTD.className = "small";
			htmlTR.appendChild(htmlTD);

			tdspan = document.createElement("span");
			tdspan.innerHTML = "<span style='color: #C5C5C5; font-size: 11px;'>/</span> ";
			htmlTD.appendChild(tdspan);

			tdspan = document.createElement("span");
			tdspan.innerHTML = "<a href=\"#\" onclick=\"cafeOpen('"+this.cidArray[i]+"')\">"+this.rankArray[i]+"</a>";
			htmlTD.appendChild(tdspan);

		  }

			htmlTR = document.createElement("TR");
			this.rankArea.appendChild(htmlTR);

			htmlTD = document.createElement("TD");
			htmlTD.setAttribute('height', '1');
			htmlTD.setAttribute('bgColor', '#E7E7E7');
			htmlTR.appendChild(htmlTD);
			htmlTD = document.createElement("TD");
			htmlTD.setAttribute('bgColor', 'E7E7E7');
			htmlTR.appendChild(htmlTD);
		}
	}

	// 활동중인 카페 리스트
	cafeMain.prototype.cafeList = function(){
		var cafeList = document.getElementById("cafeList");
		totalList = cafeList.childNodes.length;
		if(totalList > 0){
			for(i = 0; i < totalList; i++){
				cafeList.removeChild(cafeList.childNodes[0]);
			}
		}
		
		totalList = this.docXML.getElementsByTagName("cafe").length;	
		for(j = 0; j < totalList; j++){

			cafeObj = this.docXML.getElementsByTagName("cafe").item(j);
			cafeTitle = cafeObj.firstChild.nodeValue;			// 메뉴num
			CID = cafeObj.getAttribute('CID');
			cnt = cafeObj.getAttribute('cnt');

			htmlTR = document.createElement("TR");
			htmlTR.setAttribute('height', '20');
			cafeList.appendChild(htmlTR);

			htmlTD = document.createElement("TD");
			htmlTR.appendChild(htmlTD);

			htmlTD.innerHTML = "<img src='/core/cafe/images/_public/ico02.gif' width='13' height='5' hspace='0' vspace='0'><a href=\"#\" onclick=\"cafeOpen('"+CID+"')\">"+cafeTitle+"</a>";
			
			htmlTD = document.createElement("TD");
			htmlTD.setAttribute("width", 90);
			htmlTD.setAttribute("align", "right");
			htmlTR.appendChild(htmlTD);

			txtNode = document.createTextNode("회원수 " + cnt +"명");
			htmlTD.appendChild(txtNode);

			htmlTD = document.createElement("TD");
			htmlTD.setAttribute("width", 50);
			htmlTD.setAttribute("align", "right");
			htmlTR.appendChild(htmlTD);

			htmlTD.innerHTML = "<img src='../images/_main/btn_gaib.gif' onclick=\"window.open('/core/cafe/view/memberWrite.html?CID=" + CID + "&pageCode=memberReg');\" style='cursor:pointer;'>";
		}
	}

	// 
	cafeMain.prototype.requestXML = function(action, flag) {
		params = "action=" + action;
		if(flag == "next"){
			this.page = parseInt(this.page) + 1;
		}
		if(flag == "pre"){
			this.page = parseInt(this.page) - 1;
		}
		params += "&page=" + this.page;
		this.sendRequest("/core/xml/cafe/cafeMain.xml.html", params, this.resultXML, "POST");
	}	


	
}	// end cafeMain Class

//-->
