var aa = false;
function Register(){
	this.Uname = document.getElementById("username").value;
	this.PassWord = document.getElementById("password").value;
	this.ApassWord = document.getElementById("againpass").value;
	this.Email = document.getElementById("email").value;
	this.FormatSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">用户名中含有特殊字符！</font>&nbsp;</font>';
	this.LongLengthSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">用户名长度太长！</font>&nbsp;</font>';
	this.ShortLengthSTR= '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">用户名长度太短！</font>&nbsp;</font>';
	//this.RepeatNameSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">用户名已被注册,请换一个！</font>&nbsp;</font>';
	//this.OkNameSTR = '<font style="border:solid 1px #53ac45;"><img src="/resource/images/ok.gif">&nbsp;<font color="#53ac45">该用户名合法，可以注册</font>&nbsp;</font>';
	this.LongPSLengthSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">密码长度太长！</font>&nbsp;</font>';
	this.ShortPSLengthSTR= '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">密码长度太短！</font>&nbsp;</font>';
	this.DifferentSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">两次密码不同，请重新输入</font>&nbsp;</font>';
	this.ErrorSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">Email格式错误！</font>&nbsp;</font>';
	this.OkSTR= '<font style="border:solid 1px #53ac45;"><img src="/resource/images/ok.gif">&nbsp;<font color="#53ac45">填写正确</font>&nbsp;</font>';
	this.Reg0=/[0-9,a-z,_$]+@([0-9,a-z,_$]+\.)+[0-9,a-z,_$]+/gi;

	this.fucCheckSTR = function(strcheck){
		var i,j,strTemp;
		strTemp="0123456789abcdefghijklmnopqrstuvwxyz_@.";
		if ( strcheck.length== 0)
			return 0
		for (i=0;i<strcheck.length;i++)
		{
		   j=strTemp.indexOf(strcheck.charAt(i));
		   if (j==-1)
		   {
			 return 0;
		   }
		}
		return 1;
	}

	this.RegisterCheckUserName = function(){
		if(this.Uname.length < 6){
			document.getElementById("checkname").innerHTML = this.ShortLengthSTR;
			return false;
		}
		else if(this.Uname.length > 20){
			document.getElementById("checkname").innerHTML = this.LongLengthSTR;
			return false;
		}
		else if(!this.fucCheckSTR(this.Uname)){
			document.getElementById("checkname").innerHTML = this.FormatSTR;
			return false;
		}
		else
		{
			
			var pars = 'Uname=' + encodeURI(this.Uname) ;
			_ajax = new Ajax.Request('http://www.hiu.cn/post/RegisterCheckUserName/',
				{
					method		: 'get',
					parameters	: pars,
					onComplete	: function(transport, json)
					{
						
						if(json.success == false)
						{
							document.getElementById("checkname").innerHTML = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">用户名已被注册,请换一个！</font>&nbsp;</font>';
							aa = false;
						}
						else if(json.success == true)
						{
							document.getElementById("checkname").innerHTML = '<font style="border:solid 1px #53ac45;"><img src="/resource/images/ok.gif">&nbsp;<font color="#53ac45">该用户名合法，可以注册</font>&nbsp;</font>';
							aa = true;
						}
					}
				}
			);
			return aa;
		}
	}

	this.RegisterCheckPssWord = function(){
		if(this.PassWord.length < 6){
			document.getElementById("checkpwd").innerHTML = this.ShortPSLengthSTR;
			return false;
		}
		else if(this.PassWord.length > 16){
			document.getElementById("checkpwd").innerHTML = this.LongPSLengthSTR;
			return false;
		}
		else
		{
			document.getElementById("checkpwd").innerHTML = this.OkSTR;
			return true;
		}
	}

	this.RegisterAgainPssWord = function(){
		if(this.PassWord != this.ApassWord)
		{
			document.getElementById("checkapwd").innerHTML = this.DifferentSTR;
			return false;
		}
		else
		{
			document.getElementById("checkapwd").innerHTML = this.OkSTR;
			return true;
		}
	}

	this.RegisterEmail = function(){
		if(!this.Reg0.test(this.Email))
		{
			document.getElementById("checkemail").innerHTML = this.ErrorSTR;
			return false;
		}
		else
		{
			document.getElementById("checkemail").innerHTML = this.OkSTR;
			return true;
		}
	}

	this.RegisterSubmit = function(){
		if(this.RegisterCheckUserName() == true)
		{
			if(this.RegisterCheckPssWord() == true)
			{
				if(this.RegisterAgainPssWord() == true)
				{
					if(this.RegisterEmail() == true)
					{
						registerform.submit();
					}
				}
			}
		}
	}
}

function ShowMoreinfo(){
	
	if(document.registerform.box1.checked == true)
	{
		document.getElementById('Moreinfo').style.display = '';
	}
	else
	{
		document.getElementById('Moreinfo').style.display = 'none';
	}
}

function onsetmap(cityname)
		{
			var rs = window.showModalDialog('http://www.hiu.cn/iframe/map_set.php?city='+encodeURI(cityname), '', 'dialogHeight:650px;dialogWidth:800px;');
			if(rs != null)
			{
				releaseform.lo.value = rs[0];
				releaseform.la.value = rs[1];
				window.alert('标注成功');
			}
		}

function mapsearch(cityname)
{
	document.getElementById("distance_div").style.display = '';
	document.getElementById("searchname").style.width = '80';
	var rs = window.showModalDialog('http://www.hiu.cn/iframe/map_search.php?city='+encodeURI(cityname), '', 'dialogHeight:650px;dialogWidth:800px;');
	if(rs != null)
			{
				topform.lo.value = rs[0];
				topform.la.value = rs[1];
				alert('坐标选定，请选择坐标走周边范围');
				document.getElementById("mapsearch").style.display = 'none';
				document.getElementById("mapqingchu").style.display = '';
				document.getElementById("distance").options[0].selected = true;
			}
}

function mapqingchu()
{
				topform.lo.value = '';
				topform.la.value = '';
				alert('坐标清除');
				document.getElementById("mapsearch").style.display = '';
				document.getElementById("mapqingchu").style.display = 'none';
				document.getElementById("distance_div").style.display = 'none';
				document.getElementById("searchname").style.width = '160';
}

function onsetmap1(cityname,lo,la)
		{
			var rs = window.showModalDialog('http://www.hiu.cn/iframe/map_show.php?city='+encodeURI(cityname)+'&lo='+encodeURI(lo)+'&la='+encodeURI(la), '', 'dialogHeight:600px;dialogWidth:800px;');
		}

function ChecklgoinForm(){
	 
	var Objs = window.document.loginform;
	if(Objs.username.value == '') 
	{ 
		alert("用户名不能为空！"); 
		Objs.username.focus();
		return false; 
	} 
	else if(Objs.password.value == '')
	{
		alert("密码不为空");
		Objs.password.focus();
		return false;
	}
	loginform.submit();
}

function Chmodinfo(){
	this.PassWord = document.getElementById("password").value;
	this.ApassWord = document.getElementById("againpass").value;
	this.Email = document.getElementById("email").value;
	this.LongPSLengthSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">密码长度太长！</font>&nbsp;</font>';
	this.ShortPSLengthSTR= '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">密码长度太短！</font>&nbsp;</font>';
	this.DifferentSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">两次密码不同，请重新输入</font>&nbsp;</font>';
	this.ErrorSTR = '<font style="border:solid 1px #ed6c00;"><img src="/resource/images/error.gif">&nbsp;<font color="#ed6c00">Email格式错误！</font>&nbsp;</font>';
	this.OkSTR= '<font style="border:solid 1px #53ac45;"><img src="/resource/images/ok.gif">&nbsp;<font color="#53ac45">填写正确</font>&nbsp;</font>';
	this.Reg0=/[0-9,a-z,_$]+@([0-9,a-z,_$]+\.)+[0-9,a-z,_$]+/gi;

	this.ChmodinfoCheckPssWord = function(){
		if(this.PassWord.length < 6){
			document.getElementById("checkpwd").innerHTML = this.ShortPSLengthSTR;
			return false;
		}
		else if(this.PassWord.length > 16){
			document.getElementById("checkpwd").innerHTML = this.LongPSLengthSTR;
			return false;
		}
		else
		{
			document.getElementById("checkpwd").innerHTML = this.OkSTR;
			return true;
		}
	}

	this.ChmodinfoAgainPssWord = function(){
		if(this.PassWord != this.ApassWord)
		{
			document.getElementById("checkapwd").innerHTML = this.DifferentSTR;
			return false;
		}
		else
		{
			document.getElementById("checkapwd").innerHTML = this.OkSTR;
			return true;
		}
	}

	this.ChmodinfoEmail = function(){
		if(!this.Reg0.test(this.Email))
		{
			document.getElementById("checkemail").innerHTML = this.ErrorSTR;
			return false;
		}
		else
		{
			document.getElementById("checkemail").innerHTML = this.OkSTR;
			return true;
		}
	}

	this.ChmodinfoSubmit = function(){
		
			if(this.ChmodinfoCheckPssWord() == true)
			{
				if(this.ChmodinfoAgainPssWord() == true)
				{
					if(this.ChmodinfoEmail() == true)
					{
						Chmodinfoform.submit();
					}
				}
			}
	}
}