/* EXAMPLE */

/*$.ajax({
	type: "POST",
	url: "handler.php",
	data: "action=checkAnswer&questionId="+question+"&answerId="+checkedValue+"",

	success: function(msg){
						
		
	}
});

/* END */


function addToBasket(basketId, trainingDateId) {
	
	
	$("#add-button-"+basketId).hide();
	$("#add-load-button-"+basketId).show();
	$("#add-to-cart-message-"+basketId).html('<img src="BusinessThing/images/loading.gif" />');
	$("#add-to-cart-message-"+basketId).show('<img src="BusinessThing/images/loading.gif" />');
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=addToBasket&addToBasket="+basketId+"&trainingDateId="+trainingDateId+"",
	
		success: function(msg){
			totalCartItems();
			updateQuantity(basketId);
			updateTotal(basketId);
			updateCompleteTotal();
			updateSaving();
			updateCompleteVat();
			updatePostage();
			$("#add-to-cart-message-"+basketId).html(msg);	
			$("#add-to-cart-message-"+basketId).show('highlight');
			$("#add-to-cart-message2-"+basketId).html(msg);	
			$("#add-to-cart-message2-"+basketId).show('highlight');	
			  $.fn.colorbox({href:'.addbasketoverlay', open:true, inline:true})
			  $('.closebtn').click(function() {				   
					$.fn.colorbox.close()
					return false;
			   });
			/* setTimeout(function(){
				$('#add-to-cart-message-'+basketId).removeAttr('style').hide().fadeOut();
			}, 20000); */	
			setTimeout(function(){
				$('#add-to-cart-message2-'+basketId).removeAttr('style').hide().fadeOut();
			}, 5000);		
			$("#add-button-"+basketId).show('highlight');
			$("#add-load-button-"+basketId).hide();			
			
		}
	});

}

function addToBasket2(basketId, trainingDateId) {
	
	
	$("#add-button-"+basketId).hide();
	$("#add-load-button-"+basketId).show();
	$("#add-to-cart-message-"+basketId).html('<img src="BusinessThing/images/loading.gif" />');
	$("#add-to-cart-message-"+basketId).show('<img src="BusinessThing/images/loading.gif" />');
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=addToBasket&addToBasket="+basketId+"&trainingDateId="+trainingDateId+"",
	
		success: function(msg){
			totalCartItems();
			updateQuantity(basketId);
			updateTotal(basketId);
			updateCompleteTotal();
			updateSaving();
			updateCompleteVat();
			updatePostage();
			$("#add-to-cart-message-"+basketId).html(msg);	
			$("#add-to-cart-message-"+basketId).show('highlight');
			$("#add-to-cart-message2-"+basketId).html(msg);	
			$("#add-to-cart-message2-"+basketId).show('highlight');	
			/* setTimeout(function(){
				$('#add-to-cart-message-'+basketId).removeAttr('style').hide().fadeOut();
			}, 20000); */	
			setTimeout(function(){
				$('#add-to-cart-message2-'+basketId).removeAttr('style').hide().fadeOut();
			}, 5000);		
			$("#add-button-"+basketId).show('highlight');
			$("#add-load-button-"+basketId).hide();			
			
		}
	});

}


function addRooms(id) {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=addRooms&id="+id,
	
		success: function(msg){
			updateTotal(id);
			updateCompleteTotal();
			updateSaving();
			updateCompleteVat();
			if(msg >= 1) {
				$("#rooms-"+id).val(msg);
			}				
			
		}
	});

}

function deleteRooms(id) {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=deleteRooms&id="+id,
	
		success: function(msg){
			updateTotal(id);
			updateCompleteTotal();
			updateSaving();
			updateCompleteVat();
			if(msg >= 0) {
				$("#rooms-"+id).val(msg);
			}			
			
		}
	});
	
}

function deleteFromBasket(basketId, trainingDateId) {
	
	$("#sub-button-"+basketId).hide();
	$("#sub-load-button-"+basketId).show();
	$("#add-to-cart-message-"+basketId).html('<img src="BusinessThing/images/loading.gif" />');	
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=deleteFromBasket&deleteFromBasket="+basketId+"&trainingDateId="+trainingDateId+"",
	
		success: function(msg){
			totalCartItems();
			updateQuantity(basketId);
			updateTotal(basketId);
			updateCompleteTotal();
			updateSaving();
			updateCompleteVat();
			updatePostage();
			$("#add-to-cart-message-"+basketId).html(msg);	
			$("#add-to-cart-message-"+basketId).show('highlight');	
			setTimeout(function(){
				$('#add-to-cart-message-'+basketId).removeAttr('style').hide().fadeOut();
			}, 2000);	
			$("#sub-button-"+basketId).show('highlight');
			$("#sub-load-button-"+basketId).hide();						
			
		}
	});	
}

function updateAccomm(basketId, trainingDateId) {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateAccomm&addToBasket="+basketId+"&trainingDateId="+trainingDateId+"&accommId="+$("#accommodation-value-"+basketId).val()+"",
	
		success: function(msg){
			totalCartItems();
			updateQuantity(basketId);
			updateTotal(basketId);
			updateCompleteTotal();
			updateSaving();
			updateCompleteVat();	
			
		}
	});
}

function totalCartItems() {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=totalCartItems",
	
		success: function(msg){							
			$("#total-amount").html(msg);
		}
	});
}

function updateTotal(id) {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateTotal&id="+id+"",
	
		success: function(msg){
			$("#total-"+id).html(msg);		
			
		}
	});
}

function updateCompleteTotal() {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateTotal",
	
		success: function(msg){
			$("#complete-total").html(msg);		
			
		}
	});
}

function updateCompleteVat() {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateCompleteVat",
	
		success: function(msg){
			$("#complete-vat").html(msg);				
			
		}
	});
}

function updateSaving() {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateSaving",
	
		success: function(msg){
			$("#saving-total").html(msg);				
			
		}
	});
}


function updatePrices(id, currency, memberPrice, nonMemberPrice) {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateCurrency&id="+id+"&currentCurrency="+currency+"&price="+memberPrice+"&type=memberPrice",
	
		success: function(msg){
			document.getElementById('member-price').innerHTML = msg;					
			
		}
	});

	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateCurrency&id="+id+"&currentCurrency="+currency+"&price="+nonMemberPrice+"&type=nonMemberPrice",
	
		success: function(msg){
			document.getElementById('non-member-price').innerHTML = msg;				
			
		}
	});
}


function updateQuantity(id) {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updateQuantity&id="+id,
	
		success: function(msg){
			if(msg >= 1) {
				$("#quantity-"+id).val(msg);
				$("#quantity-2-"+id).html(msg);
			}							
		}
	});	
	
}


function updatePostage() {
	
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=updatePostage",
	
		success: function(msg) {
			document.getElementById('postage').innerHTML = msg;
		}
	});	
	
}

function setDownload(val) {
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=setDownload&download="+val,
	
		success: function(msg){					
		}
	});	
}

function setPostage(val) {
	$.ajax({
		type: "POST",
		url: "handler.php",
		data: "action=setPostage&postage="+val,
	
		success: function(msg){	
		}
	});	
}
				
	// TOGGLE AN AREA - target an element to use the jquery slide effect			
			$(document).ready(function(){
				//hide the all of the element with class msg_body
				$(".msg_body").hide();
				//toggle the componenet with class msg_body
				$(".msg_head").click(function(){
					$(this).next(".msg_body").slideToggle(300);
					
						var $this = $(this);
							if( $this.is('.removed') ) 
								 {
								   $this.removeClass('removed');
								   $this.addClass('selected');
								  // $('.msg_body').removeClass('selected');
								  // $(".msg_body").addClass('removed');
							}
							else {
								   if( $this.is('.selected') ) 
								 {
								   $this.removeClass('selected');
								   $this.addClass('removed');
								}
								   //$('.msg_body').removeClass('selected');
						 }
						 
				return false;
					
					//$(this).addClass("selected");
					//if () {$(this).removeClass("selected");}
				});
			});
// home image fade

			
/*
	$(document).ready(
		function(){
			$('#mySlides').innerfade({
				speed: 'slow',
				timeout: 4000,
				type: 'sequence',
				containerheight: '240px'
			});
		}
	);

	*/