function ajaxuploaddata()
{
		$("#submitbutton").unbind("click");		 

		$("#order-loading")
		.ajaxStart(function(){
		    $(this).show();
		})
		.ajaxComplete(function(){
		    $(this).hide();
		});

		$.ajaxFileUpload
		(
		    {
			url:'order/uploadfile',
			secureuri:false,
			fileElementId:'userfile',
			dataType: 'json',
			success: function (data, status)
			{
			    uploaddata();
			    if(typeof(data.error) != 'undefined')
			    {
				if(data.error != '')
				{
//				    alert(data.error);
				}else
				{
//				    alert(data.msg);
				}
			    }
			},
			error: function (data, status, e)
			{
			    alert(e);
			}
		    }
		)
}

function uploaddata()
{
		$.ajax({
		   type: "POST",
		   url: "order/index",
		   data: $("#orderform").serialize(),
		   success: function(data){
		     $('#content').replaceWith(data);		   
  		     $("#submitbutton").bind("click",  ajaxuploaddata);	
		     $("#service").bind("change",  recalculate);
		     $("#subservice").bind("change",  recalculate);
		     $("#turnaround").bind("change",  recalculate);
		     $("body").scrollTop(0);	
		     },
		   complete: function() {
//		     $("#content").fadeIn("fast");		     		   
		   }
		 });
}

function recalculate()
{
		$.ajax({
		   type: "POST",
		   url: "order/calculatetotal",
		   data: $("#orderform").serialize(),
		   success: function(data){
		     $('#totalprice').html(data);
		   }
		 });
}


$(document).ready(function(){
	
	$("#submitbutton").bind("click",  ajaxuploaddata);
	
	$("#service").bind("change",  recalculate);
	$("#subservice").bind("change",  recalculate);
	$("#turnaround").bind("change",  recalculate);
			
});
