function isEmail(object)
{ 
	var s =document.getElementById(object).value; 
	var pattern =/^[a-zA-Z0-9_\-]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
	 if(s!="")
	 {
		 if(!pattern.exec(s))
		 {
		  alert('请输入正确的邮箱地址');
		  document.getElementById(object).focus();
		  return false;
		 }
	 }else{
		alert('请输入邮箱地址');
		document.getElementById(object).focus();
		return false;
	}
	
}
function isMobile(object)
{

}
jQuery(function($){
	//返回上一级
	$("#js-pre-step").click(function(){
		window.location.href = "index.php?_m=frontpage&_a=check";
	});
	//用户名 密码 数据库验证
	$("#js-install-at-once").click( function () {
		var s =document.getElementById("db-mobile").value; 
		var reg0 = /^13\d{5,9}$/;
		var reg1 = /^153\d{4,8}$/;
		var reg2 = /^159\d{4,8}$/;
		var reg3 = /^1\d{10,11}$/;
		var my = false;
		if (reg0.test(s))my=true;
		if (reg1.test(s))my=true;
		if (reg2.test(s))my=true;
		if (reg3.test(s))my=true;
		if(s!=""||s.length!=11)
		{
			if (!my)
			{
			   alert('请输入正确的手机号码');
			   document.getElementById("db-mobile").focus();
			   return false;
			}
		}else{
			alert('请输入手机号码');
			document.getElementById("db-mobile").focus();
			return false;
		}
		/**/
		var s =document.getElementById("db-qq").value;
		if(s!="")
		{
			if(isNaN(s)||s.length<6||s.length>12)
			{
			 alert("请输入正确的QQ号码");
			 document.getElementById("db-qq").focus();
			 return false;
			}
		}else{
			alert('请输入QQ');
			document.getElementById("db-qq").focus();
			return false;
		}
		/**/
		function obj(){
			var _this = this;
			var step = 1;
			var step_a ="checkconnection";
			this.resend = function(){
				if(step==2){
					step_a ="create";
				}else if(step==3){
					step_a ="createadmin";
				}
				$.ajax({
					type: "POST",
					url: "index.php",
					data: "db_host="+$("#db-host").val()+"&db_port="+$("#db-port").val()+"&db_user="+$("#db-user").val()+"&db_pwd="+$("#db-pwd").val()+"&db_name="+$("#db-name").val()+"&db_prefix="+$("#db-prefix").val()+"&admin_name="+$("#js-admin-name").val()+"&admin_pwd="+$("#js-admin-password").val()+"&_a="+step_a+"&step="+step+"&demo=1&mobile="+$("#db-mobile").val()+"&qq="+$("#db-qq").val()+"",
					success: function(msg){
						if(msg=="1001"){
							$("#install_result").html("连接数据库失败");
							return;
						}else if(msg=="1002"){
							$("#install_result").html("该数据库不存在");
							return;
						}else if(msg=="1006"){
							$("#install_result").html("数据写入失败！");
							return;
						}else{
							$("#install_result").html("正在创建数据表...");
							if(msg=="1005"){
								$("#install_result").html("创建表失败！");
								return;
							}
							if(msg=="1003"){
								$("#install_result").html("正在创建管理账户...");
							}
							if(msg=="1004"){
								$("#install_result").html("管理员用户创建成功！...");
								window.location.href = "index.php?_m=frontpage&_a=result";
							}
						}
						if(step < 4){
							step++;
							_this.resend();
						}
					}
				}); 
			}
		}
		var obj = new obj();
		obj.resend();
});

});
