﻿//***************************************************************/
// 作者：冯岩
// 日期：2008-06-19
// 功能：创建进度条效果
// 修改：修改日期,修改人加说明
//***************************************************************/
function DoubleAnimation(target,targetProperty,from,to,Duration)
{
    this.Begin=function anonymous()
    {
        target[targetProperty]=from;
        var starttime=new Date();
        setTimeout(StoryBoard(),1);
        function StoryBoard()
        {
            return function()
            {                 
                var now=new Date();
                var d=now.getTime()-starttime.getTime();
                target[targetProperty]=Math.round(from+(to-from)*d/Duration);
                if(d<Duration)setTimeout(StoryBoard(),10);
            }
        }
    }
    this.setTo=function(val){to=val;}
    this.setFrom=function(val){from=val;}
} 

var Container;
var p=0;
var pb1;
var backToUrl;
function ProgressBar(ID,msg)
{
    Container.style.display = "inline";
    var html = "<div id=\""+ID+"\" style=\"position:absolute;top:10%;width:100; left: 108px;\">";
    html +=" <image src=\"../images/emptypb.jpg\" style=\"position: absolute;left: 84px; top: 137px;\" />";
    html +=" <div id=\""+ID+"pb\" style=\"position: absolute; left: 86px; top: 137px;z-index:5;overflow:hidden;width:130;\" > ";
    html +=" <img src=\"../images/iconfullpb.jpg\"/> ";
    html +=" <div id=\""+ID+"highlight\" style=\"background:#ffffff;left: -500px; position: absolute; top: -1px;width:100;height:20;filter:Alpha(Opacity=75,FinishOpacity=0,Style=2)\"></div>        </div> ";
    html +=" <div style=\"position:absolute;top:118px;width:180px;text-align: center; left: 148px;\">"+msg+"</div>   </div>";

    Container.innerHTML = html;
    var story=new DoubleAnimation(document.getElementById(ID+"highlight").style,"left",-100,324,2000)
    var stophandle=setInterval(story.Begin,2000);
    this.set=function(percentage)
    {
        document.getElementById(ID+"pb").style.width=Math.round(percentage*329/100);
    }
}


function loading(ID,msg,url)
{
    if(Container == undefined)
    {
       
        hide();
       
        Container=document.createElement('div');
		Container.id='globalLoadDiv';
		Container.style.display='inline';
		Container.style.zIndex='9999';	
		Container.style.position = 'absolute';
		Container.style.marginLeft ='-175px';
		Container.style.textAlign = 'left';
		Container.style.top = '100px';
		Container.style.left = '30%';
		Container.style.width= "350px";
		if(document.readyState=="complete")
		{  
		    document.body.appendChild(Container);		
		}
        pb1=new ProgressBar(ID,msg,url);
        backToUrl = url;
    }
    
    pb1.set(p+=0.3);
    if(p<100)
	    setTimeout(loading,2);
    else
    {
        cancel();
        document.body.removeChild(Container);        
	    window.setTimeout("window.location.href='"+backToUrl+"';",500);
	   return;
	}
}
//调用示例 by fengyan 2008-06-19
//loading('ok''成功','http://www.baidu.com');
