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

var PathEdit = window.getElementByName("SyncPath");
var btn_ok = window.getElementByName("SyncOK");
var caution_text = window.getElementByName("caution_text");

var WizardManager = new IWizardManager();
function OnClick(obj) {
    if (obj.getName() == "ViewPath") {
        var strPath = window.selectDir("选择同步目录", "", BIF_RETURNONLYFSDIRS |BIF_USENEWUI | BIF_UAHINT);
        if (strPath != 0) {
            var bOpen = WizardManager.judgeFileExent(strPath);
            PathEdit.setText(strPath);
            if (bOpen) {
                
                btn_ok.setEnabled(true);
                caution_text.setVisible(false);
            }
            else
            {
                btn_ok.setEnabled(false);
                caution_text.setVisible(true);
            }
        }

    }
    else if (obj.getName() == "SyncOK") {
        var strPath = PathEdit.getText();       
        var bHasfile = WizardManager.hasFile(strPath);
        if (bHasfile == true) {
          var nRetID = window.messageBox("您选的文件夹下已经有文件了，将它们也上传到天翼云盘服务器吗？", "天翼云盘", MB_YESNO | MB_ICONQUESTION);
          if (nRetID == IDYES) {
                WizardManager.doSaveSyncFolder(strPath);
                window.closeWnd();
          }
        }
        else
        {
           WizardManager.doSaveSyncFolder(strPath);
           window.closeWnd();
        }       
        
    }
    else if (obj.getName() == "closebtn") {
        window.closeWnd();
    }
}
