﻿var hd_url = 'http://www.hanoihd.vn/hd1beta/';
i=0;
j=0;

function set_status(size) {
	widthpx = 500 * ( size / 2000 );
	if (widthpx < 551) {
	$("#GBcounter").animate({width: widthpx + 'px'},1000); };
	$("#hd_gb").text(size);
}

function set_status_ipod(size) {
	widthpx = 500 * ( size / 160 );
	if (widthpx < 551) {
	$("#iGBcounter").animate({width: widthpx + 'px'},1000); };
	$("#ip_gb").text(size);
}

function set_status_all (hd,ip,dv,tt) {
	widthpx = 500 * ( hd / 2000 );
	if (widthpx < 551) {
	$("#GBcounter").animate({width: widthpx + 'px'},1000); };
	$("#hd_gb").text(hd);

	widthpx = 500 * ( ip / 160 );
	if (widthpx < 551) {
	$("#iGBcounter").animate({width: widthpx + 'px'},1000); };
	$("#ip_gb").text(ip);

	$("#dv_count").text(dv);
	$("#total_count").text(tt);	

}

function paction(id) {

	$('#p'+id).find(".p_status").addClass("processing");

	if($('#p'+id).find(".p_status").hasClass('selected'))
	{
		
		
		$.ajax({
				url: hd_url + 'ajax.php',
				type: "POST",
				dataType: "json",
				data: {cmd:'rem',id:id},
				success: function(data) 

					{ 
						//alert("Phim đã được xóa khỏi giỏ hàng");
						//alert("Rem Done with cmd:'rem',id:"+id);
						set_status_all (data.total_size,data.ipod_size,data.device_count,data.total_price);	
						$('#p'+id).find(".p_status").removeClass("selected");
						$('#p'+id).find(".p_status").removeClass("processing");
					}
		
				});
	}

	else

	{

		$.ajax({
				url: hd_url + 'ajax.php',
				type: "POST",
				dataType: "json",
				data: {cmd:'add',id:id},
				success: function(data) 
					
					{ 
						//alert("Phim đã được thêm giỏ hàng");
						//alert("Add Done with cmd:'add',id:"+id);
						set_status_all (data.total_size,data.ipod_size,data.device_count,data.total_price);	
						$('#p'+id).find(".p_status").addClass("selected"); 
						$('#p'+id).find(".p_status").removeClass("processing");
										
					}
		
				});

	}

}


function caction(id) {

	$('#p'+id).find(".c_status").addClass("processing");

	if($('#p'+id).find(".c_status").hasClass('deleted'))
	{
		
		
		$.ajax({
				url: hd_url + 'ajax.php',
				type: "POST",
				dataType: "json",
				data: {cmd:'add',id:id},
				success: function(data) 

					{ 
						//alert("Phim đã được xóa khỏi giỏ hàng");
						//alert("Re Added Done with cmd:'rem',id:"+id);
						set_status(data.total_size);
						set_status_ipod(data.ipod_size);	
						$('#p'+id).find(".c_status").removeClass("deleted");
						$('#p'+id).find(".c_status").removeClass("processing");
					}
		
				});
	}

	else

	{

		$.ajax({
				url: hd_url + 'ajax.php',
				type: "POST",
				dataType: "json",
				data: {cmd:'rem',id:id},
				success: function(data) 
					
					{ 
						//alert("Phim đã được thêm giỏ hàng");
						//alert("Remove Done with cmd:'add',id:"+id);
						set_status(data.total_size);
						set_status_ipod(data.ipod_size);
						$('#p'+id).find(".c_status").addClass("deleted"); 
						$('#p'+id).find(".c_status").removeClass("processing");
										
					}
		
				});

	}

}


