/* ----------------------------------------------------------------------------------------------------
* 个人中心
* ----------------------------------------------------------------------------------------------------
*/

/* 左侧菜单 */
function memberHandler()
{
	$(".subMenu dt").click(function(){
		if ($(this).hasClass("collapse")){
			$(this).removeClass("collapse").nextAll("dd").show();
		}else{
			$(this).addClass("collapse").nextAll("dd").hide();
		}
	});
	$(".subMenu a").click(function(){
		$(".subMenu").children("dd").removeClass("currentMenu");
		$(this).parent().addClass("currentMenu");
	});
}

/* 充值 */
function paycountnow(){
	$.post(APP+"/Member/regcheck",
		{},
		function(data){
		if(data=="1"){
			addDialogbox("#mbpaycountnow","拍点充值",10001,768);
			//quitScreenMask();
			/*
			$.ajax({
				url: APP+"/Member/mb_count_single/",
				cache: false,
				success: function(msg){
					$("#mbpaycountnow .dialogboxContent").addClass("regWrap");
					$("#mbpaycountnow .dialogboxContent").prepend(msg);
				}
			});
			*/
			document.location = APP+"/Member/";
		}else{
			addDialogbox("#check_dl","您的账户资金充足，无需充值!",10001,302);
			msg=''+
					'<div class="tc">'+
						'<span class="button">'+
							'<span class="first-child">'+
								'<button type="button" class="f12" onclick="check_dl_ok()">我知道了,返回</button>'+
							'</span>'+
						'</span>'+
					'</div>';
			$("#check_dl .dialogboxContent").html(msg);
		}
	});
}

function check_dl_ok(){
	removeDialogbox("#check_dl");
}


function inimember()
{
	var islogin;
	var mb_id;
	var mb_nickname;
	var mb_key;
	var content;
	islogin=getCookie('islogin');
	mb_id=getCookie('mb_id');
	mb_key=getCookie('mb_key');


/*
	//控制打开关闭浮动层
	openDiv();
	var regNow = '<a id="qLink" href="'+APP+'/User/register" title="注册拍拍账户"><img src="'+IMG_PATH+'/regNow.gif" width="106" height="24" /></a>';
	var getPoint = '<a id="qLink" href="javascript:paycountnow();" title="充值获得更多拍点"><img src="'+IMG_PATH+'/getPoint.gif" width="106" height="24" /></a>';
	
	$.ajax({
		url: APP+"/User/inimember/",
		cache: false,
		type: "POST",
		"data": '',
		success: function(content){
			
			$("#userInfo").html(content);
			if(islogin){
				$("#fixedDivState").html(getPoint);
			}else{
				$("#fixedDivState").html(regNow);
			}
			
			opentopbox();//控制打开个人获得的浮动层

			// 当前页面登录 
			$("#signin").click(function(){
				loadloginbox();
			}).focus(function(){
				$(this).blur();
			});


			// 顶部菜单/
			$(".dropMenu").hover(
			function(){
				$(this).addClass("dropMenuOn");

				//获取当前鼠标over区域的id来判断显示动作
				var currentId = "#" + $(this).attr("id");

				//账户余额
				if(currentId == "#mbcount")
				{
					$("#mbcountlist").html(loading);
					$.ajax({
						type: "POST",
						url:APP+"/User/getcount/",
						data: "mb_key="+mb_key,
						dataType: "html",
						success: function(msg){
							if(msg=='1'){
								logout();//如果服务里转回1刚表示服务器里已没有这个用户的session
							}else{
								$("#mbcountlist").html(msg);
							}
						}
					});
				}

				//我正在参与的拍卖
				if(currentId == "#bidBox")
				{
					$("#bidBoxlist").html(loading);
					$.ajax({
						type: "GET",
						url:APP+"/Auction/getmyaction/",
						//data: "mb_key="+mb_key,
						dataType: "html",
						success: function(msg){
							$("#bidBoxlist").html(msg);
						}
					});
				}
				
				if(currentId == "#MyOrderList")
				{
				
					var o = $("#MyOrderlistDiv");
					o.html(loading);
					$.ajax({
						type: "GET",
						url:APP+"/User/getmyorderlist/",
						data: "",
						dataType: "html",
						success: function(msg){
							if(msg=='1'){
								logout();//如果服务里转回1刚表示服务器里已没有这个用户的session
							}
							else{
								o.html(msg);
							}
						},
						error:function()
						{
							ShowErrorMsg(msg);
						}
					});				
				}
				
			},
			function(){
				$(this).removeClass("dropMenuOn");
			}
			);
		}
	});
	*/
}

//打开个人获得的浮动层
function opentopbox(){
	var topboxopen=0;//=getCookie('topboxopen');
	var proTopshowvalue=getCookie('proTopshowvalue');
	var islogin=getCookie('islogin');
	//proTopshowvalue=proTopshowvalue;// / 10;

//	if(proTopshowvalue==null || proTopshowvalue=="")
	{
		$.ajax({
			type: "POST",
			url:APP+"/User/getcountInWeek4/",
			data: "",
			dataType: "html",
			success: function(msg){
				proTopshowvalue=getCookie('proTopshowvalue');
				//alert(proTopshowvalue);
				if((topboxopen!='1')&& islogin ){
					$("#proTop").show();
					$("#proTopshowvalue").text(proTopshowvalue);
				}else{
					$("#proTop").hide();
					$("#proTopshowvalue").text(proTopshowvalue);
				}				
			}
		});
	}
	//else
	return ;
	{
	
		if((topboxopen!='1')&& islogin ){
			$("#proTop").show();
			$("#proTopshowvalue").text(proTopshowvalue);
		}else{
			$("#proTop").hide();
			$("#proTopshowvalue").text(proTopshowvalue);
		}
	}
}

//islogin
$(document).ready(function(){
	$("#webimBtn").click(function(){
		if(!$(this).hasClass("webimOn"))
		{
			$("#fixedDiv").show("fast");
			$("#webimBtn").addClass("webimOn").attr("title","隐藏");	
			setCookie('DivIsOpen','1');
		}else{
			$("#fixedDiv").hide("fast");
			$("#webimBtn").removeClass("webimOn").attr("title","展开");
			delCookie('DivIsOpen');
		}
	}).focus(function(){
		$(this).blur();
	});
});

function openDiv(){
	var IsOpen=getCookie('DivIsOpen');
	if(IsOpen=='1'){
		$("#fixedDiv").show("fast");
		$("#webimBtn").addClass("webimOn").attr("title","隐藏");	
	}else{
		$("#fixedDiv").hide("fast");
		$("#webimBtn").removeClass("webimOn").attr("title","展开");
	}
}

//退出
function logout(){
	$.post(APP+"/User/logout",'',function(msg){
		if(msg){//先保留msg这个值以备以后使用
			client_clear();
		}
		location.href=REQUEST_URI;
	});
}

//退出
function client_clear(){
	delCookie('islogin');
	delCookie('mb_id');
	delCookie('proTopshowvalue');

}

//更新用户状态
function updateuser() {
	if(window.isfoucs==0){//如果当前页面不是在激活的状态
		return;
	}

    $.ajax({
        type: "POST",
        url:APP+"/User/ajaxcheckuser/",
		"data": '',
        success: function(msg){
            if(msg==2){						//证明已经被封了或是没登陆
                logout();
            }else{
                setTimeout("updateuser()", 60000);//60S
            }
        }
    });
}



//加载登录信息
function loadloginbox(){
	addDialogbox("#ajaxSignin","登录",10001,502);
	//quitScreenMask();


	$.ajax({
		url: APP+"/User/signin",
		cache: false,
		"data": '',
		success: function(msg){
			$("#ajaxSignin .dialogboxContent").prepend(msg);
			initStyle();
			if($("#userID").attr("value") == ""){
				$("#userID").focus();
			}else{
				$("#userPW").focus();
			}
		}
	});
}

//登录操作
function ajaxlogin() {
	var exp  = new Date();
	var codehtml='<label for="logincode">验证码:</label>'+'<input type="text" class="input fl space" id="logincode" name="logincode" style="width:60px;" maxlength="4" />'+'<img id="verifyImg_login" class="fl" src="'+APP+'/User/verify/'+exp.getTime()+'" onclick="fleshVerify(\'verifyImg_login\')" title="点击刷新验证码" />';
	var pass=$.formValidator.pageIsValid('loginform');
	var loginwrongtime=getCookie('loginwrongtime');

	if(pass){
		var queryString = $('#loginform').formSerialize();
		//alert(queryString);
		$.post(APP+"/User/ajaxlogin",queryString,function(msg){
			if(msg==1){
				if(loginwrongtime>2){
					$('#verifycodeInput').removeClass("displayNone");
					$('#verifycodeInput').html(codehtml);
				}
				showtips('邮箱名或密码不正确，请确认','tips',3);
			}else if(msg==3){
				$('#verifycodeInput').removeClass("displayNone");
				$('#verifycodeInput').html(codehtml);
				showtips('验证码有误，请重新输入','tips',3);
			}else if(msg==2){
				showtips('您的账号已经被冻结，请联系拍拍客服','tips',3);
			}else{
				dologinurl();//跳转本页
			}
		});
	}
}

//注册
function addMember(EmailId,VerifyCodeId,FormId) {

	if(FormId==null || FormId=="")FormId = "addMemberform";
	if(EmailId==null || EmailId=="") EmailId = "userEmail";
	if(VerifyCodeId==null || VerifyCodeId=="") VerifyCodeId = "addMembercode";
	var userEmail=$("#"+EmailId).val();
	var userverifycode=$("#"+VerifyCodeId).val();
	var pass=$.formValidator.pageIsValid(FormId);
	if(pass)
	{
		$.ajax({
		  type: "POST",
		  url: APP+"/User/addmember",
		  dataType: "html",
		  data:{'user':userEmail,'code':userverifycode},
		  success:function(msg)
		  {
		  	if(msg=='1')
			{//先保留msg这个值以备以后使用：旧值：0
				showtips('注册成功，系统已发送验证邮件到您邮箱：'+userEmail+'里，如果5分钟内没有收到邮件请更换注册邮箱或重复发送邮件！','tips',1);
				showresendbtn();//让用户可以再次发送邮件
			}
			else if(msg=="-2")
			{
				showtips("验证码无效,请检查后再试.",'tips',2);
			}
			else
			{
				ShowErrorMsg("邮件发送失败,请稍候重试.");
				//showtips(msg,'tips',2);
			}
		  },
		  error:function(msg)
		  {
		  	ShowErrorMsg(msg.responseText);//.replace(/<[^>]*>/g,'')
		  }	  	  
		}); 
		//$.post(APP+"/User/addmember",'user='+userEmail+'&code='+userverifycode,function(msg)	{		});
		
	}
	else
	{
			showtips("验证未通过,邮件停止发送",'tips',2);
	}
}

//已有相同用户名的处理方式
//隐藏发送按钮
function showresendbtn() {
	//已有相同的用户名
	$('#sendbtn').attr("style","display:none");
	$('#resendbtn').removeAttr("style");
}

//已有相同用户名的处理方式
//隐藏重发发送按钮
function hideresendbtn() {
	//已有相同的用户名
	$('#resendbtn').attr("style","display:none");
	$('#sendbtn').removeAttr("style");
}

//重新发送邮件
function resendmail() {
	var userEmail=$("#userEmail").val();
	var userverifycode=$("#addMembercode").val();
	var pass=$.formValidator.pageIsValid('addMemberform');
	if(pass){
		$.post(APP+"/User/resendmail",'user='+userEmail+'&code='+userverifycode,function(msg){
			if(msg=='1'){//先保留msg这个值以备以后使用
				showtips('系统已重新发送验证邮件到您邮箱：'+userEmail+'里，如果5分钟内没有收到邮件请更换注册邮箱或重复发送邮件！','tips',1);
			}			
			else if(msg=="-2")
			{
				showtips("验证码无效,请检查后再试.",'tips',2);
			}
			else
			{
				ShowErrorMsg("邮件发送失败,请稍候重试.");
			}
		});
	}
}

//找回密码
function ajaxgetpwd() {
	var pass=$.formValidator.pageIsValid('getpwdform');

	if(pass){
		var queryString = $('#getpwdform').formSerialize();
		//alert(queryString);
		$.post(APP+"/User/getpwd",queryString,function(msg){
			if(msg=='1'){//先保留msg这个值以备以后使用,原值0
				showtips('操作成功，系统已发送邮件到您邮箱','tips',1);
			}else{
				showtips(msg,'tips',2);
			}
		});
	}
}

//判断是否在登陆页还是用ajax的形式登陆
function dologinurl()
{
	if(REQUEST_URI =='/User/register')
	{
		location.href=APP+'/Member/';
	}else{
		location.href=REQUEST_URI;
	}
}

//用户地址薄
function userAddress()
{
	addDialogbox("#userAddress","选择您的地址",10001,502);
	//quitScreenMask();
	$.ajax({
		url: APP+"/Member/userAddress",
		cache: false,
		success: function(msg){
			$("#userAddress .dialogboxContent").html(msg);
			$("#userAddress .dialogboxContent").addClass("regWrap");
		}
	});
}

//用户地址薄
function selectaddr(id)
{
	//addDialogbox("#userAddress","选择您的地址",10001,502);
	//quitScreenMask();
	//alert($("#userRealName_"+id).text());
	$("#userRealName").val(
	$("#userRealName_"+id).text()
	);
	$("#userPhoneNumber").val(
	$("#userPhoneNumber_"+id).text()
	);
	$("#detailedAddress").val(
	$("#detailedAddress_"+id).text()
	);
	$("#zipCode").val(
	$("#zipCode_"+id).text()
	);
	$("#remarks").val(
	$("#remarks_"+id).text()
	);
	removeDialogbox("#userAddress");
}

//加载订单页面
function loadOrder(oid)
{
	addDialogbox("#order","订单",10001,860);
	var orderFrame = '<iframe id="orderFrame" onload="iframeAutoHeight(\'orderFrame\')" name="orderFrame" width="100%" scrolling="no" frameborder="no" allowtransparency="yes" src='+APP+'/Member/showOrder/id/'+oid+'></iframe>';
	$("#order .dialogboxContent").html(orderFrame);
}
//返点处理
function returnPoint(oid){
	if(confirm('是否返点？返点操作成功后将不能再进行补价购买！')){
	$.post(APP+'/Member/returnPoint',{id:oid},function(data){
		if(data=='1'){
			alert('操作成功，您本次竞拍的消费点已返回到您的帐户!');
			mbsimajax('/Member/mb_addgame','mbAjaxShow');
		}else{
			alert('操作不成功，请再试一次或与客服联系，谢谢!');
		}
	});
	}
}
//加载订单页面
function loadGameOrder(oid)
{
	addDialogbox("#order","订单",10001,860);
	var orderFrame = '<iframe id="orderFrame" onload="iframeAutoHeight(\'orderFrame\')" name="orderFrame" width="100%" scrolling="no" frameborder="no" allowtransparency="yes" src='+APP+'/Member/showGameOrder/id/'+oid+'></iframe>';
	$("#order .dialogboxContent").html(orderFrame);
}

//选择图像
function loadUserIcon()
{
	$.ajax({
		url: APP+"/User/memberlogo",
		cache: false,
		success: function(msg){
			$("#UserIconDiv .dialogboxContent").html(msg);
			$("#newIconList button").click(function(){
				loadUserIcon();
			});
		}
	});
}

//晒图操作及成功感言
function winnersay(tid)
{
	addDialogbox("#winersay","进行晒图及感言",10001,860);
	$.ajax({
		url: APP+"/Member/mb_winersay/tid/"+tid,
		cache: false,
		type: "POST",
		success: function(msg){
			$("#winersay .dialogboxContent").html(msg);
		}
	});
}
//晒图操作删除图片
function winnersay_delimg(id,tid)
{
	$.ajax({
		url: APP+"/Member/mb_winersay_delimg/id/"+id,
		cache: false,
		type: "POST",
		success: function(msg){
			//alert('OK');
			simajax(APP+"/Member/mb_winersay_loadimg/tid/"+tid,"picList");
		}
	});
}

//用户选择自己的图像
function usericon()
{
	addDialogbox("#UserIconDiv","选择自己的个性图像",10001,502);
	//quitScreenMask();
	loadUserIcon();
}

//用户选择自己的图像后操作
//function selsectlogo(path)
function SelsectUserImage(path)
{
	$('#showicon').attr('src',path);
	$('#photo').attr('value',path);
	removeDialogbox("#UserIconDiv");
}




/*++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//11:41 2010-9-29 Add
function client_SetPageNo(pageno,id)
{
	if(!id) id="";
	setCookie("Client_Center_PageNo" + id,pageno)
}
function client_GetPageNoToUrlParam(id)
{
	if(!id) id="";
	var pageno= 1;
	
    pageno= getCookie('Client_Center_PageNo' + id );
    if (isNaN(pageno)) pageno=1;
    if(pageno<2)
    	return "";
    else
    	return "&p="+pageno;
}

/*-----------------------------------------------------
 18:14 2010-10-23 订单支付
-----------------------------------------------------*/
//订单确认
function CheckOrderForm(id,pid,pname,money,ptype)
{
		//确认订单,则要进行付款操作,取消,则付款不会被取消
		//mbsimajax(APP+'/Member/ajax_order_Check/'+ CheckState +'/'+ id ,'TdOrderCheck_'+id);
		//产品编号,产品名称,竞拍期号,金额,购买类型
		//保价购买
		//ptype:订单类型:0默认,1,竞拍,2体验竞拍,3保价,4体验保价,100购买拍点
		//var param = 'vid='+ id + '&pid=&pname=&money=&ptype';
		addDialogbox("#mb_payBar","您确认支付本订单吗?",10003,400,"_PaySubId");
		$.ajax({
			type: "POST",
			"url":APP+'/Member/mb_Pay/',
			"data": 
			{
			"vid":id,
			"pid": pid,
			"money":money,
			"ptype":ptype
			},
			success: function(msg)
			{
				//ShowErrorMsg(msg);
				$("#mb_payBar .dialogboxContent").html(msg);	
			}
			
		});
}
