var progressSpeed = 1;
var progressRate = 4;
var progressHeight = 3;
var progressWidth = 0;
var progressFlg = 0;
var progressIntervalId;
var progressWindowWidth = 300;
var progressWindowHeight = 50;
var progressWindowHtml = '<center>' + 
                         'waiting....' + 
                         '<table width="' + progressWindowWidth + '" height="' + progressWindowHeight + '">' + 
                         '<tr>' + 
                         '<td id="progressLeft" width="0%"></td>' +
                         '<td id="progressMiddle" width="100%"><div id="progressBar"></div></td>' +
                         '<td id="progressRight" width="0%"></td>' +
                         '</tr>' + 
                         '</table>' + 
                         '</center>';

function openProgressWindow(){
    var x = (document.body.clientWidth/2) - (progressWindowWidth/2);
    var y = (document.body.clientHeight/2) - progressWindowHeight;
    var progressWindow = document.getElementById('progressWindow');
    progressWindow.style.left = x;
    progressWindow.style.top = y;
    progressWindow.style.visibility = "visible";
    progressWindow.innerHTML = progressWindowHtml;
    var wnd = initProgress();
    document.getElementById('progressBar').innerHTML = wnd;
}

function closeProgressWindow(){
    clearInterval(progressIntervalId);
    var progressWindow = document.getElementById('progressWindow');
    progressWindow.style.visibility = 'hidden';
}

function initProgress(){
    progressWidth = 0;
    progressIntervalId = setInterval('progress()',progressSpeed);
    
    var str = '<table width="100%" height="' + progressHeight + '" cellspacing="0" cellpadding="0"><tr>';
    for(var i=0;i<256;i+=progressRate){
        var r = (255-i).toString(16);
        var g = (255-i).toString(16);
        var b = "FF";
        r = leftPad(r);
        g = leftPad(g);
        str += '<td bgcolor="#' + r + g + b + '"></td>';
    }
    for(var i=0;i<256;i+=progressRate){
        var r = i.toString(16);
        var g = i.toString(16);
        var b = "FF";
        r = leftPad(r);
        g = leftPad(g);
        str += '<td bgcolor="#' + r + g + b + '"></td>';
    }
    str += '</tr></table>';
    
    return str;
}

function leftPad(val){
    if((""+val).length==1){
        return "0" + val;
    }
    return val;
}

function progress(){
    progressWidth ++;
    if(progressWidth>100){
        if(progressFlg==0){
            progressFlg = 1;
        }else if(progressFlg==1){
            progressFlg = 0;
        }
        progressWidth = 0;
    }
    if(progressFlg==0){
        document.getElementById('progressLeft').style.width=progressWidth + "%";
        document.getElementById('progressMiddle').style.width=(100-progressWidth) + "%";
        document.getElementById('progressRight').style.width="0%";
    }else if(progressFlg==1){
        document.getElementById('progressLeft').style.width="0%";
        document.getElementById('progressMiddle').style.width=progressWidth + "%";
        document.getElementById('progressRight').style.width=(100-progressWidth) + "%";
    }
}



