﻿<html><head><meta charset="utf-8"></head><body>﻿

    <title>MetaData Demonstration</title>
    


    ﻿ ﻿
    <script src="../../../ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="Scripts/SDK.MetaData.js" type="text/javascript"></script>
    <script src="Scripts/jquery1.8.3.js" type="text/javascript"></script>
    <script src="Scripts/Json.js" type="text/javascript"></script>
    <script language="jscript" type="text/jscript">
        // Global variables
        var context;
        var serverUrl;
        var ODATA_ENDPOINT;
        var selEmailUser;
        var setemailuser;
        var success = true;
        var allEntityListArray = new Array();

        window.onload = function () {
            SDK.Metadata.RetrieveAllEntities(SDK.Metadata.EntityFilters.Entity, false, RetrieveAllEntities, errorRetrieveEntities);
            RetrieveHtmlTemplates()
            RetrieveEmailBodyCustomization();
        }

        function sortMultiDimensional(a, b) {
            // for instance, this will sort the array using the second element    
            return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));
        }

        var GetServerURL = function () {
            var serverUrl = null;
            if (typeof Xrm.Page.context.getClientUrl !== 'function')
                serverUrl = Xrm.Page.context.getServerUrl();
            else
                serverUrl = Xrm.Page.context.getClientUrl();
            return serverUrl;
        };

        var RetrieveAllEntities = function (entityMetadataCollection) {
            var entityArray = new Array(entityMetadataCollection.length);
            var counter = 0;
            for (var i = 0; i < entityMetadataCollection.length; i++) {
                if (entityMetadataCollection[i].DisplayName != null && entityMetadataCollection[i].DisplayName.UserLocalizedLabel != null && entityMetadataCollection[i].IsCustomizable != null && entityMetadataCollection[i].IsCustomizable.Value == true) {
                    entityArray[i] = new Array(2);
                    entityArray[i][0] = entityMetadataCollection[i].SchemaName.toLowerCase();
                    entityArray[i][1] = entityMetadataCollection[i].DisplayName.UserLocalizedLabel.Label;
                    counter++;
                }
            }
            entityArray.sort(sortMultiDimensional);
            for (var i = 0; i < counter; i++) {
                $('#entityList').append('<option value="' + entityArray[i][0].toLowerCase() + '">' + entityArray[i][1].toString() + '</option>')
            }

            serverUrl = GetServerURL();
            ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc" + "/" + "iotap_schedulereportselectedentitiesSet";

            RetrieveEntityList(serverUrl + ODATA_ENDPOINT, false);
        };

        var RetrieveHtmlTemplates = function (odataSetName) {
            $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: GetServerURL() + "/XRMServices/2011/OrganizationData.svc/iotap_htmltemplatesSet",
                beforeSend: function (XMLHttpRequest) {
                    //Specifying this header ensures that the results will be returned as JSON.             
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {
                    if (data.d.results != null & data.d.results.length > 0) {
                        $(data.d.results).each(function (i, data) {
                            $("#drpHtmltemplates").append('<option value="' + $(this)[0].iotap_htmltemplatesId + '">' + $(this)[0].iotap_name + '</option>');
                        });
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert(JSON.parse(XmlHttpRequest.responseText).error.message.value);
                }
            });
        };

        var RetrieveEmailBodyCustomization = function (odataSetName) {
            $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: GetServerURL() + "/XRMServices/2011/OrganizationData.svc/iotap_emailbodycustomizationSet",
                beforeSend: function (XMLHttpRequest) {
                    //Specifying this header ensures that the results will be returned as JSON.             
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {
                    if (data.d.results != null & data.d.results.length > 0) {
                        $("#drpHtmltemplates").val(data.d.results[0].iotap_templateid.Id);
                        $("#txtIotap_emailbodycustomizationid").val(data.d.results[0].iotap_emailbodycustomizationId);
                        $("#txtExcludeDomains").val(data.d.results[0].iotap_excludedomains);
                        $("#txtExcludeUsers").val(data.d.results[0].iotap_excludeusers);
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert(JSON.parse(XmlHttpRequest.responseText).error.message.value);
                }
            });
        };

        var errorRetrieveEntities = function (error) {

        };

        function loadUsersRequest() {        ///<summary>
            /// Use the REST endpoint to retrieve a list of System User Records.
            ///</summary>
            var retrieveusersReq;
            if (window.ActiveXObject) // IE
            {
                retrieveusersReq = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest) // Mozilla/Safari
            {
                retrieveusersReq = new XMLHttpRequest();
            }
            retrieveusersReq.open("GET", getRESTUrl() + "/SystemUserSet?$select=FullName,SystemUserId&$filter=IsDisabled eq false and AccessMode/Value ne 3", true);
            retrieveusersReq.setRequestHeader("Accept", "application/json");
            retrieveusersReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            retrieveusersReq.onreadystatechange = function () {
                loadUsersResponse(retrieveusersReq);
            };
            retrieveusersReq.send();
        }

        function loadUsersResponse(retrieveusersReq) {
            ///<summary>
            /// Callback function from  loadUsersRequest  populates the options in the userSelect select control.
            ///</summary>
            ///<param name="retrieveusersReq" type="XMLHttpRequest">The request passed back with the data.</param>
            if (retrieveusersReq.readyState == 4 /* complete */) {
                if (retrieveusersReq.status == 200) {
                    //Success
                    var retrievedUsers = JSON.parse(retrieveusersReq.responseText).d.results;
                    for (var i = 0; i < retrievedUsers.length; i++) {
                        var user = retrievedUsers[i];
                        selEmailUser.options[i + 1] = new Option(user.FullName, user.SystemUserId);
                    }
                    if (setemailuser != null && document.getElementById("selEmailUser").length > 0) {
                        for (var i = 0; i < document.getElementById("selEmailUser").length; i++) {
                            if (setemailuser.Id == document.getElementById("selEmailUser")[i].value) {
                                document.getElementById("selEmailUser")[i].selected = true;
                            }
                        }
                    }
                }
                else {
                    //Failure
                    errorHandler(retrieveusersReq);
                }
            }
        }

        function getRESTUrl() {
            ///<summary>
            /// Returns a valid URL for REST endpoint requests.
            ///</summary>
            var RESTServicePath = "/xrmservices/2011/organizationdata.svc";
            var serverUrl = "";
            if (typeof GetGlobalContext == "function") {
                var context = GetGlobalContext();
                if (typeof context.getClientUrl !== 'function')
                    serverUrl = context.getServerUrl();
                else
                    serverUrl = context.getClientUrl();
                //serverUrl = context.getServerUrl();
            }
            else {
                if (typeof Xrm.Page.context == "object") {
                    if (typeof Xrm.Page.context.getClientUrl !== 'function')
                        serverUrl = Xrm.Page.context.getServerUrl();
                    else
                        serverUrl = Xrm.Page.context.getClientUrl();
                    //serverUrl = Xrm.Page.context.getServerUrl();
                }
                else { throw new Error("Unable to access the server URL"); }
            }
            if (serverUrl.match(/\/$/)) {
                serverUrl = serverUrl.substring(0, serverUrl.length - 1);
            }
            return serverUrl + RESTServicePath;
        }
        function errorHandler(XmlHttpRequest) {
            ///<summary>
            /// Helper function to handle any errors when using the REST endpoint.
            ///</summary
            var errorMessage = "";
            try {
                errorMessage = JSON.parse(XmlHttpRequest.responseText).error.message.value;
            }
            catch (e) {
                errorMessage = "Unable to parse Error message."
            }
            showMessage("Error : " +
        XmlHttpRequest.status + ": " +
        XmlHttpRequest.statusText + ": " +
        errorMessage, "errormsg");
        }
        var LoadSelectedEntityList = function (data, successCallback, errorCallback) {
            var entityArray = new Array(data.length);
            var counter = 0;
            for (var i = 0; i < data.length; i++) {
                entityArray[i] = new Array(2);
                entityArray[i][0] = data[i].iotap_entitylogicalname;
                entityArray[i][1] = data[i].iotap_entityname;
                counter++;
            }
            entityArray.sort(sortMultiDimensional);
            for (var i = 0; i < counter; i++) {
                $('#selectedEntityList').append('<option value="' + entityArray[i][0].toLowerCase() + '">' + entityArray[i][1].toString() + '</option>')
                $("#entityList option[value='" + data[i].iotap_entitylogicalname + "']").remove();
                setemailuser = data[i].iotap_emailuser;
                //yo
                $("#eventlog").attr('checked', data[i].iotap_eventlog);
                //yo
                // Enable multiple emails to multiple user test functionality if checkbox is checked. This will create all emails in draft mode.
                //$("#chkTestEmails").attr('checked', data[i].iotap_multipleemailstest);
            }
            if (setemailuser != null) {
                document.getElementById("userName").value = setemailuser.Name;
                document.getElementById("userId").value = setemailuser.Id;

            }
        };
        function ToLeft() {
            for (var i = 0; i < selectedEntityList.length; i++) {
                if (selectedEntityList[i].selected) {
                    var optionObj = document.createElement("OPTION");
                    optionObj.text = selectedEntityList[i].text;
                    optionObj.value = selectedEntityList[i].value;
                    entityList.options.add(optionObj);

                    selectedEntityList.remove(i);
                }
            }
        }

        function ToRight() {
            for (var i = 0; i < entityList.length; i++) {
                if (entityList[i].selected) {
                    var optionObj = document.createElement("OPTION");
                    optionObj.text = entityList[i].text;
                    optionObj.value = entityList[i].value;
                    selectedEntityList.options.add(optionObj);

                    entityList.remove(i);
                }
            }
        };


        function StartProcess() {
            ClearMessage();
            if (success == true) {
                $('#loadingmessage').show();
                setTimeout(function () { SaveSelectedEntityList() }, 1000);
            }
        }

        function SaveSelectedEntityList() {
            var excludedDomains = validateMultipleCommaSeparated($("#txtExcludeDomains"), ';');
            var excludedUserEmailIds = validateMultipleCommaSeparated($("#txtExcludeUsers"), ';');

            if (!excludedDomains) {
                alert('Please correct Domain names.')
                $('#loadingmessage').hide();
                return;
            } else if (!excludedUserEmailIds) {
                alert('Please correct User Email Ids.')
                $('#loadingmessage').hide();
                return;
            }

            // clear all retrieved entity names during page load
            allEntityListArray.length = 0;
            // Retrieve all entity names & delete all
            RetrieveEntityList(serverUrl + ODATA_ENDPOINT, true);
            // clear all previous saved entity names.
            allEntityListArray.length = 0;

            var parent = new Object();
            parent.Id = document.getElementById("userId").value;
            parent.LogicalName = "systemuser";
            //yo
            var eventlog = $("#eventlog").is(":checked");
            //yo
            // Enable multiple emails to multiple user test functionality if checkbox is checked. This will create all emails in draft mode.
            //var chkTestEmails = $("#chkTestEmails").is(":checked");

            for (var i = 0; i < selectedEntityList.length; i++) {
                var objCampaign = {
                    iotap_entityname: selectedEntityList[i].text,
                    iotap_entitylogicalname: selectedEntityList[i].value,
                    iotap_emailuser: parent,
                    iotap_eventlog: eventlog
                    //iotap_multipleemailstest: chkTestEmails
                };
                createRecord(objCampaign, "iotap_schedulereportselectedentitiesSet", null, null);
            }

            // Save Email Body Customization,Excluded domains,users
            SaveEmailCustomization();

            if (success == true) {
                alert('Data saved successfully!!');
                $('#loadingmessage').hide();
            }
        };

        function SaveEmailCustomization() {

            success = false;

            var objEmailBodyCustomizationCreate = {
                iotap_templateid: $("#drpHtmltemplates").val() != "" ? { "__metadata": { "type": "Microsoft.Crm.Sdk.Data.Services.EntityReference" }, "Id": $("#drpHtmltemplates").val(), "LogicalName": "iotap_htmltemplates" } : null,
                iotap_excludedomains: $("#txtExcludeDomains").val(),
                iotap_excludeusers: $("#txtExcludeUsers").val()
            };

            var objEmailBodyCustomizationUpdate = {
                iotap_emailbodycustomizationId: $("#txtIotap_emailbodycustomizationid").val(),
                iotap_templateid: $("#drpHtmltemplates").val() != "" ? { "__metadata": { "type": "Microsoft.Crm.Sdk.Data.Services.EntityReference" }, "Id": $("#drpHtmltemplates").val(), "LogicalName": "iotap_htmltemplates" } : null,
                iotap_excludedomains: $("#txtExcludeDomains").val(),
                iotap_excludeusers: $("#txtExcludeUsers").val()
            };
            var url = GetServerURL() + "/XRMServices/2011/OrganizationData.svc/iotap_emailbodycustomizationSet";

            var jsonEntity = $("#txtIotap_emailbodycustomizationid").val() != "" ? window.JSON.stringify(objEmailBodyCustomizationUpdate) : window.JSON.stringify(objEmailBodyCustomizationCreate);
            $.ajax({

                type: "POST",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                data: jsonEntity,
                url: $("#txtIotap_emailbodycustomizationid").val() != "" ? url + "(guid'" + $("#txtIotap_emailbodycustomizationid").val() + "')" : url,

                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");

                    if ($("#txtIotap_emailbodycustomizationid").val() != "") {
                        //Specify the HTTP method MERGE to update just the changes you are submitting.
                        XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
                    }
                },

                success: function (data, textStatus, XmlHttpRequest) {
                    success = true;
                },

                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    if (XmlHttpRequest && XmlHttpRequest.responseText) {
                        var errorMessage = JSON.parse(XmlHttpRequest.responseText).error.message.value;
                        alert(errorMessage);
                    }
                },
                async: false
            });
        }

        function validateEmail(field) {
            var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/;
            return (regex.test(field)) ? true : false;
        }
        function CheckIsValidDomain(domain) {
            var re = new RegExp(/^((?:(?:(?:\w[\.\-\+]?)*)\w)+)((?:(?:(?:\w[\.\-\+]?){0,62})\w)+)\.(\w{2,6})$/);
            return domain.match(re);
        }

        function validateMultipleCommaSeparated(emailcntl, seperator) {
            var value = emailcntl.val();
            if (value != '') {
                var result = value.split(seperator);

                // If seperator is not specified in textbox like "www.google.com" without comma
                if (result.length <= 1 && (emailcntl.attr('id') == 'txtExcludeUsers' && !validateEmail(value)))
                    return false;
                else if (result.length <= 1 && (emailcntl.attr('id') == 'txtExcludeDomains' && !CheckIsValidDomain(value)))
                    return false;
                for (var i = 0; i < result.length; i++) {
                    if (result[i] != '') {
                        if (emailcntl.attr('id') == 'txtExcludeUsers' && !validateEmail(result[i])) {
                            return false;
                        } else if (emailcntl.attr('id') == 'txtExcludeDomains' && !CheckIsValidDomain(result[i])) {
                            return false;
                        }
                    }
                }
            }
            return true;
        }

        var DeleteEntityList = function (data, successCallback, errorCallback, odataSetName) {
            var jsonObject = data;
            for (var i = 0; i < jsonObject.length; i++) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    url: odataSetName + "(guid'" + jsonObject[i].iotap_schedulereportselectedentitiesId + "')",
                    beforeSend: function (XMLHttpRequest) {
                        //Specifying this header ensures that the results will be returned as JSON.                 
                        XMLHttpRequest.setRequestHeader("Accept", "application/json");
                        //Specify the HTTP method DELETE to perform a delete operation.                 
                        XMLHttpRequest.setRequestHeader("X-HTTP-Method", "DELETE");
                    },
                    async: false
                });
            }
        };

        var RetrieveEntityList = function (odataSetName, successCallback) {

            $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: odataSetName,
                beforeSend: function (XMLHttpRequest) {
                    //Specifying this header ensures that the results will be returned as JSON.             
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {
                    if (successCallback) {
                        if (data && data.d && data.d.results) {
                            // Add all entity into array
                            $(data.d.results).each(function () {
                                allEntityListArray.push($(this)[0]);
                            });

                            // look for next set
                            if (data.d.__next != null) {
                                var url = data.d.__next;
                                RetrieveEntityList(url, true);
                            }
                            // Delete entity
                            DeleteEntityList(allEntityListArray, null, null, odataSetName);
                        }
                        else if (data && data.d) {
                            // Add all entity into array
                            $(data.d).each(function () {
                                allEntityListArray.push($(this)[0]);
                            });

                            // look for next set
                            if (data.__next != null) {
                                var url = data.__next;
                                RetrieveEntityList(url, true);
                            }

                            DeleteEntityList(allEntityListArray, null, null, odataSetName);
                        }
                        else {
                            DeleteEntityList(data, null, null, odataSetName);
                        }
                    } else {

                        if (data && data.d && data.d.results) {

                            // Add all entity into array
                            $(data.d.results).each(function () {
                                allEntityListArray.push($(this)[0]);
                            });

                            // look for next set
                            if (data.d.__next != null) {
                                var url = data.d.__next;
                                RetrieveEntityList(url, false);
                            }

                            // if selected entity list & all retrieved entities list length are not equal then add retrieved item into selectedEntityList
                            if ($("#selectedEntityList option").length != allEntityListArray.length)
                                LoadSelectedEntityList(allEntityListArray, null, null);
                        }
                        else if (data && data.d) {
                            // Add all entity into array
                            $(data.d).each(function () {
                                allEntityListArray.push($(this)[0]);
                            });

                            // look for next set
                            if (data.__next != null) {
                                var url = data.__next;
                                RetrieveEntityList(url, false);
                            }
                            // if selected entity list & all retrieved entities list length are not equal then add retrieved item into selectedEntityList
                            if ($("#selectedEntityList option").length != allEntityListArray.length)
                                LoadSelectedEntityList(allEntityListArray, null, null);
                        }
                        else {
                            LoadSelectedEntityList(data, null, null);
                        }
                    }
                },
                async: false
            });
        };

        function createRecord(entityObject, odataSetName, successCallback, errorCallback) {

            //            var context = Xrm.Page.context;
            //            var serverUrl = context.getServerUrl();

            var serverUrl = null;
            if (typeof Xrm.Page.context.getClientUrl !== 'function')
                serverUrl = Xrm.Page.context.getServerUrl();
            else
                serverUrl = Xrm.Page.context.getClientUrl();

            var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
            //entityObject is required    
            if (!entityObject) {
                alert("entityObject is required.");
                return;
            }

            //odataSetName is required, i.e. "AccountSet"    
            if (!odataSetName) {
                alert("odataSetName is required.");
                return;
            }

            //Parse the entity object into JSON    
            var jsonEntity = window.JSON.stringify(entityObject);

            //Asynchronous AJAX function to Create a CRM record using OData
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName,
                data: jsonEntity,
                beforeSend: function (XMLHttpRequest) {
                    //Specifying this header ensures that the results will be returned as JSON.                         
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {
                    success = true;
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    errorHandler(XmlHttpRequest);

                },
                async: false
            });
        };

        function ClearMessage() {
            document.getElementById("message").innerHTML = "";
            if (document.getElementById("userName").value == "") {
                alert('Please select Email User!');
                success = false;
            }
            else if (selectedEntityList.length == 0) {
                alert('Please select atleast one entity!');
                success = false;
            }
            else {
                success = true;
            }
        }

        function showMessage(errorMessage, cssclassname) {
            document.getElementById("message").innerHTML = errorMessage;
            document.getElementById('message').className = cssclassname;
        }
        function showlookupDialog() {
            var isCRM2013 = false; if (Xrm.Page.context.client != undefined) { isCRM2013 = true; }

            var isCRM2015 = false; if (parent.Xrm.Page.context.getServerUrl == undefined) { isCRM2015 = true; }

            if (isCRM2013 == false) {
                //---------------OOB Lookup-----------------------------
                var CRMServerUrl = Xrm.Page.context.prependOrgName('');
                var lookupEntity = 8;
                var url = CRMServerUrl + "/_controls/lookup/lookupsingle.aspx?objecttypes=8&browse=0&ShowNewButton=0&ShowPropButton=0&DefaultType=0";
                var parameter = " dialogWidth="
                  + Math.floor(screen.availWidth * 0.4) + "px; "
                  + " dialogHeight="
                  + Math.floor(screen.availHeight * 0.7) + "px; "
                  + " center=yes; ";

                //var retVal = window.openStdDlg(url, null, "540", "650", false);
                var retVal = window.showModalDialog(url, null, "dialogWidth:600px;dialogHeight:500px;center :yes on 1");

                retVal = retVal != undefined ? JSON.parse(retVal) : null;
                if (retVal != null) {
                    document.getElementById("userName").value = retVal.items[0].name;
                    document.getElementById("userId").value = retVal.items[0].id;
                }
            }
            else if(isCRM2013 == true || isCRM2015 == true) {
                //-------------------Custom Lookup------------------------------
                var ServerUrl = GetServerURL();

                var arguments = [];
                arguments[0] = "systemuser";
                var DialogOptions = new Xrm.DialogOptions();
                DialogOptions.width = 540;
                DialogOptions.height = 650;
                var retvalue = Xrm.Internal.openDialog(ServerUrl + "/WebResources/iotap_CustomLookup.html", DialogOptions, arguments, null,
                    function (returnValue) {

                        returnVal1 = returnValue;
                        if (returnVal1 != null) {
                            var retVal = returnVal1.split("|");//.toString()
                            var names = retVal[0].split(";");
                            var IDs = retVal[1].split(";");

                            document.getElementById("userName").value = names;
                            document.getElementById("userId").value = IDs;
                        }
                    });
            }
        }

    </script>
    <style type="text/css">        
        .label
        {
            font-family: "Segoe UI";
            font-size: 11px;
        }        
        .selectlist
        {
            font-family: "Segoe UI";
            font-size: 11px;
            width: 260px;
            height: 260px;
        }        
        .crmbutton
        {
            font-family: Segoe UI, Tahoma, Arial;
            font-size: 11px;
            height: 20px;
            padding-right: 5px;
            padding-left: 5px;
            border-top-width: 1px;
            border-right-width: 1px;
            border-bottom-width: 1px;
            border-left-width: 1px;
            border-top-style: solid;
            border-left-style: solid;
            border-bottom-style: solid;
            border-right-style: solid;
            cursor: pointer;
            background-repeat: repeat-x;
            border-bottom-color: #666666;
            border-top-color: #666666;
            border-left-color: #666666;
            border-right-color: #666666;
            background-image: url('Images/Button.png');
        }
        .errormsg
        {
            font-family: "Segoe UI";
            text-align: left;
            color: Red;
            font-size: 11px;
        }
        
        .msg
        {
            font-family: "Segoe UI";
            text-align: left;
            color: Black;
            font-size: 11px;
        }
        .loader
        {
            top: 50%;
            left: 0px;
            z-index: 99999;
            background-repeat: no-repeat;
            background-position: center;
            width: 100%;
            height: 100%;
            position: absolute;
            text-align: center;
        }
        .dropdown
        {
            font-family: Segoe UI, Tahoma, Arial;
            font-size: 11px;
            color: Black;
            ime-mode: auto;
            border: 1px solid #CCCCCC;
            margin: 1px 0 0 1px;
            width: 180px;
        }
        .ExcludeTextbox
        {
            width: 244px;
        }
    </style>
    <table style="width: 580px;" border="0" cellspacing="0" cellpadding="0">
        <tbody>
            <tr>
                <td class="label" colspan="2">
                    Enable Event logging
                    <img title="Set checkbox to enable detailed event logging" alt=" Set checkbox to enable detailed event logging" src="images/questionmark.jpg">
                </td>
                <td>
                    <input name="eventlog" id="eventlog" type="checkbox" value="select">
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td class="label" colspan="2">
                    Outgoing Email Owner
                    <img title="CRM User whose account has been configured to use Email Router" alt=" CRM User whose account has been configured to use Email Router" src="images/questionmark.jpg">
                </td>
                <td style="width: 100%;">
                    <input disabled="disabled" id="userName" style="width: 80%; height: 20px; color: black; padding-bottom: 2px; padding-left: 3px; font-family: Segoe UI, Tahoma, Arial; font-size: 11px; vertical-align: middle;">
                    <img id="imgLookup" style="left: -4px; top: 6px; position: relative;" onclick="showlookupDialog();" alt="look user" src="images/lookupon.gif">
                </td>
            </tr>
            <tr>
                <td class="label" colspan="2">
                    Email Template 
                    <img title="Please leave blank to use default template provided by IOTAP" alt=" Please leave blank to use default template provided by IOTAP " src="images/questionmark.jpg">
                </td>
                <td style="width: 100%;">
                <select name="drpHtmltemplates" class="dropdown" id="drpHtmltemplates">
                    <option value=""></option>
                </select>
                </td>   
            </tr>
            <tr>
                <td class="label" colspan="2">
                    Exclude Domains 
                    <img title="Semicolon separated list of domain addresses eg. gmail.com;yahoo.com" alt=" Semicolon separated list of domain addresses eg. gmail.com;yahoo.com" src="images/questionmark.jpg">
                </td>
                <td style="width: 100%;">
					<input name="txtExcludeDomains" class="ExcludeTextbox" id="txtExcludeDomains" type="text">
                </td>   
            </tr>
			
            <tr>
                <td class="label" colspan="2">
                    Exclude Email Addresses
                    <img title="Semicolon separated list of email addresses eg. xyz@gmail.com;abc@yahoo.com" alt=" Semicolon separated list of email addresses eg. xyz@gmail.com;abc@yahoo.com" src="images/questionmark.jpg">
                </td>
                <td style="width: 100%;">
					<input name="txtExcludeUsers" class="ExcludeTextbox" id="txtExcludeUsers" type="text">
                </td>   
            </tr>
            
            <tr>
                <td class="label" colspan="3">
                    Enabled Entities
                    <img title="Select entities for which Report Scheduling will be enabled" alt=" Select entities for which Report Scheduling will be enabled" src="images/questionmark.jpg">
                </td>
            </tr>
            <tr>
                <td align="middle" class="label">
                    All
                </td>
                <td>
                    &nbsp;
                </td>
                <td align="middle" class="label">
                    Selected
                </td>
            </tr>
            <tr>
                <td style="width: 60%;">
                    <select name="entityList" class="selectlist" id="entityList" ondblclick="ToRight()" multiple="">
                    </select>
                </td>
                <td style="width: 20%;">
                    <input name="toRight" class="crmbutton" id="toRight" onclick="ToRight()" type="button" value=">>"><br>
                    <br>
                    <input name="toLeft" class="crmbutton" id="toLeft" onclick="ToLeft()" type="button" value="<<">
                </td>
                <td style="width: 60%;">
                    <select name="selectedEntityList" class="selectlist" id="selectedEntityList" ondblclick="ToLeft()" multiple="">
                    </select>
                </td>
            </tr>
            <tr>
                <td align="middle" colspan="3">
                    <input name="btnSave" class="crmbutton" id="btnSave" onclick="StartProcess();" type="button" value="Save">
                </td>
            </tr>
            <tr>
                <td colspan="3">
                </td>
            </tr>
            <tr>
                <td align="left" class="errormsg" colspan="3">
                    <span class="label" id="message"></span>
                </td>
            </tr>
        </tbody>
    </table>
    <div class="loader" id="loadingmessage" style="display: none;">
        <img alt="loading..." src="images/loading_spiner.gif">
        <input id="userId" type="hidden">
    </div>    
    <input name="txtIotap_emailbodycustomizationid" id="txtIotap_emailbodycustomizationid" type="hidden" value="">


</body></html>