﻿
var Page = Class.create();

 Page.prototype = {
    initialize:function() { // constructor 의 역할을 하는 initialize메쏘드
    	this.page = 1;
    },

    postPage:function(idx){
      //document.getElementById("idx").value = idx;
     // document.getElementById("postPageFrm").submit();
     // tSearch.pg = page;
	  //tSearch.get(tSearch.keyword.value);
    },

    pagingQ:function(pagevar){

      switch(pagevar) {

	  		 case "b10":
	        var	pageTemp = (tSearch.pg%tSearch.lc == 0) ? pagescale : tSearch.pg%tSearch.lc;
	        page =  eval(tSearch.pg) - pageTemp;
	        break;

        case "f10":
	       var	pageTemp = (tSearch.pg%tSearch.lc == 0) ? pagescale : tSearch.pg%tSearch.lc;
	        page =  eval(tSearch.pg) - pageTemp + eval(tSearch.lc) + 1;
	        break;

        case "b1":
	        page = eval(tSearch.pg) - 1;
	        break;

        case "f1":
	        page = eval(tSearch.pg) + 1;
	        break;

	      case "b_end":
	        page = 1;
	        break;

        case "f_end":
	        page = totalpage;
	        break;

        default:
	        page = pagevar;
	        break;
      }

//		tSearch.pg = page;
//		tSearch.get(tSearch.keyword.value);
//		document.location.href="#resultArea";

      document.getElementById("pageFrm").query.value = tSearch.keyword.value;
      document.getElementById("pageFrm").nhit.value = tSearch.sort;
      document.getElementById("pageFrm").page.value = page;

      if(tSearch.cateNm == "TRIP" || tSearch.cateNm == "COMMUNITY"){
	      document.getElementById("check1").value= document.getElementById("allCheck").checked;
				document.getElementById("check2").value= document.getElementById("themeCheck").checked;
				document.getElementById("check3").value= document.getElementById("villCheck").checked;
				document.getElementById("check4").value= document.getElementById("experprogCheck").checked;
				document.getElementById("check5").value= document.getElementById("accommodationCheck").checked;
				document.getElementById("check6").value= document.getElementById("itemsCheck").checked;
				document.getElementById("check7").value= document.getElementById("restaurantCheck").checked;
				document.getElementById("check8").value= document.getElementById("tourCheck").checked;
				document.getElementById("check9").value= document.getElementById("festivalCheck").checked;
				document.getElementById("check10").value= document.getElementById("goodsCheck").checked;
			}
	  	document.getElementById("pageFrm").submit();

    }
  }



  function makePaging(page,pagescale, totalrow){
  	if(totalrow == undefined){

  		return false;

  	}
		var pagevar= "";
		page = eval(page);
		totalpage = Math.ceil(totalrow / pagescale);

    var	pageTemp = (page%pagescale == 0) ? pagescale : page%pagescale;
    var	StartPage = page - pageTemp +1;

    pageTemp = page/pagescale%pagescale;
    pageTemp = 10 - pageTemp;
    var	LastPage = Math.ceil(StartPage / pagescale)*pagescale;

    if(LastPage >= totalpage)
      LastPage = totalpage;
    pagevar += "<div class='pagenation'>";
    pagevar += "<span class='prev'>";
    if(page > pagescale){
      pagevar += "<a href=\"javascript:a.pagingQ('b_end')\" class='home'><img  alt='처음페이지' src='../image/welchon/skin/rr_btn.gif' /></a>";
    }

    if(page >=  11){
      pagevar += "<a href=\"javascript:a.pagingQ('b10')\" class='prev'>이전</a>";
    }
    pagevar += "</span>";
    pagevar += "<span class='page'>";
    for(i=StartPage;i<=LastPage;i++){
      if( page == i){
        pagevar+= "<a href=\"javascript:a.pagingQ("+i+")\" class='on'><b>"+i+"</b></a>";
      } else {
       	pagevar+= "<a href=\"javascript:a.pagingQ("+i+")\">"+i+"</a>";
      }
    }
    pagevar += "</span>";
    pagevar += "<span class='next'>";
    if(totalpage >= page +1){
       pagevar += "<a href=\"javascript:a.pagingQ('f10')\" class='next'>다음</a>";
    }

    if(LastPage < totalpage){
       pagevar += "<a href=\"javascript:a.pagingQ('f_end')\" class='end'><img  alt='마지막페이지' src='../image/welchon/skin/pp_btn.gif' /></a>";
    }
    pagevar += "</div>";
		pagevar += "</span>";
		document.getElementById("pageDiv").innerHTML = pagevar;
  }


var SearchResult = Class.create();

SearchResult.prototype = {
	initialize: function(valSearch)
	{
		this.cateObj = new Array();
		this.cateTemplet = new Array();
		this.cateCount = new Array();
		this.cateTab = new Array();
		this.cateTabCount = new Array();
		this.search = valSearch;

		this.keyword = this.createObj(this.search.inputId); // 검색어 Input
		this.keyword.value = this.search.query;
		this.keyword.instance = this;
		this.keyword.onkeydown = function(e){this.instance.enterKey(e);}


		this.searchBtn = this.createObj(this.search.searchBtn); // 검색버튼
		this.searchBtn.instance = this;
		this.searchBtn.onclick = function(e){this.instance.enterKey(e);}

		this.cateNm = this.search.cateNm;
		this.menuNm = this.createObj(this.search.menuNm);
		this.menuNm.innerHTML = this.search.categoryname[this.cateNm];



		this.qtMsg = this.createObj(this.search.qtMsg);


		this.resultArea = this.createObj(this.search.resultArea);
		this.noSearch = this.createObj(this.search.noSearch);
		//this.notAllTitle = this.createObj(this.search.notAllTitle);
		//this.notAllTitleCnt = this.createObj(this.search.notAllTitleCnt);

		//this.titleSmpl = this.createObj(this.search.titleSmpl);



		if(this.search.tabTF == true){
		 	this.setTab();
		}


		if(this.search.sortAccuracyTF == true){
		 	this.setSortAccuracy();
		}

		if(this.search.sortDateTF == true){
		  this.setSortDate();
		}

		if(this.cateNm !="ALL"){
		  this.sortObj = this.createObj(this.search.sortObj);
		  this.sortObj.instance = this;

		  this.sortAction = this.createObj(this.search.sortAction);
		  this.sortAction.instance = this;
		  this.sortAction.onclick = function(e){this.instance.clickSort(e, 0);}
		}
		if(this.cateNm == "TRIP" || this.cateNm == "COMMUNITY"){
			var tripColName = new Array("THEME","VILL","EXPERPROG","ACCOMMODATION","ITEMS","RESTAURANT","TOUR","FESTIVAL","GOODS");

			this.allCheck = this.createObj(this.search.allCheck);
			this.allCheck.instance = this;

			this.themeCheck = this.createObj(this.search.themeCheck);
			this.themeCheck.instance = this;

			this.villCheck = this.createObj(this.search.villCheck);
			this.villCheck.instance = this;

			this.experprogCheck = this.createObj(this.search.experprogCheck);
			this.experprogCheck.instance = this;

			this.accommodationCheck = this.createObj(this.search.accommodationCheck);
			this.accommodationCheck.instance = this;

			this.itemsCheck = this.createObj(this.search.itemsCheck);
			this.itemsCheck.instance = this;

			this.restaurantCheck = this.createObj(this.search.restaurantCheck);
			this.restaurantCheck.instance = this;

			this.tourCheck = this.createObj(this.search.tourCheck);
			this.tourCheck.instance = this;

			this.festivalCheck = this.createObj(this.search.festivalCheck);
			this.festivalCheck.instance = this;
			
			this.goodsCheck = this.createObj(this.search.goodsCheck);
			this.goodsCheck.instance = this;

		}

		if(this.search.sortHitTF == true){
		 	this.setSortHit();
		}

		if(this.search.topKeywordTF == true){
		 	this.setTopkeyword();
		}

		if(this.search.autoTF == true){
		 	this.setAutoComplete();
		}

		if(this.search.inResultSearchTF == true){
		 	this.setInResultSearch();
		}

		if(this.search.formSendTF == true){
		 	this.form = this.createObj(this.search.formId);
		}

		//this.setQtMsg('',0);

		this.lastQuery = "";

		this.sort = this.search.nhit;
		this.pg = this.search.page;
		if(this.pg < 0)
			this.pg = 1;
		if(this.cateNm=="ALL"){
			this.lc = 3;
		}else{
			this.lc = 10;
		}

		this.get(this.keyword.value);
		if(this.keyword.value == ""){
			this.resultArea.style.display = "none";
			//this.noSearch.style.display = "";

		}else{
			this.resultArea.style.display = "";
			//this.noSearch.style.display = "none";

		}

		this.setCategrory(this.search.category); //카테고리세팅
		if(this.search.tabTF)
			this.cateTab[this.cateNm].className = "ty2";


	},
	createObj: function(_objNm){
		try{
			var tmpObj = document.getElementById(_objNm);
			if(!tmpObj && this.search.debug)
				alert(_objNm+" id를 가진 개체가 없습니다. 다시 확인 해 주세요");

			return tmpObj
		}catch(e){
			alert(e);
			return false;
		}
	},
	enterKey: function(e)
	{
		var key = window.ActiveXObject ? window.event.keyCode : e.which;

		if(key == 13 || key == 1 || key == 0){
			this.pg = 1;
			if(this.cateNm=="ALL"){
				this.lc = 3;
			}else{
				this.lc = 10;
			}
			if(this.cateNm == "TRIP" || this.cateNm == "COMMUNITY"){
				document.getElementById("check1").value= this.check1;
				document.getElementById("check2").value= this.check2;
				document.getElementById("check3").value= this.check3;
				document.getElementById("check4").value= this.check4;
				document.getElementById("check5").value= this.check5;
				document.getElementById("check6").value= this.check6;
				document.getElementById("check7").value= this.check7;
				document.getElementById("check8").value= this.check8;
				document.getElementById("check9").value= this.check9;
				document.getElementById("check10").value= this.check10;

				this.form.check1.value = this.allCheck.checked;
				this.form.check2.value = this.themeCheck.checked;
				this.form.check3.value = this.villCheck.checked;
				this.form.check4.value = this.experprogCheck.checked;
				this.form.check5.value = this.accommodationCheck.checked;
				this.form.check6.value = this.itemsCheck.checked;
				this.form.check7.value = this.restaurantCheck.checked;
				this.form.check8.value = this.tourCheck.checked;
				this.form.check9.value = this.festivalCheck.checked;
				this.form.check10.value = this.goodsCheck.checked;
				}
			this.goTab("?");
			//this.get();

		}
	},
	clickInResult: function(e, obj)
	{
		var key = window.ActiveXObject ? window.event.keyCode : e.which;

		if(key == 1 || key == 0){
			if(obj.checked == true){
				this.inResultWord = this.keyword.value;
			}else{
				this.inResultWord = "";
			}


		}

	},
	clickSort: function(e, sort)
	{
		var key = window.ActiveXObject ? window.event.keyCode : e.which;

		if(key == 1 || key == 0){

				this.sort = this.sortObj.value;
				this.goTab("?");
				//this.get(this.keyword.value);
		}

	},
	get: function()
	{
		value = this.keyword.value;
		lastQuery = value;
		var url = jsonSrc;


	if(this.search.cateNm == "BLOG" || this.search.cateNm == "ALLBOARD" ){

		url = "http://211.241.9.213:8080/ProCMSv2/searchAll.jsp?searchVal="+value+"&type=Blog&pg="+this.pg;
		//url = "./js/xautocomplete.js";
		var script = document.createElement("script");
	    script.setAttribute("src",url);
	    script.setAttribute("type","text/javascript");
	    document.body.appendChild(script);


	}else{
		if(this.search.cateNm == "TRIP"){
			var collNmae = "";
			var srchgbn = "TRIP";
			var tripColName = new Array("THEME","VILL","EXPERPROG","ACCOMMODATION","ITEMS","RESTAURANT","TOUR","FESTIVAL","GOODS");
			var tripChkIdName = new Array("themeCheck","villCheck","experprogCheck","accommodationCheck","itemsCheck","restaurantCheck","tourCheck","festivalCheck","goodsCheck");
			if( this.allCheck.checked){
				collNmae = "THEME,VILL,EXPERPROG,ACCOMMODATION,ITEMS,RESTAURANT,TOUR,FESTIVAL,GOODS";
			}else{
				for( var i=0; i<tripChkIdName.length; i++){
					if( eval("this." + tripChkIdName[i]).checked ){
						collNmae += tripColName[i] + ",";
					}
				}
				if( collNmae.length > 0 ){ collNmae= collNmae.substring(0,collNmae.length-1); }
				else if(collNmae == ""){ value = ""; }
			}
			var pars = 'query=' + value + "&sort="+ this.sort+ "&colName="+ collNmae + "&pg=" +(this.pg-1)+ "&lc=" + this.lc + "&srchgbn=" + srchgbn;

		}else if(this.search.cateNm == "COMMUNITY"){
			var ftvName = "";
			var srchgbn = "COMMUNITY";
			var comuFtvName = new Array("BOARD","PHOTO","MOVIE","REVIEW","CAFE","CAFETEXT");
			var comuChkIdName = new Array("themeCheck","villCheck","experprogCheck","accommodationCheck","itemsCheck","restaurantCheck");
			if( this.allCheck.checked){
				ftvName = "BOARD,PHOTO,MOVIE,REVIEW,CAFE,CAFETEXT";
			}else{
				for( var i=0; i<comuChkIdName.length; i++){
					if( eval("this." + comuChkIdName[i]).checked ){
						ftvName += comuFtvName[i] + ",";
					}
				}
				if( ftvName.length > 0 ){ ftvName= ftvName.substring(0,ftvName.length-1); }
				else if(ftvName == ""){ value = ""; }
			}
			var pars = 'query=' + value + "&sort="+ this.sort+ "&colName="+ this.cateNm + "&pg=" +(this.pg-1)+ "&lc=" + this.lc + "&srchgbn=" + srchgbn + "&ftvName=" + ftvName;
		}else{
			var pars = 'query=' + value + "&sort="+ this.sort+ "&colName="+ this.cateNm + "&pg=" +(this.pg-1)+ "&lc=" + this.lc;
		}
		if(this.keyword.value==""){
			this.setQtMsg('',0);
			return false;
		}

		if(this.search.inResultSearchTF == true && this.inResultWord != ""){
			pars += '&oldQuery=' + this.inResultWord;
		}

		 objAjaxReq.open("POST", url, true);
		 objAjaxReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=uft-8");
		 objAjaxReq.setRequestHeader("Accept","text/xml");
		 objAjaxReq.onreadystatechange = setXml;
		 objAjaxReq.send(pars);

		}

	},
	setQtMsg: function(word, cnt){
		if(this.keyword.value==""){
			this.qtMsg.innerHTML = "<strong>검색어를 입력해 주세요</strong>";
		 	return false;
		}else{
			if(word == ""){
				word = this.keyword.value;
			}

			if(cnt == "" || isNaN(cnt) || cnt == null || cnt == undefined ||  cnt < 0){
				cnt = 0;
				this.resultArea.style.display = "none";
				//this.noSearch.style.display = "";
				this.qtMsg.innerHTML = "<strong>"+word+"</strong> 에 대한 검색결과가 없습니다";
			}
			//this.qtMsg.innerHTML = "<span class='text02 m_left01'>\""+word+"\"</span>에 대한 검색 결과는 총 <span class='text02' >"+cnt+"건</span> 입니다.";
		  else{
			  this.qtMsg.innerHTML = "<strong>"+word+"</strong> 에 대해 <em>"+cnt+"</em>건이 검색되었습니다.";
			}
				return true;
		}


	},
	makeUI : function(xml)
	{


		var totalCnt = 0;

		for(j = 0; j < this.search.category.length; j++){ //초기화

			CRID = this.search.category[j];
			var CRID2 = CRID;

			if( CRID == "TRIP" )
			  CRID2 = "THEME,VILL,EXPERPROG,ACCOMMODATION,ITEMS,RESTAURANT,TOUR,FESTIVAL,GOODS";
			var cateCnt = xml.colsCountMap[0][CRID2];
			if(cateCnt > 0){
				this.cateObj[CRID].style.background = "";
				this.cateObj[CRID].innerHTML = "";
			}else{

			}

//			var tblCnt = this.cateObj[CRID].rows.length;
//			for(i=0;i<tblCnt-1;i++){
//
//				this.cateObj[CRID].deleteRow(0);
//
//			}


			if(this.search.tabTF)
				this.cateTabCount[CRID].innerHTML = cateCnt;


			totalCnt += eval(cateCnt);

			if(this.cateNm == CRID && cateCnt == 0){

				this.resultArea.style.display = "none";

				//this.noSearch.style.display = "";
			}else if(this.cateNm == CRID && cateCnt > 0){
				this.resultArea.style.display = "";
				//this.noSearch.style.display = "none";

			}
			if(this.cateNm=="ALL" ){

				this.cateObj[CRID].style.display = "";
				//this.notAllTitle.style.display = "none";
			}else{
				this.cateObj[CRID].style.display = "none";
				//this.notAllTitle.style.display = "";
			}

			if(this.cateNm == "ALL" || this.cateNm == CRID){
				this.cateObj[CRID].style.display = "";
				//this.notAllTitleCnt.innerHTML = "총 "+cateCnt+" 건";
				if(this.cateNm != "ALL"){

					//this.totalCount.innerHTML = "총 "+cateCnt +" 건";

					makePaging( this.pg, this.lc,cateCnt);

				}else{

//				var	template = this.titleSmpl.innerHTML;
//					template = template.replace("#tabName", this.search.categoryname[CRID]);
//					template = template.replace("#cnt", cateCnt);
//					template = template.replace("#class", "h4_search_area2 clfix");
//
//					this.cateObj[CRID].innerHTML = template;
//
//					this.cateObj[CRID].innerHTML = this.cateObj[CRID].innerHTML +'<div class="h4_search_area clfix" align="center"></div>';
//

				}
			}
		}
		this.setQtMsg(lastQuery, totalCnt);

		this.setAllTabCnt(totalCnt);

		if(this.cateNm == "ALL"){

			if(totalCnt == 0){
				this.resultArea.style.display = "none";
				//this.noSearch.style.display = "";

			}else{
				this.resultArea.style.display = "";
				//this.noSearch.style.display = "none";

			}
		}

		for(i = 0; i < xml.resultResult.length; i++){

				divNm = xml.resultResult[i].CRID;
				TT = xml.resultResult[i].TT.replace(lastQuery, HIGHLIGHT_START+lastQuery+HIGHLIGHT_END);
				AT = xml.resultResult[i].AT.replace(lastQuery, HIGHLIGHT_START+lastQuery+HIGHLIGHT_END);
				CRID = xml.resultResult[i].CRID;
				WriteDate = xml.resultResult[i].DT;
				Hit = "HITS : " + xml.resultResult[i].FTD1 + " / NHIT : " + xml.resultResult[i].NHIT;
				FT = "FTD1 : " + xml.resultResult[i].FTD1 + " / FTD2 : " + xml.resultResult[i].FTD2
							+ " / FTD3 : " + xml.resultResult[i].FTD3 + " / FTD4 : " + xml.resultResult[i].FTD4
							+ " / FTV1 : " + xml.resultResult[i].FTV1 + " / FTV2 : " + xml.resultResult[i].FTV1;
				description = (xml.resultResult[i].CMT.replace(lastQuery, HIGHLIGHT_START+lastQuery+HIGHLIGHT_END));

				categoryPath = "";
				var sCRID = CRID.trim();
				if( sCRID == "THEME" ||sCRID == "VILL" ||sCRID == "EXPERPROG" ||sCRID == "ACCOMMODATION" ||sCRID == "ITEMS" ||sCRID == "RESTAURANT" ||sCRID == "TOUR" ||sCRID == "FESTIVAL" ||sCRID == "GOODS"){
				  sCRID = "TRIP";
				}

				obj = this.cateObj[sCRID];
				var fileNm = "";
				var fileType = "";
				var telNo = "";
				var	tblEl = "<div class=\"list\">";
				var base_url = "/welchon_front/handler/welchon-view?";
				var base_tour_url = "/welchon_front/handler/tour-view?";
				var base_img_url = "/welchon_front";

				var section_id = xml.resultResult[i].FD12;
				var menu_id = xml.resultResult[i].FD11;
				var post_id = xml.resultResult[i].DRID.replace(CRID+":", "");
				var post_id_param = "";
				var titleLink = "";
				var imagepath = "";
				var imageAlt = "alt='"+xml.resultResult[i].TT+"'";

				if(this.cateNm == "ALL" || this.cateNm == sCRID){

					if(CRID == "LIFE"){
						imagepath = "";
						section_id = xml.resultResult[i].FD13;
						menu_id = xml.resultResult[i].FD12;
						categoryPath = "생활" + xml.resultResult[i].FD11;

					}else if(CRID == "COMMUNITY"){
						imagepath = "";
						section_id = xml.resultResult[i].FD13;
						menu_id = xml.resultResult[i].FD12;
						categoryPath = "커뮤니티" + xml.resultResult[i].FD10;

					}else if(CRID == "BUSINESS"){
						imagepath = "";
						section_id = xml.resultResult[i].FD13;
						menu_id = xml.resultResult[i].FD12;
						categoryPath = "사업" + xml.resultResult[i].FD11;

					}else if(CRID == "CUSTCENTER"){
						imagepath = "";
						section_id = xml.resultResult[i].FD13;
						menu_id = xml.resultResult[i].FD12;
						categoryPath = "고객지원" + xml.resultResult[i].FD10;

					}else if(CRID == "SITE"){
						imagepath = "";
						categoryPath = post_id;
						
					}else if(CRID == "ATTACH"){
						fileType = xml.resultResult[i].FTV1.toUpperCase();
						section_id = xml.resultResult[i].FD17;
						imageAlt = "";
						rootCateNm = "";
						menu_id = xml.resultResult[i].FD14;
						
						if( section_id == '20090901000004' ){
					    	rootCateNm = '여행';
					    } else if( section_id == '20090901000002' ){
					    	rootCateNm = '생활';
					    }else if( section_id == '20090901000001' ){
					    	rootCateNm = '커뮤니티';
					    }else if( section_id == '20090901000003' ){
					    	rootCateNm = '사업';					    
					    }else if( section_id == '20090901000007' ){
					    	rootCateNm = '고객센터';					    
					    }else if( section_id == '' ){
					    	rootCateNm = '여행';					    
					    }else{
					    	rootCateNm = '';					    
					    }
						
						switch(fileType){
							case "PPT":
								imagepath = "/image/welchon/search/filetype_ppt.gif";
								imageAlt = "alt='파워포인트문서'";
								break;
								
							case "XLS":
								imagepath = "/image/welchon/search/filetype_xls.gif";
								imageAlt = "alt='엑셀문서'";
								break;
								
							case "DOC":
								imagepath ="/image/welchon/search/filetype_doc.gif";
								imageAlt = "alt='워드문서'";
								break;
								
							case "HWP":
								imagepath = "/image/welchon/search/filetype_hwp.gif";
								imageAlt = "alt='한글문서'";
								break;
								
							case "PDF":
								imagepath = "/image/welchon/search/filetype_pdf.gif";
								imageAlt = "alt='PDF문서'";
								break;
								
							case "HTML":
								imagepath = "/image/welchon/search/filetype_html.gif";
								imageAlt = "alt='웹문서'";
								break;
							
							case "HTM":
								imagepath = "/image/welchon/search/filetype_html.gif";
								imageAlt = "alt='웹문서'";
								break;
							
							case "TXT":
								imagepath = "/image/welchon/search/filetype_txt.gif";
								imageAlt = "alt='텍스트문서'";
								break;
								
							default:
								imagepath = "/image/welchon/search/filetype_txt.gif";
								imageAlt = "alt='일반문서'";
						}
						categoryPath = rootCateNm + xml.resultResult[i].FD12;	
						//categoryPath = "통합검색>자료실";

					}else if(CRID == "THEME"){
						section_id = "20090901000004";
						menu_id = "20090901000078";
						post_id_param = "&theme_id=";
						imagepath = xml.resultResult[i].FD8;
						categoryPath = "여행>테마여행정보";

					}else if(CRID == "VILL"){
						section_id = "20090901000004";
						menu_id = "20090901000079";
						post_id_param = "&vill_id=";
						imagepath = xml.resultResult[i].FD9;
						categoryPath = "여행>체험마을";

					}else if(CRID == "EXPERPROG"){
						section_id = "20090901000004";
						menu_id = "20090901000080";
						post_id_param = "&exper_event_id=";
						imagepath = xml.resultResult[i].FD8;
						categoryPath = "여행>체험행사";

					}else if(CRID == "ACCOMMODATION"){
						section_id = "20090901000004";
						menu_id = "20090901000081";
						post_id_param = "&lodg_id=";
						imagepath = xml.resultResult[i].FD9;
						categoryPath = "여행>숙박";

					}else if(CRID == "ITEMS"){
						section_id = "20090901000004";
						menu_id = "20090901000082";
						post_id_param = "&spec_item_id=";
						imagepath = xml.resultResult[i].FD17;
						categoryPath = "여행>특산물";

					}else if(CRID == "RESTAURANT"){
						section_id = "20090901000004";
						menu_id = "20090901000083";
						post_id_param = "&restaurant_id=";
						imagepath = xml.resultResult[i].FD12;
						categoryPath = "여행>맛집";

					}else if(CRID == "TOUR"){
						section_id = "20090901000004";
						menu_id = "20090901000084";
						post_id_param = "&tour_id=";
						imagepath = xml.resultResult[i].FD12;
						categoryPath = "여행>관광";

					}else if(CRID == "FESTIVAL"){
						section_id = "20090901000004";
						menu_id = "20090901000085";
						post_id_param = "&festival_id=";
						imagepath = xml.resultResult[i].FD17;
						categoryPath = "여행>축제";
						
					}else if(CRID == "GOODS"){
						section_id = "20090901000004";
						menu_id = "20090901000076";
						post_id_param = "&productId=";
						imagepath = xml.resultResult[i].FD11;
						categoryPath = "여행>여행상품";
					}
					

					if(sCRID != "TRIP"){
						titleLink = base_url + "section_id="+ section_id + "&menu_id=" + menu_id + "&post_id=" + post_id;
					}else if(sCRID == "TRIP"){
						titleLink = base_tour_url + "section_id="+ section_id + "&menu_id=" + menu_id + post_id_param + post_id;
					}
					if(sCRID == "SITE" ){
						titleLink = post_id;
					}
					if(CRID == "GOODS"){
						titleLink = "/mallfront/handler/Product-Detail?" + "section_id="+ section_id + "&menu_id=" + menu_id + post_id_param + post_id;
					}

					WriteDate = WriteDate.replace("-", "");
					WriteDate = WriteDate.replace("-", "");
					WriteDate = WriteDate.replace(".", "");
					WriteDate = WriteDate.replace(".", "");
					WriteDate = "<br>" + "DATE : " + WriteDate.substring(0,4)+"/"+WriteDate.substring(4,6)+"/"+WriteDate.substring(6,8) + " / " + Hit + "<br>" + FT;


					var template = this.cateTemplet[sCRID];
					if(imagepath == "" || imagepath == undefined){
						template = template.replace("#imgclass", "");
						template = template.replace("#imgtag", "style=\"display:none\"");
					}else{
						if(CRID == "GOODS"){
							imagepath = imagepath;
						}else{
							imagepath = base_img_url + imagepath;
						}
						template = template.replace("#imgclass", "thumb");
						template = template.replace("#imgtag", "");
					}

					template = template.replace("#title", TT);
					template = template.replace("#imgalt", imageAlt);
					template = template.replace("#imgerror","onError=\"this.src='\.\./image/welchon/skin/ico_NoimgM.gif'\"");
					template = template.replace("#ttLink", titleLink);
					template = template.replace("#ttLink", titleLink);
					template = template.replace("#ttLink", titleLink);
					template = template.replace("#writer", AT);
					template = template.replace("#write_date", WriteDate);
					template = template.replace("#description", description);
					template = template.replace("#category", categoryPath);
					template = template.replace("#telNo", telNo);
					template = template.replace("#imgpath", imagepath);
					if(fileNm != ""){
						splNm = fileNm.split(".");
						switch(splNm[1]){
							case "doc":
								fileSrc = "icon_ea_word.gif";
							break;
							case "xls":
								fileSrc = "icon_ea_excel.gif";
							break;
							case "ppt":
								fileSrc = "icon_ea_powerpoint.gif";
							break;
							case "hwp":
								fileSrc = "icon_ea_hangeul.gif";
							break;
							default:
								fileSrc = "ico_zip.gif";
							break;

						}

						template = template.replace("#fileNm", fileNm);
						template = template.replace("#fileSrc", fileSrc);
						template = template.replace("#fileLink", "http://211.112.153.51:8080/wcom/webdown/"+fileNm);
					}

					tblEl = tblEl + template;
			}
				var htmls = tblEl + "</div>" ;
				//if( this.cateNm == "ALL"  && sCRID == "TRIP"){
				//	htmls += "<div align=right><a href=\"javascript:tSearch.goTab('search_tour.jsp');\" class=\"more_list\">결과 더보기</a><div>";
				//}
			this.cateObj[sCRID].innerHTML +=htmls ;

		}
		

		if(this.cateNm == "ALL" || this.cateNm == sCRID){
			document.getElementById("allTabCnt").innerHTML = "(" +  totalCnt + ")";
			var businessCount = "";
			var tripCount = "";
			var custcenterCount = "";
			var communityCount = "";
			var lifeCount = "";
			var siteCount = "";
			var attachCount = "";

			for(j = 0; j < this.search.category.length; j++){ //초기화
			  CRID = this.search.category[j];

				if( CRID == "BUSINESS" ){
					businessCount = xml.colsCountMap[0][CRID];
					document.all.businessCnt.innerHTML = "(" +  businessCount + ")";
				}else if( CRID == "TRIP" ){
					CRID = "THEME,VILL,EXPERPROG,ACCOMMODATION,ITEMS,RESTAURANT,TOUR,FESTIVAL,GOODS";
					tripCount = xml.colsCountMap[0][CRID];
					document.all.tripCnt.innerHTML = "(" +  tripCount + ")";
				}else if( CRID == "CUSTCENTER" ){
					custcenterCount = xml.colsCountMap[0][CRID];
					document.all.custcenterCnt.innerHTML = "(" +  custcenterCount + ")";
				}else if( CRID == "COMMUNITY" ){
					communityCount = xml.colsCountMap[0][CRID];
					document.all.communityCnt.innerHTML = "(" +  communityCount + ")";
				}else if( CRID == "LIFE" ){
					lifeCount = xml.colsCountMap[0][CRID];
					document.all.lifeCnt.innerHTML = "(" +  lifeCount + ")";
				}else if( CRID == "SITE" ){
					siteCount = xml.colsCountMap[0][CRID];
					document.all.siteCnt.innerHTML = "(" +  siteCount + ")";
				}else if( CRID == "ATTACH" ){
					attachCount = xml.colsCountMap[0][CRID];
					document.all.attachCnt.innerHTML = "(" +  attachCount + ")";
				}

				if( xml.colsCountMap[0][CRID] == 0 ){
					if( CRID == "THEME,VILL,EXPERPROG,ACCOMMODATION,ITEMS,RESTAURANT,TOUR,FESTIVAL,GOODS" ){
						CRID = "TRIP";
				  }
			    document.getElementById(CRID + "menuNm").style.display="none";
				}
			}

			var TripAllColl = "THEME,VILL,EXPERPROG,ACCOMMODATION,ITEMS,RESTAURANT,TOUR,FESTIVAL,GOODS";

			document.getElementById("businessTabCnt").innerHTML = "(" +  xml.colsCountMap[0].BUSINESS + ")";
      document.getElementById("tripTabCnt").innerHTML = "(" +  xml.colsCountMap[0][TripAllColl] + ")";
      document.getElementById("custcenterTabCnt").innerHTML = "(" +  xml.colsCountMap[0].CUSTCENTER + ")";
      document.getElementById("communityTabCnt").innerHTML = "(" +  xml.colsCountMap[0].COMMUNITY + ")";
      document.getElementById("lifeTabCnt").innerHTML = "(" +  xml.colsCountMap[0].LIFE + ")";
      document.getElementById("siteTabCnt").innerHTML = "(" +  xml.colsCountMap[0].SITE + ")";
      document.getElementById("attachTabCnt").innerHTML = "(" +  xml.colsCountMap[0].ATTACH + ")";

	  //document.getElementById("moreView").innerHTML = "<a href=\"javascript:tSearch.goTab('search_tour.jsp');\" >결과 더보기</a>"


      var totalCnt2 = 0;

      totalCnt2 = totalCnt2 + Number( xml.colsCountMap[0].BUSINESS );
      totalCnt2 = totalCnt2 + Number( xml.colsCountMap[0][TripAllColl] );
      totalCnt2 = totalCnt2 + Number( xml.colsCountMap[0].CUSTCENTER );
      totalCnt2 = totalCnt2 + Number( xml.colsCountMap[0].COMMUNITY );
      totalCnt2 = totalCnt2 + Number( xml.colsCountMap[0].LIFE );
      totalCnt2 = totalCnt2 + Number( xml.colsCountMap[0].SITE );
      totalCnt2 = totalCnt2 + Number( xml.colsCountMap[0].ATTACH );
      document.getElementById("allTabCnt").innerHTML = "(" +  totalCnt2 + ")";

		}

	},
	goTab:function(tabNm){
//		this.pg = 1;
//		this.cateTab[this.cateNm].className = "";
//		this.cateTab[tabNm].className = "ty2";
//		this.cateNm = tabNm;
//
//		if(this.cateNm=="ALL"){
//
//				this.lc = 3;
//				document.getElementById("pageDiv").style.display="none";
//			}else{
//				this.lc = 10;
//				this.menuNm.innerHTML = this.search.categoryname[tabNm];
//				document.getElementById("pageDiv").style.display="";
//			}
//
//		this.get(this.keyword.value);

		if(this.search.formSendTF == true){
		 	this.form.query.value = this.keyword.value;
		 	this.form.action = tabNm;
		 	this.form.nhit.value = this.sort;
		 	this.form.page.value = 1;

		 	if(this.cateNm == "TRIP" || this.cateNm == "COMMUNITY"){
		 		if(this.form.action == "?"){
					document.getElementById("check1").value= this.check1;
					document.getElementById("check2").value= this.check2;
					document.getElementById("check3").value= this.check3;
					document.getElementById("check4").value= this.check4;
					document.getElementById("check5").value= this.check5;
					document.getElementById("check6").value= this.check6;
					document.getElementById("check7").value= this.check7;
					document.getElementById("check8").value= this.check8;
					document.getElementById("check9").value= this.check9;
					document.getElementById("check10").value= this.check10;

					this.form.check1.value = this.allCheck.checked;
					this.form.check2.value = this.themeCheck.checked;
					this.form.check3.value = this.villCheck.checked;
					this.form.check4.value = this.experprogCheck.checked;
					this.form.check5.value = this.accommodationCheck.checked;
					this.form.check6.value = this.itemsCheck.checked;
					this.form.check7.value = this.restaurantCheck.checked;
					this.form.check8.value = this.tourCheck.checked;
					this.form.check9.value = this.festivalCheck.checked;
					this.form.check10.value = this.goodsCheck.checked;

				}else{
					document.getElementById("check1").value= "true";
					document.getElementById("check2").value= "true";
					document.getElementById("check3").value= "true";
					document.getElementById("check4").value= "true";
					document.getElementById("check5").value= "true";
					document.getElementById("check6").value= "true";
					document.getElementById("check7").value= "true";
					document.getElementById("check8").value= "true";
					document.getElementById("check9").value= "true";
					document.getElementById("check10").value= "true";
				}
		  }
		 	this.form.submit();
		}


	},
	setCategrory: function setCategrory(category){

		var len = category.length;
		if(this.search.tabTF)
			this.cateTab["ALL"] = this.createObj("ALLTab");

		for( i=0; i<len; i++){
			var tmpObj = this.createObj(category[i]+"SMPL");

			if(tmpObj){


				this.cateObj[category[i]] = this.createObj(category[i]);

				this.cateTemplet[category[i]] = this.createObj(category[i]+"SMPL").innerHTML;
				if(this.search.tabTF){
					this.cateTab[category[i]] = this.createObj(category[i]+"Tab");
					this.cateTabCount[category[i]] = this.createObj(category[i]+"TabCNT");
				}
			}
		}

	},
	setTopkeyword: function (){

	 	ulEl = this.createObj(this.search.topKeywordId);
		var tempKeyWord = "";
		var keycount = 0;
		var tempLen  = topkeyword.length > 5 ? 5 : topkeyword.length;
		for (j=0;j<tempLen;j++){
			tempKeyWord += topkeyword[j];
			if(j != tempLen-1){
				tempKeyWord += ",";
			}
			keycount++;
			if (tempKeyWord.length > 20)
			{
				keycount--;
				break;
			}
		}
		if(keycount == 0) keycount = 1;
		//alert(keycount);
	 	//var len  = topkeyword.length > 5 ? 5 : topkeyword.length;
		var len = keycount;
	 	for(i=0;i < len; i++){
	 		aEl = document.createElement("A");
	 		uEl = document.createElement("A");
	 		aEl.instance = this;
	 		aEl.href = "#";
	 		aEl.onclick = function(e){this.instance.keyword.value = this.innerHTML; this.instance.goTab('?');};
	 		aEl.innerText = topkeyword[i];

			if (i == 0 && aEl.innerText.length > 20){
				aEl.innerText = aEl.innerText.substring(0,20)+"...";
				ulEl.appendChild(aEl);
				break;
			}

	 		ulEl.appendChild(aEl);
	 		if(i != len-1){
		 		uEl.innerText = ",";
		 		ulEl.appendChild(uEl);
			}else if(tempLen != len){
				uEl.innerText = "...";
				ulEl.appendChild(uEl);
			}
	 	}


	 },
	 setAutoComplete: function(){
	 	new TAutoComplete(this.search.autoComplete, this);

	 },
	 setInResultSearch: function(){

			this.inResultSearchChkboxId = this.createObj(this.search.inResultSearchChkboxId); // 결과내 재검색
			this.inResultSearchChkboxId.instance = this;
			this.inResultSearchChkboxId.onclick = function(e){this.instance.clickInResult(e,inResultSearchChkboxId);}
			this.inResultWord = "";

	},
	 setSortAccuracy: function(){

	   this.sortAccuracy = this.createObj(this.search.sortAccuracy); // 정확도정렬
	   this.sortAccuracy.instance = this;
	   this.sortAccuracy.onclick = function(e){this.instance.clickSort(e,1);}

	},
	 setSortDate: function(){

		this.sortDate = this.createObj(this.search.sortDate); // 날짜순 정렬
		this.sortDate.instance = this;
		this.sortDate.onclick = function(e){this.instance.clickSort(e,2);}


	},
	 setSortHit: function(){

		this.sortHit = this.createObj(this.search.sortHit); // 조회도순 정렬
		this.sortHit.instance = this;
		this.sortHit.onclick = function(e){this.instance.clickSort(e,3);}

	},
	 setTab: function(){

		this.ALLTabCNT = this.createObj(this.search.ALLTabCNT);

	},
	 setAllTabCnt: function(totalCnt){
		if(this.search.tabTF)
			this.ALLTabCNT.innerHTML = totalCnt;

	}


};




/***************************************************************************************/
/*	Search Ver 1.0
/*	제 작 일 : 2008/11/27
/*	제	 작: 연구2팀 최제홍
/*
/***************************************************************************************/
var valSearch = new String();
valSearch.debug = true;//id개체 유무 판별(세팅시에 giude역할)



{

	valSearch.inputId = "qt"; //검색창
	valSearch.inputTxt = "qtTxt"; //검색어
	valSearch.searchBtn = "qtBtn"; //검색버튼
	valSearch.qtMsg = "qtMsg"; //검색어

}//search base attribute

{
   valSearch.sortObj = "sortObj";
   valSearch.sortAction = "sortAction";
}//new_sort

{

	valSearch.sortAccuracyTF = true;
	valSearch.sortAccuracy = "sortAccBtn"; //정확도
	valSearch.sortDateTF = true;
	valSearch.sortDate = "sortDateBtn"; //최근등록순
	valSearch.sortHitTF = true;
	valSearch.sortHit = "sortHitBtn"; //조회수순

}//sort


{

	valSearch.cateNm = "";
	valSearch.menuNm = "menuNm";
	valSearch.noSearch = "noSearch";//결과값없음 메세지
	valSearch.resultArea = "resultArea"; //결과 뿌려주는 AREA wrap
	valSearch.tabTF = false;
	valSearch.ALLTabCNT = "ALLTabCNT"; //타이틀 템플릿
	//valSearch.notAllTitle = "notAllTitle";
	//valSearch.notAllTitleCnt = "notAllTitleCnt";
	//valSearch.titleSmpl = "TITLESMPL"; //타이틀 템플릿

}// ui attribute

{
	valSearch.autoTF = true;
	valSearch.autoComplete = new String();
	valSearch.autoComplete.fontSize = "12px"; // 자동완성 폰트크기
	valSearch.autoComplete.listSize = "7";
	valSearch.autoComplete.autoKeywordInputId = "qt"; // 검색박스 id
}//autocomplete

{

	valSearch.inResultSearchTF = false;
	valSearch.inResultSearchChkboxId = "inResult"; //결과내 재검색

}//search in result

{
	valSearch.TourTabCheckFrm = "TourTabCheckFrm";				//여행 카테고리 체크박스
	valSearch.allCheck = "allCheck"; 											//여행 카테고리 체크박스
	valSearch.themeCheck = "themeCheck"; 									//여행 카테고리 체크박스
	valSearch.villCheck = "villCheck"; 										//여행 카테고리 체크박스
	valSearch.experprogCheck = "experprogCheck"; 					//여행 카테고리 체크박스
	valSearch.accommodationCheck = "accommodationCheck";	//여행 카테고리 체크박스
	valSearch.itemsCheck = "itemsCheck"; 									//여행 카테고리 체크박스
	valSearch.restaurantCheck = "restaurantCheck"; 				//여행 카테고리 체크박스
	valSearch.tourCheck = "tourCheck"; 										//여행 카테고리 체크박스
	valSearch.festivalCheck = "festivalCheck";						//여행 카테고리 체크박스
	valSearch.goodsCheck = "goodsCheck";						//여행 카테고리 체크박스
	valSearch.check1 = "check1";
	valSearch.check2 = "check2";
	valSearch.check3 = "check3";
	valSearch.check4 = "check4";
	valSearch.check5 = "check5";
	valSearch.check6 = "check6";
	valSearch.check7 = "check7";
	valSearch.check8 = "check8";
	valSearch.check9 = "check9";
	valSearch.check10 = "check10";

}//checkbox result

{

	valSearch.topKeywordTF = true;//인기검색 유무
	valSearch.topKeywordId = "TopKeywordUl";

}//top keyword

{

	valSearch.formSendTF = true;
	valSearch.formId = "pageFrm";

}//



pagescale = 10;
var HIGHLIGHT_START = "<font color=\"#b85c2e\">";
var HIGHLIGHT_END   = "</font>";

var jsonSrc = './toJson.jsp';
var tSearch = null;




var searchInit =  function(){
	valSearch.query = query // 파라메터로 받은 검색어
	valSearch.cateNm = cateNm.toUpperCase();
	valSearch.page = page;//인기검색 유무
	valSearch.nhit = nhit;
		if(cateNm.toUpperCase() == "TRIP" || cateNm.toUpperCase() == "COMMUNITY"){
		valSearch.check1 = check1;
		valSearch.check2 = check2;
		valSearch.check3 = check3;
		valSearch.check4 = check4;
		valSearch.check5 = check5;
		valSearch.check6 = check6;
		valSearch.check7 = check7;
		valSearch.check8 = check8;
		valSearch.check9 = check9;
		valSearch.check10 = check10;
	}
	tSearch = new SearchResult(valSearch);
	 a = new Page();

}


function tmaxRequest(tmax){
	if(document.getElementById(valSearch.inputId))
		document.getElementById(valSearch.inputId).instance.makeUI(tmax);
}

function setXml(){

	  if(objAjaxReq.readyState == 4) {
			if(objAjaxReq.status == 200 || objAjaxReq.status == 0) {
				xml =  eval('(' + objAjaxReq.responseText + ')');
				if( xml.resultResult.length);
				if( objAjaxReq.responseText ){
					document.getElementById(valSearch.inputId).instance.makeUI(xml);
				}else{
					document.getElementById("resultArea").style.display = "none";
					//document.getElementById(valSearch.noSearch).style.display = "";
					document.getElementById(valSearch.inputId).instance.setQtMsg(lastQuery, 0);
				}
			}else{
			alert(objAjaxReq.status);
			}
		}
	}
