/* *
 * 全局变量
 */
var js_shipping_price = '';

/* *
 * 显示导航部分购物车
 */
$(document).ready(function(){
	$("#carthover").hover(
		function(){
			$("#cart_cbox").slideDown();
		},
		function(){
			$("#cart_cbox").hide();
	 });
	
	$("#cart_cbox").hover(
		function(){
			$("#cart_cbox").show();
		},
		function(){
			$("#cart_cbox").slideUp();
	 });
	
	$("#menubox").hide();
	var canHide = false;
	function doHide(){
		if(canHide)
			$("#menubox").hide();
		}
		$("#categoryid").hover(function(){
		$("#menubox").show();
		canHide = false;
	},function(){
		canHide = true;
		window.clearTimeout(t);
		var t = window.setTimeout(doHide,0);
		doHide;
	});
	$("#menubox").hover(function(){
		canHide = false;
	},function(){
		canHide = true;
		window.clearTimeout(t);
		var t = window.setTimeout(doHide,0);
	});
	
});

<!--//--><![CDATA[//><!--
function menuFix() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onMouseDown=function() {
		this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onMouseUp=function() {
		this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout=function() {
		this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"),"");
		}
	}
}
window.onload=menuFix;
//--><!]]>
navHover = function() {
  var lis = document.getElementById("navmenu-v").getElementsByTagName("LI");
  for (var i=0; i<lis.length; i++) {
    lis[i].onmouseover=function() {
      this.className+=" iehover";
    }
    lis[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" iehover\\b"), "");
    }
  }
}

if (window.attachEvent) window.attachEvent("onload", navHover);

/* *
 * 重新获得购物车数据
 */
function get_menu_cart_list() {
	$.getJSON("/cart/cart.php?act=get_json_cart_list",{t:new Date()},
	function (data) {
		var product_list = data.product_list;
		var cart_total = data.cart_total;
		$("[@id=create_memu_cart_list]").remove();
		$("[@id=menu_cart_list_old]").remove();
		$.each(product_list, function(i, n){
			var row = $("#menu_cart_list_tmp").clone();
			row.find("#menu_cart_pic").html("<p><a href="+n.url+" target=\"_blank\"><img src="+n.pic+" width=\"60\" height=\"45\" /></a></p>");
			row.find("#menu_cart_product_name").html("<a href="+n.url+" title="+n.product_name+" class=\"black5a\">"+n.product_name+"</a>");
			row.find("#menu_cart_price_quantity").html("<div class=\"cart_clistp\"><span>$"+n.cart_price+"</span> X <span>"+n.quantity+"</span></div><div class=\"cart_clistd\"><a onclick=\"del_cart("+n.cart_id+");\" style=\"cursor:pointer\" class=\"redf5\">Delete</a></div>");
			row.attr("id","create_memu_cart_list");
			row.appendTo("#menu_cart_data");
		});
		

		$("[@id=create_memu_cart_list]").show();
		$("#menu_sub_quantity_show").html(cart_total.sub_quantity);
		$("#menu_sub_quantity").html(cart_total.sub_quantity);
		$("#menu_sub_total").html('$'+cart_total.sub_total);
	});
}

/* *
 * 删除购物车产品
 */
function del_cart(cart_id){
	$.get("/cart/cart.php?act=del_cart&ajax=true",{cart_id:cart_id},
	function(){
		get_menu_cart_list();
		if(typeof(view_type)=="function") { // 列表页显示已购数量
			view_type();
		}
	});
}

/* *
 * 层提示框
 */
function show_div_msg_box(msg){
	$("#div_msg_info").html(msg);
	$("#div_msg_box").fadeIn("fast");
	document.getElementById("div_msg_box").style.left=(document.documentElement.clientWidth-document.getElementById("div_msg_box").clientWidth)/2+document.documentElement.scrollLeft+"px"; 
	document.getElementById("div_msg_box").style.top=(document.documentElement.clientHeight-document.getElementById("div_msg_box").clientHeight)/2+document.documentElement.scrollTop+"px";

	var timer;
	window.clearTimeout(timer);
	timer=setTimeout(function() {$("#div_msg_box").fadeOut("fast")}, 1500);
}

/* *
 * 只能输入数字
 */
isNumber = function (e) {   
    if ($.browser.msie) {   
        if ( ((event.keyCode > 47) && (event.keyCode < 58)) ||   
              (event.keyCode == 8) ) {   
            return true;   
        } else {   
            return false;   
        }   
    } else {   
        if ( ((e.which > 47) && (e.which < 58)) ||   
              (e.which == 8) ) {   
            return true;   
        } else {   
            return false;   
        }   
    }   
}

/* *
 * 在线咨询工具
 */
function openChat(product_name,product_id,workerid) {
	var sWoker = ""
	if(typeof(workerid) != "undefined") sWoker = "workId="+workerid + "&flag=3&";
	var username = product_name +"||"+product_id;
	var kf_openurl="  http://chat.5251.net/client.jsp?flag=1&companyId=11283&style=24432&locate=en&" + sWoker +"refer="+ escape(window.location.href)+"&username="+encodeURIComponent(username)+"&conn_word="+encodeURIComponent("");
	var chat_win= window.open(kf_openurl,'chat_11283','height=473,width=703,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no');
	chat_win.focus();
}

document.getCookie = function getCookie(sName) {
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++) {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return decodeURIComponent(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

document.setCookie = function(sName, sValue, sExpires) {
  var sCookie = sName + "=" + encodeURIComponent(sValue);
  if (sExpires != null) {
    sCookie += "; expires=" + sExpires;
  }

  document.cookie = sCookie;
}

document.removeCookie = function(sName,sValue) {
  document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
