multiFileUploadAdd = function(id)
{
    var field = document.createElement('input');

    var type = document.createAttribute('type');
    type.nodeValue = 'file';
    field.setAttributeNode(type);

    var name = document.createAttribute('name');
    name.nodeValue = id+'[]';
    field.setAttributeNode(name);
    
    var class = document.createAttribute('class');
    class.nodeValue = 'file';
    field.setAttributeNode(class);

    document.getElementById(id).appendChild(field); 
}


function changePage(id, pages, file, targetID, current)
{
    new Ajax.Updater(id, root + 'sentaqor/ajax.php?get=pageSet'
                              + '&id=' + id
                              + '&pages=' + pages
                              + '&file=' + file
                              + '&targetID=' + targetID
                              + '&current=' + current
    );
    new Ajax.Updater(targetID, unescape(file)+current);
}

SQR = function()
{
}

SQR.Ajax = function(call, processing)
{
    return new SQR.AjaxRequest(root + 'index.php?sqrAjax='+ call, processing);
}

SQR.AjaxRequest = function(get, processing)
{
    var gate;
    processing = eval(processing);

    if (window.XMLHttpRequest) {
        gate = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        gate = new ActiveXObject('Microsoft.XMLHTTP');
    }

    if (gate) {
        gate.open('POST', get, true);
        gate.onreadystatechange = function ()
        {
            if (gate.readyState == 4) {
                if (processing.onComplete) {
                    processing.onComplete(gate.responseText);
                }
                if (processing.update) {
                    document.getElementById(processing.update).innerHTML = gate.responseText;
                }
                if (document.getElementById('ajaxLoader')) {
                    document.getElementById('ajaxLoader').style.display = 'none';
                }
            }
        };
        gate.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        gate.send('sqrVitualRoot='+root+'&get=' + get);
        if (processing.update) {
           document.getElementById(processing.update).innerHTML = '<div class="loader"><span>lade ...</span></div>';
        }
        if (document.getElementById('ajaxLoader')) {
            document.getElementById('ajaxLoader').style.display = 'block';
        }
    }
}

function send(id)
{
    SQR.Ajax('embany::message('+id+')', {
        onComplete: function(r) {
            var container = document.createElement('div');
            var body = document.getElementsByTagName('body')[0];
            body.insertBefore(container, body.firstChild);
            container.innerHTML = r;

            /*document.getElementById('ebnyMessage').style.left = ((window.innerWidth-340)/2) + 'px';
            document.getElementById('ebnyMessage').style.top = ((window.innerHeight-340)/2) + 'px';*/
        }
    });
}

function message(id)
{
    SQR.Ajax('embany::message('+id+', 1)', {
        onComplete: function(r) {
            var container = document.createElement('div');
            var body = document.getElementsByTagName('body')[0];
            body.insertBefore(container, body.firstChild);
            container.innerHTML = r;

            /*document.getElementById('ebnyMessage').style.left = ((window.innerWidth-340)/2) + 'px';
            document.getElementById('ebnyMessage').style.top = ((window.innerHeight-340)/2) + 'px';*/
        }
    });
}

function sendMessage(message, uid)
{
    message = message.replace(/"/g, '\\\"');
    SQR.Ajax('embany::sendMessage("'+message+'",'+uid+')', {
        onComplete: function(r) {
            if (r) {
                alert(r);
            }
        }
    });
}