
var CrmUrl = "#";
var ShopUrl = "#";

//网页收藏
function addBookmark(title,url) {
  if (window.sidebar) { 
    window.sidebar.addPanel(title, url,""); 
  }else if( document.all ) {
  window.external.AddFavorite( url, title);
  }else if( window.opera && window.print ){
   return true;
  }
}

/*把用户退出商城系统*/
function logout(userId) {
    var postUrl = CrmUrl +"/Tool/Ajax.ashx"; 
    var re = false;  
    var param = $.param({ op: "shoplogout", userId: userId });
    jQuery.getScript(postUrl+ "?" + param + "&callback=?", function(data) {        
          if(data){
            alert("成功退出！");
           }            
       }); 
    }
    
function jsonp_callback(t){
        var j = eval('(' + t + ')');
        if (j.result == 0) {
            re = true;                     
            location.href= ShopUrl + "/Login.html";
        }
        else {
            alert(j.msg);           
            re = false;
        }
    }



    $(function() {
        if ($("#search").val() == '') {
            $("#search").val('搜索商城商品!');
        }

        $('#search').keydown(function(event) {
            if (event.keyCode == 13) {
                if ($(this).val().length == 0) {
                    alert("请输入要搜索的商品关键字");
                }
                else {
                    $("#btnsearch").click();
                    return false;
                }
            }
        }).focus(function() {
            if ($(this).val() == '搜索商城商品!') {
                $(this).val('');
            }
        }).blur(function() {
            if ($(this).val().length == 0) {
                $(this).val('搜索商城商品!');
            }
        });

        //头部搜索商品
        $("#btnsearch").click(function() {
            var keyword = $("#search").val();
            if (keyword == '' || keyword.indexOf('搜索') != -1) {
                alert("请输入要搜索的商品关键字");
                $("#search").val('');
                $("#search").focus();
            }
            else {
                keyword = encodeURIComponent(keyword);
                var url = ShopUrl + 'products.asp?keyword=' + keyword + '';
                location.href = url;
            }
        });
    });

/*删除导航栏购物车商品*/
function DeleteTopCartPro(rec_id){
      $.ajax({
        type: 'Get',
        url: ShopUrl + '/Handler/AjaxHandler.ashx',
        data: 'action=DeleteCartSinglePro&rec_id=' + rec_id,
        cache: false,
        contentType:"application/x-www-form-urlencoded; charset=utf-8",
        timeout:10000,
        dataType: 'text',
        success: function(result) {
           switch(parseInt(result)){
              case -1:
               alert("系统繁忙，请稍后再试！");
               break;
             case 1104:
                alert("删除失败！");
                break;
             case 1105:
                  load_Top_MenuCart();//重新加载导航条购物车             
                break;
             case 1106:
                alert("参数异常!");
                break;
           }
        }
    });
}
/*加载导航条购物车*/
function load_Top_MenuCart() {
    var thisHREF = document.location.href;
    $.ajax({
        type: 'Get',
        url: ShopUrl + '/Handler/AjaxHandler.ashx',
        data: 'action=getTopCartData',
        cache: false,
        contentType: "application/x-www-form-urlencoded; charset=utf-8",
        timeout: 10000,
        dataType: 'text',
        success: function(result) {
            if (thisHREF.indexOf("CartList") != -1) {//如果当前在购物车页面就刷新页面
                location.href = thisHREF;
            } else {
                $("#top_cart").html(result);
                hoverisblokcornone();
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus);
        }
    });
}
/*购车车效果*/
function hoverisblokcornone(){
   $("#ulCard li").hover( function(){$("#gwcCard").show();},function(){$("#gwcCard").hide();});
}
function iMycartBind(){
//var object_mycart = jQuery("#o-mycart-list");
//jQuery("#i-mycart").bind("mouseover",function(){
//	//object_mycart.show();  
//	jQuery("#o-mycart-list").show();      
//}).bind("mouseleave",function() {
//	//object_mycart.hide(); 
//	jQuery("#o-mycart-list").hide(); 
//	});     
}

jQuery(function() {
       hoverisblokcornone();
	//show-all-category
	var object_category = jQuery("#all_category_warp");
	jQuery("#all_category_menu").bind("mouseover",function() {
		object_category.show();
	}).bind("mouseleave",function() {
		object_category.hide();   
	});
	//del-mycart-items
	jQuery(".pane .del").click(function() {
		jQuery(this).parents(".pane").hide();
	});
});

