﻿   var Timer = function()
	{		
		// Property: Frequency of elapse event of the timer in millisecond
		this.Interval = 3000;
		
		// Property: Whether the timer is enable or not
		this.Enable = new Boolean(false);
		
		// Event: Timer tick
		this.Tick;
		
		// Member variable: Hold interval id of the timer
		var timerId = 0;
		
		// Member variable: Hold instance of this class
		var thisObject;
		
		// Function: Start the timer
		this.Start = function()
		{
			this.Enable = new Boolean(true);
	
			thisObject = this;
			if (thisObject.Enable)
			{
				thisObject.timerId = setInterval(
				function()
				{
					thisObject.Tick(); 
				}, thisObject.Interval);
			}
		};
		
		// Function: Stops the timer
		this.Stop = function()
		{			
			thisObject.Enable = new Boolean(false);
			clearInterval(thisObject.timerId);
		};
	
	};
	

	function timer_tick()
	{
		CallProcess();
		if (index == 100) 
		{
			obj.Stop();
		}
	}
   
   var cInfo = "0";
   var cInfoAdd = "0";
   
   function CallProcess() {
      http_request = false;
      var d = new Date()
      var tmp = d.getTime();

      var url = "CreateProcess.aspx?dt="+tmp+"&id=" + npid + "&cinfo=" + cInfo + "&cinfoadd=" + cInfoAdd; 
      if (window.XMLHttpRequest) 
      {
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) 
         {
            http_request.overrideMimeType('text/html');
         }
      } 
      else if (window.ActiveXObject) 
      {
         try 
         {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } 
         catch (e) 
         {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
//         alert('Error');
         return false;
      }
      http_request.onreadystatechange = ReadyProcess;
      http_request.open('GET', url, true);
      http_request.send(null);
   }
   function ReadyProcess() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) { 
              PrintProcess(http_request.responseText);
         } 
//         else {
//            alert('An error has occured');
//         }
      }
   }
   function PrintProcess(value)
   {
       var c_array=value.split("|");
       cInfo = c_array[0];
       cInfoAdd = c_array[1];
       
       var vSetContent = document.getElementById("dSetContent");
       var vSetContentText = document.getElementById("dSetContentText");
       
       if(cInfo == "error")
       {
            vSetContent.style.backgroundImage = "url(../../core/graphics/progressbar/error.gif)"; 
            vSetContent.style.display = "block";
            vSetContent.style.width = "100%";
            vSetContent.innerHTML = liErrorCreating;
            vSetContentText.innerHTML = "N/A";
       }
       else if (cInfo == "inline")
       {
            vSetContent.style.display = "none";
            vSetContentText.innerHTML = liCurrentStatusLine + cInfoAdd;
       }
       else if (cInfo == "finished")
       {
            vSetContent.style.backgroundImage = "url(../../core/graphics/progressbar/clear.gif)"; 
            vSetContent.style.display = "block";
            vSetContent.style.width = "100%";
            vSetContent.innerHTML = liReadyMessage;
            index = 100;
            vSetContentText.innerHTML = liCurrentStatusDone;
            
            if(cInfoAdd != "0")
            {
                window.location = cInfoAdd;
            }
       }
       else
       {
            vSetContent.style.display = "block";
            vSetContent.style.width = cInfoAdd + "%";
            vSetContentText.innerHTML = liCurrentStatusProcessing + cInfoAdd + "%";
       }
       
   } 
