Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
63 views
Good Day Everyone 

i have a radgrid and i have a formdecorator in my masterpage that skin all the controls nicely. so now my gridview has paging, the numbers in the paging are not looking good in IE10

i have attached an image showing what i mean. 

Galin
Telerik team
 answered on 23 May 2013
1 answer
117 views
Hi support team,

I paste the following text into a radeditor instance running in html mode:

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
</head>
<body>
</body>
</html>


Then I change to design mode and back to html mode. After that the html looks like this:

&lt;html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"&gt;
<head>
</head>
<body>
</body>
</html>

"<html" is modified to "&lt;html" and ">" is modified to "&gt". Why? By this behaviour I produce a lot of wrongly encoded html documents. What can I do to preserve the html tags for getting a "normal" html document?

When I paste e.g.

<div style="font-family: Arial; font-size: 10pt;"></div>

nothing is modified, i.e. the tags are preserved as expected.

The following filters are disabled:

this.RadEditor1.DisableFilter(EditorFilters.ConvertFontToSpan | EditorFilters.ConvertToXhtml);

I'm using Telerik.Web.UI.dll version 2013.1.417.35 and I observe the descibed behaviour in both Chrome version 26.0.1410.64 m and Firefox version 21.0.

Any help would be very appreciated.
Thanks in advance.

Best regards,
Christian Klug
Marin Bratanov
Telerik team
 answered on 23 May 2013
3 answers
153 views
Our JavaScript is working fine on all platforms except IE8.  The following problems arise:

We use external JS files.  The jquery $find function on the splitter's id fails. The line reads as follows:

var splMain = $find(splMainId);,

but changing the line to this works:

    var splMain = $(window).find(splMainId);

Unfortunately, the changed line does not work for all other browsers.

The second issue in IE8 is that we are getting "Object doesn't support this property or method" with the following:

splMain.getStartPane()

From what I've read, IE8 has a tough time properly detecting the JS files it needs to include and therefore, you need to include the required JS files.  I have done so, but the problem remains.

I have pasted both the ASPX file in question and its included JS files (two of them).  IE8 breaks on the following line, line 55 of CreateEstimate.js.  

var mainWidth = $(window).width() - splMain.getStartPane().get_width() - 37;

Please let me know what I need to do in order to ensure that the page runs in IE8.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateEstimate.aspx.cs" Inherits="UP.Estimate.CreateEstimate" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="cache-control" content="max-age=0" />
        <meta http-equiv="cache-control" content="no-cache" />
        <meta http-equiv="expires" content="0" />
        <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
        <meta http-equiv="pragma" content="no-cache" />
        <title></title>
        <link rel="stylesheet" type="text/css" href="../Styles/Styles.css" />
        <link href="../Styles/Skin_ipd/ComboBox.Skin_ipd.css" rel="stylesheet" type="text/css" />
        <link href="../Styles/Skin_ipd/Button.Skin_ipd.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
            .container
            {
            border: solid 1px #9BB5C1;
            }
            .col1, .col2, .col3
            {
            float: left;
            width: 280px;
            margin: 0;
            padding: 0 5px 0 0;
            line-height: 14px;
            }
            .rcbHeader ul,
            .rcbFooter ul,
            .rcbItem ul, .rcbHovered ul, .rcbDisabled ul
            {
            width: 100%;
            display: inline-block;
            margin: 0;
            padding: 0;
            list-style-type: none;
            }
        </style>
    </head>
    <body>
        <form id="estimateForm" runat="server">
            <%-- The RadAjaxLoadingPanel contains a Skin property that can be set to "", or null.  
            Doing so basically turns off the loading image that shows normally when an AJAX call is made.--%>
            <telerik:RadAjaxLoadingPanel ID="pnlAjaxLoading" runat="server" Skin=""/>
            <telerik:RadSkinManager ID="RadSkinManager1" Runat="server" Skin="Web20">
            </telerik:RadSkinManager>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <%--Needed for JavaScript IntelliSense in VS2010--%>
                    <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryPlugins.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Navigation.NavigationScripts.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Splitter.RadSplitterScripts.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Splitter.RadSlidingZoneScripts.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.PopUp.PopUpScripts.js" />
                    <asp:ScriptReference Path="../Scripts/Main.js" />
                    <asp:ScriptReference Path="Scripts/CreateEstimate.js" />
                </Scripts>
            </telerik:RadScriptManager>
            <telerik:RadAjaxManager ID="ajaMain" runat="server" DefaultLoadingPanelID="pnlAjaxLoading">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="cboIntelligentSearch">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="cboIntelligentSearch" LoadingPanelID="pnlAjaxLoading" />
                            <telerik:AjaxUpdatedControl ControlID="ajaMain" LoadingPanelID="pnlAjaxLoading"/>
                            <telerik:AjaxUpdatedControl ControlID="lblLogs" LoadingPanelID="pnlAjaxLoading"/>
                            <telerik:AjaxUpdatedControl ControlID="lblReports" LoadingPanelID="pnlAjaxLoading"/>
                            <telerik:AjaxUpdatedControl ControlID="lblProjectOverview" LoadingPanelID="pnlAjaxLoading"/>
                            <telerik:AjaxUpdatedControl ControlID="actionOnLoad" LoadingPanelID="pnlAjaxLoading"/>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    var newTab = false;
                    (function ($)
                    {
                        $(document).ready(function ()
                        {
                            doLoadStuff();
                        });
                    })($telerik.$);

                    //Telerik DOM Id's
                    var cboIntelligentSearchId = '<%= cboIntelligentSearch.ClientID %>';
                    var ajaxManagerId = '<%= ajaMain.ClientID %>';
                    var toolTipId = '<%= toolTip.ClientID %>';
                    var tolErrorId = '<%= tolError.ClientID %>';
                    var trvMainId = '<%= trvMain.ClientID %>';
                    var splMainId = '<%= splMain.ClientID %>';
                    var pnlMainId = '<%= pnlMain.ClientID %>';
                    var contextMenuId = '<%= ctxMain.ClientID %>';
                    var btnSaveId = '<%= btnSave.ClientID %>';
                    var cboBidItemVersionId = '<%= cboBidItemVersion.ClientID %>';
        
                    //Strings
                    var Global_Undefined = '<%=Global_Undefined%>';
                    var Estimate_Project = '<%=Estimate_Project%>';
                    var Estimate_Description = '<%=Estimate_Description%>';
                    var ELECTRONIC_BIDDING_BEGIN = '<%=ELECTRONIC_BIDDING_BEGIN%>';
                    var Estimate_CannotDuplicate = '<%=Estimate_CannotDuplicate%>';
                    var Estimate_SelectProject = '<%=Estimate_SelectProject%>';
                    var Contract_Lock = '<%=Contract_Lock%>';
                    var Contract_Unlock = '<%=Contract_Unlock%>';

                    var ProjectTree_AddProject = "<%#ProjectTree_AddProject%>";
                    var ProjectTree_AddVersion = "<%#ProjectTree_AddVersion%>";
                    var ProjectTree_AddCategory = "<%#ProjectTree_AddCategory%>";
                    var ProjectTree_AddAlternateGroup = "<%#ProjectTree_AddAlternateGroup%>";
                    var ProjectTree_AddAlternate = "<%#ProjectTree_AddAlternate%>";
                    var ProjectTree_AddItem = "<%#ProjectTree_AddItem%>";
                    var ProjectTree_DeleteVersion = "<%#ProjectTree_DeleteVersion%>";
                    var ProjectTree_DeleteCategory = "<%#ProjectTree_DeleteCategory%>";
                    var ProjectTree_DeleteAlternateGroup = "<%#ProjectTree_DeleteAlternateGroup%>";
                    var ProjectTree_DeleteAlternate = "<%#ProjectTree_DeleteAlternate%>";
                    var ProjectTree_ConfirmDeleteVersion = "<%#ProjectTree_ConfirmDeleteVersion%>";
                    var ProjectTree_ConfirmDeleteCategory = "<%#ProjectTree_ConfirmDeleteCategory%>";
                    var ProjectTree_ConfirmDeleteAlternateGroup = "<%#ProjectTree_ConfirmDeleteAlternateGroup%>";
                    var ProjectTree_ConfirmDeleteAlternate = "<%#ProjectTree_ConfirmDeleteAlternate%>";
                    var ProjectTree_ConfirmDeleteHeader = "<%#ProjectTree_ConfirmDeleteHeader%>";
                    var ProjectTree_MoveProject = "<%#ProjectTree_MoveProject%>";
                    var TakeProject_TakeProject = "<%#TakeProject_TakeProject%>";
                    var TakeProject_TooManyWindows = "<%#TakeProject_TooManyWindows%>";
                    var Category_ItemFooter = '<%=Category_ItemFooter%>';
                </script>
            </telerik:RadCodeBlock>
            <div>
                <asp:Table runat="server" style="width:100%">
                    <asp:TableRow>
                        <asp:TableCell style="width:100px"  HorizontalAlign="Right">
                            <span runat="server" id="lblIntelligentSearchSpan">
                                <asp:Label runat="server" ID="lblIntelligentSearch" AssociatedControlID="cboIntelligentSearch" Text='<%#Estimate_SelectProject%>' CssClass="fieldPrompt"/>:
                            </span>
                        </asp:TableCell>
                        <asp:TableCell HorizontalAlign="Left">
                            <telerik:RadComboBox runat="server" ID="cboIntelligentSearch" Width="420px" Height="190px" DropDownWidth="610" EnableEmbeddedSkins="False" Skin="Skin_ipd"
                                                 AutoPostBack="false" EmptyMessage="<%#Global_IntelligentSearch%>" EnableLoadOnDemand="true" OnClientSelectedIndexChanging="changingContract"
                                                 AllowCustomText="true" OnItemsRequested="cboIntelligentSearch_OnItemsRequested" OnClientDropDownOpening="setIntelligentSearchHeaders"
                                                 OnItemDataBound="cboIntelligentSearch_ItemDataBound" HighlightTemplatedItems="True">
                                <HeaderTemplate>
                                    <table style="width:600px" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td style="width: 200px;" id="header2">
                                                <asp:Literal runat="server" ID="searchContractLiteral" Text="<%#Estimate_Project%>" />
                                            </td>
                                            <td style="width: 400px;" id="header3">
                                                <asp:Literal runat="server" ID="searchProjectLiteral" Text="<%#Estimate_Description%>" />
                                            </td>
                                        </tr>
                                    </table>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <table style="width:600px" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td style="width: 200px;"><%# DataBinder.Eval(Container.DataItem, "DD_NAME") %></td>
                                            <td style="width: 400px;"><%# DataBinder.Eval(Container.DataItem, "DD_DESCRIPTION") %></td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label runat="server" ID="lblRefineSearch" Text="<%#Category_ItemFooter%>" />
                                </FooterTemplate>
                            </telerik:RadComboBox>
                        </asp:TableCell>
                        <asp:TableCell HorizontalAlign="Right">
                            <span id="spnAdd" runat="server" style="display:inline-block;width:110px;text-align:right">
                                <telerik:RadButton ID="btnAddProject" Width="100" runat="server" AutoPostBack="false" EnableEmbeddedSkins="false" Skin="Skin_ipd"
                                                   OnClientClicked="addButtonClicked" Text="<%#CreateEstimate_AddContract%>"
                                                   secure="ProjectAdministrationGroup"/>
                            </span>
                            <span id="spnSave" runat="server" style="display:inline-block;width:65px;text-align:right">
                                <telerik:RadButton ID="btnSave" Width="60" runat="server" AutoPostBack="false" EnableEmbeddedSkins="false" Skin="Skin_ipd"
                                                   OnClientClicked="saveButtonClicked" Text="<%#Global_Save%>" Enabled="false"/>
                            </span>
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </div>
            <div>
                <telerik:RadSplitter ID="splMain" runat="server" Orientation="Vertical" OnClientLoad="splMain_OnClientLoad" ResizeMode="AdjacentPane">
                    <telerik:RadPane ID="RadPane1" runat="server" >
                        <telerik:RadComboBox ID="cboBidItemVersion" runat="server" Width="100%" TabIndex="5" EnableEmbeddedSkins="False" Skin="Skin_ipd"
                                             AutoPostBack="false" OnClientSelectedIndexChanged="selectVersionChanged" MarkFirstMatch="true">
                        </telerik:RadComboBox>
                        <hr/>
                        <telerik:RadTreeView ID="trvMain" runat="server" EnableDragAndDrop="true" OnClientNodeDragStart="nodeDragStart"
                                             OnClientNodeDropping="onNodeDropping" OnClientNodeDragging="onNodeDragging" OnClientNodeClicking="treeNodeClick"
                                             OnClientContextMenuItemClicking="trvMainMenuItemClick" OnClientContextMenuShowing="trvMainMenuOpening">
                            <Nodes></Nodes>
                            <ContextMenus>
                                <telerik:RadTreeViewContextMenu ID="ctxMain" runat="server">
                                    <Items>
                                        <telerik:RadMenuItem Value="Lock" Text="<%#Contract_Lock%>" ImageUrl="../Images/Add.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="AddX" Text="<%#ProjectTree_AddCategory%>" ImageUrl="../Images/Add.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Text="<%#Category_AddItemBatch%>" Value="AddInBatch" ImageUrl="../Images/Add.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Text="<%#Category_AddItemFile%>" Value="AddByFile" ImageUrl="../Images/Add.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="MoveProject" Text="<%#ProjectTree_MoveProject%>" ImageUrl="../Images/Add.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="AddExisting" Text="<%#TakeProject_TakeProject%>" ImageUrl="../Images/Add.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="AddGroup" Text="<%#ProjectTree_AddAlternateGroup%>" ImageUrl="../Images/Add.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="SelectVersion" Text="<%#ProjectTree_SelectVersion%>" ImageUrl="../Images/Properties.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="Delete" Text="<%#ProjectTree_Delete%>" ImageUrl="../Images/Delete.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="Cut" Text="<%#Global_Cut%>" ImageUrl="../Images/Cut.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="Copy" Text="<%#Global_Copy%>" ImageUrl="../Images/Copy.gif">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Value="Paste" Text="<%#Global_Paste%>" ImageUrl="../Images/Paste.gif">
                                        </telerik:RadMenuItem>
                                    </Items>
                                    <CollapseAnimation Type="none" />
                                </telerik:RadTreeViewContextMenu>
                            </ContextMenus>
                        </telerik:RadTreeView>
                    </telerik:RadPane>
                    <telerik:RadSplitBar ID="splMain1" runat="server">
                    </telerik:RadSplitBar>
                    <telerik:RadPane ID="pnlMain" runat="server" Width="100%" Height="100%" Scrolling="None">
                        <iframe id='ifrMain' runat='server' width='100%' height='100%'  style='border-style:none;overflow:hidden' />
                    </telerik:RadPane>
                </telerik:RadSplitter>
            </div>
            <telerik:RadToolTip runat="server" ID="tolError" OffsetX="125" Position="TopLeft" HideEvent="Default"
                                ShowEvent="FromCode" Width="175px" RelativeTo="Element" EnableShadow="true" AutoCloseDelay="3000" 
                                Animation="Fade" AnimationDuration="250" ShowCallout="false"
                                />
            <telerik:RadToolTip runat="server" OffsetX="560" OffsetY="0" Position="TopLeft" HideEvent="Default" ID="toolTip"
                                ShowEvent="FromCode" Width="85px" RelativeTo="Element" EnableShadow="false" ShowCallout="false" Text="<%#Tooltip_DataSaved%>"/>
            <asp:HiddenField ID="actionOnLoad" runat="server" />
            <asp:HiddenField ID="modified" Value="false" runat="server" />
            <asp:HiddenField ID="contractStatus" runat="server" />
            <asp:HiddenField ID="isReadOnly" runat="server" />
            <asp:HiddenField ID="ELECTRONIC_BIDDING_BEGIN" runat="server" />
            <asp:HiddenField ID="viewModelGuid" runat="server" Value="unset" />
            <asp:HiddenField ID="currentPrimaryKey" runat="server"/>
        </form>
    </body>
</html>

CreateEstimate.js:

var selectedNode;
var candidateSelectedNode;
var destinationNode = null;
var sourceNode = null;
var projectToBeSelected;
var projectNumberToBeSelected;
var ajaxLocation = "CreateEstimateAjax.aspx";
var nodeTypeToBeAdded;
var isOnwerAVersionOnAdd;
var parentNodeKeyOnAdd;
var appRoot = "..";
var childActionOnLoad;
var versionToBeSelected;
var selectVersionUponContract;

function doLoadStuff()
{
    doGenericLoadStuff(true);
    resizeSplitter();
    $(window).resize(function ()
    {
        resizeSplitter();
    });
    setModified(isModified());
    var actionOnLoadValue = $("#actionOnLoad").val();
    if (actionOnLoadValue && actionOnLoadValue.indexOf("load") >= 0)
    {
        projectToBeSelected = actionOnLoadValue.substring(4);
        doChangeProject(actionOnLoadValue.substring(4));
    }
}

function doChangeProject(projectToBeSelected)
{
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "changeProject", contractId: projectToBeSelected };
    $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function resizeSplitter()
{
    //We've got an issue with height and it's all over the place.  One issue is that
    //WC3 set the standard that for height, if you set the entire stack of DOM
    //elements to 100%, it'll show 0 height.  Basically, some element in the stack
    //has to have a specific value and not a percentage.  That causes issues.
    //Additionally, Telerik does some resizing of its own, which further complicates
    //things.  You're going to have to do some resizing like this in pretty much
    //every screen we make.
    //Resizing the entire splitter didn't work.  Seems that there's a Telerik
    //function that executes after this that sets the height to what it wants.
    //Therefore, what I'm doing is setting the height of the first pane within
    //the splitter.
    var splMain = $find(splMainId);
    var tempHeight = $(window).height();
    var totalHeight = tempHeight - 43;
    var mainWidth = $(window).width() - splMain.getStartPane().get_width() - 37;
    var frameWidth = mainWidth;
    var tempWidth = $(window).width();
    if (tempWidth > 1500)
    {
        frameWidth = mainWidth + 10;
    }
    else
    {
        frameWidth = mainWidth + 25;
    }
    splMain.getStartPane().set_height(totalHeight);
    splMain.getEndPane().set_height(totalHeight);
    splMain.getEndPane().set_width(mainWidth);
    var ifrMain = $("#ifrMain");
    if (ifrMain)
    {
        ifrMain.width(frameWidth);
        ifrMain.height(totalHeight);
    }
}

function returnYesNoCancel(result, type)
{
    switch (type)
    {
        case "confirmDelete":
            if (result == "yes")
            {
                var nodeType = selectedNode.get_attributes().getAttribute("nodeType");
                var nodeKey = selectedNode.get_attributes().getAttribute("key");
                doDelete(nodeType, nodeKey);
            }
            break;
        default:
            alert(Global_Undefined);
    }
}

//This function is currently not used in CreateEstimate, but is a standard call that 
//could be made from Index.js so we're leaving it in place.
function returnConfirm(result, type)
{
    switch (type)
    {
        case "SOMETHING":

            break;
        default:
            alert(Global_Undefined);
    }
}

function doAbandon()
{
    setModified(false);
    var nodeKey = selectedNode.get_attributes().getAttribute("key");
    var nodeType = selectedNode.get_attributes().getAttribute("nodeType");
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "reloadContract", nodeKey: nodeKey, nodeType: nodeType };
    $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function doCustomDeleteProcessing(xml)
{
    if ($(xml).find('RESULT').text() == "DELETE_SUCCESS")
    {
        var trvMain = $find(trvMainId);
        trvMain.trackChanges();
        nodeTypeKey = $(xml).find('DELETE_NODE_TYPE').text() + $(xml).find('DELETE_NODE_KEY').text();
        nodeToDelete = trvMain.findNodeByValue(nodeTypeKey);
        nodeToDelete.get_parent().get_nodes().remove(nodeToDelete);
        trvMain.commitChanges();
        var ifrMain = $("#ifrMain");
        if (ifrMain && ifrMain[0].contentWindow)
        {
            ifrMain[0].contentWindow.location = "about:blank";
        }
    }
}

function ajaxReturn(xml)
{
    var callResult = $(xml).find('RESULT').text();
    var trvMain = $find(trvMainId);
    var ifrMain = $("#ifrMain");
    var callResultXml;
    var mainNode;
    switch (callResult)
    {
        case "NEW_PROJECT_SUCCESS":
            callResultXml = $(xml).find('CALL_RESULT');
            trvMain.trackChanges();
            mainNode = trvMain.get_nodes().getNode(0);
            makeChildNodes(callResultXml[0], mainNode);
            trvMain.commitChanges();
            if (ifrMain && ifrMain[0].contentWindow)
            {
                ifrMain[0].contentWindow.location = "about:blank";
            }
            break;
        case "NEW_VERSION_SUCCESS":
            $("#isReadOnly").val($(xml).find('READ_ONLY').text());
            callResultXml = $(xml).find('CALL_RESULT');
            trvMain.trackChanges();
            mainNode = trvMain.get_nodes().getNode(0);
            if (mainNode.get_selected())
            {
                mainNode.unselect();
                selectedNode = null;
                candidateSelectedNode = null;
            }
            $(xml).find("CE_PROJECT").each(function ()
            {
                var projectNode;
                var nodeKey = $(this).find("PROJECT_NODE_KEY").text();
                for (var i = 0; i < mainNode.get_nodes().get_count(); i++)
                {
                    var tempNode = mainNode.get_nodes().getNode(i);
                    if (tempNode.get_attributes().getAttribute("key") == nodeKey)
                    {
                        projectNode = tempNode;
                        break;
                    }
                }
                projectNode.get_nodes().clear();
                makeChildNodes(this, projectNode);
            });
            trvMain.commitChanges();
            if (ifrMain && ifrMain[0].contentWindow)
            {
                ifrMain[0].contentWindow.location = "about:blank";
            }
            break;
        case "ADD_SUCCESS":
            var newNodeType = $(xml).find('NEW_NODE_TYPE').text();
            if (newNodeType == "EB_CONTRACT")
            {
                buildNewProjectNodes(xml);
                var nodes = trvMain.get_allNodes();
                for (var i = 0; i < nodes.length; i++)
                {
                    if (nodes[i].get_nodes() != null)
                    {
                        nodes[i].set_expanded(true);
                    }
                }
                trvMain.get_nodes().getNode(0).select();
                changeMain(trvMain.get_nodes().getNode(0));
            }
            else
            {
                var newNodeKey = $(xml).find('NEW_NODE_KEY').text();
                var newNodeText = $(xml).find('NEW_NODE_TEXT').text();
                var newNodeValue = $(xml).find('NEW_NODE_VALUE').text();
                candidateSelectedNode = makeNewNode(newNodeType, newNodeKey, newNodeText, newNodeValue, selectedNode.get_nodes());
                var parent = candidateSelectedNode.get_parent();
                if (parent && typeof parent.set_expanded == 'function')
                {
                    parent.set_expanded(true);
                }
                sortChildNodes(selectedNode);
                selectedNode = candidateSelectedNode;
                if (newNodeType == "CE_ESTIMATE_VERSION")
                {
                    var categoryNode = $(xml).find('CE_ESTIMATE_CATEGORY')[0];
                    switchSelectedVersion(selectedNode);
                    if (categoryNode)
                    {
                        callResultXml = $(xml).find('CALL_RESULT');
                        makeChildNodes(callResultXml[0], selectedNode);
                    }
                }
                changeMainContent();
            }
            break;
        case "NEW_CONTRACT_SUCCESS":
            $("#currentPrimaryKey").val($(xml).find('NEW_CONTRACT_KEY').text());
            $("#contractStatus").val($(xml).find('CONTRACT_STATUS').text());
            var doSelect = $(xml).find('DO_SELECT').text();
            $("#isReadOnly").val($(xml).find('READ_ONLY').text());
            setViewOnly();
            var cboIntelligentSearch = $find(cboIntelligentSearchId);
            cboIntelligentSearch.trackChanges();
            cboIntelligentSearch.clearItems();
            cboIntelligentSearch.set_text($(xml).find('NEW_CONTRACT_TEXT').text());
            cboIntelligentSearch.commitChanges();

            var cboBidItemVersion = $find(cboBidItemVersionId);
            cboBidItemVersion.trackChanges();
            cboBidItemVersion.clearItems();
            $(xml).find("BID_ITEM_VERSION").each(function ()
            {
                var versionText = $(this).text();
                var item = new Telerik.Web.UI.RadComboBoxItem();
                item.set_text(versionText.substring(0, versionText.indexOf("|")));
                item.set_value(versionText.substring(versionText.indexOf("|") + 1));
                cboBidItemVersion.get_items().add(item);
            });
            cboBidItemVersion.commitChanges();
            selectVersionUponContract = true;
            cboBidItemVersion.get_items().getItem(cboBidItemVersion.get_items().get_count() -1).select();
            buildNewProjectNodes(xml);
            if (ifrMain && ifrMain[0].contentWindow)
            {
                ifrMain[0].contentWindow.location = "about:blank";
            }
            //We're going to expand the project node selected.
            trvMain.get_nodes().getNode(0).set_expanded(true);
            if (projectToBeSelected)
            {
                var projectNode = trvMain.findNodeByValue("CE_PROJECT" + projectToBeSelected);
                projectNode.set_expanded(true);
                var versionNode;
                for (var i = 0; i < projectNode.get_nodes().get_count(); i++)
                {
                    var tempVersionNode = projectNode.get_nodes().getNode(i);
                    if (tempVersionNode.get_imageUrl() == "../Images/Selected.gif")
                    {
                        versionNode = tempVersionNode;
                        break
                    }
                }
                if (versionNode)
                {
                    versionNode.set_expanded(true);
                    //Now we're going to expand all Alternate Group nodes under the versionNode.
                    for (var i = 0; i < versionNode.get_nodes().get_count(); i++)
                    {
                        var childNode = versionNode.get_nodes().getNode(i);
                        childNode.set_expanded(true);
                        for (var j = 0; j < childNode.get_nodes().get_count(); j++)
                        {
                            var alternateNode = childNode.get_nodes().getNode(j);
                            alternateNode.set_expanded(true);
                        }
                    }
                }
                projectToBeSelected = null;
                projectNumberToBeSelected = null;
            }
            if (doSelect == "CONTRACT")
            {
                candidateSelectedNode = trvMain.get_nodes().getNode(0);
                changeMainContent();
            }
            break;
        case "PROJECT_ALREADY_CHOSEN":
            $find(cboIntelligentSearchId).set_text("");
            getIndexContainer(window).showAlert(Estimate_CannotDuplicate, 250, 140, Estimate_SelectProject);
            break;
        case "CUT_SUCCESS":
            trvMain.trackChanges();
            nodeTypeKey = $(xml).find('CUT_NODE_TYPE').text() + $(xml).find('CUT_NODE_KEY').text();
            nodeToDelete = trvMain.findNodeByValue(nodeTypeKey);
            nodeToDelete.get_parent().get_nodes().remove(nodeToDelete);
            trvMain.commitChanges();
            if (ifrMain && ifrMain[0].contentWindow)
            {
                ifrMain[0].contentWindow.location = "about:blank";
            }
            break;
        case "COPY_SUCCESS":
            // There's really nothing to do with a copy success.
            break;
        case "PASTE_SUCCESS":
            buildPastedNodes(xml);
            break;
        case "PASTE_FAIL":
            getIndexContainer(window).openValidationWindow(getValidationErrorList(xml));
            break;
        case "MOVE_SUCCESS":
            if (sourceNode && destinationNode)
            {
                var droppedNodeType = sourceNode.get_attributes().getAttribute("nodeType");
                trvMain.trackChanges();
                if (droppedNodeType == "CE_ESTIMATE_VERSION")
                {
                    sourceNode.set_imageUrl("../Images/Unselected.gif");
                }
                sourceNode.get_parent().get_nodes().remove(sourceNode);
                destinationNode.get_nodes().add(sourceNode);
                sortChildNodes(destinationNode);
                trvMain.commitChanges();
            }
            break;
        case "EXCEPTION":
            getIndexContainer(window).doError();
            break;
        case "SELECT_VERSION_SUCCESS":
            switchSelectedVersion(selectedNode);
            break;
        case "RELOAD_SUCCESS":
            var nodeKey = parseInt(selectedNode.get_attributes().getAttribute("key"));
            if (nodeKey < 0)
            {
                trvMain.trackChanges();
                var nodeToDelete = selectedNode;
                selectedNode.set_selected(false);
                selectedNode.get_parent().get_nodes().remove(nodeToDelete);
                trvMain.commitChanges();
            }
            candidateSelectedNode = selectedNode;
            if (candidateSelectedNode)
            {
                candidateSelectedNode.set_selected(true);
            }
            changeMainContent();
            break;
        case "TOGGLE_LOCK_SUCCESS":
            setModified(true);
            var menu = $find(contextMenuId);
            var menuLock = menu.findItemByValue("Lock");
            menu.trackChanges();
            if ($(xml).find('LOCKED').text() == "true")
            {
                menuLock.set_text(Contract_Unlock);
            }
            else
            {
                menuLock.set_text(Contract_Lock);
            }
            if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.setModified == 'function')
            {
                ifrMain[0].contentWindow.location = ifrMain[0].contentWindow.location;
            }
            menu.commitChanges();
            break;
    }
}

function setViewOnly()
{
    if ($("#isReadOnly").val() == "readOnly" || $("#isReadOnly").val() == "bidItemVersion")
    {
        $find(trvMainId).set_enableDragAndDrop(false);
    }
    else
    {
        $find(trvMainId).set_enableDragAndDrop(true);
    }
}

function buildNewProjectNodes(xml)
{
    var nodeType = "EB_CONTRACT";
    var nodeKey = $(xml).find('NEW_CONTRACT_KEY').text();
    var nodeText = $(xml).find('NEW_CONTRACT_TEXT').text();
    var nodeValue = $(xml).find('NEW_NODE_VALUE').text();
    var callResultXml = $(xml).find('CALL_RESULT');
    var trvMain = $find(trvMainId);
    trvMain.trackChanges();
    trvMain.get_nodes().clear();
    var newNode = makeNewNode(nodeType, nodeKey, nodeText, nodeValue, trvMain.get_nodes());
    newNode.set_allowDrag(false);
    makeChildNodes(callResultXml[0], newNode);
    trvMain.commitChanges();
}

function buildPastedNodes(xml)
{
    var pasteNodeType = $(xml).find('PASTE_NODE_TYPE').text();
    var pasteNodeKey = $(xml).find('PASTE_NODE_KEY').text();
    var pasteNodeText = $(xml).find('PASTE_NODE_TEXT').text();
    var pasteNodeValue = $(xml).find('PASTE_NODE_VALUE').text();
    var callResultXml = $(xml).find('CALL_RESULT');
    var trvMain = $find(trvMainId);
    trvMain.trackChanges();
    var newNode = makeNewNode(pasteNodeType, pasteNodeKey, pasteNodeText, pasteNodeValue, selectedNode.get_nodes());
    sortChildNodes(selectedNode);
    makeChildNodes(callResultXml[0], newNode);
    trvMain.commitChanges();
}

function makeChildNodes(xml, parentNode)
{
    var childNodes = xml.childNodes;
    for (var i = 0;i < childNodes.length;i++)
    {
        var childNode = childNodes[i];
        if ($(childNode).find('NODE_TYPE')[0])
        {
            var nodeKey;
            var nodeType;
            var nodeText;
            var nodeValue;
            for (var j = 0; j < childNode.childNodes.length; j++)
            {
                var childChildNode = $(childNode.childNodes[j]);
                switch (childChildNode[0].nodeName)
                {
                    case "NODE_KEY":
                        nodeKey = childChildNode.text();
                        break;
                    case "NODE_TYPE":
                        nodeType = childChildNode.text();
                        break;
                    case "NODE_TEXT":
                        nodeText = childChildNode.text();
                        break;
                    case "NODE_VALUE":
                        nodeValue = childChildNode.text();
                        break;
                }
            }
            if (nodeType.length > 0)
            {
                newNode = makeNewNode(nodeType, nodeKey, nodeText, nodeValue, parentNode.get_nodes());
                makeChildNodes(childNode, newNode);
            }
        }
    }
    if (parentNode && parentNode.get_attributes().getAttribute("nodeType") != "CE_PROJECT")
    {
        sortChildNodes(parentNode);
    }
}

function makeNewNode(nodeType, nodeKey, nodeText, nodeValue, nodes)
{
    var newNode = new Telerik.Web.UI.RadTreeNode();
    if (nodeType.indexOf("CE_ESTIMATE_VERSION") >= 0)
    {
        if (nodeType.substring(nodeType.indexOf("|") + 1) == "True")
        {
            newNode.set_imageUrl("../Images/Selected.gif");
        }
        else
        {
            newNode.set_imageUrl("../Images/Unselected.gif");
        }
        nodeType = "CE_ESTIMATE_VERSION";
    }
    newNode.set_text(nodeText);
    newNode.get_attributes().setAttribute("nodeType", nodeType);
    newNode.get_attributes().setAttribute("key", nodeKey);
    newNode.set_value(nodeValue);
    if (nodes)
    {
        nodes.add(newNode);
    }
    return newNode;
}

function returnDialog(arguments, callType)
{
    var argument = arguments.get_argument();
    if (argument)
    {
        var result = argument.substring(0, arguments.get_argument().indexOf("|"));
        argument = argument.substring(arguments.get_argument().indexOf("|") + 1);
        var inputData;
        switch (callType)
        {
            case "takeProject":
                inputData = { viewModelGuid: getViewModelGuid(), callType: "isTakeProjectCall" };
                $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
                break;
            case "AddProject":
                if (result == "successClose")
                {
                    var primaryKey = argument.substring(0, argument.indexOf("|"));
                    inputData = { viewModelGuid: getViewModelGuid(), callType: "getNewProjectNodes", key: primaryKey };
                    $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
                }
                else
                {
                    //Very odd.  If I don't do this timeout, the call to open a new window gets all crossed up
                    //with the Add New Project window that's in the middle of closing.  The result is the error
                    //message appears and immediately disappears.
                    setTimeout("getIndexContainer(window).doError();", 500);
                }
                break;
            case "AddContract":
                if (result == "successClose")
                {
                    var projectToBeSelected = argument.substring(0, argument.indexOf("|"));
                    projectNumberToBeSelected = argument.substring(argument.indexOf("|") + 1);
                    var cboIntelligentSearch = $find(cboIntelligentSearchId);
                    cboIntelligentSearch.trackChanges();
                    cboIntelligentSearch.clearItems();
                    cboIntelligentSearch.set_text(projectNumberToBeSelected);
                    cboIntelligentSearch.commitChanges();
                    doChangeProject(projectToBeSelected);
                }
                else
                {
                    //Very odd.  If I don't do this timeout, the call to open a new window gets all crossed up
                    //with the Add New Project window that's in the middle of closing.  The result is the error
                    //message appears and immediately disappears.
                    setTimeout("getIndexContainer(window).doError();", 500);
                }
                break;
            case "itemUpload":
                //Reloading the Category.aspx page.
                var ifrMain = $("#ifrMain");
                if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.reloadItems == 'function')
                {
                    ifrMain[0].contentWindow.reloadItems();
                }
                break;
        }
    }
}

//This is a TOTAL kludge, but it works so I'm going to leave it.  There's not a
//way to access the content of the cboSelectContract's HeaderTemplate in the code
//behind so changing the order of the columns in the code behind is nigh unto impossible.
//Yes, there's supposedly a way you can implement an ITemplate and set the HeaderTemplate,
//in its entirety, in the code behind.  A) I couldn't get that to work and B) this is 
//simpler.  This function, setSelectHeaders, will fire every time the user drops down
//the cboSelectContract combo box.  It'll read the selection in cboProjectSort and
//set the column header accordingly.
function setIntelligentSearchHeaders()
{
    $("#header2")[0].innerHTML = Estimate_Project;
    $("#header3")[0].innerHTML = Estimate_Description;
    $find(cboIntelligentSearchId).get_dropDownElement().children[2].innerHTML = Category_ItemFooter;
}

function doAddExistingProject(sender, args)
{
    if (getIndexContainer(window).permitTakeProject())
    {
        getIndexContainer(window).openWindow("Estimate/TakeProject.aspx?viewModelGuid=" + getViewModelGuid(), "Transfer Project", 650, 610, 50, 50, true, true, window, "takeProject", true);
    }
    else
    {
        getIndexContainer(window).showAlert(TakeProject_TooManyWindows, 400, 150, TakeProject_TakeProject);
    }
}

function saveButtonClicked(sender, args)
{
    saveData();
}

function addButtonClicked(sender, args)
{
    nodeTypeToBeAdded = "EB_CONTRACT";
    parentNodeKeyOnAdd = "0";
    isOnwerAVersionOnAdd = "false";

    if (isModified())
    {
        candidateSelectedNode = null;
        getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddNew");
    }
    else
    {
        doAddNew();
    }
}

function returnSavePromptResult(result, inCallType)
{
    //The SaveConfirm dialog permits the user to set saveAsYouGo to true.  If the user does, we need
    //to know that in JavaScript because ContractManagement.aspx would never reload.  I am definitely 
    //not a fan of this, but I slapped the saveAsYouGo value on the end of the result string.
    var saveAsYouGoControl;
    var ifrMain = $("#ifrMain");
    if (result.indexOf("True") > 0)
    {
        result = result.substring(0, result.indexOf("True"));
        saveAsYouGoControl = $("#saveAsYouGo");
        saveAsYouGoControl.val("true");
    }
    else if (result.indexOf("False") > 0)
    {
        result = result.substring(0, result.indexOf("False"));
        saveAsYouGoControl = $("#saveAsYouGo");
        saveAsYouGoControl.val("false");
    }
    switch (inCallType)
    {
        case "saveOnChangeMain":
            switch (result)
            {
                case "yes":
                    saveData();
                    break;
                case "no":
                    //I have to now allow the user to change tabs, which means I'll have to abandon changes to
                    //the previous contract and then change the tab
                    doAbandon();
                    break;
                case "cancel":
                    candidateSelectedNode = null;
                    break;
            }
            break;
        case "confirmSaveOnChangeProject":
            switch (result)
            {
                case "yes":
                    saveData();
                    break;
                case "no":
                    //I have to now allow the user to change projects, which means I just get the new project
                    setModified(false);
                    var cboIntelligentSearch = $find(cboIntelligentSearchId);
                    cboIntelligentSearch.trackChanges();
                    cboIntelligentSearch.clearItems();
                    cboIntelligentSearch.set_text(projectNumberToBeSelected);
                    cboIntelligentSearch.commitChanges();
                    doChangeProject(projectToBeSelected);
                    projectToBeSelected = null;
                    projectNumberToBeSelected = null;
                    if (ifrMain && ifrMain[0].contentWindow)
                    {
                        ifrMain[0].contentWindow.location = "about:blank";
                    }
                    break;
                case "cancel":
                    //No need to do anything here; the tab change has been cancelled.
                    break;
            }
            break;
        case "confirmSaveOnChangeVersion":
            switch (result)
            {
                case "yes":
                    saveData();
                    break;
                case "no":
                    //I have to now allow the user to change projects, which means I just get the new project
                    setModified(false);
                    doChangeVersion(versionToBeSelected);
                    versionToBeSelected = null;
                    if (ifrMain && ifrMain[0].contentWindow)
                    {
                        ifrMain[0].contentWindow.location = "about:blank";
                    }
                    break;
                case "cancel":
                    //No need to do anything here; the tab change has been cancelled.
                    break;
            }
            break;
        case "confirmSaveOnAddNew":
            switch (result)
            {
                case "yes":
                    saveData();
                    break;
                case "no":
                    doAbandon();
                    doAddNew();
                    break;
                case "cancel":
                    //No need to do anything here; the tab change has been cancelled.
                    break;
            }
            break;
    }
}

function changingContract(sender, args)
{
    if (isModified())
    {
        args.set_cancel(true);
        projectToBeSelected = args.get_item().get_value();
        projectNumberToBeSelected = args.get_item().get_text();
        getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnChangeProject");
    }
    else
    {
        projectToBeSelected = args.get_item().get_value();
        doChangeProject(projectToBeSelected);
    }
}

function isInEletronicBidding()
{
    return $("#contractStatus").val() >= $("#ELECTRONIC_BIDDING_BEGIN").val();
}

function trvMainMenuOpening(sender, args)
{
    //Right-clicking on a node other than the selected
    //node will fire this event first.  Therefore, we have to see if the selectedNode
    //is different than the node we get in args.  If the new, incoming node is different
    //than selectedNode, we'll permit the context-sensitive menu to show, but only if
    //the main form's "modified" value is false.  If it is true, then we'll kill this
    //menu opening and call chnageMain.
    var treeNode = args.get_node();
    if (treeNode != selectedNode)
    {
        //First thing we'll do is see of our main page's content is modified.
        var ifrMain = $("#ifrMain");
        if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
        {
            //We're going to cancel the context-sensitive menu so it's not in the
            //way when we do the save when we changeMain.
            args.set_cancel(true);
            return false;
        }
        else
        {
            //The current main page is not modified.  We can go ahead and permit this thing to open.
            setContextSensitiveContent(treeNode);
        }
        treeNode.select();
        if (!changeMain(args.get_node()))
        {
            args.set_cancel(true);
        }
    }
    else
    {
        args.set_cancel(false);
        setContextSensitiveContent(treeNode);
    }
}

function setContextSensitiveContent(treeNode)
{
    var menu = $find(contextMenuId);
    var menuLock = menu.findItemByValue("Lock");
    var menuAddX = menu.findItemByValue("AddX");
    var menuAddInBatch = menu.findItemByValue("AddInBatch");
    var menuAddByFile = menu.findItemByValue("AddByFile");
    var menuAddGroup = menu.findItemByValue("AddGroup");
    var addExisting = menu.findItemByValue("AddExisting");
    var moveProject = menu.findItemByValue("MoveProject");
    var menuDelete = menu.findItemByValue("Delete");
    var menuCut = menu.findItemByValue("Cut");
    var menuCopy = menu.findItemByValue("Copy");
    var menuPaste = menu.findItemByValue("Paste");
    var selectVersion = menu.findItemByValue("SelectVersion");
    menu.trackChanges();
    if ($("#isReadOnly").val() == "readOnly")
    {
        menuLock ? menuLock.set_enabled(false) : false;
        addExisting ? addExisting.set_enabled(false) : false;
        menuAddX ? menuAddX.set_enabled(false) : false;
        menuAddInBatch ? menuAddInBatch.set_enabled(false) : false;
        menuAddByFile ? menuAddByFile.set_enabled(false) : false;
        menuAddGroup ? menuAddGroup.set_enabled(false) : false;
        menuDelete ? menuDelete.set_enabled(false) : false;
        menuCut ? menuCut.set_enabled(false) : false;
        menuCopy ? menuCopy.set_enabled(true) : true;
        menuPaste ? menuPaste.set_enabled(false) : false;
        selectVersion ? selectVersion.set_enabled(false) : false;
        moveProject ? moveProject.set_enabled(false) : false;
    }
    else if ($("#isReadOnly").val() == "bidItemVersion")
    {
        menuLock ? menuLock.set_enabled(true) : true;
        addExisting ? addExisting.set_enabled(false) : false;
        menuAddInBatch ? menuAddInBatch.set_enabled(true) : true;
        menuAddByFile ? menuAddByFile.set_enabled(true) : true;
        menuAddGroup ? menuAddGroup.set_enabled(true) : true;
        menuCopy ? menuCopy.set_enabled(true) : true;
        menuPaste ? menuPaste.set_enabled(false) : false;
        selectVersion ? selectVersion.set_enabled(false) : false;
        moveProject ? moveProject.set_enabled(false) : false;

        var nodeType = treeNode.get_attributes().getAttribute("nodeType");
        if (nodeType == "EB_CONTRACT" || nodeType == "CE_PROJECT")
        {
            menuAddX ? menuAddX.set_enabled(false) : false;
            menuDelete ? menuDelete.set_enabled(false) : false;
            menuCut ? menuCut.set_enabled(false) : false;
        }
        else if (nodeType == "CE_ESTIMATE_VERSION")
        {
            menuAddX ? menuAddX.set_enabled(true) : true;
            menuDelete ? menuDelete.set_enabled(false) : false;
            menuCut ? menuCut.set_enabled(false) : false;
        }
        else
        {
            menuAddX ? menuAddX.set_enabled(true) : true;
            menuDelete ? menuDelete.set_enabled(true) : true;
            menuCut ? menuCut.set_enabled(true) : true;
        }
    }
    else
    {
        menuLock ? menuLock.set_enabled(true) : true;
        addExisting ? addExisting.set_enabled(true) : true;
        menuAddX ? menuAddX.set_enabled(true) : true;
        menuAddInBatch ? menuAddInBatch.set_enabled(true) : true;
        menuAddByFile ? menuAddByFile.set_enabled(true) : true;
        menuAddGroup ? menuAddGroup.set_enabled(true) : true;
        menuDelete ? menuDelete.set_enabled(true) : true;
        menuCut ? menuCut.set_enabled(true) : true;
        menuCopy ? menuCopy.set_enabled(true) : true;
        menuPaste ? menuPaste.set_enabled(true) : true;
        selectVersion ? selectVersion.set_enabled(true) : true;
        moveProject ? moveProject.set_enabled(true) : true;

        menuLock ? menuLock.set_visible(true) : true;
        menuAddX ? menuAddX.set_visible(true) : true;
        menuAddInBatch ? menuAddInBatch.set_visible(true) : true;
        menuAddByFile ? menuAddInBatch.set_visible(true) : true;
        menuAddGroup ? menuAddGroup.set_visible(true) : true;
        menuDelete ? menuDelete.set_visible(true) : true;
        menuCut ? menuCut.set_visible(true) : true;
        menuCopy ? menuCopy.set_visible(true) : true;
        menuPaste ? menuPaste.set_visible(true) : true;
        selectVersion ? selectVersion.set_visible(true) : true;
        moveProject ? moveProject.set_visible(true) : true;
    }
    switch (treeNode.get_attributes().getAttribute("nodeType"))
    {
        case "EB_CONTRACT":
            menuAddX ? menuAddX.set_text(ProjectTree_AddProject) : true;
            menuLock ? menuAddX.set_visible(true) : true;
            addExisting ? addExisting.set_visible(true) : true;
            menuAddX ? menuAddX.set_visible(true) : true;
            menuAddInBatch ? menuAddInBatch.set_visible(false) : false;
            menuAddByFile ? menuAddByFile.set_visible(false) : false;
            menuAddGroup ? menuAddGroup.set_visible(false) : false;
            menuDelete ? menuDelete.set_visible(false) : false;
            menuCut ? menuCut.set_visible(false) : false;
            menuCopy ? menuCopy.set_visible(false) : false;
            menuPaste ? menuPaste.set_visible(false) : false;
            selectVersion ? selectVersion.set_visible(false) : false;
            moveProject ? moveProject.set_visible(false) : false;
            break;
        case "CE_PROJECT":
            menuLock ? menuLock.set_visible(false) : false;
            menuAddX ? menuAddX.set_text(ProjectTree_AddVersion) : true;
            menuAddX ? menuAddX.set_visible(true) : true;
            menuAddInBatch ? menuAddInBatch.set_visible(false) : false;
            menuAddByFile ? menuAddByFile.set_visible(false) : false;
            addExisting ? addExisting.set_visible(false) : false;
            menuAddGroup ? menuAddGroup.set_visible(false) : false;
            menuDelete ? menuDelete.set_visible(false) : false;
            menuCut ? menuCut.set_visible(false) : false;
            menuCopy ? menuCopy.set_visible(false) : false;
            selectVersion ? selectVersion.set_visible(false) : false;

            if (treeNode.get_parent().get_nodes().get_count() > 1)
            {
                moveProject ? moveProject.set_visible(true) : true;
            }
            else
            {
                moveProject ? moveProject.set_visible(false) : false;
            }

            //You can paste a Version or a project
            if (getIndexContainer(window).getClipboardType() == "CE_ESTIMATE_VERSION")
            {
                menuPaste ? menuPaste.set_visible(true) : true;
            }
            else
            {
                menuPaste ? menuPaste.set_visible(false) : false;
            }
            break;
        case "CE_ESTIMATE_VERSION":
            menuLock ? menuLock.set_visible(false) : false;
            menuAddX ? menuAddX.set_text(ProjectTree_AddCategory) : true;
            menuDelete ? menuDelete.set_text(ProjectTree_DeleteVersion) : true;
            menuAddX ? menuAddX.set_visible(true) : true;
            menuAddInBatch ? menuAddInBatch.set_visible(false) : false;
            menuAddByFile ? menuAddByFile.set_visible(false) : false;
            addExisting ? addExisting.set_visible(false) : false;
            menuAddGroup ? menuAddGroup.set_visible(true) : true;
            menuDelete ? menuDelete.set_visible(true) : true;
            menuCut ? menuCut.set_visible(true) : true;
            menuCopy ? menuCopy.set_visible(true) : true;
            moveProject ? moveProject.set_visible(false) : false;
            if (isModified() || isInEletronicBidding())
            {
                menuCut ? menuCut.set_enabled(false) : false;
            }
            else
            {
                menuCut ? menuCut.set_enabled(true) : true;
            }
            menuCopy ? menuCopy.set_enabled(true) : true;
            selectVersion ? selectVersion.set_visible(true) : true;
            //You can paste a Category or an Alternate Group on a version
            if (getIndexContainer(window).getClipboardType() == "CE_ESTIMATE_CATEGORY" || getIndexContainer(window).getClipboardType() == "CE_ALTERNATE_GROUP")
            {
                menuPaste ? menuPaste.set_visible(true) : true;
            }
            else
            {
                menuPaste ? menuPaste.set_visible(false) : false;
            }
            break;
        case "CE_ESTIMATE_CATEGORY":
            menuLock ? menuLock.set_visible(false) : false;
            menuDelete ? menuDelete.set_text(ProjectTree_DeleteCategory) : true;
            menuAddX ? menuAddX.set_text(ProjectTree_AddItem) : true;
            menuAddX ? menuAddX.set_visible(true) : true;
            menuAddInBatch ? menuAddInBatch.set_visible(true) : true;
            menuAddByFile ? menuAddByFile.set_visible(true) : true;
            addExisting ? addExisting.set_visible(false) : false;
            menuDelete ? menuDelete.set_visible(true) : true;
            menuCut ? menuCut.set_visible(true) : true;
            menuCopy ? menuCopy.set_visible(true) : true;
            moveProject ? moveProject.set_visible(false) : false;
            if (isModified() || isInEletronicBidding())
            {
                menuCut ? menuCut.set_enabled(false) : false;
            }
            else
            {
                menuCut ? menuCut.set_enabled(true) : true;
            }
            menuCopy ? menuCopy.set_enabled(true) : true;
            selectVersion ? selectVersion.set_visible(false) : false;
            //You can paste Items on a Category
            if (getIndexContainer(window).getClipboardType() == "ITEM")
            {
                menuPaste ? menuPaste.set_visible(true) : true;
            }
            else
            {
                menuPaste ? menuPaste.set_visible(false) : false;
            }
            menuAddGroup ? menuAddGroup.set_visible(false) : false;
            break;
        case "CE_ALTERNATE_GROUP":
            menuLock ? menuLock.set_visible(false) : false;
            menuAddX ? menuAddX.set_text(ProjectTree_AddAlternate) : true;
            menuDelete ? menuDelete.set_text(ProjectTree_DeleteAlternateGroup) : true;
            menuAddX ? menuAddX.set_visible(true) : true;
            menuAddInBatch ? menuAddInBatch.set_visible(false) : false;
            menuAddByFile ? menuAddByFile.set_visible(false) : false;
            addExisting ? addExisting.set_visible(false) : false;
            menuDelete ? menuDelete.set_visible(true) : true;
            menuCut ? menuCut.set_visible(true) : true;
            menuCopy ? menuCopy.set_visible(true) : true;
            moveProject ? moveProject.set_visible(false) : false;
            if (isModified() || isInEletronicBidding())
            {
                menuCut ? menuCut.set_enabled(false) : false;
            }
            else
            {
                menuCut ? menuCut.set_enabled(true) : true;
            }
            menuCopy ? menuCopy.set_enabled(true) : true;
            selectVersion ? selectVersion.set_visible(false) : false;
            //You can paste Items on a Category
            if (getIndexContainer(window).getClipboardType() == "CE_ALTERNATE")
            {
                menuPaste ? menuPaste.set_visible(true) : true;
            }
            else
            {
                menuPaste ? menuPaste.set_visible(false) : false;
            }
            menuAddGroup ? menuAddGroup.set_visible(false) : false;
            break;
        case "CE_ALTERNATE":
            menuLock ? menuLock.set_visible(false) : false;
            menuAddX ? menuAddX.set_text(ProjectTree_AddCategory) : true;
            menuDelete ? menuDelete.set_text(ProjectTree_DeleteAlternate) : true;
            menuAddX ? menuAddX.set_visible(true) : true;
            menuAddInBatch ? menuAddInBatch.set_visible(false) : false;
            menuAddByFile ? menuAddByFile.set_visible(false) : false;
            addExisting ? addExisting.set_visible(false) : false;
            menuDelete ? menuDelete.set_visible(true) : true;
            menuCut ? menuCut.set_visible(true) : true;
            menuCopy ? menuCopy.set_visible(true) : true;
            moveProject ? moveProject.set_visible(false) : false;
            if (isModified() || isInEletronicBidding())
            {
                menuCut ? menuCut.set_enabled(false) : false;
            }
            else
            {
                menuCut ? menuCut.set_enabled(true) : true;
            }
            menuCopy ? menuCopy.set_enabled(true) : true;
            selectVersion ? selectVersion.set_visible(false) : false;
            //You can paste Category items on an Alternate
            if (getIndexContainer(window).getClipboardType() == "CE_ESTIMATE_CATEGORY")
            {
                menuPaste ? menuPaste.set_visible(true) : true;
            }
            else
            {
                menuPaste ? menuPaste.set_visible(false) : false;
            }
            menuAddGroup ? menuAddGroup.set_visible(false) : false;
            break;
        default:
            break;
    }
    //Last thing we'll do is disable a bunch of functions if the node in question
    //is in the process of being added.
    if (treeNode.get_attributes().getAttribute("key") < 0)
    {
        menuLock ? menuLock.set_enabled(false) : false;
        menuAddX ? menuAddX.set_enabled(false) : false;
        menuAddInBatch ? menuAddInBatch.set_enabled(false) : false;
        menuAddByFile ? menuAddByFile.set_enabled(false) : false;
        menuAddGroup ? menuAddGroup.set_enabled(false) : false;
        addExisting ? addExisting.set_enabled(false) : false;
        moveProject ? moveProject.set_enabled(false) : false;
        menuCut ? menuCut.set_enabled(false) : false;
        menuCopy ? menuCopy.set_enabled(false) : false;
        menuPaste ? menuPaste.set_enabled(false) : false;
        selectVersion ? selectVersion.set_enabled(false) : false;
    }
    menu.commitChanges();
}

function trvMainMenuItemClick(sender, args)
{
    var menuItem = args.get_menuItem();
    menuItem.get_menu().hide();
    selectedNode = args.get_node();
    var nodeType = selectedNode.get_attributes().getAttribute("nodeType");
    var nodeKey = selectedNode.get_attributes().getAttribute("key");
    var ifrMain = $("#ifrMain");
    var saveAsYouGo = $("#saveAsYouGo").val();
    var inputData;
    switch (menuItem.get_value())
    {
        case "Lock":
            doLock();
            break;
        case "AddX":
            switch (nodeType)
            {
                case "EB_CONTRACT":
                    nodeTypeToBeAdded = "CE_PROJECT";
                    isOnwerAVersionOnAdd = false;
                    parentNodeKeyOnAdd = nodeKey;
                    if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
                    {
                        if (saveAsYouGo == "true")
                        {
                            saveData();
                        }
                        else
                        {
                            getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddNew");
                        }
                    }
                    else
                    {
                        doAddNew();
                    }
                    break;
                case "CE_PROJECT":
                    nodeTypeToBeAdded = "CE_ESTIMATE_VERSION";
                    isOnwerAVersionOnAdd = false;
                    parentNodeKeyOnAdd = nodeKey;
                    if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
                    {
                        if (saveAsYouGo == "true")
                        {
                            saveData();
                        }
                        else
                        {
                            getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddNew");
                        }
                    }
                    else
                    {
                        doAddNew();
                    }
                    break;
                case "CE_ESTIMATE_VERSION":
                    nodeTypeToBeAdded = "CE_ESTIMATE_CATEGORY";
                    isOnwerAVersionOnAdd = true;
                    parentNodeKeyOnAdd = nodeKey;
                    if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
                    {
                        if (saveAsYouGo == "true")
                        {
                            saveData();
                        }
                        else
                        {
                            getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddNew");
                        }
                    }
                    else
                    {
                        doAddNew();
                    }
                    break;
                case "CE_ALTERNATE_GROUP":
                    nodeTypeToBeAdded = "CE_ALTERNATE";
                    isOnwerAVersionOnAdd = true;
                    parentNodeKeyOnAdd = nodeKey;
                    if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
                    {
                        if (saveAsYouGo == "true")
                        {
                            saveData();
                        }
                        else
                        {
                            getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddNew");
                        }
                    }
                    else
                    {
                        doAddNew();
                    }
                    break;
                case "CE_ALTERNATE":
                    nodeTypeToBeAdded = "CE_ESTIMATE_CATEGORY";
                    isOnwerAVersionOnAdd = false;
                    parentNodeKeyOnAdd = nodeKey;
                    if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
                    {
                        if (saveAsYouGo == "true")
                        {
                            saveData();
                        }
                        else
                        {
                            getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddNew");
                        }
                    }
                    else
                    {
                        doAddNew();
                    }
                    break;
                case "CE_ESTIMATE_CATEGORY":
                    if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.addItem == 'function')
                    {
                        ifrMain[0].contentWindow.addItem(false);
                    }
                    break;
            }
            break;
        case "AddInBatch":
            if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.addItem == 'function')
            {
                ifrMain[0].contentWindow.addItem(true);
            }
            break;
        case "AddByFile":
            if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.getCategoryKey == 'function')
            {
                var categoryPrimaryKey = ifrMain[0].contentWindow.getCategoryKey();
                getIndexContainer(window).openWindow("Estimate/ItemUpload.aspx?viewModelGuid=" + getViewModelGuid() + "&key=" + categoryPrimaryKey, "Item Upload", 450, 200, 50, 50, true, false, window, "itemUpload", true);
            }
            break;
        case "AddExisting":
            if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
            {
                if (saveAsYouGo == "true")
                {
                    saveData();
                    doAddExistingProject();
                }
                else
                {
                    contractToBeSelected = "CE_PROJECT";
                    getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddExistingProject");
                }
            }
            else
            {
                doAddExistingProject();
            }
            break;
        case "AddGroup":
            nodeTypeToBeAdded = "CE_ALTERNATE_GROUP";
            isOnwerAVersionOnAdd = true;
            parentNodeKeyOnAdd = nodeKey;
            if (ifrMain && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
            {
                if (saveAsYouGo == "true")
                {
                    saveData();
                    doAddNew();
                }
                else
                {
                    contractToBeSelected = "CE_ALTERNATE_GROUP";
                    getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnAddNew");
                }
            }
            else
            {
                doAddNew();
            }
            break;
        case "Delete":
            switch (nodeType)
            {
                case "CE_ESTIMATE_VERSION":
                    getIndexContainer(window).showYesNoCancel(ProjectTree_ConfirmDeleteVersion, 300, 150, ProjectTree_ConfirmDeleteHeader, window, "confirmDelete", false);
                    break;
                case "CE_ESTIMATE_CATEGORY":
                    getIndexContainer(window).showYesNoCancel(ProjectTree_ConfirmDeleteCategory, 300, 150, ProjectTree_ConfirmDeleteHeader, window, "confirmDelete", false);
                    break;
                case "CE_ALTERNATE_GROUP":
                    getIndexContainer(window).showYesNoCancel(ProjectTree_ConfirmDeleteAlternateGroup, 300, 150, ProjectTree_ConfirmDeleteHeader, window, "confirmDelete", false);
                    break;
                case "CE_ALTERNATE":
                    getIndexContainer(window).showYesNoCancel(ProjectTree_ConfirmDeleteAlternate, 300, 150, ProjectTree_ConfirmDeleteHeader, window, "confirmDelete", false);
                    break;
            }
            break;
        case "Cut":
            getIndexContainer(window).setClipboardType(nodeType);
            inputData = { viewModelGuid: getViewModelGuid(), callType: "isCutCall", nodeType: nodeType, nodeKey: nodeKey };
            $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
            break;
        case "Copy":
            getIndexContainer(window).setClipboardType(nodeType);
            inputData = { viewModelGuid: getViewModelGuid(), callType: "isCopyCall", nodeType: nodeType, nodeKey: nodeKey };
            $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
            break;
        case "Paste":
            if (getIndexContainer(window).getClipboardType() == "ITEM")
            {
                //If the clipboard type is items, I'm going to go to Category.aspx to paste them. 
                //I'm not going to use the Ajax infrastructure to do so.
                if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.doPaste == 'function')
                {
                    ifrMain[0].contentWindow.doPaste();
                }
            }
            else
            {
                inputData = { viewModelGuid: getViewModelGuid(), callType: "isPasteCall", nodeType: nodeType, nodeKey: nodeKey };
                $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
            }
            break;
        case "SelectVersion":
            inputData = { viewModelGuid: getViewModelGuid(), callType: "selectVersion", nodeKey: nodeKey };
            $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
            break;
        case "MoveProject":
            inputData = { viewModelGuid: getViewModelGuid(), callType: "moveToNewContract", projectKey: nodeKey };
            $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
            break;
    }
}

function onNodeDragging(sender, args)
{
    var target = args.get_htmlElement();

    if (!target)
        return;

    if (target.tagName == "INPUT")
    {
        target.style.cursor = "hand";
    }

    var grid = isMouseOverGrid(target)
    if (grid)
    {
        grid.style.cursor = "hand";
    }
}

function nodeDragStart(sender, args)
{
    var draggedType = args.get_node().get_attributes().getAttribute("nodeType");
    var trvMain = $find(trvMainId);
    var nodes = trvMain.get_allNodes();
    for (var i = 0; i < nodes.length; i++)
    {
        var overType = nodes[i].get_attributes().getAttribute("nodeType");
        //CONTRACT and PROJECT objects cannot be dragged.
        switch (draggedType)
        {
            case "CE_ESTIMATE_VERSION":
                if (overType == "CE_PROJECT")
                {
                    nodes[i].set_allowDrop(true);
                }
                else
                {
                    nodes[i].set_allowDrop(false);
                }
                break;
            case "CE_ESTIMATE_CATEGORY":
                if (overType == "CE_ESTIMATE_VERSION" || overType == "CE_ALTERNATE")
                {
                    nodes[i].set_allowDrop(true);
                }
                else
                {
                    nodes[i].set_allowDrop(false);
                }
                break;
            case "CE_ALTERNATE_GROUP":
                if (overType == "CE_ESTIMATE_VERSION")
                {
                    nodes[i].set_allowDrop(true);
                }
                else
                {
                    nodes[i].set_allowDrop(false);
                }
                break;
            case "CE_ALTERNATE":
                if (overType == "CE_ALTERNATE_GROUP")
                {
                    nodes[i].set_allowDrop(true);
                }
                else
                {
                    nodes[i].set_allowDrop(false);
                }
                break;
        }
    }
    args.get_node().get_parent().set_allowDrop(false);
}

function isMouseOverGrid(target)
{
    parentNode = target;
    while (parentNode != null)
    {
        parentNode = parentNode.parentNode;
    }
    return null;
}

function onNodeDropping(sender, args)
{
    destinationNode = args.get_destNode();
    if (destinationNode)
    {
        if (destinationNode.get_allowDrop())
        {
            sourceNode = args.get_sourceNodes()[0];
            if (sourceNode)
            {
                //The TreeView has the dragged node in the right spot, but the Model component doesn't have the
                //proper foreign key to its parent.  We have to make an AJAX call to change that.
                //We need to pass a bunch of information to the AJAX handler.  Getting that now.
                var droppedNodeType = sourceNode.get_attributes().getAttribute("nodeType");
                var droppedNodeKey = sourceNode.get_attributes().getAttribute("key");
                var receivingNodeType = destinationNode.get_attributes().getAttribute("nodeType");
                var receivingNodeKey = destinationNode.get_attributes().getAttribute("key");
                var inputData = { viewModelGuid: getViewModelGuid(), callType: "isDropCall", dnt: droppedNodeType, dnk: droppedNodeKey, rnt: receivingNodeType, rnk: receivingNodeKey };
                $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
            }
        }
    }
}

function splMain_OnClientLoad(splitter, args)
{
    var indexes = $telerik.$(".indexes");
    indexes.each(function (i)
    {
        $telerik.$(this).click(function ()
        {
            var contentPane = splitter.getPaneById("pnlMain");
            var pageNo = $telerik.$(this).text();

            var scrollValue = 650 * (pageNo - 1); //650 is the height of a 'page'
            contentPane.setScrollPos(0, scrollValue);
        });
    });
}

function treeNodeClick(object, args)
{
    if (!changeMain(args.get_node()))
    {
        args.set_cancel(true);
    }
}

function changeMain(inSelectedNode)
{
    if (inSelectedNode != selectedNode)
    {
        //First thing we'll do is see if the currently-displayed ASPX has been changed.
        //If it has not, we'll just permit the change to happen without doing a thing.
        //If it has, we'll need to call saveData
        candidateSelectedNode = inSelectedNode;
        //Couldn't get the jquery way of doing this to work so we're just doing straight
        //JavaScript
        var ifrMain = $("#ifrMain");
        if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.isModified == 'function' && ifrMain[0].contentWindow.isModified())
        {
            //First thing we'll do here is to see if saveAsYouGo is true.
            var saveAsYouGo = getIndexContainer(window).getSaveAsYouGo();
            if (saveAsYouGo == "true")
            {
                saveData();
            }
            else
            {
                //We have an unusual set of circumstances right here.  If there's a new
                //Version, it might have a new Calculated Items node underneath it.  If so,
                //we have to send an immediate false.  Letting the save confirm thing show
                //and continue with that process, then we'll get JavaScript errors if the 
                //user clicks on that Calculated Items node.
                var selectedNodeType = selectedNode.get_attributes().getAttribute("nodeType");
                var selectedNodeKey = parseInt(selectedNode.get_attributes().getAttribute("key"));
                var newNodeKey = parseInt(inSelectedNode.get_attributes().getAttribute("key"));
                if (selectedNodeType == "CE_ESTIMATE_VERSION" && selectedNodeKey < 0 && newNodeKey < 0 && selectedNode.get_nodes().get_count() > 0)
                {
                    return false;
                }
                getIndexContainer(window).showSaveConfirm(window, "saveOnChangeMain");
            }
            return false;
        }
        else
        {
            changeMainContent();
            return true;
        }
    }
    else
    {
        return true;
    }
}

function changeMainContent()
{
    var nodeType;
    if (candidateSelectedNode)
    {
        selectedNode = candidateSelectedNode;
        candidateSelectedNode = null;
        selectedNode.select();
        nodeType = selectedNode.get_attributes().getAttribute("nodeType");
    }
    //Doing the work of setting ifrMain's content.  Now, you might be wondering why
    //I'm dynamically adding an iframe instead of creating a static iframe and then
    //changing its content.  The reason is that I need to be able to call the iframe's
    //scripts.  The DOM gets all wonky when you dynamically change an iframe's
    //src property
    var ifID = document.getElementById('ifrMain');
    if (ifID)
    {
        ifID.parentNode.removeChild(ifID);
    }
    switch (nodeType)
    {
        case "EB_CONTRACT":
            $find(pnlMainId).get_element().innerHTML = "<iframe id='ifrMain' runat='server' style='border-style:none;width:100%;height:100%;overflow:hidden' scrolling='no' src='Contract.aspx?key=" + selectedNode.get_attributes().getAttribute("key") + "&viewModelGuid=" + getViewModelGuid() + "'/>";
            break;
        case "CE_PROJECT":
            $find(pnlMainId).get_element().innerHTML = "<iframe id='ifrMain' runat='server' style='border-style:none;width:100%;height:100%;overflow:hidden' scrolling='no' src='ProjectSetup.aspx?key=" + selectedNode.get_attributes().getAttribute("key") + "&viewModelGuid=" + getViewModelGuid() + "'/>";
            break;
        case "CE_ESTIMATE_VERSION":
            $find(pnlMainId).get_element().innerHTML = "<iframe id='ifrMain' runat='server' style='border-style:none;width:100%;height:100%;overflow:hidden' scrolling='no' src='Version.aspx?key=" + selectedNode.get_attributes().getAttribute("key") + "&viewModelGuid=" + getViewModelGuid() + "'/>";
            break;
        case "CE_ESTIMATE_CATEGORY":
            $find(pnlMainId).get_element().innerHTML = "<iframe id='ifrMain' runat='server' style='border-style:none;width:100%;height:100%;overflow:hidden' scrolling='no' src='Category.aspx?key=" + selectedNode.get_attributes().getAttribute("key") + "&viewModelGuid=" + getViewModelGuid() + "'/>";
            break;
        case "CE_ALTERNATE_GROUP":
            $find(pnlMainId).get_element().innerHTML = "<iframe id='ifrMain' runat='server' style='border-style:none;width:100%;height:100%;overflow:hidden' scrolling='no' src='AlternateGroup.aspx?key=" + selectedNode.get_attributes().getAttribute("key") + "&viewModelGuid=" + getViewModelGuid() + "'/>";
            break;
        case "CE_ALTERNATE":
            $find(pnlMainId).get_element().innerHTML = "<iframe id='ifrMain' runat='server' style='border-style:none;width:100%;height:100%;overflow:hidden' scrolling='no' src='Alternate.aspx?key=" + selectedNode.get_attributes().getAttribute("key") + "&viewModelGuid=" + getViewModelGuid() + "'/>";
            break;
        default:
            break;
    }
    resizeSplitter();
}

function switchSelectedVersion(selectedNode)
{
    var siblingNodes = selectedNode.get_parent().get_nodes();
    for (var i = 0; i < siblingNodes.get_count(); i++)
    {
        siblingNodes.getNode(i).set_imageUrl("../Images/Unselected.gif");
    }
    selectedNode.set_imageUrl("../Images/Selected.gif");
}

function sortChildNodes(parentNode)
{
    var nodes = parentNode.get_nodes();
    var sortNode;
    var testNode;
    var i;
    var j;
    for (i = 0; i < nodes.get_count(); i++)
    {
        sortNode = nodes.getNode(i);
        var nodeType = sortNode.get_attributes().getAttribute("nodeType");
        var nodeText = sortNode.get_text();
        if (nodeType == "CE_ESTIMATE_CATEGORY")
        {
            for (j = 0; j < nodes.get_count(); j++)
            {
                testNode = nodes.getNode(j);
                if (testNode.get_attributes().getAttribute("nodeType") == "CE_ALTERNATE_GROUP")
                {
                    nodes.insert(j, sortNode);
                    break;
                }
                else if (testNode.get_text().toLowerCase() >= nodeText.toLowerCase())
                {
                    nodes.insert(j, sortNode);
                    break;
                }
            }
            nodes.insert(j, sortNode);
        }
        else if (nodeType == "CE_ALTERNATE_GROUP")
        {
            for (j = 0; j < nodes.get_count(); j++)
            {
                testNode = nodes.getNode(j);
                var test = testNode.get_attributes().getAttribute("nodeType");
                if (test == "CE_ALTERNATE_GROUP" && testNode.get_text().toLowerCase() >= nodeText.toLowerCase())
                {
                    nodes.insert(i, sortNode);
                    break;
                }
            }
            nodes.insert(j, sortNode);
        }
        else
        {
            for (j = 0; j < nodes.get_count(); j++)
            {
                testNode = nodes.getNode(j);
                if (testNode.get_text().toLowerCase() >= nodeText.toLowerCase())
                {
                    nodes.insert(j, sortNode);
                    break;
                }
            }
            nodes.insert(j, sortNode);
        }
        if (sortNode == selectedNode)
        {
            sortNode.set_selected(true);            
        }
    }
}

function doLock()
{
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "toggleLockCall" };
    $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function doAddNew()
{
    if (nodeTypeToBeAdded == "CE_PROJECT")
    {
        getIndexContainer(window).openWindow("Estimate/AddProject.aspx?viewModelGuid=" + getViewModelGuid() + "&contractKey=" + getContractKey(), "AddProject", 760, 310, 150, 100, true, true, window, "AddProject", true);
        nodeTypeToBeAdded = null;
        parentNodeKeyOnAdd = null;
    }
    else if (nodeTypeToBeAdded == "EB_CONTRACT")
    {
        var trvMain = $find(trvMainId);
        trvMain.trackChanges();
        trvMain.get_nodes().clear();
        trvMain.commitChanges();
        var ifrMain = $("#ifrMain");
        ifrMain[0].contentWindow.location = "about:blank";
        $find(cboIntelligentSearchId).set_text("");
        getIndexContainer(window).openWindow("Estimate/AddProject.aspx?viewModelGuid=" + getViewModelGuid() + "&contractKey=NEW", "AddContract", 760, 410, 150, 100, true, true, window, "AddContract", true);
        nodeTypeToBeAdded = null;
        parentNodeKeyOnAdd = null;
    }
    else
    {
        setViewOnly();
        var inputData = { viewModelGuid: getViewModelGuid(), callType: "isAddCall", nodeType: nodeTypeToBeAdded, parentNodeKey: parentNodeKeyOnAdd, isOwnerAVersion: isOnwerAVersionOnAdd };
        $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
        nodeTypeToBeAdded = null;
        parentNodeKeyOnAdd = null;
    }
}

function setNodeText(newText)
{
    var trvMain = $find(trvMainId);
    trvMain.trackChanges();
    selectedNode.set_text(newText);
    sortChildNodes(selectedNode.get_parent());
    trvMain.commitChanges();
}

function getContractKey()
{
    return $("#currentPrimaryKey").val();
}

function doCustomSaveProcessing(xml)
{
    var ifrMain = $("#ifrMain");
    var saveResults = $(xml).find('RESULT').text();
    //This is the function called by the ifrMain's ASPX when that ASPX's save work is done.
    //It'll process the results.
    if (saveResults == "SAVE_SUCCESS")
    {
        if (getIndexContainer(window).getSaveAsYouGo() == "true")
        {
            showSaveToolTip();
        }
        var nodeKey = selectedNode.get_attributes().getAttribute("key");
        if (nodeKey < 0)
        {
            //I'm sure there's a way to select a node by the node's text, but I couldn't see it quickly online.
            //Therefore, I'm doing this in the cheesy way.
            $(xml).find("KEY_PAIR").each(function ()
            {
                var oldKey = $(this).find("OLD_KEY").text();
                if (oldKey == nodeKey)
                {
                    selectedNode.get_attributes().setAttribute("key", $(this).find("NEW_KEY").text());
                    selectedNode.set_value(selectedNode.get_attributes().getAttribute("nodeType") + $(this).find("NEW_KEY").text());
                }
                else
                {
                    for (var i = 0; i < selectedNode.get_nodes().get_count(); i++)
                    {
                        var node = selectedNode.get_nodes().getNode(i);
                        var childNodeKey = node.get_attributes().getAttribute("key");
                        if (oldKey == childNodeKey)
                        {
                            node.get_attributes().setAttribute("key", $(this).find("NEW_KEY").text());
                            node.set_value(node.get_attributes().getAttribute("nodeType") + $(this).find("NEW_KEY").text());
                        }
                    }
                }
            });
        }
        if (projectToBeSelected > 0)
        {
            //You now have to do a number of things here.  First, you have to set the intelligent search's
            //text property to be the new project selected.  Then you have to get rid of the iframe so nothing
            //is showing in the main content area.
            var selectProject = $find(cboIntelligentSearchId);
            selectProject.trackChanges();
            selectProject.clearItems();
            selectProject.set_text(projectNumberToBeSelected);
            selectProject.commitChanges();
            doChangeProject(projectToBeSelected);
            if (ifrMain && ifrMain[0].contentWindow)
            {
                ifrMain[0].contentWindow.location = "about:blank";
            }
        }
        else if (candidateSelectedNode)
        {
            candidateSelectedNode.set_selected(true);
            setTimeout("changeMainContent()", 100);
        }
        else if (nodeTypeToBeAdded != null && nodeTypeToBeAdded.length > 0)
        {
            doAddNew();
        }
        else if (versionToBeSelected > 0)
        {
            doChangeVersion(versionToBeSelected);    
        }
        getIndexContainer(window).notifySave(true);
    }
    else if (saveResults.indexOf("SAVE_SUCCESS_NEW_CONTRACT") >= 0)
    {
        $("#actionOnLoad").val(saveResults);
        $("#estimateForm").submit();
    }
    else if (saveResults == "SAVE_CONCURRENCY")
    {
        projectToBeSelected = null;
        projectNumberToBeSelected = null;
        candidateSelectedNode = null;
        getIndexContainer(window).openValidationWindow(getValidationErrorList(xml));
        getIndexContainer(window).notifySave(false);
        //Reloading the page so it grabs the most current data.
        $("#ifrMain")[0].contentWindow.location = $("#ifrMain")[0].contentWindow.location;
    }
    else if (saveResults == "SAVE_FAIL")
    {
        //Don't need to do anything here because there are no fields on the CreateEstimate page.
    }
    if (ifrMain[0] && ifrMain[0].contentWindow && typeof ifrMain[0].contentWindow.doCustomSaveProcessing == 'function')
    {
        ifrMain[0].contentWindow.doCustomSaveProcessing(xml);
    }
}

function reloadPage()
{
    $("#ifrMain")[0].contentWindow.location = $("#ifrMain")[0].contentWindow.location;
}

function reloadEstimate()
{
    doChangeContract($("#currentPrimaryKey").val());
}

function doChangeContract(contractToBeSelected)
{
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "changeContract", contractId: contractToBeSelected };
    $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function selectVersionChanged(sender, args)
{
    if (selectVersionUponContract)
    {
        selectVersionUponContract = false;
    }
    else
    {
        if (isModified())
        {
            args.set_cancel(true);
            versionToBeSelected = args.get_item().get_value();
            getIndexContainer(window).showSaveConfirm(window, "confirmSaveOnChangeVersion");
        }
        else
        {
            versionToBeSelected = args.get_item().get_value();
            doChangeVersion(versionToBeSelected);
        }
    }
}

function doChangeVersion(inVersionToBeSelected)
{
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "changeVersion", versionNumber: inVersionToBeSelected };
    $.ajax({ type: 'POST', url: ajaxLocation, success: ajaxReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

Main.js:

//Using this variable to avoid an endless loop in the setModified function.
var haveSetEstimateModfied = false;
var haveSetBiddingModfied = false;
var haveSetSubContractModified = false;
var haveSetChangeOrderModified = false;
var changedComboBox;
var comboBoxChangeback = false;
var overflowCounter = 0;

function doGenericLoadStuff()
{
    if (window.location.href.indexOf(window.parent.location.href) == 0)
    {
        //This is where relative paths break down.  The ASPX calling this function
        //could be anywhere in our application.  I'm going to get the path from a hidden value,
        //if it exists.  If it doesn't exist, I'm going to send the user to msn.com.  This if
        //statement exists so that users do not attempt to enter a URL path to an ASPX that is
        //intended to be shown within Index.aspx somewhere.
        if (appRoot) 
        {
            window.location = appRoot + "/Index.aspx";
        }
        else 
        {
            window.location = "http://www.msn.com";
        }
    }
    else
    {
        if ($("#actionOnLoad").val() == "notLoggedIn")
        {
            //This will reload the page, causing Login.aspx to be shown.
            getIndexContainer(window).location = appRoot + "/Index.aspx";
        }
        else if ($("#actionOnLoad").val() == "doError")
        {
            getIndexContainer(window).doError();
        }
        else
        {
            if ($("#viewModelGuid"))
            {
                registerThisViewModel();
                setInterval("registerThisViewModel()", 59000);
            }
        }
    }
}

function registerThisViewModel()
{
    getIndexContainer(window).registerViewModel($("#viewModelGuid").val());
}

function isModified()
{
    if ($("#modified").val() == "true")
    {
        return true;
    }
    else
    {
        return false;
    }
}

function getIndexContainer(inForm)
{
    overflowCounter++;
    if (overflowCounter > 50)
    {
        overflowCounter = 0;
        return null;
    }
    if (inForm.location.href.indexOf(inForm.parent.location.href) == 0 && inForm.location.href.indexOf("Index") >= 0)
    {
        //If inForm is the outermost container, we'll return it.
        overflowCounter = 0;
        return inForm;
    }
    else
    {
        //If inForm is NOT the outermost container, it'll call itself until
        //the very outermost container is found and return that.
        var test = inForm.location.href == inForm.parent.location.href;
        return getIndexContainer(inForm.parent);
    }
}

function getCreateEstimateContainer(inForm)
{
    overflowCounter++;
    if (overflowCounter > 50)
    {
        overflowCounter = 0;
        return null;
    }
    if (inForm.location.href.indexOf("CreateEstimate.aspx") >= 0)
    {
        //If inForm is the outermost container, we'll return it.
        return inForm;
    }
    else if (inForm.parent.location.toString().indexOf("Index.aspx") == -1)
    {
        //If inForm is NOT the outermost container, it'll call itself until
        //the very outermost container is found and return that.
        return getCreateEstimateContainer(inForm.parent);
    }
    else
    {
        return null;
    }
}

function getBiddingContainer(inForm)
{
    overflowCounter++;
    if (overflowCounter > 50)
    {
        overflowCounter = 0;
        return null;
    }
    if (inForm.location.href.indexOf("ElectronicBidding.aspx") >= 0)
    {
        //If inForm is the outermost container, we'll return it.
        return inForm;
    }
    else if (inForm.parent.location.toString().indexOf("Index.aspx") == -1)
    {
        //If inForm is NOT the outermost container, it'll call itself until
        //the very outermost container is found and return that.
        return getBiddingContainer(inForm.parent);
    }
    else
    {
        return null;
    }
}

function getSubContractContainer(inForm)
{
    overflowCounter++;
    if (overflowCounter > 50)
    {
        overflowCounter = 0;
        return null;
    }
    if (inForm.location.href.indexOf("SubContractorManagement.aspx") >= 0) 
    {
        //If inForm is the outermost container, we'll return it.
        return inForm;
    }
    else if (inForm.parent.location.toString().indexOf("Index.aspx") == -1) 
    {
        //If inForm is NOT the outermost container, it'll call itself until
        //the very outermost container is found and return that.
        return getSubContractContainer(inForm.parent);
    } 
    else 
    {
        return null;
    }
}

function getChangeOrderContainer(inForm)
{
    overflowCounter++;
    if (overflowCounter > 50)
    {
        overflowCounter = 0;
        return null;
    }
    if (inForm.location.href.indexOf("ChangeOrderManagement.aspx") >= 0) 
    {
        //If inForm is the outermost container, we'll return it.
        return inForm;
    }
    else if (inForm.parent.location.toString().indexOf("Index.aspx") == -1) 
    {
        //If inForm is NOT the outermost container, it'll call itself until
        //the very outermost container is found and return that.
        return getChangeOrderContainer(inForm.parent);
    }
    else 
    {
        return null;
    }
}

function setModified(isModified)
{
    var estimateContainer = getCreateEstimateContainer(window);
    var biddingContainer = getBiddingContainer(window);
    var subcontractContainer = getSubContractContainer(window);
    var changeOrderContainer = getChangeOrderContainer(window);
    var btnSave;
    if (typeof btnSaveId != "undefined")
    {
        btnSave = $find(btnSaveId);
    }
    if (!isModified || isModified == "false")
    {
        $("#modified").val("false");
        if (btnSave)
        {
            btnSave.set_enabled(false);
        }
        if (!haveSetEstimateModfied)
        {
            haveSetEstimateModfied = true;
            if (estimateContainer)
            {
                estimateContainer.setModified(false);
            }
        }
        else
        {
            haveSetEstimateModfied = false;
        }
        if (!haveSetBiddingModfied)
        {
            haveSetBiddingModfied = true;
            if (biddingContainer)
            {
                biddingContainer.setModified(false);
            }
        }
        else
        {
            haveSetBiddingModfied = false;
        }
        if (!haveSetSubContractModified) 
        {
            haveSetSubContractModified = true;
            if (subcontractContainer) 
            {
                subcontractContainer.setModified(false);
            }
        }
        else
        {
            haveSetSubContractModified = false;
        }
    }
    else
    {
        if (!haveSetEstimateModfied)
        {
            haveSetEstimateModfied = true;
            if (estimateContainer)
            {
                estimateContainer.setModified(true);
            }
        }
        else
        {
            haveSetEstimateModfied = false;
        }
        if (!haveSetBiddingModfied)
        {
            haveSetBiddingModfied = true;
            if (biddingContainer)
            {
                biddingContainer.setModified(true);
            }
        }
        else
        {
            haveSetBiddingModfied = false;
        }
        if (!haveSetSubContractModified) 
        {
            haveSetSubContractModified = true;
            if (subcontractContainer) 
            {
                subcontractContainer.setModified(true);
            }
        }
        else 
        {
            haveSetSubContractModified = false;
        }
        if (!haveSetChangeOrderModified) 
        {
            haveSetChangeOrderModified = true;
            if (changeOrderContainer) 
            {
                changeOrderContainer.setModified(true);
            }
        }
        else 
        {
            haveSetChangeOrderModified = false;
        }
        if (btnSave)
        {
            btnSave.set_enabled(true);
        }
        $("#modified").val("true");
    }
}

function myvoid() 
{
    ;
}

function clearPoundSign(inString)
{
    if (inString && typeof inString.indexOf == 'function')
    {
        while (inString.indexOf("#") >= 0)
        {
            inString = inString.replace("#", "%23");
        }
        while (inString.indexOf("+") >= 0)
        {
            inString = inString.replace("+", "%2b");
        }
    }
    return inString;
}

function clearAmpersand(inString)
{
    if (inString && typeof inString.indexOf == 'function')
    {
        while (inString.indexOf("&") >= 0)
        {
            inString = inString.replace("&", "%26");
        }
    }
    return inString;
}

function selectValueChanged(sender, args)
{
    if (comboBoxChangeback)
    {
        comboBoxChangeback = false;
    }
    else
    {
        fieldValueChanged(sender);
    }
}

function fieldValueChanged(changedControl)
{
    setModified(true);
    window.parent.setModified(true);
    var changedControljq;
    if (changedControl)
    {
        changedControljq = $(changedControl);
    }
    else
    {
        return;
    }
    var mapping;
    var newValue;
    var formatting = "";
    var errorFieldName;
    var primaryKey = $("#currentPrimaryKey").val();
    if (changedControljq.parent().attr("mapping"))
    {
        //Odd.  Sometimes, checkboxes show up in this format.  Other times, they show up in a format we're accounting for
        //just below this if.
        changedControljq = $(changedControl);
        mapping = changedControljq.parent().attr("mapping");
        newValue = changedControljq.is(":checked");
        if (changedControljq.parent().attr("primaryKey") != null && changedControljq.parent().attr("primaryKey").length > 0)
        {
            primaryKey = changedControljq.parent().attr("primaryKey");
        }
        errorFieldName = changedControljq.parent().attr("errorFieldName");
    }
    else if (changedControl && changedControl.firstElementChild && changedControl.firstElementChild.type == "checkbox")
    {
        //This is an ASP CheckBox as well.  For some reason, ASP .NET is laying it out differently in this case.
        changedControljq = $(changedControl);
        mapping = changedControljq.attr("mapping");
        if (changedControl.firstElementChild.checked)
        {
            newValue = true;
        }
        else
        {
            newValue = false;
        }
        if (changedControljq.attr("primaryKey") != null && changedControljq.attr("primaryKey").length > 0)
        {
            primaryKey = changedControljq.attr("primaryKey");
        }
        errorFieldName = changedControljq.attr("errorFieldName");
    }
    else if (changedControl.id)
    {
        //I'm going to get a jquery handle on the control.  They're so much easier to get information from.
        changedControljq = $("#" + changedControl.id);
        mapping = changedControljq.attr("mapping");
        newValue = changedControljq.val();
        if (!newValue)
        {
            newValue = changedControljq.val();
        }
        if (changedControljq.attr("primaryKey") != null && changedControljq.attr("primaryKey").length > 0)
        {
            primaryKey = changedControljq.attr("primaryKey");
        }
        if (changedControljq.attr("formatting") != undefined)
        {
            formatting = changedControljq.attr("formatting");
        }
        errorFieldName = changedControljq.attr("errorFieldName");
    }
    else if (changedControl && typeof changedControl.set_expandDirection == 'function')
    {
        //We have a Telerik combo box.
        changedControljq = changedControl;
        changedComboBox = changedControl;
        mapping = changedControljq.get_attributes().getAttribute("mapping");
        newValue = changedControljq.get_value();
        //A bit odd.  The following line, remarked out, is the way I'd normally get
        //an attribute on a combo box.
        //primaryKey = sender.get_attributes().getAttribute("primaryKey");
        //That's Telerik's way.  Works fine under most circumstances, but I have
        //code that deals with a save to a temporary primary and switches it to
        //a permanent, database one.  For some reason, that line above is still
        //returning the old key.  So, we'll get the primary key with the following
        //line.
        primaryKey = $(changedControljq.get_element()).attr("primaryKey");
        errorFieldName = changedControljq.get_attributes().getAttribute("errorFieldName");
    }
    else if (changedControl && typeof changedControl.get_buttonType == 'function')
    {
        //Well, that's not cool.  While other Telerik contrls support custom attributes, 
        //the RadButton doesn't appear to.  For example, look above at the code we have for the
        //Telerik combo box.  I have that get_attributes().getAttribute line.  Well, can't do 
        //that for a RadButton. So, we're going to use the RadButton's GroupName property for the
        //mapping and the Value property for the newValue.  It's a deviation from our preferred
        //standard, but it'll work.
        //Also, the primary key is getting stuck on the end of the group name so we have to strip 
        //it off.
        changedControljq = changedControl;
        newValue = changedControljq.get_value();
        mapping = changedControljq.get_groupName();
        if (mapping.length > 0)
        {
            primaryKey = mapping.substring(mapping.lastIndexOf("|") + 1);
            mapping = mapping.substring(0, mapping.lastIndexOf("|"));
        }
        else
        {
            var element = changedControljq.get_element();
            mapping = $(element.outerHTML).attr("mapping");
            primaryKey = $(element.outerHTML).attr("primaryKey");
        }
    }
    else if (changedControl && typeof changedControl.get_selectedDate == 'function')
    {
        var elementComponent = changedControl.get_element();
        var searchString = "[id*='" + elementComponent.id + "_wrapper']";
        var wrapperComponent = $(searchString);
        primaryKey = wrapperComponent.attr("primaryKey");
        mapping = wrapperComponent.attr("mapping");
        errorFieldName = wrapperComponent.attr("errorFieldName");
        newValue = changedControl.get_textBox().value;
    }
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "fieldValueChanged", mapping: mapping, newValue: newValue, formatting: formatting, errorFieldName: errorFieldName, primaryKey: primaryKey };
    $.ajax({ type: 'POST', url: ajaxLocation, success: fieldValueChangedReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function fieldValueChangedReturn(xml)
{
    var resultValue = $(xml).find('RESULT').text();
    var primaryKey = $(xml).find('PRIMARY_KEY').text();
    var propertyField;
    var errorImageField;
    var searchString;
    switch (resultValue)
    {
        case "SUCCESS":
            if (primaryKey && primaryKey.length > 0)
            {
                propertyField = $("[mapping='" + $(xml).find('PROPERTY').text() + "'][primaryKey='" + primaryKey + "']");
            }
            else
            {
                propertyField = $("[mapping='" + $(xml).find('PROPERTY').text() + "']");
            }
            var formattedReturnValue = $(xml).find('FORMATTED_RETURN_VALUE').text();
            if (formattedReturnValue)
            {
                propertyField.val(formattedReturnValue);
            }
            //If we got a successful change, the error field might be showing because the user
            //previously entered a bad value.  Hiding it here.
            searchString = "[id*='" + propertyField.attr("errorImageField") + "']";
            errorImageField = $(searchString);
            errorImageField.hide();
            //We're setting a variable in case a combo box change causes a VALIDATION_FAIL.
            //If we're here and changeComboBox is not null, we're going to unset it so
            //it doesn't cause problems with future validation fails.
            if (changedComboBox)
            {
                changedComboBox = null;
            }
            break;
        case "VALIDATION_FAIL":
            var exceptionText = $(xml).find('ERROR_TEXT').text();
            var previousValue = $(xml).find('PREVIOUS_VALUE').text();
            propertyField = $("[mapping='" + $(xml).find('PROPERTY').text() + "'][primaryKey='" + primaryKey + "']");
            if (changedComboBox)
            {
                comboBoxChangeback = true;
                changedComboBox.findItemByValue(previousValue).select();
                changedComboBox = null;
            }
            else
            {
                propertyField.val(previousValue);
                var checkBox = $(propertyField[0].children[0]);
                if (checkBox)
                {
                    if (previousValue == "true")
                    {
                        checkBox.attr('checked', 'checked');
                    }
                    else
                    {
                        checkBox.removeAttr('checked');
                    }
                }
            }
            searchString = "#" + propertyField.attr("errorImageField");
            errorImageField = $(searchString);
            searchString = "[id*='" + propertyField.attr("errorTextField") + "']";
            var errorTextField = $(searchString);
            errorTextField.val(exceptionText);
            errorImageField.show();
            propertyField.focus();
            var tempPosition = propertyField.position();
            tempPosition.left = tempPosition.left + Number(propertyField.css("width").substring(0, propertyField.css("width").length - 2));
            tempPosition.top = tempPosition.top + 20;
            showErrorTip(tempPosition, propertyField.attr("errorTextField"));
            break;
        case "EXCEPTION":
            getIndexContainer(window).doError();
            break;
    }
    if (typeof doCustomChangeProcessing == 'function')
    {
        doCustomChangeProcessing(xml);
    }
}

function doDelete(objectType, objectKey)
{
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "isDeleteCall", objectType: objectType, objectKey: objectKey };
    $.ajax({ type: 'POST', url: ajaxLocation, success: deleteReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function deleteReturn(xml)
{
    setModified(false);
    var callResult = $(xml).find('RESULT').text();
    switch (callResult)
    {
        case "DELETE_SUCCESS":

            break;
        case "DELETE_FAIL":
            doSaveFail(xml);
            break;
        case "EXCEPTION":
            getIndexContainer(window).doError();
            break;
    }
    if (typeof doCustomDeleteProcessing == 'function')
    {
        doCustomDeleteProcessing(xml);
    }
}

function getViewModelGuid()
{
    if ($("#childViewModelGuid").length > 0)
    {
        return $("#childViewModelGuid").val();
    }
    else
    {
        if ($("#viewModelGuid").length > 0)
        {
            return $("#viewModelGuid").val();
        }
        else if (parent.location.toString().indexOf("Index.aspx") == -1)
        {
            return parent.getViewModelGuid();
        }
        else
        {
            return null;
        }
    }
}

function showErrorTip(inOffset, inTextField)
{
    var tolError = $find(tolErrorId);
    if (tolError)
    {
        var searchString = "[id*='" + inTextField + "']";
        var errorMessage = $(searchString).val();
        tolError.set_offsetX(inOffset.left);
        tolError.set_offsetY(inOffset.top);
        tolError.set_text(errorMessage);
        tolError.show();
    }
}

function saveData()
{
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "saveData" };
    $.ajax({ type: 'POST', url: ajaxLocation, success: saveReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function saveReturn(xml)
{
    var resultValue = $(xml).find('RESULT').text();
    switch (resultValue)
    {
        case "SAVE_SUCCESS":
            hideValidationImages();
            setModified(false);
            if (parent && typeof parent.setModified == 'function')
            {
                parent.setModified(false);
            }
            $(xml).find("KEY_PAIR").each(function ()
            {
                var oldKey = $(this).find("OLD_KEY").text();
                var newKey = $(this).find("NEW_KEY").text();
                var fieldToChange = $("[primaryKey='" + oldKey + "']");
                fieldToChange.attr("primaryKey", newKey);
            });
            break;
        case "SAVE_CONCURRENCY":
            if (doConcurrencyFail && typeof doConcurrencyFail == 'function')
            {
                doConcurrencyFail(xml);
            }
            break;
        case "SAVE_FAIL":
            //If there's a doCustomSaveProcessing, then that function is responsible
            //for showing the save fail message.
            if (typeof doCustomSaveProcessing != 'function')
            {
                doSaveFail(xml);
            }
            break;
        case "EXCEPTION":
            getIndexContainer(window).doError();
            break;
    }
    if (parent && parent.ajaxLocation != undefined)
    {
        parent.saveReturn(xml);
    }
    if (typeof doCustomSaveProcessing == 'function')
    {
        doCustomSaveProcessing(xml);
    }
}

function getValidationErrorList(xml)
{
    var returnString = "";
    $(xml).find("RESULT_RECORD").each(function ()
    {
        returnString = returnString + "|" + $(this).find("RESULT_TEXT").text();
    });
    return returnString;
}

function doSaveFail(xml)
{
    $(xml).find("RESULT_RECORD").each(function ()
    {
        var mappingString = $(this).find("MAPPING").text();
        if (mappingString.length > 0)
        {
            var valueBox;
            var i;
            var mappedFields = mappingString.split("|");
            //First thing to do is to get a "replaced" text string.  That means we'll
            //replace all the mapping names in the error text with the errorFieldName values.
            var formattedString = $(this).find("RESULT_TEXT").text()
            for (i = 0; i < mappedFields.length; i++)
            {
                var mapping = mappedFields[i];
                valueBox = $("[mapping*='" + mapping + "']");
                var errorFieldName;
                for (var j = 0; j < valueBox.length; j++)
                {
                    var testName = $(valueBox[j]).attr("errorFieldName");
                    if (testName && testName.length > 0)
                    {
                        errorFieldName = $(valueBox[j]).attr("errorFieldName");
                    }
                }
                if (errorFieldName != null)
                {
                    formattedString = clearPoundSign(formattedString.replace(mapping, errorFieldName));
                }
            }
            $(this).find("RESULT_TEXT").text(formattedString);
            for (i = 0; i < mappedFields.length; i++)
            {
                valueBox = $("[mapping*='" + mappedFields[i] + "']");
                var searchString = "[id*='" + valueBox.attr("errorTextField") + "']";
                $(searchString).val(formattedString);
                searchString = "[id*='" + valueBox.attr("errorImageField") + "']";
                $(searchString).show();
            }
        }
    });
    getIndexContainer(window).openValidationWindow(getValidationErrorList(xml));
    getIndexContainer(window).notifySave(false);
}

function doConcurrencyFail(xml)
{
    getIndexContainer(window).openValidationWindow(getValidationErrorList(xml));
    getIndexContainer(window).notifySave(false);
}

function hideValidationImages()
{
    $(".validationImage").each(function ()
    {
        $(this).hide();
    }
    );
}

function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow)
    {
        oWindow = window.radWindow;
    }
    else if (window.frameElement.radWindow)
    {
        oWindow = window.frameElement.radWindow;
    }
    return oWindow;
}

function showCommentsDialog(mapping, primaryKey, isReadOnly)
{
    var indexPage = getIndexContainer(window);
    indexPage.openTextDetail(window, mapping, primaryKey, getViewModelGuid(), textHeader, isReadOnly);
}

function ajaxError(xhr, ajaxOptions, thrownError)
{
    alert("A client-side error occurred.  Please report the following to ExeVision, LLC: " + xhr.responseText);
    getIndexContainer(window).doError();
}

function getAbsolutePosition(element)
{
    var tempPosition = new Point();
    tempPosition.left = 0;
    tempPosition.top = 0;
    do
    {
        tempPosition.left = tempPosition.left + element.offsetLeft;
        tempPosition.top = tempPosition.top + element.offsetTop;
        element = element.offsetParent;
    }
    while (element.offsetParent);
    return tempPosition;
}

//Used by the getAbsolutePosition function above.
function Point()
{
    this.x;
    this.y;
}

function listTransferring(sender, args)
{
    setModified(true);
    parent.setModified(true);
    var ajaxUrl;
    var newValues = args.get_items();
    var newValuesList = "";
    var i;
    for (i = 0; i < newValues.length; i++)
    {
        if (newValuesList.length != 0)
        {
            newValuesList = newValuesList + "|"
        }
        newValuesList = newValuesList + newValues[i].get_value();
    }
    var sourceBox = args.get_sourceListBox();
    var destinationBox = args.get_destinationListBox();
    var isAssigning = destinationBox.get_attributes().getAttribute("isAssigned") != null;
    var mapping;
    var isAdding;
    var owningKey = 0;
    if (isAssigning)
    {
        mapping = sourceBox.get_attributes().getAttribute("mapping");
        isAdding = "true";
    }
    else
    {
        mapping = destinationBox.get_attributes().getAttribute("mapping");
        isAdding = "false";
    }
    if ($("#currentPrimaryKey"))
    {
        owningKey = $("#currentPrimaryKey").val();
    }
    setTimeout(function ()
    {
        destinationBox.clearSelection();
    }, 100);
    setTimeout(function ()
    {
        sourceBox.clearSelection();
    }, 100);
    sortListBoxItems(args.get_destinationListBox(), args.get_item());
    var inputData = { viewModelGuid: getViewModelGuid(), callType: "listChange", mapping: mapping, newValues: newValuesList, isAdding: isAdding, owningKey: owningKey };
    $.ajax({ type: 'POST', url: ajaxLocation, success: listChangeReturn, error: ajaxError, datatype: "xml", cache: false, data: inputData });
}

function sortListBoxItems(listBox, item)
{
    listBox.reorderItem(item, 0);
    var transferredItemText = item.get_text();
    var listBoxItems = listBox.get_items();
    var i = 0;
    for (i = 0; i < listBoxItems.get_count(); i++)
    {
        if (listBoxItems.getItem(i).get_text() > transferredItemText)
        {
            break;
        }
    }
    listBox.reorderItem(item, i - 1);
}

function listChangeReturn(xml)
{
    var resultValue = $(xml).find('RESULT').text();
    if (resultValue == "EXCEPTION")
    {
        getIndexContainer(window).doError();
    }
    if (typeof doCustomListChangeProcessing == 'function')
    {
        doCustomListChangeProcessing(xml);
    }
}

function showSaveToolTip()
{
    var toolTipSave = $find(toolTipId);
    if (toolTipSave)
    {
        toolTipSave.show();
    }
}

//Forms that do not have a Button object, something that submits the form, will take an 
//Enter keypress as a form submit.  Well, I don't want to add a button to the form just
//so Enter doesn't submit the form.  Therefore, we'll use this method to cancel an enter.
function cancelPressEnter(event)
{
    if (event.keyCode == 13)
    {
        fieldValueChanged(event.currentTarget);
        return false;
    }
    else
    {
        return true;
    }
}
Vessy
Telerik team
 answered on 23 May 2013
6 answers
210 views
We have a desktop application that is being ported to web, and while some of the code has to be redeveloped from the ground up, there is alot that won't need to be (I hope). In the desktop application we were able to populate comboboxes and listboxes with custom objects by simply overriding the ToString method.

For example:
Public Class SimpleItem
    Private _id As Integer
    Private _name As String
    Private _birthdate As Date
  
    Public Sub New(ByVal id As Integer, ByVal Name As String, ByVal Birthday As Date)
        _name = Name
        _id = id
        _birthdate = Birthday
    End Sub
  
    Public ReadOnly Property Age() As Integer
        Get
            Return If((Date.Today.Month >= _birthdate.Month) And (Date.Today.Day >= _birthdate.Day), Date.Today.Year - _birthdate.Year, Date.Today.Year - _birthdate.Year - 1)
        End Get
    End Property
  
    Public ReadOnly Property Name() As Integer
        Get
            Return _name
        End Get
    End Property
  
    Public Overrides Function ToString() As String
        Return String.Format("{0}, Age: {1}", _name, Me.Age)
    End Function
  
End Class
  
    'Add several unique items to listbox
    MyListBox.Items.Add(New SimpleItem(12, "John Doe", New Date(1960, 12, 17)))
  
    'Loop through items
    For Each item As SimpleItem in MyListbox.Items
        If (item.Age >= 21)
            MsgBox (item.Name & " can purchase alcoholic beverages.")
        End If
    Next item


Web applications however are a completely different thing, I can't add an object to the asp listbox control and I can't explicitly store an asp listboxitem into a class.

The problem comes in when you start having larger classes with several properties that are not visible client-side because ToString sets what text of the control will be only, other items are never utilized and seemingly cannot be retrieved. We can set a value in the listbox, but if there are half a dozen proerties that need to make the round trip, it won't work.

Winforms stores the object then sets the ToString value in the listbox and all class data is preserved. Is there something I am missing? Can this be done with Telerik Rad controls or will I need to completely rethink how to handle this issue? ToString and Value are simply not enough fields to work.
Kate
Telerik team
 answered on 23 May 2013
1 answer
85 views
Hi,

I am using Telerik Grid in my project.I set the "EnableHeaderContextMenu="true" " to Hide/Show the Grid Columns.My requirement is how to get the Hide Columns information from Javascript. Please find the attachment for your reference ,i hide the 2 of clolumns from list ,my requirement is how to get "ORDERID" and "SHIPNAME" columns?


Thanks for advance ..
Eyup
Telerik team
 answered on 23 May 2013
2 answers
243 views
I have a rad chart which is throwing a java script error on a postback. here is the code:

<telerik:RadHtmlChart Width ="400px" ChartTitle-Appearance-TextStyle-FontSize ="12px" Font-Size ="12px" Skin = "WebBlue"  ID = "chartReportsAll" runat ="server" Transitions ="true">
                <PlotArea>
                    <Series>
                        <telerik:ColumnSeries DataFieldY = "TotalAmount" Name = "Test" ></telerik:ColumnSeries>                
                    </Series>
                    <XAxis DataLabelsField = "Name" Name = "test2">
                        <TitleAppearance Text="Campaign Name">
                            <TextStyle FontSize = "12px" />
                        </TitleAppearance>
                    </XAxis>
                    <YAxis>
                        <TitleAppearance Text="Amount Donated">
                            <TextStyle Margin="20" FontSize = "12px"/>
                        </TitleAppearance>
                    </YAxis>
                </PlotArea>           
            </telerik:RadHtmlChart 

And here is the code behind:

chartReportsAll.DataSource = tb2
chartReportsAll.DataBind()


The first time everything is fine. The chart shows correct data. I also have a button on this page which does a does a postback and some changes to the inputs of the graphs. After the postaback, i am getting a 

Microsoft JScript runtime error: Expected ']'

at

{var c=eval(this._dataSource); ( a dynamic page)

and when i see the datasource it is showing as:

[[{"TotalAmount":1000,"campaignID":2,"Name":"Annual Fund"},
{"TotalAmount":300,"campaignID":3,"Name":"Library Fund"}]

{"TotalAmount":1000,"campaignID":2,"Name":"Annual Fund"},
{"TotalAmount":83,"campaignID":1,"Name":"Athletics Fund"},
{"TotalAmount":300,"campaignID":3,"Name":"Library Fund"}]


The first two lines is the data before the postback and the next 3 after the postback. So the problem here is the radchart is not clearing its datatsource. It is also remembering the prrevious one. Can any one please give me a solution ? Thanks.
Sagar
Top achievements
Rank 1
 answered on 23 May 2013
1 answer
76 views
Hi All,

I am using RadTreeList, in which i have a TreeListSelectColumn and a template column for image , I am binding the treelist and it displays it correctly but when I click on any checkbox the image dissappear. could anybody help on this .

Regards,
Sandeep
Princy
Top achievements
Rank 2
 answered on 23 May 2013
1 answer
93 views
Hi
I have a problem using radimageeditor.when i crop or resize an image and save it using onimagesaving file size gets too larger than expected.how can i fix that.



 private void GenerateThumbnails(System.Drawing.Image image,string sourcePath, string thumbname, string thumbname2)
    {

    
        using (image)
        {
            var thumbnailImg = new System.Drawing.Bitmap(245, 200);
            var thumbGraph = System.Drawing.Graphics.FromImage(thumbnailImg);
            thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
            thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //thumbGraph.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
            var imageRectangle = new System.Drawing.Rectangle(0, 0, 245, 200);
            thumbGraph.DrawImage(image, imageRectangle);

            thumbnailImg.Save(thumbname, image.RawFormat);


           thumbnailImg = new System.Drawing.Bitmap(70, 70);
          thumbGraph = System.Drawing.Graphics.FromImage(thumbnailImg);
          imageRectangle = new System.Drawing.Rectangle(0, 0, 70, 70);
          thumbGraph.DrawImage(image, imageRectangle);


            thumbnailImg.Save(thumbname2, image.RawFormat);

        }
    }


 protected void RadImageEditor1_OnImageSaving(object sender, Telerik.Web.UI.ImageEditorSavingEventArgs e)
    {
        string filename = Server.MapPath(folderPath + e.FileName + ".jpg");

        string thumbname = Server.MapPath(folderPath + e.FileName + "_thumb.jpg");

        string thumbname2 = Server.MapPath(folderPath + e.FileName + "_thumb2.jpg");

        System.Drawing.Image img = e.Image.Image;

     
        GenerateThumbnails(img,filename, thumbname, thumbname2);
        e.Cancel = true;
    }
Niko
Telerik team
 answered on 23 May 2013
1 answer
203 views
Does anybody know what's the problem and how to solve it?

Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "Resources.RadComboBox.resources" was correctly embedded or linked into assembly "App_GlobalResources.nccljpyx" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Nencho
Telerik team
 answered on 23 May 2013
1 answer
106 views
Can i set image properties when i will exporting to Excel.
I'm trying to set the image property "Move but not resize with cell", because if it's not setted i can't apply ordination in Excel columns, when i do this just the data has ordered the images still in the same cells.


Have any solution to do this ?

Thanks.
Princy
Top achievements
Rank 2
 answered on 23 May 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Chester
Top achievements
Rank 1
Iron
Simon
Top achievements
Rank 1
Iron
Douglas
Top achievements
Rank 2
Iron
Iron
SUNIL
Top achievements
Rank 3
Iron
Iron
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Chester
Top achievements
Rank 1
Iron
Simon
Top achievements
Rank 1
Iron
Douglas
Top achievements
Rank 2
Iron
Iron
SUNIL
Top achievements
Rank 3
Iron
Iron
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?