function cls_layer(obj_nm) {
  var num= 0;
  var obj = document.getElementsByName(obj_nm);
  while (true) {
    if (obj[num] != null) {
      obj[num].style.display = "none";
    } else {
      break;
    }
    num++;
  }
}

function tog_slayer(obj_nm,obj_no) {
  cls_layer(obj_nm);
  var obj = document.getElementsByName(obj_nm);
  obj[obj_no].style.display = "block";
}

function tog_layer(obj_nm,obj_no,dir) {
  var num= 0;
  var obj = document.getElementsByName(obj_nm);
  var ptl = location.protocol.substr(0,4).toLowerCase();
//  var ptl = document.location.protocol.replace(/:/, '').toLowerCase();
  var img = ptl=='http'? 'http://img.hotelnjoy.com':'../../image';
  	var dirroot = "kor";
	if(dir.indexOf("main/")>-1){
		dirroot = "";
	}
  while (true) {
    if (obj[num] != null) {
      obj[num].src = img+"/"+dirroot+"/"+dir+"/"+obj_nm+num+"_n.gif";
    } else {
      break;
    }
    num++;
  }
  obj[obj_no].src = img+"/"+dirroot+"/"+dir+"/"+obj_nm+obj_no+"_s.gif";
  if (obj_nm=="room_info" && obj_no=="2") {
    nmapView();
  }
  tog_slayer(obj_nm+"_",obj_no);
}

function tog_layermdl(obj_nm,obj_no,dir) {
  var num= 0;
  var obj = document.getElementsByName(obj_nm);
  var ptl = location.protocol.substr(0,4).toLowerCase();
  var img = ptl=='http'? 'http://img.hotelnjoy.com':'../../image';

  while (true) {
    if (obj[num] != null) {
      obj[num].src = img+"/"+dir+"/"+obj_nm+num+"_n.gif";
    } else {
      break;
    }
    num++;
  }
  obj[obj_no].src = img+"/"+dir+"/"+obj_nm+obj_no+"_s.gif";
  if (obj_nm=="room_info" && obj_no=="2") {
    nmapView();
  }
  tog_slayer(obj_nm+"_",obj_no);
}

function touch_layer(obj_nm,obj_no) {
  var objSrc1 = document.getElementById(obj_nm+obj_no).style;
  if (objSrc1.display=="none") {
    objSrc1.display = "block";
  } else {
    objSrc1.display = "none";
  }
}

function ifrmResize(obj) {
    var Body;
    var H, Min;
    Min = 165;
//    Min = 188;
    var doc = obj.contentWindow.document;
    Body = (doc.getElementsByTagName('BODY'))[0];
    H = parseInt(Body.scrollHeight);
    obj.style.height = (H<Min?Min:H) + 'px';
}

function showCal(obj_nm,obj_no){
//  close_layer('obj_nm');
  if (document.getElementById(obj_nm+"_"+obj_no).style.display=="none") {
    document.getElementById(obj_nm+"_"+obj_no).style.display = "block";
  } else {
    document.getElementById(obj_nm+"_"+obj_no).style.display = "none";
  }
}

function sendDate(obj_no,dateVal,chk,tgt) {
  var error = "ok";
  var objForm;
  if(chk=="x") {
  	objForm = comSerach.theForm;
  } else if (chk=="r") { //¸ÞÀÎ Search¿¡¼­ ÇØ¿ÜÈ£ÅÚ »ç¿ë
  	objForm = comSerach1.theForm;
  } else if (chk=="a") { //¸ÞÀÎ Search¿¡¼­ Ç×°ø°Ë»ö »ç¿ë //Ãß°¡
  	objForm = comSerach2.theForm;
  } else {
  	objForm = document.theForm;
  }
  var obj = eval("objForm.v_date"+obj_no);
  obj.value = dateVal;
  setDateCookie("c_date"+obj_no,dateVal);
  endFrame.document.location.reload();

//  document.all[tgt+"_"+obj_no].style.display = "none";
  document.getElementById(tgt+"_"+obj_no).style.display = "none";

  if(objForm.v_date0.value=="" && objForm.v_date1.value!=""){
    alert("Åõ¼÷ÀÏÀ» ¼±ÅÃÇÏ¼¼¿ä."); error="ng";
  }

  if(objForm.v_date0.value!=""){
    var st = objForm.v_date0.value.split("-");
    var sd = new Date(st[0],st[1]-1,st[2].substr(0,2));

    var et = new Date(st[0],st[1]-1,st[2].substr(0,2));
    var timestamp = et.getTime() + 86400000;
    var end = new Date();
    end.setTime(timestamp);

    var month = end.getMonth() + 1;
    month = month < 10 ? "0"+month : month;

    var date = end.getDate();
    date = date < 10 ? "0"+date : date;

    var week = new Array("ÀÏ", "¿ù", "È­", "¼ö", "¸ñ", "±Ý", "Åä");
    var day = week[end.getDay()];

    var end_date = end.getFullYear() + "-" + month + "-" + date + " (" + day + ")";

    if (objForm.v_date1.value=="")
      objForm.v_date1.value = end_date;

    var en = objForm.v_date1.value.split("-");
    var ed = new Date(en[0],en[1]-1,en[2].substr(0,2));
    chkdate = (ed.getTime()-sd.getTime())/(1000*24*60*60);
    if(chkdate>30){
      alert("30ÀÏ ÀÌ»ó °Ë»öÇÒ¼ö ¾ø½À´Ï´Ù.");
      objForm.v_date0.value = "";
      objForm.v_date1.value = "";
      error="ng";
    } else if(chkdate < 1){
      if(obj_no==1) {
        alert("°Ë»ö±â°£À» Àß¸ø ¼±ÅÃ ÇÏ¼Ì½À´Ï´Ù.");
//        objForm.v_date0.value = "";
        objForm.v_date1.value = "";
        error="ng";
      } else {
        objForm.v_date1.value = end_date;
      }
    }
    if(error=="ok" && chk=="c") {
//      document.theForm.action = "roomcost.php";
//      document.theForm.target = "_self";
//      document.theForm.submit();
      getInfoView();
    }
  }
}

function sendDateTest(obj_no,dateVal,chk,tgt) { //»èÁ¦¿¹Á¤
  var error = "ok";
  var objForm;
  if(chk=="x") {
  	objForm = comSerach.theForm;
  } else if (chk=="r") { //¸ÞÀÎ Search¿¡¼­ ÇØ¿ÜÈ£ÅÚ »ç¿ë
  	objForm = comSerach1.theForm;
  } else {
  	objForm = document.theForm;
  }
  var obj = eval("objForm.v_date"+obj_no);
  obj.value = dateVal;
  setDateCookie("c_date"+obj_no,dateVal);
  endFrame.document.location.reload();

//  document.all[tgt+"_"+obj_no].style.display = "none";
  document.getElementById(tgt+"_"+obj_no).style.display = "none";

  if(objForm.v_date0.value=="" && objForm.v_date1.value!=""){
    alert("Åõ¼÷ÀÏÀ» ¼±ÅÃÇÏ¼¼¿ä."); error="ng";
  }
  if(objForm.v_date0.value!="" && objForm.v_date1.value!=""){
    var st = objForm.v_date0.value.split("-");
    var en = objForm.v_date1.value.split("-");
    var sd = new Date(st[0],st[1]-1,st[2].substr(0,2));
    var ed = new Date(en[0],en[1]-1,en[2].substr(0,2));
    chkdate = (ed.getTime()-sd.getTime())/(1000*24*60*60);
    if(chkdate>30){
      alert("30ÀÏ ÀÌ»ó °Ë»öÇÒ¼ö ¾ø½À´Ï´Ù.");
      objForm.v_date0.value = "";
      objForm.v_date1.value = "";
  	  error="ng";
    } else if(chkdate < 1){
      if(obj_no==1) {
        alert("°Ë»ö±â°£À» Àß¸ø ¼±ÅÃ ÇÏ¼Ì½À´Ï´Ù.");
//        objForm.v_date0.value = "";
        objForm.v_date1.value = "";
        error="ng";
      } else {
        objForm.v_date1.value = "";
      }
    }
    if(error=="ok" && chk=="c") {
//      document.theForm.action = "roomcost.php";
//      document.theForm.target = "_self";
//      document.theForm.submit();
      getInfoViewTest();
    }
  }
}

function sendDateCoupon(obj_no,dateVal,chk,tgt) {
  var error = "ok";
  var objForm;
  if(chk=="x") {
  	objForm = comSerach.theForm;
  } else {
  	objForm = document.theForm;
  }
  var obj = eval("objForm.v_date"+obj_no);
  obj.value = dateVal;
  setDateCookie("c_date"+obj_no,dateVal);
  endFrame.document.location.reload();
  document.getElementById(tgt+"_"+obj_no).style.display = "none";
  if(objForm.v_date0.value=="" && objForm.v_date1.value!=""){
    alert("Åõ¼÷ÀÏÀ» ¼±ÅÃÇÏ¼¼¿ä."); error="ng";
  }

  if(objForm.v_date0.value!=""){
    var st = objForm.v_date0.value.split("-");
    var sd = new Date(st[0],st[1]-1,st[2].substr(0,2));

    if(error=="ok" && chk=="c") {

	  var tempDate=dateVal.split(" ");
	  tempDate = tempDate[0].split("-");

	  strCheckInYYYY  = tempDate[0];
	  strCheckInMM	= tempDate[1];
	  strCheckInDD	= tempDate[2];


	  dtCheckOut =  new Date(strCheckInYYYY,strCheckInMM - 1, parseInt(strCheckInDD,10) + 1)

	  strCheckOutYYYY = dtCheckOut.getFullYear();


	  if(parseInt(dtCheckOut.getMonth()+ 1) < 10)
		strCheckOutMM = "0"+ parseInt(dtCheckOut.getMonth()+ 1) ;
	  else
		strCheckOutMM = dtCheckOut.getMonth() + 1;


	  if(dtCheckOut.getDate().toString().length==1)
		strCheckOutDD = "0"+dtCheckOut.getDate();
	  else
		strCheckOutDD = dtCheckOut.getDate();

	  strCheckOut = strCheckOutYYYY + "-" + strCheckOutMM + "-" + strCheckOutDD


	  var tempSolar = strCheckOut.split("-");
	  dtCheckOut =  new Date(tempSolar[0],Number(tempSolar[1])-1,tempSolar[2])
	  var checkDay;

	  switch(dtCheckOut.getDay())
	  {
		case 0:
		{
			checkDay = "(ÀÏ)";
			break;
		}
		case 1:
		{
			checkDay = "(¿ù)";
			break;
		}
		case 2:
		{
			checkDay = "(È­)";
			break;
		}
		case 3:
		{
			checkDay = "(¼ö)";
			break;
		}
		case 4:
		{
			checkDay = "(¸ñ)";
			break;
		}
		case 5:
		{
			checkDay = "(±Ý)";
			break;
		}
		case 6:
		{
			checkDay = "(Åä)";
			break;
		}
	  }

	  document.theForm.v_date1.value = strCheckOut + " " + checkDay;
      if(error=="ok" && chk=="c") {
  //      document.theForm.action = "roomcost.php";
  //      document.theForm.target = "_self";
  //      document.theForm.submit();
        getInfoViewCoupon();
      }
    }
  }
}

var optWin;
function optWindow(locationStr, winWidth, winHeight)
{
	var winTop  = (parseInt(window.screen.height) - parseInt(winHeight)) / 2;
	var winLeft = (parseInt(window.screen.width)  - parseInt(winWidth))  / 2;
	optionStr = "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,copyhistory=0,top="+winTop+",left="+winLeft+",width="+winWidth+",height="+winHeight;
  if (optWin) {
      optWin.close();
  }
	optWin = window.open(locationStr,'', optionStr);
	optWin.opener.name = this.name;
}

function allSearch(tgt) {
  var error="ok";
  if(theForm.v_area1.selectedIndex==0 &&
    theForm.v_rank.selectedIndex==0 &&
    theForm.v_date0.value=="" &&
    theForm.v_date1.value=="" &&
    lTrim(theForm.v_sWord.value)=="") {
    alert("°Ë»öÁ¶°ÇÀ» ÇÑ°¡ÁöÀÌ»ó ¼±ÅÃÇÏ½Ê½Ã¿À");
    error="ng";
  }
  if(error=="ok" && theForm.v_date0.value=="" && theForm.v_date1.value!="") {
    alert("Åõ¼÷ÀÏÀ» ¼±ÅÃÇÏ½Ê½Ã¿À");
    error="ng";
  }
  if(error=="ok" && theForm.v_date0.value!="" && theForm.v_date1.value=="") {
    alert("Åð½ÇÀÏÀ» ¼±ÅÃÇÏ½Ê½Ã¿À");
    error="ng";
  }

  if(error=="ok") {
    theForm.target = tgt==undefined? "_self":tgt;
		theForm.action = "../info/search.php";
    theForm.submit();
  } else {
		return false;
	}
}

function allSearchReal(tgt) {
  var error="ok";
  if(theForm.v_area1.selectedIndex==0 &&
    theForm.v_rank.selectedIndex==0 &&
    theForm.v_date0.value=="" &&
    theForm.v_date1.value=="" &&
    lTrim(theForm.v_sWord.value)=="") {
    alert("°Ë»öÁ¶°ÇÀ» ÇÑ°¡ÁöÀÌ»ó ¼±ÅÃÇÏ½Ê½Ã¿À");
    error="ng";
  }
  if(error=="ok" && theForm.v_date0.value=="" && theForm.v_date1.value!="") {
    alert("Åõ¼÷ÀÏÀ» ¼±ÅÃÇÏ½Ê½Ã¿À");
    error="ng";
  }
  if(error=="ok" && theForm.v_date0.value!="" && theForm.v_date1.value=="") {
    alert("Åð½ÇÀÏÀ» ¼±ÅÃÇÏ½Ê½Ã¿À");
    error="ng";
  }

  if(error=="ok") {
    theForm.target = tgt==undefined? "_self":tgt;
		theForm.action = "../info/search_real.php";
    theForm.submit();
  } else {
		return false;
	}
}

function wordSearch() {
  var word = leftSchForm.v_sWord.value;
  if(lTrim(word)=="") {
    alert("°Ë»öÇÏ½Ç È£ÅÚ¸íÀ» ÀÔ·ÂÇÏ½Ê½Ã¿À");
  } else {
		leftSchForm.action = "../info/search.php";
    leftSchForm.submit();
  }
}

// ¸ÞÀÎÆäÀÌÁö ·Ñ¿À¹ö ½ºÅ©¸³Æ®
function over(obj) {
 var nm = obj.src;
 var swap = nm.replace('_off.gif','_on.gif');
 obj.src = swap;
}
function out(obj) {
 var nm = obj.src;
 var swap = nm.replace('_on.gif','_off.gif');
 obj.src = swap;
}

// document.getElementById("objectID")
// document.getElementsByName("testName");


function putWishList(pcode) {
  reqwish = createRequest();
  var url = 'ajax_putwishlist.php?v_pcode=' + pcode;
  //alert(url);
  //document.location.href = url;
  reqwish.onreadystatechange = processPutWishList;
  reqwish.open("GET", url, true);
  reqwish.send(null);
}

function processPutWishList() {
    if (reqwish.readyState == 4) {
        eval (reqwish.responseText);
    }
}

function logOut() {
  var ReturnUrl = "";
  ReturnUrl = "http://www.hotelnjoy.com/kor/mem/mem_logout_process.php";
  RtsUrl = "http://www.tablenjoy.com/mid/sso/sso_logout.php?v_return=";
  location.href = RtsUrl + ReturnUrl;

}

function change_area(val, sel) {

	var obj = document.getElementById("v_area2_sel");
	var layer = '';

	layer = '<select name="v_area2" class="sele" style="z-index:500">';
	layer = layer + '<option value="">¼±ÅÃ</option>';

	if (val) {
		var row = AREA[val];
		var selected = '';

		for (i = 1; i <= row.length; i++){
			b = i - 1;
			selected = sel == row[b] ? "selected" : '';
			layer = layer + '<option value="' + row[b] + '" ' + selected + '>' + row[b].substr(0,3) + '</option>';
		}
	}

	layer = layer + '</select>';
	obj.innerHTML = layer;
}
function closecalendar(){
	document.getElementById("cal_inn").style.display = "none";
	document.getElementById("cal_out").style.display = "none";
}
function view_useafter(idx) {
	var popUpURL = '../../abroad/room/virtual_tour.php?v_useafter=use&v_hotelId='+idx;
	window.open(popUpURL,'virtualtour','height=860,width=750,menubar=no,toolbar=no,location=no,resizable=no,status=no,scrollbars=yes');
}
function view_useaftermdl(pathurl,idx) {
	var popUpURL = '../../'+pathurl+'/room/virtual_tour.php?v_useafter=use&v_hotelId='+idx;
	window.open(popUpURL,'virtualtour','height=860,width=750,menubar=no,toolbar=no,location=no,resizable=no,status=no,scrollbars=yes');
}
var topBannerRollingCnt=-1;
var topBannerRollingArr=new Array();
var topBannerRollingArrimg=new Array();
function topBannerRolling(gubun){
	if(document.getElementById('topBannerRollingdiv')){
		if(gubun == "pre"){
			if(topBannerRollingCnt == 1){
				topBannerRollingCnt = topBannerRollingArr.length;
			} else {
				topBannerRollingCnt = topBannerRollingCnt -1;
			}

		} else {
			if(topBannerRollingCnt == topBannerRollingArr.length){
				topBannerRollingCnt = 1;
			} else {
				topBannerRollingCnt = topBannerRollingCnt +1;
			}
		}
		document.getElementById('topBannerRollingdiv').innerHTML = '<a href="'+topBannerRollingArr[topBannerRollingCnt-1]+'" onfocus="this.blur()">'+topBannerRollingArrimg[topBannerRollingCnt-1]+'</a>';
	}
}