function hideMessage(){
	$("#message").dialog('close');
}

function addCar(pid,num){
	   var data="";
	   if(document.getElementById("sizes")!=null && document.getElementById("sizes")!=undefined){
		 if(document.getElementById("sizes").checked){
	  	     data = 'pid='+pid+'&num='+num+'&size=s';
		 }else if(document.getElementById("sizem").checked){
	  	     data = 'pid='+pid+'&num='+num+'&size=m';
		 }else if(document.getElementById("sizel").checked){
	  	     data = 'pid='+pid+'&num='+num+'&size=l';
		 }else if(document.getElementById("sizexl").checked){
	  	     data = 'pid='+pid+'&num='+num+'&size=xl';
		 }else{
		 	alert("請選擇尺寸");
			return false;
		 }
	   }else{
	   	 data = 'pid='+pid+'&num='+num;
	   }
	   var action= '/products/car.php';
	   $.ajax({
		   type: "POST",
		   url: action,
		   cache: false,
		   data: data,
		   beforeSend:function(){
//		  		$.blockUI({message:'<h1>資料傳輸中...</h1>'});
		   },
		   success: function(response){
		   
		   		if(response=="addfalse"){
					alert("Shopping car error ");				
				}else if(response=="age:login"){
					alert("此為限制級商品，請先登入會員");
					document.location="/member/member_login.php";
				}else if(response=="age:false"){
					alert("此為限制級商品，您尚未滿十八歲");
				}else{
//					alert('已加入購物車');
					$("#message").html(response).dialog('open');
					setTimeout(hideMessage,1500);		
				}//else{
				//	alert("此產品現在庫存不足或已下架");
				//}
		   },
		   error:function(response,status,error){		   
			  alert("Shopping car error");
		   }
	   });
	}
	
	function changeCar(pid,num,price){
	  
	   var data = 'pid='+pid+'&num='+num;
	   var action= '/products/car.php';
	   $.ajax({
		   type: "POST",
		   url: action,
		   cache: false,
		   data: data,
		   beforeSend:function(){
//		  		$.blockUI({message:'<h1>資料傳輸中...</h1>'});
		   },
		   success: function(response){
		   
		   		if(response=="addfalse"){
					alert("Shopping car error ");				
				}else{
//					alert('已加入購物車');
					$("#message").html(response).dialog('open');
					$("#sub"+pid).html("$"+num*price);
					
					setTimeout(hideMessage,1500);		
				}//else{
				//	alert("此產品現在庫存不足或已下架");
				//}
		   },
		   error:function(response,status,error){		   
			  alert("Shopping car error");
		   }
	   });
	}

	
	
	function delCar(pid){
	  
	   var data = 'pid='+pid;
	   var action= '/products/del.php';
	   $.ajax({
		   type: "POST",
		   url: action,
		   cache: false,
		   data: data,
		   beforeSend:function(){
//		  		$.blockUI({message:'<h1>資料傳輸中...</h1>'});
		   },
		   success: function(response){
		   		
					//$("#message").html(response).dialog('open');
					//$("#item"+pid).remove();
					 location.reload(); 
					//setTimeout(hideMessage,1500);		
	   },
		   error:function(response,status,error){		   
			  alert("Item Removed from Shopping Cart!");
			  location.reload(); 
		   }
	   });
	}
	

