<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);

session_start();

if (isset($_SESSION["client_id"])){
}else{
	$_SESSION["client_id"] = 1;
	
	//get sales_id if logged in
	
	
}

if (isset($_COOKIE["t_cont_search_type"])){
	
	
}else{
	
	setcookie("t_cont_search_type", "All", time() + (20 * 365 * 24 * 60 * 60),'/');
	
}


if (isset($_COOKIE["t_cont_sel_id"])){
	
	
}else{
	
	setcookie("t_cont_sel_id", 0, time() + (20 * 365 * 24 * 60 * 60),'/');
	
}

?>
<!doctype html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="theme-color" content="#000000">
    <title>phoenixsoftware.co.nz. Shop POS solutions.</title>
    <meta name="description" content="phoenixsoftware.co.nz. Shop POS solutions.">
    <link rel="icon" type="image/png" href="../images/logo.png" sizes="32x32">
    <link rel="apple-touch-icon" sizes="180x180" href="../images/logo.png">


	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="manifest" href="manifest.json">
	 <link href='../fullcalendarr/dist/fullcalendar.css' rel='stylesheet' />
<link href='../fullcalendarr/dist/fullcalendar.print.css' rel='stylesheet' media='print' />

         <style type="text/css">
		 .ui-dialog { z-index: 9999999999 !important ;}
           
         </style>
											
											
<style>
    div#users-contain { width: 350px; margin: 20px 0; }
    div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
    div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
    .ui-dialog .ui-state-error { padding: .3em; }
    .validateTips { border: 1px solid transparent; padding: 0.3em; }
</style>

   <style type="text/css">
        .auto-style1 {
            width: 340px;
        }
        .auto-style2 {
            width: 210px;
        }

             .auto-style3 {
                 text-align: left;
                 height: 64px;
				                  width: 200px;
             }
             .auto-style4 {
                 width: 200px;
             }
    </style>
<style>

	body {
		margin-top: 0px;
		font-size: 14px;
		font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
	}
		
	#wrap {
		width: 1500px;
		height: 1500px;
		margin: 0 auto;
	}
		
	#external-events {
		float: left;
		padding: 0 10px;
		border: 1px solid #ccc;
		background: #eee;
		text-align: left;
	}
		
	#external-events h4 {
		font-size: 16px;
		margin-top: 0;
		padding-top: 1em;
	}
		
	.external-event { /* try to mimick the look of a real event */
		margin: 10px 0;
		padding: 2px 4px;
		background: #0099CC;
		color: #fff;
		font-size: .85em;
		cursor: pointer;
	}
		
	#external-events p {
		margin: 1.5em 0;
		font-size: 11px;
		color: #666;
	}
		
	#external-events p input {
		margin: 0;
		vertical-align: middle;
	}

	
	#calendar {
		float: left;
		width: 100%;
	}

	#script-warning {
		display: none;
		background: #eee;
		border-bottom: 1px solid #ddd;
		padding: 0 10px;
		line-height: 40px;
		text-align: center;
		font-weight: bold;
		font-size: 12px;
		color: red;
	}
	#loading {
		display: none;
		position: absolute;
		top: 10px;
		right: 10px;
	}

.fc-event{
  width: 280px !important;}
  
    .holiday, 
    .fc-event-inner a .holiday .fc-event-time,
    .holiday a
    {
        background-color: Olive; /* background color */
        border-color: Olive;     /* border color */
        color: White;           /* text color */
    }
    .vacation, 
    .fc-agend a .vacation .fc-event-time,
    .vacation a
    {
        background-color: Maroon; /* background color */
        border-color: Maroon;     /* border color */
        color: White;           /* text color */
    }
    .other, 
    .fc-agend a .other .fc-event-time,
    .other a
    {
        background-color: Fuchsia; /* background color */
        border-color: Fuchsia;     /* border color */
        color: White;           /* text color */
    }

	
</style>

</head>

<body class=""  onload="javascript: load_calendar()">
    <link rel="stylesheet" href="../assets/css/style.min.css">
	<link rel="stylesheet" href="../css/jquery-ui.min.css">
	
<link rel="stylesheet" href="//cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">

	

	
	
    <!-- loader -->

    <!-- * loader -->

    <!-- App Header -->
    <div class="appHeader bg-primary scrolled is-active">
        <div class="left">
            <a href="#" class="headerButton" data-toggle="modal" data-target="#sidebarPanel">
                <ion-icon name="menu-outline"></ion-icon>
            </a>
        </div>

        <div  class="center">
		
		<?php
		
		//get 
		
		
		?>
	
	PhoenixCRM for 
	<img src="../images/logo/<?php echo $_COOKIE['phxcrmclient_id']?>.jpg" alt="icon" style="height: 50px">
	Diary


		</div>
    </div>
    <!-- * App Header -->

    <!-- Search Component -->

    <!-- * Search Component -->

    <!-- App Capsule -->
    <div id="appCapsule">
<center>





    <div class="row" style="height: 900px;" >
	


        <div style="border: solid 1px; border-color: #6c757d" class="col-md-2">
                 <div style="" class="section mt-6 mb-6"><br>
				 
				 
				 
				         

             
                  
              

			<div id='script-warning'>
		<code>php/get-events.php</code> must be running.
	</div>

		<div id='external-events'>
		<p>		<center>
<h4>Date Selector: </h4>		</center>

		<input type="text" style="width: 125px" id="datepicker"></p>
		
		
		<?
		if ($_COOKIE['phxcrmclient_id'] == 76){
		?>
		
		<button id="plus3wks" type="button" onclick="javascript: inccalday(21)">+3 Wks</button>
		<button id="plus4wks" type="button" onclick="javascript: inccalday(28)">+4 Wks</button>
		<button id="plus5wks" type="button" onclick="javascript: inccalday(35)">+5 Wks</button>

		<?
		}else{
		?>
		
		<button id="plus4wks" type="button" onclick="javascript: inccalday(28)">+4 Wks</button>
		<button id="plus5wks" type="button" onclick="javascript: inccalday(35)">+5 Wks</button>
		<button id="plus6wks" type="button" onclick="javascript: inccalday(42)">+6 Wks</button>
		
		<?
		}
		?>
		

 
 <center>		<h4>Diary Notes</h4></center>
<textarea rows="8" id="diarynotes" onchange="changediarynotes();" cols="16">

</textarea> 		

	<button style="width: 155px; height: 48px" name="sendremindersday" id="sendremindersday" type="button" 
                        onclick="javascript: sendremindersday()">Send Reminder texts for day</button>

				<button  style="width: 155px; height: 48px" name="smsgetelecreply" id="smsgetelecreply" type="button" onclick="javascript: smsgetelecreply()">Check SMS replies</button>
				<input type='hidden' id='drop-remove' checked />
				<label for='drop-remove'></label>
				<button style="width: 155px; height: 48px" name="dailysheetall" id="dailysheetall" type="button" 
                        onclick="javascript: consultsheetday()">Consult Sheet All</button>
		<button style="width: 155px; height: 48px" name="dailysheetall" id="dailysheetall" type="button" 
                        onclick="javascript: printdiarydave()">Daily Sheet All</button>

				<button style="width: 155px; height: 48px" name="dailysheetall" id="btnSsave" type="button" onclick="javascript: printdiarydave2()">Print Calendar</button>

<center>		<h4>Search Options</h4></center>
<form>Select Stylists to view:<br>


<? 
$outlet_id =  1;
$staffresfilename = 'staffressel' . $_COOKIE["phxcrmclient_id"] . '_' . $outlet_id . '.php';
include $staffresfilename; 
?>

</form>
		<center>

						<input type='hidden' id='drop-remove' checked />
				<label for='drop-remove'></label>
		
		</div>

                
                </div> 

        </div>
 <div style="border: solid 1px; border-color: #6c757d" class="col-md-10">
		<div id='calendar'></div>

		<div style='clear:both'></div>
                        </div>
        </div>


    </div>

</div>




        <!-- app footer -->
        <div  class="section mt-6 mb-6">


		<center>	<small>
 </center>
	<?	
					 	 include '../php/configi.php';
						 
		//	echo "cookie".$_COOKIE['phxcrmclient_id'];			 
						 
						 
	if (isset($_COOKIE['phxcrmclient_id'])){
		 $phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
		 
		 		$queryclient="SELECT * from ".$_COOKIE['phxcrmclient_id']."_client where uid_client = " . $phxcrmclient_id;
	//	echo $queryprod;
		$resultclient=mysqli_query($conn, $queryclient);

		while($rowclient=mysqli_fetch_array($resultclient)) { 

			$comp_name			 				= $rowclient['comp_name'];
			
		}

?>

<?

//echo $_COOKIE['phxcrmclient_id'];

	}else{
		
		
	//	echo $_COOKIE['phxcrmclient_id'];

		
	}
	?>
	<br>

     
            <div class="footer-title">
			<center>
                Copyright © phoenixsoftware.co.nz 2021.<br> All Rights Reserved.
            </center>
			</div>
 


        </div>
        <!-- * app footer -->

    </div>
    <!-- * App Capsule -->
<div class="modal fade dialogbox" id="DialogBasic" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Apply Payment:</h5>
                    </div>
                    <div class="modal-body">
                      

						
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-primary" data-dismiss="modal">OK</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		

		
		        <div class="modal inset fade action-sheet ios-add-to-home" id="ios-add-to-home-screen" tabindex="-1"
            role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Add to Home Screen</h5>
                        <a href="javascript:;" class="close-button" data-dismiss="modal">
                            <ion-icon name="close"></ion-icon>
                        </a>
                    </div>
                    <div class="modal-body">
                        <div class="action-sheet-content text-center">
                            <div class="mb-1"><img src="../images/logo.png" alt="image" class="imaged w48">
                            </div>
                            <h4>phoenixsoftware.co.nz</h4>
                            <div>
                                Install phoenixsoftware.co.nz on your iPhone's home screen.
                            </div>
                            <div>
                                Tap the menu for your browser. Then tap Add to homescreen.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- * iOS Add to Home Action Sheet -->
        <!-- Android Add to Home Action Sheet -->
        <div class="modal inset fade action-sheet android-add-to-home" id="android-add-to-home-screen" tabindex="-1"
            role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Add to Home Screen</h5>
                        <a href="javascript:;" class="close-button" data-dismiss="modal">
                            <ion-icon name="close"></ion-icon>
                        </a>
                    </div>
                    <div class="modal-body">
                        <div class="action-sheet-content text-center">
                            <div class="mb-1"><img src="../images/logo.png" alt="image" class="imaged w48">
                            </div>
                            <h4>phoenixsoftware.co.nz</h4>
                            <div>
                                Install phoenixsoftware.co.nz on your Android's home screen.
                            </div>
                            <div>
								Click menu for your browser then click "add app" or "install app".<br>If these options are not there - check for "add to home" option.<br> Once install is complete, go to your home screen and there should<br> be a phoenixsoftware.co.nz app installed. 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    <!-- App Bottom Menu -->
    <div class="appBottomMenu">
        <a href="index.php" class="item active">
            <div class="col">
                <ion-icon name="home-outline"></ion-icon>
            </div>
        </a>


		
		
        <a href="javascript:;" class="item" data-toggle="modal" data-target="#sidebarPanel">
            <div class="col">
                <ion-icon name="menu-outline"></ion-icon>
            </div>
        </a>
    </div>
    <!-- * App Bottom Menu -->

    <!-- App Sidebar -->
	<?php include ('../php/sidebar.php'); ?>
    <!-- * App Sidebar -->

    <!-- welcome notification  -->
    <div id="notification-welcome" class="notification-box">
        <div class="notification-dialog android-style">
            <div class="notification-header">
                <div class="in">
                    <img src="../assets/img/icon/72x72.png" alt="image" class="imaged w24">
                    <strong>phoenixsoftware.co.nz</strong>
                    <span>just now</span>
                </div>
                <a href="#" class="close-button">
                    <ion-icon name="close"></ion-icon>
                </a>
            </div>
            <div class="notification-content">
                <div class="in">
                    <h3 class="subtitle">Welcome to phoenixcrm.co.nz</h3>
                    <div class="text">
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
        <div id="toast-login-successful" class="toast-box toast-bottom bg-success">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Login Successful</center>
                </div>
            </div>
        </div>
				        <div id="toast-login-failed" class="toast-box toast-bottom bg-danger">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Login Failed. Please try again</center>
                </div>
            </div>
        </div>

    <!-- * welcome notification -->

    <!-- ///////////// Js Files ////////////////////  -->
    <!-- Jquery -->
    <script src="../assets/js/lib/jquery-3.4.1.min.js"></script>
	
	

	<script src="../js/jquery-ui.min.js"> </script>
	
    <!-- Bootstrap-->
    <script src="../assets/js/lib/popper.min.js"></script>
    <script src="../assets/js/lib/bootstrap.min.js"></script>
    <!-- Ionicons -->
    <script type="module" src="https://unpkg.com/ionicons@5.2.3/dist/ionicons/ionicons.js"></script>
  
    <!-- Base Js File
    <script src="../assets/js/base.js"></script> -->

    
	 	<script src="../fullcalendarr/lib/jquery.min.js"></script>
			 	<script src="../fullcalendarr/lib/jquery-ui/ui/jquery-ui.min.js"></script>

<script src='../fullcalendarr/lib/moment.min.js'></script>

<script src='../fullcalendarr/lib/jquery-ui.custom.min.js'></script>
<script src='../fullcalendarr/dist/fullcalendar.min.js'></script>    
	
	<!-- Owl Carousel -->
	
	
    <script src="../assets/js/plugins/owl-carousel/owl.carousel.min.js"></script>
    <!-- jQuery Circle Progress -->
    <script src="../assets/js/plugins/jquery-circle-progress/circle-progress.min.js"></script>

    <script>
	
	
	function getCookie(cname) {
  let name = cname + "=";
  let ca = document.cookie.split(';');
  for(let i = 0; i < ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}



    </script>

    <script>




function logout_staff(){



	window.location.replace("logout.php");

//	alert ("logout staff");

	
}



	  function load_todays_sales() {
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		         document.getElementById("divtodaysalesreport").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "../php/todaysalesshop.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}



	  function load_todays_sales_bypymnt() {
		  
	//	  alert ("xmlhttp.responseText");
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//	alert (xmlhttp.responseText);
		         document.getElementById("divtodaysalesreportpymnt").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "../php/todaysalesshop.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}



	  function load_todays_sales_bystaff() {
		  
	//	  alert ("xmlhttp.responseText");
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//	alert (xmlhttp.responseText);
		         document.getElementById("divtodaysalesreportstaff").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "../php/todaysalesshopstaff.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}

	  function load_todays_sales_byitem() {
		  
	//	  alert ("xmlhttp.responseText");
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//	alert (xmlhttp.responseText);
		         document.getElementById("divtodaysalesreportitem").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "../php/todaysalesshopitem.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}



	
	function setCookie(cname, cvalue, exdays) {
  const d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  let expires = "expires="+ d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"+ ";Secure";
}

		function reload_calendar(){
		

$('#calendar').fullCalendar('refetchEvents');
	
//	alert ("ref");
	}
	
	function refresh_calendar_sms(){
		$('#calendar').fullCalendar('removeEvents');
	
		$('#calendar').fullCalendar('refetchEvents');
		$('#calendar').fullCalendar('rerenderEvents')
//	alert ("done");
	}


	function refresh_calendar(){
		

$('#calendar').fullCalendar('refetchEvents');
	
	//alert ("ref done");
	}

	function load_calendar(){
		      var date = new Date();
		var d = date.getDate();
		var m = date.getMonth();
		var y = date.getFullYear();

	//	var e =  document.getElementById('Outlet_ID');
	//	var outlet_id =  e.options[e.selectedIndex].value;

	//  var staffprofile = "


      cal = $('#calendar').fullCalendar({
		header: {	
			left: 'prev,next today',
			center: 'title',
			right: 'resourceDay'
        },
			allDaySlot: false,
			defaultView: 'resourceDay',
			editable: true,
			droppable: true,
			height: 1300,
			minTime: "08:00:00",
			maxTime: "21:00:00",
			resources: [
<? 
$outlet_id =  1;
$stafffilename = 'staffres' . $_COOKIE["phxcrmclient_id"] . '_' . $outlet_id . '.php';
//$stafffilename = 'staffres100_1.php';
include $stafffilename; 
?> 
        ],
        resourceFilter: function (resource) {
          var active = $("input").map(function(){
            return this.checked ? this.name : null;
          }).get();
          return $.inArray(resource.id, active) > -1;
        },
			events: {
				url: '../fullcalendarr/demos/php/get-events-salon.php',
				error: function() {
					alert ("error");
					$('#script-warning').show();
				}
			},
				   eventRender: function(event, element) { 		
var sales_id = event.st_id;		
var widthValue = '500px';		   
                    element.qtip({
				            content: {
                text: function(event, api) {
	                $.ajax({
                        url: 'bookingdetailstip.php?outlet_id=1&sales_id='+sales_id, // Use href attribute as URL
 					})
                    .then(function(content) {
                        // Set the tooltip content upon successful retrieval
                        api.set('content.text', content);
                    }, function(xhr, status, error) {
                        // Upon failure... set the tooltip content to error
                        api.set('content.text', status + ': ' + error);
                    });
        
                    return 'Loading...'; // Set some initial text
                }
            },
			    position: {
					        my: 'top left',  // Position my top left...
        at: 'top center', // at the bottom right of...
        adjust: {
            x: -280,
			   y: -150
        }
    },
	                         hide: {
                fixed: true,
                delay: 200
            },
			  show: 'mouseover',
   hide: 'mouseleave',
   onHide: function() { $(this).qtip('destroy'); },
			   style: {
      classes: 'qtip-bootstrap',
	  width: 550,
      tip: 'bottomRight', width: 1000 // Notice the corner value is identical to the previously mentioned positioning corners
   }
                    }); // end of element.qtip({

                    //element.tooltip();
        },	
		eventAfterRender: function (event, element, view) {
	//		alert (event.btcolor);
		element.css('border-style', 'solid');
		element.css('border-right-width', '8px');
		element.css('border-right-color', event.btcolor);
		
		if (event.alert_flag == "yes"){
			element.css('border-left-width', '5px');
			element.css('border-left-color', 'red');
			
		}
		},
		eventAfterAllRender: function(event, element) { 	
		    var moment = $('#calendar').fullCalendar('getDate');
//    alert("The current date of the calendar is " + moment.format("YYYY/MM/DD"));
			get_diary_notes(moment);	
//		alert ("after all");
		},
			        // the 'ev' parameter is the mouse event rather than the resource 'event'
        // the ev.data is the resource column clicked upon
        selectable: true,
        selectHelper: true,
        select: function (start, end, ev) {
			
			var davedate = moment(start);
			
			var davetime = davedate.format('HH:mm:ss');
			
//			alert ("davetime"+davetime);
	//	var resourcesel = event.resources+"sel";
      //    alert (ev.data);
	//  alert(event);
	//	  console.log(start);
     //     console.log(end);          console.log(event);
	 
	//  console.log(ev);
	  
		$(this).qtip('destroy');
	  
		var startdate = start;
		
	//	alert (start);
		
		var enddate = end;
		var staff_id = ev.data.staff_id;
		var staff_name = ev.data.name;
	
		 var sales_id=getCookie("movebookingtime");
		 var paste_name=getCookie("movebookingname");
		 	 
		var startdate_time = startdate;
		 
		 SetCookie("pastestartdate",davetime,365);
		 
		 localStorage.setItem('pastestarttime', davetime);
		 
		 
	//	 alert ("12startdate"+start+"pastestartdate12"+getCookie("pastestartdate"));
		 
		 SetCookie("pasteenddate",enddate,365);
		 SetCookie("pastestaffid",staff_id,365);
		 SetCookie("pastestaffname",staff_name,365);
		 
//		 alert (sales_id);
	///	 if (sales_id == null){
// alert ("null");

//}

	//	 if (sales_id == "undefined"){
// alert ("is is undefined");

//}
		 
		 if (sales_id == null){

myConfirm("Please confirm you want to create a booking for " + staff_name, function () {
 		create_booking(startdate, enddate, staff_id, staff_name);
  }, function () {
    alert('Create Booking cancelled');
  },
  'Confirm Create new Booking no paste'
);
		 }else{
			 
myConfirmpaste("Please confirm you want to create a booking for " + staff_name + " <br> Paste is available for " + paste_name , function () {
 		create_booking(startdate, enddate, staff_id, staff_name);
  }, function () {
    alert('Create Booking cancelled');
  },
  'Confirm Create new Booking paste'
);			 
		 }
	
//			  var txt;
//var r = confirm("Please confirm you want to create a booking for " + staff_name);
//if (r == true) {
//		create_booking(startdate, enddate, staff_id, staff_name);	
//} else {
//	
// }
			   
			   //         alert ("dave"+ev.resources); // resources
        },
        eventClick: function (event) {
          console.log(event);
        },
		eventDrop: function (event, delta, revertFunc) {
//          console.log(event);
//		  alert(event.start);
 // 		  alert(event.end);
	//	    		  alert(event.resources);
		//    		  alert(event.sts_id);
		
		$(this).qtip('destroy');
		
			var resourcesel = event.resources+"sel";
			var resourceselname = event.resources+"name";

			
			update_booking(event.sts_id, event.start.format("HH:mm:ss"), event.end.format("HH:mm:ss"), event.resources, resourcesel, resourceselname);					  

    },
		    eventResize: function(event, delta, revertFunc) {

			var resourcesel = event.resources+"sel";
			var resourceselname = event.resources+"name";

			
			update_booking(event.sts_id, event.start.format("HH:mm:ss"), event.end.format("HH:mm:ss"), event.resources, resourcesel, resourceselname);					  

			
//        alert(event.title + " end is now " + event.end.format());

//        if (!confirm("is this okay?")) {
  //          revertFunc();
    //    }

    }
      });
	  

        $("#datepicker").datepicker({
 
   // While using year and month change I prefer to use inline  date picker  like (  <div id="datepicker"></div>   )
 		//		dateFormat: 'dd-mm-yy',

                     dateFormat: 'dd-mm-yy', 
					changeMonth: true,
 numberOfMonths:3,
                        changeYear: true,
 
                        onChangeMonthYear: function(year, month, inst) {

						
                        var date = new Date();
						
						var d = new Date(year,month,date.getDate());
// alert (date.getDate());
                        $('#calendar').fullCalendar('gotoDate', moment(d)); 
 
                         },
 
                onSelect: function(dateText, inst) {
 
			//			alert ("onselect"+dateText);
						
                        var date = new Date(dateText.replace( /(\d{2})-(\d{2})-(\d{4})/, "$2/$1/$3"));
						
						
                        $('#calendar').fullCalendar('gotoDate',moment(date));  
                }
 
        }); 

	  
	}
   	function get_diary_notes(diary_date){
	
			var diary_date = moment(diary_date).format('YYYY/MM/DD');
			
	//		alert (diary_date);
			
					var itemfields = {};
		itemfields.diary_date	 		= 	diary_date;	
					$.ajax({
				url: '../php/getdiarynote.php',
				type: 'post',
				data: {"itemfields" : JSON.stringify(itemfields)},
				success: function(data) {
			//		alert (data);
					obj = JSON.parse(data);
					var result_message = obj.result_message;
				if (result_message == "Found"){
						document.getElementById("diarynotes").value = obj.diary_note;
				}else{
											document.getElementById("diarynotes").value = obj.diary_note;
//					alert ("Update failed error details are22"+data);
				}

				}
			});
	}
	
   	function inccalday(days){
//alert ("inccal"+days);

	var startdate = $('#calendar').fullCalendar('getDate');
						
	var returned_date = startdate.add(moment.duration(days, 'days'));
// alert (date.getDate());
                        $('#calendar').fullCalendar('gotoDate', returned_date); 

//$('#calendar').fullCalendar('incrementDate', 1, 1, 1);

//alert ("done");
	} 


    </script>
	 <script>

function updatesmsreplied(client_id, msg_sales_id){

	var client_id = 765567;
	var sales_id = 499967;
	
    var vars = "client_id="+client_id+"&sales_id="+sales_id;


var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.phoenixsoftware.co.nz/ajaxdave.php?client_id="+client_id+"&sales_id="+sales_id, true);
xhr.onload = function () {
    console.log(xhr.responseText);
};
xhr.send(vars);


//alert ("done3");


}

  

 function myTimer() {
    var d = new Date();
    alert ("hello");
 }
     $(document).ready(function () {
 
 //var myVar = setInterval(myTimer, 5000);
 
     });
 
    $(document).ready(function () {
	
	$('button').button();
		
		document.getElementById("tophalf").style.display = 'block';
		load_calendar();
	  
	  
    });


	</script>
<script>
    $(document).ready(function() {

      $('input:checkbox').change(function(){
        $('#calendar').fullCalendar('render');
      });
    });
   function changediarynotes(diary_date){


	var diary_date_get = $('#calendar').fullCalendar('getDate');

	var diary_date 		= moment(diary_date_get).format('YYYY/MM/DD');
	
//	alert ("changedate"+diary_date);

//    var suid = document.getElementById("sales_id").value;
    var sdiary_notes 	= document.getElementById("diarynotes").value;
	
//	var sdiary_notes = sdiary_notes.replace(/\n/g, '<br>');

	var sdiary_notes = sdiary_notes.replace("\r\n", "\\r\\n");
	
//	alert (sdiary_notes);
	
//	var sdiary_notes	= sdiary_notes.replace("&","#$#$#$?");
	
//	alert (diary_date + sdiary_notes);

	var ourObj = {};
	ourObj.diary_date = diary_date;
	ourObj.diary_notes = sdiary_notes;
	
	
	$.ajax({
		url: 'diaryupdnotes.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj), "diary_notes" : sdiary_notes},
		success: function(data) {
        // Do something with data that came back. 
		
				if (data == "Update Successful"){
					
				//	alert (xmlhttp.responseText);
				}else{
					alert ("diary note update error " + data);
				}

	
	}
	});

//>>>

		//>>>
		
}

   	   	function create_booking(event_start, event_end, staff_id, staff_name){
			


			
			
			var startdate = moment(event_start);
			var enddate = moment(event_end);
			
			var startdate_date = startdate.format('YYYY-MM-DD');
			var startdate_time = startdate.format('HH:mm:ss');

			var enddate_date = enddate.format('YYYY-MM-DD');
			var enddate_time = enddate.format('HH:mm:ss');
						
			var staff_id = staff_id;

			var staff_name = staff_name;
			
			var e =  document.getElementById('Outlet_ID');
			var outlet_id =  e.options[e.selectedIndex].value;

		
		
    var hr = new XMLHttpRequest();
  
      var url = "createeventdetssalon.php";
	
//    var vars = "sts_id="+sts_id+"&event_start="+event_start+"&event_end="+event_end+"&new_staff_id="+staff_id+"&new_staff_name="+staff_name;
	var vars = "startdate_date="+startdate_date+"&startdate_time="+startdate_time+"&enddate_date="+enddate_date+"&enddate_time="+enddate_time+"&outlet_id="+outlet_id+"&staff_id="+staff_id+"&staff_name="+staff_name;
//	alert (vars);
//	return false;
	
    hr.open("POST", url, true);
 
    // Set content type header information for sending url encoded variables in the request
 
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 
    // Access the onreadystatechange event for the XMLHttpRequest object
 
    hr.onreadystatechange = function() {
 
	   if(hr.readyState == 4 && hr.status == 200) {
 
		var data = hr.responseText;
		
//		alert (data);
		
		obj = JSON.parse(data);
 
		if (obj.result == "Insert Successful") {
			
			
						 var rebook_client_id=getCookie("rebookclientid");
				//		 alert (rebook_client_id);
						if ( rebook_client_id === undefined || rebook_client_id === null){
										showbooking(obj.st_id);
				//	alert ("no rebook");
			}else{
		//		alert ("rebook");
			//	updateclient(rebook_client_id);
				
				
				
				
				
				   var hr2 = new XMLHttpRequest();
 

 
    var url = "updsalesclient.php";


    var suid = obj.st_id;
	
//	alert (suid);
 
	
//	var snew_cat = document.getElementById("prod_cat_new").value;
	
//	 alert ("new cat" + snew_cat + suid);

//	if (snew_cat.length > 1) {
//	}else{
//	alert ("You must enter a valid category");
//	}
	

	
    var vars = "sales_id="+suid+"&new_client_id="+rebook_client_id;

    hr2.open("POST", url, true);
 
    // Set content type header information for sending url encoded variables in the request
 
    hr2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 
    // Access the onreadystatechange event for the XMLHttpRequest object
 
    hr2.onreadystatechange = function() {
 
	   if(hr2.readyState == 4 && hr2.status == 200) {
 
	//	alert (hr2.responseText);
		   var return_data = hr2.responseText;
 
		if (hr2.responseText == "Update Successful") {
						    SetCookie("rebookclientid",1,-365);
				SetCookie("rebookclientname",'test',-365);
							showbooking(obj.st_id);
	//			loaddiary_refresh();

	//			alert (document.getElementById("date").value);
//				loaddiary(document.getElementById("date").value);
					}else{
			alert ("An error occurred while updating a client. Please try again. If error happens again, please contact support" + hr2.responseText);
		}
	   }
 
    }
 
    // Send the data to PHP now... and wait for response to update the status div
 
    hr2.send(vars); // Actually execute the request
					
				
				
				
				
				
				
				
				
				

			}
			

			//	alert ("Product " + uid + " changed to Inactive status");
					}else{
			alert ("An error occused while moving event. Please try again. If error happens again, please contact support" + hr.resporseText);
		}
	   }
 
    }
 
		// Send the data to PHP now... and wait for response to update the status div
 
		hr.send(vars); // Actually execute the request
		
	}
	
	
   	function update_booking(sts_id, event_start, event_end, resource, resourcesel, resourcename){

//		alert ("hello");

		
	//	alert (resourceidtosel);
	
//	alert (resourcesel);

		var staff_id = document.getElementById(resourcesel).value;

		var staff_name = document.getElementById(resourcename).value;

//		alert (sts_id+event_start+event_end+resource+staff_id+staff_name);
		
	//	return false;
		
    var hr = new XMLHttpRequest();
  
    var url = "updateeventdetssalon.php";
	
    var vars = "sts_id="+sts_id+"&event_start="+event_start+"&event_end="+event_end+"&new_staff_id="+staff_id+"&new_staff_name="+staff_name;
	
//	alert (vars);
//	return false;
	
    hr.open("POST", url, true);
 
    // Set content type header information for sending url encoded variables in the request
 
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 
    // Access the onreadystatechange event for the XMLHttpRequest object
 
    hr.onreadystatechange = function() {
 
	   if(hr.readyState == 4 && hr.status == 200) {
 
		var data = hr.responseText;
		
//		alert (data);
		
		obj = JSON.parse(data);
 
		if (obj.result == "Update Successful") {
			//	alert ("Product " + uid + " changed to Inactive status");
					}else{
			alert ("An error occused while moving event. Please try again. If error happens again, please contact support" + hr.resporseText);
		}
	   }
 
    }
 
		// Send the data to PHP now... and wait for response to update the status div
 
		hr.send(vars); // Actually execute the request
		
	}
	
			
function updateprodinactive(uid){
 
 
    var hr = new XMLHttpRequest();
  
    var url = "updateprodinactive.php";
	
    var vars = "new_uid="+uid;
	
	//alert (vars);

    hr.open("POST", url, true);
 
    // Set content type header information for sending url encoded variables in the request
 
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 
    // Access the onreadystatechange event for the XMLHttpRequest object
 
    hr.onreadystatechange = function() {
 
	   if(hr.readyState == 4 && hr.status == 200) {
 
	//	alert (hr.responseText);
					var data = hr.responseText;
				

 
		if (hr.responseText == "Update Successful") {
				alert ("Product " + uid + " changed to Inactive status");
					}else{
			alert ("An error occused while adding a category. Please try again. If error happens again, please contact support" + hr.resporseText);
		}
	   }
 
    }
 
    // Send the data to PHP now... and wait for response to update the status div
 
    hr.send(vars); // Actually execute the request
  
}

//Value parameter - required. All other parameters are optional.
function isDate(value, sepVal, dayIdx, monthIdx, yearIdx) {
    try {
        //Change the below values to determine which format of date you wish to check. It is set to dd/mm/yyyy by default.
        var DayIndex = dayIdx !== undefined ? dayIdx : 0; 
        var MonthIndex = monthIdx !== undefined ? monthIdx : 0;
        var YearIndex = yearIdx !== undefined ? yearIdx : 0;
 
        value = value.replace(/-/g, "/").replace(/\./g, "/"); 
        var SplitValue = value.split(sepVal || "/");
        var OK = true;
        if (!(SplitValue[DayIndex].length == 1 || SplitValue[DayIndex].length == 2)) {
            OK = false;
        }
        if (OK && !(SplitValue[MonthIndex].length == 1 || SplitValue[MonthIndex].length == 2)) {
            OK = false;
        }
        if (OK && SplitValue[YearIndex].length != 4) {
            OK = false;
        }
        if (OK) {
            var Day = parseInt(SplitValue[DayIndex], 10);
            var Month = parseInt(SplitValue[MonthIndex], 10);
            var Year = parseInt(SplitValue[YearIndex], 10);
 
            if (OK = ((Year > 1900) && (Year < new Date().getFullYear()))) {
                if (OK = (Month <= 12 && Month > 0)) {

                    var LeapYear = (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0));   
                    
                    if(OK = Day > 0)
                    {
                        if (Month == 2) {  
                            OK = LeapYear ? Day <= 29 : Day <= 28;
                        } 
                        else {
                            if ((Month == 4) || (Month == 6) || (Month == 9) || (Month == 11)) {
                                OK = Day <= 30;
                            }
                            else {
                                OK = Day <= 31;
                            }
                        }
                    }
                }
            }
        }
        return OK;
    }
    catch (e) {
        return false;
    }
}
	</script>

</body>

</html>