﻿///----------------------------------------------------------------
/// Copyright (C) 2006 中国数码集团
/// 版权所有。 
///
/// 文件名：BlogRegister.js
/// 文件功能描述：注册时使用的script方法
///
/// 
/// 创建标识：简相辉/20061113
///----------------------------------------------------------------

/// <summary>
/// 页面加载事件
/// </summary>
function Page_Load()
{

	var btnShow = document.getElementById("btnShowReal");
	var pnlReal = document.getElementById("pnlRealInfo");
	var isReal = document.getElementById("hdnIsReal");
	if (btnShow != null)
	{
	  if (isReal.value == "0")
	  {
		btnShow.value = "填写详细信息";
		pnlReal.style.display = "none";
	  }
	  else
	  {
		btnShow.value = "不填写详细信息";
		pnlReal.style.display = "block";
	  }
	}
}

/// <summary>
/// 隐藏/显示 详细注册信息
/// </summary>
function btnShowReal_click()
{
	var btnShow = document.getElementById("btnShowReal");
	var pnlReal = document.getElementById("pnlRealInfo");
	var isReal = document.getElementById("hdnIsReal");
	
	if (pnlReal.style.display == "block")
	{
		btnShow.value = "填写详细信息";
		pnlReal.style.display = "none";
		isReal.value = "0";
	}
	else
	{
		btnShow.value = "不填写详细信息";
		pnlReal.style.display = "block";
		isReal.value = "1";
	}
	
	return false;
}

/// <summary>
/// 用户名是否可用
/// </summary>
function btnCheck_click()
{
	var chkResult = CheckData("txtLoginName","L/C","用户登录名",15,4);
	
	if (chkResult)
	{
		var userName = document.getElementById("txtLoginName").value;
		var userExist = CE.Components.Blog.PersonSpace.UI.BlogRegister.btnCheck_Click(userName);
			
		if (userExist.value == true)
		{
			alert('该用户名已占用.');
		}
		else
		{
			alert('该用户名可以使用.');
		}
	}
	
	return false;
}

/// <summary>
/// 访问地址是否可用
/// </summary>
function btnUserUrl_click()
{
    var chkResult = CheckData("txtUserUrl","C/L","访问路径",50,4);
    
    if (chkResult)
    {
       var userUrl = document.getElementById("txtUserUrl").value;
       var userExist = CE.Components.Blog.PersonSpace.UI.BlogRegister.btnUserUrl_Click(userUrl);
       
       if (userExist.value == true)
		{
			alert('该访问路径已占用.');
		}
		else
		{
			alert('该访问路径可以使用.');
		}
    }
    
    return false ;
}

/// <summary>
/// 注册信息验证
/// </summary>
function btnCreate_click()
{
	var chkResult = true;
	var loginInfo = document.getElementById("pnlLoginInfo");
	
	if (loginInfo != undefined && loginInfo != null)
	{
		//用户登录名验证
		chkResult = CheckData("txtLoginName","L/C","用户登录名",15,4);
		
		if (!chkResult)
		{
			return false;
		}
		
		//密码提示问题验证
		chkResult = CheckData("txtQuestion","E/L","密码提示问题",50,6);
		
		if (!chkResult)
		{
			return false;
		}
		
		//密码提示答案验证
		chkResult = CheckData("txtAnswer","E/L","密码提示答案",100,6);
		
		if (!chkResult)
		{
			return false;
		}

		//登录密码验证
		chkResult = CheckData("txtpwd","E/L/C","登录密码",20,6);
		
		if (!chkResult)
		{
			return false;
		}
		
		//验证密码
		chkResult = CheckData("txtpwd1","E","验证密码");
		
		if (!chkResult)
		{
			return false;
		}
		
		//登录密码和验证密码比较
		chkResult = CompareObject("txtpwd","txtpwd1","密码");
		
		if (!chkResult)
		{
			return false;
		}			
	}
	
	//显示名称
	chkResult = CheckData("txtUserName","E/L","显示名称",15);
	
	if (!chkResult)
	{
		return false;
	}
	
	//自我简介
	chkResult = CheckData("txtDes","E/L","自我简介",100);
	
	if (!chkResult)
	{
		return false;
	}
	
	//访问路径
	/*chkResult = CheckData("txtUserUrl","C/L","访问路径",25,4);
	
	if (!chkResult)
	{
		return false;
	}*/
	
	//空间名称
	chkResult = CheckData("txtSpaceName","E/L","博客名",50);
	
	if (!chkResult)
	{
		return false;
	}
	
	//空间简介
	chkResult = CheckData("txtSpaceDes","E/L","博客简介",150);
	
	if (!chkResult)
	{
		return false;
	}
	
	var realInfo = document.getElementById("hdnIsReal");
	
	if (realInfo != undefined && realInfo != null && realInfo.value != "0")
	{
		//真实姓名
		chkResult = CheckData("txtUserTrueName","L","真实姓名",10);
		
		if (!chkResult)
		{
			return false;
		}
		
		//出生日期
		var year = Trim(document.getElementById("txtYear").value);
		var month = Trim(document.getElementById("ddlMonth").value); 
		var day = Trim(document.getElementById("ddlDay").value);
		var dateString = year + "-" + month + "-" + day
		
		if (year.length !=4 || CheckDate(dateString) == false)
		{
			alert("日期不合法。");
			document.getElementById("txtYear").focus();
			document.getElementById("txtYear").select();
			return false;
		}
		
		//有效证件
		chkResult = CheckData("txtPerfectInstrument","L/C","有效证件",20);
		
		if (!chkResult)
		{
			return false;
		}
		
		//电子邮箱
		chkResult = CheckData("txtUserConnection","M/L","电子邮箱",50);
		
		if (!chkResult)
		{
			return false;
		}
		
		//电话
		chkResult = CheckData("txtOfficePhone","T/L","电话",20);
		
		if (!chkResult)
		{
			return false;
		}
		
		//手机
		chkResult = CheckData("txtCellPhone","N/L","手机",11);
		
		if (!chkResult)
		{
			return false;
		}
		
		//邮政编码
		chkResult = CheckData("txtPostalCode","N/L","邮政编码",6);
		
		if (!chkResult)
		{
			return false;
		}
		
		//详细地址
		chkResult = CheckData("txtCompleteAddress","L","详细地址",100);
		
		if (!chkResult)
		{
			return false;
		}
	}
	
	//return confirm("是否开通?");
	return true;
}