
$(document).ready(function() {
	$(".addinput").keypress(function (e) { 
		// Disable enter key as well to ensure user doesn't accidently add multiple items.
	  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)){
	    return false;
    }	
	});
	if ($("#groupname").val() == ''){
	  $("#groupname").hide();
	} else {
		$("#chkgroup").attr('checked', true);
	}
	
	$("#chkgroup").click(function(){
		$("#groupname").toggle();
		$("#groupname").focus();	
	});
	
	$(".bookform").ajaxForm(function(e) {
		e = e.replace('<meta http-equiv="refresh" content="5; url=index.php" />','');
		e = e.replace('<meta http-equiv="refresh" content="0; url=index.php" />','');
		if (e=='1' || e == 1 || e==''){					
		  UpdateMinCart();
		} else {
			alert(e);
		}
	})
	UpdateMinCart();
});

function UpdateMinCart(){
	document.getElementById("minicart").innerHTML = '<img src="images/ajax-loader.gif" alt="Loading" />';
	var ndata = '';
  if (location.href=='http://www.graceandfaith.uk.net/site/booking/booking.php' || location.href=='http://www.graceandfaith.uk.net/site/booking/cart.php'){
  	ndata = 'nocheckout=true';
  }
	$.ajax({
		type: "GET",
		data: ndata,
		url: "read-mini-cart.php",
		success: function(ret){
			document.getElementById("minicart").innerHTML = ret;
			//$("#minicart").html('<div>' + ret + '</div>');
		}		
	});
	return false;	
}	

function RemoveItem(id){
	$("#minicart").html('<img src="images/ajax-loader.gif" alt="Loading" />');
	$.ajax({
	type: "GET",
	url: "bookit.php",
	data: "mode=remove&id=" + id + "&ref=index.php",
			
	 success: function(msg){
			msg = msg.replace('<meta http-equiv="refresh" content="5; url=index.php" />','');
			msg = msg.replace('<meta http-equiv="refresh" content="0; url=index.php" />','');
	  	if (msg == "1" || msg == 1){
		    UpdateMinCart();
		  } else {
		  	alert(msg);
		  }
		}			
	});
	return false;	
	
}

function viewlist(pid,cid) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('view-list.php?id="+pid+"&cid="+cid+"', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=400,left = 715,top = 325');");
}

function viewgrouplist(pid) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('view-group-list.php?id="+pid+"', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=400,left = 715,top = 325');");
}