Thursday, September 18, 2014

Partial view in MVC

@model   VIS.Models.HomeModels

@functions
{
    public string GetStatus(int count)
    {
        var d = "";
        if (count == 0)
        {
            d = "style=display:none ";
        }
        return d;
    }

    public string GetLocalDate(DateTime date_, string lng)
    {
        var d = "";
        if (date_ != null)
        {
            lng = lng.Replace("_", "-");
            d = date_.ToLocalTime().ToString("F", new System.Globalization.CultureInfo(lng));
        }
        return d;
    }      
}

<div class="container-fluid" id="dataContainer">
    <div class="row scrollerHorizontal">
        <!-- App Welcome Screen START -->
        <div id="welcomeScreen">
            <div class="vis-welcomeScreenContainer">
                <!-- App Welcome Screen Profile START -->
                <div class="vis-welcomeScreen-Data">
                    <div class="vis-welcomeMessage">

                        <h1>@Model.Greeting</h1>
                        <h2 id="visusrName">@Model.UsrName</h2>
                    </div>

                    <div class="vis-userAvatar-Container">
                        @if (Model.UsrImage != null)
                        {
                            <img id="imgUsrImage" alt="User Avatar" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "User Image")" class="vis-userAvatar-Large"  src="data:image/jpg;base64,@Model.UsrImage" />
                        }
                        else
                        {
                            <img id="imgUsrImage" alt="User Avatar" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "User Image")" class="vis-userAvatar-Large" src="~/Areas/VIS/Images/home/defaultUser.png" />
                           
                        }
                        @*<input type="hidden" id="hdfUserImage" value="@Model.UsrImage" />*@
                    </div>
                    <div style="text-align: center;">
                        <label for="vis-file-input" class="vis-file-label">
                            <span class="vis-change-picture-ico"></span>@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "ChangePicture")
                        </label>
                        <input id="vis-file-input" title=" " type="file" accept="image/*" />
                    </div>
                    <!--<div style="margin-left:120px">
                        <input type="file" id="ImgUpload" name="Change Picture"/>
                    </div>-->
                </div>
                <!-- App Welcome Screen Profile END -->
                <!-- App Welcome Screen Feeds START -->
                <div class="vis-welcomeScreenFeeds">
                    <!-- App Feeds Heading START -->
                    <div class="row">
                        <h2 style="width: 100%">
                            <span style="float: left;" id="spanWelcomeTabtopHdr" class="vis-welcomeScreenContentTittle-icon"></span>
                            <strong style="float: left;" id="sAlrtTxtType"></strong><strong id="hAlrtTxtTypeCount" style="display: none;"></strong>
                            <a id="hlnkTabDataRef" href="#" style="float: right; margin-top: 0px; cursor: pointer; margin-right: 17px;" class="vis-feedIcons vis-icon-refresh" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Refresh")">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Refresh")</a>
                            <span id="sNewNts" style="display: none; float: right; margin-top: 0px; cursor: pointer; margin-right: 6px;" class="vis-linksIcons icon-add" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "New")">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "New")></span>
                        </h2>
                    </div>
                    <!-- App Feeds Heading END -->
                    <div id="welcomeScreenFeedsList" class="scrollerVertical">
                    </div>
                    <div id="divTabMenuDataLoder">
                        <img height="20" width="20" src="~/Areas/VIS/Images/busy.gif" />
                    </div>
                </div>
                <!-- App Welcome Screen Feeds END -->
                <!-- Welcome Screen Tab Menu START -->
                <ul id="ulHomeTabMenu" class="vis-welcomeScreenTabMenu">
                    <li class="vis-activeTab">
                        <div title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "User profile")"  class="vis-welcomeScreenTab-notificationBubbles vis-blank"></div>
                        <a data-vishome="userprofile" href="javascript:void(0)" class="vis-icon-userprofile">user profile</a></li>
                    <li>
                        <div id="divfActivity"  title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "workflow")" class="vis-welcomeScreenTab-notificationBubbles vis-feedsAlert"  @GetStatus(Model.WorkFlowCnt)>@Model.WorkFlowCnt</div>
                        <a data-vishome="workflow"  href="javascript:void(0)"title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "workflow")" class="vis-icon-userfeeds">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "WorkFlow")</a></li>
                    <li>
                        <div id="divNoticeCount" class="vis-welcomeScreenTab-notificationBubbles vis-alertAlert" @GetStatus(Model.NoticeCnt)>@Model.NoticeCnt</div>
                        <a data-vishome="notice" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Notice")"  href="javascript:void(0)" class="vis-icon-useralerts">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Notice")</a></li>
                    <li>
                        <div id="divRequestCount"   title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Request")"  class="vis-welcomeScreenTab-notificationBubbles vis-calendarAlert"  @GetStatus(Model.RequestCnt)>@Model.RequestCnt</div>
                        <a  data-vishome="request" href="javascript:void(0)"  title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Request")" class="vis-icon-usercalendar">Request</a></li>
                    <li>
                        <div id="divAptCount" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Appointments")"   class="vis-welcomeScreenTab-notificationBubbles vis-todoAlert"  @GetStatus(Model.AppointmentCnt) >@Model.AppointmentCnt</div>
                        <a  data-vishome="appointments" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Appointments")"  href="javascript:void(0)" class="vis-icon-usertodo">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Appointments")</a></li>
                    <li>
                        <div id="divMyTaskCount" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "MyTask")" class="vis-welcomeScreenTab-notificationBubbles vis-favouritesAlert" @GetStatus(Model.MyTaskCnt)>@Model.MyTaskCnt</div>
                        <a  data-vishome="mytask" href="javascript:void(0)" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "MyTask")" class="vis-icon-userfavourites">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "MyTask")</a></li>
                    <li>
                        <div id="divTaskAssignBymeCount" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "WSP_TaskAssignByMe")" class="vis-welcomeScreenTab-notificationBubbles vis-linksAlert" @GetStatus(Model.TaskAssignByMeCnt)>@Model.TaskAssignByMeCnt</div>
                        <a data-vishome="taskassignbyme" href="javascript:void(0)"title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "WSP_TaskAssignByMe")"  class="vis-icon-userlinks">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "WSP_TaskAssignByMe")</a></li>
                    <li>
                        <div id="divNotesCount"  title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Notes")"  class="vis-welcomeScreenTab-notificationBubbles vis-contactsAlert" @GetStatus(Model.NotesCnt)>@Model.NotesCnt</div>
                        <a  data-vishome="notes" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Notes")" href="javascript:void(0)" class="vis-icon-usercontacts">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Notes")</a></li>
                    <li>
                        <div id="divKPI"  title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "KPI")" class="vis-welcomeScreenTab-notificationBubbles vis-notesAlert"  @GetStatus(0)>0</div>
                        <a data-vishome="KPI" href="javascript:void(0)" class="vis-icon-usernotes">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "KPI")</a></li>
                    <li>
                        <div id="divDocReceveCnt" @VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "document count") class="vis-welcomeScreenTab-notificationBubbles vis-blank"  @GetStatus(Model.KPICnt)>@Model.KPICnt</div>
                        <a data-vishome="documentrecive"   href="javascript:void(0)" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "documents")" class="vis-icon-userdashboard">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Documents")</a></li>
                </ul>
                <!-- Welcome Screen Tab Menu END -->
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- App Welcome Screen END -->

        <!-- Workflow Activity Screen START -->
        <div id="workflowActivity">
            <div class="vis-workflowActivityContainer">
                <div class="vis-workflowActivityTitleBar">
                    <h3 id="hWelcomeScreenSwapHdr"></h3>
                    <div class="vis-workflowActivityTitleBar-buttons">
                        <a href="#" title="Unsubscribe Feed" class="vis-mainMenuIcons vis-icon-menuclose" id="btnWFAClose" style="height: 40px;">feed check</a>
                    </div>
                </div>
                <div id="workflowActivityData">
                    <div class="scrollerVertical">
                        <div class="vis-workflowActivityDetails" id="workflowActivityDetails">
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- Workflow Activity Screen END -->

        <!-- App Follups START -->
        <div id="fllupsScreen">
            <!-- App Follups Heading START -->
            <div class="row">
                <h2><span class="vis-feedIcons vis-icon-feed"></span>@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "FollowUps") - <strong id="follupsCount">@Model.FollowUpCnt</strong></h2>
                <a id="hlnkFllupsRef" href="#" class="vis-feedIcons vis-icon-refresh" title="Refresh">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Refresh")</a>
            </div>
            <!-- App Follups Heading END -->

            <!-- Follups Data START -->
            <div id="fllupsList" class="scrollerVertical">
                @if (Model.HomeFolloUpsInfo != null && Model.HomeFolloUpsInfo.lstFollowups != null)
                {
                    if (Model.HomeFolloUpsInfo.lstFollowups.Count > 0)
                    {
                        foreach (var item in Model.HomeFolloUpsInfo.lstFollowups)
                        {
                            var divfllupsID = item.ChatID + "-" + item.RecordID + "-" + item.SubscriberID + "-" + item.TableID + "-" + item.WinID + "-" + item.TableName;
                            var divfllcmntID = "divfllcmntdata" + item.ChatID;
                            var divfllvmID = "divfllvm_" + item.ChatID;
                            var divfllvlID = "divfllvl_" + item.ChatID;
                            var txtFllCmntID = "txtFllCmnt" + item.ChatID;
                            var btnFllCmntID = "btnFllCmnt" + item.ChatID;
                       
                    <div id="@divfllupsID"  data-fll="divfllups" class="vis-feedContainer">
                        <div class="vis-feedTitleBar">
                            <h3>
                                @item.WinName</h3>
                            <div class="vis-feedTitleBar-buttons">
                                <ul>
                                    <li>
                                        <a href="#"  data-fll='azoomfllups' title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "ViewFollowups")" class="vis-feedIcons vis-icon-viewFeed">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "ViewFollowups")</a>
                                    </li>
                                    <li>
                                        <a href="#" data-fll='asubscribefllups'  title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "UnsubscribeFollowups")" class="vis-feedIcons vis-icon-unsubscribeFeed">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "UnsubscribeFollowups")</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div id="@divfllcmntID" data-fll="divfllupscmntdata" class="vis-feedDetails">
                            <div class="vis-feedDetails-cmnt" data-fll="fll-cmnt">
                                @if (item.AD_Image_ID == 0)
                                {                                  
                                    <img class="userAvatar-Feeds" src="~/Areas/VIS/Images/home/defaultUser.png" />
                                }
                                else
                                {
                                    foreach (var uitem in Model.HomeFolloUpsInfo.lstUserImg)
                                    {
                                        if (uitem.AD_Image_ID == item.AD_Image_ID)
                                        {
                                            if (uitem.UserImg != "NoRecordFound" && uitem.UserImg != "FileDoesn'tExist")
                                            {
                                    <img  class="userAvatar-Feeds" src="@uitem.UserImg" alt="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "UserImage")" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "UserImage")" />
                                            }
                                            else
                                            {
                                    <img class="userAvatar-Feeds" src="~/Areas/VIS/Images/home/defaultUser46X46.png" alt="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "UserImage")" title="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "UserImage")" />
                                            }
                                        }
                                    }
                                }
                                <p>
                                    <strong>@item.Name</strong><br />
                                    @item.ChatData
                                </p>
                                <p class="vis-feedDateTime">@GetLocalDate(item.Cdate, ViewBag.Current_Ad_Lang)</p>
                            </div>
                        </div>
                        <a id="@divfllvmID"  data-fll="viewmorefllupscmnt" href="#" class="vis-viewMoreComments"><span class="vis-feedIcons vis-icon-viewMoreComments"></span>@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "ViewMoreComments") ..</a>
                        <a id="@divfllvlID"  data-fll="viewlessfllupscmnt" style="display:none;" href="#" class="vis-viewMoreComments"><span class="vis-feedIcons vis-icon-viewMoreComments"></span>@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "ViewLessComments") ..</a>

                        <div class="clearfix"></div>
                        <div id="@item.ChatID" class="vis-feedMessage">
                            <input id="@txtFllCmntID"  placeholder="@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Type message") ...." data-fll="txtcmntfll" type="text" value="" />
                            @*   <input id="@btnFllCmntID" data-fll="btncmntfll" type="button" class="vis-feedIcons vis-icon-message" value="" />*@
                            <span id="@btnFllCmntID" data-fll="btncmntfll" title=" @VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "Post message")"  class="vis-feedIcons vis-icon-message" ></span>

                            <div class="clearfix"></div>
                        </div>
                    </div>
                        }
                    }
                    else
                    {
                    <p style="margin-top: 200px; margin-left: 100px;">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "NoRecordFound") !!!!</p>
                    }
                }
                else
                {
                    <p style="margin-top: 200px; margin-left: 100px;">@VAdvantage.Utility.Msg.GetMsg(ViewBag.lang, "NoRecordFound") !!!!</p>
                }
            </div>
            <!-- Follups Data END -->
            <!-- App Follups Loder start -->
            <div id="divFllMainLoder" style="display: none">
                <img height="20" width="20" src="~/Areas/VIS/Images/busy.gif" />
            </div>
            <!-- App Follups Loder End-->
        </div>
        <!-- App Follups END -->

        <!-- App Favourite And Links START -->
        <div id="favLinks">
            <!-- Favourite And Links Heading Tabs START -->

            <!-- App Links Heading START -->
            <div class="col-md-6 col-sm-6" id="userLinks">
                <div class="row userLinks_activeTab">
                    <h2><a href="#" id="userLinks-Tab"><span class="vis-linksIcons vis-icon-link"></span>Links - <strong>24</strong></a></h2>
                    <a href="#" class="vis-linksIcons icon-add" title="Add Link">Add Link</a>
                </div>
            </div>
            <!-- App Links Heading END -->

            <!-- App Favourites Heading START -->
            <div class="col-md-6 col-sm-6" id="userFavs">
                <div class="row userFavs_inactiveTab">
                    <h2><a href="#" id="userFav-Tab"><span class="favouritesIcons icon-favourite"></span><span class="favouriteTabLabel-Small">Fav</span><span class="favouriteTabLabel-Large">Favourites</span> - <strong>12</strong></a></h2>
                    <a href="#" class="vis-linksIcons icon-add" title="Add Link">Add Link</a>
                </div>
            </div>
            <!-- App Favourites Heading END -->
            <!-- Favourite And Links Heading Tabs END -->

            <!-- App Links List START -->
            <div id="userLinks-List">
                <div id="vis_linkScroll" class="scrollerVertical">

                    <img src="~/Areas/VIS/Images/LoadingCircle.gif" />

                    @*<ul class="vis-userLinks-ListMenu">
                        <li><a href="#"><span class="vis-linksIcons vis-icon-docs"></span>Docs</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-settings"></span>Settings</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-videos"></span>Videos</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-contacts"></span>Contacts</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-businesscockpit"></span>Business</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-reports"></span>Reports</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-market"></span>Market</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-help"></span>Help</a></li>
                        <li><a href="#"><span class="vis-linksIcons vis-icon-docs"></span>Docs</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-settings"></span>Settings</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-videos"></span>Videos</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-contacts"></span>Contacts</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-businesscockpit"></span>Business</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-reports"></span>Reports</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-market"></span>Market</a></li>
                        <li><a href="#"><span class="vis-linksIcons icon-help"></span>Help</a></li>
                    </ul>*@
                </div>
                <div class="vis-verticalScroller-End"></div>
            </div>
            <!-- App Links List END -->

            <!-- App Favourites List START -->
            <div id="userFavs-List">
                <div id="vis_favScroll" class="scrollerVertical">
                    <img src="~/Areas/VIS/Images/LoadingCircle.gif" />
                    @*<ul class="vis-userFavourites-ListMenu">
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Project Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Partner Relationship</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Customer Assets</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Invoice Enquire</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Order Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Workplace Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Contacts Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Dealers Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Project Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Partner Relationship</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Customer Assets</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Invoice Enquire</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Order Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Workplace Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Contacts Management</i></a></li>
                        <li><a href="#"><span class="favouritesIcons icon-favourite-large"></span><i>Dealers Management</i></a></li>
                    </ul>*@
                </div>
                <div class="vis-verticalScroller-End"></div>
            </div>
            <!-- App Favourites List END -->
        </div>
        <!-- App Favourite And Links END -->
    </div>
</div>
<div class="vis-apanel-busy" id="divfeedbsy" style="width: 98%; height: 98%; text-align: center; position: absolute; visibility: hidden; z-index: 6;"></div>


<script type="text/x-kendo-template" id="backgroundColor-template">
       @* <label for='templateTool' style='vertical-align:middle;'>Background:</label>*@
        <select id='templateTool' style='width:90px'><option value=''>none</option><option value='\#ff9'>yellow</option><option value='\#dfd'>green</option> <option value='\#2424E0'>Blue</option> <option value='\#E04324'>Red</option></select>
</script>

JS Area and prototype

; WSP = window.WSP || {};
(function (WSP, $) {

    WSP.WspSharedUser = [];

    WSP.wspLoadScheduler = function () {
        this.frame;
        this.windowNo;
        this.height;
        var SchedWindowNo = null;
        var $mscheduler = null;

        var $divscalendar = null;
        var $scalendar = null;
        var $divSharedContact = null;

        var $rdoMyCal = null;
        var $rdoSharedCal = null;
        var $imgMyCal = null;
        var $imgSharedCal = null;
        var isShredDeleted = false;
        var selectedUser = '';
        var $CustomSchedTemplate = null;

        var $btnLoadScheduler = null;
        var $btnAddcontact = null;
        var $btnDeletecontact = null;
        var $root = $("<div>");
        var $busyDiv = null;
        var self = this;
        var autoLoadSharedUser = false;
        var sharedData = null;
        var sharedContact = null;
        var isShared = false;
        var arrUsr = [], arrAptUsr = [], arrAptCat = [];
        var lusrid = null;
        var lusrname = null;
        var s_startDate = "";
        var sUserID = [];
        var sUserName = [];

        //Load Scheduler  
        this.LoadScheduler = function () {
            SchedWindowNo = self.windowNo;
            $root.height(self.height);
            $root.css("overflow-x", "auto");
            // debugger;
            $(($root.parent()).parent().children()[1]).show();
            var divaptbusy = $("<div id='divAptBusy' class='wsp-busy-indicater'></div>");
            $("body").append(divaptbusy);
            //$busyDiv = ($root.parent()).parent().children()[1];
            //  $busyDiv.show();
            $.ajax({
                url: VIS.Application.contextUrl + "WSP/Scheduler/ReadJsonSchedData",
                dataType: "json",
                success: function (result) {
                    for (var s in result.lstCategories) {
                        arrAptCat.push({ text: result.lstCategories[s].CatName, value: result.lstCategories[s].ID });
                    }
                    for (var s in result.lstUsrInfo) {
                        arrAptUsr.push({ text: result.lstUsrInfo[s].Name, value: result.lstUsrInfo[s].ID });
                    }
                    Loadshed();
                }
            });

            //Load scheduler
            function Loadshed() {
                $root.load(VIS.Application.contextUrl + 'WSP/Scheduler/Scheduler?windowNo=' + SchedWindowNo, function () {
                    //  $busyDiv.hide();
                    $(".wsp-home-scheduler").height(self.height);
                    $(".wsp-home-left").height(self.height);
                    $(".wsp-home-right").height(self.height);
                    $(".wsp-scheduler").height(self.height);
                    $(".wsp-home-left-calendar").height(self.height / 2);
                    $(".wsp-home-left-btm").height(self.height / 2);

                    //$divscalendar.height((self.height / 2) - 5);
                    //$scalendar.height((self.height / 2) - 5);
                    //$(".home-left-calendar").height(self.height / 2 - 1);

                    lusrid = VIS.context.getAD_User_ID();
                    lusrname = VIS.context.getContext("##AD_User_Name");
                    arrUsr = [{ text: lusrname, value: lusrid }];

                    $mscheduler = $("#mscheduler_" + SchedWindowNo);
                    $divscalendar = $("#divcalendar_" + SchedWindowNo);
                    $scalendar = $("#scalendar_" + SchedWindowNo);

                    $rdoMyCal = $("#mycalendar_" + SchedWindowNo);
                    $rdoSharedCal = $("#sharedcalendar_" + SchedWindowNo);
                    $imgMyCal = $("#imgMyCal_" + SchedWindowNo);
                    $imgSharedCal = $("#imgSharedCal_" + SchedWindowNo);
                    $CustomSchedTemplate = $("#CustomSchedTemplate_" + SchedWindowNo);
                    $divSharedContact = $("#scontct_" + SchedWindowNo);

                    $btnLoadScheduler = $("#btnLoadScheduler_" + SchedWindowNo);
                    $btnAddcontact = $("#btnAddcontact_" + SchedWindowNo);
                    $btnDeletecontact = $("#btnDeletecontact_" + SchedWindowNo);

                    //By default disable Button
                    $divSharedContact.find("input[type='checkbox']").attr("disabled", true);
                    $btnLoadScheduler.attr("disabled", true);

                    if (autoLoadSharedUser == true) {
                        $divSharedContact.height("57%")
                        $btnLoadScheduler.hide();
                    }
                    else {
                        $btnLoadScheduler.show();
                    }
                    if (VIS.context.getContext("##WSP_Start_Date") != "") {
                        s_startDate = VIS.context.getContext("##WSP_Start_Date");

                        VIS.context.setContext("##WSP_Start_Date", "")
                    }
                    else {
                        s_startDate = new Date();
                    }

                    //Remove Busy indicater
                    divaptbusy.remove();

                    //######### start to initilize shceduler in div #########################//                

                    $mscheduler.kendoScheduler({
                        //date: new Date("2014/6/10"),
                        // max: new Date("2014/7/10"),
                        date: s_startDate,
                        // startTime: new Date("2014/6/10 11:00 AM"),
                        // endTime: new Date("2014/6/10 12:00 AM"),
                        startTime: new Date(new Date().setHours(0, 0, 0, 0)),
                        selectable: true,

                        allDaySlot: true,
                        showWorkHours: true,
                        workDayStart: new Date(new Date().setHours(9, 0, 0, 0)),
                        workDayEnd: new Date(new Date().setHours(19, 0, 0, 0)),

                        views: [
                         { type: "day", name: "day", selected: true },
                           "week",
                           "month",
                           "agenda"
                        ],
                        messages: {
                            views: {
                                day: VIS.Msg.getMsg("Day")
                            },
                            views: {
                                week: VIS.Msg.getMsg("Week")
                            },
                            views: {
                                month: VIS.Msg.getMsg("Month")
                            },
                            views: {
                                agenda: VIS.Msg.getMsg("Agenda")
                            },
                            editor: {
                                editorTitle: VIS.Msg.getMsg("Appointments")
                            }
                        },

                        group: {
                            resources: ["userID"],
                            orientation: "vertical"
                        },
                        resources: [
                            {
                                field: "statusID",
                                title: "Status",
                                dataSource: [
                                    { text: "Free", value: 1, color: "#E4E4E4" },
                                    { text: "Busy", value: 3, color: "#48ADDB" },
                                    { text: "Busy", value: 4, color: "#93e1b3" }
                                ]
                            },
                            {
                                field: "contacts",
                                name: "contacts",
                                multiple: true,
                                dataSource: arrAptUsr
                            },
                            {
                                field: "userID",
                                name: "userID",
                                //multiple: true,
                                dataSource: arrUsr
                            }

                        ],
                        editable: {
                            //set the template
                            template: kendo.template($CustomSchedTemplate.html()),
                            create: true,
                            update: true,
                        },
                        change: function (e) {
                            var calendar = $scalendar.data("kendoCalendar");
                            if (e.sender.calendar.value() != null && e.sender.calendar.value() != "" && e.sender.calendar.value() !== undefined) {
                                calendar.value(e.sender.calendar.value());
                            }
                            else {
                                var start = (e.start.getMonth() + 1) + "/" + e.start.getDate() + "/" + e.start.getFullYear();
                                calendar.value(e.sender.calendar.value());
                            }

                        },
                        edit: function (e) {
                            //To Accept the appointments
                            if (e.event.start.getHours() == 0) {
                                $("#isAllDay_" + SchedWindowNo).attr("checked", true);

                            }

                            if (e.event.statusID == 1 && e.event.ID > 0) {
                                $("#divIsAccept_" + SchedWindowNo).show();
                                $("#title_" + SchedWindowNo).attr("disabled", true);
                                $("#location_" + SchedWindowNo).attr("disabled", true);

                                var ddlCategories = $("#categories_" + SchedWindowNo).data("kendoDropDownList");
                                ddlCategories.enable(false);

                                var startDateTimePicker = $("#startDateTime_" + SchedWindowNo).data("kendoDateTimePicker");
                                startDateTimePicker.enable(false);

                                $("#isAllDay_" + SchedWindowNo).attr("disabled", true);

                                var endDateTimePicker = $("#endDatetime_" + SchedWindowNo).data("kendoDateTimePicker");
                                endDateTimePicker.enable(false);


                                //var ddlRecurrenceRule = $("#recurrenceRule_" + SchedWindowNo);
                                //ddlRecurrenceRule.find('input, span, ul,li, select').attr('disabled', 'disabled');

                                var ddlNotRecurrenceRule = $("#NotRecurrenceRule_" + SchedWindowNo);
                                ddlNotRecurrenceRule.show();

                                //e.container.find("[for=recurrenceRule]").parent().hide();
                                //e.container.find("[data-container-for=recurrenceRule]").hide();

                                $("#isPrivate_" + SchedWindowNo).attr("disabled", true);
                                $("#description_" + SchedWindowNo).attr("disabled", true);
                                var $txtTaskAutocomplete = $("#txtSchedContacts_" + SchedWindowNo);
                                $txtTaskAutocomplete.attr("readonly", true);
                                $txtTaskAutocomplete.css("background-color", "#fff");

                                var span = $("<span>").text(VIS.Msg.getMsg("Me")),
                                    a = $("<a  data-index='" + lusrid + "' id='spanRemove" + lusrid + "'>").addClass("remove").attr({ href: "javascript:", title: "Remove " + VIS.Msg.getMsg("Me") }).text("x").appendTo(span);
                                //add friend to friend div
                                span.insertBefore($txtTaskAutocomplete);

                                //var contactMultiSelect_ = $("#selectContact_" + SchedWindowNo).data("kendoMultiSelect");
                                //contactMultiSelect_.enable(false);
                            }
                                //To see Accepted Appointemnts
                            else if (e.event.statusID == 4 && e.event.ID > 0) {

                                $("#divIsAccept_" + SchedWindowNo).hide();
                                $("#title_" + SchedWindowNo).attr("disabled", true);
                                $("#location_" + SchedWindowNo).attr("disabled", true);

                                var ddlCategories = $("#categories_" + SchedWindowNo).data("kendoDropDownList");
                                ddlCategories.enable(false);

                                var startDateTimePicker = $("#startDateTime_" + SchedWindowNo).data("kendoDateTimePicker");
                                startDateTimePicker.enable(false);

                                $("#isAllDay_" + SchedWindowNo).attr("disabled", true);

                                var endDateTimePicker = $("#endDatetime_" + SchedWindowNo).data("kendoDateTimePicker");
                                endDateTimePicker.enable(false);

                                var ddlRecurrenceRule = $("#recurrenceRule_" + SchedWindowNo);
                                ddlRecurrenceRule.find('span').off("clcik");
                                var ddlNotRecurrenceRule = $("#NotRecurrenceRule_" + SchedWindowNo);
                                $(".wsp-Recurrence-disable").show();
                                //e.container.find("[for=recurrenceRule]").parent().hide();
                                //e.container.find("[data-container-for=recurrenceRule]").hide();

                                $("#isPrivate_" + SchedWindowNo).attr("disabled", true);
                                $("#description_" + SchedWindowNo).attr("disabled", true);

                                var $txtTaskAutocomplete = $("#txtSchedContacts_" + SchedWindowNo);
                                $txtTaskAutocomplete.attr("readonly", true);
                                $txtTaskAutocomplete.css("background-color", "#fff");

                                var span = $("<span>").text(VIS.Msg.getMsg("Me")),
                                    a = $("<a  data-index='" + lusrid + "' id='spanRemove" + lusrid + "'>").addClass("remove").attr({ href: "javascript:", title: "Remove " + VIS.Msg.getMsg("Me") }).text("x").appendTo(span);
                                //add friend to friend div
                                span.insertBefore($txtTaskAutocomplete);
                                WSP.WspSharedUser = [];

                            }
                            else {
                                $("#divIsAccept_" + SchedWindowNo).hide();
                                WSP.WspSharedUser = [];
                                var $txtTaskAutocomplete = $("#txtSchedContacts_" + SchedWindowNo);
                                var txtContacts_ = $("#txtContacts_" + SchedWindowNo)
                                //ddlContacts_.enable(false);
                                var d_contact = [];
                                if (e.event.contactsInfo != null) {
                                    d_contact = e.event.contactsInfo;
                                }
                                if (d_contact.length > 0) {
                                    for (var c = 0; c < d_contact.length; c++) {
                                        var span = $("<span>").text(d_contact[c].Name),
                                        a = $("<a  data-index='" + d_contact[c].ID + "' id='spanRemove" + d_contact[c].ID + "'>").addClass("remove").attr({ href: "javascript:", title: "Remove " + d_contact[c].Name }).text("x").appendTo(span);
                                        //add friend to friend div
                                        span.insertBefore($txtTaskAutocomplete);
                                        WSP.WspSharedUser.push({ ID: d_contact[c].ID, Name: d_contact[c].Name });

                                    }
                                    // ddlContacts_.dataSource = WSP.WspSharedUser;
                                    var $divSharedContacts = $txtTaskAutocomplete.parent();
                                }
                            }
                            $("#title_" + SchedWindowNo).focus();
                        },
                        //dataBinding: function (e) {
                        //    debugger;
                        //},
                        //dataBound: function (e) {
                        //    debugger;

                        //},
                        //add: function (e) {
                        //    debugger;
                        //},
                        //cancel: function (e) {

                        //},
                        resizeStart: function (e) {
                            if (e.event.statusID == 1 || e.event.statusID == 4) {
                                e.preventDefault();
                            }
                        },
                        resize: function (e) {
                            if (e.event.statusID == 1 || e.event.statusID == 4) {
                                e.preventDefault();
                            }
                        },
                        resizeEnd: function (e) {
                            if (e.event.statusID == 1 || e.event.statusID == 4) {
                                e.preventDefault();
                            }
                        },
                        moveStart: function (e) {
                            if (e.event.statusID == 1 || e.event.statusID == 4) {
                                e.preventDefault();
                            }
                        },
                        move: function (e) {
                            if (e.event.statusID == 1 || e.event.statusID == 4) {
                                e.preventDefault();
                            }
                        },
                        moveEnd: function (e) {
                            if (e.event.statusID == 1 || e.event.statusID == 4) {
                                e.preventDefault();
                            }
                        },
                        //add: function (e) {
                        //    if (!checkAvailability(e.event.start, e.event.end, e.event)) {
                        //        e.preventDefault();
                        //    }
                        //},
                        save: function (e) {
                            e.event.contacts = [];
                            e.event.contactsInfo = [];
                            if (WSP.WspSharedUser.length > 0) {
                                for (var s in WSP.WspSharedUser) {
                                    e.event.contacts.push(WSP.WspSharedUser[s].ID);
                                    e.event.contactsInfo.push({ ID: WSP.WspSharedUser[s].ID, Name: WSP.WspSharedUser[s].Name });
                                }
                            }
                            // var mscheduler_ = $mscheduler.data("kendoScheduler");
                            //  mscheduler_.dataSource.transport.update(e);
                        },
                        dataSource: {
                            batch: true,
                            //autoSync: true,
                            transport: {
                                read: function (e) {
                                    //ajax getting JSON data from server
                                    var arrData = [];
                                    $.ajax({
                                        url: VIS.Application.contextUrl + "WSP/Scheduler/ReadJson_Appointments",
                                        dataType: "json",
                                        data: { isShared: isShared, sharedContact: sharedContact, autoLoadSharedUser: autoLoadSharedUser },
                                        success: function (result) {
                                            data = JSON.parse(result);
                                            if (isShared == false) {
                                                for (var s in data) {
                                                    arrData.push({
                                                        AppointmentID: data[s].AppointmentID,
                                                        Title: data[s].Title,
                                                        UserName: data[s].UserName,
                                                        UserID: data[s].UserID,
                                                        CreatedBy: data[s].CreatedBy,
                                                        Start: new Date(data[s].Start),
                                                        End: new Date(data[s].End),
                                                        StartTimezone: data[s].StartTimezone,
                                                        EndTimezone: data[s].EndTimezone,
                                                        Description: data[s].Description,
                                                        RecurrenceID: data[s].RecurrenceID,
                                                        RecurrenceRule: data[s].RecurrenceRule,
                                                        RecurrenceException: data[s].RecurrenceException,
                                                        Location: data[s].Location,
                                                        IsPrivate: data[s].IsPrivate,
                                                        IsAllDay: data[s].IsAllDay,
                                                        IsAccept: data[s].IsAccept,
                                                        StatusID: data[s].StatusID,
                                                        Categories: data[s].Categories,
                                                        Contacts: data[s].Contacts,
                                                        ContactsText: data[s].ContactsText,
                                                        ContactsID: data[s].ContactsID,
                                                        ContactsInfo: data[s].ContactsInfo

                                                    });
                                                }
                                            }
                                            else {
                                                if (autoLoadSharedUser == true) {
                                                    sharedData = data;
                                                    arrData = [];
                                                }
                                                else {
                                                    for (var s in data) {
                                                        arrData.push({
                                                            AppointmentID: data[s].AppointmentID,
                                                            Title: data[s].Title,
                                                            CreatedBy: data[s].CreatedBy,
                                                            UserID: data[s].UserID,
                                                            UserName: data[s].UserName,
                                                            Start: new Date(data[s].Start),
                                                            End: new Date(data[s].End),
                                                            StartTimezone: data[s].StartTimezone,
                                                            EndTimezone: data[s].EndTimezone,
                                                            Description: data[s].Description,
                                                            RecurrenceID: data[s].RecurrenceID,
                                                            RecurrenceRule: data[s].RecurrenceRule,
                                                            RecurrenceException: data[s].RecurrenceException,
                                                            Location: data[s].Location,
                                                            IsPrivate: data[s].IsPrivate,
                                                            IsAccept: data[s].IsAccept,
                                                            IsAllDay: data[s].IsAllDay,
                                                            StatusID: data[s].StatusID,
                                                            Categories: data[s].Categories,
                                                            Contacts: data[s].Contacts,
                                                            ContactsText: data[s].ContactsText,
                                                            ContactsID: data[s].ContactsID,
                                                            ContactsInfo: data[s].ContactsInfo
                                                        });
                                                    }
                                                }
                                            }

                                            e.success(arrData);
                                        }
                                    });

                                },
                                create: function (e) {
                                    $.ajax({
                                        url: VIS.Application.contextUrl + "WSP/Scheduler/CreateJson_Appointments",
                                        type: "POST",
                                        datatype: "JSON",
                                        contentType: "application/json; charset=utf-8",
                                        async: true,
                                        data: JSON.stringify({ models: e.data.models }),
                                        success: function (result) {
                                            var AID = JSON.parse(result);
                                            e.data.models[0].AppointmentID = AID;
                                            e.data.models[0].ContactsInfo = WSP.WspSharedUser;
                                            e.data.models[0].UserID = parseInt(lusrid);
                                            e.data.models[0].CreatedBy = 3;
                                            e.success(e.data.models);
                                            WSP.WspSharedUser = null;
                                            WSP.WspSharedUser = [];
                                        }
                                    });
                                    //e.data.models[0].AppointmentID = Math.ceil(Math.random() * 100000);

                                },
                                update: function (e) {
                                    $.ajax({
                                        url: VIS.Application.contextUrl + "WSP/Scheduler/UpdateJson_Appointments",
                                        type: "POST",
                                        datatype: "JSON",
                                        contentType: "application/json; charset=utf-8",
                                        async: true,
                                        data: JSON.stringify({ models: e.data.models }),
                                        success: function (result) {

                                            var AID = JSON.parse(result);
                                            e.data.models[0].AppointmentID = AID;
                                            e.data.models[0].ContactsInfo = WSP.WspSharedUser;
                                            e.data.models[0].UserID = parseInt(lusrid);
                                            //  e.data.models[0].CreatedBy = 3;
                                            e.success(e.data.models);
                                            WSP.WspSharedUser = null;
                                            WSP.WspSharedUser = [];
                                        }
                                    });
                                    //e.data.models[0].AppointmentID = Math.ceil(Math.random() * 100000);

                                },
                                destroy: function (e) {
                                    $.ajax({
                                        url: VIS.Application.contextUrl + "WSP/Scheduler/DeleteJson_Appointments",
                                        type: "POST",
                                        datatype: "JSON",
                                        contentType: "application/json; charset=utf-8",
                                        async: true,
                                        data: JSON.stringify({ models: e.data.models }),
                                        success: function (result) {
                                            WSP.WspSharedUser = null;
                                            WSP.WspSharedUser = [];
                                            //e.data.models[0].AppointmentID = result;
                                            e.success(e.data.models);
                                        }
                                    });
                                    //e.data.models[0].AppointmentID = Math.ceil(Math.random() * 100000);

                                },
                                parameterMap: function (options, operation) {

                                    if (operation !== "read" && options.models) {
                                        return { models: kendo.stringify(options.models) };
                                    }
                                }
                            },
                            schema: {
                                model: {
                                    id: "ID",
                                    fields: {
                                        ID: { from: "AppointmentID", type: "number" },
                                        title: { from: "Title", validation: { required: true } },
                                        start: { from: "Start", type: "date" },
                                        end: { from: "End", type: "date" },
                                        userName: { from: "UserName" },
                                        userID: { from: "UserID" },
                                        createdBy: { from: "CreatedBy" },
                                        startTimezone: { from: "StartTimezone" },
                                        endTimezone: { from: "EndTimezone" },
                                        description: { from: "Description" },
                                        recurrenceId: { from: "RecurrenceID" },
                                        recurrenceRule: { from: "RecurrenceRule" },
                                        recurrenceException: { from: "RecurrenceException" },
                                        isAllDay: { from: "IsAllDay", type: "boolean" },
                                        isAccept: { from: "IsAccept", type: "boolean" },
                                        isPrivate: { from: "IsPrivate", type: "boolean" },
                                        location: { from: "Location" },
                                        categories: { from: "Categories" },
                                        statusID: { from: "StatusID" },
                                        contacts: { from: "Contacts" },
                                        contactsID: { from: "ContactsID" },
                                        contactsText: { from: "ContactsText" },
                                        contactsInfo: { from: "ContactsInfo" }

                                    }
                                }
                            }
                        }
                    });

                    $('html').css("overflow-x", "scroll");
                    //To initilize scheduler
                    var myscheduler = $mscheduler.data("kendoScheduler");
                    /* to start bind single click event for my scheduler when new appointments will be created*/
                    myscheduler.wrapper.on("click", "td.k-state-selected", function (e) {
                        if (myscheduler.options.editable != false) {
                            var slot = myscheduler.slotByElement(e.currentTarget);
                            myscheduler.addEvent({
                                start: slot.startDate,
                                end: slot.endDate
                            });
                            //$("#contacts").kendoMultiSelect().data("kendoMultiSelect").source = "";
                            //$("#contacts").kendoMultiSelect().data("kendoMultiSelect").source = arrAptUsr;
                        }
                    });
                    /* to end bind single click event for my scheduler when new appointments will be created*/

                    /* to start bind single click event for my scheduler in edit mode*/
                    myscheduler.wrapper.on("div.k-event k-event-inverse k-state-selected").click(function (e) {
                        if (myscheduler.options.editable != false) {
                            if (e.target.className == "k-event-template") {
                                var uid = $(e.target.parentNode.parentNode).data("uid");
                                var event = myscheduler.occurrenceByUid(uid);
                                myscheduler.editEvent(event);

                                //if (event.isPrivate != true) {
                                // myscheduler.editEvent(event);
                                // }
                                // else {
                                //if (event.createdBy == lusrid) {
                                //    myscheduler.editEvent(event);
                                //}
                                //else {
                                //    return;
                                //}
                                // }
                            }
                            else if (e.target.className === "k-event-template k-event-time") {
                                var uid = $(e.target.parentNode.parentNode).data("uid");
                                var event = myscheduler.occurrenceByUid(uid);
                                myscheduler.editEvent(event);

                                //if (event.isPrivate != true) {
                                // myscheduler.editEvent(event);
                                // }
                                // else {
                                //if (event.createdBy == lusrid) {
                                //    myscheduler.editEvent(event);
                                //}
                                //else {
                                //    return;
                                //}
                                // }
                            }
                            else if (e.target.className === "k-event k-event-inverse k-state-selected") {
                                var uid = $(e.target).data("uid");
                                var event = myscheduler.occurrenceByUid(uid);
                                myscheduler.editEvent(event);

                                //if (event.isPrivate != true) {
                                // myscheduler.editEvent(event);
                                // }
                                // else {
                                //if (event.createdBy == lusrid) {
                                //    myscheduler.editEvent(event);
                                //}
                                //else {
                                //    return;
                                //}
                                // }
                            }
                        }
                    });
                    /* to end bind single click event for my scheduler in edit mode*/

                    /* to start filter aapointments by date using calenar in myscheduler*/
                    $scalendar.kendoCalendar({
                        value: new Date(),
                        change: function () {
                            myscheduler.date(this.value());
                        }
                    });
                    /* to end filter aapointments by date using calenar in myscheduler*/

                    //Add Contacts for shared Calendar
                    $btnAddcontact.on("click", function (evnt) {
                        if (isShared == true) {
                            isShredDeleted = false;//Test
                            var susr = VIS.context.getAD_User_ID()
                            for (var s in arrAptUsr) {
                                susr += "," + arrAptUsr[s].value;
                            }

                            var sqlwhere = " AD_User.AD_User_ID IN (Select Distinct AD_User_ID from C_Bpartner JOIN AD_User on C_BPartner.C_BPartner_ID=AD_User.C_BPartner_ID "
                                              + "Where c_bpartner.isemployee='Y') AND AD_User.AD_User_ID NOT IN (" + susr + ")";

                            var info = new VIS.infoGeneral(true, VIS.Env.getWindowNo(), "", "AD_User", "AD_User_ID", true, sqlwhere, null);

                            info.onClose = function () {
                                var s_Suser = info.getSelectedValues();
                                for (var s in s_Suser) {
                                    selectedUser += s_Suser[s] + ",";
                                }
                                selectedUser = selectedUser.substr(0, selectedUser.length - 1);
                                if (selectedUser != "") {
                                    $.ajax({
                                        url: VIS.Application.contextUrl + "WSP/Scheduler/AddDeleteGetJson_sharedUser",
                                        type: "POST",
                                        datatype: "JSON",
                                        contentType: "application/json; charset=utf-8",
                                        async: true,
                                        data: JSON.stringify({ selectedUser: selectedUser, isShredDeleted: isShredDeleted }),
                                        success: function (data) {
                                            arrAptUsr = [];
                                            var result = JSON.parse(data);
                                            for (var s in result) {
                                                arrAptUsr.push({ text: result[s].Name, value: result[s].ID });
                                            }
                                            selectedUser = "";
                                            BindSharedContacts();
                                        }
                                    });
                                }
                            };
                            info.show();
                        }
                        else {
                            return;
                        }
                    });
                    //Delete Contacts for shared Calendar
                    $btnDeletecontact.on("click", function (evnt) {
                        if (isShared == true) {
                            isShredDeleted = true;
                            var selectedUser = $("input[name=chkSContcts]:checked").map(function () { return this.value; }).get().join(",");
                            if (selectedUser != "") {
                                $.ajax({
                                    url: VIS.Application.contextUrl + "WSP/Scheduler/AddDeleteGetJson_sharedUser",
                                    type: "POST",
                                    datatype: "JSON",
                                    contentType: "application/json; charset=utf-8",
                                    async: true,
                                    data: JSON.stringify({ selectedUser: selectedUser, isShredDeleted: isShredDeleted }),
                                    success: function (data) {
                                        arrAptUsr = [];
                                        var result = JSON.parse(data);
                                        for (var s in result) {
                                            arrAptUsr.push({ text: result[s].Name, value: result[s].ID });
                                        }
                                        BindSharedContacts();
                                    }
                                });
                            }

                        }
                        else {
                            return;
                        }
                    });
                    //bind click event of my calendar radio button
                    $rdoMyCal.on("click", function (evnt) {
                        isShared = false;
                        sharedData = null;
                        sharedContact = null;
                        $('input[name=chkSContcts]').attr('checked', false);
                        $divSharedContact.find("input[type='checkbox']").attr("disabled", true);
                        $btnLoadScheduler.attr("disabled", true);

                        $divscalendar.addClass("div-home-left-calendar1");
                        $divscalendar.removeClass("wsp-div-home-left-calendar");

                        $btnLoadScheduler.css('background-color', 'none');
                        $btnAddcontact.css("background-color", "none");
                        $btnDeletecontact.css("background-color", "none");

                        $btnLoadScheduler.css('background-color', '#A7D8FE');
                        $btnAddcontact.css("background-color", "#A7D8FE");
                        $btnDeletecontact.css("background-color", "#A7D8FE");

                        $btnLoadScheduler.attr("disabled", true);

                        arrUsr = [];
                        arrUsr = [{ text: lusrname, value: lusrid }];
                        //myscheduler editable true
                        myscheduler.options.editable = true;
                        //referesh resource of data and scheduler of data for shared

                        myscheduler.resources[1].dataSource.data("");
                        myscheduler.resources[1].dataSource.data(arrAptUsr);


                        myscheduler.resources[2].dataSource.data("");
                        myscheduler.resources[2].dataSource.data(arrUsr);
                        myscheduler.dataSource.read();
                        myscheduler.view(myscheduler.view().name);

                    });
                    //bind click event of shared calendar radio button
                    $rdoSharedCal.on("click", function (evnt) {
                        isShared = true;
                        $divSharedContact.find("input[type='checkbox']").attr("disabled", false);

                        $divscalendar.removeClass("div-home-left-calendar1");
                        $divscalendar.addClass("wsp-div-home-left-calendar");

                        //VIS.Application.contextUrl
                        $btnLoadScheduler.css('background-color', 'none');
                        $btnAddcontact.css("background-color", "none");
                        $btnDeletecontact.css("background-color", "none");

                        $btnLoadScheduler.css('background-color', '#1aa0ed');
                        $btnAddcontact.css('background-color', '#1aa0ed');
                        $btnDeletecontact.css('background-color', '#1aa0ed');
                        $btnLoadScheduler.attr("disabled", false);

                        //Bind Shared Contact
                        BindSharedContacts();
                        //myscheduler editable false
                        myscheduler.options.editable = false;
                        //referesh resource of data and scheduler of data for shared
                        myscheduler.dataSource.read();
                        myscheduler.view(myscheduler.view().name);
                    });
                    //fielter the shared user data on check box when autoShared user True
                    $("#scontct_" + SchedWindowNo + " :checkbox").change(function (e) {
                        if (autoLoadSharedUser == true) {
                            //var checked = $.map($("#scontct_" + SchedWindowNo + ":checked"), function (checkbox) {
                            //    return parseInt($(checkbox).val());
                            //});
                            console.log("In chk" + sharedData);
                            var chekdCntct = $("input[name=chkSContcts]:checked").map(function () { return this.value; }).get();
                            var myscheduler = $mscheduler.data("kendoScheduler");

                            myscheduler.dataSource.data("");
                            var arrVals = [];
                            for (var s in sharedData) {
                                //var arrdata = sharedData[s];
                                for (var j in chekdCntct) {
                                    if (sharedData[s].UserID == chekdCntct[j]) {
                                        arrVals.push(sharedData[s]);
                                        myscheduler.dataSource.add({
                                            ID: sharedData[s].AppointmentID,
                                            userID: sharedData[s].UserID,
                                            title: sharedData[s].Title,
                                            start: new Date(sharedData[s].Start),
                                            end: new Date(sharedData[s].End),
                                            description: sharedData[s].Description
                                        });
                                    }
                                }
                            }

                            //for (var i = 0; typeof (sharedData[i].UserID) != 'undefined'; vals.push(sharedData[i++].getAttribute('value')));
                            //var myscheduler = $mscheduler.data("kendoScheduler");
                            //myscheduler.dataSource.filter({
                            //    operator: function (task) {
                            //        return $.inArray(task.userID, chekdCntct) >= 0;
                            //    }
                            //});

                            //sharedContact = $("input[name=chkSContcts]:checked").map(function () { return this.value; }).get().join(",");
                            //var myscheduler = $mscheduler.data("kendoScheduler");
                            ////referesh data for shared
                            //myscheduler.dataSource.read();
                            //myscheduler.view(myscheduler.view().name);
                        }
                        else {
                            return;
                        }
                    });
                    //fielter the shared user data on check box when autoShared user false
                    $btnLoadScheduler.on("click", function (evnt) {
                        if (isShared == true) {
                            sharedContact = $("input[name=chkSContcts]:checked").map(function () { return this.value; }).get().join(",");
                            var arrContact = $("input[name=chkSContcts]:checked").map(function () { return this.value; }).get();
                            //  if (arrContact.length > 0) {
                            arrUsr = [];
                            for (var s in arrAptUsr) {
                                for (var j in arrContact) {
                                    if (arrAptUsr[s].value == arrContact[j]) {
                                        arrUsr.push(arrAptUsr[s]);
                                    }
                                }
                            }

                            if (arrUsr.length > 0) {
                                myscheduler.resources[1].dataSource.data("");
                                myscheduler.resources[1].dataSource.data(arrAptUsr);

                                myscheduler.resources[2].dataSource.data("");
                                myscheduler.resources[2].dataSource.data(arrUsr);


                                myscheduler.dataSource.read();
                                myscheduler.view(myscheduler.view().name);
                            }
                            //}
                            //else {

                            //}
                        } else {
                            return;
                        }
                    });
                    //referesh scheduler data for my calender
                    $imgMyCal.on("click", function (evnt) {
                        if (isShared == false) {
                            $(".wsp-left-viewtype-left").animate({ "opacity": "0.5" });
                            myscheduler.dataSource.read();
                            myscheduler.view(myscheduler.view().name);
                            $(".wsp-left-viewtype-left").animate({ "opacity": "1" });
                        }
                        else {
                            return;
                        }
                        //debugger;

                        //var s_sched = $CustomSchedTemplate.html();
                        //var contacts_ = $("#contacts").kendoMultiSelect().data("kendoMultiSelect");

                    });
                    //referesh  scheduler data for shared calender
                    $imgSharedCal.on("click", function (e) {
                        if (isShared == true) {
                            $(".wsp-left-viewtype-right").animate({ "opacity": "0.5" });
                            //Bind Shared Contact
                            //  BindSharedContacts();
                            myscheduler.dataSource.read();
                            myscheduler.view(myscheduler.view().name);
                            //$mscheduler.data("kendoGrid").dataSource.read();
                            // $mschedulerdata("kendoScheduler").refresh();
                            $(".wsp-left-viewtype-right").animate({ "opacity": "1" });
                        }
                        else {
                            return;
                        }
                    });
                    /* ############## end  to initilize  shceduler in div ##################### */
                    /*######### Start Bind Shared contact ############ */

                    function BindSharedContacts() {
                        if (arrAptUsr.length > 0) {
                            var str = "";
                            $divSharedContact.html("");
                            for (var s in arrAptUsr) {
                                str += "<div class='wsp-home-left-contacts-inner'>"
                                    + "<input id='scntct_" + arrAptUsr[s].value + SchedWindowNo + "'  type='checkbox' name='chkSContcts' value=" + arrAptUsr[s].value + ">"
                                    + "<label style='font-weight:100;' for='scntct_" + arrAptUsr[s].value + SchedWindowNo + "'>" + arrAptUsr[s].text + "</label>"
                                    + "</div>"
                            }
                            $divSharedContact.html(str);
                        }
                        else {
                            $divSharedContact.html("No Contacts for Share");
                        }
                    }
                    //BindSharedContacts();
                    /*######### End Bind Shared contact ############ */

                });
            }
        }
        //Get Root frame
        this.getRoot = function () {
            return $root;
        };
        //dispose variable
        this.disposeComponent = function () {

            SchedWindowNo = null;
            // $mscheduler.empty();
            // $mscheduler = null;
            $divscalendar.empty();
            $divscalendar = null;
            $scalendar.empty();
            $scalendar = null;
            $divSharedContact.empty();
            $divSharedContact = null;
            $rdoMyCal.off("click");
            $rdoMyCal = null;
            $rdoSharedCal.off("click");
            $rdoSharedCal = null;
            $imgMyCal.off("click");
            $imgMyCal = null;
            $imgSharedCal.off("click");
            $imgSharedCal = null;
            isShredDeleted = null;
            selectedUser = null;
            $btnLoadScheduler.off("click");
            $btnLoadScheduler = null;
            $btnAddcontact.off("click");
            $btnAddcontact = null;
            $btnDeletecontact.off("click");
            $btnDeletecontact = null;
            $root.empty();
            $root = null;
            self = null;
            autoLoadSharedUser = null;
            sharedData = null;
            sharedContact = null;
            isShared = null;
            arrUsr = null, arrAptUsr = null, arrAptCat = null;
            lusrid = null;
            lusrname = null;
            s_startDate = null;
        }
    }

    //Must Implement with same parameter
    WSP.wspLoadScheduler.prototype.init = function (windowNo, frame) {
        //Assign to this Varable
        this.frame = frame;
        this.windowNo = windowNo;
        this.frame.getContentGrid().append(this.getRoot());
        this.height = this.frame.getContentGrid().height();
        //to load scheduler
        this.LoadScheduler();
    };

    //Must implement dispose
    WSP.wspLoadScheduler.prototype.dispose = function () {
        /*CleanUp Code */
        //dispose this component
        this.disposeComponent();

        //call frame dispose function
        if (this.frame)
            this.frame.dispose();
        this.frame = null;
    };

})(WSP, jQuery);