var xmlHttp;

var timeout;

var progress = false;

var progressTimer = null;

ajax = {	

	
	 getObject : function(){

		var xml;
		
		try
  			{  
			// Firefox, Opera 8.0+, Safari  
			xml=new XMLHttpRequest();  
			}
			catch (e)
  			{  
			// Internet Explorer  
			try
    			{    
				 xml=new ActiveXObject("Msxml2.XMLHTTP");    
				 }
  			catch (e)
    			{    
				try
      			{      
				xml=new ActiveXObject("Microsoft.XMLHTTP");      
				}
    		catch (e)
      			{      
				  alert("Your browser does not support AJAX!");      
				  return false;      
				  }    
				}  
				}    
		
			return xml;
	}
	,
	getContent : function(url,params,divid){
		
				
		xmlHttp = ajax.getObject();
		
		
		
		xmlHttp.open("POST",url,true);
		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		
		xmlHttp.onreadystatechange=function(){
			
			window.status = xmlHttp.readyState;
			
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
			 	
			 	ajax.endProgress();
				clearTimeout(timeout);
				document.getElementById(divid).innerHTML=xmlHttp.responseText;
				xmlHttp = null;
			}
			
		}
		
		ajax.startProgress();
		xmlHttp.send(params);	
		timeout = setTimeout("ajax.AjaxAbort()", 20000);
	}
	,
	addEntry : function(url,params){
		
		xmlHttp = ajax.getObject();
		
		
		
		xmlHttp.open("POST",url,true);
		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		
		xmlHttp.onreadystatechange=function(){
			
			window.status = xmlHttp.readyState;
			
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
			 	
			 	//ajax.endProgress();
				clearTimeout(timeout);
				xmlHttp = null;
			}
			
		}
		
		//ajax.startProgress();
		xmlHttp.send(params);	
		timeout = setTimeout("ajax.AjaxAbort()", 20000);
		
		
	}
	,
	AjaxAbort : function() {
	 	ajax.endProgress();
   		xmlHttp.abort();
   		xmlHttp = null;
   		alert("AJAX request failed.\r\n\r\nTimeout. Server did not respond to request.");
	}
	,	
	//use for input text onkeydown
	SearchTextEntered : function (e,button_name)
	 {
	  var charCode;
	  var button = document.getElementById(button_name);
	        
	        if(e && e.which){ 
	            e = e;
	            charCode = e.which; //if which property of event object is supported (netscape)
	        }
	        else{
	            e = event
	            charCode = e.keyCode; //character code is contained in IE's keyCode property
	        }
	 
	        if(charCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
	            button.focus();
	            button.click(); //click search button
	        }
	 
	 }
	 ,
	 //Progress Meter
	 startProgress : function(){
		
		progress = true;
		
		if(progressTimer != null)
			window.clearTimeout(progressTimer);
		progressTimer = setTimeout(ajax.showProgress, 20);
		
	}
	,
	endProgress : function(){
		
		progress = false;
		if(progressTimer != null)
			window.clearTimeout(progressTimer);	
		progressTimer = setTimeout(ajax.showProgress, 20);
	}
	,
	showProgress : function(){
		progressTimer = null;
		var a = document.getElementById("AjaxProgressIndicator");
		
		if(progress && (a!=null)){
			//just display the existing object
			a.style.top = "390px";
		    a.style.display = "";
		}else if(progress){
			
			// create new standard progress object
		    a = document.createElement("div");
		    a.id = "AjaxProgressIndicator";
		    a.style.position = "absolute";
		    a.style.left = "200px";
		    a.style.top = "390px";
		    a.style.width = "98px";
		    a.style.height = "70px"
		    a.style.padding = "2px";
		    a.style.verticalAlign = "bottom";
		    a.style.backgroundColor="#FFF";
		
		    a.innerHTML = "<img style='VERTICAL-ALIGN:bottom' src='http://192.168.1.11/bluewave/supply/images/ajax-loader.gif'> please wait...";
		    document.body.appendChild(a);
			
		}else if (a) {
		
		    a.style.display = "none";
		
		}
		
		
	}
	 
	 
}