$(document).ready(function() { 
	$(".frmcart").bind("submit", function() {
		
		$.ajax({
			type		: "POST",
			cache	: false,
			url		: "external.php",
			data		: $(this).serializeArray(),
			success: function(data) {
				$.fancybox({'autoDimensions':false,'type':'iframe','href': 'external.php?action=cart-result','showCloseButton':true,'padding':5,'showCloseButton':false,'width':720,'height':516 }); 
				//$.fancybox(data,{'autoDimensions':false,'type':'inline','showCloseButton':true,'width':760,'height':490 }); 
			}
		});
	
		return false;
	});
	
}); 


function update_price(id,qty) {
	
	
		var dataString="pg=checkout&action=update-action&id=" + id + "&qty=" + qty;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
		   		result = msg.split("|");
				$("#subtotal" + id).html('$' + result[0]);
				$("#subtotal").html('$' + result[1]);
				$("#disocunt").html('$' + result[2]);
				$("#total").html('$' + result[3]);
		   }  
		});

}


function update_room_price() {
	
	itmid=$("#type").val();	
	date=$("#date").val();	
	day=$("#day").val();	
	

		var dataString="pg=priceupdate&itmid=" + itmid + "&date=" + date + "&day=" + day;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
		  
		   		$("#number").html(msg);
		   }  
		});	
	
}


function update_tour_price() {
	tour=$("#tour").val();	
	qty1=$("#qty1").val();	
	qty2=$("#qty2").val();
	
	
		var dataString="pg=tourupdate&tour=" + tour + "&qty1=" + qty1 + "&qty2=" + qty2;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
		   		
		   		tmp=msg.split("|");
		   		$("#subtotal").html(tmp[0]);
		   		$("#discount").html(tmp[1]);
		   		$("#number").html(tmp[2]);
		   }  
		});		
	
}

function switchtab(id) {
	
	$("#tab1").removeClass("selected");
	$("#tab2").removeClass("selected");
	$("#tab3").removeClass("selected");
	$("#tab4").removeClass("selected");

	$("#tab" + id).addClass("selected");
	
	$("#panel1").hide();
	$("#panel2").hide();
	$("#panel3").hide();
	$("#panel4").hide();
	
	$("#panel" + id).slideDown("fast");

	
}


function update_type(type) {
	
	if (type=="hotel") {
		$("#search-price1").attr('disabled','disabled');
		$("#search-price2").removeAttr('disabled');
		$("#search-price1").hide();
		$("#search-price2").show();
		$("#star").show();
	} else {
		$("#search-price2").attr('disabled','disabled');
		$("#search-price1").removeAttr('disabled');
		$("#search-price1").show();
		$("#search-price2").hide();
		$("#star").hide();
	
		
	}
	
}


function next_week(id) {
	now=now+(86400*7);

		var dataString="pg=detail&action=price-action&id=" + id + "&sdate=" + now;
		
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
		   		$("#table").html(msg);
		   }  
		});		
	
	
}


function last_week(id) {
	now=now-(86400*7);

		var dataString="pg=detail&action=price-action&id=" + id + "&sdate=" + now;
		
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
		   		$("#table").html(msg);
		   }  
		});		
	
	
}

function update_cart() {
	
	room=$("#room").val();	
	date=$("#date").val();	
	day=$("#day").val();	
	qty=$("#qty").val();	
	

		var dataString="pg=updatecart&qty=" + qty;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
		  		
			   tmp=msg.split("|");
				$("#subtotal").html(tmp[0]); 
				$("#discount").html(tmp[1]); 
				$("#totalprice").html(tmp[2]); 
				$("#total").html(tmp[3]); 
		   		
		   }  
		});	
	
	
}

function calendar(id,y,m) {
	
		var dataString="pg=calendar&id=" + id + "&y=" + y + "&m=" + m;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
		   		$("#calendar").html(msg);
		   }  
		});		
	
}


function submit_form(frm) {
	
	var error='';

	if (frm.name.value=="") { error+="- 您的姓名\n"; }
	
	if (frm.cname.value=="") { error+="- 持卡人姓名\n"; }
	if (frm.cnumber.value=="") { error+="- 信用卡卡號\n"; }
	if (frm.cvs.value=="") { error+="- 信用卡安全碼\n"; }
	if (!frm.checkbox.checked) { error+="- 閱讀並同意101box.com的線上預約條款\n"; }
	
	if (error!='') { alert('請確認必填以下欄位:\n\n' + error); return false; } else { return true; }
	


}


function apply_promocode() {
	
	var promo=$("#code").val();
	var qty1=$("#qty1").val();
	var qty2=$("#qty2").val();
	
		var dataString="pg=checkout&action=promo-action&promo=" + promo + "&qty1=" + qty1 + "&qty2=" + qty2;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) { 
		   		
		   		tmp=msg.split("|");
				$("#subtotal").html(tmp[0]); 
				$("#discount").html(tmp[1]); 
				$("#number").html(tmp[2]); 
		   		$("#result").html(tmp[3]);
		   }  
		});		
	
	
}


function apply_hotel_promocode() {
	var promo=$("#code").val();
	var qty=$("#qty").val();
	
	
		var dataString="pg=checkout&action=promohotel-action&promo=" + promo + "&qty=" + qty;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) { 
		   		
		   		tmp=msg.split("|");
				$("#subtotal").html(tmp[0]); 
				$("#discount").html(tmp[1]); 
				$("#totalprice").html(tmp[2]); 
				$("#total").html(tmp[3]); 
		   		$("#result").html(tmp[4]);
		   }  
		});		
}
