//初始化全局变量
var wait1 = 0;
var wait2 = 0;
var wait3 = 0;
var wait4 = 0;

function GetObj(id){
    return document.getElementById(id);
}

function ShowWaitStatus(index){
    var id = "wait" + index;
    GetObj(id).innerHTML = GetObj(id).innerHTML + ".";
    if(GetObj(id).innerHTML == "............"){
        GetObj(id).innerHTML = ".";
    }
}

function WaitVerify(){
    //结束循环条件
    if(wait1 == 1){
        return;
    }
    ShowWaitStatus(1);
    CheckIsFirstConnect();
    setTimeout('WaitVerify()', 1000);
}

function StopVerify(){
    if(wait3 == 0){
        $("NextStep_5").value = "验证超时，继续安装程序";
        $("NextStep_5").disabled = false;
        wait1 = 1;
        wait2 = 1;
        wait3 = 1;
    }
}

function WaitVerify_3(){
    //结束循环条件
    if(wait3 == 1){
        return;
    }
    ShowWaitStatus(3);
    CheckIsThirdConnect();
    setTimeout('WaitVerify_3()', 1000);
}

function WaitVerify_2(){
    //结束循环条件
    if(wait2 == 1){
        return;
    }
    ShowWaitStatus(2);
    CheckIsSecondConnect();
    setTimeout('WaitVerify_2()', 1000);
}

//AJAX判断是否有连接验证文件
function CheckIsFirstConnect(){
    var url = "index.aspx?act=firstcheck&d=" + Date()
    var myajax = new Ajax.Updater(    
        {success: 'status1'},     
        url,    
        {    
            asynchronous:true,    
            method: 'get',    
            evalscrīpts:true,
			onComplete : ShowNextStep
        }    
    );
}

//判断开始下一步验证
function ShowNextStep(){
    if($("status1").innerHTML == "服务器连接成功"){
        //alert(11);
        $("wait1").innerHTML = " ------ <span style='color:green'>OK!</span>";
        wait1 = 1;
        //开始下一步验证
        WaitVerify_2();
       // $("status2").innerHTML = "服务器域名验证请求已发送，等待服务器的回复";
    }
}

//判断第2次连接是否成功
function CheckIsSecondConnect(){
    var url = "index.aspx?act=secondcheck&d=" + Date()
    var myajax = new Ajax.Updater(    
        {success: 'status2'},     
        url,    
        {    
            asynchronous:true,    
            method: 'get',    
            evalscrīpts:true,
			onComplete : ShowNextStep2
        }    
    );
}

//判断开始下一步验证
function ShowNextStep2(){
    if($("status2").innerHTML == "服务器域名验证通过"){
        //alert(22);
        $("wait2").innerHTML = " ------ <span style='color:green'>OK!</span>";
        wait2 = 1;
        //开始下一步验证
        WaitVerify_3();
        //$("status3").innerHTML = "正在下载您的授权文件";
    }
}

//判断第3次连接是否成功
function CheckIsThirdConnect(){
    var url = "index.aspx?act=thirdcheck&d=" + Date()
    var myajax = new Ajax.Updater(    
        {success: 'status3'},     
        url,    
        {    
            asynchronous:true,    
            method: 'get',    
            evalscrīpts:true,
			onComplete : ShowSuccess
        }    
    );
}

function ShowSuccess(){
    if($("status3").innerHTML == "授权文件下载完毕"){
        //alert(33);
        $("wait3").innerHTML = " ------ <span style='color:green'>OK!</span>";
        wait3 = 1;
        $("NextStep_5").value = "验证成功，开始安装程序";
        $("NextStep_5").disabled = false;
    }
}


function checkInstall(){
    if($("txtVirtualPath").value == ""){
        alert("虚拟路径地址不能为空");
        $("txtVirtualPath").focus()
        return false;
    }
    if($("txtAdminName").value == ""){
        alert("后台管理员帐号不能为空");
        $("txtAdminName").focus()
        return false;
    }
    if($("txtAdminPass").value == ""){
        alert("后台管理员密码不能为空");
        $("txtAdminPass").focus()
        return false;
    }
    
    if(confirm('数据库的旧数据将被清空，您确认要进行安装吗？')){
        setTimeout('VerifyDataBaseStatus()','1000');
        return true;
    }else{
        return false;
    }
}

function VerifyDataBaseStatus(){
    $("NextStep_4").disabled = true;
    $("Panel_4").innerHTML = "<hr/><table width='100%' cellpadding='0' cellspacing='0'><tr><td align='center' height='150' valign='middle'>安装进度 - <span id='databasestatus' style='font-color:blue'></span> %</td></tr></table>";
    $("NextStep_4").value = "数据库安装中...";
    
    var url = "index.aspx?act=database&str1="+$("str1").value+"&str2="+$("str2").value+"&str3="+$("str3").value+"&str4="+$("str4").value+"&str5="+$("str5").value+"&d=" + Date()
    var myajax = new Ajax.Updater(    
        {success: 'databasestatus'},     
        url,    
        {    
            asynchronous:true,    
            method: 'get',    
            evalscrīpts:true
        }    
    );
    setTimeout('VerifyDataBaseStatus()', 1000);
}