var ajaxObjects = new Array();
var isIE = false;

function ajax(){
	this.xmlhttp;
	this.formElement;
	this.requestFile;
	this.URLString;
	this.innerDivID;
	this.method 		= 'GET';
	this.responseType 	= 'Text'; /*Text , XML*/
	this.loadingType 	= 0;
	this.async 			= true;
	this.onCompletion 	= function() { };
	this.onProcess 		= function() { };
	this.loading 		= function(v){
		var v;
		if(this.loadingType>0){
			if(this.loadingType==1){
				if(!getID("loading")) {this.createLoaddingDiv();}
			}
			if(v==1){
				if(this.loadingType==1){ getID("loading").style.visibility = "visible";}
			}else{
				if(this.loadingType==1){ getID("loading").style.visibility = "hidden";}
			}
		}
	}
	
	this.ConnXmlHttp = function(){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				isIE = true;
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				xmlhttp = false;
			}
		}
	
		if(!xmlhttp && document.createElement){
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}
	
	this.getRequestBody = function(myForm) {
		var aParams = new Array();  
			for (var i=0 ; i < myForm.elements.length; i++) {
				
				var formElement = myForm.elements[i];
				if(formElement.type=='checkbox' && !formElement.checked){ continue;} 
            	var sParam = encodeURIComponent(myForm.elements[i].name);
               	sParam += "=";
               	sParam += encodeURIComponent(myForm.elements[i].value);
               	aParams.push(sParam);
           	}     
           	return aParams.join("&");        
	}
	
	this.loadXMLDoc = function() {
	
		var self = this;
		this.xmlhttp = this.ConnXmlHttp();

		
		if (this.method == "GET") {
			this.xmlhttp.open(this.method, this.requestFile, this.async);
		}else{
			this.URLString = this.getRequestBody(this.formElement);
			this.xmlhttp.open(this.method,this.requestFile, this.async);
		}
		if (this.method == "POST"){
  			try {
				this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')  
			} catch (e) {}
		}
		this.xmlhttp.onreadystatechange = function(){
			if(self.xmlhttp.readyState==4){
				if(self.loadingType==1){ self.loading(0);}
				if (self.xmlhttp.status == 200) {
					if(self.responseType == "Text"){
						self.response = self.xmlhttp.responseText;
					}else{
						self.response = self.xmlhttp.responseXML;
					}	
					
					self.onCompletion();
				}
			}else{
				if(self.loadingType==1){ self.loading(1);}
				if(self.loadingType==2){ 
					self.response = " <img src=images/load.gif width=16 height=16> ";
					self.onCompletion();
				}
			}
		}
		this.xmlhttp.send(this.URLString);
	}
	
	/*
	* Show Loading
	*/
	
	this.createLoaddingDiv = function(){
	
		var connLoading = document.createElement("DIV")
			connLoading.id = "loading";
			connLoading.style.position="absolute";
			connLoading.style.left="0px";
			connLoading.style.top="0px";
			connLoading.style.width="185px";
			connLoading.style.height="15px";
			connLoading.style.zIndex=99999;
			connLoading.style.backgroundColor="#FF0000";
			connLoading.style.visibility = "visible";
			connLoading.style.font = '11px Lucida Sans Unicode';
			connLoading.style.filter = 'alpha(opacity=60)';
			connLoading.innerHTML = "<strong><font color=\"#FFFFFF\">&nbsp;working on your request...</font></strong>";
		document.body.appendChild(connLoading);
		
	}
}
function getID(namex){
	if (document.getElementById){
			return document.getElementById(namex);
	}else if (document.all){
			return document.all[namex];
	}else{return null;}
}
	function getData(index,requestFile,URLString,innerDivID,loadtype){   
		   
		var index; var requestFile; var URLString; var innerDivID;   
		ajaxObjects[index] = new ajax();   
		ajaxObjects[index].method="GET";   
		ajaxObjects[index].requestFile=requestFile;   
		ajaxObjects[index].URLString=URLString;   
		ajaxObjects[index].loadingType =loadtype; 
		ajaxObjects[index].innerDivID=innerDivID;   
		ajaxObjects[index].onCompletion = function(){ showData(index,innerDivID); };   
		ajaxObjects[index].loadXMLDoc();   
	}   
	function showData(index,innerDivID){       
		   
		getID(innerDivID).innerHTML = ajaxObjects[index].response;   
	} 
	function getMenu(index,File,param,showDIV,type){
		getData(index,File + param,'',showDIV,type);
	}
