<!DOCTYPE html>
<html>
<!--
 * 
 * Copyright © 2012 All Rights Reserved, http://simpletrees.co.uk
 * 
 * NOTICE:  All information contained herein is, and remains the property 
 * of Simple Trees Ltd and its suppliers, if any. The intellectual and 
 * technical concepts contained herein are proprietary to Simple Trees Ltd 
 * and its suppliers and may be covered by UK, EU and Foreign Patents, 
 * patents in process, and are protected by copyright law. Dissemination of 
 * this information or reproduction of this material is strictly forbidden
 * unless prior written permission is obtained from Simple Trees Ltd. 
 *
 * This version of the product and all associated intellectual/technical
 * concepts are intended for demo purposes only and not for resale.
 *
 * Contact info@simpletrees.co.uk for license agreements or more details.
 *
-->
<head>
    <title><!-- --></title>
    <script src="../../ClientGlobalContext.js.aspx" type="text/javascript"> </script>
    <script src="../js/common.min.js"> </script>
    <script src="../js/crmhelper.min.js"> </script>
    <script src="../js/dashboard.min.js"> </script>
    <script src="../js/clienthierarchyfv.min.js"> </script>
    <script src="../js/jquery.min.js"> </script>
    <script src="../KendoUI/js/kendo.all.min.js"> </script>
    <script src="../KendoUI/js/kendo.window.min.js"> </script>
    <script src="../KendoUI/js/kendo.treeview.min.js"> </script>
    <link href="../KendoUI/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="../KendoUI/styles/kendo.blueopal.min.css" rel="stylesheet" />
    <link href="../css/fonts.css" rel="stylesheet" />
    <link href="../css/dashboard.css" rel="stylesheet" />
    <link href="../css/common.css" rel="stylesheet" />
</head>
<body style="height: 100%">
        <div id="window">
		    <div id="treeview"> </div>
        </div>
        <div class="fullscreen">
	        <div class="topborder"> </div>
	        <div class="lefttop-50-50"><iframe id="dashboard1" class="fill" frameborder="no"> </iframe></div>
	        <div class="righttop-50-50"><iframe id="dashboard2" class="fill" frameborder="no"> </iframe></div>
	        <div class="leftbottom-50-50"><iframe id="dashboard3" class="fill" frameborder="no"> </iframe></div>
	        <div class="rightbottom-50-50"><iframe id="dashboard4" class="fill" frameborder="no"> </iframe></div>
        </div>
        <span id="undo" style="display:none" class="k-group">...</span>
        <script id="treeview-template" type="text/kendo-ui-template">
            #= item.text #
            # if (item.noaccount) { #
                <img src='../images/noaccount.png' height='12' />
            # } #
            # if (item.opportunity) { #
                <img src='../images/opportunity.png' height='12' />
            # } #
            # if (item.watchlist) { #
                <img src='../images/watchlist.png' height='12' />
            # } #
        </script>
        <script type="text/javascript">
	    	var accountSelectwindow;
	    	function itemDblClick(e) {
                var accountName = $(this).text().trim();
                $("#undo").text(accountName);
                accountSelectwindow.close();
				var testMode = getQueryString("testmode", "false");
                if (testMode != "true") {
                	var accountData = getObjects($("#treeview").data("kendoTreeView").options.dataSource, "text", accountName);
                	var _treeSelectedId = accountData[0].accountId;
                	$("#dashboard1").attr('src', 
                		PadServerUrl(Xrm.Page.context.getServerUrl()) + 
                		"/userdefined/areas.aspx?formid=b053a39a-041a-4356-acef-ddf00182762b&navItemName=Opportunities&oId=" + 
                		_treeSelectedId + 
                		"&oType=1&pagemode=iframe&security=852023&tabSet=areaOpps");
                	$("#dashboard2").attr('src', 
                		PadServerUrl(Xrm.Page.context.getServerUrl()) + 
                		"userdefined/areas.aspx?formid=b053a39a-041a-4356-acef-ddf00182762b&navItemName=Activities&oId=" + 
                		_treeSelectedId + 
                		"&oType=1&pagemode=iframe&security=852023&tabSet=areaActivities");
                	$("#dashboard3").attr('src', 
                		PadServerUrl(Xrm.Page.context.getServerUrl()) + 
                		"/userdefined/areas.aspx?formid=b053a39a-041a-4356-acef-ddf00182762b&navItemName=Contacts&oId=" + 
                		_treeSelectedId + 
                		"&oType=1&pagemode=iframe&security=852023&tabSet=areaContacts");
                	$("#dashboard4").attr('src', 
                		PadServerUrl(Xrm.Page.context.getServerUrl()) + 
                		"WebResources/smp_/Controls/ClientTreeFV.html?id=" + 
                		accountData[0].accountId);
                }
	    	}
	    	
	    	
	    	$(document).ready(function() {
                var onClose = function() {
                    undo.fadeIn(300);
                };

                var undo,
                    initWindow = function () {
                        var windowOptions = {
                                                width: "500px",
                                                title: "Select an Account",
                                                visible: false,
                                                maxHeight: 400,
                                                close: onClose
                                            };

                        windowOptions.animation = { open: { effects: "expand:vertical fadeIn" }, close: { effects: "expand:vertical fadeIn", reverse: true } };

                        accountSelectwindow = $("#window").kendoWindow(windowOptions).data("kendoWindow");

                        undo = $("#undo")
                            .bind("click", function() {
                                accountSelectwindow.open();
                                undo.fadeOut(300);
                            });

                        accountSelectwindow.open();
                    };

                initWindow();
                getAccounts();
                initDashboard();
			});
	

	    </script>
        <style scoped="scoped">
            #example 
            {
                min-height:25px;
            }
			#undo {
			    background-color: #a7cdf0;
			    border-radius: 4px 4px 4px 4px;
			    border-style: solid;
			    border-width: 1px;
			    cursor: pointer;
			    height: 20px;
			    left: 1px;
			    padding: 1px 1px 1px 5px;
			    position: absolute;
			    text-align: left;
			    top: 1px;
			    white-space: nowrap;
			    width: 150px;
			}
        </style>

</body>
</html>