var flag=true;
var data="";

function refreshProgress()
{
    var url='http://www.cellsea.com/ajaxproxy1/uploadstatus?t='+new Date().getTime();
    var myAjax = new Ajax(url, {method: 'get',onComplete: updateProgress}).request();
}



function updateProgress(response)
{
	if(flag==false){clearInterval(timeoutRet);}
	
	if(response==100){
		document.getElementById('progressBarText').innerHTML = '<b><font color=#A00050>Upload in progress: 100%</font></b>';	
		document.getElementById('progressBarBoxContent').style.width = '300px';
		document.getElementById('progressBarText1').innerHTML ='';
	}else if(response.replace(/^\s+|\s+$/g, '')=='error'){
		return true;
    }else{
		var uploadInfo = eval('(' + response.replace(/^\s+|\s+$/g, '') + ')');
	    if(uploadInfo!=null&&uploadInfo.totalSize>0){	  
		    var fileIndex = uploadInfo.fileIndex;	
		    var progressPercent = Math.ceil((uploadInfo.bytesRead / uploadInfo.totalSize) * 100);	     
		    document.getElementById('progressBarText').innerHTML = '<b><font color=#A00050>Upload in progress: ' + progressPercent + '%</font></b>';	
		    document.getElementById('progressBarBoxContent').style.width = parseInt(progressPercent * 3) + 'px';
		    document.getElementById('progressBarText1').innerHTML =uploadInfo.bytesRead+ ' of ' + uploadInfo.totalSize + ' bytes at '+uploadInfo.transmitRate +' KB/sec, '+uploadInfo.remainTime+' remain';
		}
	}
    return true;
}


var ind=1;
var timeoutRet;

function startProgress()
{   
	document.getElementById('mask').style.width=document.body.clientWidth+document.body.scrollWidth+'px';
	document.getElementById('mask').style.height=document.body.clientHeight+document.body.scrollHeight+'px';
    document.getElementById('mask').style.display = 'block';
    document.getElementById('progress').style.display = 'block';
    document.getElementById('progressBarText').innerHTML = '<b><font color=#A00050>Upload in progress: '+ind+'%</font></b>';
    //wait a little while to make sure the upload has started ..
    timeoutRet=window.setInterval("refreshProgress()",1000);
    ind=ind+2;
    document.forms['upload'].submit();
    return true;
}

function startProgress1()
{   
    var tempu=document.getElementById('url').value;
    if(tempu==''){
      alert("Please enter the url.");
      return false;
    }
    document.getElementById('mask').style.width=document.body.clientWidth+document.body.scrollWidth+'px';
	document.getElementById('mask').style.height=document.body.clientHeight+document.body.scrollHeight+'px';
    //alert(document.getElementById('mask').style.height+" "+document.getElementById('mask').style.width);
	document.getElementById('mask').style.display = 'block';
    document.getElementById('progress').style.display = 'block';
    document.getElementById('progressBarText').innerHTML = '<b><font color=#A00050>Upload in progress: '+ind+'%</font></b>';
    //wait a little while to make sure the upload has started ..
    timeoutRet=window.setInterval("refreshProgress()",1000);
    ind=ind+2;
    document.forms['urlUpload'].submit();
    return true;
}