﻿var doafterxmlget='';
var lastajaxreply='';

function fast(url)
{
    thedelete=1;
    
    if(typeof showwait!='undefined')
        attachhandler();
        
    loadXML(url,'','')
}

function buildPOST(theFormName)
{
    theForm=document.forms[theFormName];
    var qs='';
    for(e=0;e<theForm.elements.length;e++)
    {
        if(theForm.elements[e].name!='')
        {
            var name=theForm.elements[e].name;qs+=(qs=='')?'':'&';
            var theval=theForm.elements[e].value.replace(/%/g,'%25');
            qs+=name+'='+encodeURIComponent(theval)
        }
    }
    
    return qs
}

function XMLbusy()
{
    return true
}

function loadXML(url,theFormName,datajj)
{
    if(!XMLbusy())
        return;
        
    var thetype='GET';
    if(theFormName!='')
    {
        if(url=='')
            url=document.forms[theFormName].action;
        
        datajj=buildPOST(theFormName)
    }
    
    if(datajj!='')
        thetype='POST';
        
    if(window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest()
    }
    else if(window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    
    if(typeof xmlhttp!='undefined')
    {
        if(typeof showwait!='undefined')
            attachhandler();
            
        xmlhttp.onreadystatechange=xmlhttpChange;
        xmlhttp.open(thetype,url,true);
        xmlhttp.setRequestHeader("Cache-Control","no-cache");
        if(theFormName!=''||datajj!='')
            xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            
        xmlhttp.send(datajj);
        xmlonline=1
    }
    else
    {
        if(theFormName!=''&&datajj!='')
        {
        }
        
        if(url)
            imgxmlget.src=url;
            
        if(typeof doafterxmlget!='undefined'&&doafterxmlget!='')
            eval(doafterxmlget)
    }
}

function xmlhttpChange()
{
    if(xmlhttp.readyState==4)
    {
        if(xmlhttp.status==200)
        {
            xmlonline=0;
            var regout=xmlhttp.responseText.match(/<\!\-\- \[(infowin|infoalert)\]([\w \,\.\-\'\(\)]+)\-\->/i);
            
            if(regout)
            {
                if(regout[2])
                {
                    if(regout[1]=='infoalert')
                    {
                        alert(regout[2])
                    }
                    else
                    {
                        jwindow('',300,120,regout[2])
                    }
                }
                
                return true
            }
            
            if(typeof doafterxmlget=='undefined'||doafterxmlget=='')
            {
                fnFrameLoadHandler(xmlhttp.responseText)
            }
            else
            {
                eval(doafterxmlget)
            }
        }
        else
        {
        }
    }
}

function fnFrameLoadHandler(gotinfo)
{
}

var diGXMLRequest=
{
    get:function(url,callback)
    {
        var _getter=GXmlHttp.create();
        _getter.open("GET",url,true);
        _getter.onreadystatechange=function()
        {
            if(_getter.readyState==4)
            {
                callback(_getter.responseXML)
            }
        };
        
        _getter.send(null)
    },
    post:function(url,form,callback)
    {
        var _poster=GXmlHttp.create();
        _poster.open("POST",url,true);
        _poster.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        _poster.setRequestHeader('Connection','close');
        _poster.send(form);
        _poster.onreadystatechange=function()
        {
            if(_poster.readyState==4)
            {
                if(adding_block==3)
                {
                    var regout=_poster.responseText.match(/<\!\-\- \[(infowin|infoalert)\]([\w \,\.\-\'\(\)]+)\-\->/i);
                    if(regout)
                    {
                        adding_block=2;
                        edit_block_id=0;
                        
                        if(regout[2])
                        {
                            if(regout[1]=='infoalert')
                            {
                                alert(regout[2])
                            }
                            else
                            {
                                jwindow('',300,120,regout[2])
                            }
                        }
                        
                        return true
                    }
                    
                    var the_id=_poster.responseText.match(/<\!\-\- xy:(\-?\d+x\-?\d+x\-?\d+x\-?\d+x?\d*)/);
                    
                    adding_block=2;
                    if(the_id)
                    {
                        if(the_id[1])
                            window_edit(0,the_id[1]);
                            
                        return
                    }
                    else
                    {
                    }
                    
                    var the_id1=_poster.responseText.match(/<\!\-\- reloadxy/);
                    clear_cache();
                    
                    update_objects('refresh')
                }
                
                callback(_poster.responseXML)
            }
        }
    }
};
