$(function() {
	//底部调整
	var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null; 
	if (!isChrome) {
		$(".tpl-page-container .tpl-content-wrapper").addClass("R-wra");
		$(".tpl-page-container .tpl-left-nav").addClass("L-tpl");
	}
	// 检测表单
	function isTelCode(str) {
		var reg = /^((0\d{2,3}-\d{7,8})|(1\d{10}))$/;
		return reg.test(str);
	}
	function IsEmail(str) {
		var reg = /^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/;
		return reg.test(str);
	}
	// 检测密码
	function IsPwd(str) {
		var reg = /^[0-9a-zA-Z_]{5,19}$/;
		return reg.test(str);
	}
	$('#ngme-Yjs-sublime').click(function() {
		if ($('#user-name').val() != '') {
			if ($('#user-name').val().length >= 5 && $('#user-name').val().length <= 20) {
				var reg = /^[a-zA-Z][0-9a-zA-Z_]{4,19}$/;
				var r = reg.test($('#user-name').val());
				if (!r) {           
					confirm('用户名必须以字母开头');
					return false;
				}
			} else {           
				confirm('长度为5-20');
				return false;
			}
		} else {
			confirm('请输入登录用户名');
			return false;
		}
		if ($('#password').val() != $('#password_').val()) {           
			confirm('两次输入的密码不一致');
			return false;
		}
		if ($('#email').val() != '') {
			if (!IsEmail($('#email').val())) {           
				confirm('您输入的邮箱不合法');
				return false;
			}
		}
		if ($('#phone').val() != '') {
			if (!isTelCode($('#phone').val())) {           
				confirm('您输入的手机号不合法');
				return false;
			}
		}
		if ($('#user-name').val() == '' && $('#phone').val() == '' && $('#email').val() == '') {           
			confirm('用户名,手机号,邮箱至少填写一项');
			return false;
		}
		return true;
	})
	//当输入框输入为空,失去焦点时,提示图标为交叉,
	//当输入框输入不为空,失去焦点时,提示图标为勾
	var userParent = $('#user-name').parent().parent('.am-form-group');
	var userNext = $('#user-name').next('i');
	var phoneParent = $('#phone').parent().parent('.am-form-group');
	var phoneNext = $('#phone').next('i');
	var emailParent = $('#email').parent().parent('.am-form-group');
	var emailNext = $('#email').next('i');
	var pwdParent = $('#password').parent().parent('.am-form-group');
	var pwdNext = $('#password').next('i');
	var pwd_Parent = $('#password_').parent().parent('.am-form-group');
	var pwd_Next = $('#password_').next('i');
	// 添加必填标记
	$('#user-name,#phone,#password,#password_').addClass('am-back-input');
	//登录用户名 失去焦点时的事件
	$('#user-name').blur(function() {
		if ($('#user-name').val() != '') {
			if ($('#user-name').val().length >= 5 && $('#user-name').val().length <= 20) {
				var reg = /^[a-zA-Z][0-9a-zA-Z_]{4,19}$/;
				var r = reg.test($('#user-name').val());
				if (!r) {
					$(userParent).removeClass('am-form-success');
					$(userParent).addClass('am-form-error');
					$(userNext).removeClass('am-icon-check');
					$(userNext).addClass('am-icon-times');
					$('#user-name').removeClass('am-back-input');
				} else {
					$(userParent).removeClass('am-form-error');
					$(userParent).addClass('am-form-success')
					$(userNext).removeClass('am-icon-times');
					$(userNext).addClass('am-icon-check');
					$('#user-name').removeClass('am-back-input');
				}
			} else {
				$(userParent).removeClass('am-form-success');
				$(userParent).addClass('am-form-error');
				$(userNext).removeClass('am-icon-check');
				$(userNext).addClass('am-icon-times');
			}
		}
		//用户名为空时，执行
		if ($('#user-name').val() == '') {
			$(userParent).removeClass('am-form-success am-form-error');
			$(userNext).removeClass('am-icon-check am-icon-times');
			$('#user-name').addClass('am-back-input');
		}
	})
	// 手机号
	$('#phone').blur(function() {
		if ($('#phone').val() != '') {
			if (!isTelCode($('#phone').val())) {
				$('#phone').removeClass('am-back-input');
				$(phoneParent).removeClass('am-form-success');
				$(phoneParent).addClass('am-form-error');
				$(phoneNext).removeClass('am-icon-check');
				$(phoneNext).addClass('am-icon-times');
			} else {
				$('#phone').removeClass('am-back-input');
				$(phoneParent).removeClass('am-form-error');
				$(phoneParent).addClass('am-form-success');
				$(phoneNext).removeClass('am-icon-times');
				$(phoneNext).addClass('am-icon-check');
			}
		}
		//手机号码为空时，执行
		if ($('#phone').val() == '') {
			$(phoneParent).removeClass('am-form-success am-form-error');
			$(phoneNext).removeClass('am-icon-check am-icon-times');
			$('#phone').addClass('am-back-input');
		}
	})
	//邮箱
	$('#email').blur(function() {
		if ($('#email').val() != '') {
			if (!IsEmail($('#email').val())) {
				$(emailParent).removeClass('am-form-success');
				$(emailParent).addClass('am-form-error');
				$(emailNext).removeClass('am-icon-check');
				$(emailNext).addClass('am-icon-times');
			} else {
				$(emailParent).removeClass('am-form-error');
				$(emailParent).addClass('am-form-success');
				$(emailNext).removeClass('am-icon-times');
				$(emailNext).addClass('am-icon-check');
			}
		}
		//邮箱为空时，执行
		if ($('#email').val() == '') {
			$(emailParent).removeClass('am-form-success am-form-error');
			$(emailNext).removeClass('am-icon-check am-icon-times');
		}
	})
	// 密码
	$('#password').blur(function() {
		if ($('#password').val() != '') {
			if (!IsPwd($('#password').val())) {
				$('#password').removeClass('am-back-input');
				$(pwdParent).removeClass('am-form-success');
				$(pwdParent).addClass('am-form-error');
				$(pwdNext).removeClass('am-icon-check');
				$(pwdNext).addClass('am-icon-times');
			} else {
				$('#password').removeClass('am-back-input');
				$(pwdParent).removeClass('am-form-error');
				$(pwdParent).addClass('am-form-success');
				$(pwdNext).removeClass('am-icon-times');
				$(pwdNext).addClass('am-icon-check');
			}
			//确定密码不为空时，执行
			if ($('#password_').val() != '') {
				//两次不一致
				if ($('#password_').val() != $('#password').val()) {
					$('#password_').removeClass('am-back-input');
					$(pwd_Parent).removeClass('am-form-success');
					$(pwd_Parent).addClass('am-form-error');
					$(pwd_Next).removeClass('am-icon-check');
					$(pwd_Next).addClass('am-icon-times');
				} else {
					$('#password_').removeClass('am-back-input');
					$(pwd_Parent).removeClass('am-form-error');
					$(pwd_Parent).addClass('am-form-success');
					$(pwd_Next).removeClass('am-icon-times');
					$(pwd_Next).addClass('am-icon-check');
				}
			}
		}
		if ($('#password').val() == '') {
			$('#password').addClass('am-back-input');
			$(pwdParent).removeClass('am-form-success am-form-error');
			$(pwdNext).removeClass('am-icon-check am-icon-times');
		}
	})
	//二次密码
	$('#password_').blur(function() {
		if ($('#password_').val() != '') {
			if (!IsPwd($('#password_').val())) {
				$('#password_').removeClass('am-back-input');
				$(pwd_Parent).removeClass('am-form-success');
				$(pwd_Parent).addClass('am-form-error');
				$(pwd_Next).removeClass('am-icon-check');
				$(pwd_Next).addClass('am-icon-times');
			} else {
				$('#password_').removeClass('am-back-input');
				$(pwd_Parent).removeClass('am-form-error');
				$(pwd_Parent).addClass('am-form-success');
				$(pwd_Next).removeClass('am-icon-times');
				$(pwd_Next).addClass('am-icon-check');
			}
			//两次不一致
			if ($('#password_').val() != $('#password').val()) {
				$('#password_').removeClass('am-back-input');
				$(pwd_Parent).removeClass('am-form-success');
				$(pwd_Parent).addClass('am-form-error');
				$(pwd_Next).removeClass('am-icon-check');
				$(pwd_Next).addClass('am-icon-times');
			}
		}
		if ($('#password_').val() == '') {
			$('#password_').addClass('am-back-input');
			$(pwd_Parent).removeClass('am-form-success am-form-error');
			$(pwd_Next).removeClass('am-icon-check am-icon-times');
		}
	})
})