// JavaScript Document
// v.1.0 Belsis Belediye Bilgi Sistemleri Yazılım Ltd. Şti.
/*
 * 
 * @developer : Atilla Ilhan KARTAL
 * 
 * 
 */





function belsisAjaxObject(url,method,parameter,async,handler){
	this.xmlDoc = "";
	if(async!=null && async!=undefined){
		this.async =  async;	
	}
	else{
		this.async = true;
	}
	this.__belsisAjaxVersion = "1.0.0.0";
	this.url = null || url;
	this.submitMethod = null || method;
	this.parameter = null || parameter;
	this.handler = handler;
	return this;
}


belsisAjaxObject.prototype = {
	sendRequest:function(){
		if(this.url!=null && this.url!=undefined){
			if (window.XMLHttpRequest){
				this.xmlDoc = new XMLHttpRequest();
			}
			else {
				if (document.implementation && document.implementation.createDocument) {
					this.xmlDoc = document.implementation.createDocument("", "", null);
					this.xmlDoc.onload = new this.handleResponse(this);
					this.xmlDoc.load(this.url);
					return
				} else
					this.xmlDoc = new ActiveXObject("Microsoft.XMLHTTP")
			}
			if (this.async)
				this.xmlDoc.onreadystatechange = new this.handleResponse(this);
			this.xmlDoc.open(this.submitMethod, this.url, this.async);
			this.xmlDoc.setRequestHeader("User-Agent", "belsisAjax v"+ this.__belsisAjaxVersion +" ("+ navigator.userAgent + ")");
			if (this.submitMethod == "POST"){
				this.xmlDoc.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			}
			this.xmlDoc.setRequestHeader("X-Requested-With", "XMLHttpRequest");
			this.xmlDoc.send(this.parameter);
			//alert(this.async);
			if (!this.async)
				(new this.handleResponse(this))();
		}
		else{
			alert("Ajax Error : RequestURL Tanımsız");
		}
	},
	handleResponse:function(belsisObj){
		var wait = true;
		this.checkResponse = function(){
			if((belsisObj) && belsisObj.handler!=null){
				if ((!belsisObj.xmlDoc.readyState) || (belsisObj.xmlDoc.readyState == 4)) {
					if (!wait)
						return;
					wait = false;
					if (typeof(belsisObj.handler) == "function"){
						belsisObj.handler(belsisObj.xmlDoc);
					}
				} else {  document.getElementById('haberContent').innerHTML = "<div style='text-align:center;'>Yükleniyor...<br/><img src='images/loading.gif' style='border:0px;'></div>"; }
			}
		}
		return this.checkResponse;
	}
}
	
	
belsisAjax={
		post:function(url,parameter,async,handler){
			var rq = new belsisAjaxObject(url,"POST",parameter,async,handler);
			rq.sendRequest();
			return rq;
		},
		get:function(url,parameter,async,handler){
			var rq = new belsisAjaxObject(url+"?" + parameter ,"GET",null,async,handler);
			rq.sendRequest();
			return rq;
		}	
}

