var checklogin = { 
	checkUse:function(type){
		if(type == 0){
			$("checkusername").set('text','');
			var usertype = $("username").value.trim();
			var url = '/user/ajax_username_exist.php';
			var data = 'username=' + usertype;
			var thisObj = this;
			var callback = function(e) { thisObj.backCheckUse(e,type) };

			if(/^[\-\.\w]+@[\.\-\w]+(\.\w+)+$/.test(usertype)){
				RequestOld.reSend(url,data,callback);
			}
//			else if(usertype == "" || !/^[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*[a-zA-Z0-9]*$/.test(usertype)){
//				$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 输入的用户名为空或者格式不正确,只支持英文和数字');
//			}
			else if(usertype.length < 2 || usertype.length > 30){
				$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 用户名长度需要在2-30个字符之间！！');
			}
			else	if(usertype.length == 11 && /[1][358][0-9]{9}/.test(usertype)){
				$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 你输入的是手机号，互联网不允许为用户名');
			}else	{
				RequestOld.reSend(url,data,callback);
			}
		}else if(type == 1){
			$("checknickname").set('text','');
			var usernick = sketch("nickname1").trim();
			var url = '/user/ajax_nickname_exist.php';
			var data = 'nickname=' + usernick;
			var thisObj = this;
			var callback = function(e) { thisObj.backCheckUse(e,type) } ;
			if(usernick == ""){
				$("checknickname").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 输入的昵称为空,请重新输入');
			}else if(getLength(usernick) < 3 || getLength(usernick) > 16){
				$("checknickname").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 昵称长度需要在2-16个字符之间！！');
			}else{
				RequestOld.reSend(url,data,callback);
			}
		}else if(type == 2){
			$("checkusername").set('text','只允许输入数字、字母A-Z,a-z,0-9，如:bengxin,bengxin521，长度限制为4-10个字符');
			var usertype = $("username").value.trim();
			if(usertype == "" || !/^[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*[a-zA-Z0-9]*$/.test(usertype)){
				$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 输入的用户名为空或者格式不正确,只支持英文和数字');
			}else if(usertype.length < 4 || usertype.length > 10){
				$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 用户名长度需要在4-10个字符之间！！');
			}else{
				$('idBtn').disabled = false;
			}
		}
	} ,
	backCheckUse:function(httpObj,type){
		var ret = httpObj.responseText ;
		var jsontxt = JSON.decode(ret) ;
		if(type == 0){
			var usertype = sketch("username").trim();
			if(jsontxt == 0){
				if(/^[\-\.\w]+@[\.\-\w]+(\.\w+)+$/.test(usertype)){
					$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_right.gif" alt="" /> 你的帐号可以注册，但是你输入的是电子邮件，将会发送到你的邮箱内请求验证啊');
				}else{
					$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_right.gif" alt="" /> 恭喜你没有和你重名的，可以注册');
				}
			}else if(jsontxt == 1){
					$("checkusername").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 已被注册，请重新输入用户名');
			}
		}else if(type == 1){
			if(jsontxt == 0){
					$("checknickname").set('html','<img src="http://img.' + domain + '.cn/web/check_right.gif" alt="" /> 该昵称可以使用');
			}else if(jsontxt == 1){
					$("checknickname").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" /> 该昵称已被使用');
			}
		}
	},
	checkpassword2:function(confirm){
		var password =  sketch("signin-password").trim() ;
		var password2 =  sketch("signin-password-ag").trim() ;
		if(password2 != '') {
			this.checkpassword(true);
		}
		if(password == '' || (confirm && password2 == '')){
				$("checkpasswordag").set('html','');
				return;
			}
		if(password != password2){
			$("checkpasswordag").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" />两次输入的密码不一样');
		} else{
			$("checkpasswordag").set('text','');
		}
	},
	checkpassword:function(confirm){
			var password =  sketch("signin-password").trim() ;
			if(password == '' || /[\'\"\\]/.test(password)) {
				$("checkpassword").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" />密码为空或有特殊字符');
			}else if(getLength(password) < 4 || getLength(password) > 16){
				$("checkpassword").set('html','<img src="http://img.' + domain + '.cn/web/check_error.gif" alt="" />密码长度只允许4-16个字符');
			}else {
				$("checkpassword").set('text','');
				if(!confirm) {
					this.checkpassword2(true);
				}
				return true;
			}
	},
	signin:function(){
	
		var name = sketch("username").trim() ;
		if(!name) {
			alert('请输入用户名') ;
			$("username").focus();
			return false ;
		}
		
		if(name.length < 2 || name.length > 30){
			alert('用户名长度需要在2-30个字符');
			$("username").focus();
			return false ;
		}
		
		if($("emailPW")){
			var emailPW = sketch("emailPW").trim();
			if(!emailPW){
				alert("请输入你的Email");
				return false ;
			}
		}	
		
		
		
		if($("smale")){
			if($("smale").checked != true && $("sfemale").checked != true){
				alert("请先选择性别");
				return false ;
			}
		}
		if($("year")){
			var year = sketch("year").trim();
			if(!year){
				alert("请先选择出生日期");
				return false ;
			}
		}		
		
		if($("month")){
			var month = sketch("month").trim();
			if(!month){
				alert("请先选择出生日期");
				return false ;
			}
		}	
		
		if($("day")){
			var day = sketch("day").trim();
			if(!day){
				alert("请先选择出生日期");
				return false ;
			}
		}	
		
		if($("location2")){
			var location2 = sketch("location2").trim();
			if(!location2){
				alert("请先选择现常居地");
				return false ;
			}
		}
		
		var password =  sketch("signin-password").trim() ;
		if(!password) {
			alert('请输入密码') ;
			$("signin-password").focus();
			return false ;
		}
		if($("signin-password-ag")){
			var passworda =  sketch("signin-password-ag").trim() ;
			if(password != passworda){
				alert('两次输入的密码不一致，请确认。重新填写。') ;
				return false ;
			}
		}
//		var mark =  sketch("sessmark").trim() ;
//		if(!mark) {
//			alert('请输入验证码') ;
//			$("sessmark").focus();
//			return false ;
//		}
//		if(mark.length != 4){
//			alert("验证码长度不正确");
//			$("sessmark").focus();
//			return false ;
//		}
		if($("reading")){
			if($("reading").checked != true){
				alert("请先阅读协议");
				return false ;
			}
		}
//		md5hash($("signin-password"), $("md5password"), '');
//		if($('confirm_password')){
//			md5hash($("signin-password-ag"), $("confirm_password"), '');
//		}
	}
}
function inputUser(){
	if(sketch('username') == "邮箱/用户名"){
		$('username').value = "";
		$('signin-password').value = "";
	};
}
function inputPsw(){
	if(sketch('signin-password') == "*$@#M("){
		$('signin-password').value = "";
	};
	
}


var obtainCoin = { 
		obtain:function(){
			var myrequest = new Request.JSON({
				url: '/ajax/get_coin.php',
				onSuccess: function(jsonObj) {
					alert(jsonObj);
					location.href = location.href;
				}
			})
			myrequest.cancel();
			myrequest.send();
		}
}



Timer = function(elem_id, current_ms, del_elem_id){
	this.current_ms = current_ms;
	this.elem = document.getElementById(elem_id);
	this.del_elem = (del_elem_id)? document.getElementById(del_elem_id) : null;
	this.count = 0;
	this.delay = false;
}
Timer.prototype.start = function(){
	this.showTime();
	this.current_ms -= 1000;
	if(this.current_ms < 0 && this.current_ms >= -1000){
		this.elem.value="领取么么币";
		this.elem.disabled = false;
	}else if(this.current_ms >= 0 && this.current_ms <= 5000){
		if(this.del_elem) this.del_elem.style.display = "none";
	}
	var _self = this;
	if(this.count > 0) setTimeout(function(){_self.start()}, 1000);
}
Timer.prototype.showTime = function(){
	this.count ++;
	var ms = this.current_ms;
	var s = h = m = 0;
	if(this.count == 1 && ms < 0){
		if(this.del_elem) this.del_elem.style.display = "none";
		this.elem.value="领取么么币";
		this.elem.disabled = false;
		this.count = 0;
		return;
	}else if(ms < 1000){
		this.elem.value="领取么么币";
		this.elem.disabled = false;
		return;
	}
	else s = Math.floor(ms/1000);
	if(this.elem != null) {
		if(s>=60){
            m=Math.floor(s/60);
            s=s-m*60
        }
        if(m>=60){
            h=Math.floor(m/60);
            m=m-h*60
        }
        if(s<10) s="0"+s;
        if(m<10) m="0"+m;
        if(h<10) h="0"+h;
        this.elem.value = ""+h+":"+m+":"+s;
        this.elem.disabled = true;
	}
}

