
<!DOCTYPE html>
<!-- 
App Name: Rx Optical System.
Version: 1.0.0
Author: Rx Health Info Systems.
Website: http://www.rxhealthinfosystems.com/
Contact: info@rxhealthinfosystems.com
-->
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
    <!--<![endif]-->
    <!-- BEGIN HEAD -->

    <head>
        <meta charset="utf-8" />
        <title> Optical Management System </title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <meta content="" name="description" />
        <meta content="" name="author" />
        <!-- BEGIN GLOBAL MANDATORY STYLES -->
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
        <!--<link href="assets/global/css/font.css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />-->
        <link href="assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
        <!-- END GLOBAL MANDATORY STYLES -->
        
        <!-- BEGIN DYMANICLY LOADED CSS FILES(all plugin and page related styles must be loaded between GLOBAL and THEME css files ) -->
        <link id="ng_load_plugins_before"/>
        <!-- END DYMANICLY LOADED CSS FILES -->
        
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <link href="assets/global/plugins/morris/morris.css" rel="stylesheet" type="text/css" />
        <!-- END PAGE LEVEL PLUGINS -->
        <!-- BEGIN THEME GLOBAL STYLES -->
        <link href="assets/global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
        <link href="assets/global/css/plugins.min.css" rel="stylesheet" type="text/css" />
        <!-- END THEME GLOBAL STYLES -->
        <link href="assets/pages/css/profile.min.css" rel="stylesheet" type="text/css" />
        <!-- BEGIN THEME LAYOUT STYLES -->
        <link href="assets/admin/layouts/css/layout.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/admin/layouts/css/themes/blue.min.css" rel="stylesheet" type="text/css" id="style_color" />
        <link href="assets/admin/layouts/css/custom.css" rel="stylesheet" type="text/css" />
        <link href="assets/scripts/sweet/sweetalert.css" rel="stylesheet" type="text/css"/>
        <link href="assets/scripts/toast/toast.css" rel="stylesheet" type="text/css"/>
        <link rel="stylesheet" href="assets/scripts/animate.css/animate.css" />
        <link href="assets/scripts/fakeloader/fakeLoader.css" rel="stylesheet" type="text/css"/>
        <link href="assets/global/plugins/jquery-ui/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css"/>
        <link href="assets/scripts/dist/css/lightgallery.css" rel="stylesheet" type="text/css"/>
        <link href="assets/scripts/timepicker/jquery.timepicker.css" rel="stylesheet" type="text/css"/>

        <link href="assets/scripts/calendar/fullcalendar.css" rel="stylesheet" type="text/css"/>
        
        <!-- END THEME LAYOUT STYLES -->
        <link rel="shortcut icon" href="favicon.ico" />
        
        <script>
    </script>
    
    </head>
    
    <!-- END HEAD -->

    <body class="page-sidebar-closed-hide-logo page-container-bg-solid page-boxed page-header-fixed" >
    <!--<body class="page-sidebar-closed-hide-logo page-container-bg-solid wysihtml5-supported page-boxed page-header-fixed" >-->
    <!--<body class="page-header-fixed page-sidebar-closed-hide-logo page-container-bg-solid">-->
        <!-- BEGIN HEADER -->
        <div class="page-header navbar navbar-fixed-top">
            <!-- BEGIN HEADER INNER -->
            <div class="page-header-inner container">
                <!-- BEGIN LOGO -->
                <div class="page-logo">
                    <a href="">
                        <img src="images/app_pics/rns_logo.jpeg" alt="logo" class="logo-default" style="height: 40px;margin-top:5px" /> </a>
                    <div class="menu-toggler sidebar-toggler">
                        <!-- DOC: Remove the above "hide" to enable the sidebar toggler button on header -->
                    </div>
                </div>
                <!-- END LOGO -->
                <!-- BEGIN RESPONSIVE MENU TOGGLER -->
                <a href="javascript:;" class="menu-toggler responsive-toggler" data-toggle="collapse" data-target=".navbar-collapse"> </a>
                <!-- END RESPONSIVE MENU TOGGLER -->
                <!-- BEGIN PAGE ACTIONS -->
                <!-- DOC: Remove "hide" class to enable the page header actions -->
                <div class="page-actions">
                    <!-- <div class="btn-group">
                        <button type="button" class="btn btn-circle btn-outline red active" onclick="PushPullData('push_data', '#push_data_icon');">
                            <i id="push_data_icon" class="fa fa-arrow-up"></i> &nbsp;
                            <span class="hidden-sm hidden-xs">Push Data &nbsp;</span>&nbsp;
                        </button>
                    </div>
                    <div class="btn-group">
                        <button type="button" class="btn btn-circle btn-outline red active" onclick="PushPullData('pull_data', '#pull_data_icon');">
                            <i id="pull_data_icon" class="fa fa-arrow-down"></i> &nbsp;
                            <span class="hidden-sm hidden-xs">Pull Data &nbsp;</span>&nbsp;
                        </button>
                    </div> -->
                </div>
                <!-- END PAGE ACTIONS -->
                <!-- BEGIN PAGE TOP -->
                <div class="page-top">
                    <div class="top-menu">
                        <ul class="nav navbar-nav pull-right">
                            <li style="display:none;" class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar">
                                <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                    <i class="icon-bell"></i>
                                    <span class="badge badge-default"> 7 </span>
                                </a>
                                <ul class="dropdown-menu">
                                    <li class="external">
                                        <h3>
                                            <span class="bold">12 pending</span> notifications</h3>
                                        <a href="page_user_profile_1.html">view all</a>
                                    </li>
                                    <li>
                                        <ul class="dropdown-menu-list scroller" style="height: 250px;" data-handle-color="#637283">
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">just now</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-success">
                                                            <i class="fa fa-plus"></i>
                                                        </span> New user registered. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">3 mins</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-danger">
                                                            <i class="fa fa-bolt"></i>
                                                        </span> Server #12 overloaded. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">10 mins</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-warning">
                                                            <i class="fa fa-bell-o"></i>
                                                        </span> Server #2 not responding. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">14 hrs</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-info">
                                                            <i class="fa fa-bullhorn"></i>
                                                        </span> Application error. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">2 days</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-danger">
                                                            <i class="fa fa-bolt"></i>
                                                        </span> Database overloaded 68%. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">3 days</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-danger">
                                                            <i class="fa fa-bolt"></i>
                                                        </span> A user IP blocked. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">4 days</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-warning">
                                                            <i class="fa fa-bell-o"></i>
                                                        </span> Storage Server #4 not responding dfdfdfd. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">5 days</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-info">
                                                            <i class="fa fa-bullhorn"></i>
                                                        </span> System Error. </span>
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:;">
                                                    <span class="time">9 days</span>
                                                    <span class="details">
                                                        <span class="label label-sm label-icon label-danger">
                                                            <i class="fa fa-bolt"></i>
                                                        </span> Storage server failed. </span>
                                                </a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                            <li class="dropdown dropdown-user">
                                <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                    <img alt="" class="img-circle" src="assets/admin/layouts/img/avatar3_small.jpg" />
                                    <span class="username username-hide-on-mobile"> <?php echo $_SESSION['myMM_Fullname']; ?> <b>[ BRANCH : <?php echo $_SESSION['branch_name']; ?> ]</b> </span>
                                    <i class="fa fa-angle-down"></i>
                                </a>
                                <ul class="dropdown-menu dropdown-menu-default">
                                    <!-- <li>
                                        <a href="#">
                                            <i class="icon-rocket"></i> My Tasks
                                            <span class="badge badge-success"> 7 </span>
                                        </a>
                                    </li>
                                    <li class="divider"> </li> -->
                                    <li>
                                        <a href="#change_password" data-toggle="modal">
                                            <i class="icon-lock"></i> Change Password </a>
                                    </li>
                                    <li>
                                        <a href="<?php echo $logoutAction; ?>">
                                            <i class="icon-key"></i> Log Out </a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!-- END HEADER -->
        <!-- BEGIN HEADER & CONTENT DIVIDER -->
        <div class="clearfix"> </div>
        <!-- END HEADER & CONTENT DIVIDER -->
        <!-- BEGIN CONTAINER -->
        <div class="container">
             <div class="page-container">
            <!-- BEGIN SIDEBAR -->
              <?php include 'leftmenu.php'; ?>
             <div class="fakeloader" style="visibility: hidden;"></div>
            <!-- END SIDEBAR -->
            <!-- BEGIN CONTENT -->
            <div class="page-content-wrapper" >
                <div class="page-content" id="currentarea">
                                                
   <?php  if(isset($_GET['calendar'])){ 
      include 'scheduler/view_calendar.php';
    } else{
if($_SESSION['branch_type'] == 'procurement'){
         // include("dashboard_procurement.php");
}else if($_SESSION['branch_type'] == 'lab'){
         // include("dashboard_lab.php");
}else{
          include("dashboard.php");
}
   } ?>
                </div>
            </div>
            <!-- END CONTENT -->
            <!-- BEGIN QUICK SIDEBAR -->
            <a href="javascript:;" class="page-quick-sidebar-toggler">
                <i class="icon-login"></i>
            </a>
            <div class="page-quick-sidebar-wrapper" data-close-on-body-click="false">
                <div class="page-quick-sidebar">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="javascript:;" data-target="#quick_sidebar_tab_1" data-toggle="tab"> Users
                                <span class="badge badge-danger">2</span>
                            </a>
                        </li>
                        <li>
                            <a href="javascript:;" data-target="#quick_sidebar_tab_2" data-toggle="tab"> Alerts
                                <span class="badge badge-success">7</span>
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"> More
                                <i class="fa fa-angle-down"></i>
                            </a>
                            <ul class="dropdown-menu pull-right">
                                <li>
                                    <a href="javascript:;" data-target="#quick_sidebar_tab_3" data-toggle="tab">
                                        <i class="icon-bell"></i> Alerts </a>
                                </li>
                                <li>
                                    <a href="javascript:;" data-target="#quick_sidebar_tab_3" data-toggle="tab">
                                        <i class="icon-info"></i> Notifications </a>
                                </li>
                                <li>
                                    <a href="javascript:;" data-target="#quick_sidebar_tab_3" data-toggle="tab">
                                        <i class="icon-speech"></i> Activities </a>
                                </li>
                                <li class="divider"></li>
                                <li>
                                    <a href="javascript:;" data-target="#quick_sidebar_tab_3" data-toggle="tab">
                                        <i class="icon-settings"></i> Settings </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                  
                </div>
            </div>
            <!-- END QUICK SIDEBAR -->
        </div>
        <!-- END CONTAINER -->
        <!-- BEGIN FOOTER -->
        <div class="page-footer">
            <div class="page-footer-inner"> <?php echo date('Y');?> &copy; Rx Health Info Systems.
            </div>
            <div class="scroll-to-top">
                <i class="icon-arrow-up"></i>
            </div>
        </div>
        </div>
        <!-- BEGIN CORE PLUGINS -->
        <script src="assets/global/plugins/jquery.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/jquery-ui/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script> 
        <script src="assets/scripts/timepicker/jquery.timepicker.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
        <!-- END CORE PLUGINS -->
        
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <script src="assets/global/plugins/moment.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap-daterangepicker/daterangepicker.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/morris/morris.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/morris/raphael-min.js" type="text/javascript"></script>
        
        <script src="assets/global/plugins/counterup/jquery.waypoints.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/counterup/jquery.counterup.min.js" type="text/javascript"></script>
        <script src="assets/scripts/sweet/sweetalert.js" type="text/javascript"></script>
        <script src="assets/scripts/toast/toast.js" type="text/javascript"></script>
        <script language="javascript" src="assets/scripts/jquery.form.js"></script>
        
        <script src="assets/global/plugins/jquery-easypiechart/jquery.easypiechart.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/jquery.sparkline.min.js" type="text/javascript"></script>
        <!-- END PAGE LEVEL PLUGINS -->
        <!-- BEGIN THEME GLOBAL SCRIPTS -->
        <script src="assets/global/scripts/app.min.js" type="text/javascript"></script>
        <!-- END THEME GLOBAL SCRIPTS -->
        <!-- BEGIN PAGE LEVEL SCRIPTS -->
        <!-- <script src="assets/global/scripts/dashboard.min.js" type="text/javascript"></script> -->
        <!-- END PAGE LEVEL SCRIPTS -->
        <!-- BEGIN THEME LAYOUT SCRIPTS -->
        
        <script src="assets/global/scripts/metronic.js" type="text/javascript"></script>
        <script src="assets/admin/layouts/scripts/layout.min.js" type="text/javascript"></script>
        <script src="assets/admin/layouts/scripts/demo.min.js" type="text/javascript"></script>
        <script src="assets/admin/layouts/scripts/quick-sidebar.min.js" type="text/javascript"></script>
        <script src="assets/scripts/leftmenu.js?version=<?php echo rand(); ?>" type="text/javascript"></script>
        <script src="assets/scripts/fakeloader/fakeLoader.js" type="text/javascript"></script>
        
       <script type="text/javascript" src="assets/scripts/drawings/lib/jquery.ui.core.1.10.3.min.js"></script>
      <script type="text/javascript" src="assets/scripts/drawings/lib/jquery.ui.widget.1.10.3.min.js"></script>
      <script type="text/javascript" src="assets/scripts/drawings/lib/jquery.ui.mouse.1.10.3.min.js"></script>
      <script type="text/javascript" src="assets/scripts/drawings/lib/jquery.ui.draggable.1.10.3.min.js"></script>
      
      <link rel="Stylesheet" type="text/css" href="assets/scripts/drawings/lib/wColorPicker.min.css" />
      <script type="text/javascript" src="assets/scripts/drawings/lib/wColorPicker.min.js"></script>

      <link rel="Stylesheet" type="text/css" href="assets/scripts/drawings/wPaint.min.css" />
      <script type="text/javascript" src="assets/scripts/drawings/wPaint.min.js"></script>
      <script type="text/javascript" src="assets/scripts/drawings/plugins/main/wPaint.menu.main.min.js"></script>
      <script type="text/javascript" src="assets/scripts/drawings/plugins/text/wPaint.menu.text.min.js"></script>
      <script type="text/javascript" src="assets/scripts/drawings/plugins/shapes/wPaint.menu.main.shapes.min.js"></script>
      <script type="text/javascript" src="assets/scripts/drawings/plugins/file/wPaint.menu.main.file.min.js"></script>
      
      <script type="text/javascript" src="assets/scripts/dist/js/lightgallery.js"></script>
      <script type="text/javascript" src="assets/scripts/dist/js/lg-fullscreen.js"></script>
      <script type="text/javascript" src="assets/scripts/dist/js/lg-thumbnail.js"></script>
      <script type="text/javascript" src="assets/scripts/dist/js/lg-autoplay.js"></script>
      <script type="text/javascript" src="assets/scripts/dist/js/lg-zoom.js"></script>
      <script type="text/javascript" src="assets/scripts/jquery_validate/jquery.validate.js"></script>
      <script language="javascript" src="assets/scripts/calendar/fullcalendar.min.js"></script>

      <script language="javascript" src="assets/scripts/highcharts/highcharts.js"></script>
      <script language="javascript" src="assets/scripts/highcharts/exporting.js"></script>


      <script type="text/javascript">
   $(document).ready(function() {
      var zone = "00:00";  //Change this to your timezone
	$.ajax({
		url: 'scheduler/process_calendar.php',
                type: 'POST', 
                data: 'type=fetch' + "&calendar=" + <?php echo $_GET['calendar'];?> ,
                async: false,
                 success: function(s){
        	   json_events = s;
        }
	});


	var currentMousePos = {
	    x: -1,
	    y: -1
	};
		jQuery(document).on("mousemove", function (event) {
                currentMousePos.x = event.pageX;
                currentMousePos.y = event.pageY;
    });

		/* initialize the external events
		-----------------------------------------------------------------*/

		$('#external-events .fc-event').each(function() {

			// store data so the calendar knows to render an event upon drop
			$(this).data('event', {
				title: $.trim($(this).text()), // use the element's text as the event title
				stick: true // maintain when user navigates (see docs on the renderEvent method)
			});

			// make the event draggable using jQuery UI
			$(this).draggable({
				zIndex: 999,
				revert: true,      // will cause the event to go back to its
				revertDuration: 0  //  original position after the drag
			});

		});


		/* initialize the calendar
		-----------------------------------------------------------------*/

		$('#calendar').fullCalendar({
			events: JSON.parse(json_events),
			utc: true,
			header: {
				left: 'prev,next today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay'
			},
			editable: true,
			droppable: true, 
			slotDuration: '00:15:00',
			eventReceive: function(event){
				var title = event.title;
				var start = event.start.format();
                                var end = (event.end == null) ? start : event.end.format();
				$.ajax({
		    		url: 'scheduler/process_calendar.php',
		    		data: 'type=new&title='+title+'&startdate='+start+'&enddate='+end+"&calendar=" + <?php echo $_GET['calendar'];?>,
		    		type: 'POST',
		    		dataType: 'json',
		    		success: function(response){
		    			event.id = response.eventid;
		    			$('#calendar').fullCalendar('updateEvent',event);
//                                        ShowEventDiv(response.eventid,'pop_up_modal_2','fetch_single');
		    		},
		    		error: function(e){
		    			console.log(e.responseText);

		    		}
		    	});
				$('#calendar').fullCalendar('updateEvent',event);
				console.log(event);
			},
			eventDrop: function(event, delta, revertFunc) {
		        var title = event.title;
		        var start = event.start.format();
		        var end = (event.end == null) ? start : event.end.format();
		        $.ajax({
					url: 'scheduler/process_calendar.php',
					data: 'type=resetdate&title='+title+'&start='+start+'&end='+end+'&eventid='+event.id + "&calendar=" + <?php echo $_GET['calendar'];?>,
					type: 'POST',
					dataType: 'json',
					success: function(response){
						if(response.status == 'overlap'){
                                                    swal("Appointment Conflicts","This Appointment Overlaps with "+response.laps+" other appointment schedules","error");
                                                    revertFunc();
                                                }else if(response.status == 'success'){}else{		    				
						revertFunc();
                                            }
					},
					error: function(e){		    			
						revertFunc();
						alert('Error processing your request: '+e.responseText);
					}
				});
		    },
		    eventClick: function(event, jsEvent, view) {
                    ShowEventDiv(event.id,'pop_up_modal_2','fetch_single');
//                              $(document).on( "click", "#create_event", function() {
                                 $('#create_event').unbind().click(function(){
		                    $.ajax({
				    		url: 'scheduler/process_calendar.php',
				    		data: $('form').serialize() + '&type=update_event&eventid='+event.id + "&calendar=" + <?php echo $_GET['calendar'];?>,
				    		type: 'POST',
//				    		dataType: 'json',
				    		success: function(response){
				    			if(response == 'success'){			    			
                                                        $('#calendar').fullCalendar('removeEvents');
                                                        HideEventDiv();
                                                        getFreshEvents();
                                                    }else{
                                                       $('#clash_appointment_div').html(response); 
                                                    }
				    		}
				    	});
                                    });
                                 $('#delete_event').unbind().click(function(){
		                         swal({
                                            title: "Are you sure?",
                                            text: 'You want to Permanently Delete this Appointment/Event',
                                            type: "warning",
                                            showCancelButton: true,
                                            confirmButtonColor: '#DD6B55',
                                            confirmButtonText: 'Yes, delete it!',
                                            cancelButtonText: "No, cancel!",
                                            closeOnConfirm: true,
                                            closeOnCancel: true
                                       },
                                       function(isConfirm) {
                                             if (isConfirm) {
                                        $.ajax({
				    		url: 'scheduler/process_calendar.php',
				    		data: $('form').serialize() + '&type=delete_event&eventid='+event.id,
				    		type: 'POST',
				    		dataType: 'json',
				    		success: function(response){
				    			if(response.status == 'success')			    			
                                                        $('#calendar').fullCalendar('removeEvents');
                                                        HideEventDiv();
                                                        getFreshEvents();
				    		},
				    		error: function(e){
				    			alert('Error processing your request: '+e.responseText);
				    		}
				    	});
                                       }
                                     });  
                                    });
			},
			eventResize: function(event, delta, revertFunc) {
				console.log(event);
				var end = event.end.format();
				var start = event.start.format();
		        update(start,end,event.id);
		    },
			eventDragStop: function (event, jsEvent, ui, view) {
			    if (isElemOverDiv()) {
                                 swal({
                                    title: "Are you sure?",
                                    text: 'You want to Permanently Delete this Appointment/Event',
                                    type: "warning",
                                    showCancelButton: true,
                                    confirmButtonColor: '#DD6B55',
                                    confirmButtonText: 'Yes, delete it!',
                                    cancelButtonText: "No, cancel!",
                                    closeOnConfirm: true,
                                    closeOnCancel: true
                                },
                                    function(isConfirm) {
                                            if (isConfirm) {
						$.ajax({
				    		url: 'scheduler/process_calendar.php',
				    		data: 'type=remove&eventid='+event.id + "&calendar=" + <?php echo $_GET['calendar'];?>,
				    		type: 'POST',
				    		dataType: 'json',
				    		success: function(response){
				    			console.log(response);
				    			if(response.status == 'success') {
                                        $('#calendar').fullCalendar('removeEvents');
                                        getFreshEvents();
                                    }
                                },
                                error: function(e) {
                                    alert('Error processing your request: ' + e.responseText);
                                }
                            });
                        }
                    });  
				}
			}
		});

	function getFreshEvents(){
		$.ajax({
			url: 'scheduler/process_calendar.php',
                        type: 'POST', 
                        data: 'type=fetch' + "&calendar=" + <?php echo $_GET['calendar'];?>,
                        async: false,
                        success: function(s){
                                freshevents = s;
                        }
		});
		$('#calendar').fullCalendar('addEventSource', JSON.parse(freshevents));
	}
	
        function update(start,end,id){
		$.ajax({
			url: 'scheduler/process_calendar.php',
                        type: 'POST', 
                        dataType: 'json',
                        data: 'type=update_resize&start='+start+'&end='+end+'&eventid='+id + "&calendar=" + <?php echo $_GET['calendar'];?>,
                        async: false,
                        success: function(response){
                                    if(response.status == 'overlap'){
                                          swal("Appointment Conflicts","This Appointment Overlaps with "+response.laps+" other appointment schedules","error");
                                                }
                                    $('#calendar').fullCalendar('removeEvents');
                                    getFreshEvents();
                                                
                        }
		});
	}


	function isElemOverDiv() {
        var trashEl = jQuery('#trash');
        var ofs = trashEl.offset();
        var x1 = ofs.left;
        var x2 = ofs.left + trashEl.outerWidth(true);
        var y1 = ofs.top;
        var y2 = ofs.top + trashEl.outerHeight(true);

        if (currentMousePos.x >= x1 && currentMousePos.x <= x2 &&
            currentMousePos.y >= y1 && currentMousePos.y <= y2) {
            return true;
        }
        return false;
    }

	});

</script>


<script type="text/javascript">
   $(document).ready(function() {
      // rxVersionControl('rxCheckNewVersion','versionControlWrapper');
       
       $("body").on("click", ".date_time_picker", function(){
        if (!$(this).hasClass("hasDatepicker"))
        {
            $(this).datepicker({
                numberOfMonths: 1,
                changeMonth: true,
                changeYear: true,
                yearRange: "-150:+0",
            });
            $(this).datepicker("option", "dateFormat", "yy-mm-dd");
            $(this).datepicker("show");
        }
    });
       
        $("body").on("click", ".time_picker", function(){
            $(this).timepicker(
                    { 'step': 5
//                      'timeFormat': 'H:i:a' 
                    });
            $(this).timepicker("show");
    });
    
     $(".fakeloader").fakeLoader({
                    top:'30px',  // Default Top value
                    bgColor:"#000000",
                    left:'7%',
                    right:'60%',
                    width:'0%',
                    spinner:"spinner7"
                });
       
       });

</script>

 <div id="version_update" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="false">
                                        <div class="modal-dialog">
                                            <div class="modal-content" id="versionControlWrapper">
                                                
                                            </div>
                                        </div>
                                    </div>


                                    <div class="modal fade" id="change_password" tabindex="-1" role="basic" aria-hidden="true">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                                                        <h4 class="modal-title">Change Password</h4>
                                                    </div>
                                                    <div class="modal-body"> 
                                                    
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                        <form name="" role="form" class="form-horizontal">
                                                        <div id="pass_notification"></div>
                                                          <div class="form-body">  
                                                            <div class="form-group">
                                                                <label class="col-md-5 control-label"><span class="pull-left">Old Password</span></label>
                                                                <div class="col-md-7">
                                                                    <input name="old_password" id="old_password" type="password" class="form-control">
                                                                </div>
                                                            </div>

                                                            <div class="form-group">
                                                                <label class="col-md-5 control-label"><span class="pull-left">New Password</span></label>
                                                                <div class="col-md-7">
                                                                    <input name="new_password" id="new_password" type="password" class="form-control">
                                                                </div>
                                                            </div>

                                                            <div class="form-group">
                                                                <label class="col-md-5 control-label"><span class="pull-left">Confirm Password</span></label>
                                                                <div class="col-md-7">
                                                                    <input name="confirm_password" id="confirm_password" type="password" class="form-control">
                                                                </div>
                                                            </div>

                                                            </div>
                                                            </form>
                                                        </div>
                                                    </div>

                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn red btn" data-dismiss="modal">Close</button>
                                                        <button type="button" class="btn green" onclick="changePassword('change_password','<?php echo $_SESSION['myMM_Userid'];?>','#pass_notification')">Change Password</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
   
</body>


</html>