var interval; //生成间隔
var CurrentPercent = 0;
var CurrentRowIndex = 0;
var GetUrlListAjax;
var UrlList = new Array();
var MakeState; //生成状态
var Ajax;
var url;
function Make()
{
    Ajax = new AjaxClass();
    Ajax.RequestUrl = url;
    Ajax.Method = "get";
    Ajax.IsAsyn = true;
    Ajax.StateChangeEvent = GetUrlListAjaxReadyStateChange;
    Ajax.SendRequest();
}
function GetUrlListAjaxReadyStateChange()
{
    if (Ajax.XmlHttp.readyState == 4)
    {
        if (Ajax.XmlHttp.status == 200)
        {
            UrlList = Ajax.XmlHttp.responseText.split("|");

            Message("已经取得数据列队。");

            window.setTimeout("MakeStart()", 10);
            PercentChange(1, UrlList.length);
        }
    }
    else
    {
        Message("正在取得数据列队。");
    }
}

function MakeStart()
{
    if (UrlList.length > 0)
    {
        MakeState = 1;
        CurrentRowIndex = 0;
        MakeHTML(CurrentRowIndex);
    }
}

function MakeHTML(index)
{
    if (MakeState == 0)
    {
        return;
    }

    if (UrlList[index] == "")
    {
        return;
    }
    Ajax = new AjaxClass();
    Ajax.RequestUrl = UrlList[index] + "&n=" + Math.random(); ;
    Ajax.Method = "get";
    Ajax.IsAsyn = true;
    Ajax.StateChangeEvent = XmlHttpQuarryStateChange;
    Ajax.SendRequest();
}
function XmlHttpQuarryStateChange()
{
    if (Ajax.XmlHttp.readyState == 4)
    {
        PercentChange(CurrentRowIndex + 1, UrlList.length);

        if (Ajax.XmlHttp.status == 200)
        {

        }
        else
        {
            Message("--操作失败。错误代码为：[" + Ajax.XmlHttp.status + "]," + Ajax.XmlHttp.statusText);
        }

        CurrentRowIndex++;

        if (CurrentRowIndex < UrlList.length)
        {
            window.setTimeout("MakeHTML(" + CurrentRowIndex + ")", interval);
        }
        else
        {
            Message("生成完毕。");
            Stop();
        }
    }
}
function Start()
{
    interval = $("txt_interval").value; //生成间隔
    MakeState = 1;
    UrlList = new Array();
    $('bt_start').disabled = true;
    $('bt_stop').disabled = false;
    Make();
}
function Stop()
{
    interval = 0; //生成间隔
    CurrentPercent = 0;
    CurrentRowIndex = 0;
    GetUrlListAjax = null;
    UrlList = null;
    MakeState = 0;
    $("bt_start").disabled = false;
    $("bt_stop").disabled = true;
    MakeState = 0;
}
function PercentChange(PageCount, PageTotal)
{

    $("ProcessBar").style.width = PageCount * (600 / PageTotal) + "px";
    $("ProcessBar").innerText = (PageCount / PageTotal * 100).toPrecision(4).toString() + "%";
    $("ProcessBar").title = "当前进度量：" + PageCount;
    $("ProgressNum").innerText = PageCount;
    $("ProgressTotal").innerText = PageTotal;

    if (PageCount > 0 && PageCount != PageTotal)
    {
        Message("正在生成");
    }
}
function Message(str)
{
    $("Message").innerText = str;
}