var connected = true;
var attempts = 0;
var cLoader = null;
var validEmail = false;
var currentLabelId = 0;
var fancy;
var ajaxCount = 0;
var multiUpload;
var lastId = null;
var hide = true;
var isOver = false;
var currentDrop = null;
var loaded = false;

var zip_attempts = 0;
var extracted = 0;
var toExtract;
var host;
var zipExtAttempts = 10;

var previewImageCount;
var previewImageLoaded = 0;
var previewImageCurrent = 1;

var selectedFolder = '';
var clone;

function submitNewFolderOld(request){
    if (request == 'true'){
        alert(lang.transl("FOLDER_EXISTS_PART1") + ' ' + Q('newFolderInput').value + ' ' + lang.transl("FOLDER_EXISTS_PART2"));
        return false;
    }
    var folderNewName = encodeURIComponent(Q('#newFolderInput').val());
    var params = 'folderNewName='+folderNewName+'&hiddenSelCatId='+hiddenSelCatId;
    var url = 'x-add-new-folder';
    edisk.loadAjax(url, params, function(req) {
        alert(req);
        loadFooter('my-files');
        loadFileList(ownerId, hiddenSelCatId, 0);
    });
    return false;
}

function submitNewFolder() {
    var name = Q('#folder').val();
    if (name == null || name == '') {
        alert(lang.transl("FOLDER_EMPTY"));return false;
    }
    var params = 'folderNewName='+name+'&hiddenSelCatId='+hiddenSelCatId;
    var url = 'x-add-new-folder';
    edisk.loadAjax(url, params, function(req) {
        edisk.showMessage(req);
        edisk.dialog.dialog('close');
        loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord);
    });
    return false;
}

function loadFileList(userId, labelId, fromRecord, sortby, up){
    Q("#options").hide("fast");
    Q("#folderOptions").hide("fast");
    lastId = null;
    loaded = false;
    var url = 'x-load-file-list/acc/'+sessId;
    hiddenFromRecord = fromRecord;
    params = 'userId='+userId+'&labelId='+labelId+'&fromRecord='+fromRecord;
    params += '&sortby='+sortby+'&up='+up;

    edisk.loadAjax(url, params, function(req) {
        Q('#vypis-souboru').html(req);
        Q('#hoverbox-middle').css('height', '170px');
        loadFooter('my-files');
        hiddenSelCatId = labelId;
        hiddenFromRecord = fromRecord;
        hiddenOrderBy = sortby;
        hiddenAsc = up;
    });

    hiddenSelCatId = labelId;
}

function loadFooter(loc){
    lastFooterLocation = loc;
    var url = 'x-load-footer';
    var params = 'location='+loc;
    edisk.loadAjax(url, params, function(req) {
        Q('#footer').html(req);
        Q('#footer').css('display', 'block');
        loadUbrUpload();
        lateLoad();
    });
}

function doSearch(){
    var qry = encodeURIComponent(Q('#searchQry').val());
    if ( qry != '' ){
        var url = 'x-search';
        var params = 'searchQry='+qry;
            if (Q('#searchContacts').is(':checked')){
                params += '&searchContacts=1';
            }
            if (Q('#searchAll').is(':checked') ) {
                params += '&searchAll=1';
            }
            
            edisk.loadAjax(url, params, function(req) {
                Q("#vypis-souboru").html(req);
                showFooter('none');
                Q('#oItem5').css('display', 'none');
                Q('#oItem3').css('display', 'none');
                Q('#oItem4').css('borderBottom', '0px solid #e0e0e0');
            });
    }
}

function showFooter(disp){
    if (Q('#footer')) Q('#footer').css('display', disp);
}

function isImageOk(img) {
    if (!img.complete) {return false;}
    if (img.complete) return true;
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {return false;}
    return true;
}

function collapseTodoList(){
    var clist = document.getElementById('toggleTodoList');
    if ( clist.className == 'maximize mootoolsTips' ){
        clist.className = 'minimize mootoolsTips';
    } else {
        clist.className = 'maximize mootoolsTips';
    }
    clist = document.getElementById('toggleTodoList');
    var url = 'x-save-todolist-state';
    var params= 'class=' + clist.className.split(' ')[0];
    edisk.loadAjax(url, params, function(req) {
        todoRefresh();
    });
}

function collapseContacts(){
    var clist = document.getElementById('toggleContactList');
    if ( clist.className == 'maximize mootoolsTips' ){
        clist.className = 'minimize mootoolsTips';
    } else {
        clist.className = 'maximize mootoolsTips';
    }
    var url = 'x-save-contactlist-state';
    var params= 'class=' + clist.className.split(' ')[0];
    edisk.loadAjax(url, params, function(req) {
        todoRefresh();
    });
}

function todoRefresh() {
    var url = 'x-reload-todoitem';
    var params = '';
    edisk.loadAjax(url, params, function(req) {
        Q('#todoWrapper').html(req);
        Q("#todoWrapper .todoItem").draggable({
            containment: 'document',
            opacity: 0.6,
            revert: 'invalid',
            helper: 'clone',
            zIndex: 100
        });
    });
}

function toggleGroup(gid, anchor){

    var expanded = true;
    if (gid == 0) {
        if ( anchor.className == 'group-minimize' ){
            document.getElementById('grpspan_0').style.display = 'none';
            document.getElementById('userCount_0').style.display = 'inline';
            anchor.className = 'group-maximize';
            expanded = false;
        } else {
            document.getElementById('grpspan_0').style.display = 'block';
            document.getElementById('userCount_0').style.display = 'none';
            anchor.className = 'group-minimize';
        }
    }
    else {
        if ( anchor.className == 'group-minimize' ){
            anchor.className = 'group-maximize';
            if (document.getElementById('grpspan_'+gid))
                document.getElementById('grpspan_'+gid).style.display = 'none';
            document.getElementById('userCount_'+gid).style.display = 'inline';
            expanded = false;
        } else {
            if (document.getElementById('grpspan_'+gid))
                document.getElementById('grpspan_'+gid).style.display = 'block';
            document.getElementById('userCount_'+gid).style.display = 'none';
            anchor.className = 'group-minimize';
        }
    }

    var url = 'x-save-group-state/acc'+sessId;
    var params = 'gid='+gid+'&expanded=';
    if (expanded){
        params += '1';
    } else {
        params += '0';
    }
    edisk.loadAjax(url, params, function(req) {
        
    });	
}


function contactsRefresh() {
    var url = 'x-reload-contacts';
    var params = '';
    edisk.loadAjax(url, params, function(req) {
        Q('#groupWrapper').html(req);
        loadTodoDrag();
    });
}

function addGroup() {
    
    var groupName = lang.transl("NAME");
    
    groupName = window.prompt(lang.transl("NEW_GROUP_NAME") + ' ', groupName);
    if (groupName == null || groupName.length == null || groupName.length <= 0 ) {
        return false;
    }

    var url = 'x-new-group';
    var params = 'groupName='+encodeURIComponent(groupName);
    edisk.loadAjax(url, params, function(req) {
        window.location = '/';
    });
    return false;
}

function inviteNewContact(addr) {
    var url = 'x-invite-contact';
    var params = 'contactEmail='+encodeURIComponent(addr);
    edisk.loadAjax(url, params, function(req) {
        Q("#userExistMsg").html(req);
    });
    return false;
}

function label(){
    var fArr = getChecked('fileCheck[]');
    var sb = document.getElementById('actionSelBox');
    var url = '';
    var paramName = '';
    if ( sb[sb.selectedIndex].className == 'addCat' ){
        url = 'x-add-label/acc/'+sessId;
        paramName = 'addCat';
    } else {
        url = 'x-rm-label/acc/'+sessId;
        paramName = 'rmCat';
    }
    var params = paramName + '=' + sb[sb.selectedIndex].value;
    for (var i = 0; i < fArr.length; i++){
        params += '&fileCheck[]=' + fArr[i];
    }
    
    edisk.loadAjax(url, params, function(req) {
        loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
        edisk.showMessage(request);
    });
    return false;
}

function getChecked(elName){
    var checked = new Array();
    cbA = document.getElementsByName(elName);
    for(var i = 0; i < cbA.length; i++){
        if (cbA[i].checked){
            checked[checked.length] = cbA[i].value;
        }
    }
    return checked;
}

function getCheckedElements(elName){
    var checked = new Array();
    var cbA = document.getElementsByName(elName);

    for(var i = 0; i < cbA.length; i++){
        if (cbA[i].checked){
            checked[checked.length] = cbA[i].id;
        }
    }
    return checked;
}

function setUnchecked(elName){
    var checked = new Array();
    cbA = document.getElementsByName(elName);
    for(var i = 0; i < cbA.length; i++){
        if (cbA[i].checked){
            cbA[i].checked = 0;
        }
    }
    return checked;
}

function goToUrl(url){
    document.location = url;
}

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function createPreview(host, id) {
    document.getElementById('uploadIFrame').src = host+'/nahled/'+id;
}

function switchImgs() {
    attempts += 1;
	document.getElementById('previewImg').src = document.getElementById('previewImg').src + '#';
	if (attempts < 10) {
        if (isImageOk(document.getElementById('previewImg'))) {
            document.getElementById('switch1').style.display = 'none';
            document.getElementById('switch2').style.display = 'block';
        }
        else
            setTimeout('switchImgs()', 500);
    }
    else {
        // failsafe
        document.getElementById('switch1').style.display = 'none';
        document.getElementById('switch2').style.display = 'block';
    }
}

function loadOrangeButton() {
    Q("a.bg-button").mouseover(function(){
        this.style.color = 'black';
    }).mouseout(function(){
        this.style.color = '#fff';
    });
}

function hideContextMenu() {
    if (hide == true) {
        Q("#options").hide("fast");
        lastId = null;
    }
}

function showOptions(id) {
    hide = false;
    Q("#folderOptions").hide("fast");


    var element = document.getElementById('options');
    var clickEl1 = document.getElementById('optionsItem1');
    var clickEl2 = document.getElementById('optionsItem2');
    var clickEl3 = document.getElementById('optionsItem3');
    var clickEl4 = document.getElementById('optionsItem4');
    var clickEl5 = document.getElementById('optionsItem5');
    var clickEl6 = document.getElementById('optionsItem6');
    var clickEl7 = document.getElementById('optionsItem7');

    var href = document.getElementById('itemhref_'+id).href;
    
    clickEl6.href = href;
    
    if (href.search(/.zip_/) >= 0) {
        document.getElementById('li_item7').style.display = 'block';
        if (document.getElementById('oItem3').style.display == 'none') {
            document.getElementById('hoverbox-middle').style.height = '144px';
            document.getElementById('hoverbox-middle').style.background = 'url(../images/hover-box3.png) no-repeat';
        }
        else {
            document.getElementById('hoverbox-middle').style.height = '205px';
            document.getElementById('hoverbox-middle').style.background = 'url(../images/hover-box4.png) no-repeat';
        }
    }
    else if (document.getElementById('oItem3').style.display == 'none') { // contact page list
        document.getElementById('li_item7').style.display = 'none';
        document.getElementById('hoverbox-middle').style.height = '120px';
        document.getElementById('hoverbox-middle').style.background = 'url(../images/hover-box3.png) no-repeat';
    }
    else {
        document.getElementById('li_item7').style.display = 'none';
        document.getElementById('hoverbox-middle').style.height = '173px';
        document.getElementById('hoverbox-middle').style.background = 'url(../images/hover-box3.png) no-repeat';
    }

    var elemId = id;
    clickEl1.onclick=function(){jQuery("#options").hide("fast");lastId = null;fileSettings(elemId, 'links');};
    clickEl2.onclick=function(){jQuery("#options").hide("fast");lastId = null;fileSettings(elemId, 'email');};
    clickEl3.onclick=function(){jQuery("#options").hide("fast");lastId = null;fileSettings(elemId, 'share');};
    clickEl4.onclick=function(){jQuery("#options").hide("fast");lastId = null;fileSettings(elemId, 'statistics');};
    clickEl5.onclick=function(){deleteFile(elemId);};
    clickEl7.onclick=function(){jQuery("#options").hide("fast");lastId = null;fileSettings(elemId, 'zip');};

    clickEl1.onmouseover=function(){hide=false;clickEl1.style.background = "#eaeaea";};
    clickEl1.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl1.style.background = "transparent url(../images/ico-gen-odkaz.gif) no-repeat 10px 50%";};
    clickEl2.onmouseover=function(){hide=false;clickEl2.style.background = "#eaeaea";};
    clickEl2.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl2.style.background = "transparent url(../images/ico-zas-email.gif) no-repeat 10px 50%";};
    clickEl3.onmouseover=function(){hide=false;clickEl3.style.background = "#eaeaea";};
    clickEl3.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl3.style.background = "transparent url(../images/ico-nas-prav.gif) no-repeat 10px 50%";};
    clickEl4.onmouseover=function(){hide=false;clickEl4.style.background = "#eaeaea";};
    clickEl4.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl4.style.background = "transparent url(../images/ico-statistika.gif) no-repeat 10px 50%";};
    clickEl5.onmouseover=function(){hide=false;clickEl5.style.background = "#eaeaea";};
    clickEl5.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl5.style.background = "transparent url(../images/ico-smazat.gif) no-repeat 10px 50%";};
    clickEl6.onmouseover=function(){hide=false;clickEl6.style.background = "#eaeaea";};
    clickEl6.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl6.style.background = "transparent url(../images/arrow-down.gif) no-repeat 10px 50%";};
    clickEl7.onmouseover=function(){hide=false;clickEl7.style.background = "#eaeaea";};
    clickEl7.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl7.style.background = "transparent url(../images/briefcase.png) no-repeat 10px 50%";};

    var obj = document.getElementById('option_'+id);
    var objOrig = obj;

    var elleft = eltop = i = 0;
    if(obj.offsetParent)
        while(1)
        {
          if (i<2)
                elleft += obj.offsetLeft;
          eltop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
          i++;
        }
    else if(obj.x) {
        elleft += obj.x;
        eltop += obj.y;
    }
    elleft += 26;
    eltop -= 10;
    if (objOrig.className == 'bottomOption') eltop -= 238;
    else eltop -= 158;
    element.style.left = elleft + 'px';
    element.style.top = eltop + 'px';

    if (Q("div").filter("#options").is(":visible")) {
        if (lastId == id) {
            Q("#options").hide("fast");
            lastId = null;
        }
        else {
            lastId = id;
        }
    }
    else {
        if (lastId == id) {
            Q("#options").hide("fast");
            lastId = null;
        }
        else {
            Q("#options").show("fast");
            lastId = id;
        }
    }
}

function goTo(id){
    return false;
}

function showError(request){
    alert(request.responseText);
}

function submitNewTodoItem() {
    if (document.getElementById('todoItem').value.length == 0) {
        alert(lang.transl("EMPTY_TODOITEM"));
        return false;
    }
    var msg = document.getElementById('todoItem').value;
    var url = 'x-ulozit-novy-todoitem';
    var params = 'msg='+msg+'&priority='+document.getElementById('priority').value;

    edisk.loadAjax(url, params, function(req) {
        edisk.hideDialog();
        todoRefresh();
    });
    return true;
}

function findContact() {
    var addr = document.getElementById('contactEmail').value;
    if ( addr == '' ){
        alert(lang.transl("EMAIL_EMPTY"));
        return false;
    }
    var params = 'contactEmail='+encodeURIComponent(addr);
    var url = 'x-search-contact';
    edisk.loadAjax(url, params, function(req) {
        edisk.showDialog(req);
    });
    return false;
}

function findContactNotEdisk(email) {
    if ( email == '' ){
        alert(lang.transl("EMAIL_EMPTY"));
        return false;
    }
    var params = 'contactEmail='+encodeURIComponent(email);
    var url = 'x-add-contact-not-edisk';
    edisk.loadAjax(url, params, function(req) {
        edisk.showDialog(req);
    });
    return true;
}

function submitContactNotEdisk(email){
    var contactEmail = email;
    var name = document.getElementById('inviteEmailName').value;
    var params = 'name='+name+'&contactEmail='+contactEmail;
    var url = 'x-insert-contact-not-edisk';
    edisk.loadAjax(url, params, function(req) {
        edisk.hideDialog();
        contactsRefresh();
        edisk.showMessage(req);
    });
}

function submitContact() {
    var msg = Q('#inviteMsg').val();
    var contactId = document.getElementById('contactId').value;
    var gs = document.getElementById('groupSelect');
    var gid = gs[gs.selectedIndex].value;
    
    if ( msg == '' ){
        alert(lang.transl("EMPTY_INVITATION"));
        return false;
    }
    var encodedMsg = encodeURIComponent(msg);
    var params = 'msg='+encodedMsg+'&contactId='+encodeURIComponent(contactId)+'&gid='+encodeURIComponent(gid);
    var url = 'x-add-contact';
    edisk.loadAjax(url, params, function(req) {
        edisk.hideDialog();
        contactsRefresh();
        edisk.showMessage(req);
    });
    return false;
}



function readMail(msgId){
    var params = '';
    var url = 'x-read-edisk-message/'+msgId;
    edisk.loadAjax(url, params, function(req) {
        edisk.showDialog(req);
        loadOrangeButton();
    });
    return false;
}

function addTodoItem(){
    var url = 'x-add-new-todoitem';
    var params = '';
    edisk.loadAjax(url, params, function(req) {
        edisk.showDialog(req);
    });
}

function setTodoDone(id) {
    var params = null;
    if (document.getElementById('todoCheck'+id).checked) {
        document.getElementById('todoContent'+id).style.textDecoration  = 'line-through';
        document.getElementById('contentLong'+id).style.textDecoration  = 'line-through';
        params = 'checked=1&id='+id;
    }
    else {
        document.getElementById('todoContent'+id).style.textDecoration  = '';
        document.getElementById('contentLong'+id).style.textDecoration  = '';
        params = 'checked=0&id='+id;
    }

    var url = 'x-done-todoitem';
    edisk.loadAjax(url, params, function(req) {
        todoRefresh();
    });
}

function deleteTodoitem(id) {
    var value = confirm(lang.transl("CONFIRM_DELETE_TODO"));
    if (value) {
        var url = 'x-delete-todoitem';
        var params = 'id='+id;
        edisk.loadAjax(url, params, function(req) {
            todoRefresh();
            edisk.showMessage(req);
        });
    }
}

function hideMessageLogin(){
    document.getElementById('loadingDiv').style.visibility = 'hidden';
    connected = false;
    clearTimeout(tipTimeout);
}

function multiUpload()
{
    var url = 'x-multi-upload';
    var params = '';
    edisk.loadAjax(url, params, function(req) {
        multiUpload = new MultiUpload(document.getElementById('main_form'), 3, '[{id}]', true, true);
        edisk.showDialog(req);
    });
}

function multiUploadFlash()
{
    var url = 'x-multi-upload-flash';
    var params = '';
    edisk.loadAjax(url, params, function(req) {
        multiUpload = new MultiUpload(document.getElementById('main_form'), 3, '[{id}]', true, true);
        edisk.showDialog(req);
    });
}



function sendMessage() {
    if (document.getElementById('emailInput').value == '') {
        alert(lang.transl("EMAIL_NOT_EMAIL"));
        return false;
    }
    var fArr = getChecked('fileCheck[]');
    var params = 'emailAddr=' + encodeURIComponent(document.getElementById('emailInput').value) + '&message=' + encodeURIComponent(document.getElementById('messageInput').value);
    for (var i = 0; i < fArr.length; i++){
        params += '&fileCheck[]=' + encodeURIComponent(fArr[i]);
    }
    var url = 'x-send-mail/acc/'+sessId;
    
    edisk.loadAjax(url, params, function(req) {
        edisk.showMessage(req);
        edisk.dialog.dialog('close');
    });
    return true;
}

function deleteSelectedMail() {
    if ( confirm(lang.transl("CONFIRM_DELETE")) ) {
        var cbArray = getChecked('mailCheck[]');
        if ( cbArray.length <= 0 ){
            return false;
        }
        var params = '';
        for(i = 0; i < cbArray.length; i++ ){
            params += '&mailCheck[]=' + cbArray[i];
        }
        var url = 'x-unlink-mail/acc'+sessId;
        edisk.loadAjax(url, params, function(req) {
            loadMailList(fromMail);
            edisk.showMessage(req);
        });
    }
    return false;
}

function shareFiles(){
    var fArr = getChecked('fileCheck[]');
    var cArr = getChecked('contactCheck[]');
    var cArrNE = getChecked('contactNotEdiskCheck[]');

    if ( (fArr.length < 1) ){
        alert(lang.transl("NO_FILES"));
        return false;
    }
    if (cArr.length < 1 && cArrNE.length < 1){
        alert(lang.transl("NO_CONTACT"));
        return false;
    }

    if (cArr.length >= 1) {
        var params = '';
        for (var k = 0; k < fArr.length; k++){
            params += '&fileCheck[]=' + fArr[k];
        }
        for (var l = 0; l < cArr.length; l++){
            params += '&contactCheck[]=' + cArr[l];
        }

        var url = 'x-new-acl-entry/acc/'+sessId;
        edisk.loadAjax(url, params, function(req) {
            edisk.showMessage(req);
        });
    }

    if (cArrNE.length >= 1) {
        var params2 = '';
        for (var i = 0; i < fArr.length; i++){
            params2 += '&fileCheck[]=' + fArr[i];
        }
        for (var j = 0; j < cArrNE.length; j++){
            params2 += '&contactNotEdiskCheck[]=' + cArrNE[j];
        }

        var url2 = 'x-send-links-not-edisk-mail';
        edisk.loadAjax(url2, params, function(req) {
            edisk.showMessage(req);
        });
    }
    return true;
}

function sendFileLink(id) {
    var email = encodeURIComponent(document.getElementById('contactEmail').value);
    var params = '';
    params += '&fileId=' + id;
    params += '&contactEmail=' + email;
    var url = 'x-send-link';
    edisk.loadAjax(url, params, function(req) {
        edisk.hideDialog();
        edisk.showMessage(req);
    });
}

function sendQuickFileLink(id) {
    var email = encodeURIComponent(Q('#contactEmail').val());
    var params = '';
    params += '&fileId=' + id;
    params += '&contactEmail=' + email;
    var url = 'odeslat-odkazy';
    edisk.loadAjax(url, params, function(req) {
        edisk.hideDialog();
        edisk.showMessage(req);
    });
}

function deleteFile(id) {
    var params = 'fileid=' + id;
    var url = 'x-get-filename';
    edisk.loadAjax(url, params, function(req) {
        request = req.replace( /\s/g, "" );
        if ( confirm(lang.transl("CONFIRM_DELETE") + ' ' + request + '?') ){
            var params2 = '&fileCheck[]=' + id;
            var url2 = 'x-unlink-files/acc'+sessId;
            edisk.loadAjax(url2, params2, function(req2) {
                loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord);
                edisk.showMessage(req2);
            });
        }
    });
}

function deleteFiles(){
    var cbArray = getChecked('fileCheck[]');
    if ( cbArray.length <= 0 ){
        return false;
    }
    var params = '';
    for(i = 0; i < cbArray.length; i++ ){
        params += '&fileCheck[]=' + cbArray[i];
    }
    var url = 'x-unlink-files/acc'+sessId;
    edisk.loadAjax(url, params, function(req) {
        loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
        edisk.showMessage(req);
    });
    return true;
}

function fileSettings(id, type){
    var obj = document.getElementById('option_'+id);
    if (obj.className == 'quick') var qid = 'q' + id;
    var url = 'x-file-'+type+'/';
    if (qid) url = url + qid;
    else url = url + id;
    
    var params = '';
    edisk.loadAjax(url, params, function(req) {
        if (type == 'share' || type == 'email')
            edisk.showDialog(req, true);
        else
            edisk.showDialog(req);
        loadOrangeButton();
        if (type == 'zip') {generateZip(id);}
    });
}

// zip section start //
function generateZip(id) {
    var host = document.getElementById("hiddenhost").value;
    document.getElementById('uploadIFrame').src = host+'/x-zip-package/'+id;
    zip_attempts = 0;
    setTimeout('getZipContents('+id+')', 1000);
}


function getZipContents(id) {
    if (zip_attempts < 10) {
        zip_attempts++;
        var params = 'id='+id;
        var url = 'x-get-zip-contents';

        edisk.loadAjax(url, params, function(req) {
            
            if (req == null || req == '') {
                setTimeout('getZipContents('+id+')', 500);
            }
            else {
                document.getElementById('switch1').style.display = 'none';
                edisk.showDialog(req);
                var host = document.getElementById("hiddenhost").value;
            }
        });
    }
}

function extract(id) {
    extracted = 0;
    toExtract = getCheckedElements('fileZipCheck[]');
    host = document.getElementById("hiddenhost").value;
    if (toExtract.length == 0) {
        alert(lang.transl("NO_FILES_ZIP"));
    }
    else {
        document.getElementById("ajaxloading").style.display = 'block';
        document.getElementById("extract").style.display = 'none';
        extractNext(id);
    }
}

function extractNext(id) {
    if (toExtract && extracted < toExtract.length) {
        document.getElementById('uploadIFrame').src = host+'/x-zip-package-extract/'+id+'/'+toExtract[extracted];
        //alert(host+'/x-zip-package-extract/'+id+'/'+toExtract[extracted]);
        zipExtAttempts = 10;
        setTimeout('processExtraction('+id+')', 500);
    }
    else {
        document.getElementById("ajaxloading").style.display = 'none';
        document.getElementById("extract").style.display = 'block';
        setUnchecked('fileZipCheck[]');
        edisk.hideDialog();
        loadFileList(ownerId, hiddenSelCatId, 0);
    }
}

function processExtraction(id) {
    
    var params = 'id='+id + '&extracting='+toExtract[extracted];
    var url = 'x-check-zip-extraction';
    
    edisk.loadAjax(url, params, function(req) {
        if (req && req.length == 32) {
            document.getElementById('uploadIFrame').src = host+'/x-zip-save-file/'+req+'/'+toExtract[extracted]+'/'+id+'/'+hiddenSelCatId;
            //alert(host+'/x-zip-save-file/'+req+'/'+toExtract[extracted]+'/'+id+'/'+hiddenSelCatId);
            saveFile(id, req);
        }
        else {
            
            zipExtAttempts--;
            if (zipExtAttempts > 0)
                setTimeout('processExtraction('+id+')', 500);
            else {
                document.getElementById("ajaxloading").style.display = 'none';
                alert(lang.transl("ZIP_PASSWORD"));
                edisk.hideDialog();
            }
        }
    });
}

function saveFile(id) {
    var params = 'id='+id + '&idFile='+toExtract[extracted];
    var url = 'x-check-zip-extraction-saved';
    edisk.loadAjax(url, params, function(request) {
        if (request && request.toString().substr(0, 5) == 'error') {
            extracted++;
            extractNext(id);
        }
        else if (request && request > 0) {
            extracted++;
            extractNext(id);
        }
        else {
            setTimeout('saveFile('+id+')', 500);
        }
    });
}
// zip section end //

function checkCatSettings() {
    var url = 'x-check-cat-name';
    var catNewName = document.getElementById('catNewName').value;
    var selCat = encodeURIComponent(hiddenSelCatId);
    var params = 'selCatId='+selCat+'&catNewName='+encodeURIComponent(catNewName);
    edisk.loadAjax(url, params, function(request) {submitCatSettings(request);});
    return false;
}

function checkNewCatSettings(){
    var url = 'x-check-new-cat-name';
    
    var catNewName = null;
    if (document.getElementById('catNewName') && document.getElementById('catNewName').value != null)
        catNewName = document.getElementById('catNewName').value;
    else
        catNewName = document.getElementById('newFolderInput').value;

    if (catNewName == '' || catNewName == null) {alert(lang.transl("CAT_EMPTY"));return false;}
    var params = 'catNewName='+encodeURIComponent(catNewName);
    edisk.loadAjax(url, params, function(request) {submitNewCat(request);});
    return false;
}

function submitNewCat(req){
    
    if ( req == '1'){
        alert(lang.transl("CAT_EXISTS_PART1") + ' ' + document.getElementById('catNewName').value + ' ' + lang.transl("CAT_EXISTS_PART2"));
        return false;
    }
    
    var url = 'x-add-new-cat';
    var sharedCheck = 0;
    var publicCheck = 1;

    if ( document.getElementById('catSharedCheck') && document.getElementById('catSharedCheck').checked ){
        sharedCheck = 1;
    }
    var catNewName = null;
    if (document.getElementById('catNewName') && document.getElementById('catNewName').value != null)
        catNewName = encodeURIComponent(document.getElementById('catNewName').value);
    else
        catNewName = encodeURIComponent(document.getElementById('newFolderInput').value);

    var params = 'catNewName='+catNewName+'&publicCheck='+publicCheck+'&sharedCheck='+sharedCheck;
    edisk.loadAjax(url, params, function(request) {
        loadFileList(ownerId, hiddenSelCatId, 0);
        loadFooter('my-files');
        edisk.hideDialog();
        edisk.showMessage(request);
        Q('#catNewName').val('');
    });
    return false;
}

function submitCatSettings(request){
    if ( request == '1'){
        alert(lang.transl("CAT_EXISTS_PART1") + ' ' + document.getElementById('catNewName').value + ' ' + lang.transl("CAT_EXISTS_PART2"));
        return false;
    }
    var url = 'x-ulozit-nastaveni-kategorie';
    var sharedCheck = 0;
    var publicCheck = 1;
    if ( document.getElementById('catSharedCheck').checked ){
        sharedCheck = 1;
    }
    var catNewName = encodeURIComponent(document.getElementById('catNewName').value);
    var params = 'selCatId='+selCatId+'&catNewName='+catNewName+'&publicCheck='+publicCheck+'&sharedCheck='+sharedCheck;

    edisk.loadAjax(url, params, function(request) {
        edisk.hideDialog();
        loadFooter('my-files');
        loadFileList(ownerId, selCatId, 0);
        edisk.showMessage(request);
    });
    return false;
}

function showEmailValid(req){
    if ( parseInt(req) == 1 ){
        validEmail = true;
        document.getElementById('validMailImg').style.visibility = 'visible';
        document.getElementById('invalidMailImg').style.visibility = 'hidden';
    } else {
        validEmail = false;
        document.getElementById('validMailImg').style.visibility = 'hidden';
        document.getElementById('invalidMailImg').style.visibility = 'visible';
    }
}

function checkMail(addr) {
    if (addr == '') {
        return false;
    }

    var url = 'x-check-email';
    var params = 'emailAddr='+addr;
    edisk.loadAjax(url, params, function(request) {
        showEmailValid(request);
    });
    return true;
}

function setActiveTab(tabName){
    var tab = document.getElementById(tabName);
    var menuItems = document.getElementById('menuList');
    for (i = 0; i < menuItems.childNodes.length; i++){
        if (menuItems.childNodes[i].nodeName == 'LI'){
            menuItems.childNodes[i].className = 'inactiveTab';
        }
    }
    tab.className = 'activeTab';
}

function ediskMail(idRecpt){
    var url = 'x-new-edisk-mail/'+idRecpt;
    var params = '';
    edisk.loadAjax(url, params, function(request) {
        edisk.showDialog(request);
        loadOrangeButton();
    });
    return false;
}

function createFolder() {
    var name = document.getElementById('newFolderInput').value;
}



function checkNewEdiskMail(){
    var msgSubject = document.getElementById('msgSubject').value;
    var msgContents = document.getElementById('msgContents').value;
    var idRecpt = document.getElementById('idRecpt').value;

    if ( msgSubject == '' ){
        alert(lang.transl("NO_MESSAGE_SUBJ"));
        return false;
    }

    if ( msgContents == ''){
        alert(lang.transl("NO_MESSAGE_BODY"));
        return false;
    }

    var url = 'x-send-edisk-mail';
    var params = 'msgSubject='+encodeURIComponent(msgSubject)+'&msgContents='+encodeURIComponent(msgContents)+'&idRecepient='+encodeURIComponent(idRecpt);
    document.getElementById('loadingDiv').style.visibility = 'visible';
    edisk.loadAjax(url, params, function(request) {
        edisk.hideDialog();
        edisk.showMessage(request);
    });
    return true;
}

function catSettings(){
    if ( hiddenSelCatId != 0){
        var url = 'x-nastaveni-kategorie';
        var params = 'hiddenSelCatId='+hiddenSelCatId;
        edisk.loadAjax(url, params, function(request) {
            edisk.showDialog(request, true);
        });
    }
    return false;
}

function highlightRow(rowId, cb, cName){
    var row = document.getElementById('row'+rowId);
    if (cb.checked){
        row.className = 'selRow';
    } else {
        row.className = cName;
    }
}

function doAction(){

    var sb = document.getElementById('actionSelBox');

    var fArr = getChecked('fileCheck[]');
    if (fArr.length < 1){
            alert(lang.transl("NO_FILES"));
            return false;
    }

    switch(sb[sb.selectedIndex].value){
        case 'shareSelected':
            var cArr = getChecked('contactCheck[]');
            var cArrNE = getChecked('contactNotEdiskCheck[]');
            if (cArr.length < 1 && cArrNE.length < 1){
                alert(lang.transl("NO_CONTACT"));
                return false;
            }
            shareFiles();
            break;
        case 'sendLinkPerEmail':
            sendLinkPerEmail();
            break;
        case 'generateLink':
            getFileLinks();
            break;
        case 'unlink':
            if ( confirm(lang.transl("CONFIRM_MULTI_DELETE")) ){
                deleteFiles();
            }
            break;
        default:
            label();
            break;
    }
    return false;
}

function addNewCat(){
    var url = 'x-new-cat';
}

function navToCategory(ownerId, labelId, from, orderBy, asc) {
    hiddenSelCatId = labelId;
    document.getElementById('hiddenOrderBy').value = orderBy;
    document.getElementById('hiddenAsc').value = asc;
    loadFileList(ownerId, hiddenSelCatId, 0, document.getElementById('hiddenOrderBy').value, document.getElementById('hiddenAsc').value);
}

function showCategory(){
    sb = document.getElementById('catSelect');
    switch (sb.options[sb.selectedIndex].value){
        case 'all':
            selCatId = 0;
            hiddenSelCatId = selCatId;
            loadFileList(ownerId, 0, 0);
            break;
        case 'nocategory':
            selCatId = 'nocategory';
            hiddenSelCatId = selCatId;
            loadFileList(ownerId, 'nocategory', 0);
            break;
        default:
            selCatId = sb.options[sb.selectedIndex].value;
            hiddenSelCatId = selCatId;
            loadFileList(ownerId, sb.options[sb.selectedIndex].value, 0, hiddenOrderBy, hiddenAsc);
            break;
    }
}

function labelToCat(lid){
    hiddenSelCatId = lid;
    loadFileList(ownerId, lid, 0, hiddenOrderBy, hiddenAsc);
}

function saveFileSettings(fId){
    var acl = getChecked('fileAclCheck[]');
    var fileNameInput = document.getElementById("fileNameInput").value;
    var params = 'fId='+fId;
    for(i = 0; i < acl.length; i++ ){
            params += '&fileAclCheck[]=' + acl[i];
    }
    params += '&fileNameInput='+encodeURIComponent(fileNameInput);
    var url = 'x-modify-acl';
    edisk.loadAjax(url, params, function(request) {
        edisk.hideDialog();
        loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
    });
}

function showReply(){
    document.getElementById('msgHeading').innerHTML = lang.transl("REPLY");
    document.getElementById('msgContainer').style.display = 'none';
    document.getElementById('replyContainer').style.display = 'block';
    document.getElementById('replyBtnWrapper').style.display = 'none';
    document.getElementById('sendReplyBtnWrapper').style.display = 'inline';
}

function loadMailList(from){
    fromMail = from;
    var params = 'fromRecord='+from;
    var url = 'x-render-mail-list';
    edisk.loadAjax(url, params, function(request) {
        Q('#vypis-souboru').html(request);
    });
}

function closeMailLightBox(){
    loadMailList(fromMail);
    edisk.hideDialog();
}

function dropMessage(msgId){
    if ( window.confirm(lang.transl("CONFIRM_DELETE2")) ){
        var url = 'x-drop-edisk-message/'+encodeURIComponent(msgId);
        var params = '';
        edisk.loadAjax(url, params, function(request) {
            loadMailList(fromMail);
        });
    }
}

function showInviteOptions(id){
    var url = 'x-show-invite-options';
    var params = 'inviteId='+encodeURIComponent(id);

    edisk.loadAjax(url, params, function(request) {
        edisk.showDialog(request);
    });
}

function acceptInvite(id){
    var url = 'x-accept-invite';
    var gs = document.getElementById('groupSelect');
    var gid = gs[gs.selectedIndex].value;
    var inviteId = document.getElementById('inviteId').value;
    var params = 'inviteId='+encodeURIComponent(inviteId)+'&gid='+encodeURIComponent(gid);
    edisk.loadAjax(url, params, function(request) {
        edisk.hideDialog();
        contactsRefresh();
    });
}

function addContact() {
    var url = 'x-find-new-contact';
    var params = '';
    edisk.loadAjax(url, params, function(request) {
        document.getElementById("lbContent").innerHTML = request;
    });
}

function notEdiskMail(email) {
    var value = confirm(lang.transl("CONFIRM_SEND_INVITATION"));
    if (value) {
        var url = 'x-invite-contact';
        var params = 'contactEmail='+email;
        edisk.loadAjax(url, params, function(request) {
            edisk.showMessage(request);
        });
    }
}

function showContentLong(id) {
    var element = 'contentLong'+id;
    var elementTest = 'contentLongInput'+id;
    if (document.getElementById(elementTest).style.display == 'none')
        document.getElementById(element).style.display = 'block';
}

function hideContentLong(id) {
    var element = 'contentLong'+id;
    document.getElementById(element).style.display = 'none';
}

function editTodoitem(id) {
    var element = 'contentLongInput'+id;
    var element2 = 'confirmIcon'+id;
    var element3 = 'todoitem-ico'+id;
    var element4 = 'deleteTodoitem'+id;
    document.getElementById(element4).src = '/images/check.gif';
    document.getElementById(element4).onclick = function() {confirmEditTodoitem(id)};

    hideContentLong(id);
    document.getElementById(element).style.display = 'block';
    document.getElementById(element3).style.display = 'none';
    document.getElementById(element).focus();
    document.getElementById(element).select();
}

function confirmEditTodoitem(id) {
    var element = 'contentLongInput'+id;
    var element2 = 'confirmIcon'+id;
    var element3 = 'todoitem-ico'+id;
    var element4 = 'deleteTodoitem'+id;
    var value = document.getElementById(element).value;

    var url = 'x-edit-todoitem';
    var params = 'id='+id+'&msg='+value;
    edisk.loadAjax(url, params, function(request) {
        document.getElementById(element2).style.display = 'none';
        document.getElementById(element3).style.display = 'block';
        todoRefresh();
        document.getElementById(element4).src = '/images/delete-todoitem.gif';
        document.getElementById('loadingDiv').style.visibility = 'hidden';
        edisk.showMessage(request);
    });
}

function submitAllTodoItems(length) {
    var elements = document.getElementsByName('todoitemLongSpan');
    for (i = 0; i < length; i++)
    {
        var id = elements[i].getAttribute('id');
        id = id.slice(16);
        var element = 'todoitem-ico'+id;
        if (document.getElementById(element).style.display == 'none') 
            confirmEditTodoitem(id);
    }
}



function setUploadFile() {
    var path = document.getElementById('cesta-k-souboru').value;
    var ext = path.substr(path.lastIndexOf('.') + 1);
    path = path.substr(path.lastIndexOf('\\') + 1);
    document.getElementById('inputFileOverWrapper').innerHTML = '<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+path+'</p>';
    document.getElementById('inputFileOverWrapper').style.background = 'white url(images/icons/'+ext+'.png) no-repeat 3px 3px';
}

function showRes(request){
    alert(request.responseText);
    loadFileList(ownerId, currentLabelId, 0);
    document.getElementById('loadingDiv').style.display = 'hidden';
}

function closelb(fId){
    lb.close();
}

function closeMultiLightBox()
{
    lb.deactivate();
    fileId = 0;
    filesTotal = 0;
    loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
}


function loadZipList(host, id) {
    var subframe = Q('uploadIFrame');
    if (host.substr(0,4) == 'muj5')
            host = 'muj5';
    else if (host.substr(0,4) == 'muj4')
            host = 'muj4';
    else if (host.substr(0,4) == 'muj3')
            host = 'muj3';
    else if (host.substr(0,4) == 'muj2')
            host = 'muj2';
    else if (host.substr(0,3) == 'muj')
            host = 'muj';
    else host = 'muj';
    subframe.src = 'http://'+host+'.edisk.cz/x-zip-package/'+id;
    subframe.style.visibility = 'visible';
    subframe.style.display = 'block';
    setTimeout("loadZipLightBox("+id+")", 1200);
}

function offRowZip(id, cls){
    row = document.getElementById('row'+id);
    if ( document.getElementById('zipCheck_'+id).checked ){
        row.className = 'selRow';
    } else {
        row.className = cls;
    }
}

function zipPackage(id){
    var host = null;
    var url = 'x-get-file-download-host';
    var params = 'id='+id;
    edisk.loadAjax(url, params, function(request) {
        loadZipList(request, id);
    });
}

function checkAllZip(){
    var check;
    if ( document.getElementById('fCheckCtrlZip').checked ){
        check = true;
    } else {
        check = false;
    }

    var cbA = document.getElementsByName('fileZipCheck[]');
    for (var i = 0; i < cbA.length; i++){
        cbA[i].checked = check;
        if (check){
            document.getElementById('row'+cbA[i].value).className = 'selRow';
        } else {
            if ( (i % 2) == 0 ){
                document.getElementById('row'+cbA[i].value).className = 'light';
            } else {
                document.getElementById('row'+cbA[i].value).className = 'dark';
            }
        }
    }
}

function loadContactFiles(contactId, fromRecord, sortby, asc){
    displayFooter = true;
    var url = 'x-load-contact-file-list/acc/'+sessId;
    var params = 'userId='+contactId+'&fromRecord='+fromRecord+'&sortby='+sortby+'&asc='+asc;
    
    document.getElementById('loadingDiv').style.visibility = 'visible';
    edisk.loadAjax(url, params, function(request) {
        Q('#vypis-souboru').html(request);
        document.getElementById('oItem5').style.display = 'none';
        document.getElementById('oItem3').style.display = 'none';
        document.getElementById('oItem4').style.borderBottom = '0px solid #e0e0e0';
        showFooter('none');
    });
}

function getFileLinks(){
    var fArr = getChecked('fileCheck[]');
    var params = '';
    for (var i = 0; i < fArr.length; i++){
        params += '&fileCheck[]='+fArr[i];
    }
    
    var url = 'x-generate-links/acc/'+sessId;
    edisk.loadAjax(url, params, function(request) {
       edisk.showDialog(request);
    });
}

function sendLinkPerEmail(){
    var params = '';
    var url = 'x-email-link-lightbox';
    edisk.loadAjax(url, params, function(request) {
       edisk.showDialog(request);
    });
}

function showLinks(request){
    edisk.showDialog(request);
}

function changeFileMulti(num){
    var id = num - 1;
    var element = document.getElementById('selectedFile'+id);
    var fileName = document.getElementById('upfile_'+id).value;
    var ext = fileName.substr(fileName.lastIndexOf('.') + 1, 4);
    extension = ext.toLowerCase();
    var extarr = ["avi", "bz2", "c", "cpp", "doc", "exe", "gif", "gz", "html", "img", "jpeg", "jpg", "js", "mp3", "mpeg", "mpg", "msi", "nfo", "pdf", "php", "png", "ppt", "psd", "rar", "rtf", "swf", "txt", "wav", "wma", "wmv", "xls", "zip"];
    if (extension == '') {extension = 'unknown';}
    else {
        var found = 0;
        for ( var i in extarr )
        {
            if (extarr[i] == extension) {
                found = 1;
                break;
            }
        }
        if(found == 0) {extension = 'unknown';}
    }
    element.style.paddingLeft = '25px';
    element.style.background = 'url(../images/icons/' + extension + '.png) no-repeat 2px 0px';
    var filteredName = fileName.substr(fileName.lastIndexOf('/') + 1);
    filteredName = fileName.substr(fileName.lastIndexOf('\\') + 1);
    if (filteredName.length > 30)
    filteredName = filteredName.substr(0, 30) + ' ...';
    element.innerHTML = filteredName;

    if(upload_range <= max_upload_slots){
        if(num == upload_range){
            var up = document.getElementById('upload_slots_multi');
            var dv = document.createElement("div");
            dv.className = 'con';
            dv.id = 'con'+upload_range;
            document.getElementById('con'+id).style.display = 'none';
            dv.innerHTML = '<div id="fileInputBox'+upload_range+'"><div class="button btn2" style="cursor: pointer;"><a style="cursor: pointer;" id="browseFile'+upload_range+'"><span class="left"></span><span class="center smaller" style="font-size: 11px; cursor: pointer;">vybrat...</span><span class="right"></span></a></div><div id="selectedFile'+upload_range+'" class="selectedFile">Vyberte soubor</div><div class="inputWrapper"><input type="file" onChange="changeFileMulti('+(upload_range + 1)+');" id="upfile_'+upload_range+'" name="upfile_'+upload_range+'" size="1" onkeypress="return handleKey(event);" value="" class="jsuFileInput"/></div></div>';
            up.appendChild(dv);
            upload_range++;
            up = null;
            dv = null;
            document.getElementById('files').style.display = 'block';
            var para = document.createElement('p');
            para.innerHTML = filteredName + '<img src="/images/cross.gif" class="deleteFileIco" onclick="removeFileMulti('+id+');"/>';
            para.className = 'filePara';
            para.id = 'para_' + id;
            para.style.background = 'url(../images/icons/' + extension + '.png) no-repeat 3px 2px';
            document.getElementById('files').insertBefore(para, document.getElementById('para_' + id));
        }
    }
    else {
        alert(lang.transl("LIMITUPLOAD"));
    }
}

function removeFileMulti(id) {
    var remove = document.getElementById('para_' + id);
    var remove2 = document.getElementById('con' + id);
    var old = document.getElementById('files');
    var old2 = document.getElementById('upload_slots_multi');
    old.removeChild(remove);
    old2.removeChild(remove2);
    alert(document.getElementById('lightwindow-content').innerHTML);
    max_upload_slots++;
}

function deleteFileMultiUpload(id) {
    var remove = document.getElementById('para_' + id);
    var remove2 = document.getElementById('con' + id);
    var old = document.getElementById('files');
    var old2 = document.getElementById('upload_slots');
    old.removeChild(remove);
    old2.removeChild(remove2);
    filesCount -= 1;
    if (filesCount == 0) {
        document.getElementById('files').style.display = 'none';
    }
}



function addSlot() {
    var element = document.createElement('div');
    element.id = 'con' + currentFile;
    element.className = 'con';
    var input = document.createElement('div');
    input.id = 'fileInputBox' + currentFile;
    var button = document.createElement('div');
    button.className = 'button btn2';
    var browse = document.createElement('a');
    browse.href = 'javascript:void(0);';
    browse.id = 'browseFile' + currentFile;
    var left = document.createElement('span');
    left.className = 'left';
    var center = document.createElement('span');
    center.className = 'center smaller';
    center.style.fontSize = '11px';
    center.innerHTML = 'Vybrat';
    var right = document.createElement('span');
    right.className = 'right';
    button.appendChild(browse);
    button.appendChild(left);
    button.appendChild(center);
    button.appendChild(right);
    var sel = document.createElement('div');
    sel.className = 'selectedFile';
    sel.id = 'selectedFile' + currentFile;
    sel.innerHTML = 'není vybrán soubor';
    var wrap = document.createElement('div');
    wrap.className = 'inputWrapper';
    wrap.innerHTML = '<input type="file" id="upfile_'+currentFile+'" name="upfile_'+currentFile+'" size="35" class="jsuFileInput" onchange="changeFileMulti('+currentFile+');"/>';
    input.appendChild(button);
    input.appendChild(sel);
    input.appendChild(wrap);
    element.appendChild(input);
    var parent = document.getElementById('upload_slots_multi');
    var before = document.getElementById('con' + (currentFile - 1));
    parent.insertBefore(element, before);
    document.getElementById('con' + (currentFile - 1)).style.display = 'none';
}

function changeFile() {
    var element = document.getElementById('selectedFile');
    var fileName = document.getElementById('fileInput').value;
    if (fileName != '') {
        var fileInputBox = document.getElementById('fileInputBox');
        var ext = fileName.substr(fileName.lastIndexOf('.') + 1, 4);
        extension = ext.toLowerCase();
        var extarr = ["avi", "bz2", "c", "cpp", "doc", "exe", "gif", "gz", "html", "img", "jpeg", "jpg", "js", "mp3", "mpeg", "mpg", "msi", "nfo", "pdf", "php", "png", "ppt", "psd", "rar", "rtf", "swf", "txt", "wav", "wma", "wmv", "xls", "zip"];
        if (extension == '') {extension = 'unknown';}
        else {
            var found = 0;
            for ( var i in extarr )
            {
                if (extarr[i] == extension) {
                    found = 1;
                    break;
                }
            }
            if(found == 0) {extension = 'unknown';}
        }
        element.style.paddingLeft = '25px';
        element.style.background = 'url(../images/icons/' + extension + '.png) no-repeat 3px 2px';
        var filteredName = fileName.substr(fileName.lastIndexOf('/') + 1);
        filteredName = fileName.substr(fileName.lastIndexOf('\\') + 1);
        if (filteredName.length > 30)
        filteredName = filteredName.substr(0, 30) + ' ...';
        element.innerHTML = filteredName;
    }
}

function changeAsc() {
    if (document.getElementById('hiddenAsc').value == 'ASC')
        document.getElementById('hiddenAsc').value = 'DESC';
    else
        document.getElementById('hiddenAsc').value = 'ASC';
}




function countDown(type, action, captchaCode){
    counterDiv = document.getElementById('countDown');
    line = document.getElementById('countDownLine');
    line = lang.transl("DOWNLOAD_WAIT_PART1") + '<span id="orange">' + waitSecs + "s.</span>"; //transl("DOWNLOAD_WAIT_PART2");

    if ( waitSecs > 0 ){
        waitSecs--;
        counterDiv.innerHTML = line;
        dlTimeOut = setTimeout('countDown(\''+type + '\', \''+action+'\', \''+captchaCode+'\');', 1000);
    } else {
        counterDiv.style.display = 'none';
        document.getElementById('countDown').style.display = 'none';
        if (document.getElementById('registered'))
            document.getElementById('registered').style.display = 'none';
        var params = 'captchaCode='+captchaCode+'&type='+type;
        var url = 'x-download/' + action;
        edisk.loadAjax(url, params, function(request) {
            document.getElementById('directLink').href = req.responseText;
            setTimeout(downloadDirectly(req.responseText), 1000);
        });
    }
}

function copy(text2copy) {
    if (window.clipboardData) {
        window.clipboardData.setData("Text",text2copy);
    }
    else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="http://www.edisk.cz/images/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
}

function selectbeforecopy(element)
{
    document.getElementById(element).focus();
    document.getElementById(element).select();
    copy(document.getElementById(element).value);
}


function startSlideShow() {
    previewImageLoaded++;
    if (previewImageLoaded == previewImageCount)
        setTimeout(nextPrevImg, 1000);
}

function nextPrevImg() {
    document.getElementById('previewImg_'+previewImageCurrent).style.display = 'none';
    if (previewImageCurrent < previewImageCount)
        previewImageCurrent++;
    else
        previewImageCurrent = 1;
    document.getElementById('previewImg_'+previewImageCurrent).style.display = 'inline';
    setTimeout(nextPrevImg, 1000);
}

function hideFolderContextMenu() {
    if (hide == true) {
        Q("#folderOptions").hide("fast");
        lastId = null;
    }
}

function moveFileToFolder(idFile, idFolder) {
    var params = 'idFile='+idFile;
    params += '&idFolder='+idFolder;
    var url = 'x-move-file-to-folder';
    edisk.loadAjax(url, params, function(request) {
        loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
        edisk.showMessage(request);
    });
}

function newFolder(){
    var newFolder = null
    var url = 'x-check-new-folder-name';

    if (document.getElementById('newFolderInput') && document.getElementById('newFolderInput').value != null)
        newFolder = document.getElementById('newFolderInput').value;
    else
        newFolder = null;

    if (newFolder == '' || newFolder == null) {alert(lang.transl("FOLDER_EMPTY"));return false;}
    var params = 'newFolder='+encodeURIComponent(newFolder);

    edisk.loadAjax(url, params, function(request) {
        submitNewFolder(request);
    });
    return true;
}

function goToFolder(id) {
    loadFileList(ownerId, id, 0);
}

function showFolderOptions(id) {
    hide = false;
    Q("#options").hide("fast");
    var element = document.getElementById('folderOptions');
    var clickEl1 = document.getElementById('folderOptionsItem1');
    var clickEl2 = document.getElementById('folderOptionsItem2');
    var clickEl3 = document.getElementById('folderOptionsItem3');
    var clickEl5 = document.getElementById('folderOptionsItem5');
    var elemId = id;

    clickEl1.onclick=function(){Q("#folderOptions").hide("fast");lastId = null;folderSettings(elemId, 'links');};
    clickEl2.onclick=function(){Q("#folderOptions").hide("fast");lastId = null;folderSettings(elemId, 'email');};
    clickEl3.onclick=function(){Q("#folderOptions").hide("fast");lastId = null;folderSettings(elemId, 'rename');};
    clickEl5.onclick=function(){dropFolder(elemId, '');};

    clickEl1.onmouseover=function(){hide=false;clickEl1.style.background = "#eaeaea";};
    clickEl1.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl1.style.background = "transparent url(../images/ico-gen-odkaz.gif) no-repeat 10px 50%";};
    clickEl2.onmouseover=function(){hide=false;clickEl2.style.background = "#eaeaea";};
    clickEl2.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl2.style.background = "transparent url(../images/ico-zas-email.gif) no-repeat 10px 50%";};
    clickEl3.onmouseover=function(){hide=false;clickEl3.style.background = "#eaeaea";};
    clickEl3.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl3.style.background = "transparent url(../images/ico-rename.gif) no-repeat 10px 50%";};
    clickEl5.onmouseover=function(){hide=false;clickEl5.style.background = "#eaeaea";};
    clickEl5.onmouseout=function(){hide = true;setTimeout('hideContextMenu()', 2000);clickEl5.style.background = "transparent url(../images/ico-smazat.gif) no-repeat 10px 50%";};

    var obj = document.getElementById('folderOption_'+id);
    var objOrig = obj;
    var elleft = eltop = i = 0;
    if(obj.offsetParent)
        while(1)
        {
          if (i<2)
                elleft += obj.offsetLeft;
          eltop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
          i++;
        }
    else if(obj.x) {
        elleft += obj.x;
        eltop += obj.y;
    }
    elleft += 26;
    eltop -= 10;
    if (objOrig.className == 'bottomOption') eltop -= 200;
    else eltop -= 120;
    
    element.style.left = elleft + 'px';
    element.style.top = eltop + 'px';

    if (Q("div").filter("#folderOptions").is(":visible")) {
        if (lastId == id) {
            Q("#folderOptions").hide("fast");
            lastId = null;
        }
        else {
            lastId = id;
        }
    }
    else {
        if (lastId == id) {
            Q("#folderOptions").hide("fast");
            lastId = null;
        }
        else {
            Q("#folderOptions").show("fast");
            lastId = id;
        }
    }
}


function folderSettings(id, type){
    var url = 'x-folder-'+type+'/'+id;
    var params = '';
    edisk.loadAjax(url, params, function(request) {
        if (type == 'rename' || type == 'email')
            edisk.showDialog(request, true);
        else
            edisk.showDialog(request);
        loadOrangeButton();
    });
}

function renameFolder(id, name){
    var newName = '';
    if (document.getElementById('name')) newName = document.getElementById('name').value;
    else newName = window.prompt(lang.transl("NEW_FOLDER_NAME"), name);

    if ( (newName != '') && (newName != name) && (newName != null) ){
        var url = 'x-rename-folder';
        var params = 'folderId='+encodeURIComponent(id)+'&newName='+encodeURIComponent(newName);
        edisk.loadAjax(url, params, function(request) {
            if (document.getElementById('name')) {
                edisk.hideDialog();
                loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
            }
            else {
                window.location = '/nastaveni-adresaru';
            }
        });
    }
}

function dropFolder(id, redir) {
    var params = 'folderid=' + id;
    var url = 'x-get-foldername';
    edisk.loadAjax(url, params, function(request) {
        request = request.replace( /\s/g, "" );

        if ( window.confirm(lang.transl("FOLDER_REMOVE1") + request + lang.transl("FOLDER_REMOVE2")) ){
            var url2 = 'x-drop-folder';
            var params2 = 'folderId='+encodeURIComponent(id);
            edisk.loadAjax(url2, params2, function(request) {
                if (redir != '')
                    window.location = redir;
                else
                    loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
            });
        }
    });
}

function sendFolderLink(id) {
    var email = encodeURIComponent(document.getElementById('contactEmail').value);
    if (email == null || email == '') {alert(lang.transl("EMAIL_EMPTY"));return false;}
    var params = '';
    params += '&folderId=' + id;
    params += '&contactEmail=' + email;

    var url = 'x-send-folder-link';
    edisk.loadAjax(url, params, function(request) {
        alert(request);
        edisk.hideDialog();
        edisk.showMessage(request);
    });
    return true;
}

function checkAllIncFolders(){
    var check = false;
    if ( document.getElementById('fCheckCtrl').checked ){
        check = true;
    }
    var cbA = document.getElementsByName('fileCheck[]');
    var cbF = document.getElementsByName('folderCheck[]');
    for (var i = 0; i < cbA.length; i++){
        cbA[i].checked = check;
        if (check){
            document.getElementById('row'+cbA[i].value).className = 'selRow';
        } else {
            if ( (i % 2) == 0 ){
                document.getElementById('row'+cbA[i].value).className = 'light';
            } else {
                document.getElementById('row'+cbA[i].value).className = 'dark';
            }
        }
    }
    for (var j = 0; j < cbF.length; j++){
        cbF[j].checked = check;
        if (check){
            document.getElementById('folder'+cbF[j].value).className = 'selRow';
        } else {
            if ( (j % 2) == 0 ){
                document.getElementById('folder'+cbF[j].value).className = 'light';
            } else {
                document.getElementById('folder'+cbF[j].value).className = 'dark';
            }
        }
    }
}

function doFolderAction(){
    var sb = document.getElementById('actionSelBox');
    var fArr = getChecked('fileCheck[]');
    var foldArr = getChecked('folderCheck[]');
    
    if (fArr.length < 1 && foldArr < 1){
        alert(lang.transl("NO_FILES_OR_FOLDERS"));
        return false;
    }
    if (sb[sb.selectedIndex].value != '0')
    switch(sb[sb.selectedIndex].value){
        case 'shareSelected':
            var cArr = getChecked('contactCheck[]');
            var cArrNE = getChecked('contactNotEdiskCheck[]');
            if (cArr.length < 1 && cArrNE.length < 1){
                alert(lang.transl("NO_CONTACT"));
                return false;
            }
            shareFiles();
            break;
        case 'sendLinkPerEmail':
            sendLinkPerEmail();
            break;
        case 'generateLink':
            getFileLinks();
            break;
        case 'unlink':
            if (fArr.length < 1 && foldArr >= 1) {
                if (!confirm(lang.transl("CONFIRM_MULTI_DELETE_FOLDERS")) ) return false;
            }
            else if (fArr.length >= 1 && foldArr < 1) {
                if (!confirm(lang.transl("CONFIRM_MULTI_DELETE")) ) return false;
            }
            else if (fArr.length >= 1 && foldArr >= 1) {
                if (!confirm(lang.transl("CONFIRM_MULTI_DELETE_BOTH")) ) return false;
            }
            deleteFilesAndFolders();
            break;
        default:
            folder();
            break;
    }
    return false;
}

function deleteFilesAndFolders(){
    var cbArray = getChecked('fileCheck[]');
    var foldArray = getChecked('folderCheck[]');
    if ( cbArray.length <= 0 && foldArray <= 0){
        return false;
    }

    var params = '';
    for(i = 0; i < cbArray.length; i++ ){
        params += '&fileCheck[]=' + cbArray[i];
    }
    var url = 'x-unlink-files/acc'+sessId;
    edisk.loadAjax(url, params, function(request) {
        var params = '';
        for(i = 0; i < foldArray.length; i++ ){
            params += '&folderCheck[]=' + foldArray[i];
        }
        var url = 'x-unlink-folders/acc'+sessId;
        edisk.loadAjax(url, params, function(request) {
            loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
            showMessage(request + ' ' + innerrequest);
        });
    });
    return true;
}

function folder(){
    var fArr = getChecked('fileCheck[]');
    var foldArr = getChecked('folderCheck[]');

    var sb = document.getElementById('actionSelBox');
    var url = 'x-move-folders-and-files/acc/'+sessId;

    var params = 'folder=' + sb[sb.selectedIndex].value;

    for (var i = 0; i < fArr.length; i++){
        params += '&fileCheck[]=' + fArr[i];
    }
    for (var j = 0; j < foldArr.length; j++){
        if (sb[sb.selectedIndex].value != foldArr[j])
            params += '&folderCheck[]=' + foldArr[j];
    }

    edisk.loadAjax(url, params, function(request) {
        loadFileList(ownerId, hiddenSelCatId, hiddenFromRecord, hiddenOrderBy, hiddenAsc);
        edisk.showMessage(request);
    });
}

function showTip(elemName){
    document.getElementById(elemName+'Tip').style.visibility = 'visible';
}

function hideTip(elemName){
    document.getElementById(elemName+'Tip').style.visibility = 'hidden';
}

function confirmDrop(){
    if ( window.confirm(lang.transl("CONFIRM_ACCOUNT_DROP")) ){
        document.getElementById('dropForm').submit();
    }
}

function deleteNotEdiskContact(id) {
    var value = confirm(lang.transl("CONFIRM_DELETE"));
    if (value) {
        var url = 'x-delete-not-edisk-contact';
        var params = 'id='+id;
        edisk.loadAjax(url, params, function(request) {
            window.location = '/nastaveni-kontaktu';
        });
    }
}

function renameLabel(id, name){
    var newName = window.prompt(lang.transl("NEW_NAME"), name);
    if ( (newName != '') && (newName != name) && (newName != null) ){
        var url = 'x-rename-label';
        var params = 'labelId='+encodeURIComponent(id)+'&newName='+encodeURIComponent(newName);
        edisk.loadAjax(url, params, function(request) {
            window.location = '/nastaveni-kategorii';
        });
    }
}

function dropLabel(id){

    var url = 'x-get-labelname';
    var params = 'labelId='+encodeURIComponent(id);
    edisk.loadAjax(url, params, function(request) {
        if ( window.confirm(lang.transl("LABEL_REMOVE1") + request.replace( /\s/g, "" )  + lang.transl("LABEL_REMOVE2")) ){
            var url_inner = 'x-drop-label';
            var params_inner = 'labelId='+encodeURIComponent(id);
            edisk.loadAjax(url_inner, params_inner, function(request) {
                window.location = '/nastaveni-kategorii';
            });
        }
    });
}

function renameGroup(id, name){
    var newName = window.prompt(lang.transl("NEW_NAME"), name);
    if ( (newName != '') && (newName != name) && (newName != null) ){
        var url = 'x-rename-group';
        var params = 'groupId='+encodeURIComponent(id)+'&newName='+encodeURIComponent(newName);
        edisk.loadAjax(url, params, function(request) {
            window.location = '/nastaveni-skupin';
        });
    }
}

function dropGroup(id){
    if ( window.confirm(lang.transl("GROUP_REMOVE")) ){
        var url = 'x-drop-group';
        var params = 'groupId='+encodeURIComponent(id);
        edisk.loadAjax(url, params, function(request) {
            window.location = '/nastaveni-skupin';
        });
    }
}

function dropUser(id, gid){
    if ( window.confirm(lang.transl("CONTACT_REMOVE")) ){
        var url = 'x-drop-user';
        var params = 'userId='+encodeURIComponent(id)+'&groupId='+encodeURIComponent(gid);
        edisk.loadAjax(url, params, function(request) {
            window.location = '/nastaveni-kontaktu';
        });
    }
}

function renameUser(id, gid, name){
    var newName = window.prompt(lang.transl("NEW_NAME"), name);
    if (newName == '') {alert(lang.transl("NO_CONTACT_NAME"));return false;}
    if ( (newName != '') && (newName != name) && (newName != null) ){
        var url = 'x-rename-user';
        var params = 'userId='+encodeURIComponent(id)+'&groupId='+encodeURIComponent(gid)+'&newName='+encodeURIComponent(newName);
        edisk.loadAjax(url, params, function(request) {
            window.location = '/nastaveni-kontaktu';
        });
    }
    return false;
}

function renameNotEdiskUser(id, name){
    var newName = window.prompt(lang.transl("NEW_NAME"), name);
    if (newName == '') {alert(lang.transl("NO_CONTACT_NAME"));return false;}
    if ( (newName != '') && (newName != name) && (newName != null) ){
        var url = 'x-rename-user-not-edisk';
        var params = 'userId='+encodeURIComponent(id)+'&newName='+encodeURIComponent(newName);
        edisk.loadAjax(url, params, function(request) {
            window.location = '/nastaveni-kontaktu';
        });
    }
    return false;
}

function checkPassEqual(){
    var pass1 = document.getElementById('passwd1').value;
    var pass2 = document.getElementById('passwd2').value;
    if ( pass1 != pass2 ){
        alert(lang.transl("PASS_NOT_MATCH"));
        return false;
    } else {
        return true;
    }
}

function showUpgradeOptions(){
    var atSel = document.userSettingsForm.accountType;
    var accType = document.getElementById('freeUser').value;
    var regToInd = document.getElementById('regToInd').checked;
    var regToCom = document.getElementById('regToCom').checked;
    var selType = atSel[document.userSettingsForm.accountType.selectedIndex].value;
    var display = '';

    if ( (selType == 'premium') ) {
        document.getElementById('accountSettings').style.display = 'none';
        document.getElementById('accountUpgrade').style.display = '';
        document.getElementById('regTo').style.display = display;
        document.getElementById('timePeriodDiv').style.display = display;
        document.getElementById('streetDiv').style.display = display;
        document.getElementById('cityDiv').style.display = display;
        document.getElementById('zipDiv').style.display = display;
        document.getElementById('countryDiv').style.display = display;
        if ( regToInd == true ){
            document.getElementById('indNameDiv').style.display = display;
        } else {
            document.getElementById('comNameDiv').style.display = display;
            document.getElementById('icDiv').style.display = display;
            document.getElementById('dicDiv').style.display = display;
        }
    } else {
        document.getElementById('accountUpgrade').style.display = 'none';
        document.getElementById('accountSettings').style.display = '';
    }

    if ( selType != accType ){
        document.getElementById('changeAccType').value = 1;
    } else {
        document.getElementById('changeAccType').value = 0;
    }
}

function switchFields(){
    var regToInd = document.getElementById('regToInd').checked;
    var display = '';
    if ( regToInd == true ){
        document.getElementById('comNameDiv').style.display = 'none';
        document.getElementById('icDiv').style.display = 'none';
        document.getElementById('dicDiv').style.display = 'none';
        document.getElementById('indNameDiv').style.display = display;
    } else {
        document.getElementById('indNameDiv').style.display = 'none';
        document.getElementById('comNameDiv').style.display = display;
        document.getElementById('icDiv').style.display = display;
        document.getElementById('dicDiv').style.display = display;
    }
}

function togglePrice(){
    var tps = document.getElementById('timePeriod');

    if ( tps[tps.selectedIndex].value == 'oneMonth' ){
        document.getElementById('price3').style.display = 'none';
        document.getElementById('price6').style.display = 'none';
        document.getElementById('price12').style.display = 'none';
        document.getElementById('price1').style.display = 'block';
        return true;
    }

    if ( tps[tps.selectedIndex].value == 'threeMonths' ){
        document.getElementById('price6').style.display = 'none';
        document.getElementById('price12').style.display = 'none';
        document.getElementById('price1').style.display = 'none';
        document.getElementById('price3').style.display = 'block';
        return true;
    }

    if ( tps[tps.selectedIndex].value == 'sixMonths' ){
        document.getElementById('price3').style.display = 'none';
        document.getElementById('price12').style.display = 'none';
        document.getElementById('price1').style.display = 'none';
        document.getElementById('price6').style.display = 'block';
        return true;
    }

    if ( tps[tps.selectedIndex].value == 'oneYear' ){
        document.getElementById('price6').style.display = 'none';
        document.getElementById('price3').style.display = 'none';
        document.getElementById('price1').style.display = 'none';
        document.getElementById('price12').style.display = 'block';
        return true;
    }
    return true;
}

function moveUser(groupid, id) {
    var url = 'x-move-user';
    var params= 'userId=' + id + '&groupSelect=' + groupid;
    
    edisk.loadAjax(url, params, function(request) {
        edisk.showMessage(request);
        setTimeout ( "edisk.reloadPage()", 700 );
    });
}

function checkElementEmpty(element, errMsg){
    if ( document.getElementById(element).value.length == 0 ){
        alert(errMsg);
        document.getElementById(element).select();
        return false;
    } else {
        return true;
    }
}

function checkPassLen(){
    if ( document.getElementById('passwd1').value.length < 5 ){
        alert(lang.transl("SHORT_PASS"));
        document.getElementById('passwd1').select();
        return false;
    } else {
        return true;
    }
}

function checkPassEqual(){
    var pass1 = document.getElementById('passwd1').value;
    var pass2 = document.getElementById('passwd2').value;
    if ( pass1 != pass2 ){
        alert(lang.transl("PASS_NOT_MATCH"));
            return false;
    } else {
        return true;
    }
}

function checkSettingsForm() {
    if (document.getElementById('freeUser').value == 'free')
    {
        if (document.getElementById('accountType').selectedIndex == 1)
        {
            if (!checkElementEmpty('displayName', lang.transl("NO_DISPLAY_NAME"))) return false;
            if ((document.getElementById('passwd1').value.length > 0) || (document.getElementById('passwd2').value.length > 0) || (document.getElementById('currentPasswd').value.length > 0))
            {
                if (!checkPassLen()) return false;
                if (!checkPassEqual()) return false;
            }
        }
        else if (document.getElementById('accountType').selectedIndex == 0)
        {
            if (document.getElementById('regToInd').checked) {
                if (!checkElementEmpty('indName', lang.transl("NO_NAME"))) return false;
            }
            else {
                if (!checkElementEmpty('comName', lang.transl("NO_COMPANY_NAME"))) return false;
            }
            if (!checkElementEmpty('street', lang.transl("NO_STREET"))) return false;
            if (!checkElementEmpty('city', lang.transl("NO_CITY"))) return false;
            if (!checkElementEmpty('zip', lang.transl("NO_POSTAL"))) return false;

            if (document.getElementById('regToCom').checked) {
                if (!checkElementEmpty('ic', lang.transl("NO_IC"))) return false;
                if (!checkElementEmpty('dic', lang.transl("NO_DIC"))) return false;
            }
        }
    }
    else {
        if (!checkElementEmpty('displayName', lang.transl("NO_DISPLAY_NAME"))) return false;
        if ((document.getElementById('passwd1').value.length > 0) || (document.getElementById('passwd2').value.length > 0) || (document.getElementById('currentPasswd').value.length > 0))
        {
            if (!checkPassLen()) return false;
            if (!checkPassEqual()) return false;
        }
    }

    var ret = window.confirm(lang.transl("REALLY_SAVE"));
    if (!ret) {
        return false;
    }
    document.getElementById('userSettingsForm').submit();
    return false;
}

function loadSettingsDrag() {
    

    Q(".tabulka .settings-box .item").draggable({
	containment: 'document',
	opacity: 0.6,
	revert: 'invalid',
	helper: 'clone',
	zIndex: 100
    });


    Q("td.underline").droppable({
        drop:
            function(e, ui)
            {
                var dropid = Q(this).attr('id');
                var groupid = parseInt(dropid.substr(11));
                var id = Q(ui.draggable).attr('id');
                var subid = '';
                if (id.substr(0, 5) == 'item_') {
                    subid = id.substr(5);
                    moveUser(groupid, subid);
                }
            }
    });
    
    /*
	var drop = $('draggable');
    var element = document.getElementById('setting-aray');
		$$('#draggable .item').each(function(item){

				item.addEvent('mousedown', function(e) {
					e = new Event(e).stop();

			 		$$('.underline').each(function(item){
			 			item.setStyles({'text-decoration': 'underline'});
			 		});
					var clone = this.clone()
						.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
						.setStyles({'opacity': 0.7, 'z-index': 10000, 'background-color': 'white', 'position': 'absolute', 'left': e.page.x + 80, 'top': e.page.y + 80, 'margin-left': '-50px', 'margin-top': '-60px', 'border': '3px solid #dc540a', 'padding': '5px', 'width': '150px', 'height': '15px'})
						.addEvent('emptydrop', function() {
							this.remove();
							drop.removeEvents();
						}).inject(document.body);

					drop.addEvents({
						'drop': function() {
							drop.removeEvents();
							clone.remove();
							$$('.underline').each(function(item){
					 			item.setStyles({'text-decoration': 'none'});
					 		});
							moveUser(currentDrop, item.id.substr(5));
						}
					});

					var drag = clone.makeDraggable({
						droppables: [drop]
					});
					drag.start(e);
				});


	 	}); */
}





/*
			var drop2 = $('groupWrapper');

			$$('td .item').each(function(item){

				item.addEvent('mousedown', function(e) {
					e = new Event(e).stop();

					var clone2 = this.clone()
						.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
						.setStyles({'opacity': 0.7, 'z-index': 10000, 'background-color': 'white', 'position': 'absolute', 'left': e.page.x + 80, 'top': e.page.y + 80, 'margin-left': '-50px', 'margin-top': '-60px', 'border': '3px solid #dc540a', 'padding': '5px', 'width': '150px', 'height': '15px'})
						.addEvent('emptydrop', function() {
							this.remove();

							clone2.remove();
							clone2 = null;
							drop2.removeEvents();

						}).inject(document.body);
                    var ele = clone2.getElementsByTagName('a');
                    if (ele[0].innerHTML.length > 20) ele[0].innerHTML = ele[0].innerHTML.substr(0, 20) + '...';
					drop2.addEvents({
						'drop': function() {

								drop2.removeEvents();

										// check element we dragged from
										ajaxCount = 0;
										item.parentNode.parentNode.getElementsByTagName('input')[0].checked = true;
										// check element we dropped onto
										currentDrop.getElementsByTagName('input')[0].checked = true;
										// share files

										var fArr = new Array();
										var cbA = document.getElementsByName('fileCheck[]');
										for(var i = 0; i < cbA.length; i++){
											if (cbA[i].checked){
												fArr[fArr.length] = cbA[i].value;
											}
										}

										var cArr = new Array();
										cbA = document.getElementsByName('contactCheck[]');
										for(i = 0; i < cbA.length; i++){
											if (cbA[i].checked){
												cArr[cArr.length] = cbA[i].value;
											}
										}

										var cArrNE = new Array();
										cbA = document.getElementsByName('contactNotEdiskCheck[]');
										for(i = 0; i < cbA.length; i++){
											if (cbA[i].checked){
												cArrNE[cArrNE.length] = cbA[i].value;
											}
										}

										if (cArr.length >= 1 && ajaxCount == 0) {
											var params = '' ;
											for (i = 0; i < fArr.length; i++){
												params += '&fileCheck[]=' + fArr[i];
											}

											for (i = 0; i < cArr.length; i++){
												params += '&contactCheck[]=' + cArr[i];
											}

											var url = ed_basename+'/x-new-acl-entry/acc/'+sessId;
											document.getElementById('loadingDiv').style.visibility = 'visible';

											clone2.remove();
											clone2 = null;
											ajaxCount++;

											var req = new Ajax(url, {postBody: params, onComplete: showResponse, update: ''}).request();

										}

										if (cArrNE.length >= 1) {

											params = '';
											for (i = 0; i < fArr.length; i++){
												params += '&fileCheck[]=' + fArr[i];
											}

											for (i = 0; i < cArrNE.length; i++){
												params += '&contactNotEdiskCheck[]=' + cArrNE[i];
											}

											clone2.remove();
											clone2 = null;
											ajaxCount++;

											url = ed_basename+'/x-send-links-not-edisk-mail';
											document.getElementById('loadingDiv').style.visibility = 'visible';

											req = new Ajax(url, {postBody: params, onComplete: showResponse, update: ''}).request();
										}
										function showResponse(request) {
												document.getElementById('loadingDiv').style.visibility = 'hidden';
												showMessage(request);
										}
										// share files
										item.parentNode.parentNode.getElementsByTagName('input')[0].checked = false;
										currentDrop.getElementsByTagName('input')[0].checked = false;

								if (clone2 != null) {
									clone2.remove();
									clone2 = null;
								}
								currentDrop = null;

						}
					});

					var drag2 = clone2.makeDraggable({
						droppables: [drop2]
					});
					drag2.start(e);
			});
	 	});*/


function loadDeleteDrag() {
/*
			

                    var ele2 = clone3.getElementsByTagName('a');
                    if (ele2[0].innerHTML.length > 20) ele2[0].innerHTML = ele2[0].innerHTML.substr(0, 20) + '...';

					drop3.addEvents({
						'drop': function() {

								drop3.removeEvents();

								item.parentNode.parentNode.getElementsByTagName('input')[0].checked = true;

								var fArr = new Array();
								var cbA = document.getElementsByName('fileCheck[]');
								for(var i = 0; i < cbA.length; i++){
									if (cbA[i].checked){
										fArr[fArr.length] = cbA[i].value;
									}
								}

								if (typeof(clone) != "undefined") {
									clone.remove();
									clone = null;
								}
								if (typeof(clone2) != "undefined") {
									clone2.remove();
									clone2 = null;
								}
								if (typeof(clone3) != "undefined") {
									clone3.remove();
									clone3 = null;
								}

								for (var j = 0; j < fArr.length; j++){
									deleteFile(fArr[j]);
								}




								item.parentNode.parentNode.getElementsByTagName('input')[0].checked = false;



						}
					});

					var drag3 = clone3.makeDraggable({
						droppables: [drop3]
					});
					drag3.start(e);
			});
	 	});*/
}
