var buttons = window.getElementsByClassName("ButtonUI");
for (var i = 0; i < buttons.length; i++) {
    buttons[i].OnClick = "OnClick";
}

var TransUpList = window.getElementByName("transferuplist");
var TransDownList = window.getElementByName("transferdownloadlist");
var TransFinishedList = window.getElementByName("transferfinishedlist");
var BackupManager = new IBackupWndManager();

function WndNotify(a, b) {
    if (b == "windowinit") {

    }
    else if ("click" == b)
    {
        if (a == "paly_button" || a == "paly_op") {
            if (TransUpList.isVisible())
                BackupManager.doAction(TransUpList, TransUIAction_Start, false);
            else if(TransDownList.isVisible())
                BackupManager.doAction(TransDownList, TransUIAction_Start, false);
        }
        else if (a == "stop_button" || a == "stop_op") {
            if (TransUpList.isVisible())
                BackupManager.doAction(TransUpList, TransUIAction_Stop);
            else if(TransDownList.isVisible())
                BackupManager.doAction(TransDownList, TransUIAction_Stop);
        }
        else if (a == "Cancel_button") {
             BackupManager.doAction(TransUpList, TransUIAction_Delete);
        }
    }
}

function OnClick(obj) {
        if (TransUpList.isVisible() || TransDownList.isVisible())
        {
            if(obj.getName() == "all_start")
            {
                BackupManager.doAction(TransUpList, TransUIAction_StartAll);
            }
            else if(obj.getName() == "all_pause")
            {
                BackupManager.doAction(TransUpList, TransUIAction_StopAll);
            }
            else if (obj.getName() == "all_start1")
            {
                BackupManager.doAction(TransDownList, TransUIAction_StartAll);
            }
            else if (obj.getName() == "all_pause1")
            {
                BackupManager.doAction(TransDownList, TransUIAction_StopAll);
            }
        }
        else 
        {
        }  
}

function OnMenuClick(a) {
    if (a == "menu_backup_selectall") {
        if (TransUpList.isVisible()) {
            TransUpList.selectAllItems();
        }
        else if (TransDownList.isVisible())
            TransDownList.selectAllItems();
        else
            TransFinishedList.selectAllItems();
    }
    else if (a == "menu_backup_fresh") {        
        if (TransUpList.isVisible()) {
            TransUpList.needFreshData(true);
        }
        else if (TransDownList.isVisible())
            TransDownList.needFreshData(true);
        else
            TransFinishedList.needFreshData(true);
    }
    else if (a == "menu_backup_openfile") {
        if (TransUpList.isVisible()) 
        {
            BackupManager.doMenuAction(TransUpList, TransUIAction_OpenFile);
        }
        else if (TransDownList.isVisible())
            BackupManager.doMenuAction(TransDownList, TransUIAction_OpenFile);
        else             
            BackupManager.doMenuAction(TransFinishedList, TransUIAction_OpenFile);
    }
    else if (a == "menu_backup_openfolder") {
        if (TransUpList.isVisible()) 
        {
            BackupManager.doMenuAction(TransUpList, TransUIAction_OpenFolder);
        }
        else if (TransDownList.isVisible())
            BackupManager.doMenuAction(TransDownList, TransUIAction_OpenFolder);
        else 
            BackupManager.doMenuAction(TransFinishedList, TransUIAction_OpenFolder);
    }
    else if (a == "menu_backup_pause") {
        if (TransUpList.isVisible()) 
        {
            BackupManager.doMenuAction(TransUpList, TransUIAction_Stop);
        }
        else if (TransDownList.isVisible())
            BackupManager.doMenuAction(TransDownList, TransUIAction_Stop);
        else 
            BackupManager.doMenuAction(TransFinishedList, TransUIAction_Stop);
    }
    else if (a == "menu_backup_play") {
        if (TransUpList.isVisible()) 
        {
            BackupManager.doMenuAction(TransUpList, TransUIAction_Start);
        }
        else if (TransDownList.isVisible())
            BackupManager.doMenuAction(TransDownList, TransUIAction_Start);
        else
            BackupManager.doMenuAction(TransFinishedList, TransUIAction_Start);
    }
    else if (a == "menu_backup_cancel") {
        if (TransUpList.isVisible()) 
        {
            BackupManager.doMenuAction(TransUpList, TransUIAction_Delete);
        }
        else if (TransDownList.isVisible())
            BackupManager.doMenuAction(TransDownList, TransUIAction_Delete);
        else 
            BackupManager.doMenuAction(TransFinishedList, TransUIAction_Delete);
    }
    else if (a == "menu_backup_redo") {
        if (TransUpList.isVisible()) 
        {
            BackupManager.doMenuAction(TransUpList, TransUIAction_Start);
        }
        else if (TransDownList.isVisible())
            BackupManager.doMenuAction(TransDownList, TransUIAction_Start);
        else
            BackupManager.doMenuAction(TransFinishedList, TransUIAction_Start);
    }
    
}