/*
 * Created on 2007-5-25
 * 
 * Author: Xi Weidong, xiwd@peptalk.cn
 * Description: 用户注册
 */
 //POST 注册信息
function signup_do(requestURL,preURL)
{
	$("#msg1").addClass('loading');	
	$("#msg1").html("<span style='color:#0066cc'>处理中,请稍候...</span>");
	$.post( requestURL + "?time="+new Date().getTime(), 
	{ 
		nickname: $("#nickname").val(),
		email: $("#email").val(),
		password: $("#password").val(),	
		check_password: $("#check_password").val(),	
		region: $("#region").val(),
		mobile: $("#mobile").val(),
		random: $("#random").val()
	}, 
	function(xml)
	{ 
		try
		{
			var msg = xml.getElementsByTagName("checkmsg")[0].childNodes[0].nodeValue;
			if(msg == 'success') 
			{
				send_mail('send_mail.php','',preURL);
			}
			else
			{
				$("#msg1").html(msg);
				//setTimeout('$("#msg1").html("")',2000);
			}					
		}
		catch(e)
		{
			$("#msg1").removeClass('loading');
			$("#msg1").html('');
			alert(e);
		}							
	} 
	);		
}
//发送email
function send_mail(requestURL,at,preURL)
{
	$.get( requestURL + "?time="+new Date().getTime(),
	function(data_)
	{ 
		try
		{
			if(data_ == 'success') 
			{
				if(at == "true") alert("邮件已成功发送!");
				location.href = preURL+"?mailed=yes";
			}
			else if(data_ == 'fail') 
			{
				if(at == "true") alert("邮件发送失败!");
				location.href = preURL+"?mailed=no";
			}				
			else if(data_ == 'timeout')
			{
				if(at == "true") alert("对不起,您已超时!");
				location.href = preURL+"?mailed=no";
			}	
			else
			{
				if(at == "true") alert("发送出错!");
				location.href = preURL+"?mailed=no";
			}	
		}
		catch(e)
		{
			alert(e);
		}							
	} 
	);		
}
//修改email
function modify_email(requestURL,preURL)
{
	$("#msg1").addClass('loading');
	$("#msg1").html("<span style='color:#0066cc'>处理中,请稍候...</span>");
	$.post( requestURL + "&time="+new Date().getTime(), 
	{ 
		email: $("#email").val(),
		ckemail: $("#ckemail").val()
	}, 
	function(xml)
	{ 
		try
		{
			var msg = xml.getElementsByTagName("checkmsg")[0].childNodes[0].nodeValue;
			if(msg == 'success') 
			{
				send_mail('send_mail.php','',preURL);
			}
			else
			{
				var show = xml.getElementsByTagName("show")[0].childNodes[0].nodeValue;
				$("#"+show).html(msg);
				//setTimeout('$("#'+show+'").html("")',2000);
			}					
		}
		catch(e)
		{
			$("#msg1").removeClass('loading');
			$("#msg1").html('');
			alert(e);
		}							
	} 
	);		
}
//开通blog
function create_blog(requestURL,rootURL)
{
	$("#msg1").addClass('loading');
	$("#msg1").html("<span style='color:#0066cc'>处理中,请稍候...</span>");
	$.post( requestURL + "&time="+new Date().getTime(), 
	{ 
		email: $("#email").val()
	}, 
	function(xml)
	{ 
		try
		{
			var msg = xml.getElementsByTagName("checkmsg")[0].childNodes[0].nodeValue;			
			if(msg == 'yes') 
			{
				location.href = rootURL+"/site/index.php";
			}
			else if(msg == "no")
			{
				send_mail('send_mail.php','',rootURL+"/site/signup_success.php");
			}
			else
			{
				var show = xml.getElementsByTagName("show")[0].childNodes[0].nodeValue;
				$("#"+show).html(msg);
				//setTimeout('$("#'+show+'").html("")',2000);
			}					
		}
		catch(e)
		{
			$("#msg1").removeClass('loading');
			$("#msg1").html('');
			alert(e);
		}							
	} 
	);		
}
//老用户处理
function old_user_process(requestURL,preURL)
{
	$("#msg1").addClass('loading');
	$("#msg1").html("<span style='color:#0066cc'>处理中,请稍候...</span>");
	$.post( requestURL + "&time="+new Date().getTime(), 
	{ 
		username: $("#username").val(),
		password: $("#password").val(),
		jid: $("#jid").val(),
		im_pass: $("#im_pass").val(),
		email: $("#email").val()
	}, 
	function(xml)
	{ 
		try
		{
			var msg = xml.getElementsByTagName("checkmsg")[0].childNodes[0].nodeValue;
			if(msg == 'success') 
			{
				send_mail('send_mail.php','',preURL);
			}
			else
			{
				var show = xml.getElementsByTagName("show")[0].childNodes[0].nodeValue;
				$("#"+show).html(msg);
				//setTimeout('$("#'+show+'").html("")',2000);
			}					
		}
		catch(e)
		{
			$("#msg1").removeClass('loading');
			$("#msg1").html('');
			alert(e);
		}							
	} 
	);		
}
function keyDown(event,requestURL,preURL,method)
{
	if(event.keyCode==13) 
	{	
		if(method == 'signup_do') signup_do(requestURL,preURL);
		if(method == 'modify_email') modify_email(requestURL,preURL);
		if(method == 'old_user_process') old_user_process(requestURL,preURL);
		if(method == 'create_blog') create_blog(requestURL,preURL);
	}
}
//刷新验证码
function changeNum(authimgURL)
{
	document.getElementById("check_num").src = authimgURL+'?rand='+new Date().getTime();
}