var xmlHttp_upload

function stateChanged_upload (){
    if (xmlHttp_upload.readyState == 4 || xmlHttp_upload.readyState == "complete") {
	document.getElementById ("upload_status").innerHTML = xmlHttp_upload.responseText;
    }
}

function GetXmlHttpObject_upload (){
    var xmlHttp_upload = null;
    
    try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp_upload = new XMLHttpRequest ();
    }

    catch (e) {
	//Internet Explorer
	try {
	    xmlHttp_upload = new ActiveXObject ("Msxml2.XMLHTTP");
	}
    
	catch (e) {
	    xmlHttp_upload = new ActiveXObject ("Microsoft.XMLHTTP");
	}
    }

    return xmlHttp_upload;
}



var UP = function() {
    var infoUpdated = 0;
    var upload_id = null;
    return {
        start: function() {
	   upload_id = document.getElementById("UPLOAD_IDENTIFIER").value;
    	   document.getElementById("upload_status").className = "upload_progressbar";
           infoUpdated = 0;
           this.requestInfo();
        },
        stop: function() {
	    infoUpdated = 1;
            startTime = null;
        },

        requestInfo: function() {
	   xmlHttp_upload = GetXmlHttpObject_upload ()
    	   if (xmlHttp_upload == null) {
		alert ("Browser does not support HTTP Request");
		return;
	    }
	    var url = "/ape/lib/upload_info.php?ID="+upload_id+"&st="+infoUpdated;
	    url = url + "&sid=" + Math.random ();
	    xmlHttp_upload.onreadystatechange = stateChanged_upload;
	    xmlHttp_upload.open ("GET", url, true);
	    xmlHttp_upload.send (null)
	    if (infoUpdated == 0) {
    		window.setTimeout("UP.requestInfo()",1000);
    	    } 
        },
        
        
    }

}()


