function getEl(e)
{
	if(typeof e=='string')
		e=document.getElementById(e);
	return e
};

function collect(a,f)
{
	var n=[];
	for(var i=0;i<a.length;i++)
	{
		var v=f(a[i]);
		if(v!=null)
			n.push(v);
	}
	return n
};


           

Ajax = {};
Ajax.xmlHttp = new Array();
Ajax.getXmlHttpObject = function()
{
   
    try
    {
        return new ActiveXObject('Msxml2.XMLHTTP')
    }
    catch(e){
        try
        {
            return new ActiveXObject('Microsoft.XMLHTTP')
        }
        catch(e)
        {
            return new XMLHttpRequest()
        }
    }
    
};


Ajax.updater = function(id, url, method, form, progress)
{
    
    method = typeof method !== 'undefined' ? method.toLowerCase() : 'get';
    params = typeof form !== 'undefined' ? Ajax.serialize(getEl(form)) : null;
    progress =  typeof progress !== 'undefined' ? progress : false;    
    
    //var rand_no = Math.ceil(100*Math.random());
    
    
    
    if (Ajax.xmlHttp[url]!=null)
    {
        
        return false;
    }
    
    
    
    if(method == 'get' && params !== null)
    {
        splitedUrl = url.split('?');
        url = splitedUrl[0];
        url += '?'+params;
    }
    
    Ajax.xmlHttp[url] = Ajax.getXmlHttpObject();
    
    Ajax.xmlHttp[url].onreadystatechange = function (){ Ajax._updater(url, id, progress); };
    Ajax.xmlHttp[url].open(method,url,true);
    
    if(method == 'post')
        Ajax.xmlHttp[url].setRequestHeader('Content-type','application/x-www-form-urlencoded');
    
    Ajax.xmlHttp[url].send(params); 
    
    
};

Ajax._updater = function(url, id, progress)
{
    
       
    if (Ajax.xmlHttp[url].readyState==4)
    { 
        if(Ajax.xmlHttp[url].status == 200)
        {
        
            if(typeof id !== 'undefined' && Ajax.xmlHttp[url].responseText != "")
            {
                if(Ajax.xmlHttp[url].responseText.search(/dzoukrframework-abort-javascript-output/) == -1)
                    getEl(id).innerHTML=Ajax.xmlHttp[url].responseText;
            }
                
            
        }
        
        delete Ajax.xmlHttp[url];
    }
    else
    {
        if(progress)
        {
            if(typeof id !== 'undefined')
                getEl(id).innerHTML=progress;
        }
        
    }
    
};

Ajax.serialize = function(f)
{
    
    var g=function(n)
    {
        return f.getElementsByTagName(n)
    };
    
    var nv=function(e)
    {
        if(e.name)
            return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);
        else
            return ''
    };
    
    var i=collect(g('input'),
    function(i)
    {
        if((i.type!='radio'&&i.type!='checkbox')||i.checked)
            return nv(i)
    });
    
    var s=collect(g('select'),nv);
    var t=collect(g('textarea'),nv);
    
    return i.concat(s).concat(t).join('&');
};