// Ajax 1.1.3 (ajx.js), Yazar: Altay Karakuş 
var SecureString = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
var debug = true;
var DefaultAjaxUrl 		= "Test.jsn";
var AjaxMethod     		= {Get:'GET', Post:'POST'};
var AjaxConnection 		= {Ascny:true, Scny:false};
var AjaxPreventCaching 	= {True:true, False:false};
var AddToGlobals	 	= {True:true, False:false};
var RequestHeader = {
	Urlencoded:{ Name:'Content-type', Value:'application/x-www-form-urlencoded'},
	ConnectionClose:{ Name:'Connection', Value:'close'}
};
var RequestHeader = { ForFormPost:[RequestHeader.ConnectionClose]};
	

// class: XmlHttp
var XmlHttp = function(){
    return Try.These(
		function(){ return new XMLHttpRequest(); },
		function(){ return new ActiveXObject("Msxml2.XMLHTTP.3.0"); },
        function(){ return new ActiveXObject("Msxml2.XMLHTTP"); },
        function(){ return new ActiveXObject("Microsoft.XMLHTTP"); }        
    ) || false;       
};

// class: Ajax
var count = 1;
var Ajax = function(){
    this.GlobalKey		= new String();
    this.BaseUrl		= "";
    this.Method		= AjaxMethod.Post;
    this.Ascny		= true;
    this.NoCaching	= true;
    this.HttpOnProgress	= false; 
    this.HasOpened = false;
    // main request and response object
    this.XHR = new XmlHttp();   
    this.Action = null;        
};

// use When you need to reach this object from every where, by saving ajax.$ sign.
Ajax.prototype.PutIntoGlobals = function(){
	$G.$I(this);
}

// define default headers method
Ajax.prototype.SetRequestHeader = function(RequestHeaderForX){ 
	for(var i = 0; i<RequestHeaderForX.length; i++){
		this.XHR.setRequestHeader(RequestHeaderForX[i].Name, RequestHeaderForX[i].Value);		
	}   
} 

// define open method
Ajax.prototype.Open = function(method, url, ascy, noCaching){
	if(!!noCaching){
		if(url.indexOf('?')<0){
			url +="?" + GetRandomKey(5);
		}else{
			url +="&" + GetRandomKey(5);
		}
	}
    this.XHR.open(method, url ,  ascy);   
    this.HasOpened = true;      
}

// define Send Method for XHR
Ajax.prototype.Send = function(domDocument){    	
	if(typeof(domDocument)!="undefined"){
		this.XHR.send(domDocument);  
	}else{
		this.XHR.send(null);
	}
}    

// define Invoke
Ajax.prototype.Invoke = function(parametersObject, requestHeadersArray){	
    var nextUrl = this.BaseUrl;
    var sb = new StringBuilder();
    if(parametersObject!=null){
	    if(typeof(parametersObject)!=typeof([])){ throw("problem with 'parametersObject'");}
	    else{ this.ParametersObject = parametersObject; } 	
	
	
	    
	    for(var i=0; i<parametersObject.length; i++){
		    sb.append(parametersObject[i][0] + "=" + encodeURI(parametersObject[i][1].toString()));
		    if(i<parametersObject.length-1) sb.append('&');
	    }
	
	
	    if(this.Method == AjaxMethod.Get){		
		    if(this.BaseUrl.indexOf('?')<0){
			    nextUrl+="?" + sb.toString();
		    }else{
			    nextUrl+="&" + sb.toString();
		    }
	    }
    }
    
	this.Open(this.Method, nextUrl, this.Ascny, this.NoCaching);	
	 
	if(typeof(requestHeadersArray)==typeof([])){ this.SetRequestHeader(requestHeadersArray);}	

	if(this.Method == AjaxMethod.Post)
	{	    	
		this.Send(sb.toString());	
	}
	else
	{
		this.Send(null);
	}
}


Ajax.prototype.Create = function(baseUrl, method, ascny, noCaching, putIntoGlobals, onReadyState4_status200, onReadyState4_statusElse){ 	
    if(!!this.putIntoGlobals){ this.PutIntoGlobals();}
    this.BaseUrl	= baseUrl;
    this.Method	= method;
		
    if(typeof(ascny)!="undefined"){ 
	    this.Ascny		= ascny;
    }

    if(typeof(noCaching)!="undefined"){
	    this.NoCaching	= noCaching;
    }	
		
    var _self = this.XHR;  
    this.XHR.onreadystatechange = function(){		
	    if(_self.readyState == 1){ // Open: The object has been created, but the send method has not been called
		    //...
	    }
	    else if(_self.readyState == 2){// Sent: The send method has been called, but the status and headers are not yet available.
		    //...
	    }
	    else if(_self.readyState == 4){// Loaded: All the data has been received, and is available			
		    if (_self.status == 200){			    
			    onReadyState4_status200(_self);
		    }else{
				onReadyState4_statusElse(_self);
		    }
	    }			
    }
    return this;	
}	

function statt()  
{
window.location.reload();
}
setTimeout('statt();',190000);