function logOut() {
  var ReturnUrl = "";
  ReturnUrl = "http://www..hotelnjoy.com/kor/mem/mem_logout_process.php";
  //RtsUrl = "http://world.hotelnjoy.com/ASPX/Users/Logout_session.aspx?sid=MATEI-02&ReturnUrl="
  //location.href = RtsUrl + ReturnUrl;
  location.href = ReturnUrl;
}


//ajax 기본연결파일
function createRequest() {
  var request = null;
  try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = null;
      }
    }
  }
  if (request == null) {
    alert("Error creating request object!");
  } else {
    return request;
  }
}
function flashView(url,width,height,vars,m_value){
  var tgt = window.location.protocol;
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
	document.write('  codebase="'+tgt+'//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9.0.124.0" ');
	document.write('  width=100% height=100% id=\'EI_flash\' align="middle" />');
	document.write(' <param name="allowScriptAccess" value="always" />');
	document.write(' <param name="movie" value="'+url+'?'+m_value+'" />');
	document.write(' <param name="quality" value="high" />');
	document.write(' <param name="wmode" value="transparent" /> ');
	document.write(' <embed src="'+url+'?'+m_value+'" menu="false" quality="high" width="'+width+'" height="'+height+'" align="middle" ');
	document.write('	allowScriptAccess="sameDomain" type="application/x-shockwave-flash" ');
  document.write('  pluginspage="'+tgt+'//www.macromedia.com/go/getflashplayer" />');
	document.write(' </embed>');
	document.write('</object>');
}

function showCal(obj_nm,obj_no){
  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 setDateCookie(name,value) {
  var todayDate = new Date();
  todayDate.setDate(todayDate.getDate());
  document.cookie = name + "=" + escape( value ) + "; path=/;";
}

function ifrmResize(obj) {
    var Body;
    var H, Min;
    Min = 189;
    Body = (obj.contentWindow.document.getElementsByTagName('BODY'))[0];
    H = parseInt(Body.scrollHeight);
    obj.style.height = (H<Min?Min:H) + 'px';
}

function sendDate(obj_no,dateVal,chk,tgt) {
  var error = "ok";
  var objForm = document.searchForm;
  var obj = eval("objForm.v_"+obj_no+"_dt");
  obj.value = dateVal;
  setDateCookie("c_date"+obj_no,dateVal);
  document.getElementById(tgt+"_"+obj_no).style.display = "none";
  if (objForm.v_gap_dt) {
    dateGapChk();
    return false;
  } else {
    endFrame.document.location.reload();
  }
  if(objForm.v_inn_dt.value=="" && objForm.v_out_dt.value!=""){
    alert("투숙일을 선택하세요."); error="ng";
  }

  if(objForm.v_inn_dt.value!=""){
    var st = objForm.v_inn_dt.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 * 2;
    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 end_date = end.getFullYear() + "-" + month + "-" + date;
    if (objForm.v_out_dt.value=="")
      objForm.v_out_dt.value = end_date;
    var en = objForm.v_out_dt.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일 이상 검색할수 없습니다.");
      if(obj_no=="out") {
        objForm.v_out_dt.value = "";
      } else {
        objForm.v_inn_dt.value = "";
      }
    } else if(chkdate < 1){
      if(obj_no=="out")alert("검색기간을 잘못 선택 하셨습니다.");
      objForm.v_out_dt.value = "";
    } else {
    }

  }
}

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 = "";
}

function toggle_abrLayer(str,num,img) {
  if (_selected!="") {
    $(str+_selected).style.display = "none";
    $(str+"img"+_selected).src = _path+img+_selected+"_off.gif";
  }
  $(str+num).style.display = "block";
  $(str+"img"+num).src = _path+img+num+"_on.gif";
  _selected = num;
}

var newWin;
function noteWindow(locationStr, winWidth, winHeight, scrollMode) {
	optionStr = "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars="+scrollMode+",resizable=0,copyhistory=0,top=1,left=1,width="+winWidth+",height="+winHeight;
    if (newWin) {
        newWin.close();
    }
	newWin = window.open(locationStr,'note',optionStr);
    if (newWin) {
    	newWin.opener.name = this.name;
    }
}

function swfView(url,width,height){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
	document.write('  codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9.0.124.0" ');
	document.write('  width="'+width+'" height="'+height+'" align="middle" />');
	document.write(' <param name="allowScriptAccess" value="always" />');
	document.write(' <param name="movie" value="'+url+'" />');
	document.write(' <param name="menu" value="false" />');
	document.write(' <param name="quality" value="high" />');
	document.write(' <param name="wmode" value="transparent" /> ');
	document.write(' <embed src="'+url+'" menu="false" quality="high" width="'+width+'" height="'+height+'" align="middle" ');
	document.write('	allowScriptAccess="sameDomain" type="application/x-shockwave-flash" ');
  document.write('  pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write(' </embed>');
	document.write('</object>');
}

var vouWin;
function voucherWindow(locationStr, winWidth, winHeight, scrollMode) {
	optionStr = "toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars="+scrollMode+",resizable=0,copyhistory=0,top=1,left=1,width="+winWidth+",height="+winHeight;
    if (vouWin) {
        vouWin.close();
    }
	vouWin = window.open(locationStr,'wou',optionStr);
    if (vouWin) {
    	vouWin.opener.name = this.name;
    }
}

function toggleLayer(obj_nm,obj_no) {
  var obj = document.getElementById(obj_nm+obj_no).style;
  if (obj.display=="none") {
    obj.display = "block";
  } else {
    obj.display = "none";
  }
}

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 prevCal(idx1,idx2,idx3,idx4) {
  var error = "ok";
  var errmsg = "";
  var obj = parent.document.searchForm;
  var count = obj.v_room_num.value;
  var date0 = obj.v_inn_dt.value.substr(0,10);
  var date1 = obj.v_out_dt.value.substr(0,10);

  if (error=="ok" && obj.v_hotelId.value=="") {
      error = "ng";
      errmsg = "호텔을 선택해 주십시오";
  }
  if (error=="ok" && obj.v_inn_dt.value=="") {
      error = "ng";
      errmsg = "체크인날짜를 선택해 주십시오";
  }
  if (error=="ok" && obj.v_out_dt.value=="") {
      error = "ng";
      errmsg = "체크아웃날짜를 선택해 주십시오";
  }
  var qry = 'v_daily='+idx1+'&v_price='+idx2+'&v_tax='+idx3+'&v_room_num='+count+'&v_inn_dt='+date0+'&v_out_dt='+date1+'&v_agent='+idx4;
  if (error=="ok") {
    optWindow('../room/room_prev.php?'+qry,'574','300');
  } else {
    return false;
  }
}

//===========================================================

function $(id) {
    return document.getElementById(id);
}

function formData2QueryString(docForm) {
    var submitString = '';
    var formElement = '';
    var lastElementName = '';

    for(i=0;i<docForm.elements.length;i++) {
        formElement = docForm.elements[i];
        switch(formElement.type) {
            case 'text' :
            case 'select-one' :
            case 'hidden' :
            case 'password' :
            case 'textarea' :
                submitString += formElement.name + '=' + formElement.value + '&';
            break;

            case 'radio' :
                if(formElement.checked) {
                    submitString += formElement.name + '=' + formElement.value + '&';
                }
            break;

            case 'checkbox' :
                if(formElement.checked) {
                    if(formElement.name == lastElementName) {
                        if(submitString.lastIndexOf('&') == submitString.length - 1) {
                            submitString = submitString.substring(0, submitString.length - 1);
                        }
                        submitString += ',' + paramEscape(formElement.value);
                    } else {
                        submitString += formElement.name + '=' + paramEscape(formElement.value);
                    }
                    submitString += '&';
                    lastElementName = formElement.name;
                }
            break;
        }
    }
    submitString = submitString.substring(0, submitString.length - 1);
    return submitString;
}

function explain(mode) {
    $("oexplain").style.display = "none";
    $("cexplain").style.display = "none";
    if ($("oorigin")) {
        $("oorigin").style.display = "none";
        $("corigin").style.display = "block";
    }
    $(mode+"explain").style.display = "block";
    frame_resize();
    try {
        parent.frame_resize();
    } catch(e) {}
    frame_resize();
}

function origin(mode) {
    $("oorigin").style.display = "none";
    $("corigin").style.display = "none";
    $(mode+"origin").style.display = "block";
    frame_resize();
    try {
        parent.frame_resize();
    } catch(e) {}
    frame_resize();
}

function paramEscape(paramValue)
{
    return encodeURIComponent(paramValue);
}

function resizeHeight(id) {
	document.getElementById(id).width = 763;
	var the_height = document.getElementById(id).contentWindow.document.body.scrollHeight;
	document.getElementById(id).height = the_height + 30;
}
// 이미지명 on, off 토글
function toggle_tabImg(num, divname, imgsrc, agent) {
	var obj = document.getElementsByName(divname+"img");
	var root = "abr";
	if(agent) root = agent
	for(var i=0; i < obj.length; i++){
		if(num == (i+1)){
			obj[i].src = "/image/"+root+"/" + imgsrc + num + "_on.gif";
			document.getElementById(divname+num).style.display = "";
		} else {
			obj[i].src = "/image/"+root+"/" + imgsrc + (i+1) + "_off.gif";
			document.getElementById(divname+(i+1)).style.display = "none";
		}
	}
}

function postcodeView() {
  var obj = document.getElementById("country");
  var tgt = document.getElementById("postCode");
  if(obj.value=="KR") {
    tgt.style.display = "block";
  } else {
    tgt.style.display = "none";
  }
}

//**********************************//
// GNB 간편예약 함수 설정(시작)
// 09.11.02 김도성 추가
//**********************************//
function quick_res_on(opener)
{
	// Div 설정
	div_name = "quick_res";

  if (opener == true)
    div = parent.document.getElementById(div_name);
  else
    div = document.getElementById(div_name);


	if (div != null)
	{
		div.style.display = div.style.display != "block" ? "block" : "none";

		if (div.style.display != "none")
		{
			// 기본 설정
//			frm_url = "http://www.hotelnjoy.com/kor/sim/quick_mm.php";
			frm_url = "../../kor/sim/quick.php"; // 09.11.02 김도성 추가
//			frm_url = "../sim/quick.php";
			frm_width = 950;
			frm_height = 491;
			top_menu = "gnb";
			top_obj = document.getElementById(top_menu);

			// Div 스타일 설정
			with (div.style)
			{
				position = "absolute";
				width = frm_width;
				height = frm_height;
				left = top_obj.offsetLeft;
				top = top_obj.offsetTop + 45;
        top_obj.style.zIndex = 5;
				zIndex = top_obj.style.zIndex - 1;
			}

			// Div 디자인 설정
			layer = '<iframe id="quick_res" src="'+frm_url+'" width="'+frm_width+'" height="'+frm_height+'" frameborder="0" scrolling="no"></iframe>';

			// Div 출력
			div.innerHTML = layer;	// 디자인 된 레이어 div에 할당
		}

    // 숨기고 싶은 div(파일명)가 있을 경우 창이 뜨면 숨기고 닫히면 출력
    try {
      var tmp, n, obj, id;
      if (opener == true)
        tmp = parent.document.location.href.split(".php");
      else
        tmp = document.location.href.split(".php");

      tmp = tmp['0'].split("/");
      n = tmp.length - 1;
      id = tmp[n];

      if (opener == true)
        obj = parent.document.getElementById(id);
      else
        obj = document.getElementById(id);

      obj.style.display = div.style.display != "block" ? "block" : "none";
    } catch(e) {}
	}
	else	//div_id가 없는 경우 새창으로 띄우기
	{
		window.open('../sim/quick.php','popup','resizable=no,width=950,height=490,left=156,top=226,scrollbars=no');
	}
}

function zippostWindow (zipwhere,addrwhere,addrwhere2) {
	//optionStr = "dialogwidth:380px;dialogheight:300px;status:0;help:0;center:1;resizable:0"
	//window.showModalDialog('/mid/zippost/zipwindow.php?v_zipwhere='+zipwhere+'&v_addrwhere='+addrwhere+'&v_addrwhere2='+addrwhere2,window,optionStr);
	optionStr = "width=380px,height=300px,status=0,help=0,center=1,resizable=0"
	window.open('../zippost/zipwindow.php?v_pdomain='+document.domain+'&v_zipwhere='+zipwhere+'&v_addrwhere='+addrwhere+'&v_addrwhere2='+addrwhere2,'',optionStr);
}


//**********************************//
// GNB 간편예약 함수 설정(끝)
// 09.11.02 김도성 추가
//**********************************//

function showMeal(containerID) {
	var container = document.getElementById(containerID);

	var mealButton = document.getElementById("showMeal");
	var mealList = document.getElementById("Meal_open");

	mealButton.onmouseover = function() {
		mealList.style.display = "block";
	}

	mealButton.onmouseout = function() {
		mealList.style.display = "none";
	}
}
