function ajaxRequest(url) 
{
	//document.getElementById('loading').style.display='block';

	var http_request = false; 
   if (window.XMLHttpRequest) 
   { // Mozilla, Safari,... 
       http_request = new XMLHttpRequest(); 
       if (http_request.overrideMimeType) 
           http_request.overrideMimeType('text/xml'); 
   } 
   else if (window.ActiveXObject) 
   { // IE 
       try 
	   { 
           http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
       } 
	   catch (e) 
	   { 
           try 
		   { 
               http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
           } 
		   catch (e) 
		   {} 
       } 
   } 

   if (!http_request) 
   { 
       alert('Unfortunatelly you browser doesn\'t support this feature.'); 
       return false; 
   } 

   http_request.onreadystatechange = function() { 
	   if (http_request.readyState == 4) 
	   { 
		   if (http_request.status == 200) 
		   		updateScreen(http_request.responseText)
		   else 
			   alert('There was a problem with the request.(Code: ' + http_request.status + ')'); 
	   } 
   }
   
   http_request.open('GET', url, true); 
   http_request.send(null); 
}

var aRecord;
function updateScreen(sData)
{
	aRecord = sData.split('[row]');
	//document.getElementById('loading').style.display='none';
	setTimeout(aRecord[0],1);
}





var zzAjax = 0;
function Ajax(destID, url, showLoading, sendResultToCallbackOnly, parameters) 
{                                    // This is the object constructor
   var that=this;                                                    // A workaround for some javascript idiosyncrocies
   var updating = false;                                             // Set to true if this object is already working on a request
   this.callback = function() {}                                     // A post-processing call -- a stub you overwrite.

   this.update = function(passData) {                                // Initiates the server call.
      if (updating==true) { return false; }                          // Abort if we're already processing a call.
      updating=true;  // Set the updating flag.
	  
	  if (bShowLoadingAnimation)
	  {
		  objMove('dataLoading',{move:cMOVEREL,objID:'fieldData',offset:cRELTOPLEFT,offsetLeft:0,offsetTop:0});
		  document.getElementById('dataLoading').style.display='block';
	  }
	  var AJAX = null;                                               // Initialize the AJAX variable.
      if (window.XMLHttpRequest) {                                   // Are we working with mozilla?
         AJAX=new XMLHttpRequest();                                  //  Yes -- this is mozilla.
      } else {                                                       // Not Mozilla, must be IE
         AJAX=new ActiveXObject("Microsoft.XMLHTTP");                //  Wheee, ActiveX, how do we format c: again?
      }                                                              // End setup Ajax.
      if (AJAX==null) {                                              // If we couldn't initialize Ajax...
         alert("Your browser doesn't support AJAX.");                // Sorry msg.						
         return false                                                // Return false (WARNING - SAME AS ALREADY PROCESSING!)
      } else {
         AJAX.onreadystatechange = function() {                      // When the browser has the request info..
            if (AJAX.readyState==4 || AJAX.readyState=="complete")   //   see if the complete flag is set.
			{
				if (AJAX.responseText == 'TIMEOUT')
				{
					AJAXTimeout();
				}
				else
				{
					if (destination!=null)
					{
						if (!bSendResultToCallbackOnly)
						{
							if (destination!=null)
								destination.innerHTML=AJAX.responseText;                  //   It is, so put the new data in the object's layer
							
						}
						if (bShowLoadingAnimation)
							  document.getElementById('dataLoading').style.display='none';
					}
				   that.callback(AJAX.responseText);  
				}
               delete AJAX;                                          //   delete the AJAX object since it's done.
               updating=false;                                       //   Set the updating flag to false so we can do a new                                                                     // End Ajax readystate check.
		 	}
         }                                                           // End create post-process fucntion block.
         var timestamp = new Date();                                 // Get a new date (this will make the url unique)
         var uri=urlCall+'?';
		 
		 if (typeof(passData)!='undefined')
		 	uri += passData+'&'
		 uri += 'tamp='+(timestamp*1);   // Append date to url (so the browser doesn't cache the call)

		 AJAX.open("GET", uri, true);                                // Open the url this object was set-up with.
         AJAX.send(null);                                            // Send the request.
         return true;                                                // Everything went a-ok.
      }                                                              // End Ajax setup aok if/else block                 
   }
      
   // This area set up on constructor calls.
   var bShowLoadingAnimation = showLoading;
   var bSendResultToCallbackOnly = sendResultToCallbackOnly;
   
   var destination = null;
   if (destID!='')
	destination = document.getElementById(destID);
	
   var urlCall = url;	// Remember the url associated with this object.
   if (typeof(parameters)!='undefined')
	   this.update(parameters);
}                                                                    // End AjaxObject

function AJAXTimeout()
{
	window.location = 'http://dell/multiyearv2/logout.asp';
}

var nAjaxCalls = 0;
function DataDownload(study,tabID,url,numRows,totalRows,fixedWidth,otherWidth,rowHeight,callbackEachChunk,callbackWhenDone)
{
	//console.time('TotalTime');
	
	this.study = study;
	this.tabID = tabID;
	this.url = url;
	this.callbackEachChunk = callbackEachChunk;
	this.callbackWhenDone = callbackWhenDone;
	this.fixedWidth = fixedWidth;
	this.otherWidth = otherWidth;
	this.rowHeight = rowHeight;

	var key = this.study+this.tabID;
	var nPosition = 0;
	var nNumRows = numRows;
	var nTotalRows = totalRows;
	var nChunkSize = 50;
	data.searching.status[key].dataDownloads = this;
	
	var bAbort = false;
	
	this.stopDownloading = function() {
		bAbort = true;
	}
	this.changeChunkSizeTo = function(newSize) {
		nChunkSize = newSize;
		}
	
	this.nextChunk = function(firstTime) {
		if (!bAbort)
		{
/*			if (!firstTime)
			{
				var aData = frames['iframeBox'].document.body.innerHTML;
				callbackEachChunk(key,0,0,nNumRows,aData);
				
				nPosition += nChunkSize;
				if (nPosition<nNumRows)				
					fetchPageIFrame(key,'',this.url,'study='+this.study+'&tabID='+this.tabID+'&position='+nPosition	+'&size='+nChunkSize+'&fixedWidth='+this.fixedWidth+'&otherWidth='+this.otherWidth+'&rowHeight='+this.rowHeight)				
				else
					callbackWhenDone(key,nNumRows,nTotalRows);
				
			}
			else
				fetchPageIFrame(key,'',this.url,'study='+this.study+'&tabID='+this.tabID+'&position='+nPosition	+'&size='+nChunkSize+'&fixedWidth='+this.fixedWidth+'&otherWidth='+this.otherWidth+'&rowHeight='+this.rowHeight);
*/			

			
			var oGetResults = new Ajax('',this.url,false,true);
			oGetResults.callback = function(result)
			{
				if (!bAbort)
				{
					var v = nPosition+nChunkSize;
					if (v>nNumRows)
						v = nNumRows;
					var percent = (v/nNumRows)*100;
					
					fn.timing.stopTiming('AjaxCall'+nAjaxCalls);
					
					callbackEachChunk(key,v,percent,nNumRows,result);
					nPosition += nChunkSize;
					nChunkSize = 500;
					if (nPosition<nNumRows)
						setTimeout('data.searching.status[\''+key+'\'].dataDownloads.nextChunk()',1);
					else 
						callbackWhenDone(key,nNumRows,nTotalRows);
				}
				else
					callbackWhenDone(key,nNumRows,nTotalRows);
			}
			nAjaxCalls++;
			fn.timing.startTiming('AjaxCall'+nAjaxCalls);	
			oGetResults.update('study='+this.study+'&tabID='+this.tabID+'&position='+nPosition+'&size='+nChunkSize+'&fixedWidth='+this.fixedWidth+'&otherWidth='+this.otherWidth+'&rowHeight='+this.rowHeight);
			
		}
		else
			callbackWhenDone(key,nNumRows,nTotalRows);

	}
	
	this.nextChunk(true);
}
function fetchPage(destinationID,page,params,fn)
{
	var oAjax = new Ajax(destinationID,page,false,false);
	if (fn)
		oAjax.callback = fn;
	oAjax.update(params);
	return oAjax;
}

function fetchPageIFrame(downloadKey,destinationID,page,params,fn)
{
	document.getElementById('iframeBox').src = page+'?key='+downloadKey+'&'+params;
}
function processDownload(key)
{
	dataDownloads[key].nextChunk(false);
}