// JavaScript Document
var loading=false; 

var ajax=function (tid,p) {
		this.request=null;
		this.parameters=new Array();
		this.displayid=tid;
		this.page=p;
		this.method="POST";
		this.loader="LOADING ...";
		this.loaderid="";
		this.finalfunction="";
		
		this.ajaxCreate=function() {
		  var xmlhttp = null;
		  try {
			xmlhttp = new XMLHttpRequest();
		  } catch(e) {
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		  }
		  return xmlhttp;
		}
		
		this.getAjaxParameter=function(key) {
			return this.parameters[key];
		}
		
		this.setFinalFunction=function(functiontxt) {
			this.finalfunction=functiontxt;
		}
		
		this.setAjaxParameter=function(key, value) {
			if (loading==false) {
				value=encodeURI(value);
				this.parameters[key]=value;
			}
		}
		
		this.setAjaxMethod=function(par) {
			if (loading==false) {
				this.method=par;
			}
		}
		
		this.setLoader=function(loader,l_id) {
			if (loading==false) {
				this.loader=loader;
				
				if (l_id!=""){
				this.loaderid=l_id;
				}
			}
		}
		
		this.startAjaxConnection=function(pg,finalf) {
	           
			if (loading==false) {
				var stringParam="";
				
				for (var i in this.parameters) {
					if (typeof(this.parameters[i]) != "function") {
						stringParam += i + "=" + this.parameters[i] + "&";
					}
				}
				
				loading=true;
				if (this.loaderid!="")
				{
				 document.getElementById(this.loaderid).innerHTML= "";
				 document.getElementById(this.loaderid).innerHTML=this.loader;
				}
				request=this.ajaxCreate();
				request.onreadystatechange = function() {
				    if (request.readyState == 4  && request.status==200) { 
				        finalf(request.responseText);
				        loading=false;
				    }
				};
				
				 if (this.loaderid!="" && loading==false){
				 document.getElementById(this.loaderid).innerHTML="";}
				 
				if (this.method=="GET") {
					request.open(this.method,pg+"?"+stringParam,true);
				} else {
					request.open(this.method,pg,true);
				}
				request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				request.setRequestHeader("Content-length", this.parameters.length);
				request.setRequestHeader("Connection", "close");
				if (this.method=="POST") {
					request.send(stringParam);
				} else {
					request.send(null);
				}
				//this.parameters=null;
			}
		}
	
	}