﻿// JScript 文件

// 登录
function userControlLogin()
{
	var txtEmail = document.getElementById('txtEmail');
	 var txtPwd = document.getElementById('txtPwd');
	var txtCode = document.getElementById('txtCode');
	phookLogin(txtEmail.value,txtPwd.value,txtCode.value,true,userControlLoginBack);
}

// 登录-回调函数
function userControlLoginBack(o)
{
	setLoginInputDisabled(false);
	if(o.error)
	{
		var validateCode = document.getElementById('validateCode');
		
		var strs = o.error.split('|');
		alert(strs[0]);
		if(parseInt(strs[1]) >=3)
		{
			validateCode.style.display = '';
			var imgCode = document.getElementById('imgCode');
			imgCode.src = '/controls/rndimage.aspx?' + Math.random();
			var txtPwd = document.getElementById('txtPwd');
			var txtCode = document.getElementById('txtCode');
			txtPwd.value = '';
			txtCode.value = '';
		}else if(parseInt(strs[1]) ==1)
		{
		  validateCode.style.display = 'none';
		}
	}
	else
	{
		showUserInfoLayer(o.data);
	}
}

// 登录控件加载
function LoginUserControlLoad()
{
	showLoginLoadingLayer();
	getCurrentUserInfoForLoginControl();
}

// 获取当前用户信息
function getCurrentUserInfoForLoginControl()
{
	ajax({type:'get_current_user_info'},getCurrentUserInfoForLoginControlBack);
}

// 获取当前用户信息-回调函数
function getCurrentUserInfoForLoginControlBack(o)
{
	if(o.isError)
	{
		showLoginLayer();
	}
	else
	{
		showUserInfoLayer(o.data);
	}
}

// 设置登录INPUT为disabled
function setLoginInputDisabled(isDisabled)
{
	var divLoginLayer = document.getElementById('divLoginLayer');
	var inputs = divLoginLayer.getElementsByTagName('input');
	for(var i=0; i<inputs.length; i++)
	{
		inputs[i].disabled = isDisabled;
	}
}

// 显示登录框
function showLoginLayer()
{
	var divLoginUserInfo = document.getElementById('divLoginUserInfo');
	var divLoginLayer = document.getElementById('divLoginLayer');
	var divLoginLoading = document.getElementById('divLoginLoading');
	divLoginLoading.style.display = 'none';
	divLoginUserInfo.style.display = 'none';
	divLoginLayer.style.display = 'block';
	var txtEmail = document.getElementById('txtEmail');
	txtEmail.focus();
}

// 显示用户信息
function showUserInfoLayer(o)
{
	// 当为种子首页时，登陆后跳转到真正首页
	var topBox = document.getElementById('top-box');
	if(!topBox)
	{
		window.location.href = '/index.aspx';
		return;
	}
	var divLoginUserInfo = document.getElementById('divLoginUserInfo');
	var divLoginLayer = document.getElementById('divLoginLayer');
	var divLoginLoading = document.getElementById('divLoginLoading');
	divLoginLoading.style.display = 'none';
	divLoginUserInfo.style.display = 'block';
	divLoginLayer.style.display = 'none';
	var imgLoginSex = document.getElementById('imgLoginSex');
	var spanLoginNickName = document.getElementById('spanLoginNickName');
	var spanLoginMessageCount = document.getElementById('spanLoginMessageCount');
	var spanLoginNotifyCount = document.getElementById('spanLoginNotifyCount');
	var spanLoginFriendCount = document.getElementById('spanLoginFriendCount');
	var spanLoginCommentCount = document.getElementById('spanLoginCommentCount');
	var spanLoginProductCount = document.getElementById('spanLoginProductCount');
	var spanLoginPhotoCount = document.getElementById('spanLoginPhotoCount');
	var spanLoginOrderCount = document.getElementById('spanLoginOrderCount');
	var spanLoginNoPayOrderCount = document.getElementById('spanLoginNoPayOrderCount');
	var imgLoginHead = document.getElementById('imgLoginHead');
	var lickToMyPhookIndex = document.getElementById('linkToMyPhookIndex');
	
	imgLoginSex.src = '/images/2mai_biao' + (o.sex?'1':'2') + '.gif';
	spanLoginNickName.innerHTML = o.nickName;
	imgLoginHead.src = o.browseMiddleHeadPicture;
	spanLoginMessageCount.innerHTML = o.messageCount;
	spanLoginNotifyCount.innerHTML = o.unreadNotifiesCount;
	spanLoginFriendCount.innerHTML = o.friendRequestCount;
	spanLoginCommentCount.innerHTML = o.commentCount;
	spanLoginProductCount.innerHTML = o.productCount;
	spanLoginPhotoCount.innerHTML = o.photoCount;
	spanLoginOrderCount.innerHTML = o.orderCount;
	spanLoginNoPayOrderCount.innerHTML = o.unPaymentOrderCount;
	lickToMyPhookIndex.href = '/MyPhookManage/index.aspx';
	
	var divMainTop=document.getElementById('divLoginMainTop');
	if(divMainTop)
	{
		//showMainTopInfo(o);
	}
}

//显示主页面Top信息
function showMainTopInfo(o)
{
  var topInfo=o;
  var divMainTop=document.getElementById('divLoginMainTop');
 
  
  var divLoginInfo=document.getElementById('top-box-main-right-top');
  divLoginInfo.style.display='none';
  
  if (!topInfo.isActivated)
  {
    var divActive=document.getElementById('liActive');
    divActive.style.display='block';
  }
  
  var divHellostring=document.getElementById('liHellostring');
  divHellostring.innerHTML=topInfo.helloString;
  
  //显示我的飞看
  var liMyPhookIndex=document.getElementById('liMyPhookIndex');
  if(liMyPhookIndex)
  {
	  liMyPhookIndex.innerHTML='';   //<a class=\'myphook-index\' href=\'/MyPhookManage/index.aspx\'>我的飞看</a>
	  liMyPhookIndex.style.display='block';
  }
  var liNone=document.getElementById('liNone');
  if(liNone)
  {
	liNone.style.display='block';
  }	
  
  var divNickname=document.getElementById('liNickname');
  divNickname.innerHTML=topInfo.nickName;
  var messageCount=document.getElementById('messageCount');
  if(messageCount)
  {
    messageCount.innerHTML = o.messageCount+'条消息';
  }
  //内容显示完了再显示DIV
  divMainTop.style.display='block';
}


// 显示加载
function showLoginLoadingLayer()
{
	var divLoginUserInfo = document.getElementById('divLoginUserInfo');
	var divLoginLayer = document.getElementById('divLoginLayer');
	var divLoginLoading = document.getElementById('divLoginLoading');
	divLoginLoading.style.display = 'block';
	divLoginUserInfo.style.display = 'none';
	divLoginLayer.style.display = 'none';
}
