﻿// JavaScript Document
var LmsAPI = null;
var scoToTest = null;
var scoWin = null;
var modalWindow = null;
var oldSet_activeTabIndex;
var newTabIndex;
var tabBehavior;
var isLcms = false;
var wrapperTargetFunction = null;
var CommitedMessage = null; //*** Used in DirectLauncher - using Firefox window cannot be closed by javascript (if opened by link)

function initApi(scoID,scoUrl,LcmsID, LanguageID, strTheme, strAllreadyOpened){
    if (LmsAPI == null) {
        DetectBrowser();
        LmsAPI = new LMSApi();
        LmsAPI.setIsBrowserNetscape(Netscape);

        isLcms = (LcmsID != null);
        scoWin = window.open("../System/htmPages/SCOWrapper.htm?v1");
        LmsAPI.startTest(scoID, scoUrl, LcmsID, LanguageID, strTheme);
        setTimeout("CheckScoWinExists()", 50); //QC 59295
    }
    else if(strAllreadyOpened) {
        alert(strAllreadyOpened);
    }
}

function initApiDirect(scoID, scoUrl, LcmsID, LanguageID, strTheme, strCommitedMessage) {
    if (LmsAPI == null) {
        DetectBrowser();
        LmsAPI = new LMSApi();
        LmsAPI.setIsBrowserNetscape(Netscape);

        isLcms = (LcmsID != null);
        scoWin = this.window;
        CommitedMessage = strCommitedMessage;

        LmsAPI.startTest(scoID, scoUrl, LcmsID, LanguageID, strTheme);
    }
}


function CheckScoWinExists(objWindow) {
    if(scoWin == null || (typeof (scoWin) == "undefined") || (typeof (scoWin.location.hash) != "string")) {
        //
        // Something happened or a false positive of a popup blocker
        if(strPopUpBlocked != "undefined") {
            alert(strPopUpBlocked);
        }
        LmsAPI = null;
    }
}
  
function launchSCO(scoLoc){
    if(scoLoc)
    {
        scoToTest = scoLoc;
    }
    if(scoWin)
    {
        if(scoWin.launchSCO)
        {
            scoWin.launchSCO();
        }
        else
        {
            window.setTimeout("launchSCO()", 200);
        }
    }
}

function launchDocument(strUrl, width, height, arrCollNames, strCompleted) {
  var strOptions = "width=" + width + ",height=" + height + ",resizable=1";
  var docWin = window.open(strUrl, "DocumentWindow", strOptions);
  //if (docWin.focus!="undefined") { docWin.focus() }

  //Set status to 'completed', in completion collumns
  for (var i = 0; i < arrCollNames.length; i++) {
      var oCompleted = document.getElementById(arrCollNames[i]);
      if(oCompleted) {
          oCompleted.innerHTML = strCompleted;
      }
  }
}

function functionWrapper(oRetVal) {
    if(wrapperTargetFunction != null) {
        wrapperTargetFunction(oRetVal);
    }
}

function loadingData() {
    var oImg = document.getElementById("loadingGif");
    if (oImg == undefined)
    {
        var oImg = document.createElement("img");
    }
    oImg.id = "loadingGif"
    oImg.src = "../System/graphics/icons/loading.gif";
    oImg.style.position = "absolute";
    oImg.style.zIndex = 1000;
    //*** Position loading icon correctly if page is scrolled
    var scrollTop;
    if(document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    }
    else{
        scrollTop = document.body.scrollTop;
    }
    oImg.style.top = (scrollTop + window.document.documentElement.clientHeight / 2) + "px";
    oImg.style.left = "50%";
    document.body.appendChild(oImg);
}

function loadingFinished()
{
    var oImg = document.getElementById("loadingGif");
    if(oImg != null) {
        document.body.removeChild(oImg);
    }
}

function scoWinClosed() {
    if ((LmsAPI != null) && (LmsAPI.sendingCmiData == true))
    {
        window.setTimeout("scoWinClosed()", 100)
    }
    else {
        if((scoWin!=null)&&(scoWin.closed)) {
            LmsAPI = null;
            scoWin = null;
            window.location.reload();
            
        }
        else { // if (scoWin!="undefined" && (scoWin != null) && (!scoWin.scoLoaded))
            window.setTimeout("scoWinClosed()", 100);
        }
    }
}

//*** Called From DirectLauncher
//*** <Task>Close window when SCORM data has been sent</Task>
function closeScoWin() {
    if ((LmsAPI != null) && (LmsAPI.sendingCmiData == true)) {
        window.setTimeout("closeScoWin()", 100)
    }
    else {
        window.close()
        if (CommitedMessage != null) {
            //*** Firefox won't close a window than wasn't opened by script
            //*** If window not closed - display commitmessage and clear content
            window.setTimeout("testWinClosed()", 500)
        }
    }
}

function testWinClosed() {
    showCommitedMessage(CommitedMessage);
}

//Used to prompt User to save or discard before navigating away from formview
function OpenModalWindow(wndHeight,wndWidth,Title,message,Buttons,RefElement,oEvent) {
	var X = 0;
	var Y = 0;

	//If validation is used on page, check if page is valid before continuing.
	if(typeof(Page_Validators)!="undefined"){
        Page_ClientValidate();
        if(!Page_IsValid){
            return false;
        }
	}

    var oSrcElement;
    
    if(!oEvent)
    {
    	oEvent = window.event;
    }
    
    if(oEvent.srcElement)
    {
        oSrcElement = oEvent.srcElement;
    }
    else if(oEvent.target)
    {
        oSrcElement = oEvent.target;
    }
	
	var strScrElement = "";

	if(oSrcElement.id!=RefElement){
	    if(!oSrcElement.id){ //gives id to formview paging links
	        oSrcElement.id = "tempID"
	    }
	    strScrElement = oSrcElement.id;
	}

    if(modalWindow==null||(typeof(modalWindow)=="object"&&modalWindow.closed==true)){
	    if (screen.availWidth){
		    X = (screen.availWidth / 2) - (wndWidth / 2);
		    Y = (screen.availHeight / 2) - (wndHeight / 2);
	    }
        var bOnlyOne = true;
	    
	   var bIsFormview = RefElement.indexOf("FormView")>-1;
	   var bIsPagingLink = false;

	   if(oSrcElement.href){
	        bIsPagingLink = oSrcElement.href.indexOf("Page$")>-1;
	   }

	   if(!bIsFormview||bIsFormview&&bIsPagingLink){
           modalWindow = window.open("","","left=" + X + "screenX=" + X + "screenY=" + Y + ",top=" + Y + ",toolbar=0,scrollbars=0,resizable=0,location=0,height=" + wndHeight + ",width=" + wndWidth);
           modalWindow.document.open();
           modalWindow.document.write('<html>');
           modalWindow.document.write('<head>'); 
           modalWindow.document.write('<title>' + Title + '</title>');
           modalWindow.document.write('<link href="../System/css/modalDialog.css" rel="stylesheet" type="text/css" />')
           modalWindow.document.write('<script language="JavaScript">');
           modalWindow.document.write('function CloseForm(Response) ');
           modalWindow.document.write('{ ');
           modalWindow.document.write('window.opener.modalWindowResult(Response,"'+RefElement+'","'+strScrElement+'");');
           modalWindow.document.write(' window.close(); ');
           modalWindow.document.write('} ');
           modalWindow.document.write('</script>');   
           modalWindow.document.write('</head>');  
           modalWindow.document.write('<body onblur="window.focus();">');
           modalWindow.document.write('<div>' + message + '</div><br>');
           modalWindow.document.write('<div align="center">');
           var iCounter = Buttons.length;
           for(var i=0;i<Buttons.length;i++){
                if(i==0){
                     modalWindow.document.write('<input type="submit" value="'+Buttons[i]+'" id='+iCounter+' onclick="CloseForm(this.id);">');
                }
                else{
                    modalWindow.document.write('<input type="button" value="'+Buttons[i]+'" id='+iCounter+' onclick="CloseForm(this.id);">');
                }
                iCounter--;
           }
           
           modalWindow.document.write('<input type="button" value="Cancel" id=0 onclick="CloseForm(this.id);">');
           modalWindow.document.write('</div>');
           modalWindow.document.write('</body>');
           modalWindow.document.write('</html>'); 
           modalWindow.document.close(); 
           modalWindow.focus();            
           return false;
        }
        else{
            return true;
        }
    }
    else
    {
        return true;
    }
}

function ConfirmDialogWithOptions(wndHeight, wndWidth, Title, message, Buttons, RefElement, oEvent, cssRelPath, strConfirmMessage, arrConfirm) {
	var X = 0;
	var Y = 0;

	if (strConfirmMessage) {
	    confirmMessage = strConfirmMessage;
	}

	if (arrConfirm) {
	    arrValuesToConfirm = arrConfirm;
	}

	//If validation is used on page, check if page is valid before continuing.
	if(typeof(Page_Validators)!="undefined"){
        Page_ClientValidate();
        if(!Page_IsValid){
            return false;
        }
	}
	
	var oSrcElement;

    if(!oEvent)
    {
    	oEvent = window.event;
    }

    if(oEvent.srcElement)
    {
        oSrcElement = oEvent.srcElement;
    }
    else if(oEvent.target)
    {
        oSrcElement = oEvent.target;
    }
	
	var strScrElement = "";

	if(oSrcElement.id!=RefElement){
	    if(!oSrcElement.id){ //gives id to formview paging links
	        oSrcElement.id = "tempID"
	    }
	    strScrElement = oSrcElement.id;
	}

    if(modalWindow==null||(typeof(modalWindow)=="object"&&modalWindow.closed==true)){
        if (screen.availWidth){
            X = (screen.availWidth / 2) - (wndWidth / 2);
            Y = (screen.availHeight / 2) - (wndHeight / 2);
        }

        modalWindow = window.open("","","left=" + X + "screenX=" + X + "screenY=" + Y + ",top=" + Y + ",toolbar=0,scrollbars=0,resizable=0,location=0,height=" + wndHeight + ",width=" + wndWidth);
        modalWindow.document.open();
        modalWindow.document.write('<html>');
        modalWindow.document.write('<head>'); 
        modalWindow.document.write('<title>' + Title + '</title>');
        var strPath = "../";
        if(cssRelPath)
        {
            strPath = cssRelPath;
        }
        modalWindow.document.write('<link href="' + strPath + 'System/css/modalDialog.css" rel="stylesheet" type="text/css" />')
        modalWindow.document.write('<script language="JavaScript">');
        modalWindow.document.write('function CloseForm(Response) ');
        modalWindow.document.write('{ ');
        modalWindow.document.write('window.opener.modalWindowResult(Response,"' + RefElement + '","' + strScrElement + '");');
        //modalWindow.document.write('window.close(); ');
        modalWindow.document.write('} ');
        modalWindow.document.write('</script>');   
        modalWindow.document.write('</head>');  
        modalWindow.document.write('<body onblur="window.focus();">');
        modalWindow.document.write('<div>' + message + '</div><br>');
        modalWindow.document.write('<div align="center">');
        var iCounter = Buttons.length;
        var bCancelButtonIsInArray = false;
        for(var i=0;i<Buttons.length;i++){
            if (i == 0) {
                if (typeof (Buttons[i])== "object") {
                    modalWindow.document.write('<input type="button" value="' + Buttons[i][0] + '" id=' + Buttons[i][1] + ' onclick="CloseForm(this.id);">');
                }
                else {
                    modalWindow.document.write('<input type="button" value="' + Buttons[i] + '" id=' + iCounter + ' onclick="CloseForm(this.id);">');
                }
            }
            else {
                if (typeof (Buttons[i]) == "object") {
                    if (Buttons[i][1] == 0) //cancel button
                    {
                        modalWindow.document.write('<input type="button" value="' + Buttons[i][0] + '" id=0 onclick="CloseForm(this.id);">');
                        bCancelButtonIsInArray = true;
                    }
                    else {
                        modalWindow.document.write('<input type="button" value="' + Buttons[i][0] + '" id=' + Buttons[i][1] + ' onclick="CloseForm(this.id);">');
                    }
                }
                else {
                    modalWindow.document.write('<input type="button" value="' + Buttons[i] + '" id=' + iCounter + ' onclick="CloseForm(this.id);">');
                }
            }
            iCounter--;
        }

        if(!bCancelButtonIsInArray)
        {
            modalWindow.document.write('<input type="button" value="Cancel" id=0 onclick="CloseForm(this.id);">');
        }
        modalWindow.document.write('</div>');
        modalWindow.document.write('</body>');
        modalWindow.document.write('</html>'); 
        modalWindow.document.close(); 
        modalWindow.focus();            
        return false;
    }
    else
    {
        return true;
    }
}

var confirmMessage = null;
var arrValuesToConfirm = null;

function modalWindowResult(retVal, RefElement, strScrElement) {

	var oMsgBoxResult = document.getElementById("msgBoxResult");
	if (oMsgBoxResult == null){
	    oMsgBoxResult = document.createElement("input");
	    oMsgBoxResult.type = "hidden";
	    oMsgBoxResult.name = "msgBoxResult";
	    oMsgBoxResult.id = "msgBoxResult";
		document.forms[0].appendChild(oMsgBoxResult);
    }

    //Array of values that needs an extra confirm dialog
    if (arrValuesToConfirm != null) {
        var bConfirmNeeded = false;
        for (var i = 0; i < arrValuesToConfirm.length; i++) {
            //If selected value is in arrValuesToConfirm - confirm is needed
            if (arrValuesToConfirm[i] == retVal) {
                bConfirmNeeded = true;
            }
        }
        if (confirmMessage != null && bConfirmNeeded) {
            //Displaying confirm dialog
            var bDelete;
            if (modalWindow.closed) {
                 bDelete = window.confirm(confirmMessage);
            }
            else { //window is not closing properly the second time you get a confirmdialog
                bDelete = modalWindow.confirm(confirmMessage);
            }
            if (!bDelete) {
                retVal = 0;
            }
        }
    }

    modalWindow.close();
    modalWindow = null;
    oMsgBoxResult.value = retVal;

    if(retVal>0)
    {
        if(tabBehavior!=null) //changing tab
        {
            Page_ClientValidate();
            if(Page_IsValid){
                tabBehavior.set_activeTabIndex = oldSet_activeTabIndex;
                oldSet_activeTabIndex = null;
                tabBehavior.set_activeTabIndex(newTabIndex);
                newTabIndex = null;
                tabBehavior = null;
            }
        }
        else
        {
            var oElement = document.getElementById(RefElement);
            if(strScrElement!=""){
                var oAttrColl = oElement.attributes;
                oAttrColl.removeNamedItem("onclick");
                var oSrcElement = document.getElementById(strScrElement);
                if(oSrcElement.href){
                    eval(oSrcElement.href);
                }
            }
            else if (RefElement != "") {
            
            var arrOnClick = oElement.attributes["onclick"].value.split(";");
            oElement.attributes["onclick"].value = "";
                for(var i=1;i<arrOnClick.length;i++){
                    if (arrOnClick[i] != "") {
                        oElement.attributes["onclick"].value += arrOnClick[i] + ";"
                    }
                }
                if(oElement.attributes["onclick"].value==""){
                    var oAttrColl = oElement.attributes;
                    oAttrColl.removeNamedItem("onclick");
                }
                if(oElement.attributes["onclick"] && oElement.attributes["onclick"].value.indexOf("javascript:")>-1){
                    eval(oElement.attributes["onclick"].value);
                }
                else{
                    oElement.click();
                }
            }       
        }
    }
}

/*********** Open window and write content **************/
// Need to open window prior to webmethod call
// if opened on callback google will block the window
var _NewWin;
function openWindow(iWidth, iHeight) {
    if ((!_NewWin||_NewWin.closed)&&iWidth) {
        _NewWin = window.open('about:blank', 'HtmlWin', 'width=' + iWidth + ',height=' + iHeight + ',resizable=1');
    }
}

function writeContentToWindow(strHtml) {
    if (strHtml) {
        var doc = _NewWin.document;
        doc.open('text/html');
        doc.write(strHtml);
        doc.close();
        if (window.focus) { _NewWin.focus() }
    }
}

/***************************************************/

function PopupPicker(ctl,w,h)
{
    var PopupWindow=null;
    settings='width='+ w + ',height='+ h + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
    PopupWindow=window.open('../DatePicker.aspx?Ctl=' + ctl,'DatePicker', settings);
    PopupWindow.focus();
}

function selectItemTryDelete(strElement, arrExceptions)
{
    var retval = true;
    var oElement = document.getElementById(strElement);
    for(var i=0; i < arrExceptions.length; i++)
    {
        var strErrorMessage = arrExceptions[i][0];
        var arrErrorIdx = arrExceptions[i][1];

        for(var j=0; j < arrErrorIdx.length; j++)
        {
            if(oElement.selectedIndex == arrErrorIdx[j])
            {
                alert(strErrorMessage);
                retval = false;       
            }
        }
    }
    return retval;
}

var oImageVindow = null; 

function openImageViewer(strUrl)
{
    strSettings='width=500,height=400,location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,dependent=no';
	oImageVindow = window.open(strUrl,"ImageWindow", strSettings);
	oImageVindow.focus();
}

function hideTimeSelector(strSelector, strTextbox)
{
    var oSelector = document.getElementById(strSelector);
    var oTextBox = document.getElementById(strTextbox);
    if(oSelector.selectedIndex > -1)
    {
        oTextBox.value = oSelector.options[oSelector.selectedIndex].text;
        oTextBox.focus();
    }
    oSelector.selectedIndex = -1;
    oSelector.style.visibility = "hidden";
    document.onclick = "";
}

function toggleTimeSelector(strSelector, strTextbox, oEvent)
{
    var oSelector = document.getElementById(strSelector);
    var oTypedText = document.getElementById(strTextbox);
    var strTypedText = oTypedText.value
    
    if(strTypedText!="")
    {
        var currOptionText;
        for(var i=0;i<oSelector.options.length; i++)
        {
            currOptionText = oSelector.options[i].text;
            if(currOptionText.indexOf(strTypedText)==0)
            {
                oSelector.selectedIndex = i;
                oTypedText.value = currOptionText;
                break;
            }
        }
    }
  
    if(oSelector.style.visibility == "hidden")
    {
        oSelector.style.visibility = "visible";
    }
    else
    {
        oSelector.style.visibility = "hidden";
    }
    
    if(!oEvent)
    {
        oEvent = window.event;
        oEvent.cancelBubble = true;
    }
    else if(oEvent.stopPropagation)
    {
        oEvent.stopPropagation();
    }
    
    document.onclick = function()
    {
        hideTimeSelector(strSelector,strTextbox);
    }
}

    function togglePanel(oImgButton, strPanelID)
    {
        var oPanel = document.getElementById(strPanelID);
        oPanel.className = (oPanel.className == "PanelHidden") ? "PanelVisible" : "PanelHidden";
        oImgButton.src = (oPanel.className == "PanelHidden") ? "../System/graphics/icons/plus.gif" : "../System/graphics/icons/minus.gif"
    }
    
    function toggleEnabled(strOverLayElement)
    {
        var overLay = document.getElementById(strOverLayElement);
        var currVisibility = overLay.style.visibility;
        overLay.style.visibility = (currVisibility == "visible") ? "hidden" : "visible";
    }

    var bFormChanged = false;
    function formChanged() {
        bFormChanged = true;
    }

    function checkFormChanged(strConfirm) {
        var bContinue = true;
        if (bFormChanged) {
            bContinue = confirm(strConfirm);
            bCheckFormChangedConfirmDisplayed = true
            if (bContinue)
            {
                bFormChanged = false;
            }
        }
        return bContinue;
    }

    var bSingleFieldChanged = false;
    function singleFieldChanged() {
        bSingleFieldChanged = true;
    }

    function checkSingleFieldChanged(strConfirm) {
        var bContinue = true;
        if (bSingleFieldChanged) {
            bContinue = confirm(strConfirm);
            if (bContinue) {
                bSingleFieldChanged = false;
            }
        }
        return bContinue;
    }

    function SearchControlKeyDown(strSearchBtn, e) {
        if (!e) {
            e = window.event;
        }
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            document.getElementById(strSearchBtn).click();
            event.returnValue = false;
            event.cancel = true;
            return false;
       }
    }

    /****** End DevExpress ASPxDropDownEdit Used With ASPxTreeList ******/

    function DropDownHandler(DropDownEdit, TreeView, strPnlScrollable) {
        SynchronizeFocusedNode(DropDownEdit, TreeView);
        AdjustDropDownHeight(DropDownEdit,strPnlScrollable);
    }

    function AdjustDropDownHeight(DropDownEdit,strPnlScrollable) {
        var obj = DropDownEdit.GetMainElement()
        var offsetTop = $(obj).offset().top;
        var pageHeight = $(window).height();
        if ((pageHeight - offsetTop) < 580) {
            var newHeight = pageHeight - offsetTop - 30;
            document.getElementById(strPnlScrollable).style.maxHeight = newHeight + "px";
        }
        else {
            document.getElementById(strPnlScrollable).style.maxHeight = "600px";
        }
        DropDownEdit.AdjustDropDownWindow();
    }
    
    function TreeViewInitHandler(DropDownEdit, TreeView) {
        SynchronizeFocusedNode(DropDownEdit, TreeView);
    }

    function TreeViewNodeClickHandler(e, DropDownEdit, TreeView) {
        DropDownEdit.SetKeyValue(e.node.name);
        DropDownEdit.SetText(e.node.GetText());
        DropDownEdit.HideDropDown();
    }
    
    function SynchronizeFocusedNode(DropDownEdit, TreeView) {
        var keyValue = DropDownEdit.GetKeyValue();
        var node = TreeView.GetNodeByName(keyValue);
        if (node != null) {
            TreeView.SetSelectedNode(node);
            while (node.parent != null) {
                node = node.parent;
                node.SetExpanded(true);
            }
            UpdateEditBox(DropDownEdit, TreeView);
        }
    }
    function UpdateEditBox(DropDownEdit, TreeView) {
        var node = TreeView.GetSelectedNode();
        if (node != null && DropDownEdit.GetText() != node.GetText())
            DropDownEdit.SetText(node.GetText());
    }

    /*************End DevExpress***************/

    /****** DevExpress aspxNet DropdownCheckbox ******/
    var textSeparator = ";";
    function OnListBoxSelectionChanged(listBox, args, _checkComboBox) {
        if (args.index == 0) {
            args.isSelected ? listBox.SelectAll() : listBox.UnselectAll();
        }
        var _objCheckComboBox;
        if (typeof(_checkComboBox) != "undefined") {
            _objCheckComboBox = _checkComboBox;
        }
        else if (typeof(checkComboBox) != "undefined") {
            _objCheckComboBox = checkComboBox
        }
        var bIsAllSelected = IsAllSelected(listBox);
        if (_objCheckComboBox) UpdateText(bIsAllSelected, listBox, _objCheckComboBox);
        UpdateSelectAllItemState(bIsAllSelected, listBox);
    }
    function UpdateSelectAllItemState(bIsAllSelected, _objCheckBxLst) {
        bIsAllSelected ? _objCheckBxLst.SelectIndices([0]) : _objCheckBxLst.UnselectIndices([0]);
    }
    function IsAllSelected(_objCheckBxLst) {
        for (var i = 1; i < _objCheckBxLst.GetItemCount(); i++)
            if (!_objCheckBxLst.GetItem(i).selected)
            return false;
        return true;
    }
    function UpdateText(bIsAllSelected, _objCheckBxLst, _checkComboBox) {
        if (bIsAllSelected) {
            _checkComboBox.SetText(_objCheckBxLst.GetItem(0).text);
        }
        else {
            var selectedItems = _objCheckBxLst.GetSelectedItems();
            _checkComboBox.SetText(GetSelectedItemsText(selectedItems));
        }
    }

    function SynchronizeListBoxValues(dropDown, args, objCheckBxLst) {
        var texts = dropDown.GetText().split(textSeparator);
        var _objCheckBxLst;
        if (typeof(objCheckBxLst) != "undefined") {
            _objCheckBxLst = objCheckBxLst;
        }
        else if (typeof (checkListBox) != "undefined") {
            _objCheckBxLst = checkListBox
        }
        if (_objCheckBxLst) {
            if (texts == _objCheckBxLst.GetItem(0).text) {
                _objCheckBxLst.SelectAll();
            }
            else {
                _objCheckBxLst.UnselectAll();
                var values = GetValuesByTexts(texts, _objCheckBxLst);
                _objCheckBxLst.SelectValues(values);
                var bIsAllSelected = IsAllSelected(_objCheckBxLst);
                UpdateSelectAllItemState(bIsAllSelected, _objCheckBxLst);
                UpdateText(bIsAllSelected, _objCheckBxLst, dropDown);  // for remove non-existing texts
            }
        }
    }

    function DropDown(dropDown, args, objCheckBxLst) {
        SynchronizeListBoxValues(dropDown, args, objCheckBxLst);
    }

    var scopeFunction

    function GetSelectedItemsText(items) {
        var texts = [];
        for (var i = 0; i < items.length; i++)
            if (items[i].index != 0)
            texts.push(items[i].text);
        return texts.join(textSeparator);
    }
    function GetValuesByTexts(texts, _objCheckBxLst) {
        var objCheckBxLst;
        if (typeof (_objCheckBxLst) != "undefined") {
            objCheckBxLst = _objCheckBxLst;
        }
        else if (typeof (checkListBox) != "undefined") {
            objCheckBxLst = checkListBox;
        }
        var actualValues = [];
        var value = "";
        for (var i = 0; i < texts.length; i++) {
            value = GetValueByText(texts[i], objCheckBxLst);
            if (value != null)
                actualValues.push(value);
        }
        return actualValues;
    }
    function GetValueByText(text, _objCheckBxLst) {
        if (typeof (_objCheckBxLst) != "undefined") {
            for (var i = 0; i < _objCheckBxLst.GetItemCount(); i++)
                if (_objCheckBxLst.GetItem(i).text.toUpperCase() == text.toUpperCase())
                    return _objCheckBxLst.GetItem(i).value;
        }
        return null;
    }
  
    function getIcon(_fileExt)
    {
        var iconPath = "SmallDoc";

        switch (_fileExt)
        {
            case ".doc":
            case ".docx":
                iconPath = iconPath + "/" + "word.gif" ;
                break;
            case ".pdf":
                iconPath = iconPath + "/" + "pdf.gif" ;
                break;
            case ".xls":
            case ".xlsx":
                iconPath = iconPath + "/" + "xls.gif";
                break;
            case ".jpg":
            case ".gif":
            case ".png":
            case ".bmp":
                iconPath = iconPath + "/" + "img.gif";
                break;
            default:
                iconPath = iconPath + "/" + "txt.gif";
                break;
        }
        return "System/graphics/" + iconPath;
    }

    /********* Ajax tabpanels **********/
    //** On tabclick check if there are any changes - show confirm dialog - befor tab changes
    var setTabIdx = null;
    var currTabIdx = 0;
    var bCheckFormChangedConfirmDisplayed = false;
    var tabchangedConfirmMessage = "";
    function tabClickedCheckChanges(strMesage) {
        tabchangedConfirmMessage = strMesage;
        var retVal = checkFormChanged(strMesage)
        if (retVal == false) {
            setTabIdx = currTabIdx;
        }
        else {
            setTabIdx = null;
        }
    }

    //** If user select cancel i confirm dialog above - cancel tabchanges
    function tabIndexChangedCheckCancel(obj, e) {
        if (!bCheckFormChangedConfirmDisplayed) 
        {
            if (!checkFormChanged(tabchangedConfirmMessage)) { // if textbox is changed and tabpanel is clicked imediately after, CheckFormChanged is called before formChanged.
                setTabIdx = currTabIdx;
            }
        }
        if (setTabIdx != null) {
            obj.set_activeTabIndex(setTabIdx);
            setTabIdx = null;
        }
        else {
            currTabIdx = obj.get_activeTabIndex();
            bCheckFormChangedConfirmDisplayed = false;
        }
    }

    /********* ASDropDownTreeList ***********/

    //*** OnNodeSelectedScript doesn't get fired on dropdowntreelist
    function getDropDownTreeSelectedValues(strClientID) {
        return eval('asTreeViewObj' + strClientID + '.getSelectedNodesValue()');
    }

    /************ AjaxCT HTMLeditor ****************/
    function getHtmlEditorText(strEditorClientID) {
        var editor = $get(strEditorClientID).control;
        return editor.get_content();
    }
