$.ajaxSetup({
	cache: false
});

$().ready(function() {
	//去除链接虚线框
	$("a,:button").bind("focus", function(){    
		if(this.blur){    
			this.blur();    
		}    
	}); 
	//加载登录层
	$("#login").load("/api/user/top_bar_show.asp");

	//展开顶部购物车层
	$("#view_cart,#cart_detail_close").click(function(){
		$("#cart_detail").slideToggle("normal");
		if($("#view_cart > img").attr("src") == "/images/top/top_bar_plus.gif"){
			$("#view_cart > img").attr("src","/images/top/top_bar_minus.gif");
		}else{
			$("#view_cart > img").attr("src","/images/top/top_bar_plus.gif");
		}
	});
	//加载顶部购物车商品数量
	$("#cart label,#cart_detail_title label").load("/api/cart/cart_count.asp");
	//加载顶部购物车商品总价
	$("#cart_detail_title span").load("/api/cart/cart_price.asp");
	//加载顶部购物车商品列表
	$("#view_cart").click(function(){
		$("#cart_product_container").load("/api/cart/top_cart_show.asp")
	});
	//自动完成搜索
	$("#keyword").autocomplete(products,{
		minChars:1,
		max:100,
		width:160,
		matchContains:true,
		formatItem: function(row, i, max) {
			return row.name;
		},
		formatMatch: function(row, i, max) {
			return row.name;
		},
		formatResult: function(row) {
			return row.name;
		}
	});
	$("#keyword").result(findValueCallback);

	function findValueCallback(event, data, formatted) {
		window.location.href=data.href;
	}
});

//顶部购物车去除商品
function topdel(productid){
	$.ajax({
		type: "POST",
		url: "/api/cart/cart_edit.asp",
		data: "productid=" + productid + "&acttype=del",
		success: function(msg){
			var arrMsg = msg.split("|");   
			if(arrMsg[0] == "1"){
				$("#cart label,#cart_detail_title label").load("/api/cart/cart_count.asp");
				$("#cart_product_container").load("/api/cart/top_cart_show.asp")
				$("#cart_detail_title span").load("/api/cart/cart_price.asp");
			}else{
				location.href = "/error.html?msg=" + msg;
			}					
		}
	});
}

//退出
function sign_out(){
	$.ajax({
		type: "POST",
		url: "/api/user/user_sign_out.asp",
		success: function(msg){
			if(msg == "1"){
				$("#login").load("/api/user/top_bar_show.asp");
				location.href = "/index.html";
			}else{
				location.href = "/index.html";
			}					
		}
	});
}

