var WRFUSER={};
var WRFDJTAG={};
(function($){
	WRFDJTAG.playpage={
		itemid:0,
		uid:0,
		boxh:132,
		init:function(id){
			var _this=this;
			_this.itemid=id;
			_this.boxh=132;
			$("#djtagform").height(_this.boxh);
			if($("#djtagform .systags dd").html()!=''){
				$("#djtagform .systags").show();
				_this.boxh+=25;
				$("#djtagform").height(_this.boxh);
			}
			if(WRFUSER.Info.uid>0){
				$("#djtagform .mytags").hide();
				$.ajax({
					type: "POST",
					url: '/indexcp.php?action=getDjUserTag&ac=my&itemid='+_this.itemid+'&uid='+WRFUSER.Info.uid,
					dataType: 'json',
					success: function(data){
						if(typeof(data)!='object' || !data){
						}else{
							if(data.error == 0 && data.msg!=''){
								$("#djtagform .mytags dd").html(data.msg);
								$("#djtagform .mytags").show();
								_this.boxh+=25;
								$("#djtagform").height(_this.boxh);
							}
						}
						$("#tagform_tag").val('');
						$.ajax({
							type: "POST",
							url: '/indexcp.php?action=getDjUserTag&ac=item&itemid='+_this.itemid+'&uid='+WRFUSER.Info.uid,
							dataType: 'json',
							success: function(data){
								if(typeof(data)!='object' || !data){
									return;
								}
								if(data.error == 0){
									$("#tagform_tag").val(data.msg);
									WRFDJTAG.playpage.tagaction();
								}
							}
						});
					}
				});
			}		
		},
		setDjTag:function(){
			var _this=this;
			if(WRFUSER.Info.uid==0){
				$(".ajax_user a.ligthlogin").click();
				return;
			}
			if(_this.uid!=WRFUSER.Info.uid){
				_this.init(_this.itemid);
			}
			_this.opentagwin();
		},
		opentagwin:function(){
			var _this=this;
			if(_this.uid!=WRFUSER.Info.uid){
				window.setTimeout("WRFDJTAG.playpage.opentagwin()",300);
				return;
			}
			$.fancybox({
				'width'				: 440,
				'height'			: 222,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'scrolling'			: 'no',
				'type'				: 'inline',
				'padding'			: 0,
				'href'				: '#djtagform'
			});
		},
		tagaction:function(){
			var _this=this;
			$("#djtagform .bt_tag").css('color','black');
			$("#djtagform dl span").each(function(i){
				var tags=','+$("#tagform_tag").val()+',';
				var tagid=$(this).attr("tagid");
				var tag=$(this).text();
				var otags=tags.replace(','+tag+',',',');
				if(otags!=tags){
					$("#djtagform .bt_tag[tagid="+tagid+"]").css('color','red');
				}
			});
			$("#djtagform .bt_tag").click(function(){
				var tags=','+$("#tagform_tag").val()+',';
				var tagid=$(this).attr("tagid");
				var tag=$(this).text();
				var otags=tags.replace(','+tag+',',',');
				if(otags==tags){
					$("#djtagform .bt_tag[tagid="+tagid+"]").css('color','red');
					otags+=tag+',';
				}else{
					$("#djtagform .bt_tag[tagid="+tagid+"]").css('color','black');
				}
				otags=otags.replace(',,',',');
				var l=otags.length-2;
				$("#tagform_tag").val(otags.substr(1,l));
			});
			_this.uid=WRFUSER.Info.uid;
			$("#djtagform .btn").click(function(){
				var tag=$("#tagform_tag").val();
				tag=$.trim(tag);
				if(tag==''){
					alert('标签不能为空');
					return;
				}
				var arrtag=tag.split(',');
				if(arrtag.length>10){
					alert('最多贴10个标签');
					return;
				}
				$.ajax({
					type: "POST",
					url: '/indexcp.php?action=addItemTag',
					data: 'itemid='+_this.itemid+'&tag='+tag,
					dataType: 'json',
					success: function(data){
						if(typeof(data)!='object' || !data){
							alert('添加标签失败，稍候重试');
							return;
						}
						if(data.error == 0){
							$.fancybox.close();
						}else{
							if(typeof(data.msg)!='undefined'){
								alert(data.msg);
							}else{
								alert('设置标签失败，稍候重试');
							}
						}
					}
				});
			});
		}
	};
	WRFUSER.Info={
		uid:'0',
		username:'游客',
		vip:0
	};
	WRFUSER.Ajax={
		tpl:[],
		info:function(){
			if(WRFUSER.Ajax.tpl.length==0){
				$(".ajax_user").each(function(i){
					WRFUSER.Ajax.tpl[i]={logintpl:$(this).find('.login').html(),nologintpl:$(this).find('.nologin').html()};
				});
			}
			$.post('/ajax.php?ajax=userinfo',function(s){
				if(s==''){
					$(".ajax_user").each(function(i){
						var html=WRFUSER.Ajax.tpl[i].nologintpl;
						$(this).html(html);
						$(this).show();
					});
					WRFUSER.Info.uid='0';
					WRFUSER.Info.vip=0;
					WRFUSER.Info.username='游客';
					//xiaowei add start
					var _frm = document.createElement("iframe");
					_frm.style.display = "none";
					_frm.src = "http://www.dj.cc/jscookiejump.php?type=djlogout";
					document.body.appendChild(_frm);
					//xiaowei add end
				}else{
					var u=s.split('*wrf*');
					WRFUSER.Info.uid=u[0];
					WRFUSER.Info.username=u[1];
					WRFUSER.Info.vip=parseInt(u[10],10);
					$(".ajax_user").each(function(i){
						var html=WRFUSER.Ajax.tpl[i].logintpl;
						html=html.replace(/\[uid\]/g,u[0]);
						html=html.replace(/\[username\]/g,u[1]);
						//xiaowei add start
						html=html.replace(/\[uimg\]/g,u[2]);
						html=html.replace(/\[uhome\]/g,u[3]);
						html=html.replace(/\[k\]/g,u[4]);
						html=html.replace(/\[c\]/g,u[5]);
						//xiaowei add end
						html=html.replace(/\[jifen\]/g,u[6]);
						html=html.replace(/\[money\]/g,u[7]);
						html=html.replace(/\[vipico]/g,'<img src="img/.cc/templates/djcc/img/cm_djtb0'+u[10]+'.gif" title="'+u[11]+'" />');
						html=html.replace(/\[vipname\]/g,u[11]);
						html=html.replace(/\[vipexday\]/g,u[12]);

						isvip=parseInt(u[10]);
						if(isvip==0){
							html=html.replace(/\[tmpviptxtdesc\]/g,'<span class="txt05">您还不是VIP会员。</span> <span class="txt06"><a href="http://www.dj.cc/center.php?action=profile&i=userinfo" target="_blank">立即开通VIP</a></span>');
						}else{
							html=html.replace(/\[tmpviptxtdesc\]/g,'<span class="txt05">您的VIP账号还有'+u[12]+'到期。</span> <span class="txt06"><a href="http://www.dj.cc/center.php?action=profile&i=userinfo" target="_blank">立即续费</a></span>');
						}

						$(this).html(html);
						$(this).show();
					});
					WRFUSER.Ajax.Qiandao.today=parseInt(u[8]);
					if(parseInt(u[8])==0){
						$(".wrfjs_qdcs").html('已签到'+u[9]+'天').show();
						$(".wrfjs_qdbtn").hide();
					}else{
						$(".wrfjs_qdcs").html('已签到'+u[9]+'天').hide();
						$(".wrfjs_qdbtn").show();
					}

					var _frm = document.createElement("iframe");
					_frm.style.display = "none";
					_frm.src = "http://www.dj.cc/jscookiejump.php?type=djlogin&k="+u[4]+"&c="+encodeURIComponent(u[5]);
					document.body.appendChild(_frm);

					$(".login_box02").hover(
						function(){
							$(this).find("ul").show();
							},
						function(){
							$(this).find("ul").hide();
							}
					);
					$(".login_box02 li").hover(
						function(){
							$(this).css({"background-color":"#333"});
							},
						function(){
							$(this).css({"background-color":"#666"});
							}
					);

				}
				//$.fancybox.close();
				$(".ajax_user a.ligthreg").fancybox({
					'width'				: 685,
					'height'			: 430,
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'scrolling'			: 'no',
					'type'				: 'iframe',
					'padding'			: 0
				});
				$(".ajax_user a.ligthlogin").fancybox({
					'width'				: 685,
					'height'			: 300,
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'scrolling'			: 'no',
					'type'				: 'iframe',
					'padding'			: 0
				});
				$(".ajax_user a.ligthlogout").click(function(){
					var url=$(this).attr("href");
					$(this).attr("href","javascript:void(0)");
					$.get(url,function(a){
						WRFUSER.Ajax.info();
					});
				});
			});
		},
		Qiandao:{
			today:1,
			doit:function(){
				if(WRFUSER.Info.uid=='0'){
					window.setTimeout('$(".ajax_user a.ligthlogin").click();',100);
					return;
				}
				if(WRFUSER.Ajax.Qiandao.today==0){
					XWGOODBAD.customtools._alert('今天已经签过了，明天再来吧。');
					return;
				}
				$.ajax({
					type: "POST",
					url: '/indexcp.php?action=qiandao',
					dataType: 'json',
					success: function(data){
						if(data.error == 0){
							WRFUSER.Ajax.Qiandao.today=0;
							$(".wrfjs_qdcs").html('已签到'+data.cishu+'天').show();
							$(".wrfjs_qdbtn").hide();
							$(".wrfjs_jifen").html(data.jifen);
							$(".wrfjs_money").html(data.money);
							XWGOODBAD.customtools._alert(data.txt);
						}else if(data.error == 1){
							$(".ajax_user a.ligthlogin").click();
						}else if(data.error == 2){
							XWGOODBAD.customtools._alert('今天已经签过了，明天再来吧。');
						}
					}
				});
			}
		}
	};
	WRFUSER.Validate = {
		login:function(){
			var b, c, e, f, d, h = function() {
				var reg=/^([a-zA-Z0-9]+[_|\-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
				$(".err_email").css("visibility", "visible").css("padding-top", "10px").css("height", "26px");
				var c = $.trim($("#login_form .ipt_mail .text").val());
				c == "" ? ($(".err_email").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">请填写邮件地址</span>'), b = !1) : (!reg.test(c) ? ($(".err_email").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">邮箱地址不正确</span>'), b = !1) : ($(".err_email").html('<img src="img/ok_01.png" />'), b = !0));
				return b;
			},
			i = function() {
				$(".err_password").css("visibility", "visible").css("padding-top", "10px").css("height", "26px");
				var b = $("#login_form .ipt_password .text").val();
				b == "" ? ($(".err_password").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">请填写密码</span>'), e = !1) : (b = b.replace(/[^\x00-\xFF]/g, "**").length, b >= 6 && b <= 20 ? ($(".err_password").html('<img src="img/ok_01.png" />'), e = !0) : ($(".err_password").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">' + (b < 6 ? "密码太短啦，至少要6位哦": "密码过长") + "</span>"), e = !1));
				return e;
			};

			$("#login_form .ipt_mail .text").blur(h);
			$("#login_form .ipt_mail .text").focus(function() {
				$(".err_email").css("visibility", "visible")
			});
			$("#login_form .ipt_password .text").blur(i);
			$("#login_form .ipt_password .text").focus(function() {
				$(".err_password").css("visibility", "visible")
			});
			$("#login_form form").submit(function() {
				if (!b && !h()) return ! 1;
				if (!e && !i()) return ! 1;
			})
		},
		reg:function(){
			var b, e, f, d, h = function() {
				var reg=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
				$(".err_email").css("visibility", "visible").css("padding-top", "10px").css("height", "26px");
				var c = $.trim($("#register_form .ipt_mail .text").val());
				c == "" || !reg.test(c) ? ($(".err_email").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">邮箱地址不正确</span>'), b = !1) : $.ajax({
					url: "/user.php?action=verifyemail",
					type: "GET",
					timeout: 6E4,
					data: {
						email: c
					},
					async: !1,
					success: function(c) {
						if (c == null) alert('超时，稍候重试');
						else {
							c == 0 ? ($(".err_email").html('<img src="img/ok_01.png" />'), b = !0) : ($(".err_email").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">电子邮件地址已经被使用</span>'), b = !1)
						}
					},
					error: function(a, b) {
						"timeout" == b && alert('超时，稍候重试')
					}
				});
				return b
			},
			g = function() {
				$(".err_ulike").css("visibility", "visible").css("padding-top", "10px").css("height", "26px");
				var b = $.trim($("#register_form .ipt_ulike .text").val());
				b == "" ? ($(".err_ulike").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">请填写昵称</span>'), c = !1) : $.ajax({
					url: "/user.php?action=verifyusername",
					type: "GET",
					timeout: 6E4,
					data: {
						username: b
					},
					async: !1,
					dataType: "json",
					success: function(b) {
						if (b == null) alert('超时，稍候重试');
						else {
							if(b=='0'){
								$(".err_ulike").html('<img src="img/ok_01.png" />');
								c = !0;
							}
							if(b=='1'){
								$(".err_ulike").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">这昵称太热门了，被别人抢走啦，换一个吧</span>');
								c = !1;
							}
							if(b=='2'){
								$(".err_ulike").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">昵称只能4~20位，每个中文字算2位字符</span>');
								c = !1;
							}
						}
					},
					error: function(a, b) {
						"timeout" == b && alert('超时，稍候重试');
					}
				});
				return c
			},
			i = function() {
				$(".err_password").css("visibility", "visible").css("padding-top", "15px").css("height", "26px");
				var b = $("#register_form .ipt_password .text").val();
				b == "" ? ($(".err_password").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">请填写密码</span>'), e = !1) : (b = b.replace(/[^\x00-\xFF]/g, "**").length, b >= 6 && b <= 20 ? ($(".err_password").html('<img src="img/ok_01.png" />'), e = !0) : ($(".err_password").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">' + (b < 6 ? "密码太短啦，至少要6位哦": "密码过长") + "</span>"), e = !1));
				return e
			},
			j = function() {
				$(".err_rstpassword").css("visibility", "visible").css("height", "26px");
				var b = $("#register_form .ipt_respassword .text").val();
				b == "" ? ($(".err_rstpassword").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">请重复输入一次密码</span>'), f = !1) : $(".ipt_password .text").val() == b && $(".err_password img").attr("src").indexOf("ok") > 0 ? (f = !0, $(".err_rstpassword").html('<img src="img/ok_01.png" />')) : (b = $(".err_password img").attr("src").indexOf("ok") < 0 ? '<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">请先输入正确的密码</span>': '<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">两次输入的密码不一致</span>', $(".err_rstpassword").html(b), f = !1);
				return f
			},
			k = function() {
				$(".err_check").css("visibility", "visible").css("padding-top", "16px").css("height", "26px");
				var b = $("#register_form .ipt_check .check").val();
				b == "" ? ($(".err_check").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">请输入验证码</span>'), d = !1) : $.ajax({
					url: "/user.php?action=verifyyzm",
					type: "POST",
					timeout: 6E4,
					data: {
						sid: $("#yzmsid").val(),
						captcha: b
					},
					async: !1,
					dataType: "json",
					success: function(b) {
						if (b == null) alert('超时，稍候重试');
						else {
							b == 1 ? ($(".err_check").html('<img src="img/error1.png" /><span style="color:#ff89a7; margin-left:8px; margin-top:0;">验证码错误</span>'), d = !1) : ($(".err_check").html('<img src="img/ok_01.png" />'), d = !0);
						}
					},
					error: function(a, b) {
						"timeout" == b && alert('超时，稍候重试')
					}
				});
				return d
			};
			$("#register_form .ipt_mail .text").blur(h);
			$("#register_form .ipt_mail .text").focus(function() {
				$(".err_email").css("visibility", "visible")
			});
			/*$("#register_form .ipt_ulike .text").blur(g);
			$("#register_form .ipt_ulike .text").focus(function() {
				$(".err_ulike").css("visibility", "visible")
			});*/
			$("#register_form .ipt_password .text").blur(i);
			$("#register_form .ipt_password .text").focus(function() {
				$(".err_password").css("visibility", "visible")
			});
			$("#register_form .ipt_respassword .text").blur(j);
			$("#register_form .ipt_respassword .text").focus(function() {
				$(".err_rstpassword").css("visibility", "visible")
			});
			$("#register_form .ipt_check .check").blur(k);
			$("#register_form .ipt_check .check").focus(function() {
				$(".err_check").css("visibility", "visible")
			});
			$(".ipt_box .box").click(function() {
				$(this).attr("checked") ? $(".ipt_sub .sub").removeAttr("disabled") : $(".ipt_sub .sub").attr("disabled", "disabled");
			});
			$("#register_form form").submit(function() {
				if (!b && !h()) return ! 1;
				/*if (!c && !g()) return ! 1;*/
				if (!e && !i()) return ! 1;
				if (!f && !j()) return ! 1;
				if (!d && !k()) return ! 1;
				
			});
		}
	};
	WRFUSER.Checkcode_Change = function() {
		$("#checkcode_change").size != 0 && $("#checkcode_change").click(function() {
			var d=new Date();
			var t=d.getTime();
			var src=$("#img_checkcode").attr('src');
			var i=src.indexOf('_=');
			if(i>0){
				var newsrc=src.substr(0,i)+'_='+t;
			}else{
				var newsrc=src+'&_='+t;
			}
			$("#img_checkcode").attr('src',newsrc);
		})
	};
	WRFUSER.goUploadMp3 = function(o){
		if(WRFUSER.Info.uid=='0'){
			$(".ajax_user a.ligthlogin").click();
		}else{
			$(o).attr('href','http://www.dj.cc/center.php?action=mp3add');
			$(o).attr('target','_blank');
		}
	};
	WRFUSER.Shop={
		cart:function(id,t)	//加入购物车
		{
			//alert('功能未开放');
			//return;
			if(id > 1){
				$.ajax({
					type: "POST",
					url: '/indexcp.php?action=addcart',
					data: 'id='+id+'&t='+t,
					dataType: 'json',
					success: function(data){
						if(data.error == 0){
							$.fancybox({
								'padding'			: '0',
								'width'				: 351,
								'height'			: 105,
								'autoScale'			: false,
								'transitionIn'		: 'none',
								'transitionOut'		: 'none',
								'scrolling'			: 'no',
								'type'				: 'iframe',
								'href'				: '/html/msg/cart_cg'+t+'.html'
							});
						}else if(data.error == 1){
							XWGOODBAD.customtools._alert('参数错误, 请联系管理员!');
						}else if(data.error == 2){
							$(".ajax_user a.ligthlogin").click();
						}
					}
				});
			}
		}
	};
})(jQuery);