﻿$(function(){
//jQuey 
externallinks;
//会员状态
var userName = GetCookie("usernameJS");
var userKey = GetCookie("userKeyJS");
var userFromType = GetCookie("userFromType");
if (userName) {
	$(".loginStat .m1").html('<strong class="userName">'+ userName +'</strong> | <a class="a_color" href="/members/control.asp" rel="blank">会员中心</a>&nbsp; <a href="/members/msgBox.asp?my=yes">消息(<span class="cl_red msgNum">0</span>)</a>&nbsp; <a class="a_color" href="/members/logout.asp">退出</a>');
	$.ajax({url:"/members/ajax.asp?act=getNumbers&userName="+userName+"", type:"GET", dataType:"xml", timeout:8000, 
		success:function(xml){//alert(xml);
		if (xml) {
			var msgNum = $(xml).find("msgNum:first").text();
			var alertNum = $(xml).find("alertNum:first").text();
			$(".msgNum").html(msgNum.toString());
			$(".alertNum").html(alertNum.toString());
		}//End if
		}//End function
	});
} 

//卡片
if ($(".win_head:has(ul.card)")) {
	$(".win_head:has(ul.card)").each(function(){
		$(this).siblings(".win_body").children(".ibody").hide();
		$(this).siblings(".win_body").children("."+$(this).find("li.on>a").attr("rel")).show();
	});
}

if ($(".win_head ul.card a[rel]")) {
$(".win_head ul.card a[rel]").mouseover(function(){
	$(this).parent().attr("class","on");
	$(this).parent().siblings("li").attr("class","");
	var bodyN = "."+ $(this).attr("rel"); //alert(bodyN);
	var win_body = $(this).parents(".win_head").siblings(".win_body");
	win_body.children(".ibody").hide();
	win_body.children(bodyN).show();//fadeIn("normal",function(){});
	return false;
});
$(".win_head ul.card a[rel][rev]").unbind().click(function(){
	$(this).parent().attr("class","on");
	$(this).parent().siblings("li").attr("class","");
	var bodyN = "."+ $(this).attr("rel"); //alert(bodyN);
	var win_body = $(this).parents(".win_head").siblings(".win_body");
	win_body.children(".ibody").hide();
	win_body.children(bodyN).fadeIn("normal",function(){});
	return false;
});
}


$("a.yaoqingClick").click(function(){
	$($(".yaoqingClickHandle").html()).dialog({bgiframe:true, width:350, height:'auto', modal:true,
		title: '邀请朋友加入 （可获取现金奖励）',
		buttons: {
			'发送邀请': function (){
				var theForm = $(this);//alert(theForm.html());
				if (!theForm.find("input[name='mEmail']").val().isEmail()) {
					alert("请正确填写Email地址");
				} else if (!theForm.find("input[name='mFromName']").val()) {
					alert("请填写您的称呼");
				} else {
					var args = "mEmail="+ encodeURIComponent(theForm.find("input[name='mEmail']").val()) +"&mToName="+ encodeURIComponent(theForm.find("input[name='mToName']").val()) +"&mMsg="+ encodeURIComponent(theForm.find("input[name='mMsg']").val()) +"&mFromName="+ encodeURIComponent(theForm.find("input[name='mFromName']").val()) +"";
					theForm.html("<br /><br /><center><img src='/images/loading.gif' alt='' /></center>");
					$.post("/members/yaoqing.asp", args,
					function (data){
						//theForm.html(data);
						theForm.dialog('close');
						if (data) $("<div>"+data+"</div>").dialog({bgiframe:true, title:"发送成功", buttons:{"确认":function(){$(this).dialog("close");}}});
					});
				}
			},
			'为什么有现金奖励': function(){ window.open('/help/%E9%82%80%E8%AF%B7%E6%9C%8B%E5%8F%8B%E5%8A%A0%E5%85%A5%E7%89%A9%E6%AF%94%E4%B8%89%E5%AE%B6%EF%BC%8C%E8%8E%B7%E5%BE%97%E6%B0%B8%E4%B9%85%E8%BF%94%E7%8E%B0%E5%A5%96%E5%8A%B1%5Fr2p1.htm');},
			'取消': function(){ $(this).dialog('close');}
		},
		open: function(){ $(this).dialog('moveToTop');},
		close: function(){ $(this).dialog('destroy');}
	});
	return false;
});

$(".showInDialog").each(function(){
	$(this).click(function(){$('<div style="margin:0;"><div style="width:516px; height:400px; overflow:auto; overflow-x:hidden; overflow-y:auto;"><iframe class="dialogiframe" frameborder="0" marginheight="0" marginwidth="0" width="516" scrolling="auto" onload="javascript:this.height=this.contentWindow.document.body.scrollHeight;" src="'+ $(this).attr("href") +'"></iframe></div></div>').dialog({bgiframe:true, 
	modal:true, title:"详情", height:'auto', width:520, height:470,
	buttons:{"关闭": function(){$(this).dialog('close');}},
	open: function(){ $(this).dialog('moveToTop');},
	close: function(){ $(this).dialog('destroy');}
	});
	return false;
	});
});

//更新数据
if ($(".memberNum").length>0 || $(".goodsNum").length>0) { $.ajax({url:"/xml/siteNumbers.xml", type:"GET", dataType:"xml", timeout:8000, 
	success:function(xml){//alert(xml);
	if (xml) {
		var memberNum = $(xml).find("memberNum:first").text();
		var buyNum = $(xml).find("buyNum:first").text();
		var moneyNum = $(xml).find("moneyNum:first").text();
		var goodsNum = $(xml).find("goodsNum:first").text();
		var gNewNum = $(xml).find("gNewNum:first").text();
		var gDropNum = $(xml).find("gDropNum:first").text();
		$(".memberNum").html(memberNum.toString());
		$(".goodsNum").html(goodsNum.toString());
	}//End if
	}//End function
}); 
}


//表格鼠标效果
$("table.tableTrOn tr").not(".head").mouseover(function(){
	$(this).css({'background':'#F7FFE8'});
}).mouseout(function(){
	$(this).css({'background':'none'});
});


//Cards Digg
$(".diggs>.diggIt>.diggCard").click(function(){
	doVote('card',Number($(this).attr("rel")),1);
	$(this).siblings(".number").html( Number($(this).siblings(".number").html())+1 );
	$(this).unbind('click').click(function(){alert('只能投票一次');});
	return false;
});
function doVote(kind,ID,N){ //N = 1 / -1
	var cents = N;
	if (cents>0) {cents=1;} else if (cents<0) {cents=-1;} else { return; }
	$.get("/include/ajax.asp?act=vote&kind="+ kind +"&ID="+ ID +"&cents="+ cents +"",function(data){
		//alert(data);
	});
	return false;
}



//栏目收起
$(".win_head .close").each(function(){
	$(this).parents(".win_head").toggle(function(){
		$(this).siblings(".win_body").slideUp();
		$(this).find(".close").css("background","url(../images/icn_doShow.gif) no-repeat center");
	},function(){
		$(this).siblings(".win_body").slideDown();
		$(this).find(".close").css("background","url(../images/icn_doHide.gif) no-repeat center");
	});
});
$(".win_head .close2").each(function(){
	$(this).parents(".win_head").toggle(function(){
		$(this).siblings(".win_body").slideDown();
		$(this).find(".close").css("background","url(../images/icn_doHide.gif) no-repeat center");
	},function(){
		$(this).siblings(".win_body").slideUp();
		$(this).find(".close").css("background","url(../images/icn_doShow.gif) no-repeat center");
	});
});


//目录点击展开#category
function showHideMenu(jObj) { //jObj:list1
	var catStatus = jObj.children("a.aNext").children("div").attr("class");
	if (catStatus=="catNextOpen"){
		jObj.children("a.aNext").children("div").attr("class","catNextClose");
		jObj.css("background-color","#F5F5F5");
		jObj.siblings(".list2").slideUp("fast");
	} else {
		jObj.children("a.aNext").children("div").attr("class","catNextOpen");
		jObj.css("background-color","#FBFFEA");
		jObj.siblings(".list2").slideDown("fast");
	}
}
$(".list1").each(function(){
	if ($(this).find("a.aNext").length>0) {
		$(this).click(function(){
			showHideMenu($(this));
			return false;
		});
	}
});
$(".list2 a").click(function(){
	$(this).parent(".list2").addClass("listOn");
	$(this).parent(".list2").siblings(".list2").removeClass("listOn");
});
//默认关闭的子目录[-]
$(".catNextClose").each(function(){
	$(this).parents(".list1").siblings(".list2").hide();
	$(this).parents(".list1").css("background-color","#F5F5F5");
});
$(".catNextOpen").each(function(){
	$(this).parents(".list1").css("background-color","#FBFFEA");
});


//商品new hot
if ($(".gList").length>0) {
	$(".gList .goods").mouseover(function(){
		$(this).addClass("on");
		$(this).css("position","relative");
		if ($(this).find(".new").length>0) {
			$(this).find(".newhot").append("<img src='/images/new.gif' alt='' />");
		}
		if ($(this).find(".hot").length>0) {
			$(this).find(".newhot").append("<img src='/images/hot.gif' alt='' />");
		}
	}).mouseout(function(){
		$(this).removeClass("on");
		$(this).css("position","static");
		$(this).find(".newhot").empty();
	});
}

$(".sQ").each(function(){
	if ($(this).val()=='搜索商家、特价商品，如：女装') {
		$(this).addClass("sblur").removeClass("sfoc");
	} else {
		$(this).addClass("sfoc").removeClass("sblur");
	}
});

$(".sQ").focus(function(){
	if ($(this).val()=='搜索商家、特价商品，如：女装') {
		$(this).val("");
		$(this).addClass("sfoc").removeClass("sblur");
	}	
}).blur(function(){
	if ($(this).val()=='') {
		$(this).val("搜索商家、特价商品，如：女装");
		$(this).addClass("sblur").removeClass("sfoc");
	}	
});

if (userFromType=="taobao" && $(".mainLeftLoginTB").length>0 && userName) {
	$(".mainLeftLoginHeadTB").html('淘宝用户 ('+ userName +')');
	$.get("/members/include/memberMenu.htm",function(data){
		if (data) $(".mainLeftLoginTB").html(data);
	});
	$(".left5F").hide();
} else if ($(".mainLeftLogin").length>0 && userName) {
	$(".mainLeftLoginHead").html('我的物比三家 ('+ userName +')');
	$.get("/members/include/memberMenu.htm",function(data){
		if (data) $(".mainLeftLogin").html(data);
	});
	$(".leftTB").hide();
	$(".left5F").css({"margin-top":0});
}

//缩放图片 最好放在最后执行
function doImgResize(){
	$(".imgResize").each(function(i){
		var imgObj = $(this).find("img").get(0);
		if (!imgObj || imgObj.length==0) return;
		var width = $(this).css("width").replace("px","");
		var height = $(this).css("height").replace("px","");
		if (!width && $(imgObj).attr("title")) {
			var midNum = $(imgObj).attr("title").indexOf("*");
			width = $(imgObj).attr("title").substr(0,midNum); 
			height = $(imgObj).attr("title").substr(midNum+1);
		}
		if(imgObj.complete || imgObj.readyState =="complete") { DrawImage(imgObj,width,height);}
		else {
			$(imgObj).css({"width":width, "height":"auto"});
		}
	});
	$(".imgResize2").each(function(i){
		var imgObj = $(this).find("img").get(0);
		if (!imgObj || imgObj.length==0) return;
		var width = $(this).css("width").replace("px","");
		var height = $(this).css("height").replace("px","");
		if (!width && $(imgObj).attr("title")) {
			var midNum = $(imgObj).attr("title").indexOf("*");
			width = $(imgObj).attr("title").substr(0,midNum); 
			height = $(imgObj).attr("title").substr(midNum+1);
		}
		if(imgObj.complete || imgObj.readyState =="complete") { DrawImage2(imgObj,width,height);}
		else {
			$(imgObj).css({"width":width, "height":"auto"});
		}
	});
}
setTimeout(doImgResize, 1800);

//hotlist
var refUrl = document.referrer;
var refSE=""; var ref_reg;
ref_reg = /\.google\.com/i
if (ref_reg.test(refUrl)) refSE="google";
ref_reg = /\.google\.cn/i
if (ref_reg.test(refUrl)) refSE="google";
ref_reg = /\.baidu\.com/i
if (ref_reg.test(refUrl)) refSE="baidu";
ref_reg = /\.bing\.com/i
if (ref_reg.test(refUrl)) refSE="bing";
ref_reg = /\.yahoo\.com/i
if (ref_reg.test(refUrl)) refSE="yahoo";
ref_reg = /\.sogou\.com/i
if (ref_reg.test(refUrl)) refSE="sogou";
ref_reg = /\.youdao\.com/i
if (ref_reg.test(refUrl)) refSE="youdao";
if (refSE) {
	var refTitle=document.title;
	var myUrl=document.location.href;
	$.get("/hotlist/inc_hot.asp?se="+ refSE +"&url="+ encodeURIComponent(myUrl) +"&refUrl="+ encodeURIComponent(refUrl) +"&title="+ encodeURIComponent(refTitle) +"",function(data){
		//alert(data);
	});
}

//维护提醒
var d1 = new Date(2009,11,20,1,30,0);
var d2 = new Date(2009,11,20,6,30,0);
if (new Date()>=d1 && new Date()<=d2) {
	$(".autoMsgShow").show().append('<div class="msgWrong"><strong>维护公告</strong>：'+d1.getMonth()+'月'+d1.getDate()+'日'+d1.getHours()+'点'+d1.getMinutes()+'分到'+d2.getMonth()+'月'+d2.getDate()+'日'+d2.getHours()+'点'+d2.getMinutes()+'分期间系统维护中，由此给您带来的不便敬请谅解！</div>');
}

//jQuey End
});

