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

var BackUpList = window.getElementByName("transfermanagerlistui");
var BackUpFinishedList = window.getElementByName("transferfinishedlistui");
var BackUpFinishedListUp = window.getElementByName("transferupfinishedlistui");
var BackupManager = new IBackupWndManager();
var ChooseComboState = window.getElementByName("backup_choosecombo");

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

    }
    else if ("click" == b) {
        if (a == "view_button") {
            BackupManager.doAction(BackUpList, TransUIAction_OpenFile);//www 2015.10.22 ¹¦ÄÜ²»´æÔÚ
        }
        else if (a == "paly_button" || a == "paly_op") {
            BackupManager.doAction(BackUpList, TransUIAction_Start, false);
        }
        else if (a == "stop_button" || a == "stop_op") {
            BackupManager.doAction(BackUpList, TransUIAction_Stop);
        }
         else if (a == "Cancel_button") {
             BackupManager.doAction(BackUpList, TransUIAction_Delete);
         }
        else if (a == "Redo_button") {
            BackupManager.doAction(BackUpList, TransUIAction_Start);
        }
//         else if (a == "Vip_link") {
//             window.shellExecute("open","http://epay.21cn.com/initOrder.do?productID=P20130116121717796", "", "", SW_SHOWNOACTIVATE);
//         }
//         else if (a == "open_file_button") {            
//                 if (BackUpList.isVisible()) 
//                 {
//                     BackupManager.doMenuAction(BackUpList, TransmissionAction_Open,ACTION_FILE);
//                 }
//                 else 
//                     BackupManager.doMenuAction(BackUpFinishedList, TransmissionAction_Open,ACTION_FILE);
//         }//www 2015.05.28
//         else if (a == "open_folder_button") {            
//                 if (BackUpList.isVisible()) 
//                 {
//                     BackupManager.doMenuAction(BackUpList, TransmissionAction_Open,ACTION_FOLDER);
//                 }
//                 else 
//                     BackupManager.doMenuAction(BackUpFinishedList, TransmissionAction_Open,ACTION_FOLDER);      
//         }//www 2015.05.29
    }
}

function OnClick(obj) {
        if (BackUpList.isVisible()) 
        {
            if (obj.getName() == "deletetransferbtn"/* || obj.getName() == "all_delete"*/)
            {
                BackupManager.doMenuAction(BackUpList, TransUIAction_Delete);
            }
            else if (obj.getName() == "startbtn" )
            {
                BackupManager.doMenuAction(BackUpList, TransUIAction_Start);
            }
            else if(obj.getName() == "all_start")
            {
                BackupManager.doAction(BackUpList, TransUIAction_StartAll);
            }
            else if (obj.getName() == "pausebtn")
            {
                BackupManager.doMenuAction(BackUpList, TransUIAction_Stop);
            }
            else if(obj.getName() == "all_pause")
            {
                BackupManager.doAction(BackUpList, TransUIAction_StopAll);
            }
            else if (obj.getName() == "retrybtn") 
            {
                BackupManager.doMenuAction(BackUpList, TransUIAction_Retry);
            }
            else if (obj.getName() == "deletetransferbtn1") 
            {
                BackupManager.doMenuAction(BackUpList, TransUIAction_Delete);
            }
        }
        else 
            {
            if (obj.getName() == "deletetransferbtn"/* || obj.getName() == "all_delete1" || obj.getName() == "all_delete2"*/) {
                BackupManager.doMenuAction(BackUpFinishedList, TransUIAction_Delete);
            }
            else if (obj.getName() == "deletetransferbtn1") {
                BackupManager.doMenuAction(BackUpFinishedList, TransUIAction_Delete);
            }
            }  

//     else if (obj.getName() == "ClearHistory") {
//         BackupManager.clearComplete();
//     }
}

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