/* ------------------------------------------------------------------------- */
/*																			 */
/*					    		eyceks v1.3						 			 */
/*						eburhan [at] gmail [nokta] com						 */
/*				daha kolayını bulursanız bana da haber verin :)				 */
/*																			 */
/* ------------------------------------------------------------------------- */

function AJAX() {
   ajax = false;
   
   // Internet Explorer (5.0+)
   try {
     ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
   } catch (e) {
	   
      try {
        ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        ajax = false;
      }

   }

   // Mozilla veya Safari
   if ( !ajax && typeof XMLHttpRequest != 'undefined' ) {
	   
     try{
        ajax = new XMLHttpRequest();
		if (ajax.overrideMimeType) {
            ajax.overrideMimeType('text/xml');
         }
     }catch(e) {    
        ajax = false;
     }

   }

   // Diger (IceBrowser)
   if ( !ajax && window.createRequest ) {
     
	 try{
        ajax = window.createRequest();
     }catch(e) {  
        ajax = false;
     }

   }

	return ajax;
}

// POST işlemleri
function postXML(dosya, sc,doit_OK,doit_Loading,doit_Error) {
	ajax = new AJAX();
	
	if ( ajax ) {
		ajax.onreadystatechange = function () {}
		ajax.abort()
	}
	
	var ALoading = new Loading(doit_OK,doit_Loading,doit_Error)
	ALoading.ajax = ajax;
	ajax.onreadystatechange = function () {	ALoading.Load(); }
	ajax.open('POST', dosya, true)
	ajax.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8')
    ajax.setRequestHeader("Content-length", sc.length)
    ajax.setRequestHeader("Connection", "close")
	ajax.send(sc)		
	
	    

}



// POST işlemleri
function postText(dosya, sc,doit_OK,doit_Loading,doit_Error) {
	ajax = new AJAX();
	
	if ( ajax ) {
		ajax.onreadystatechange = function () {}
		ajax.abort()
	}

	var ALoading = new LoadingT(doit_OK,doit_Loading,doit_Error)
	ALoading.ajax = ajax;
	ajax.onreadystatechange = function () {	ALoading.Load(); }
	
	ajax.open('POST', dosya, true)
	ajax.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8')
    ajax.setRequestHeader("Content-length", sc.length)
    ajax.setRequestHeader("Connection", "close")
	ajax.send(sc)	
}

// GET işlemleri
function getXML(dosya, sc,doit_OK,doit_Loading,doit_Error) {
	ajax = new AJAX();
	if ( ajax ) {
		ajax.onreadystatechange = function () {};
		ajax.abort();
	}
	// son hazırlık
	if(sc) {
		dosya = dosya +'?'+ sc;
	}

	var ALoading = new Loading(doit_OK,doit_Loading,doit_Error)
	ALoading.ajax = ajax;
	ajax.onreadystatechange = function () {	ALoading.Load(); }

	ajax.open('GET', dosya, true);
	ajax.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	ajax.setRequestHeader("Connection", "close");
	ajax.send(null);	
}

// GET işlemleri
function getText(dosya, sc,doit_OK,doit_Loading,doit_Error) {
	ajax = new AJAX();
	if ( ajax ) {
		ajax.onreadystatechange = function () {};
		ajax.abort();
	}
	// son hazırlık
	if(sc) {
		dosya = dosya +'?'+ sc;
	}

	var ALoading = new LoadingT(doit_OK,doit_Loading,doit_Error)
	ALoading.ajax = ajax;
	ajax.onreadystatechange = function () {	ALoading.Load(); }

	ajax.open('GET', dosya, true);
	ajax.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	ajax.setRequestHeader("Connection", "close");
	ajax.send(null);	
}

// Yükleme işlemleri XML
function Loading(doit_OK,doit_Loading,doit_Error) {
	this.ajax = null;
	this.doit_OK=doit_OK;
	this.doit_Loading=doit_Loading;
	this.doit_Error=doit_Error;
}

Loading.prototype.Load = function() 
{
	
	if( this.ajax.readyState == 1 || this.ajax.readyState == 2 || this.ajax.readyState == 3 ) 
	{
		if (this.doit_Loading!=null)
		{
			this.doit_Loading("load");
		}
	}
	
	if( this.ajax.readyState == 4 ) {
		
		if (this.doit_Loading!=null)
			this.doit_Loading("unload");
		if (this.ajax.status == 200) {
			
			var xmldoc =  this.ajax.responseXML;
			// important line
			if (!xmldoc.documentElement && this.ajax.responseStream) 
			{
				xmldoc.load(this.ajax.responseStream);
			}
			this.doit_OK(xmldoc);
		} 
		else 
		{
			if (this.doit_Error!=null)
				this.doit_Error(this.ajax);
		}
		function AJAX() {};
	}
}

// Yükleme işlemleri TEXT
function LoadingT(doit_OK,doit_Loading,doit_Error) {
	this.ajax = null;
	this.doit_OK=doit_OK;
	this.doit_Loading=doit_Loading;
	this.doit_Error=doit_Error;
}

LoadingT.prototype.Load = function() {

	if( this.ajax.readyState == 1 || this.ajax.readyState == 2 || this.ajax.readyState == 3 ) 
	{
		if (this.doit_Loading!=null)
			this.doit_Loading("load");
	}
	
	if( this.ajax.readyState == 4 ) {
		
		if (this.doit_Loading!=null)
			this.doit_Loading("unload");
		if (this.ajax.status == 200) {
			var txtDoc =  this.ajax.responseText;
			// important line
			this.doit_OK(txtDoc);
        } 
		else 
		{
			if (this.doit_Error!=null)
	            this.doit_Error(ajax);
        }
		function AJAX() {};
    }
}

// Özel karakterleri zararsız hale dönüştür
// ( Fix Character )
function fc_(text) {
	var temp;
	
	temp = encodeURIComponent(text);
	
	return temp;
}