var cfg_main_path = "/";

$(document).ready(function(){
	$('.add_to_cart').click (function () {
		add_to_cart ($(this).attr('id'), $(this).attr('rel'));
	});

	$('.del_from_cart').click (function () {
		ProductId = $(this).attr('rel');
		$.ajax({
			type: "POST",
			url: cfg_main_path + 'ajax_del_from_cart.php',
			data: "ProductId=" + ProductId,
			success: function(xml){
				$("data", xml).each(function(){
					sum_product = $(this).find('sum_product').text();
					sum_total = $(this).find('sum_total').text();
					$("#sum_product").html(sum_product);
					$("#sum_product_cart").html(sum_product);
					$("#sum_total").html(sum_total);					
					$('#cart_del_' + ProductId).html('').fadeOut();
				});
			}
		});

		return false;
	});

	$('#global_keyword').keyup(function(event){
		if ($(this).val().length >= 3)	{
			$("#global_keyword_submit").attr('disabled','');
		}
		else {
			$("#global_keyword_submit").attr('disabled','disabled');
		}
	});
});

function add_to_cart (ProductId, Title) {
	var txt = 'สั่งซื้อสินค้า<br/><img src="'+cfg_main_path+'image/icon/icon_apply.png" width="16" height="16" align="absmiddle" /> ' + Title + '? <input type="hidden" id="ProductId" name="ProductId" value="'+ ProductId +'" />';	
	$.prompt(txt,{ 
		buttons:{"< ตกลง":true, "ยกเลิก >":false},
		callback: function(v,m,f){			
			if(v){
				var ProductId = f.ProductId;
				$.post(cfg_main_path + 'ajax_add_to_cart.php',{ ProductId: f.ProductId }, function(xml){
					$("data", xml).each(function(){
						sum_product = $(this).find('sum_product').text();
						$("#sum_product").html(sum_product);
						$(this).remove();
					});
				});
/*
				$.ajax({
					type: "POST",
					url: cfg_main_path + 'ajax_add_to_cart.php',
					data: "ProductId=" + f.ProductId,
					success: function(xml){
						$("data", xml).each(function(){
							sum_product = $(this).find('sum_product').text();
							alert(sum_product);
							$("#sum_product").html(sum_product);
							$(this).remove();
						});
					}
				});
*/

			}
			else{}
		}
	});
}

function jumpMenu(targ,selObj,restore){   
	if (selObj.options[selObj.selectedIndex].value != "") {
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	}
}


