/*
function AjaxRequest(cmd, data, callback, callbackdata, nocache) {
    var iframe = document.createElement('IFRAME');
    iframe.width="1";
    iframe.height="1";
    iframe.style.display="none";
    iframe.style.position="absolute";
    iframe.style.width="0px";
    iframe.style.height="0px";
    iframe.src="about:blank";
    document.body.appendChild(iframe);
    
    
    
    var url = "/ajax.php?";
    url = url + "cmd=" + cmd + "&"
    url = url + "data=" + bin2hex(data);
    if(nocache != undefined)
        url = url + "&nocache=" + nocache;

    iframe.time = new Date();
    iframe.loading = true;
    iframe.callback = callback;
    iframe.callbackdata = callbackdata;
    iframe.cmd = cmd;
    iframe.data = data;
    iframe.onload = AjaxLoaded;
    iframe.onreadystatechange = AjaxLoaded;
    iframe.src = url+'&time='+(new Date).getTime();

}
function AjaxLoaded(e) {
    
    if(!e)
        e = window.event;
    
    if(this.readyState && this.readyState != "complete")
        return false;
    
    var objE = new Object();
    objE.returnData = this.contentWindow.document.body.innerHTML; 
    objE.requestTime = this.time;
    objE.responseTime = new Date();
    objE.requestCommand = this.cmd;
    objE.requestData = this.data;
    
    this.callback(objE, this.callbackdata);
    
    this.onload = null;
    this.onreadystatechange = null;    
    this.contentWindow.location.href = "about:blank";
    
    document.body.removeChild(this);
    return true;
}
*/


var Ajax = new Object(); 
Ajax.callbackMethod = function() {}
Ajax.Request = function(method, url, callback) 
{ 
    var obj = this;
    this.time = new Date(); 
    this.callbackMethod = callback; 
    this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP"); 
    this.request.onreadystatechange = function() { obj.checkReadyState(); }; 
    this.request.open(method, url, true); 
    this.request.send(url); 
} 
Ajax.checkReadyState = function(_id) 
{ 
    switch(this.request.readyState) 
    { 
        case 1: 
        case 2: 
        case 3: 
            break; 
        case 4: 
            this.callbackMethod(this.request.responseText); 
            break;
    } 
} 

function AjaxRequest(cmd, data, callback, callbackdata, nocache) {
    var url = "/ajax.php?";
    url = url + "cmd=" + cmd + "&"
    url = url + "data=" + bin2hex(data);
    if(nocache != undefined)
        url = url + "&nocache=" + nocache;
        
    Ajax.data = data;
    Ajax.cmd = cmd;
    Ajax.callback = callback;
    Ajax.callbackdata = callbackdata;
    Ajax.Request('get', url, function(text) {
        var objE = new Object();
        text = /<html><body>(.*)<\/body><\/html>/.exec(text);
        objE.returnData = text[1]; 
        objE.requestTime = this.time;
        objE.responseTime = new Date();
        objE.requestCommand = this.cmd;
        objE.requestData = this.data;
        this.callback(objE, this.callbackdata);
    });
}
