function toggle(a){

	 $(a).slideToggle("fast");

}
function show(div){
	$('.error').hide()
	$(div).show();

}
function hide(div){
	$('.error').hide()
	$(div).hide();

}

function showhide(divin,divout){
	$('.error').hide()
	$(divout).fadeOut();
	$(divin).slideDown();
}


function postToAjax(formname,messagecontainer,posturl){


    	$.ajax({

		  type: "POST",
		  url:  posturl,

		  data:  $('#' + formname).serialize(),
		  success: function(msg){
   								$('#' + messagecontainer).empty();
								$('#' + messagecontainer).append( msg);

							  }
 		});



}




function loadToppings(id,price,toppings_price,pizza_size){

	$('#pizza_price').empty();
	$('#price_input').empty();
	$('#toppings_price').empty();
	$('#pizza_size').empty();
    	$.ajax({

		  type: "POST",
		  url:  'ajax.php?function=toppings&id=' + id +'&t='  + new Date().getTime(),

		  data:  'id=' + id,
		  success: function(msg){

								$('#toppings').html( msg);

							  }
 		});

	$('#pizza_price').text(price);
	$('#price_input').val(price);
	$('#pizza_size').val(pizza_size);
	$('#toppings_price').val(toppings_price);
	$('#pizza_footer').show();
	$('#pizza_header').html('Select Your Toppings');
	 $('#pizza_header').highlightFade('#7bff58');
	   $('#pizza_price').highlightFade('#7bff58');




}



function calculatePizza(){

    	$.ajax({

		  type: "POST",
		  url:  'ajax.php?function=calculate-pizza&t='  + new Date().getTime(),

		  data:  $('#pizzaform').serialize(),
		  success: function(msg){

								$('#pizza_price').html(msg);

							  }
 		});

   $('#pizza_price').highlightFade('#7bff58')


}
function explodeArray(item,delimiter) {
tempArray=new Array(1);
var Count=0;
var tempString=new String(item);

while (tempString.indexOf(delimiter)>0) {
tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
Count=Count+1
}

tempArray[Count]=tempString;
return tempArray;
}



function calculateItem(){

    	$.ajax({

		  type: "POST",
		  url:  'ajax.php?function=calculate-item&t='  + new Date().getTime(),

		  data:  $('#itemform').serialize(),
		  success: function(msg){


									var mySplitResult = msg.split("|");


								$	('#item_price').text( mySplitResult[3]);
									$('#final_price').val(mySplitResult[0]);
									$('#final_options').val(mySplitResult[1]);
									$('#final_price_type').val(mySplitResult[2]);
							  }
 		});




}


function finishPizza(){
		$('#pizza_header').hide();
		$('#pizza_footer').hide();
		$('#toppings').html('<p style="font-family: Georgia, "Times New Roman", Times, serif;margin:10px;font-size:20px;padding:50px;color:#FA6024;>Your items(s) were added to the cart, you can add another or continue shopping now!.</p>');

}

function transferto(from,to){

$(from).effect("transfer", { to: to }, 300);

$(to).effect("bounce", { easing: "linear", times: 1 }, 300);

}

function appendtext(text,div){
	  $("."+div).empty();
$("."+div).append(document.createTextNode(text));
}
function insertField(div,text){
	 $("."+div).attr("value", text);



}


function calcDelivery(price,delivery_time,pickup_time){

	var selectedDel = $("#delivery").val();
	if(selectedDel == 'Yes'){
	appendtext('What time would you like it Delivered?','changeme');
	insertField('changemefield',delivery_time + '');
	$("#deliveryfee").show();


	var total = parseFloat($("#totalprice").val()) + parseFloat(price);
	$("#totalprice").val(total.toFixed(2));
	$("#changeprice").text('$' + total.toFixed(2));


	}else{

	appendtext('What time would you like your order available?','changeme');
	insertField('changemefield',pickup_time + '');
	$("#deliveryfee").hide();

	var total = parseFloat($("#totalprice").val()) - parseFloat(price);

	$("#totalprice").val(total.toFixed(2));
	$("#changeprice").text('$' + total.toFixed(2));


	}

}



function addDelivery(price){
	appendtext('What time would you like it Delivered?','changeme');
	insertField('changemefield','40 Minutes');
	$("#deliveryfee").show();


	var total = parseFloat($("#totalprice").val()) + parseFloat(price);
	$("#totalprice").val(total.toFixed(2));
	$("#changeprice").text('$' + total.toFixed(2));

}
function removeDelivery(price){

	appendtext('What time would you like your order available?','changeme');
	insertField('changemefield','15 Minutes');
	$("#deliveryfee").hide();

		var total = parseFloat($("#totalprice").val()) - parseFloat(price);

	$("#totalprice").val(total.toFixed(2));
	$("#changeprice").text('$' + total.toFixed(2));

}





   function refreshCart() {
   var url = "cart.inc.php?" + "&ms=" + new Date().getTime();

 $("#cart").load(url);


	}

setInterval(refreshCart,5000);

// custom functions
  function getcart() {
   var url = "cart.inc.php?" + "ms=" + new Date().getTime();
  $("div#cart").load(url);
 $("div#cart").load(url);
  $("div#cart").load(url);

	}

// document load
$(document).ready(function(){
  getcart();



});


/**
 *
 * @access public
 * @return void
 **/
function setDelivery()
{
	window.location="index.php?act=checkout&delivery=" + $("#delivery").val();
}

