
 // 등록되지 않고 보류중인 쿠폰 리스트

function PostHoldOffCouponList(page,user_id,type)
  {      

	 CallAjax("/help/runch/runch.coupon.hold.list.ajax.php?page=" + page+ "&user_id="+user_id+ "&type="+type,"DisplayHoldOffCouponList(responseText)");

  }

function DisplayHoldOffCouponList(text)
  {
	 var target = document.getElementById("post_holdoff_coupon_list");
	 target.innerHTML = text;
   }

// 등록 완료된 쿠폰 리스트

function PostCompletedCouponList(page,user_id,type)
  {      

	 CallAjax("/help/runch/runch.coupon.agree.list.ajax.php?page=" + page+ "&user_id="+user_id+ "&type="+type,"DisplayCompletedCouponList(responseText)");

  }
function DisplayCompletedCouponList(text)
  {
	 var target = document.getElementById("post_completed_coupon_list");
	 target.innerHTML = text;
   }

// 등록 신청을 대기중인 쿠폰 리스트

function PostCouponList(page,user_id,type)
  {      

	 CallAjax("/help/runch/runch.coupon.list.ajax.php?page=" + page+ "&user_id="+user_id+ "&type="+type,"DisplayCouponList(responseText)");

  }
function DisplayCouponList(text)
  {
	 var target = document.getElementById("post_coupon_list");
	 target.innerHTML = text;
   }

//************ 쿠폰 승인 및 보류 진행 절차 ************//

function AgreeCoupon(store_name, menu_name, due_day, price, coupon_id, type){

	if (confirm(store_name+" 의 "+menu_name+" 를(을) 승인하시겠습니까?\n\n" + "마감일자 : " +due_day +"\n할인가격 : " + price + "원"))
	{ 
		alert("정상적으로 승인 처리되었습니다");
		document.location = "../runch/runch.coupon.proc.php?coupon_id=" + coupon_id + "&coupon_status=1" + "&type="+type;
	}

}

function HoldCoupon(store_name, menu_name, due_day, price, coupon_id, type){

	if (confirm(store_name+" 의 "+menu_name+" 를(을) 보류하시겠습니까?\n\n" + "마감일자 : " +due_day +"\n할인가격 : " + price + "원"))
	{ 
		alert("정상적으로 보류 처리되었습니다");
		document.location = "../runch/runch.coupon.proc.php?coupon_id=" + coupon_id + "&coupon_status=3" + "&type="+type;

	}

}

function AgreeCouponAlert(){

	alert("이미 승인상태인 쿠폰입니다!");

}

function HoldCouponAlert(){

	alert("이미 보류상태인 쿠폰입니다!");

}

function EditCoupon(store_name, store_id, menu, coupon_amount, price, day_post, date_expire, description, coupon_status, coupon_id){

	location.href = "../runch/runch.coupon.edit.php?store_name="+encodeURIComponent(store_name)+"&store_id="+store_id+"&menu="+encodeURIComponent(menu)+"&coupon_amount="+coupon_amount+"&price="+price+"&day_post="+day_post+"&date_expire="+encodeURIComponent(date_expire)+"&description="+encodeURIComponent(description)+"&coupon_status="+coupon_status+"&coupon_id="+coupon_id;

}


//************ 쿠폰 등록시 장소 검색관련 절차  ************//

function TaskStoreSearchListShow_RUNCH(e,user_id, type){

   TaskOpenPopup_RUNCH(e, "/task/store.search.ajax.php?user_id="+user_id+"&type="+type,305,550, 1, 0);
   //TaskOpenPopup_RUNCH(e, "/help/runch/runch.store.search.ajax.php?user_id="+user_id+"&type="+type,305,550, 1, 0);
	
}

function TaskOpenPopup_RUNCH(e, url, width, height, align, valign)
{
	if (popup)
		parent.ClosePopup();

	var x = e.pageX ? e.pageX : document.body.scrollLeft + e.clientX; 
    
	if (align > 0)
		x -= width;

	var y = e.pageY ? e.pageY : document.body.scrollTop + e.clientY; 
	if (valign > 1)
		y -= height;
	var html = "<p><iframe src=\"" + url + "\" width=\"" + width + "\" height=\"" + height + "\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" topmargin=\"0\"  scrolling=\"no\"  frameborder=\"0\" allowtransparency=\"true\"></iframe></p>";
	//var div = document.getElementById("popup");
	var div = parent.document.getElementById("popup");

	div.style.left = x+100;
	div.style.top = y+50;
	div.style.width = width;
	div.style.height = height;
	div.innerHTML = html;
	div.style.display = "block";
	popup = true;
	
}

function sendTextWhere_RUNCH(store_name, store_id, town_name, town_id, category_id){
	//alert(store_name+"\n"+store_id+"\n"+town_name+"\n"+town_id+"\n"+category_id);
	var Ostore_name = document.getElementById("store_name");
	var Ostore_id = document.getElementById("store_id");
	var Otown_name = document.getElementById("town_name");
	var Otown_id = document.getElementById("town_id");
	var Ocategory_id = document.getElementById("category_id");
	Ostore_name.value = store_name;
	Ostore_id.value = store_id;
	Otown_name.value = town_name;
	Otown_id.value = town_id;
	Ocategory_id.value = category_id;
	parent.ClosePopup();
}

function TaskSearchStoreList_RUNCH(page,total,keyword,type)
{   var str = "";
    if(keyword == "장소 검색"){
        str = "";
	}else{
        str = keyword;
	}
	CallAjax("../help/runch/runch.store.list.ajax.php?page=" + page + "&total="+total+"&keyword="+encodeURIComponent(str)+"&type="+type,"DisplayTaskSearchStore(responseText)"); 
}

function DisplayTaskSearchStore(text)
{
	 var target = document.getElementById("search_store");
	 target.innerHTML = text;
}



//************ 쿠폰 등록시 폼 완성 여부 확인 절차  ************//

function SubmitCheck_AddRunch(){

			
		if(!document.coupon_add.store_name.value){
			alert("장소 검색을 통해 쿠폰 발급 가게를 지정해주세요!");
			return false;
		}

		if(!document.coupon_add.menu.value){
			alert("쿠폰 발급을 위한 메뉴를 지정해주세요!");
			return false;
		}

		if(!document.coupon_add.menu_image.value){
			alert("쿠폰 발급을 위한 메뉴 이미지를 지정해주세요!");
			return false;
		}

		if(!document.coupon_add.price.value){
			alert("쿠폰 발급을 위한 메뉴의 원가를 지정해주세요!");
			return false;
		}

		if(!document.coupon_add.date_expire.value){
			alert("쿠폰 발급을 위한 유효기간을 지정해주세요!");
			return false;
		}

		if(!document.coupon_add.description.value){
			alert("쿠폰 발급을 위한 메뉴의 간단한 설명을 첨부해주세요!");
			return false;
		}
}

//************ 쿠폰 삭제시  ************//

function DeleteCoupon(coupon_id, registrant_id, store_id, type)
{
	//alert(coupon_id+"\n"+registrant_id+"\n"+store_id+"\n"+type);
	if (confirm("쿠폰을 삭제하시겠습니까?"))
		document.location = "/help/runch/runch.coupon.delete.php?coupon_id=" + coupon_id + "&registrant_id="+registrant_id+"&store_id="+store_id+"&type="+type;
}
