var functionLibServiceUri = "";
var functionLibNamespace = "http://WPFSCADA/WebFunctionLibService";
var functionLibEndpointName = "IWebFLibService";
var functionLibInterface = "IWebFunctionLibService";
var activatedByScript = false;
var windowOpened = new Array();

function InitFunctionLib() {
    functionLibServiceUri = "http://" + webServerAddress + "/WPFSCADA/WebFunctionLibService";
}

//************************************SVFunctionLibrary******************************************
//SVApplications
function SVApplications() { }
SVApplications.StopApp = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "StopApp", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.StartEngine = function (engine) {
    var pl = new SOAPClientParameters();
    pl.add("engine", engine);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "StartEngine", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.StopEngine = function (engine) {
    var pl = new SOAPClientParameters();
    pl.add("engine", engine);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "StopEngine", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.RestartEngine = function (engine) {
    var pl = new SOAPClientParameters();
    pl.add("engine", engine);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "RestartEngine", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.PauseEngines = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "PauseEngines", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.UnpauseEngines = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "UnpauseEngines", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.Output = function (Msg) {
    var pl = new SOAPClientParameters();
    pl.add("Msg", Msg);
    SOAPClient.invoke(functionLibServiceUri, "Output", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.Run = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    SOAPClient.invoke(functionLibServiceUri, "Run", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.Run1 = function (path, parameters) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    pl.add("parameters", parameters);
    SOAPClient.invoke(functionLibServiceUri, "Run1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.AppPath = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "AppPath", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.ProjectPath = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ProjectPath", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.RunAndWait = function (path, timeOut) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    pl.add("timeOut", timeOut);
    SOAPClient.invoke(functionLibServiceUri, "RunAndWait", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.RunAndWait1 = function (path, parameters) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    pl.add("parameters", parameters);
    SOAPClient.invoke(functionLibServiceUri, "RunAndWait1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.RunAndWait2 = function (path, parameters, timeOut) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    pl.add("parameters", parameters);
    pl.add("timeOut", timeOut);
    SOAPClient.invoke(functionLibServiceUri, "RunAndWait2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.DisconnectViewer = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "DisconnectViewer", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.StopViewer = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "StopViewer", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVApplications.DisableSave = function () {
    var pl = new SOAPClientParameters();
    SOAPClient.invoke(functionLibServiceUri, "DisableSave", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.EnableSave = function () {
    var pl = new SOAPClientParameters();
    SOAPClient.invoke(functionLibServiceUri, "EnableSave", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.Sleep = function (millisecondsTimeout) {
    var pl = new SOAPClientParameters();
    pl.add("millisecondsTimeout", millisecondsTimeout);
    SOAPClient.invoke(functionLibServiceUri, "Sleep", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVApplications.SendEmail = function (senderEmail, senderPassword, senderName, recipientEmails, emailSubject, emailBody, smtpClientHost, smtpClientPort) {
    var pl = new SOAPClientParameters();
    pl.add("senderEmail", senderEmail);
    pl.add("senderPassword", senderPassword);
    pl.add("senderName", senderName);
    pl.add("recipientEmails", recipientEmails);
    pl.add("emailSubject", emailSubject);
    pl.add("emailBody", emailBody);
    pl.add("smtpClientHost", smtpClientHost);
    pl.add("smtpClientPort", smtpClientPort);
    return SOAPClient.invoke(functionLibServiceUri, "SendEmail", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

// SVBrOptimus
function SVBROptimus() { }
SVBROptimus.IsValidName = function (name) {
    var pl = new SOAPClientParameters();
    pl.add("name", name);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "IsValidName", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    switch (nRet) {
        case 0:
            return true;
        case 1:
            alert("O nome de projeto n\u00E3o pode ser vazio.", "Aten\u00E7\u00E3o");
            return false;
        case 2:
            alert("O nome do projeto est\u00E1 inv\u00E1lido.\nNomes v\u00E1lidos come\u00E7am com letra ou _,\nseguidos por letra, n\u00FAmero ou _.", "Nome inv\u00E1lido");
            return false;
        case 3:
            alert("Esse nome de projeto j\u00E1 est\u00E1 em uso", "Nome inv\u00E1lido");
            return false;
        default:
            return false;
    }
}

SVBROptimus.SVMessageBox = function (message, caption) {
    return confirm(message, caption);
}

SVBROptimus.Export = function (appName, copyData, fileName) {
    var pl = new SOAPClientParameters();
    pl.add("appName", appName);
    pl.add("copyData", copyData);
    pl.add("fileName", fileName);
    pl.add("overwrite", false);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Export", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);

    switch (nRet) {
        default:
        case 0:
            return new ThreeWayBool(true, false);
        case 1:
            return new ThreeWayBool(true, true);
        case 2:
            return new ThreeWayBool(false, null);
        case -1:
            alert("Aplicativo " + appName + " n\u00E3o encontrado. Por favor verifique se este realmente existe.", "Aplicativo n\u00E3o encontrado");
            return new ThreeWayBool(true, false);
        case -2:
            if (confirm("O arquivo " + fileName + " j\u00E1 existe, se continuar o arquivo sera sobrescrito. Deseja continuar?", "Substituir")) {
                pl = new SOAPClientParameters();
                pl.add("appName", appName);
                pl.add("copyData", copyData);
                pl.add("fileName", fileName);
                pl.add("overwrite", true);
                ret = SOAPClient.invoke(functionLibServiceUri, "Export", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
                if (ret == 1) {
                    return new ThreeWayBool(true, true);
                } else if (ret == 2) {
                    return new ThreeWayBool(false, null);
                } else {
                    return new ThreeWayBool(true, false);
                }
            } else {
                return new ThreeWayBool(false, null);
            }
    }
    return new ThreeWayBool(true, false);
}

SVBROptimus.Import = function (appName, copyData, fileName) {
    var pl = new SOAPClientParameters();
    pl.add("appName", appName);
    pl.add("copyData", copyData);
    pl.add("fileName", fileName);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Import", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    switch (nRet) {
        default:
        case 0:
            return new ThreeWayBool(true, false);
        case 1:
            return new ThreeWayBool(true, true);
        case 2:
            return new ThreeWayBool(false, null);
        case -1:
            alert("Um aplicativo chamado " + appName + " j\u00E1 existe. Por favor escolha um outro nome.", "Aplicativo j\u00E1 existe");
            return new ThreeWayBool(true, false);
        case -2:
            alert("O arquivo " + fileName + " n\u00E3o foi encontrado. Por favor verifique o caminho.", "Arquivo n\u00E3o encontrado");
            return new ThreeWayBool(true, false);

    }
    return new ThreeWayBool(true, false);
}

DelayByService = function (ms) {
    var pl = new SOAPClientParameters();
    pl.add("ms", ms);
    SOAPClient.invoke(functionLibServiceUri, "DelayByService", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

Browse = function (type, remotePC, OPCServer, item, aggregateId, tempoInicial, tempoFinal, filterCriteria) {
    var pl = new SOAPClientParameters();
    pl.add("type", type);
    pl.add("remotePC", remotePC);
    pl.add("OPCServer", OPCServer);
    pl.add("item", item);
    pl.add("aggregateId", aggregateId);
    pl.add("tempoInicial", tempoInicial);
    pl.add("tempoFinal", tempoFinal);
    pl.add("filterCriteria", filterCriteria);
    return SOAPClient.invoke(functionLibServiceUri, "ItemBrowser", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

FillTreeViewWithBranches = function (tvContent) {
    if (tvContent.length > 0) {
        var rootNode = $("#OPCDABrowserTreeView1").dynatree("getRoot");
        var nodes = tvContent.split(',');
        for (i = 0; i < nodes.length; i++) {
            if (nodes[i].indexOf('.') == -1)
                rootNode.addChild({
                    title: nodes[i],
                    key: nodes[i],
                    isFolder: true
                });
            else {
                var subNodes = nodes[i].split('.');
                var currentNode = subNodes[0];
                for (j = 1; j < subNodes.length; j++) {
                    var parentNode = $("#OPCDABrowserTreeView1").dynatree("getTree").getNodeByKey(currentNode);
                    currentNode += "." + subNodes[j];
                    if ($("#OPCDABrowserTreeView1").dynatree("getTree").getNodeByKey(currentNode) == null) {
                        parentNode.addChild({
                            title: subNodes[j],
                            key: currentNode,
                            isFolder: true
                        });
                    }
                }
            }
        }
    }
}

FillListWithLeaves = function (leavesContent, item) {
    while (document.getElementById("OPCDABrowserLeavesList").hasChildNodes()) {
        document.getElementById("OPCDABrowserLeavesList").removeChild(document.getElementById("OPCDABrowserLeavesList").lastChild);
    }
    if (leavesContent.length > 0) {
        var leaves = leavesContent.split(',');
        for (i = 0; i < leaves.length; i++) {
            var node = document.createElement("LI");
            var textnode = document.createTextNode(leaves[i]);
            node.appendChild(textnode);
            document.getElementById("OPCDABrowserLeavesList").appendChild(node);
        }
    }

    // Leaf selected
    $('#OPCDABrowserLeavesList li').click(function () {
        document.getElementById("OPCDABrowserSelectedTextBox").value = item + "." + $(this).text();
        $('#OPCDABrowserLeavesList li').css('background-color', '#FFFFFF');
        $('#OPCDABrowserLeavesList li').css('color', '#000000');
        $(this).css('background-color', '#0066CC');
        $(this).css('color', '#FFFFFF');
        document.getElementById("OPCDABrowserStatusTextBox").value = "OK!!!";
    });
}

SVBROptimus.ItemBrowser = function (obj, type, remotePC, OPCServer, item, aggregateId, tempoInicial, tempoFinal, labelID) {
    var filterCriteria = "";
    return SVBROptimus.ItemBrowserWithFilter(obj, type, remotePC, OPCServer, item, aggregateId, tempoInicial, tempoFinal, filterCriteria, labelID);
}

SVBROptimus.ItemBrowserWithFilter = function (obj, type, remotePC, OPCServer, item, aggregateId, tempoInicial, tempoFinal, filterCriteria, labelID) {
    var waitDlgEnd = true;
    var browseContent = Browse(type, remotePC, OPCServer, item, aggregateId, tempoInicial, tempoFinal, filterCriteria);
    var parts = browseContent.split('&');
    var tvContent = parts[0];
    var leavesContent = parts[1];
    var serversContent = parts[2];
    var sIsLeaf = parts[3];
    var leaf = "";
    switch (type) {
        case "DA":
        case "OPC DA":
            $("#OPCDABrowserDialog").dialog({ autoOpen: false });
            $("#OPCDABrowserDialog").dialog({ width: 472 });
            $("#OPCDABrowserDialog").dialog({ height: 440 });
            $("#OPCDABrowserDialog").dialog("open");
            document.getElementById("OPCDABrowserDialog").style.display = "";

            if (sIsLeaf == "true") {
                leaf = item.substring(item.lastIndexOf('.') + 1);
                item = item.substring(0, item.lastIndexOf('.'));
            }
            // Initialize OPC Server combobox items
            if (serversContent != null && serversContent != "") {
                $("#OPCDABrowserServerComboBox").empty();
                var servers = serversContent.split(',');
                var index = -1;
                for (var i = 0; i < servers.length; i++) {
                    $("#OPCDABrowserServerComboBox").append("<option value=1>" + servers[i] + "</option>");
                    if (OPCServer != null && OPCServer != "" && servers[i] == OPCServer)
                        index = i;
                }
                if (OPCServer != null && OPCServer != "" && index != -1)
                    $('#OPCDABrowserServerComboBox>option:eq(' + index + ')').attr('selected', true);
            }

            // Initialize treeview
            $("#OPCDABrowserTreeView1").dynatree({
                onActivate: function (node) {
                    // A DynaTreeNode object is passed to the activation handler
                    // Note: we also get this event, if persistence is on, and the page is reloaded.
                    if (!activatedByScript) {
                        item = node.data.key;
                        document.getElementById("OPCDABrowserSelectedTextBox").value = "";
                        document.getElementById("OPCDABrowserStatusTextBox").value = "";
                        browseContent = Browse(type, remotePC, OPCServer, item, aggregateId, tempoInicial, tempoFinal, filterCriteria);
                        parts = browseContent.split('&');
                        var tvContent = parts[0];
                        var leavesContent = parts[1];
                        FillTreeViewWithBranches(tvContent);
                        FillListWithLeaves(leavesContent, item);
                    }
                    activatedByScript = false;
                }
            });

            // Get all treeview nodes if node passed is not root
            if ($("#OPCDABrowserTreeView1").dynatree("getTree").count() == 0 && item != null && item != "") {
                browseContent = Browse(type, remotePC, OPCServer, "", aggregateId, tempoInicial, tempoFinal, filterCriteria);
                parts = browseContent.split('&');
                var tvRootContent = parts[0];
                FillTreeViewWithBranches(tvRootContent);
            }

            // Fill treeview with branches
            FillTreeViewWithBranches(tvContent);

            // Fill list with leaves
            FillListWithLeaves(leavesContent, item);

            // OPC Server combobox selection changed
            $('#OPCDABrowserServerComboBox').change(function () {
                var rootNode = $("#OPCDABrowserTreeView1").dynatree("getRoot");
                rootNode.removeChildren();
                OPCServer = $("#OPCDABrowserServerComboBox option:selected").text();
                document.getElementById("OPCDABrowserSelectedTextBox").value = "";
                document.getElementById("OPCDABrowserStatusTextBox").value = "";
                browseContent = Browse(type, remotePC, OPCServer, "", aggregateId, tempoInicial, tempoFinal, filterCriteria);
                parts = browseContent.split('&');
                var tvContent = parts[0];
                var leavesContent = parts[1];
                FillTreeViewWithBranches(tvContent);
                FillListWithLeaves(leavesContent, item);
            });

            // Filter textbox changed
            $('#OPCDABrowserFilterTextBox').on('change keyup', function () {
                var rootNode = $("#OPCDABrowserTreeView1").dynatree("getRoot");
                filterCriteria = $('#OPCDABrowserFilterTextBox').val();
                browseContent = Browse(type, remotePC, OPCServer, item, aggregateId, tempoInicial, tempoFinal, filterCriteria);
                parts = browseContent.split('&');
                var leavesContent = parts[1];
                FillListWithLeaves(leavesContent, item);
                document.getElementById("OPCDABrowserSelectedTextBox").value = "";
                document.getElementById("OPCDABrowserStatusTextBox").value = "";
            });

            // OK button clicked
            $(document).ready(function () {
                $("#OPCDABrowserOKButton").click(function () {
                    if (document.getElementById("OPCDABrowserSelectedTextBox").value != "") {
                        document.getElementById(labelID).innerHTML = document.getElementById("OPCDABrowserSelectedTextBox").value;
                        $("#OPCDABrowserDialog").dialog("close");
                    }
                    else
                        alert("You must select an item before clicking OK");
                });
            });

            // Cancel button clicked
            $(document).ready(function () {
                $("#OPCDABrowserCancelButton").click(function () {
                    $("#OPCDABrowserDialog").dialog("close");
                });
            });

            if (item != null && item != "") {
                var node = $("#OPCDABrowserTreeView1").dynatree("getTree").getNodeByKey(item);
                activatedByScript = true;
                node.activate();
                if (sIsLeaf == "true") {
                    document.getElementById("OPCDABrowserSelectedTextBox").value = item + "." + leaf;
                    $('#OPCDABrowserLeavesList li').css('background-color', '#FFFFFF');
                    $('#OPCDABrowserLeavesList li').css('color', '#000000');
                    $(this).css('background-color', '#0066CC');
                    $(this).css('color', '#FFFFFF');
                    var ul = document.getElementById("OPCDABrowserLeavesList");
                    var leaves = ul.getElementsByTagName("li");
                    for (var i = 0; i < leaves.length; ++i) {
                        if (leaves[i].innerHTML == leaf) {
                            leaves[i].style.backgroundColor = '#0066CC';
                            leaves[i].style.color = '#FFFFFF';
                        }
                        break;
                    }
                    document.getElementById("OPCDABrowserStatusTextBox").value = "OK!!!";
                }
                else
                    document.getElementById("OPCDABrowserSelectedTextBox").value = "";
                var ret = new Array();
                ret[0] = "itemBrowserLabel";
                return ret;
            }
            break;
        default:
            break;
    }
}

SVBROptimus.GetApplicationNameFromTagName = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    return SOAPClient.invoke(functionLibServiceUri, "GetApplicationNameFromTagName", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathAlgorithms = function () {
    var pl = new SOAPClientParameters();
    return SOAPClient.invoke(functionLibServiceUri, "GetPathAlgorithms", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathBin = function () {
    var pl = new SOAPClientParameters();
    return SOAPClient.invoke(functionLibServiceUri, "GetPathBin", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathExternal = function () {
    var pl = new SOAPClientParameters();
    return SOAPClient.invoke(functionLibServiceUri, "GetPathExternal", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathExternalApp = function (externalApp) {
    var pl = new SOAPClientParameters();
    pl.add("externalApp", externalApp);
    return SOAPClient.invoke(functionLibServiceUri, "GetPathExternalApp", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathIHM = function () {
    var pl = new SOAPClientParameters();
    return SOAPClient.invoke(functionLibServiceUri, "GetPathIHM", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathInclude = function () {
    var pl = new SOAPClientParameters();
    return SOAPClient.invoke(functionLibServiceUri, "GetPathInclude", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathProjects = function () {
    var pl = new SOAPClientParameters();
    return SOAPClient.invoke(functionLibServiceUri, "GetPathProjects", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathRecipeApplication = function (aplicativo) {
    var pl = new SOAPClientParameters();
    pl.add("aplicativo", aplicativo);
    return SOAPClient.invoke(functionLibServiceUri, "GetPathRecipeApplication", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.GetPathRecipeConfig = function (recipe) {
    var pl = new SOAPClientParameters();
    pl.add("recipe", recipe);
    return SOAPClient.invoke(functionLibServiceUri, "GetPathRecipeConfig", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.AddApplication = function (nome, algoritmo, obj) {
    var pl = new SOAPClientParameters();
    pl.add("nome", nome);
    pl.add("algoritmo", algoritmo);
    pl.add("obj", obj);
    SOAPClient.invoke(functionLibServiceUri, "AddApplication", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.AddObject = function (nomeObjeto, tagObjeto) {
    var pl = new SOAPClientParameters();
    pl.add("nomeObjeto", nomeObjeto);
    pl.add("tagObjeto", tagObjeto);
    SOAPClient.invoke(functionLibServiceUri, "AddObject", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.AddObject1 = function (nomeObjeto, tagObjeto, propKeys, propValues) {
    var pl = new SOAPClientParameters();
    pl.add("nomeObjeto", nomeObjeto);
    pl.add("tagObjeto", tagObjeto);
    pl.add("propKeys", propKeys);
    pl.add("propValues", propValues);
    SOAPClient.invoke(functionLibServiceUri, "AddObject1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.AddObjectUserFunction = function (nomeObjeto, tagObjeto, propKeys, propValues) {
    var pl = new SOAPClientParameters();
    pl.add("nomeObjeto", nomeObjeto);
    pl.add("tagObjeto", tagObjeto);
    pl.add("propKeys", propKeys);
    pl.add("propValues", propValues);
    SOAPClient.invoke(functionLibServiceUri, "AddObjectUserFunction", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.RemoveApplication = function (nome) {
    var pl = new SOAPClientParameters();
    pl.add("nome", nome);
    SOAPClient.invoke(functionLibServiceUri, "RemoveApplication", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.RemoveObject = function (tagObjeto, index) {
    var pl = new SOAPClientParameters();
    pl.add("tagObjeto", tagObjeto);
    pl.add("index", index);
    SOAPClient.invoke(functionLibServiceUri, "RemoveObject", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVBROptimus.StartStopApplication = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    SOAPClient.invoke(functionLibServiceUri, "StartStopApplication", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

// SVGraphics
function SVGraphics() { }
SVGraphics.Open0 = function (screen) {
    screen = screen.replace(/\\/g, folderSeparator).replace(/\//g, folderSeparator);
    var canOpen = canOpenGraphic(screen);
    if (canOpen) {
        var parameters = GetGraphicInfoParameters(screen);
        var fullPath = getFullPathGraphic(screen);
        windowOpened[windowOpened.length] = window.open(fullPath + ".html", "_blank", parameters);
        windowOpened[windowOpened.length - 1].document.cookie = "currentUser=" + currentUser + "; activatedTime=" + activatedTime;
    }
}

SVGraphics.Open1 = function (screen, tag) {
    screen = screen.replace(/\\/g, folderSeparator).replace(/\//g, folderSeparator);
    var canOpen = canOpenGraphic(screen);
    if (canOpen) {
        var parameters = GetGraphicInfoParameters(screen);
        var fullPath = getFullPathGraphic(screen);
        windowOpened[windowOpened.length] = window.open(fullPath + ".html", "_blank", parameters);
        if (tag != undefined) {
            var tagFullName = GetTagNames(tag.toString());
            if (windowOpened[windowOpened.length - 1] !== null) {
                windowOpened[windowOpened.length - 1].document.cookie = "initialScreenTag=" + screen + screenTagSeparator + tagFullName;
                windowOpened[windowOpened.length - 1].onload = function () {
                    var screenTagName = GetScrenTagDefault(screen);
                    windowOpened[windowOpened.length - 1]["SetScreenTag"](screenTagName, tagFullName, true, false);
                };
            }
        }
        if (windowOpened[windowOpened.length - 1] !== null) {
            windowOpened[windowOpened.length - 1].document.cookie = "currentUser=" + currentUser + "; activatedTime=" + activatedTime;
        }
    }
}

SVGraphics.Open2 = function (screen, dic) {
    screen = screen.replace(/\\/g, folderSeparator).replace(/\//g, folderSeparator);
    var canOpen = canOpenGraphic(screen);
    if (canOpen) {
        var parameters = GetGraphicInfoParameters(screen);
        var fullPath = getFullPathGraphic(screen);
        windowOpened[windowOpened.length] = window.open(fullPath + ".html", "_blank", parameters);
        var tagsFullNames = "";
        var screenTagsNames = "";
        var tagNames = dic.dicValues.toString().split(",");
        var screenTag = dic.dicKeys.toString().split(",");        
        for (i = 0; i < tagNames.length; i++) {
            var tagName = tagNames[i].toString();
			if(tagName.startsWith("@"))
				tagName = tagName.substring(1);
            tagsFullNames += tagName + "|";
            screenTagsNames += screenTag[i] + "|";
        }

        if (windowOpened[windowOpened.length - 1] !== null) {
            windowOpened[windowOpened.length - 1].document.cookie = "initialScreenTag=" + screen + screenTagSeparator + screenTagsNames + screenTagSeparator + tagsFullNames;
            windowOpened[windowOpened.length - 1].document.cookie = "currentUser=" + currentUser + "; activatedTime=" + activatedTime;
            screenTagsToOpen = windowOpened[windowOpened.length - 1].document.cookie;
            windowOpened[windowOpened.length - 1].onload = function () {
                var arr = screenTagsToOpen.split(screenTagSeparator);
                var arrScreen = arr[1].toString().split("|");
                var arrTags = arr[2].toString().split("|");
                for (i = 0; i < arrTags.length; i++) {
                    var screenTag = arrScreen[i];
                    var tagName = arrTags[i];
                    windowOpened[windowOpened.length - 1]["SetScreenTag"](screenTag, tagName, true, false);
                }
                screenTagsToOpen = "";
            };
        }
    }
}

function getFullPathGraphic(screen) {
    var myURL = window.location.href;
    var fullPath = myURL.substring(0, myURL.lastIndexOf(folderSeparator));
    var count = apiLocation.split("../").length - 1
    for (var i = 0; i < count; i++) {
        fullPath = fullPath.substring(0, fullPath.lastIndexOf(folderSeparator));
    }
    fullPath = fullPath + "/" + screen;
    return fullPath;
}

SVGraphics.Close1 = function () {
    var canClose = canCloseGraphic(window.docName);
    if (canClose) {
        window.close();
        for (var index = windowOpened.length; index--;) {
            if (windowOpened[index].location.pathname == window.location.pathname)
                windowOpened.splice(index, 1);
        }
    }
}

SVGraphics.Close = function (screen) {
    screen = screen.replace(/\\/g, folderSeparator).replace(/\//g, folderSeparator);
    var canClose = canCloseGraphic(screen);
    if (canClose) {        
        var myURL = window.location.href;
        var myDir = myURL.substring(0, myURL.lastIndexOf(folderSeparator) + 1);
        if (window.location.href == myDir + screen + ".html")
            window.close();

        for (var index = windowOpened.length; index--;) {
            if (windowOpened[index].location.href == myDir + screen + ".html") {
                windowOpened[index].close();
                windowOpened.splice(index, 1);
            }
        }
    }
}

SVGraphics.GetMousePosition = function (bIsRelativeToCurrentWindow) {
    var e = window.event;
    if (e != undefined) {
        if (bIsRelativeToCurrentWindow)
            return [e.pageX, e.pageY];
        return [e.clientX, e.clientY];
    } else {
        if (bIsRelativeToCurrentWindow && auxPageX != undefined && auxPageY != undefined)
            return [auxPageX, auxPageY];
        else if (auxClientX != undefined && auxClientY != undefined)
            return [auxClientX, auxClientY];
    }
    return [0, 0];
}

var auxPageX; var auxPageY;
var auxClientX; var auxClientY;
function UpdateMousePosition(e) {
    if (e != undefined) {
        auxPageX = e.pageX;
        auxPageY = e.pageY;
        auxClientX = e.clientX;
        auxClientY = e.clientY;
    }
}

function SVRecipe() { }
SVRecipe.Save = function (RecipeFile) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    SOAPClient.invoke(functionLibServiceUri, "Save", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}
SVRecipe.SaveEx = function (RecipeFile, Path) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    pl.add("Path", Path);
    SOAPClient.invoke(functionLibServiceUri, "SaveEx", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}
SVRecipe.Load = function (RecipeFile) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    SOAPClient.invoke(functionLibServiceUri, "Load", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}
SVRecipe.LoadEx = function (RecipeFile, Path) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    pl.add("Path", Path);
    SOAPClient.invoke(functionLibServiceUri, "LoadEx", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}
SVRecipe.SaveAndWait = function (RecipeFile) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "SaveAndWait", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}
SVRecipe.SaveAndWaitEx = function (RecipeFile, Path) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    pl.add("Path", Path);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "SaveAndWaitEx", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}
SVRecipe.LoadAndWait = function (RecipeFile) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "LoadAndWait", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}
SVRecipe.LoadAndWaitEx = function (RecipeFile, Path) {
    var pl = new SOAPClientParameters();
    pl.add("RecipeFile", RecipeFile);
    pl.add("Path", Path);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "LoadAndWaitEx", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

// SVTags
function SVTags() { }
SVTags.AddDynamicTag = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "AddDynamicTag", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}

SVTags.AddDynamicTag1 = function (tagName, property, value) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    pl.add("property", property);
    pl.add("value", value.toString());
    var iRet = SOAPClient.invoke(functionLibServiceUri, "AddDynamicTag1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}

SVTags.AddDynamicTag2 = function (tagName, propKeys, propValues) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    pl.add("propKeys", propKeys);
    // Garantir que todos os valores passados são string, pois método no servidor espera vetor de string
    for (var propIndex = 0; propIndex < propValues.length; propIndex++) {
        propValues[propIndex] = propValues[propIndex].toString();
    }

    pl.add("propValues", propValues);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "AddDynamicTag2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}

SVTags.ClearDynamicTag = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    SOAPClient.invoke(functionLibServiceUri, "ClearDynamicTag", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.RemoveDynamicTag1 = function (tagName, index) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    pl.add("index", index);
    SOAPClient.invoke(functionLibServiceUri, "RemoveDynamicTag1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DynamicLength = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "DynamicLength", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}

SVTags.ChangeTagProperty = function (propertyName, value) {
    var pl = new SOAPClientParameters();
    pl.add("propertyName", propertyName);
    pl.add("value", value);
    SOAPClient.invoke(functionLibServiceUri, "ChangeTagProperty", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.ChangeTagPropertyUserFunction = function (propertyName, value) {
    var pl = new SOAPClientParameters();
    pl.add("propertyName", propertyName);
    pl.add("value", value);
    SOAPClient.invoke(functionLibServiceUri, "ChangeTagPropertyUserFunction", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.ChangeTagPropertyUserFunction1 = function (propKeys, propValues) {
    var pl = new SOAPClientParameters();
    pl.add("propKeys", propKeys);
    pl.add("propValues", propValues);
    SOAPClient.invoke(functionLibServiceUri, "ChangeTagPropertyUserFunction1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableBooleanTrue = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "EnableBooleanTrue", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableBooleanTrue1 = function (tag, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableBooleanTrue1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableBooleanFalse = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "EnableBooleanFalse", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableBooleanFalse1 = function (tag, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableBooleanFalse1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableBooleanTrue = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableBooleanTrue", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableBooleanFalse = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableBooleanFalse", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableLoLo = function (tag, limit) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    SOAPClient.invoke(functionLibServiceUri, "EnableLoLo", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableLoLo1 = function (tag, limit, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableLoLo1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableLo = function (tag, limit) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    SOAPClient.invoke(functionLibServiceUri, "EnableLo", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableLo1 = function (tag, limit, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableLo1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableHiHi = function (tag, limit) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    SOAPClient.invoke(functionLibServiceUri, "EnableHiHi", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableHiHi1 = function (tag, limit, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableHiHi1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableHi = function (tag, limit) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    SOAPClient.invoke(functionLibServiceUri, "EnableHi", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableHi1 = function (tag, limit, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("limit", limit);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableHi1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableLoLo = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableLoLo", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableLo = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableLo", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableHiHi = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableHiHi", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableHi = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableHi", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableDeviation = function (tag, variance, timeToLevelUp, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("variance", variance);
    pl.add("timeToLevelUp", timeToLevelUp);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableDeviation", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableDeviation1 = function (tag, variance, timeToLevelUp) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("variance", variance);
    pl.add("timeToLevelUp", timeToLevelUp);
    SOAPClient.invoke(functionLibServiceUri, "EnableDeviation1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableDeviation = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableDeviation", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableWatchDog = function (tag, time, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("time", time);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableWatchDog", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableWatchDog1 = function (tag, time) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("time", time);
    SOAPClient.invoke(functionLibServiceUri, "EnableWatchDog1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableWatchDog = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableWatchDog", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableFreeze = function (tag, deadband, time, message, priority) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("deadband", deadband);
    pl.add("time", time);
    pl.add("message", message);
    pl.add("priority", priority);
    SOAPClient.invoke(functionLibServiceUri, "EnableFreeze", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.EnableFreeze1 = function (tag, deadband, time) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    pl.add("deadband", deadband);
    pl.add("time", time);
    SOAPClient.invoke(functionLibServiceUri, "EnableFreeze1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.DisableFreeze = function (tag) {
    var pl = new SOAPClientParameters();
    pl.add("tag", tag);
    SOAPClient.invoke(functionLibServiceUri, "DisableFreeze", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVTags.GetValue = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "GetValue", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVTags.Filter = function (filtersKeys, filtersValues, satisfies) {
    if (filtersKeys.length != filtersValues.length)
        return new Array();

    var ret = new JSList();
    var filterIndex = 0;
    while (filterIndex < filtersKeys.length) {
        var pl = new SOAPClientParameters();
        var keysToSend = new Array();
        keysToSend[0] = filtersKeys[filterIndex];
        pl.add("propKeys", keysToSend);
        pl.add("propValues", filtersValues[filterIndex].listValues);
        pl.add("satisfies", satisfies);
        var nRet = SOAPClient.invoke(functionLibServiceUri, "Filter", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
        if (nRet != null) {
            var indexToAdd = 0;
            while (indexToAdd < nRet.length) {
                ret.Add(nRet[indexToAdd]);
                indexToAdd++;
            }
        }

        filterIndex++;
    }

    return ret;
}

SVTags.Filter1 = function (tagName, filtersKeys, filtersValues, satisfies) {
    if (filtersKeys.length != filtersValues.length)
        return new Array();

    var ret = new JSList();
    var filterIndex = 0;
    while (filterIndex < filtersKeys.length) {
        var pl = new SOAPClientParameters();
        pl.add("tagName", tagName);
        var keysToSend = new Array();
        keysToSend[0] = filtersKeys[filterIndex];
        pl.add("propKeys", keysToSend);
        pl.add("propValues", filtersValues[filterIndex].listValues);
        pl.add("satisfies", satisfies);
        var nRet = SOAPClient.invoke(functionLibServiceUri, "Filter1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
        if (nRet != null) {
            var indexToAdd = 0;
            while (indexToAdd < nRet.length) {
                ret.Add(nRet[indexToAdd]);
                indexToAdd++;
            }
        }

        filterIndex++;
    }

    return ret;
}

SVTags.StartTagSimulation = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    SOAPClient.invoke(functionLibServiceUri, "StartTagSimulation", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}
SVTags.StopTagSimulation = function (tagName) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    SOAPClient.invoke(functionLibServiceUri, "StopTagSimulation", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}
// SVEvent
function SVEvent() { }
SVEvent.Send = function (sMessage) {
    var pl = new SOAPClientParameters();
    pl.add("sMessage", sMessage);
    SOAPClient.invoke(functionLibServiceUri, "Send", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVEvent.Send1 = function (sGroup, sMessage) {
    var pl = new SOAPClientParameters();
    pl.add("sGroup", sGroup);
    pl.add("sMessage", sMessage);
    SOAPClient.invoke(functionLibServiceUri, "Send1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVEvent.Send2 = function (sGroup, nPriority, sMessage) {
    var pl = new SOAPClientParameters();
    pl.add("sGroup", sGroup);
    pl.add("nPriority", nPriority);
    pl.add("sMessage", sMessage);
    SOAPClient.invoke(functionLibServiceUri, "Send2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

// SVReport
function SVReport() { }
SVReport.ChangeFormat = function (reportFileName, newFormat, bDelete) {
    var pl = new SOAPClientParameters();
    pl.add("reportFileName", reportFileName);
    pl.add("newFormat", newFormat);
    pl.add("delete", bDelete);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "ChangeFormat", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return true;
}

SVReport.Print = function (reportFileName) {
    var pl = new SOAPClientParameters();
    pl.add("reportFileName", reportFileName);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Print", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return true;
}

SVReport.SaveFile = function(reportFile, path) {
    var pl = new SOAPClientParameters();
    pl.add("reportFile", reportFile);
    pl.add("path", path);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "SaveFile", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return true;
}

// SVSecurity
function SVSecurity() { }
SVSecurity.AddUser = function (sName, sLogin, sPassword, sProfile) {
    var pl = new SOAPClientParameters();
    pl.add("sName", sName);
    pl.add("sLogin", sLogin);
    pl.add("sPassword", sPassword);
    pl.add("sProfile", sProfile);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "AddUser", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.RemoveUser = function (sName) {
    var pl = new SOAPClientParameters();
    pl.add("sName", sName);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "RemoveUser", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);

    if (nRet) {
        pl = new SOAPClientParameters();
        pl.add("pageGuid", pageGuid);
        SOAPClient.invoke(functionLibServiceUri, "Logoff", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
        var currentUser = SOAPClient.invoke(functionLibServiceUri, "CurrentUserName", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
        if (currentUser != undefined && currentUser != null && currentUser != "") {
            window.document.cookie = "currentUser=" + currentUser;
            window.document.cookie = "activatedTime=" + ReformatDate(new Date(), "");
        }
    }
    
    return nRet;
}

SVSecurity.Login = function () {
    var pl = new SOAPClientParameters();
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Login", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    //if (nRet === 0)
    //    window.document.cookie = "currentUser=" + sUser;

    return nRet;
}

SVSecurity.Login1 = function (sUser) {
    var pl = new SOAPClientParameters();
    pl.add("sUser", sUser)
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Login1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    if (nRet === 0) {
        window.document.cookie = "currentUser=" + sUser;
        window.document.cookie = "activatedTime=" + ReformatDate(new Date(), "");
    }
    
    return nRet;
}

SVSecurity.Login2 = function (sUser, sPassword) {
    var pl = new SOAPClientParameters();
    pl.add("sUser", sUser)
    pl.add("sPassword", sPassword)
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Login2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    if (nRet === 0) {
        window.document.cookie = "currentUser=" + sUser;
        window.document.cookie = "activatedTime=" + ReformatDate(new Date(), "");
    }

    return nRet;
}

SVSecurity.Login3 = function (sUser, bIsDomainUser) {
    var pl = new SOAPClientParameters();
    pl.add("sUser", sUser)
    pl.add("bIsDomainUser", bIsDomainUser)
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Login3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    if (nRet === 0) {
        window.document.cookie = "currentUser=" + sUser;
        window.document.cookie = "activatedTime=" + ReformatDate(new Date(), "");
    }

    return nRet;
}

SVSecurity.Login4 = function (sUser, sPassword, bIsDomainUser) {
    var pl = new SOAPClientParameters();
    pl.add("sUser", sUser)
    pl.add("sPassword", sPassword)
    pl.add("bIsDomainUser", bIsDomainUser)
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Login4", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    if (nRet === 0) {
        window.document.cookie = "currentUser=" + sUser;
        window.document.cookie = "activatedTime=" + ReformatDate(new Date(), "");
    }

    return nRet;
}

SVSecurity.ProfileCount = function () {
    var pl = new SOAPClientParameters();
    var nRet = SOAPClient.invoke(functionLibServiceUri, "ProfileCount", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.AllProfiles = function () {
    var pl = new SOAPClientParameters();
    var nRet = SOAPClient.invoke(functionLibServiceUri, "AllProfiles", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.CurrentUser = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "CurrentUser", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.CurrentUserName = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "CurrentUserName", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.GetCurrentProfile = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "GetCurrentProfile", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.GetActivatedTime = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "GetActivatedTime", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.GetActiveTime = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "GetActiveTime", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.UpdateActivatedTime = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "UpdateActivatedTime", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.AllUsers = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "AllUsers", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.AllUsersNames = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "AllUsersNames", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVSecurity.Logoff = function () {
    var pl = new SOAPClientParameters();
    pl.add("pageGuid", pageGuid);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Logoff", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

//**************************************UserFunctionLibrary******************************************

// SVString
function SVString() { }
SVString.Sum = function (a, b) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    pl.add("b", b);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Concat2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Compare1 = function (strA, strB) {
    var pl = new SOAPClientParameters();
    pl.add("strA", strA);
    pl.add("strB", strB);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Compare1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Compare2 = function (strA, strB, ignoreCase) {
    var pl = new SOAPClientParameters();
    pl.add("strA", strA);
    pl.add("strB", strB);
    pl.add("ignoreCase", ignoreCase);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Compare2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Compare3 = function (strA, indexA, strB, indexB, length) {
    var pl = new SOAPClientParameters();
    pl.add("strA", strA);
    pl.add("indexA", indexA);
    pl.add("strB", strB);
    pl.add("indexB", indexB);
    pl.add("length", length);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Compare3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Compare4 = function (strA, indexA, strB, indexB, length, ignoreCase) {
    var pl = new SOAPClientParameters();
    pl.add("strA", strA);
    pl.add("indexA", indexA);
    pl.add("strB", strB);
    pl.add("indexB", indexB);
    pl.add("length", length);
    pl.add("ignoreCase", ignoreCase);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Compare4", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.CompareOrdinal1 = function (strA, strB) {
    var pl = new SOAPClientParameters();
    pl.add("strA", strA);
    pl.add("strB", strB);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "CompareOrdinal1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.CompareOrdinal2 = function (strA, strB, indexB, length) {
    var pl = new SOAPClientParameters();
    pl.add("strA", strA);
    pl.add("strB", strB);
    pl.add("indexB", indexB);
    pl.add("length", length);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "CompareOrdinal2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Concat1 = function (args) {
    var pl = new SOAPClientParameters();
    pl.add("args", args);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Concat1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Concat2 = function (arg0, arg1) {
    var pl = new SOAPClientParameters();
    pl.add("arg0", arg0);
    pl.add("arg1", arg1);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Concat2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Concat3 = function (arg0, arg1, arg2) {
    var pl = new SOAPClientParameters();
    pl.add("arg0", arg0);
    pl.add("arg1", arg1);
    pl.add("arg2", arg2);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Concat3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Concat4 = function (arg0, arg1, arg2, arg3) {
    var pl = new SOAPClientParameters();
    pl.add("arg0", arg0);
    pl.add("arg1", arg1);
    pl.add("arg2", arg2);
    pl.add("arg3", arg3);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Concat4", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Copy = function (str) {
    var pl = new SOAPClientParameters();
    pl.add("str", str);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Copy", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Equals = function (a, b) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    pl.add("b", b);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Equals", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Format1 = function (format, arg0) {
    var pl = new SOAPClientParameters();
    pl.add("format", format);
    pl.add("arg0", arg0);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Format1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Format2 = function (format, arg0, arg1) {
    var pl = new SOAPClientParameters();
    pl.add("format", format);
    pl.add("arg0", arg0);
    pl.add("arg1", arg1);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Format2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Format3 = function (format, arg0, arg1, arg2) {
    var pl = new SOAPClientParameters();
    pl.add("format", format);
    pl.add("arg0", arg0);
    pl.add("arg1", arg1);
    pl.add("arg2", arg2);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Format3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Intern = function (str) {
    var pl = new SOAPClientParameters();
    pl.add("str", str);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Intern", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IsInterned = function (str) {
    var pl = new SOAPClientParameters();
    pl.add("str", str);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IsInterned", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IsNullOrEmpty = function (value) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IsNullOrEmpty", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IsNullOrWhiteSpace = function (value) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IsNullOrWhiteSpace", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Join1 = function (separator, values) {
    var pl = new SOAPClientParameters();
    pl.add("separator", separator);
    pl.add("values", values);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Join1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Join2 = function (separator, values, startIndex, count) {
    var pl = new SOAPClientParameters();
    pl.add("separator", separator);
    pl.add("values", values);
    pl.add("startIndex", startIndex);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Join2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Clone = function (value) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Clone", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Contains = function (source, value) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Contains", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.CopyTo = function (source, sourceIndex, destination, destinationIndex, count) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("sourceIndex", sourceIndex);
    pl.add("destination", destination);
    pl.add("destinationIndex", destinationIndex);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "CopyTo", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.EndsWith = function (source, value) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "EndsWith", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.GetHashCode = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "GetHashCode", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IndexOf1 = function (source, value) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IndexOf1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IndexOf2 = function (source, value, startIndex) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    pl.add("startIndex", startIndex);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IndexOf2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IndexOf3 = function (source, value, startIndex, count) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    pl.add("startIndex", startIndex);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IndexOf3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IndexOfAny1 = function (source, anyOf) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("anyOf", anyOf);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IndexOfAny1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IndexOfAny2 = function (source, anyOf, startIndex) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("anyOf", anyOf);
    pl.add("startIndex", startIndex);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IndexOfAny2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IndexOfAny3 = function (source, anyOf, startIndex, count) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("anyOf", anyOf);
    pl.add("startIndex", startIndex);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IndexOfAny3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Insert = function (source, startIndex, value) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("startIndex", startIndex);
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Insert", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.IsNormalized = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "IsNormalized", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.LastIndexOf1 = function (source, value) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "LastIndexOf1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.LastIndexOf2 = function (source, value, startIndex) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    pl.add("startIndex", startIndex);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "LastIndexOf2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.LastIndexOf3 = function (source, value, startIndex, count) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    pl.add("startIndex", startIndex);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "LastIndexOf3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.LastIndexOfAny1 = function (source, anyOf) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("anyOf", anyOf);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "LastIndexOfAny1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.LastIndexOfAny2 = function (source, anyOf, startIndex) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("anyOf", anyOf);
    pl.add("startIndex", startIndex);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "LastIndexOfAny2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.LastIndexOfAny3 = function (source, anyOf, startIndex, count) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("anyOf", anyOf);
    pl.add("startIndex", startIndex);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "LastIndexOfAny3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Normalize = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Normalize", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.PadLeft1 = function (source, totalWidth) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("totalWidth", totalWidth);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "PadLeft1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.PadLeft2 = function (source, totalWidth, paddingChar) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("totalWidth", totalWidth);
    pl.add("paddingChar", paddingChar);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "PadLeft2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.PadRight1 = function (source, totalWidth) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("totalWidth", totalWidth);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "PadRight1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.PadRight2 = function (source, totalWidth, paddingChar) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("totalWidth", totalWidth);
    pl.add("paddingChar", paddingChar);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "PadRight2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Remove1 = function (source, startIndex) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("startIndex", startIndex);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Remove1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Remove2 = function (source, startIndex, count) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("startIndex", startIndex);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Remove2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Replace = function (source, oldValue, newValue) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("oldValue", oldValue);
    pl.add("newValue", newValue);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Replace", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Split1 = function (source, separator) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("separator", separator);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Split1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Split2 = function (source, separator, count) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("separator", separator);
    pl.add("count", count);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Split2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.StartsWith = function (source, value) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("value", value);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "StartsWith", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Substring1 = function (source, startIndex) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("startIndex", startIndex);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Substring1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Substring2 = function (source, startIndex, len) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("startIndex", startIndex);
    pl.add("len", len);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Substring2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.ToCharArray1 = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ToCharArray1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.ToCharArray2 = function (source, startIndex, length) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("startIndex", startIndex);
    pl.add("length", length);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ToCharArray2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.ToLowerInvariant = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ToLowerInvariant", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.ToLower = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ToLower", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.ToUpperInvariant = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ToUpperInvariant", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.ToUpper = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ToUpper", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.ToString = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ToString", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Trim1 = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Trim1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.Trim2 = function (source, trimChars) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("trimChars", trimChars);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "Trim2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.TrimEnd = function (source, trimChars) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("trimChars", trimChars);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "TrimEnd", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.TrimStart = function (source, trimChars) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    pl.add("trimChars", trimChars);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "TrimStart", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.GetType = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "GetType", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVString.GetTypeCode = function (source) {
    var pl = new SOAPClientParameters();
    pl.add("source", source);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "GetTypeCode", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

//SVMath
function SVMath() { }
//SVMath.Sum = function (a, b) {
//    var pl = new SOAPClientParameters();
//    pl.add("a", a);
//    pl.add("b", b);
//    var iRet = SOAPClient.invoke(functionLibServiceUri, "Sum", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
//    return iRet;
//}

//SVMath.Sum1 = function (a, b) {
//    var pl = new SOAPClientParameters();
//    pl.add("a", a);
//    pl.add("b", b);
//    var fRet = SOAPClient.invoke(functionLibServiceUri, "Sum1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
//    return fRet;
//}
SVMath.Abs= function (value) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Abs", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Acos = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Acos", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Asin = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Asin", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Atan = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Atan", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Atan2 = function (y, x) {
    var pl = new SOAPClientParameters();
    pl.add("y", y);
    pl.add("x", x);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Atan2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.BigMul = function (a, b) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    pl.add("b", b);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "BigMul", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Ceiling = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Ceiling", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Cos = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Cos", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Cosh = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Cosh", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.DivRem = function (a, b, result) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    pl.add("b", b);
    pl.add("result", result);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "DivRem", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Exp = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Exp", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Floor = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Floor", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.IEEERemainder = function (x, y) {
    var pl = new SOAPClientParameters();
    pl.add("x", x);
    pl.add("y", y);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "IEEERemainder", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Log = function (a, newBase) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    pl.add("newBase", newBase);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Log", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Log1 = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Log1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Log10 = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Log10", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Max = function (val1, val2) {
    var pl = new SOAPClientParameters();
    pl.add("val1", val1);
    pl.add("val2", val2);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Max", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Min = function (val1, val2) {
    var pl = new SOAPClientParameters();
    pl.add("val1", val1);
    pl.add("val2", val2);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Min", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Pow = function (x, y) {
    var pl = new SOAPClientParameters();
    pl.add("x", x);
    pl.add("y", y);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Pow", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Round = function (value, digits, mode) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    pl.add("digits", digits);
    pl.add("mode", mode);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Round", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Round1 = function (value, param) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    pl.add("param", param.toString());
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Round1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Round2 = function (a) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Round2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Sign = function (value) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Sign", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Sin = function (a) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Sin", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Sinh = function (value) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Sinh", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Sqrt = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Sqrt", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Tan = function (a) {
    var pl = new SOAPClientParameters();
    pl.add("a", a);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Tan", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Tanh = function (value) {
    var pl = new SOAPClientParameters();
    pl.add("value", value);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Tanh", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.Truncate = function (d) {
    var pl = new SOAPClientParameters();
    pl.add("d", d);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "Truncate", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.GetPI = function () {
    var pl = new SOAPClientParameters();
    var iRet = SOAPClient.invoke(functionLibServiceUri, "GetPI", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.GetE = function () {
    var pl = new SOAPClientParameters();
    var iRet = SOAPClient.invoke(functionLibServiceUri, "GetE", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.SquareArea = function (side) {
    var pl = new SOAPClientParameters();
    pl.add("side", side);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "SquareArea", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.SquareAreaDiagonal = function (diagonal) {
    var pl = new SOAPClientParameters();
    pl.add("diagonal", diagonal);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "SquareAreaDiagonal", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.RectangleArea = function (baseValue, height) {
    var pl = new SOAPClientParameters();
    pl.add("baseValue", baseValue);
    pl.add("height", height);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "RectangleArea", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.CircleArea = function (radius) {
    var pl = new SOAPClientParameters();
    pl.add("radius", radius);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "CircleArea", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.TrapezoidArea = function (height, base1, base2) {
    var pl = new SOAPClientParameters();
    pl.add("height", height);
    pl.add("base1", base1);
    pl.add("base2", base2);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "TrapezoidArea", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.CircleSectorArea = function (innerRadius, outerRadius) {
    var pl = new SOAPClientParameters();
    pl.add("innerRadius", innerRadius);
    pl.add("outerRadius", outerRadius);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "CircleSectorArea", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.CylindreVolume = function (height, radius) {
    var pl = new SOAPClientParameters();
    pl.add("height", height);
    pl.add("radius", radius);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "CylindreVolume", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.TubeCylindreVolume = function (height, outerRadius, innerRadius) {
    var pl = new SOAPClientParameters();
    pl.add("height", height);
    pl.add("outerRadius", outerRadius);
    pl.add("innerRadius", innerRadius);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "TubeCylindreVolume", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.SphereVolume = function (radius) {
    var pl = new SOAPClientParameters();
    pl.add("radius", radius);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "SphereVolume", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.SphereArea = function (radius) {
    var pl = new SOAPClientParameters();
    pl.add("radius", radius);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "SphereArea", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
SVMath.PyramidVolume = function (height, baseArea) {
    var pl = new SOAPClientParameters();
    pl.add("height", height);
    pl.add("baseArea", baseArea);
    var iRet = SOAPClient.invoke(functionLibServiceUri, "PyramidVolume", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return iRet;
}
//**************************************Service******************************************
function ExecuteService(serviceName) {
    var pl = new SOAPClientParameters();
    pl.add("serviceName", serviceName);
    return SOAPClient.invoke(functionLibServiceUri, "ExecuteService", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

//**************************************UserFunctionLibrary******************************************
function ExecuteUserFunction(libName, functionName, parameters) {
    var pl = new SOAPClientParameters();
    pl.add("libName", libName);
    pl.add("functionName", functionName);
    pl.add("parameters", parameters);
    var ret = SOAPClient.invoke(functionLibServiceUri, "ExecuteUserFunction", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    if (ret instanceof Array) {
        var retList = new JSList();
        for (var i = 0; i < ret.length; i++) {
            retList.Add(ret[i]);
        }
        return retList;
    }
    return ret;
}

//**********************************************SVFile************************************************
function SVFile() { }
SVFile.FileExists = function (filePath) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "FileExists", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVFile.Open = function (pathName, overwrite) {
    var pl = new SOAPClientParameters();
    pl.add("pathName", pathName);
    pl.add("overwrite", overwrite);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Open", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVFile.LineCount = function () {
    var pl = new SOAPClientParameters();
    var nRet = SOAPClient.invoke(functionLibServiceUri, "LineCount", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVFile.LineCount2 = function (filePath) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "LineCount2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVFile.ReadBuffer = function () {
    var pl = new SOAPClientParameters();
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ReadBuffer", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVFile.ReadBuffer2 = function (filePath) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ReadBuffer2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVFile.ReadLine = function (line) {
    var pl = new SOAPClientParameters();
    pl.add("line", line);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ReadLine", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVFile.ReadLine2 = function (filePath, line) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    pl.add("line", line);
    var sRet = SOAPClient.invoke(functionLibServiceUri, "ReadLine2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return sRet;
}

SVFile.Write = function (text) {
    var pl = new SOAPClientParameters();
    pl.add("text", text);
    SOAPClient.invoke(functionLibServiceUri, "Write", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.Write2 = function (filePath, text) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    pl.add("text", text);
    SOAPClient.invoke(functionLibServiceUri, "Write2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.WriteLine = function (text) {
    var pl = new SOAPClientParameters();
    pl.add("text", text);
    SOAPClient.invoke(functionLibServiceUri, "WriteLine", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.WriteLine2 = function (filePath, text) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    pl.add("text", text);
    SOAPClient.invoke(functionLibServiceUri, "WriteLine2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.FindFilesName = function (folderPath) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    SOAPClient.invoke(functionLibServiceUri, "FindFilesName", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.FindFilesName = function (folderPath, filter) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    pl.add("filter", filter);
    SOAPClient.invoke(functionLibServiceUri, "FindFilesName2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.ReadAllLines = function (filePath) {
    var pl = new SOAPClientParameters();
    pl.add("filePath", filePath);
    var lines = SOAPClient.invoke(functionLibServiceUri, "ReadAllLines", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) {
        if (lines[lineIndex] == null)
            lines[lineIndex] = "";
    }
    return lines;
}

SVFile.Create = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    SOAPClient.invoke(functionLibServiceUri, "Create", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.DeleteFile = function () {
    var pl = new SOAPClientParameters();
    SOAPClient.invoke(functionLibServiceUri, "DeleteFile", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.DeleteFile2 = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    SOAPClient.invoke(functionLibServiceUri, "DeleteFile2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.Copy = function (sourceFileName) {
    var pl = new SOAPClientParameters();
    pl.add("sourceFileName", sourceFileName);
    SOAPClient.invoke(functionLibServiceUri, "CopyFile", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.Copy2 = function (sourceFileName, param) {
    var pl = new SOAPClientParameters();
    pl.add("sourceFileName", sourceFileName);
    pl.add("param", param);
    SOAPClient.invoke(functionLibServiceUri, "CopyFile2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.Copy3 = function (sourceFileName, destFileName, overwrite) {
    var pl = new SOAPClientParameters();
    pl.add("sourceFileName", sourceFileName);
    pl.add("destFileName", destFileName);
    pl.add("overwrite", overwrite);
    SOAPClient.invoke(functionLibServiceUri, "CopyFile3", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.Move = function (destFileName) {
    var pl = new SOAPClientParameters();
    pl.add("destFileName", destFileName);
    SOAPClient.invoke(functionLibServiceUri, "Move", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.Move2 = function (sourceFileName, destFileName) {
    var pl = new SOAPClientParameters();
    pl.add("sourceFileName", sourceFileName);
    pl.add("destFileName", destFileName);
    SOAPClient.invoke(functionLibServiceUri, "Move2", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.CreateDirectory = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    SOAPClient.invoke(functionLibServiceUri, "CreateDirectory", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.DeleteDirectory = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    SOAPClient.invoke(functionLibServiceUri, "DeleteDirectory", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.DirectoryExists = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    return SOAPClient.invoke(functionLibServiceUri, "DirectoryExists", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.GetDirectories = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    return SOAPClient.invoke(functionLibServiceUri, "GetDirectories", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.GetFiles = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    return SOAPClient.invoke(functionLibServiceUri, "GetFiles", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.GetDirectoryRoot = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    return SOAPClient.invoke(functionLibServiceUri, "GetDirectoryRoot", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.MoveDirectory = function (sourceDirName, destDirName) {
    var pl = new SOAPClientParameters();
    pl.add("sourceDirName", sourceDirName);
    pl.add("destDirName", destDirName);
    SOAPClient.invoke(functionLibServiceUri, "MoveDirectory", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.GetFileName = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    return SOAPClient.invoke(functionLibServiceUri, "GetFileName", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.GetFileNameWithoutExtension = function (path) {
    var pl = new SOAPClientParameters();
    pl.add("path", path);
    return SOAPClient.invoke(functionLibServiceUri, "GetFileNameWithoutExtension", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVFile.GetGifPlayTime = function (gifFilePath) {
    var pl = new SOAPClientParameters();
    pl.add("gifFilePath", gifFilePath);
    return SOAPClient.invoke(functionLibServiceUri, "GetGifPlayTime", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

// SVDBConnection
function SVDBConnection() { }
SVDBConnection.Select = function (connString, selString) {
    var pl = new SOAPClientParameters();
    pl.add("connString", connString);
    pl.add("selString", selString);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Select", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);

    var retList = new JSList();
    if ((nRet != null) && (nRet.length > 0)) {
        for (var retIndex = 0; retIndex < nRet.length; retIndex++) {
            var innerRetList = new JSList();
            for (var innerRetIndex = 0; innerRetIndex < nRet[retIndex].length; innerRetIndex++)
                innerRetList.Add(nRet[retIndex][innerRetIndex]);

            retList.Add(innerRetList);
        }
    }

    return retList;
}

SVDBConnection.Insert = function (connString, insString) {
    var pl = new SOAPClientParameters();
    pl.add("connString", connString);
    pl.add("insString", insString);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Insert", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVDBConnection.Delete = function (connString, delString) {
    var pl = new SOAPClientParameters();
    pl.add("connString", connString);
    pl.add("delString", delString);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Delete", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

SVDBConnection.Update = function (connString, updString) {
    var pl = new SOAPClientParameters();
    pl.add("connString", connString);
    pl.add("updString", updString);
    var nRet = SOAPClient.invoke(functionLibServiceUri, "Update", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    return nRet;
}

function ThreeWayBool(hasValue, value) {
    this.hasValue = hasValue;
    this.value = value;
    this.get_HasValue = ThreeWayBoolHasValue;
    this.get_Value = ThreeWayBoolValue;
}

function ThreeWayBoolHasValue() {
    return this.hasValue;
}

function ThreeWayBoolValue() {
    return this.value;
}

//SVHistory
function SVHistory() { }
SVHistory.LoadHistoryToTag = function (startDate, daysCount, sourceTagName, targetTagName, numberOfValues) {
    var pl = new SOAPClientParameters();
    pl.add("startDate", startDate);
    pl.add("daysCount", daysCount);
    pl.add("sourceTagName", sourceTagName);
    pl.add("targetTagName", targetTagName);
    pl.add("numberOfValues", numberOfValues);
    SOAPClient.invoke(functionLibServiceUri, "LoadHistoryToTag", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
}

SVHistory.ExportTagHistoric = function (tagName, filePath) {
    var pl = new SOAPClientParameters();
    pl.add("tagName", tagName);
    var fRet = SOAPClient.invoke(functionLibServiceUri, "getTagHistoric", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    saveFile(fRet, filePath);
}

SVHistory.ExportTagHistoric1 = function (tagName, filePath, startDate, endDate) {
    pl.add("tagName", tagName);
    pl.add("filePath", filePath);
    pl.add("startDate", startDate);
    pl.add("endDate", endDate);
    var fRet = SOAPClient.invoke(functionLibServiceUri, "getTagHistoric1", pl, functionLibNamespace, functionLibEndpointName, functionLibInterface, false, null);
    saveFile(fRet, filePath);
}

function saveFile(fRet, filePath) {
    var content = "";
    for (var i = 0; i < fRet.length; i++) {
        if (fRet[i].length > 2) {
            var date = new Date(fRet[i][1]);
            var text = date.toLocaleDateString() + " " + date.toLocaleTimeString() + " " + fRet[i][2] + "\r\n";
            content += text;
        }
    }
    var blob = new Blob([content], { type: "text/plain" });
    var url = URL.createObjectURL(blob);
    SVApplications.Output("SVHistory.ExportTagHistoric: The file will be saved at the Download's folder for security reason");
    var a = document.createElement('a');
    a.download = filePath.substring(filePath.lastIndexOf("\\") + 1);
    a.href = url;
    a.click();
}

//Validação e Funções do Login Dialog
$(document).ready(function () {
    if ($ !== undefined) {
        $.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
            _title: function (title) {
                title.html("<img src='../favicon.ico' class='logo_size' style=\"width:16px; height:18px; float:left;\"><label style=\"font-size:12px; display:block; float:left; padding-top:4px; padding-left:5px;\"> Login</label>");
            }
        }));
    }
});
$(function () {
    var func = $ != undefined ? $ : J;
    var login = func("#login"),
		password = func("#password");

    func("#login-form").dialog({
        autoOpen: false,
        modal: true,
        open: function () {
            $('.ui-dialog-titlebar-close').removeClass("ui-dialog-titlebar-close")
                .css('float', 'right').css('border', 'none').css('margin-top', '3px').css('margin-right', '-14px')
                .css('font-size', '14px').css('font-weight', 'bold').css('background', 'transparent').html('X');

            $('.ui-dialog-buttonpane').find('button:contains("Cancel")').css('background', 'lightgray').css('border', '1px solid darkgray').css('width', '75px').css('height', '22px');
            $('.ui-dialog-buttonpane').find('button:contains("OK")').css('background', 'lightgray').css('border', '1px solid darkgray').css('width', '75px').css('height', '22px');
        },
        buttons: {
            "OK": function () {
                var res = -1;
                if (isDomain.checked)
                    res = SVSecurity.Login4(login.val(), password.val(), true);
                else
                    res = SVSecurity.Login2(login.val(), password.val());
                if (res == 0)
                    $(this).dialog("close");
                else
                    alert("Password and/or user invalid");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        },
        close: function () {
            login.val("");
            password.val("");
            isDomain.checked = false;
        }
    });
});
