var location_url=document.location.href;
var city_name='\u5168\u56fd';
var skip_set_city=0;
var suffix='';
var host_url='';
var site_domain='';
host_url=window.location.host;
host_url=host_url.toLowerCase();
site_domain=host_url;
function getLoginUser(user){
if(user==''){
ini_top_nav_html('');
}else{
ini_top_nav_html(user.name);
}
}
function URLEncode (clearString) {
var output = '';
var x = 0;
clearString = clearString.toString();
var regex = /(^[a-zA-Z0-9-_.]*)/;
while (x < clearString.length) {
var match = regex.exec(clearString.substr(x));
if (match != null && match.length > 1 && match[1] != '') {
output += match[1];
x += match[1].length;
} else {
if (clearString.substr(x, 1) == ' ') {
clearString[x] == ' '
output += '+';
}
else {
var charCode = clearString.charCodeAt(x);
var hexVal = charCode.toString(16);
output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
}
x++;
}
}
return output;
}
function ini_top_nav_html(login_user){
var city_id='';
city_id=jia_header_get_cookie('jia_city_id');
if(city_id=='shanghai' || city_id=='other'){
var fenzhan='';
}else{
var fenzhan=city_id+'/';
}
var div_city_id=city_id;
var app_id='201';
if(site_domain=='zhuangxiu.jia.com'){
app_id='200';
}
var returl=URLEncode(location_url);
var top_nav_html='';
if(!login_user){
top_nav_html='
';
top_nav_html+='登录 ';
top_nav_html+='注册';
top_nav_html+='|';
top_nav_html+='';
}else{
top_nav_html+='欢迎您!';
top_nav_html+='';
top_nav_html+='
'+login_user+'';
top_nav_html+='
';
top_nav_html+=' - 我的齐家
';
top_nav_html+=' - 我的订单
';
top_nav_html+=' - 我的论坛
';
top_nav_html+=' - 安全退出
';
top_nav_html+='';
top_nav_html+='
';
top_nav_html+='
';
top_nav_html+=' |';
top_nav_html+=' ';
}
top_nav_html+='';
top_nav_html+=' ';
top_nav_html+=' ';
top_nav_html+=' ';
top_nav_html+='';
top_nav_html+=' |';
top_nav_html+=' '+city_name+'[更换城市]';
top_nav_html+='';
jQuery("#user-info").html(top_nav_html);
jQuery(".myorder,.mini_cart").hover(function () {
jQuery(this).find(".menu_bd").removeClass("hide").addClass("show");
load_cart_data();
}, function () {
jQuery(this).find(".menu_hd").removeClass("hover");
jQuery(this).find(".menu_bd").removeClass("show").addClass("hide");
});
jQuery(".mini_cart .cart_bd li").hover(function () {
jQuery(this).toggleClass("item-highlight");
});
load_cart_data();
}
function del_cart_item(item_id,obj){
var $this=jQuery(obj);
jQuery.ajax({
url: 'http://mall.jia.com/order/cart/top_nav_delete_cart?item_id='+item_id+'&callback=?',
type: 'GET',
async: false,
dataType: 'jsonp',
jsonp: 'callback',
success: function(data) {
jQuery(".menu_hd .red").text("("+data['count']+")");
var parentNode = $this.parent().parent().parent();
parentNode.remove();
jQuery(".show_cart_msg").html("");
jQuery(".cart_bd li").eq(4).show();
var count = (data['count']-5>0)?(data['count']-5):0;
jQuery(".cart_info em").text(count);
load_cart_data();
}
});
}
function ini_cart_data(da){
var data = da.list ;
var item_count = da.item_count ;
if(item_count.shop_msg == 0) {
jQuery(".menu_hd .red").text("");
jQuery(".show_cart_msg").html(" 您的购物车暂时为空,请赶快购物吧!");
jQuery(".menu_bd ul").html("");
jQuery(".cart_info em").text('0');
jQuery(".mini_cart s").removeClass('has');
jQuery(".menu_hd .red").text("(0)");
}else{
var str = '';
var p_show=0;
for(var i =0;i4){ str +='style="display: none;"';}
str += '>';
str += '';
str += ' ';
if(data[i].comments || data[i].comments=='undefined')
{
str +=' 颜色:'+data[i].comments +'';
}
str +=''+(data[i].price*data[i].product_count).toFixed(2)+' 元
删除
';
if(i<5){
p_show = parseInt(p_show)+parseInt(data[i].product_count);
}
}
jQuery(".show_cart_msg").html("");
jQuery(".menu_bd ul").html("");
jQuery(".menu_hd .red").text("("+item_count['product_show_count']+')') ;
jQuery(".cart_bd ").append(str);
jQuery(".mini_cart s").addClass('has');
if(parseFloat(da['item_count']['product_show_key'])<5)
{
jQuery(".cart_info em").text(0);
jQuery(".cart_info").hide();
}else{
jQuery(".cart_info em").text((parseInt(item_count['product_show_count'])-p_show));
}
}
}
function load_cart_data(){
jQuery.ajax({
type: "get",
url: "http://mall.jia.com/order/cart/top_nav_js?json=true&callback=?",
dataType: "jsonp",
jsonp: 'callback',
cache: false,
timeout : 10000,
error: function(error){},
success: function(da) {
jQuery(".cart_bd ").html("");
ini_cart_data(da);
}
});
}
function jia_header_get_cookie(c_name){
if (document.cookie.length>0){
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1){
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
jQuery("head").append("");