function get_city_cd() {
  	try {
		v_agentpath = (typeof v_agentpath === 'undefined' ? '' : v_agentpath);
    } catch(e) {
		v_agentpath = '';
    }
	cityFrame.location.href = "../inc/city.php?v_natn_cd="+document.searchForm.v_natn_cd.value+"&v_area_vl="+document.searchForm.v_area_vl.value+"&v_agentpath="+v_agentpath;
}

function clear_dt(object) {
    var iKey = event.keyCode;
    object.value = "";
}

function arng() {
    var obj = document.searchForm;
    var tmp = obj.v_area_vl.value.split("|");
    obj.v_city_cd.value = tmp[0];
    obj.v_stat_cd.value = tmp[1];
    if (obj.v_child_age1) {
      for (i=1;i<=v_totalroom;i++) {     // 객실수
          tgt = eval("obj.v_child_age"+i);
          tgt.value = "";
          for (j=1;j<=3;j++) { // 아동수
              age = eval("obj.v_child_age"+i+j);
              if (age.value!="") {
                  if (tgt.value!="") {
                      tgt.value += ",";
                  }
                  tgt.value += age.value;
              }
          }
      }
    }
    if (obj.v_amenity) {
      obj.v_amenity.value = "";
      for (i=0;i<obj.a_amenity.length;i++) {
          if (obj.a_amenity[i].checked==true) {
              if (obj.v_amenity.value!="") {
                  obj.v_amenity.value += ",";
              }
              obj.v_amenity.value += obj.a_amenity[i].value;
          }
      }
      if (obj.v_inn_dt.value=="" || obj.v_out_dt.value=="") {
          obj.v_room_num.value = "1";
          obj.v_amenity.value = "";
      }
    }
}

function send(str) {
    var obj = document.searchForm;
    mtgt = str=="top"? "_":"";
    var error = "ok";
    var errmsg = "";
    if (error=="ok" && obj.v_natn_cd.value=="") {
        error = "ng";
        errmsg = "국가를 선택해 주십시오";
    }
    if (error=="ok" && obj.v_area_vl.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 = "체크아웃 날짜를 선택해 주십시오";
    }
    if (error=="ok" && obj.v_child_age1) {
      for (i=1;i<=4;i++) {
        tmp = eval("obj.v_child"+i).value;
        if (tmp!="0") {
          for (j=1;j<=tmp;j++) {
            age = eval("obj.v_child_age"+i+j);
            if (age.value=="") {
              error = "ng";
              errmsg = "어린이 나이를 모두 선택해 주십시오";
            }
          }
        }
      }
    }

    if (error=="ok") {
        arng();
        obj.v_hotelId.value = "";
        obj.v_cacheKey.value = "";
        obj.v_cacheLocation.value = "";
        obj.v_page.value = "";
        obj.action = "../info/search"+mtgt+".php";
        obj.target = "_self";
        obj.submit();
    } else {
        alert(errmsg);
    }
}

function control_move() {
    var obj = document.searchForm;
    arng();
    obj.v_hotelId.value = "";
    obj.v_cacheKey.value = "";
    obj.v_cacheLocation.value = "";
    obj.v_page.value = "";
    obj.action = "../info/search.php";
    obj.target = "_self";
    obj.submit();
}

function control_room(cnt) {
    var obj = document.searchForm;
    if (cnt==1 && obj.v_room_num.value>1) {
      arng();
      obj.action = "../info/search.php";
      obj.submit();
      return false;
    }
    for (i=1;i<=cnt;i++) {
        if (i<=parseInt(obj.v_room_num.value)) {
            document.getElementById("l_room"+i).style.display = "block";
        } else {
            document.getElementById("l_room"+i).style.display = "none";
            eval("obj.v_adult"+i+".value = 2;");
            eval("obj.v_child"+i+".value = 0;");
        }
    }
    try {
        frame_resize();
    } catch(e) {}
}

function control_person(mod,num) {
    var adult_obj = eval("document.searchForm.v_adult"+num);
    var child_obj = eval("document.searchForm.v_child"+num);
    var adult = 0;
    var child = 0;
    var person = 0;
    for (i=0;i<adult_obj.length;i++) {
        if (adult_obj[i].selected==true) {
            adult = adult_obj[i].value;
            break;
        }
    }
    for (i=0;i<child_obj.length;i++) {
        if (child_obj[i].selected==true) {
            child = child_obj[i].value;
            break;
        }
    }
    person = parseInt(adult) + parseInt(child);
    if (person>12) {
        if (mod=="child") {
            child = 6 - adult;
            child_obj.value = child;
        } else {
            adult = 6 - child;
            adult_obj.value = adult;
        }
    }
}

function control_age() {
    var obj = document.searchForm;
    var chk = 0;
    var tot = 0;
    for (i=1;i<=v_totalroom;i++) {
        eval("chk = obj.v_child"+i+".value;");
        chk = parseInt(chk);
        if (chk>0) {
            $("l_child_age_room"+i).style.display = "block";
            for (j=1;j<=chk;j++) {
                $("l_child_age_room"+i+"_child"+j).style.display = "block";
                tot++;
            }
            for (j=chk+1;j<=6;j++) {
                $("l_child_age_room"+i+"_child"+j).style.display = "none";
                eval("obj.v_child_age"+i+j+".value = '';");
            }
        } else {
            $("l_child_age_room"+i).style.display = "none";
            for (j=1;j<=6;j++) {
                $("l_child_age_room"+i+"_child"+j).style.display = "none";
                eval("obj.v_child_age"+i+j+".value = '';");
            }
        }
    }
}

function control_amenity(object) {
    var num = 0;
    var obj = document.searchForm;
    for (i=0;i<obj.a_amenity.length;i++) {
        if (obj.a_amenity[i].checked==true) {
            num++;
        }
    }
    if (num>3) {
        object.checked = false;
        alert("3개까지 가능합니다");
    }
}

function control_chainhotel(object) {
    var num = 0;
    var obj = document.searchForm;
    var ser = "";
    for (i=0;i<obj.a_chainhotel.length;i++) {
        if (obj.a_chainhotel[i].checked==true) {
        	ser = obj.a_chainhotel[i].value;
            num++;
        }
    }
    if (num>1) {
        object.checked = false;
        alert("1개까지 가능합니다");
    } else {
    	obj.v_keyword.value = ser;
	}
}

function view(idx) {
    var obj = document.searchForm;
    arng();
    obj.v_hotelId.value = idx;
    obj.v_cacheKey.value = "";
    obj.v_cacheLocation.value = "";
    obj.action = "../room/room_view.php";
    obj.target = "_self";
    obj.submit();
}

function view_virtual(idx) {
	var popUpURL = '../room/virtual_tour.php?v_hotelId='+idx+"&"+qry;
	window.open(popUpURL,'virtualtour','height=860,width=750,menubar=no,toolbar=no,location=no,resizable=no,status=no,scrollbars=yes');
}

function view_useafter(idx) {
	var popUpURL = '../room/virtual_tour.php?v_useafter=use&v_hotelId='+idx+"&"+qry;
	window.open(popUpURL,'virtualtour','height=860,width=750,menubar=no,toolbar=no,location=no,resizable=no,status=no,scrollbars=yes');
}

function prev() {
    history.go(-1);
}

function next(key,loc) {
    var obj = document.searchForm;
    arng();
    obj.v_hotelId.value = "";
    obj.v_cacheKey.value = key;
    obj.v_cacheLocation.value = loc;
    obj.v_page.value = "";
    obj.action = "../info/search.php";
    obj.target = "_self";
    obj.submit();
}
function sort(key) {
    var obj = document.searchForm;
    arng();
    obj.v_hotelId.value = "";
    obj.v_cacheKey.value = "";
    obj.v_cacheLocation.value = "";
    obj.v_page.value = "";
    obj.v_sortMethod.value = key;
    obj.action = "../info/search.php";
    obj.target = "_self";
    obj.submit();
}
function page(num) {
    var obj = document.searchForm;
    arng();
    obj.v_hotelId.value = "";
    obj.v_cacheKey.value = "";
    obj.v_cacheLocation.value = "";
    obj.v_page.value = num;
    obj.action = "../info/search.php";
    obj.target = "_self";
    obj.submit();
}

function dateGapChk() {
  var obj = document.searchForm;
  var inn = obj.v_inn_dt.value;
  var gap = obj.v_gap_dt.value;
  if (inn=="") {
    alert('먼저 체크인 날짜를 선택하세요.');
  } else {
    var st = inn.split("-");
    var sd = new Date(st[0],st[1]-1,st[2]);
    var et = sd.getTime()+gap*(1000*24*60*60);
    var ed = new Date(et);
    var mm = ed.getMonth() + 1;
        mm = mm<10? "0"+mm:mm;
    var dd = ed.getDate();
        dd = dd<10? "0"+dd:dd;
    var re = ed.getFullYear()+"-"+mm+"-"+dd;
    obj.v_out_dt.value = re;
  }
}

//control_room();
//control_age();
