function Ajax(){
	this.encType 		= 'text';
	this.method			= 'GET';
	this.url 			= null;
	this.responseText	= null;
	this.responseXML	= null;
	this.status			= null;
	this.mimeType		= null;
	this.readyState		= null;
	this.postData		= null;
	this.req			= null;	//Ajax XHTML object
	this.responseFormat = 'text';
	this.errorDivId		= '';
	this.outputDivId	= '';
	this.formId			= '';
	this.init = function(){
		if (!this.req){
			try {
				this.req = new XMLHttpRequest();
			}
			catch(e){
				try{
					this.req = new ActiveXObject('Msxml2.XMLHTTP');
				}
				catch(e){
					try{
						this.req = new ActiveXObject('Microsoft.XMLHTTP');
					}
					catch(e){
						return false;
					}
				}
			}
		}
		return this.req;
	};
	this.doReq = function(objForm){
		if(!this.init()){
			this.handleErr('Could not use ajax');		
			return;
		}
		if (typeof(objForm)=='object'){
			this.formId = objForm.id;
			this.method = objForm.method.toUpperCase();
			this.url 	= objForm.action;
			if(this.method == 'GET'){
				this.url += '?' + this.procForm(objForm);
			}
			this.req.open(this.method, this.url, true);
			if(this.method=='POST'){
				this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
				this.postData = this.procForm(objForm);
			}
		}else{
			this.method = 'GET';
			this.url = objForm + '?ajax=ajax';
			this.req.open(this.method, this.url, true);
		}	
		
		if (this.mimeType){
			try{
				req.overrideMimeType(this.mimeType);
			}
			catch(e){
				// error when overriding mime type
			}
		}
		var self = this;
		this.req.onreadystatechange = function() {
			var resp = null;
			if (self.req.readyState == 4){
				switch (self.responseFormat){
					case 'text':
						resp = self.req.responseText;
						break;
					case 'xml':
						resp = self.req.responseXML;
						break;
					case 'object':									
						resp = req;
						break;
				}
				if (self.req.status >= 200 && self.req.status <= 299){
					self.handleResp(resp);
				}else{
					self.handleErr(resp);
				}
				if(checkForms){
					checkForms.stopAnim(self.formId);
				}
			}
		};
		this.req.send(this.postData);
	};
	this.handleErr = function(strInput){
		strInput = "<br />Status Code: " + this.req.status + "<br />Error message: " + this.req.statusText + "<br />" + strInput;
		if(this.errorDivId != ''){
			document.getElementById(this.errorDivId).innerHTML = strInput;
		}else{
			if (strInput.length > 90){
				strInput = strInput.substring(0,90);
			}
			alert(strInput.replace(/<br \/>/g,'\r\n'));
		}
	};
	this.handleResp = function(strInput){
		if(typeof document.getElementById(this.outputDivId) == 'object' && this.outputDivId != ''){
			document.getElementById(this.outputDivId).innerHTML = strInput;
		}else{
			alert(strInput.replace(/<br \/>/g,'\r\n'));
		}
	};
	this.doAjax = function(objForm,outputDiv,errorDiv){
		this.outputDivId	= outputDiv || '';
		this.errorDivId		= errorDiv 	|| outputDiv || '';
		this.doReq(objForm);
	};
	this.abort = function(){
		if (this.req) {
			this.req.onreadystatechange = function(){};
			this.req.abort();
			this.req = null;
		}
	};
	this.procForm = function(objForm){
  		var strResult = "";
  		for(i=0; i < objForm.elements.length; i++){
			if(objForm.elements[i].type != "button" && objForm.elements[i].type != 'submit' && objForm.elements[i].type != 'reset'){
				switch(objForm.elements[i].type){
					case 'text':
            		case 'hidden':
            		case 'password':
            		case 'textarea':
            		case 'select-one':
						strResult += objForm.elements[i].name;
      					strResult += "=" + escape(objForm.elements[i].value)+'&';
						break;
					case 'radio':
						if (objForm.elements[i].checked){
							strResult += objForm.elements[i].name;
      						strResult += "=" + escape(objForm.elements[i].value)+'&';
						}
						break;
					case 'checkbox':
						if (objForm.elements[i].checked){
							strResult += objForm.elements[i].name;
      						strResult += "=" + escape(objForm.elements[i].value)+'&';
						}
						break;
				}
			}
      	}
	strResult += 'ajax=ajax'; 
  	return strResult;
	};
}
a_links = new Ajax;