var set_shop = "";
var set_year = 0;
var set_month = 0;
var set_day = 0;

var chk_style_recomm = 0;
function style_recomm(staff){
	if (staff){
		chk_style_recomm = 1;
		sendRequest(on_loaded_style_recomm,'mode=stylerecomm&staff='+staff,'POST','/include/ajax_chk.asp','true','true');
	}	
}
function on_loaded_style_recomm(oj){
	chk_style_recomm = 0;
	var res = oj.responseText;
	if (res.indexOf("LOGIN")>=0){
		var ret = window.location;
		login_reservation(ret);
		return;
	}
	if (res=="1"){
		alert2("추천해 주셔서 감사합니다.","","javascript:window.location.reload();");
	}else{
		alert2("추천은 하루에 한번만 가능합니다.");
	}
}

var chk_shopinfo_recomm = 0;
function shopinfo_recomm(code){
	if (code) {
		chk_shopinfo_recomm = 1;
		sendRequest(on_loaded_shop_recomm,'mode=shoprecomm&code='+code,'POST','/include/ajax_chk.asp','true','true');
	}
}
function on_loaded_shop_recomm(oj){
	chk_shopinfo_recomm = 0;
	var res = oj.responseText;
	if (res.indexOf("LOGIN")>=0){
		var ret = window.location;
		login_reservation(ret);
		return;
	}
	if (res=="1"){
		alert2("추천해 주셔서 감사합니다.","","javascript:window.location.reload();");
	}else{
		alert2("추천은 하루에 한번만 가능합니다.");
	}
}
var chk_shopinfo_staffrecomm = 0;
function shopinfo_staffrecomm(staff){
	if (staff){
		chk_shopinfo_staffrecomm = 1;
		sendRequest(on_loaded_staff_recomm,'mode=staffrecomm&staff='+staff,'POST','/include/ajax_chk.asp','true','true');
	}
}
function on_loaded_staff_recomm(oj){
	chk_shopinfo_staffrecomm = 0;
	var res = oj.responseText;
	if (res.indexOf("LOGIN")>=0){
		var ret = window.location;
		login_reservation(ret);
		return;
	}
	if (res=="1"){
		alert2("<img src=/images/shopinfo/shopinfo_recom_star2.gif width=13 height=15 />칭찬스티커가 발부되었습니다.","","javascript:window.location.reload();");
	}else{
		alert2("<img src=/images/shopinfo/shopinfo_recom_star2.gif width=13 height=15 />칭찬스티커 발부는<br>하루에 한번만 가능합니다.");
	}
}

function shop_reservation(name,code){
	if(name&&code){
		window.open("/shopinfo/shopinfo_reservation.asp?name="+encodeURIComponent(name)+"&code="+code,"_top");
	}
}

function shopinfo_map(locale,code){
	if(locale==0){
		locale = "";
	}
	if(!code){
		code = "";
	}
	if (locale!="" && code!="")
	{
		location.href="/shopinfo/shopinfo_shop_view.asp?idx="+code;
	}else{
		window.open("/shopinfo/shopinfo_shop_list.asp?Nation_Part="+locale+"&Shop_Part="+code,"shopinfo_shop_list");
	}
}

function reservation_step(step){
	var base = "url(/images/shopinfo/shopinfo_reservation_step";
	var get_step1 = document.getElementById("reservation_step1");
	var get_step2 = document.getElementById("res_step2");
	var get_step3 = document.getElementById("reservation_step3");
	var get_step4 = document.getElementById("reservation_step4");
	var get_step5 = document.getElementById("reservation_step5");
	
	var get_step2a = document.getElementById("res_step2");
	var get_step3a = document.getElementById("res_step3");
	var get_step4a = document.getElementById("res_step4");
	
	switch(step){
		case 1 :
			get_step1.style.backgroundImage = base + "1_bg_on.jpg)";
			get_step2.style.backgroundImage = base + "2_bg.jpg)";
			get_step3.style.backgroundImage = base + "3_bg.jpg)";
			get_step4.style.backgroundImage = base + "4_bg.jpg)";
			get_step5.style.backgroundImage = base + "5_bg.jpg)";
			get_step2a.innerHTML = "";
			get_step3a.innerHTML = "";
			get_step4a.innerHTML = "";
			break;
		case 2 :
			get_step1.style.backgroundImage = base + "1_bg_on.jpg)";
			get_step2.style.backgroundImage = base + "2_bg_on.jpg)";
			get_step3.style.backgroundImage = base + "3_bg.jpg)";
			get_step4.style.backgroundImage = base + "4_bg.jpg)";
			get_step5.style.backgroundImage = base + "5_bg.jpg)";
			get_step3a.innerHTML = "";
			get_step4a.innerHTML = "";
			break;
		case 3 :
			get_step1.style.backgroundImage = base + "1_bg_on.jpg)";
			get_step2.style.backgroundImage = base + "2_bg_on.jpg)";
			get_step3.style.backgroundImage = base + "3_bg_on.jpg)";
			get_step4.style.backgroundImage = base + "4_bg.jpg)";
			get_step5.style.backgroundImage = base + "5_bg.jpg)";
			get_step4a.innerHTML = "";
			break;
		case 4 :
			get_step1.style.backgroundImage = base + "1_bg_on.jpg)";
			get_step2.style.backgroundImage = base + "2_bg_on.jpg)";
			get_step3.style.backgroundImage = base + "3_bg_on.jpg)";
			get_step4.style.backgroundImage = base + "4_bg_on.jpg)";
			get_step5.style.backgroundImage = base + "5_bg.jpg)";
			break;
		case 5 :
			get_step1.style.backgroundImage = base + "1_bg_on.jpg)";
			get_step2.style.backgroundImage = base + "2_bg_on.jpg)";
			get_step3.style.backgroundImage = base + "3_bg_on.jpg)";
			get_step4.style.backgroundImage = base + "4_bg_on.jpg)";
			get_step5.style.backgroundImage = base + "5_bg_on.jpg)";
			break;
	}
}

var chk_res_step1_ok = 0;
function res_step1_ok(y,m){
	if(chk_res_step1_ok==1)return;
	
	var get_code = document.getElementById("res_shop_code");
	if (get_code.value == ""||get_code.value=="0"){
		alert2("매장을 선택해 주십시요.");
		set_shop = "";
		return;
	}
	if(get_code.value == 269){
		alert("청담점은 홈페이지 예약이 불가합니다. 전화 예약바랍니다.\n                     TEL. 02-514-6167");
		set_shop = "";
		return;
	}
	
	set_shop = get_code.value;
	
	
	set_year = 0;
	set_month = 0;
	set_day = 0;
	
	var get_date = "";
	var nDate = new Date();
	var get_nYear = nDate.getYear();
	var get_nMonth = nDate.getMonth();

	if (y) {
		if (get_nYear > y){
			alert2("과거는 선택할 수 없습니다.");
			return
		}else{
			get_date += "&y="+y;
		}
	}
	if(m){
		if (get_nMonth+1 > m){
			alert2("과거는 선택할 수 없습니다.");
			return
		}else{
			get_date += "&m="+m;
		}
	}
	
	reservation_step(2);
	chk_res_step1_ok = 1;
	sendRequest(on_loaded_res_step1_ok,'mode=step1&shop='+get_code.value+get_date,'POST','/include/ajax_reservation.asp','true','true');
}

function on_loaded_res_step1_ok(oj){
	chk_res_step1_ok = 0;
	var res = oj.responseText;
	if (res) {
		var get_step2 = document.getElementById("res_step2");
		get_step2.innerHTML = res;
	}
}

var chk_res_step2_ok = 0;
function res_step2_ok(y,m,d){
	if(chk_res_step2_ok==1)return;
	for (i=0;i<32;i++){
		var get_day = document.getElementById("res_day_"+i);
		if (get_day){
			get_day.style.backgroundColor = "#FFFFFF";
			get_day.style.font.color = "#000000";
		}		
	}
	var get_day = document.getElementById("res_day_"+d);
	if (get_day){
		get_day.style.backgroundColor = "#535353";
		get_day.style.font.color = "#FFFFFF";
	}
	
	set_year = y;
	set_month = m;
	set_day = d;
	reservation_step(3);
	chk_res_step2_ok = 1;
	sendRequest(on_loaded_res_step2_ok,'mode=step2&shop='+set_shop+'&y='+y+'&m='+m+'&d='+d,'POST','/include/ajax_reservation.asp','true','true');
}

function on_loaded_res_step2_ok(oj){
	chk_res_step2_ok = 0;
	var res = oj.responseText;
	if (res) {
		var get_step3 = document.getElementById("res_step3");
		get_step3.innerHTML = res;
	}
}

var chk_res_step3_ok = 0;
function res_step3_ok(){
	if(chk_res_step3_ok == 1)return;
	reservation_step(4);
	chk_res_step3_ok = 1;
	sendRequest(on_loaded_res_step3_ok,'mode=step3&shop='+set_shop+'&y='+set_year+'&m='+set_month+'&d='+set_day,'POST','/include/ajax_reservation.asp','true','true');	
}

function on_loaded_res_step3_ok(oj){
	chk_res_step3_ok = 0;
	var res = oj.responseText;
	if (res) {
		var get_step4 = document.getElementById("res_step4");
		get_step4.innerHTML = res;
	}
}

function res_step4_ok(){
	reservation_step(5);
}

var chk_res_steps_ok = 0;
function res_steps_ok(){
	//if (chk_res_steps_ok == 1)return;
	
	var get_res_shop_code = document.getElementById("res_shop_code").value;
	if(!get_res_shop_code){
		alert2("매장을 선택해 주십시요.");
		return;
	}
	if(set_year==0){
		alert2("예약일을 선택해 주십시요.");
		return;
	}
	if(set_month==0){
		alert2("예약일을 선택해 주십시요.");
		return;
	}
	if(set_day==0){
		alert2("예약일을 선택해 주십시요.");
		return;
	}

	var get_tech = document.getElementsByName("tech");
	var get_tech_list = "";
	for(i=0;i<get_tech.length;i++){
		if (get_tech[i].checked){
			get_tech_list += "*" + get_tech[i].value;
		}
	}
	if(get_tech_list==""){
		alert2("시술하실 항목을 선택해 주십시요.");
		return;
	}
	
	var get_designer = document.getElementsByName("res_designer");
	var get_designer_sel = "";
	for(d=0;d<get_designer.length;d++){
		if(get_designer[d].checked){
			get_designer_sel = get_designer[d].value;
		}
	}
	
	var get_tel1 = document.getElementById("join_tel1");
	var get_tel2 = document.getElementById("join_tel2").value;
	var get_tel3 = document.getElementById("join_tel3").value;
	
	if (!get_tel1[get_tel1.selectedIndex].value){
		alert2("연락처는 필수 입니다.");
		return;
	}
	if (!get_tel2){
		alert2("연락처는 필수 입니다.");
		return;
	}	
	if (!get_tel3){
		alert2("연락처는 필수 입니다.");
		return;
	}
	var get_tel = get_tel1[get_tel1.selectedIndex].value + "-" + get_tel2 + "-" + get_tel3;
	
	var get_time_value = 0;
	var get_time = document.getElementById("join_time");
	if (get_time){
		get_time_value = get_time[get_time.selectedIndex].value;
	}
	
	var get_comm = document.getElementById("comment").value;
	
	chk_res_steps_ok = 1;
	sendRequest(on_loaded_res_steps_ok,'mode=steps&shop='+get_res_shop_code+'&y='+set_year+'&m='+set_month+'&d='+set_day+'&tech='+get_tech_list+'&designer='+get_designer_sel+'&tel='+get_tel+'&comm='+get_comm+'&time='+get_time_value,'POST','/include/ajax_reservation.asp','true','true');	
}

function on_loaded_res_steps_ok(oj){
	chk_res_steps_ok = 0;
	var res = oj.responseText;
	var get_comm = document.getElementById("comment");
	get_comm.value = res
	if (res=1) {
		alert2("예약이 접수 되었습니다.","","/");
	}else{
		alert2("예약중 문제가 발생했습니다.<br>정보를 확인해 주십시요.","");
	}
}

function shop_type_sel1(obj,code,name){
	var get_code = document.getElementById("res_shop_code");
	get_code.value = code;
	var get_name = document.getElementById("res_shop_name");
	get_name.value = name;
	var get_sel_nation = document.getElementById("Nation_Part");
	get_sel_nation.disabled = "disabled";
	var get_sel_name = document.getElementById("Shop_Part");
	get_sel_name.disabled = "disabled";
	reservation_step(1);
}

function shop_type_sel2(){
	var get_sel_nation = document.getElementById("Nation_Part");
	get_sel_nation.disabled = "";
	var get_sel_name = document.getElementById("Shop_Part");
	get_sel_name.disabled = "";
	var get_name = document.getElementById("res_shop_name");
	var get_sel_code = document.getElementById("Shop_Part_Temp");
	var get_code = document.getElementById("res_shop_code");
	if(get_sel_name.selectedIndex > 0){
		get_name.value = get_sel_name.options[get_sel_name.selectedIndex].text;
		get_code.value = get_sel_name.options[get_sel_name.selectedIndex].value;
	}else{
		get_name.value = "";
		get_code.value = "";
	}
	reservation_step(1);
}

function Change_Local(){
	var get_sel = document.getElementsByName("shop_sel");
	if(get_sel[1].checked){
		shop_type_sel2();
	}
}

function open_local(code){
	window.open("/pscstory/pscstory_contribute_list2.asp?local="+code,"list2");
}

function login_reservation(ret){
	add_alert();
	alert2("회원 전용 서비스 입니다.</br>로그인 해주십시요.","","/member/?ret="+encodeURIComponent(ret));
	//window.open("/member/?ret="+ret,"_top");
}

function memberexit_ok(id,pw,repw){

	if (!id){
		alert2("아이디를 입력해 주십시요.");
		return;
	}
	if (!pw){
		alert2("암호를 입력해 주십시요.");
		return;
	}
	if (!repw){
		alert2("확인암호를 입력해 주십시요.");
		return;
	}
	if (repw != pw){
		alert2("암호와 확인암호를 다릅니다.");
		return;
	}
	sendRequest(on_loaded_exit,'mode=login&id='+id+'&pw='+pw,'POST','/include/ajax_exit.asp','true','true');
}

function on_loaded_exit(oj){
	var res = oj.responseText;
	if (res=="1"){
		//alert("로그인 되었습니다. 좋은 시간 되십시요.");
		window.open("/member/member_exit_ok.asp","_top");
	}else{
		alert2("아이디 또는 비밀번호가 일치하지 않습니다.");
		return;
	}
}

var returnurl = "";

var chk_login_ok = 0;
function login_ok(id,pw,ret){
	if(chk_login_ok==1)return;
	if (!id){
		alert2("아이디를 입력해 주십시요.");
		return;
	}
	if (!pw){
		alert2("암호를 입력해 주십시요.");
		return;
	}
	returnurl = ret;
	chk_login_ok = 1;
	sendRequest(on_loaded_login,'mode=login&id='+id+'&pw='+pw,'POST','/include/ajax_login.asp','true','true');
}

function on_loaded_login(oj){
	var res = oj.responseText;
	if (res=="1"){
		//alert("로그인 되었습니다. 좋은 시간 되십시요.");
		if (returnurl){
			document.location.href = returnurl;
//			window.open(returnurl,"_top");
		}else{
			window.open("/","_top");
		}
	}else{
		alert2("아이디 또는 비밀번호가 일치하지 않습니다.");
		chk_login_ok = 0;
		return;
	}
}

var chk_logout_ok = 0;
function logout_ok(){
	if(chk_logout_ok==1)return;
	chk_logout_ok = 1;
	sendRequest(on_loaded_logout,'mode=logout','POST','/include/ajax_login.asp','true','true');
}

function on_loaded_logout(oj){
	//alert("로그아웃 되었습니다.");
	window.open("/","_top");
}
//숫자만 입력가능 
function num_only(){
  if((event.keyCode<48) || (event.keyCode>57)){
	//alert("숫자만 입력가능합니다..!!");
    event.returnValue=false;
  }
}

// Trim
function Trim(varStr)
{
	var reg = /\s+/g;
	return varStr.replace(reg,'');
}

// 주민번호 체크
function fncCheckSocietyID(varSocietyID1, varSocietyID2)
{
	var varSocietyID, aryNum, varNumSum;
	
	varSocietyID = varSocietyID1 + varSocietyID2;
	aryNum = new Array(13);
	
	for (var i = 0; i < 13; i++)
	{
		aryNum[i] = parseInt(varSocietyID.charAt(i));
	}
	
	varNumSum = aryNum[0]*2 + aryNum[1]*3 + aryNum[2]*4 + aryNum[3]*5 + aryNum[4]*6 + aryNum[5]*7 + aryNum[6]*8 + aryNum[7]*9 + aryNum[8]*2 + aryNum[9]*3 + aryNum[10]*4 + aryNum[11]*5;
	varNumSum = varNumSum % 11;
	varNumSum = 11 - varNumSum;
	
	if (varNumSum > 9)
	{
			varNumSum = varNumSum % 10
	}
	
	if (varNumSum != aryNum[12])
	{
		alert ("잘못된 주민번호 입니다");
		return false;
	}else
		return true;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function swfView(width, height, url){
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' ");
	document.write("		codebase='https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,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='quality'			value='high' /> ");
	document.write("	<param name='wmode'				value='transparent'> ");
	document.write("	<embed src='"+url+"' quality='high' width='"+width+"' height='"+height+"' align='middle' wmode='transparent'");
	document.write("		allowScriptAccess='always' type='application/x-shockwave-flash' ");
	document.write("		pluginspage='https://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}

function getCookie( name ){
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length )
	{
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		
		x = document.cookie.indexOf( " ", x ) + 1;
		
		if ( x == 0 ) break;
	}
			return "";
}

function setCookie(name, value, expiredays){
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function closeWin(get_Key) { 
	get_Pop = eval("document.all.Popup"+get_Key);
	get_Pop_id = "Popup"+get_Key;

	if (get_Pop.checked){
		setCookie(get_Pop_id,"done",1);
	}

	get_layerPopup = eval("document.all.layerPopup"+get_Key);
	get_layerPopup.style.display = 'none';
}
function closeWin2(get_Key) { 
	get_Pop = eval("document.all.Popup"+get_Key);
	get_Pop_id = "Popup"+get_Key;

	if (get_Pop.checked){
		//alert(get_Pop_id);
		setCookie(get_Pop_id,"done",1);
	}
	self.close();
}
function event_ok(idx,type,val){
	sendRequest(on_loaded_event_ok,'mode=event&idx='+idx+'&type='+type+'&val='+val,'POST','/include/ajax_event.asp','true','true');
}
function on_loaded_event_ok(oj){
	var res = oj.responseText;
	if(res)alert(res);
}
	
	
function event_pop(nums){
	window.open("/event/event_pop.asp?nums="+nums,"event");
	if(nums){
		if(nums==2){
			window.open("/member/member_mypage.asp","_top");
		}else{
			window.open("/event/event_now_view.asp?idx=84","_top");
		}
	}
}
function chk_card_off(card){
	alert2_blindn_off();
	var get_qr = document.getElementById("chk_card");
	if (get_qr){
		get_qr.style.display = "none";
	}
	var get_card = document.getElementById("join_card");
	if(get_card){
		get_card.value = card;
	}
}
