// 头部相关js代码
/* 收缩的链接文字修改 /说明：target 监控标签css ,tagname 文字标签css,text1 默认文字,text2 修改文字 / */
function togglelink(target, tagname, text1, text2) {
	if ($(target).find(tagname).html() == text1) {
		$(target).find(tagname).html(text2);
	} else {
		$(target).find(tagname).html(text1);
	}
}
/*
 * 收缩的动作 /说明：target 监控标签css,togglecss 需要隐含的内容标签css, 如果隐含标签不再监控标签中target 可以为
 * toggleaction("",".clickbar"); /
 */
function toggleaction(target, togglecss) {
	if (togglecss != "") {
		$(target).find(togglecss).toggle();
	} else {
		$(togglecss).toggle();
	}

}
/* 通用提示窗口 */
function winpop(winid, h3title, contenthtml, winwidth, winheight) {
	$("#winpop").clone().insertAfter("#winpop").removeAttr("id").attr("id",
			winid).addClass(winid);
	var winidwh3 = "." + winid + " h3";
	var winidwcon = "." + winid + " .wincontent";
	var winidw = "." + winid + ".winpop";
	if ($(winidwh3).text() == '') {
		var options = {};

		$(winidwh3).html(h3title);
		$(winidwcon).append(contenthtml);

		/*
		 * $(winidw).draggable({ opacity: 0.7, handle: 'h3', cursor: 'move',
		 * containment: $('#demo-frame').length ? '#demo-frame' : 'document',
		 * start : function(){ $(".winpop").css("z-index","9999");
		 * $(winidw).css('z-index',"10000"); } });
		 */
		$("#main").append("<div class='winpopbg'></div>");
		var bgwidthvar = $("body").width();
		var bgheightvar = $("body").height();
		$(".winpopbg").animate( {
			width : bgwidthvar,
			height : bgheightvar
		});
		var leftvar = ($(window).width() / 2 - (winwidth / 2));
		var topvar = ($(window).height() / 2 - (winheight / 2));
		$(winidw).animate( {
			width : winwidth,
			height : winheight,
			top : topvar,
			left : leftvar
		});
	}
	/*
	 * $(winidw) .bind("click",function(){ });
	 */
	$(".winpop a.winclose").bind("click", function() {
		$(winidw).remove()
		$('.winpopbg').remove();
	});

}

$(function() {
	/*
	 * var Swidth=screen.width;var Surl="styles/"; var Skin=["basic.css"]; var
	 * Skintemp; if (Swidth>=1280){Surl+="css1200";} else{Surl+="css1024";} for
	 * (var i=0;i<Skin.length;i++){ Skintemp=document.createElement("link");
	 * Skintemp.type="text/css"; Skintemp.rel="stylesheet";
	 * Skintemp.href=Surl+"/"+Skin[i];
	 * document.getElementsByTagName("head")[0].appendChild(Skintemp); }
	 */
	/*全选*/
	$('.checkall').bind("click", function() {
		checked = $(this).attr("checked");
		if( checked == undefined ){
			checked = false;
		}
		$('input[@type=checkbox]').attr('checked', checked );
	});
	/* 我的关注、修改密码、常用收货人、订单详情 */
	$('#operate_del_order').click(function(e) {
		e.preventDefault();
		$('.win1').modal();
		var winwidth = $(".win1").width();
		var winheight = $(".win1").height() + 20;
		$('.simplemodal-container').animate( {
			width : winwidth,
			height : winheight
		});
	});
	/*会员中心-修改订单*/
	$(".operate_change").bind("click",function(){
		var orderCode = $(".orderCode").text();
		window.location.href = "shoppingCart.do?method=reBuyMerchandise&orderCode=" + orderCode;
	});
	/*取消订单*/
	$('.reason li input:radio' ).each(function(){
		$(this).bind("click",function(){
			if( $(this).attr("checked") ){
				if( $(this).val().charCodeAt() == "其它原因".charCodeAt() ){
					$(".c_message").focus();
				}
				$("#reason").val($(this).val());
			}
		});
	});
	/*合并订单*/
	$(".merge").bind("click",function(){
		$(".uorder input:radio").each(function(){
			if( $(this).attr("checked") ){
				window.location.href = "ordermst.do?method=merge&order_codes=" + $(this).val();
			}
		});
	});
	/*重放购物车*/
	$(".addOrder").bind("click",function(){
		var str = "";
		//var order_code = $("#order_code").val();
		$(".release input:checkbox").each(function(){
			if( $(this).attr("checked") ){
				str = $(this).val() + "," + str; 
			}
		});
		if( str != "" ){
			window.location.href = "shoppingCart.do?method=releaseShoppingCart&orderitem_id=" + str;
		}
	});
	
	$('.operate_car').click(function(e) {
		e.preventDefault();
		$('.win3').modal();
		var winwidth = $(".win3").width();
		var winheight = $(".win3").height() + 20;
		$('.simplemodal-container').animate( {
			width : winwidth,
			height : winheight
		});
	});
	$('.newaddress a:first,.newaddress button,.editaddress').click(function(e) {
		//清空数据 
		$("#updatecode").val("");
		$("#receiveMbrname").val("");
        $("#receiveMbraddress").val("");
        $("#receiveMbremail").val("");
        $("#receiveMbrmobile").val("");
        $("#receiveMbrtel").val("");
        $("#receiveMbrzip").val("");
		$("#p_name").html("");
		$("#c_name").html("");
		$("#d_name").html("");
		$("#addresscode").val("");
		
		e.preventDefault();
		$('.win3').modal();
		var winwidth = $(".win3").width();
		var winheight = $(".win3").height() + 20;
		$('.simplemodal-container').animate( {
			width : winwidth,
			height : winheight
		});
	});
	/*积分兑换*/
	$('.exchange').click(function (e) {
	 	e.preventDefault();
 		$('.win1').modal();
 		
 		$('.simplemodal-container').animate({width: 500,height: 350});
 		var mbrpointgds_ids = $(this).text().split(":");
 		$(".goodspoint").val( mbrpointgds_ids[0] );
 	}); 
	/*
	 * $(".operate_del") .bind("click",function(){ $(".win2,.win3").hide();
	 * $(".win1").toggle(); }); $(".operate_add") .bind("click",function(){
	 * $(".win1,.win3").hide(); $(".win2").toggle(); }); $(".operate_car")
	 * .bind("click",function(){ $(".win2,.win1").hide(); $(".win3").toggle();
	 * }); $(".pwquestion select option") .bind("click",function(){ if
	 * ($(this).get(0).value=="999"){ $(".questiontext").show(); } });
	 */
	$(".ordernumberback").bind("click", function() {
		$(".rmentlist").toggle();
	});
	$(".rmenttr").bind("click", function() {
		$(".rmentform").hide();
		$(this).next(".rmentform").toggle();
	});
	$(".pwselect").change(function() {
		if ($(this).get(0).value == "999") {
			$(".questiontext").show();
		}
	});
	$(".li1").bind("click", function() {
		// $("input.addressname").val($(this > span.addressname).html());
			$("input.addressname").hide();
		});
	$(".price select").change(function() {
		if ($(this).get(0).value != "0") {
			$(".clickbar").hide();
			$(".clickbar thead th").empty();
			$(".clickbar thead th").html("分类编号：");
			$(".clickbar thead th").append($(this).get(0).value);
			$(".clickbar").show();
		} else {
			$(".clickbar").hide();
		}
	});
	/*
	 * $(".price select option") .bind("click",function(){
	 * $(".clickbar").hide(); $(".clickbar thead th").html($(this).get(0).text);
	 * $(".clickbar thead th").append($(this).get(0).value);
	 * $(".clickbar").show();
	 * 
	 * });
	 */
	$(".clickbar p.close").bind("click", function() {
		$(".clickbar").hide();
	});
	/*
	 * $(".newaddress a") .bind("click",function(){ $(".addaddress").toggle();
	 * var topvar=($(window).width()/2-340);
	 * $(".addaddress").animate({top:"300",left:topvar}); });
	 */

	/*
	 * $(".chang a:eq(0)") .bind("click",function(){ $(".editaddress").toggle();
	 * var topvar=($(window).width()/2-340);
	 * $(".editaddress").animate({top:"300",left:topvar}); });
	 */

	/**/
	$(".gview").bind("click", function() {
		$(".gletter").toggle();
	});
	$(".gdel").bind("click", function() {
		$(this).parents("tr").remove();
	});
	$(".gletter .close").bind("click", function() {
		$(".gletter").hide();
	});
	$(".delbut").bind("click", function() {
		$(this).parents("tbody").remove();
	});

	/* looksee */
	$(".lview").bind("click", function() {
		$(".looksee").toggle();
	});

	$(".ljoin").bind("click", function() {
		$(".looksee2").toggle();
	});

	$(".looksee .winclose").bind("click", function() {
		$(".looksee").hide();
	});
	$(".looksee2 .winclose").bind("click", function() {
		$(".looksee2").hide();
	});

	//cookies 开始
	$.cookie = function(name, value, options) {
		if (typeof value != 'undefined') {
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires
					&& (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime()
							+ (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString();
			}
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires,
					path, domain, secure].join('');
		} else {
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0;i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);

					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie
								.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	};
	// cookies 结束
	/*
	 * $(".chooselist") .bind("click",function(){ $(".addresslist").toggle();
	 * });
	 */
	$(".addresslist .close").bind("click", function() {
		$(".addresslist").hide();
	});
	/* member feedback */
	$(".special").bind("click", function() {
		$(".feedback").toggle();
	});
	$(".feedback .close").bind("click", function() {
		$(".feedback").hide();
	});
	/* 头文件 header 登录状态 temp */
	/* pagelist search_digital search_keyword */
	$(".s2").bind("click", function() {
		$(".pagelist").addClass("pagelist2");
		$(".s1 > a").removeClass("curr");
		$(".s2 > a").addClass("curr");
	});
	$(".s1").bind("click", function() {
		$(".pagelist").removeClass("pagelist2");
		$(".s2 > a").removeClass("curr");
		$(".s1 > a").addClass("curr");
	});
	/* viewprice */
	$(".s3").bind("click", function() {
		$("#viewprice").toggle();
	});
	
	//index page category and brand toggle
	$('#main > div[class="sidebar"] > ul[class="title"] li:first').mouseover(function(){
		$(this).addClass("t");
		$(this).siblings().removeAttr("class");
		$('ul[class="category box"]').show();
		$('ul[class="category box hidden"]').hide();
	});
	
	$('#main > div[class="sidebar"] > ul[class="title"] li:last').mouseover(function(){
		$(this).addClass("t");
		$(this).siblings().removeAttr("class");
		$('ul[class="category box hidden"]').show();
		$('ul[class="category box"]').hide();
	});
	
	//商品页
	$('div[class="sidebar"] ul[class="title"] li:first').mouseover(function(){
		$(this).addClass("t");
		$(this).siblings().removeAttr("class");
		$('ul[class="category box"]').show();
		$('ul[class="category box hidden"]').hide();
	});
	
	$('div[class="sidebar"] ul[class="title"] li:last').mouseover(function(){
		$(this).addClass("t");
		$(this).siblings().removeAttr("class");
		$('ul[class="category box hidden"]').show();
		$('ul[class="category box"]').hide();
	});
 
	//brands page brand and category toggle
	$('#B_sidebar div[class="brand_sort"] ul[class="title"] li:first').mouseover(function(){
		$(this).addClass("t");
		$(this).siblings().removeAttr("class");
		$('ul[class="category box"]').show();
		$('ul[class="category box hidden"]').hide();
	});
	
	$('#B_sidebar div[class="brand_sort"] ul[class="title"] li:last').mouseover(function(){
		$(this).addClass("t");
		$(this).siblings().removeAttr("class");
		$('ul[class="category box hidden"]').show();
		$('ul[class="category box"]').hide();
	});
	
	//购物达人,社会热点切换
	$('div[class="attention"] ul:first li:first').mouseover(function(){
		$(this).addClass("y");
		$(this).siblings().removeAttr("class");
		$('ul[class="content box"]').show();
		$('ul[class="content box hidden"]').hide();
	});
	
	$('div[class="attention"] ul:first li:last').mouseover(function(){
		$(this).addClass("y");
		$(this).siblings().removeAttr("class");
		$('#H_socity').show();
		$('ul[class="content box"]').hide();
	});
	
	//新品推荐,热销商品切换
	$('#product_1 h2 a:first').mouseover(function(){
		$(this).addClass("d");
		$(this).siblings().removeAttr("class");
		$('#N_products').show();
		$('#H_products').hide();
	});
	
	$('#product_1 h2 a:last').mouseover(function(){
		$(this).addClass("d");
		$(this).siblings().removeAttr("class");
		$('#H_products').show();
		$('#N_products').hide();
	});
	
	//会员专区,积分兑换切换
	$('#product_2 h2 a:first').mouseover(function(){
		$(this).addClass("d");
		$(this).siblings().removeAttr("class");
		$('#M_products').show();
		$('#P_products').hide();
	});
	
	$('#product_2 h2 a:last').mouseover(function(){
		$(this).addClass("d");
		$(this).siblings().removeAttr("class");
		$('#P_products').show();
		$('#M_products').hide();
	});
	
	//中部类别图片切换,first
	$('p[id="name_1"] a').each(function(i){
		$(this).mouseover(function(){
			$(this).addClass("productname_1");
			if( i == 0 ){
				$('div[id="js_content_first"] img').eq(0).removeAttr("class");
				$('div[id="js_content_first"] img').eq(0).siblings("img").addClass("hidden");
			}else if( i == 1 ){
				$('div[id="js_content_first"] img').eq(1).removeAttr("class");
				$('div[id="js_content_first"] img').eq(1).siblings("img").addClass("hidden");
			}else{
				$('div[id="js_content_first"] img:last').removeAttr("class");
				$('div[id="js_content_first"] img:last').siblings("img").addClass("hidden");
			}
			$(this).siblings().removeAttr("class");
		});
	});
	
	//中部类别图片切换,second
	$('p[id="name_2"] a').each(function(i){
		$(this).mouseover(function(){
			$(this).addClass("productname_1");
			if( i == 0 ){
				$('div[id="js_content_second"] img').eq(0).removeAttr("class");
				$('div[id="js_content_second"] img').eq(0).siblings("img").addClass("hidden");
			}else if( i == 1 ){
				$('div[id="js_content_second"] img').eq(1).removeAttr("class");
				$('div[id="js_content_second"] img').eq(1).siblings("img").addClass("hidden");
			}else{
				$('div[id="js_content_second"] img:last').removeAttr("class");
				$('div[id="js_content_second"] img:last').siblings("img").addClass("hidden");
			}
			$(this).siblings().removeAttr("class");
		});
	});
	
	//中部类别图片切换,third
	$('p[id="name_3"] a').each(function(i){
		$(this).mouseover(function(){
			$(this).addClass("productname_1");
			if( i == 0 ){
				$('div[id="js_content_third"] img').eq(0).removeAttr("class");
				$('div[id="js_content_third"] img').eq(0).siblings("img").addClass("hidden");
			}else if( i == 1 ){
				$('div[id="js_content_third"] img').eq(1).removeAttr("class");
				$('div[id="js_content_third"] img').eq(1).siblings("img").addClass("hidden");
			}else{
				$('div[id="js_content_third"] img:last').removeAttr("class");
				$('div[id="js_content_third"] img:last').siblings("img").addClass("hidden");
			}
			$(this).siblings().removeAttr("class");
		});
	});
	
	//中部类别图片切换,fourth
	$('p[id="name_4"] a').each(function(i){
		$(this).mouseover(function(){
			$(this).addClass("productname_1");
			if( i == 0 ){
				$('div[id="js_content_fourth"] img').eq(0).removeAttr("class");
				$('div[id="js_content_fourth"] img').eq(0).siblings("img").addClass("hidden");
			}else if( i == 1 ){
				$('div[id="js_content_fourth"] img').eq(1).removeAttr("class");
				$('div[id="js_content_fourth"] img').eq(1).siblings("img").addClass("hidden");
			}else{
				$('div[id="js_content_fourth"] img:last').removeAttr("class");
				$('div[id="js_content_fourth"] img:last').siblings("img").addClass("hidden");
			}
			$(this).siblings().removeAttr("class");
		});
	});
	
	//品牌中心,图片切换
	$('#brand_ul li').each(function(i){
		$(this).mouseover(function(){
			$(this).addClass("tt");
			if( i == 0 ){
				$('#brand_div_pic img').eq(0).removeAttr("class");;
				$('#brand_div_pic img').eq(0).siblings("img").addClass("hidden");
			}else if( i == 1 ){
				$('#brand_div_pic img').eq(1).removeAttr("class");;
				$('#brand_div_pic img').eq(1).siblings("img").addClass("hidden");
			}else if( i == 2 ){
				$('#brand_div_pic img').eq(2).removeAttr("class");;
				$('#brand_div_pic img').eq(2).siblings("img").addClass("hidden");
			}else if( i == 3 ){
				$('#brand_div_pic img').eq(3).removeAttr("class");;
				$('#brand_div_pic img').eq(3).siblings("img").addClass("hidden");
			}else if( i == 4 ){
				$('#brand_div_pic img').eq(4).removeAttr("class");;
				$('#brand_div_pic img').eq(4).siblings("img").addClass("hidden");
			}
			$(this).siblings("li").removeClass("tt");
		});
	});
	
	//热销商品,热门资讯,积分兑换
	$('div[class="zs"] h2').eq(0).mouseover(function(){
		$(this).attr("class","h2 b");
		$('div[class="zs"] h2').eq(1).attr("class","h2_1")
		$('div[class="zs"] h2').eq(2).attr("class","h2_2");
		
		$('div[class="zs"] ul').eq(0).removeAttr("class");
		$('div[class="zs"] ul').eq(0).siblings("ul").addClass("hidden");
	});
	
	$('div[class="zs"] h2').eq(1).mouseover(function(){
		$(this).attr("class","h2_1 b");
		$('div[class="zs"] h2').eq(0).attr("class","h2")
		$('div[class="zs"] h2').eq(2).attr("class","h2_2");
		
		$('div[class="zs"] ul').eq(1).removeAttr("class");
		$('div[class="zs"] ul').eq(1).siblings("ul").addClass("hidden");
	});
	
	$('div[class="zs"] h2').eq(2).mouseover(function(){
		$(this).attr("class","h2_2 b");
		$('div[class="zs"] h2').eq(0).attr("class","h2")
		$('div[class="zs"] h2').eq(1).attr("class","h2_1");
		
		$('div[class="zs"] ul').eq(2).removeAttr("class");
		$('div[class="zs"] ul').eq(2).siblings("ul").addClass("hidden");
	});
	
	//单品牌页,页签切换
	$('div[class="xprx"] ul:first li:first').mouseover(function(){
		$(this).addClass("li_1");
		$(this).siblings("li").removeAttr("class");
		
		$('div[class="xprx"] ul').eq(1).attr("class","ul_2 box");
		$('div[class="xprx"] ul:last').attr("class","ul_2 box hidden");
	});
	
	$('div[class="xprx"] ul:first li:last').mouseover(function(){
		$(this).addClass("li_1");
		$(this).siblings("li").removeAttr("class");
		
		$('div[class="xprx"] ul:last').attr("class","ul_2 box");
		$('div[class="xprx"] ul').eq(1).attr("class","ul_2 box hidden");
	});
	
	//单商品页
	/*$('div[class="sp_info"] ul[class="u_1 box"] li:first').mouseover(function(){
		$(this).addClass("li_1");
		$(this).siblings("li").removeAttr("class");
		$('div[class="sp_info"] div:first').attr("class","content");
		$('div[class="sp_info"] div:last').attr("class","content hidden")
	});
	
	$('div[class="sp_info"] ul[class="u_1 box"] li:last').mouseover(function(){
		$(this).addClass("li_1");
		$(this).siblings("li").removeAttr("class");
		$('div[class="sp_info"] div:last').attr("class","content");
		$('div[class="sp_info"] div:first').attr("class","content hidden")
	});*/
	
});
