function check_form()
{
	if(!check_form_basic()){return false;}
	if(!checkEmailFormat($F('mail'))){return false;}
	return true;
}
function check_login()
{
	var param = "login=" + $F('login');
	new Ajax.Request(url_root + "/user/checklogin/", {
		  method: 'post',
		  parameters : param,
		  onComplete: afterCheckLogin
		});
}
function afterCheckLogin(resultat)
{
	var res = eval('('+resultat.responseText+')');
	if(res[0] == "KO")
	{
		alert(res[1]);
		setError($('login'));
		$("img_login").src = url_root + "/images/2.gif";
	}
	else
	{
		clearError($('login'));
		$("img_login").src = url_root + "/images/1.gif"; 
	}
}
function check_mail()
{
	var param = "mail=" + $F('mail');
	new Ajax.Request(url_root + "/user/checkmail/", {
		  method: 'post',
		  parameters : param,
		  onComplete: afterCheckMail
		});
}
function afterCheckMail(resultat)
{
	var res = eval('('+resultat.responseText+')');
	if(res[0] == "KO")
	{
		alert(res[1]);
		setError($('mail'));
		$("img_mail").src = url_root + "/images/2.gif";
	}
	else
	{
		clearError($('mail'));
		$("img_mail").src = url_root + "/images/1.gif"; 
	}
}

function forgotpass()
{
	var html = $("div_forgotpass").innerHTML;
	$("div_forgotpass").innerHTML = "<img src='"+url_root+"/images/ajax-loader.gif'  alt='请稍等' title='请稍等' />";
	
	Dialog.confirm({url: url_root + "/user/getpass/", options: {method: 'get'}},
	{top: 50, width:800, className: "alphacube", okLabel: "发送", cancelLabel:"返回", 
		draggable:true,maximizable:true,minimizable:true,recenterAuto:false,destroyOnClose:true,closable:true,
		onOk: function(win){
				$("GetPass").getInputs('text').each(function(element){$(element).observe('keydown', function(event){ clearError($(element)); });});
				$("GetPass").select('select').each(function(element){$(element).observe('change', function(event){ clearError($(element)); });});
				
				if(check_form_basic()==true)
				{
					$("div_forgotpass").innerHTML = html;
					$("GetPass").request({
				  		onComplete: afterValid
					});
				}
			},
		onCancel:function(win){$("div_forgotpass").innerHTML = html;}});
}

function addRelation(id,type)
{
	$("addmy" + type).innerHTML = "<img src='"+url_root+"/images/ajax-loader.gif' alt='请稍等' title='请稍等' />";
	var param = "id=" + id + '&type=' + type;
		new Ajax.Request(url_root + "/user/addrelaton", {
		  method: 'post',
		  parameters : param,
		  onComplete: afterRelation
		});
}
function delRelation(id,type)
{
	$("addmy" + type).innerHTML = "<img src='"+url_root+"/images/ajax-loader.gif' alt='请稍等' title='请稍等' />";
	var param = "id=" + id + '&type=' + type;
		new Ajax.Request(url_root + "/user/delrelaton", {
		  method: 'post',
		  parameters : param,
		  onComplete: afterRelation
		});
}
function afterRelation(resultat)
{
	var res = eval('('+resultat.responseText+')');
	alert(res[1]);
	$("addmy" + res[2]).innerHTML = res[3];
}


function addPhoto(obj) 
{
	$("user_photo").InnerHTML = "请稍后...";
	$("uploadphoto").submit();
	timeInterval=setInterval("traceUpload()", 1500);
}
function delPhoto()
{
	$("user_photo").InnerHTML = "请稍后...";
	new Ajax.Updater("user_photo",url_root + "/user/delPhoto/");
}
function traceUpload()
{
	new Ajax.Request(url_root + "/user/traceUpload/", {  onComplete: afterTraceUpload	});
}
function afterTraceUpload(resultat)
{
	var res = eval('('+resultat.responseText+')');
	
	if(res[0] > 0)
	{
		clearInterval(timeInterval);
		alert(res[2]);	
	}
	$("user_photo").innerHTML = res[1];
}

function send_mail(id)
{
	var html = $("current_mail").innerHTML;
	$("current_mail").innerHTML = "<img src='"+url_root+"/images/ajax-loader.gif'  alt='请稍等' title='请稍等' />";
	
	Dialog.confirm({url: url_root + "/user/sendmail/id/" + id, options: {method: 'get'}},
	{top: 50, width:800, className: "alphacube", okLabel: "发送", cancelLabel:"返回", 
		draggable:true,maximizable:true,minimizable:true,recenterAuto:false,destroyOnClose:true,closable:true,
		onOk: function(win){
				$("MyForm").getInputs('text').each(function(element){$(element).observe('keydown', function(event){ clearError($(element)); });});
				$("MyForm").select('select').each(function(element){$(element).observe('change', function(event){ clearError($(element)); });});
				
				if(check_form_basic()==true)
				{
					alert("正在发送，点击确定后，请稍等");
					$("MyForm").submit();
				}
			},
		onCancel:function(win){$("current_mail").innerHTML = html;}});
}
function lire_message(id,user_id)
{
	msg = $("message" + id).innerHTML;
	Dialog.confirm(msg, 
	{top: 50,width:300, okLabel: "回复", className: "alphacube", id: "mypopup", cancelLabel:"关闭", 
	onOk:function(win) {
		loading();
		location.href = "/user/index/id/" + user_id;
		}
	});
}
function send_message(id)
{
	$("btn_send").innerHTML = "<img src='"+url_root+"/images/ajax-loader.gif' alt='请稍等' title='请稍等' />";
	var param = "id=" + id + "&msg=" + $F("message");
		new Ajax.Request(url_root + "/user/sendmsg", {
		  method: 'post',
		  parameters : param,
		  onComplete: afterSend
		});
}
function afterSend(resultat)
{
	var res = eval('('+resultat.responseText+')');
	alert(res[1]);	
	if(res[0] == "OK") $("message").value = "";
	$("btn_send").innerHTML = '<a href="javascript:void()" onclick="send_message(' + res[2] + ');">发送</a>';
}
function delmsg(id_msg,id_div)
{
	
	
	msg = "你确定要删除这条短信？！";
	Dialog.confirm(msg, 
	{top: 50,width:300, okLabel: "删除", className: "alphacube", id: "mypopup", cancelLabel:"取消", 
	onOk:function(win) {
			var param = "id_msg=" + id_msg;
			new Ajax.Request(url_root + "/user/delmsg", {
				  method: 'post',
				  parameters : param
				});
			Dialog.cancelCallback();
			Effect.Shrink('msg'+id_div);
		}
	});
}

