// JavaScript Document

// 头部相关js代码

$(function() {
	$(".loginno").bind("click", function() {
		$(".loginno").hide();
		$(".loginok").show();
	});
	$(".loginok").bind("click", function() {
		$(".loginok").hide();
		$(".loginno").show();
	});
	$(".status dl").bind("mouseover", function() {
		$(".status dd").show(500);
	});
	$(".status dl").bind("mouseout", function() {
		$(".status dd").hide();
	});
	/* 头文件 购物车 */
	$(".links a.cart").bind("click", function() {

		$(".cartList").toggle();
	});
	$(".cartList a.winclose").bind("click", function() {

		$(".cartList").hide();
	});
	/* 头文件搜索 */
	$(".pform").bind("click", function() {
		$(".keywordlist").toggle();
	});
	$(".keywordlist span").bind("click", function() {
		$("input.pftext").val($(this).html());
		$(".keywordlist").hide();
	});

	/*
	 * $(".keywordlistclose") .bind("click".function(){
	 * $(".keywordlist").hide(); });
	 */

	$(".keywordlist li").mouseover(function() {
		$(this).addClass("keybg");
	}).mouseout(function() {
		$(this).removeClass("keybg");
	});
});

/* 收缩的链接文字修改 /说明：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); }
	 */

	$('button').bind("mousedown", function() {
		$(this).animate( {
			opacity : 0.3
		});
	});
	$('button').bind("mouseup", function() {
		$(this).animate( {
			opacity : 1
		});
	});
	$('button').bind("mouseout", function() {
		$(this).animate( {
			opacity : 1
		});
	});
	
	/*全选*/
	$('.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) {
		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();
	});

	$(".l2").bind("click", function() {
		$(".pagelist").addClass("pagelist2");
		$("a.l1").removeClass("curr");
		$("a.l2").addClass("curr");
	});
	$(".l1").bind("click", function() {
		$(".pagelist").removeClass("pagelist2");
		$("a.l2").removeClass("curr");
		$("a.l1").addClass("curr");
	});
	$(".licence").bind("click", function() {
		$(".pwquestion").toggle();
	});
	/*
	 * $(".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();
	});

	/* 购物车 chooseorder orderaddress */
	$(".del").bind("click", function() {
		// $(this>tr).remove();
			$(this).parents("tr").remove();
		});

	// cookies 开始
	jQuery.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();
	});

	// 显示条目
	$(".s6").bind("click", function() {
		pvCities.setPageSize(parseInt(16));
		return false;
	});
	$(".s7").bind("click", function() {
		pvCities.setPageSize(parseInt(24));
		return false;
	});
	$(".s8").bind("click", function() {
		pvCities.setPageSize(parseInt(48));
		return false;
	});

	// 排序
	// 按价格

	$(".s5").bind("click", function() {
		alert("点击");
		dsCities.sort(["goods_goods_memberprice"], "toggle");

	});

	// 按上架时间

	// 表格奇偶行
	$(".stripeTb1 tr").mouseover(function() {
		$(this).addClass("over");
	}).mouseout(function() {
		$(this).removeClass("over");
	});
	// $(".stripeTb2 tr:even").addClass("alt");
	// dl奇偶行
	// $(".stripeDl dl:odd").addClass("alt");

	// 注册隐含协议 loginstep1
	$(".loginChoose").bind("click", function() {
		$(".loginHide").toggle();
	});
});
