// XML
// ---------------------------------------------
function XML(hedef){
	var xml = {

		// Islem
		islem : function(){
			return true;
		},

		// Getir
		getir : function(){
			return this.xml;
		},

		// Yukle
		yukle : function(yukle){
			this.xml = new _xml(this);
			this.xml.load(yukle);
		},

		// Yarat
		yarat : function(metin){
			this.xml = new _xml(this);
			this.xml.loadXML(metin);
		},

		// Donustur
		donustur : function(xsl){
			return this.xml.transformNode(xsl);
		}
	}

	// Yukle ...
	if(hedef) xml.yukle(hedef);
	return xml;
}

// XHR
// ---------------------------------------------
function XHR(hedef,snc){
	var snc = typeof(snc) == 'undefined' ? true : snc;
	var xhr = {

		// Islem
		islem : function(){
			return true;
		},

		// Baglan
		baglan : function(hedef,snc){
			this.snc = snc;
			this.xhr = new _xhr(this);
			this.xhr.open('POST',hedef,true);
			this.xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
		},

		// Talep
		talep : function(talep){
			if(this.snc) sayfa.durum.yenile(false);
			this.xhr.send(talep+'&zmn='+new Date().getTime());
		},

		// Deger
		deger : function(deger){
			var sonuc = /<script>(.*?)<\/script>/.exec(deger);
			if(sonuc){
				eval(sonuc[1]);
			}
		},

		// Cevap
		cevap : function(xsl,xml){
			var xml,rst;
			if(xsl){
				xml = new XML();
				xml.yarat(this.xhr.responseText);
				rst = xml.donustur(xsl);
			}
			else{
				if(xml){
					if(window.ActiveXObject) rst = this.xhr.responseXML;
					else{
						xml = new XML();
						xml.yarat(this.xhr.responseText);
						rst = xml.getir();
					}
				}
				else rst = this.xhr.responseText;
			}
			return rst;
		}
	}

	// Baglan ...
	if(hedef) xhr.baglan(hedef,snc);
	return xhr;
}

// XIR
// ---------------------------------------------
function XIR(isim,snc){
	var snc = typeof(snc) == 'undefined' ? true : snc;
	var xir = {
		
		// Basla
		basla  : function(isim){
			xir.snc   = snc;
			xir.no    = new Date().getTime();
			xir.mform = Form(isim);
		},
		
		// Talep
		talep  : function(talep){
			if(xir.snc) sayfa.durum.yenile(false);
			xir._talep = talep+'&zmn='+new Date().getTime();			
			xir.gonder();
		},
		
		// Sonuc
		sonuc  : function(sonuc){
			if(xir.snc) sayfa.durum.yenile(true);
			xir.islem(sonuc);
			delete _xir_[xir.no];
		},
		
		// Islem
		islem  : function(sonuc){
			
		},
		
		// Gonder
		gonder : function(){
			xir.mform.hedef('xir');
			xir.mform.gonder('?'+xir._talep+'&xir='+xir.no);
		}
	}
	
	// Cikart
	if(isim){
		xir.basla(isim,snc);
		_xir_[xir.no] = xir;
	}
	return _xir_[xir.no];
}

// XML - Temel
// ---------------------------------------------
function _xml(nesne){
	var xml;

	if(window.ActiveXObject){
		xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = true;
		xml.onreadystatechange = function(){
			if(xml.readyState == 4) nesne.islem();
		};
	}
	else if(document.implementation && document.implementation.createDocument){
		xml = document.implementation.createDocument('','',null);
		xml.onload = function(){
			nesne.islem();
		}
	}

	return xml;
}

// XHR - Temel
// ---------------------------------------------
function _xhr(nesne){
	var xhr;

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
		try{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(e){ xhr = false; }
	}
	@else xhr=false; @end @*/

	if(!xhr && typeof XMLHttpRequest != 'undefined'){
		try{ xhr = new XMLHttpRequest(); }
		catch (e){ xhr = false; }
	}

	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			if(nesne.snc) sayfa.durum.yenile(true);
			nesne.islem();
		}
	};

	return xhr;
}

// Mozilla Firefox icin ...
// ---------------------------------------------

// LoadXML
if(typeof DOMParser != 'undefined'){
	Document.prototype.loadXML = function(metin){
		var _doc = (new DOMParser()).parseFromString(metin,'text/xml');

		while(this.hasChildNodes()){
			this.removeChild(this.lastChild);
		}

		for(var i = 0; i < _doc.childNodes.length; i++) {
			this.appendChild(this.importNode(_doc.childNodes[i], true));
		}
	};
}

// transformNode
if(typeof XSLTProcessor != 'undefined'){
	Document.prototype.transformNode = function(xsl){
		var xtp, _doc;
		xtp = new XSLTProcessor();
		xtp.importStylesheet(xsl);

		_doc = xtp.transformToDocument(this);
		return _doc.xml;
	};
}

// xml
if(typeof XMLSerializer != 'undefined'){
	Document.prototype.__defineGetter__('xml', function(){
		return (new XMLSerializer()).serializeToString(this);
	});
}