
var PickupCart = function(
		elm, url, vmPath){
	if(window == this || !this.init){
		return new PickupCart(
			elm, url, vmPath);
	}
	return this.init(
		elm, url, vmPath);
};

PickupCart.prototype.init = function(
		elm, url, vmPath){
	this.elm = elm;
	this.url = url;
	this.vmPath = vmPath;
};

PickupCart.prototype.load = function(){
	var elm = this.elm;
	$.ajax({
		url: this.url,
		type: "post",
		cache: false,
		data: {"vmPath": this.vmPath},
		success: function(html){
			$('#' + elm).empty().append(html);
		}
	});
};

var AddCart = function(
		elm,url,productCd,obj){
	if(window == this || !this.init){
		return new AddCart(elm,url,productCd,obj);
	}
	return this.init(elm,url,productCd,obj);
};

AddCart.prototype.init = function(elm,url,productCd,obj){
	this.elm = elm;
	this.url = url;
	this.productCd = productCd;
	this.obj = obj;

};

AddCart.prototype.load = function(){
	var elm = this.elm;
	var obj = this.obj;

	var i = 0;
	$.ajax({
		url: this.url,
		type: "post",
		cache: false,
		data: {
			"productCd" : this.productCd
		},
		success: function(html){
			$('#' + elm).empty().append(html);
			JM.clipBaloon(obj);
		},
		error:function(html){
			location.href="/www/ErrorDocument/jibunmirai/500.html"
		}
	});
};

var AddCartId = function(
		url,productCd,obj){
	if(window == this || !this.init){
		return new AddCartId(url,productCd,obj);
	}
	return this.init(url,productCd,obj);
};

AddCartId.prototype.init = function(url,productCd,obj){
	this.url = url;
	this.productCd = productCd;
	this.obj = obj;

};

AddCartId.prototype.load = function(){
	var obj = this.obj;

	var i = 0;
	$.ajax({
		url: this.url,
		type: "post",
		cache: false,
		data: {
			"productCd" : this.productCd
		},
		success: function(html){
			$('#cartCount').empty().append(html);
			$('#cartCountNow').empty().append($('#count').text());
			JM.clipBaloon(obj);
		},
		error:function(html){
			location.href="/www/ErrorDocument/jibunmirai/500.html"
		}

	});
};

var DelCartId = function(
		url,productCd,obj){
	if(window == this || !this.init){
		return new DelCartId(url,productCd,obj);
	}
	return this.init(url,productCd,obj);
};

DelCartId.prototype.init = function(url,productCd,obj){
	this.url = url;
	this.productCd = productCd;
	this.obj = obj;

};

DelCartId.prototype.load = function(){
	var obj = this.obj;
	$.ajax({
		url: this.url,
		type: "post",
		cache: false,
		data: {
			"productCd" : this.productCd
		},
		success: function(html){
			$('#cartCount').empty().append(html);
			$('#cartCountNow').empty().append($('#count').text());
			$('#cartCountListNow').empty().append($('#count').text());
			$('#submitBtn').empty().append($('#shiryoseikyuUrl'));
			if($('#cartCountNow').text() == "0"){
				$('#j_result_footer').remove();
				$('#j_resultgroup1').remove();
				$('#j_diagnosis').remove();
				$('#j_result_wrapper').remove();
				$("#noresults").attr('style',"display:block");
			}else{
				$(obj).parents("li").remove();
			}
		},
		complete: function(){
			$.unblockPage();
		}
	});
};

var CountCart = function(
		elm, url, vmPath){
	if(window == this || !this.init){
		return new CountCart(
			elm, url, vmPath);
	}
	return this.init(
		elm, url, vmPath);
};

CountCart.prototype.init = function(
		elm, url, vmPath){
	this.elm = elm;
	this.url = url;
	this.vmPath = vmPath;
};

CountCart.prototype.load = function(){
	var elm = this.elm;
	$.ajax({
		url: this.url,
		type: "post",
		cache: false,
		data: {"vmPath": this.vmPath},
		success: function(html){
			$('#' + elm).empty().append(html);
		}
	});
};
$(document).ready(function(){
	$(".addCart").click(
		function(){
			var productCd = "";
			var url = "";
			var elm = "";
			productCd = $("#productCd").val();
			url = $("#cartAddUrl").val();
			elm = "cartKoma";
			AddCart(elm,url,productCd,this).load();
			return false;
		}
	);
	$(".addCartId").click(
		function(){
			var productCd = "";
			var url = "";
			productCd = $(this).attr("id");
			url = $("#cartAddUrl").val()+productCd;
			AddCartId(url,productCd,this).load();
			return false;
		}
	);

	$(".delCartId").click(
		function(){
			$.blockPage();
			var productCd = "";
			var url = "";
			productCd = $(this).attr("id");
			url = $("#cartDelUrl").val()+productCd;
			DelCartId(url,productCd,this).load();
			return false;
		}
	);
});

