<?php include("admin_globals.php"); ?>

<script type="text/javascript" src="js/jscolor/jscolor.js"></script>
<style type="text/css">
#full-width-wrapper {
	margin-left:15px;
}
#menu-board {
	width: 67%;
	display: inline-block;
	float: left;
	margin-top:15px;
	background: #2077a1;
	border: solid 1px #cccfd2;
	-webkit-border-radius: 6px;
	-moz-border-radius: 6px;
	border-radius: 6px;
	padding: 12px;
	clear:both;
}

#menu-board .dd-item {
	width:82%;
	line-height:1.1em;
}
.column-row {
	clear: both;
}
#available-items {
	float: right;
	width: 28%;
}
#available-categories,
#available-widgets,#available-slides {
	float: right;
	width:90%;
	display: inline-block;
	margin-right:0px;
	background:#2077a1;
	border: solid 1px #cccfd2;
	  -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
	padding:13px 18px 8px 13px;
	margin-top:15px;
	margin-bottom:15px;
	padding-top:0px;
}
#available-categories h2,
#available-widgets h2,
#menu-board h2,#available-slides h2 {
	font-family:Arial, Helvetica, sans-serif;
	font-size:1.2em; color:#fff; font-weight:bold;
	cursor: pointer;
}
.columns-1 .column {
	width: 100%;
}
.columns-2 .column {
	width: 50%;
}
.columns-3 .column {
	width: 33%;
}
.columns-4 .column {
	width: 25%;
}
.column {
	box-sizing: border-box;
	display: inline-block;
	float: left;
	padding-left: 10px;
	padding-right: 10px;
}
.column li, #available-categories li,
.column li, #available-widgets li,#available-slides li {
	margin:0;padding:0;
	width:97%;
	color:#000;
	background:#fff;
	border: solid 1px #cccfd2;
	  -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
	padding:1px 4px 1px 4px;
	margin-bottom:5px;
}
.columnnew li{
	margin:0;padding:0;
	width:97%;
	color:#000;
	background:#fff;
	border: solid 1px #cccfd2;
	  -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
	padding:1px 4px 1px 4px;
	margin-bottom:5px;
}
#menu-board {
}
.column h2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 1.2em;
	color: #fff;
	font-weight: bold;
}
.dd-placeholder {
	display: inline-block;
	max-width: 100%;
	width: 100%;
}
#background-image-preview {
	max-width: 400px;
}
#background-image-preview img {
	max-width: 100%;
}
#errormsg {
	color: red;
}

#upload-btn, #delete-image {
	background:#48a3db;
	color:#fff;
	border: 1px solid #777777;
     -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
	padding:3px 6px;
	margin-top:4px;
	margin-bottom:4px;
}

#upload-btn:hover, #delete-image:hover {
	 background:#F00;
}

#upload-bg-image-wrapper {
	float:right;
	width:29%;
}

#num-columns-wrapper {
	float:left;
	width:48%;
	margin-top:2px;
	color:#000;
	clear:both;
}

#num-columns-wrapper h3 {
	font-size: 16px;
	font-weight:bold;
	margin:0;padding:0;
	margin-bottom:8px;
}

.progress{overflow:hidden;height:20px;margin-bottom:20px;background-color:#f7f7f7;background-image:-moz-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#f5f5f5),to(#f9f9f9));background-image:-webkit-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-o-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:linear-gradient(to bottom,#f5f5f5,#f9f9f9);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5',endColorstr='#fff9f9f9',GradientType=0);-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}
.progress .bar{width:0;height:100%;color:#fff;float:left;font-size:12px;text-align:center;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#0e90d2;background-image:-moz-linear-gradient(top,#149bdf,#0480be);background-image:-webkit-gradient(linear,0 0,0 100%,from(#149bdf),to(#0480be));background-image:-webkit-linear-gradient(top,#149bdf,#0480be);background-image:-o-linear-gradient(top,#149bdf,#0480be);background-image:linear-gradient(to bottom,#149bdf,#0480be);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff149bdf',endColorstr='#ff0480be',GradientType=0);-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-transition:width .6s ease;-moz-transition:width .6s ease;-o-transition:width .6s ease;transition:width .6s ease}
.progress .bar+.bar{-webkit-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15)}
.progress-striped .bar{background-color:#149bdf;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);-webkit-background-size:40px 40px;-moz-background-size:40px 40px;-o-background-size:40px 40px;background-size:40px 40px}
.progress.active .bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-moz-animation:progress-bar-stripes 2s linear infinite;-ms-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}
.progress-danger .bar,.progress .bar-danger{background-color:#dd514c;background-image:-moz-linear-gradient(top,#ee5f5b,#c43c35);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#c43c35));background-image:-webkit-linear-gradient(top,#ee5f5b,#c43c35);background-image:-o-linear-gradient(top,#ee5f5b,#c43c35);background-image:linear-gradient(to bottom,#ee5f5b,#c43c35);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b',endColorstr='#ffc43c35',GradientType=0)}
.progress-danger.progress-striped .bar,.progress-striped .bar-danger{background-color:#ee5f5b;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}
.progress-success .bar,.progress .bar-success{background-color:#5eb95e;background-image:-moz-linear-gradient(top,#62c462,#57a957);background-image:-webkit-gradient(linear,0 0,0 100%,from(#62c462),to(#57a957));background-image:-webkit-linear-gradient(top,#62c462,#57a957);background-image:-o-linear-gradient(top,#62c462,#57a957);background-image:linear-gradient(to bottom,#62c462,#57a957);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462',endColorstr='#ff57a957',GradientType=0)}
.progress-success.progress-striped .bar,.progress-striped .bar-success{background-color:#62c462;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}
.progress-info .bar,.progress .bar-info{background-color:#4bb1cf;background-image:-moz-linear-gradient(top,#5bc0de,#339bb9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#339bb9));background-image:-webkit-linear-gradient(top,#5bc0de,#339bb9);background-image:-o-linear-gradient(top,#5bc0de,#339bb9);background-image:linear-gradient(to bottom,#5bc0de,#339bb9);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff339bb9',GradientType=0)}
.progress-info.progress-striped .bar,.progress-striped .bar-info{background-color:#5bc0de;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}
.progress-warning .bar,.progress .bar-warning{background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450',endColorstr='#fff89406',GradientType=0)}
.progress-warning.progress-striped .bar,.progress-striped .bar-warning{background-color:#fbb450;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}
.pic-save-frame{display:inline-block;vertical-align:middle;padding-left:0}
.pic-size-info{text-align:right;margin-left:5px !important;margin-right:0 !important;display:inline-block;height:18px;line-height:18px;vertical-align:middle}
.progress{width:210px;border:1px solid #999 !important;vertical-align:middle;margin-bottom:0}

/*.progress-wrap{float:left;clear:both}*/
.progress-wrap .prog{clear:both;margin:10px 0;}
.progress-wrap .prog .size{clear:both;height:21px;line-height:21px;vertical-align:middle;display:inline-block;padding-right:5px;text-overflow: ellipsis;white-space:nowrap;overflow:hidden;}
.progress-wrap .prog .progress{height:21px;display:inline-block}

#custom-category-form {
	margin-top:0;padding-top:0;
	float: left;
	width: 48%;
}
.choose-category-items {
	margin-top:0;padding-top:0;
	width: 48%;
	float: right;
}
.clearfix {
	clear: both;
}
.edit-custom-category {
	position: absolute;
	right: 5px;
	top: 6px;
}
.edit-custom-category img:hover {
	cursor: pointer;
}

/** Menu board schedule styles **/
.popup_background {
	z-index: 4005; /* any number */
}
.popup_wrapper {
	z-index: 4006; /* any number + 1 */
}
.modal_close_button {
	position: absolute;
	top: 5px;
	right: 5px;
}
.popup_modal {
	display:none;
	background:white;padding:20px;
		border: 1px solid #777777;
     -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
	max-width:800px;
}
.menu-boards-schedule {
	margin-top: 15px;
	margin-bottom: 15px;
}
.menu-board-schedule-settings {
	display: none;
	margin-top: 15px;
}

#manage-slides-button a {
	float:right;
	width:25%;
	margin-right:20px;
		background:#209FF0;
	background: -moz-linear-gradient(top, #1682b2 1%, #209FF0 100%);
	background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#1682b2), color-stop(100%,#209FF0));
	background: -webkit-linear-gradient(top, #1682b2 1%,#209FF0 100%);
	background: -o-linear-gradient(top, #1682b2 1%,#209FF0 100%);
	background: -ms-linear-gradient(top, #1682b2 1%,#209FF0 100%);
	background: linear-gradient(top, #1682b2 1%,#209FF0 100%);
	color:#fff;
     -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
	padding:10px;
	text-decoration:none;
	   border: solid 3px #D0D0D0;
	font-size:1.2em;
	text-align:center;
	max-height:80px;
	vertical-align:middle;
	margin-bottom:15px;
}

#manage-slides-button a:hover {
	    background:#1eac63;
	background: -moz-linear-gradient(top, #1eac63 1%, #19894f 100%);
	background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#1eac63), color-stop(100%,#19894f));
	background: -webkit-linear-gradient(top, #1eac63 1%,#19894f 100%);
	background: -o-linear-gradient(top, #1eac63 1%,#19894f 100%);
	background: -ms-linear-gradient(top, #1eac63 1%,#19894f 100%);
	background: linear-gradient(top, #1eac63 1%,#19894f 100%);
}

.mb-top-left {
	float:left;
	width:69%;
}

.mb-top-left h1 {
	display:block;
	float:left;width:66%;
}
.edit_popUp_slide {
    position: absolute;
    right: 50px;
    top: 6px;
}

/** END Menu board schedule styles **/

</style>

<div id="full-width-wrapper">
<?php
if ($_SESSION['FirstName'] == "") {
	echo 'You are not authorized to view this page. <br><br>You may <a href="index.php">log in here.</a>';
	exit;
	}

	//print_r($_SESSION);
	$admin_folder = $_SESSION['admin_folder'];
	if($_GET['admin-page']>""){
	$admin_page = "?admin-page=".$_GET['admin-page'];
	}
	if($_GET['board']>""){
		$selected_board = $_GET['board'];
		//echo "selected: $selected_board";
	}
	/* If get a parametr of monitor */
	if(isset($_GET['monitor'])){

		$selected_board = $_GET['monitor'];
		$is_monitor     = 1;
		$qry = "SELECT count('id') as total from menu_boards_live where board_number=".$selected_board;
		$res = mysql_query($qry);
		$row = mysql_fetch_assoc($res);

		if($row['total'] != 0 ){
			$published = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Published - this monitor is live. Be sure to publish it again after making any changes</p>';
		} else {
			$published = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Unpublished. This monitor is not yet live.</p>';
		}
		//echo "selected: $selected_board";
	}else{
		$is_monitor = 0;
	}
	/* if get a parametr of monitor */

	/* If get parametr is a slide */
	if($_GET['slide']>""){

		$selected_board = $_GET['slide'];
		$is_slide = 1;
		$qry      = "SELECT count('id') as total from menu_boards_live where board_number=".$selected_board;
		$res      = mysql_query($qry);
		$row      = mysql_fetch_assoc($res);

		if($row['total'] != 0 ){
			$slidePublished = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Published - this slide is live. Be sure to publish it again after making any changes.</p>';
		} else {
			$slidePublished = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Unpublished. This slide is not yet live.</p>';
		}

		$join = "SELECT menu_board_schedule.menu_board, menu_boards_live.board_name FROM menu_board_schedule INNER JOIN menu_boards_live ON menu_board_schedule.menu_board=menu_boards_live.board_number WHERE menu_board_schedule.display_board =".$selected_board; 
		
		$Jres  = mysql_query($join) or die(mysql_error());
		$slideusedMonitor = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >';
		$i=0;
		$arr = array();
		while ( $Jrow = mysql_fetch_array($Jres) ) {
			$arr[$i] = 'Monitor '.$Jrow["menu_board"].'('.$Jrow["board_name"].')';
			$i++;
		}
		//check for popup usage
		$join2 = "SELECT menu_board_ads.menu_board, menu_boards_live.board_name FROM menu_board_ads INNER JOIN menu_boards_live ON menu_board_ads.menu_board=menu_boards_live.board_number WHERE menu_board_ads.display_board =".$selected_board; 
		
		$Jres2  = mysql_query($join2) or die(mysql_error());
		$i=0;
		$arr2 = array();
		while ( $Jrow2 = mysql_fetch_array($Jres2) ) {
			$arr2[$i] = 'Monitor '.$Jrow2["menu_board"].'('.$Jrow2["board_name"].')';
			$i++;
		}
		
		if(!empty($arr)){
			$slideusedMonitor .= 'This slide is currently in use on the following monitors: ';
			$slideusedMonitor .= implode(',',$arr);
			$slideusedMonitor .= '<br><br>';
		}
		if(!empty($arr2)){
			$slideusedMonitor .= 'This slide is currently in use as a popup ad on the following monitors: ';
			$slideusedMonitor .= implode(',',$arr2);
			$slideusedMonitor .= '<br><br>';			
		}
		
		if(empty($arr) && empty($arr2)){
			$slideusedMonitor .= 'This slide is not currently in use.</p>';
		} else {
			$slideusedMonitor .= '.</p>';
		}

	} else {
		$is_slide = 0;
	}
	/* If get parametr is a slide */

	if($_GET['show_descriptions']>""){
		if($_GET['show_descriptions']=="yes"){
			$show_descriptions = 1;
		} else {
			$show_descriptions = 0;
		}

		$qry="update menu_boards set show_menu_descriptions = '".$show_descriptions."' where board_number='$selected_board'";
		mysql_query($qry);

	}

	if($_GET['show_item_descriptions']>""){
		if($_GET['show_item_descriptions']=="yes"){
			$show_item_descriptions = 1;
		} else {
			$show_item_descriptions = 0;
		}

		$qry="update menu_boards set show_item_descriptions = '".$show_item_descriptions."' where board_number='$selected_board'";
		mysql_query($qry);

	}


	if($_GET['action']=="publish"){
		//publish current menu board to live view
		//first clear existing records for this menu board
		
		$qry="delete from menu_boards_live where board_number='$selected_board'";
		mysql_query($qry);

		$qry="delete from menu_board_items_live where board_number='$selected_board'";
		mysql_query($qry);


		$qry="INSERT INTO menu_boards_live SELECT * FROM menu_boards where board_number='$selected_board'";
		mysql_query($qry);


		$qry="INSERT INTO menu_board_items_live SELECT * FROM menu_board_items where board_number='$selected_board'";
		mysql_query($qry);

		echo "<font color='red'>Menu board published successfully. </font><br>";

		if( isset($_GET['monitor']) ){

			$qry = "SELECT count('id') as total from menu_boards_live where board_number=".$selected_board;
			$res = mysql_query($qry);
			$row = mysql_fetch_assoc($res);

			if($row['total'] != 0 ){
				$published = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Published - this monitor is live. Be sure to publish it again after making any changes</p>';
			} else {
				$published = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Unpublished. This monitor is not yet live.</p>';
			}
		}

		if( isset($_GET['slide']) ) {

			$qry = "SELECT count('id') as total from menu_boards_live where board_number=".$selected_board;
			$res = mysql_query($qry);
			$row = mysql_fetch_assoc($res);

			if($row['total'] != 0 ){
				$slidePublished = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Published - this slide is live. Be sure to publish it again after making any changes.</p>';
			} else {
				$slidePublished = '<p style="color:red;border-bottom:none;font-size:11px;margin-top:1px;margin-left: 5px;" >Unpublished. This slide is not yet live.</p>';
			}
		}
	}

if($_SESSION['menu_boards']==0){
	echo "You are not subscribed to this service.";
}

// if($selected_board > 0 && $selected_board <= $_SESSION['menu_boards']){
if(isset($selected_board)){
	$board = getMenuBoard($selected_board);

	// Get num columns
	if (isset($_GET['num_columns']) && !empty($_GET['num_columns']) && $_GET['num_columns'] > 0 && $_GET['num_columns'] < 5) {
		$numColumns = $_GET['num_columns'];
		updateMenuBoardNumColumns($board, $numColumns);
	} else {
		$numColumns = !empty($board['column_count']) ? $board['column_count'] : 1;
	}
	if(isset($_GET['monitor'])){
	echo "<div class='mb-top-left'><h1 style='text-align:left;'>You are managing monitor #$selected_board<br />
		$published
	</h1>";
	
	}elseif(isset($_GET['slide'])){
		echo "<div class='mb-top-left'><h1 style='text-align:left;'>You are managing slide #$selected_board <br> $slidePublished $slideusedMonitor </h1>";
		$url_variable = "slide";
	}

	if($is_monitor == 1){
		echo "<div id='manage-slides-button'><a style='margin-bottom:4px;' href='?admin-page=10'  
data-tooltip='Click to manage individual slides. You can have unlimited slides per each monitor.'>Manage Slides</a><div style='clear:both;'>
<a href='?admin-page=5'>Return to Monitor List</a></div></div>";
    	$url_variable = "monitor";
	}

	if($url_variable == "slide"){
	    echo "<div class='preview-menu-board'><a href='?admin-page=5'>Menu Board Home</a></div>";
	    echo '<br><br>';
		$deleteSlide = $_GET["slide"];
		echo "<div class='preview-menu-board'><a class='deleteSlide' data-id='$deleteSlide' href='javascript:void(0);'>Delete this slide </a></div>";
	}
	
	echo "</div>";

	//echo"<span class='description-text'>To create your menu board simply drag and drop menu categories into the column where you want them displayed (below). <br />
	//<strong>IMPORTANT:</strong> Preview your menu board before you publish it (make it live). You may need to adjust your menu categories and items to fit within the monitor columns.</span>";
	$display_url = "http://$_SERVER[SERVER_NAME]/menu-boards/live_display.php?$url_variable=$selected_board";
	$preview_url = "http://$_SERVER[SERVER_NAME]/menu-boards/display.php?$url_variable=$selected_board";

	echo "<div class='preview-menu-board'><a href='index.php'>Admin Home</a></div>";
	echo "<div class='preview-menu-board'><a href='?admin-page=".$_GET['admin-page']."&action=publish&$url_variable=$selected_board'>Publish</a></div>";
	if($is_slide==1){
		echo "<div class='preview-menu-board'><a href='$preview_url' target='blank'>Preview</a></div>";
	}
	echo "<div class='mb-top-right'>To display the live view of this menu board (menu board $selected_board), the web address is:<br /> <a href='$display_url' target='blank'><font color='blue'><u>$display_url</u></font></a></div>";



		// Number of columns
	if($is_slide==1){
		echo '<div id="num-columns-wrapper">';
		echo "<div style='margin-bottom:14px;'>Slide name: <input name='monitor_name' id='monitor_name' type='text' size='40' value='".$board['board_name']."'></div>";
	if($is_slide==1){
		echo '<h3>Layout Options</h3><label>Number of Columns: </label>';
		echo '<br /><select id="num-columns" name="num_columns">';
		for ($i = 1; $i < 5; $i++) {
			echo '<option value="'.$i.'"';
			if ($i == $numColumns) {
				echo ' selected';
			}
			echo '>'.$i.'</option>';
		}
		echo '</select>';
	}
		echo '<input id="original-num-columns" type="hidden" name="original_num_columns" value="'.$numColumns.'">';

	if($is_slide==1){
		// Scroll text
		echo '<div class="scroll-ctl-box">';
		echo '<h3>Add Scrolling Text</h3><label for="scroll_text">Scroll Text</label><br />';
		echo '<textarea id="scroll_text" name="scroll_text" cols="35" >';
		if (!empty($board)) {
			echo $board['scroll_text'];
		}
		echo '</textarea><br />';
		echo '';

		// Scroll position
		echo '<div style="margin-top:8px;"><label>Scroll Position: </label></div>';
		echo '<select id="scroll_position" name="scroll_position">';
		echo '<option value="1"'. ((!empty($board) && $board['scroll_position'] == 1) ? ' selected' : '') .'>Top</option>';
		echo '<option value="2"'. ((!empty($board) && $board['scroll_position'] == 2) ? ' selected' : '') .'>Bottom</option>';
		echo '</select><br />';
		echo '</div>';
		

        // Text Size
		echo '<div>';
		echo '<br /><label>Text Size: </label><br />';
		echo '<select id="text_multiplier" name="text_multiplier">';
		$sizes = array(
			'1.5' => 'X-Large',
			'1.25' => 'Large',
			'1.0' => 'Normal',
			'0.75' => 'Small',
			'0.5' => 'X-Small'
		);
		foreach ($sizes as $size => $name) {
			echo '<option value="'.$size.'"'. ((!empty($board) && $board['text_multiplier'] == $size) ? ' selected' : '') .'>'.$name.'</option>';
		}
		echo '</select>';
		echo '</div>';
		$startTime=explode(' ', $board['start_time']);
		$endTime=explode(' ', $board['end_time']);
		
		echo '<div>';
		?>
		<input type="hidden" name="recKey" id="recKey" value="<?php echo $board['recordkey']; ?>">
		<label style="margin-top:10px">Select Day of Week</label>
		<select name="dayofweek" id="dayofweek" class="s-box-jumpTo">
		    <option value="All" <?php if("All"==$board['day_of_week']) { echo 'selected'; } ?> >Every day</option>
			<option value="Sunday" <?php if("Sunday"==$board['day_of_week']) { echo 'selected'; } ?> >Sunday</option>
		    <option value="Monday" <?php if("Monday"==$board['day_of_week']) { echo 'selected'; } ?> >Monday</option>
		 	<option value="Tuesday" <?php if("Tuesday"==$board['day_of_week']) { echo 'selected'; } ?> >Tuesday</option>
		 	<option value="Wednesday" <?php if("Wednesday"==$board['day_of_week']) { echo 'selected'; } ?>>Wednesday</option>
		 	<option value="Thursday" <?php if("Thursday"==$board['day_of_week']) { echo 'selected'; } ?>>Thursday</option>
		 	<option value="Friday" <?php if("Friday"==$board['day_of_week']) { echo 'selected'; } ?>>Friday</option>
		 	<option value="Saturday" <?php if("Saturday"==$board['day_of_week']) { echo 'selected'; } ?>>Saturday</option>
		</select>
	    </div>
		
		<div>
		<label>Display Starting</label>
		<select id="starttime" name="starttime" style="min-width: 80px !important; margin: 11px;">
		<?php
		for($i = 0; $i < 13; $i++) {
			$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
			?>	<option value="<?php echo $iDisplay; ?>"
			<?php
			if($startTime[0]==$iDisplay)
			{
				echo 'selected';
			}
			?>><?php echo $iDisplay; ?></option>
		<?php 
	    }
	    ?>
		</select>
		<select id="start-meridiem" style="min-width: 80px !important;">
		<option value="am" <?php
			if($startTime[1]=="am")
			{
				echo 'selected';
			}
			?>>am</option>
		<option value="pm" <?php if($startTime[1]=="pm")
			{
				echo 'selected';
			}
			?>>pm</option>
		</select>
		</div>

		<div>
		<label>Display Until</label>
		<select id="endtime" name="endtime" style="min-width: 80px !important; margin-top: 10px; margin-left: 27px;">
		<?php
		for($i = 0; $i < 13; $i++) {
			$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
			?>
			<option value="<?php echo $iDisplay; ?>"
			<?php
			if($endTime[0]==$iDisplay)
			{
				echo 'selected';
			}
			?>
			><?php echo $iDisplay; ?></option>
		<?php 
		}
		?>
		</select>
		<select id="end-meridiem" style="margin-left:15px;min-width: 80px !important">
		<option value="am"<?php 
		    if($endTime[1]=="am")
			{
				echo 'selected';
			}
			?>>am</option>
		<option value="pm" <?php 
		    if($endTime[1]=="pm")
			{
				echo 'selected';
			}
			?>>pm</option>
		</select>
		</div>
		
		<?php
        echo '<div class="show-label"><br />';
		if($board['show_menu_descriptions']==1){$checked = " checked='checked'";} else { $checked="";}
		echo "<input type='checkbox' name='show_descriptions' id='show_descriptions'  onclick='check(this);' $checked>";
		echo "<label> Show category descriptions: </label></div>";

		echo '<div class="show-label">';
		if($board['show_item_descriptions']==1){$checked = " checked='checked'";} else { $checked="";}
		echo "<input type='checkbox' name='show_item_descriptions' id='show_item_descriptions'  onclick='toggle(this);' $checked>";
		echo "<label> Show item descriptions: </label></div>"; //end show-label

		echo '<div class="show-label">';
		$recordkeyDesc = $board['recordkey'];
		if($board['show_menu_images']==1){$checked = " checked='checked'";} else { $checked="";}
		echo "<input type='checkbox' data-recordkey='$recordkeyDesc' class='changeItemDEscpStat' name='' id='' $checked>";
		echo "<label> Show item images: </label></div>"; //end show-label

		// Text Size
		echo '<div style="clear:both;">';
		echo '</div>';
	} //end if slide loop
	//***********************************

	// Menu Board Schedule
	echo '<div class="menu-boards-schedule">';
	echo '<h3>Schedule</h3>';

	echo '<div>';
	echo '<label><input class="schedule-checkbox" type="checkbox" name="schedule" value="use_schedule" '.($board['use_schedule'] ? 'checked' : '').'> Change on time schedule</label>';
	echo '</div>';

	echo '<div>';
	echo '<label><input class="schedule-checkbox" type="checkbox" name="schedule" value="toggle_boards" '.($board['toggle_boards'] ? 'checked' : '').'> Use constant rotation 1</label>';
	echo '</div>';

	
	echo '<div class="menu-board-schedule-settings" id="time-schedule-settings">';
	echo '<h4>Slides in rotation schedule for this monitor:</h4>';
	echo '<div id="menu-boards-in-schedule">';

	$boardSchedule = getMenuBoardSchedule($board['board_number']);

	foreach ($boardSchedule as $boardScheduleItem) {
		$time = strtotime($boardScheduleItem['switch_time']);
		$hour = date('h', $time);
		$minute = date('i', $time);
		$meridiem = date('a', $time);
		echo '<div class="menu-board-in-schedule">';
		echo '<input type="hidden" name="schedule_board" value="'.$boardScheduleItem['display_board'].'">';
		echo '<input type="hidden" name="schedule_hour" value="'.$hour.'">';
		echo '<input type="hidden" name="schedule_minute" value="'.$minute.'">';
		echo '<input type="hidden" name="schedule_meridiem" value="'.$meridiem.'">';
		$slideqry="Select board_name from menu_boards where add_on_slide='1' and board_number='".$boardScheduleItem['display_board']."'";
		$rt=mysql_query($slideqry);
		while($data = mysql_fetch_array($rt)){$slide_name = $data['board_name'];}
		echo 'Slide '.$boardScheduleItem['display_board'].' ('.$slide_name.') '.$hour.':'.$minute.' '.$meridiem;
		echo ' <button class="edit-menu-board-in-schedule" type="button">Edit</button>';
		echo ' <button class="remove-menu-board-in-schedule" type="button">Remove</button>';
		echo '</div>';
	}
	echo '</div>'; // /#menu-boards-in-schedule

	echo '<div>';
	echo '<button class="add_menu_board_to_schedule_modal_open" type="button">Add a board</button>';
	echo '</div>';
	echo '</div><!-- /#time-schedule-settings -->';

	echo '<div class="menu-board-schedule-settings" id="rotation-schedule-settings">';
	echo '<div>';
	echo '<h4>Slides in rotation</h4>';
	echo '<div id="menu-boards-in-rotation">';
	foreach ($boardSchedule as $boardScheduleItem) {
		echo '<div class="menu-board-in-rotation">';
		echo '<input type="hidden" name="boards_in_rotation[]" value="'.$boardScheduleItem['display_board'].'">';
		$slideqry="Select board_name from menu_boards where add_on_slide='1' and board_number='".$boardScheduleItem['display_board']."' ";
		$rt=mysql_query($slideqry);
		while($data = mysql_fetch_array($rt)){$slide_name = $data['board_name'];}
		echo 'Slide ' .$boardScheduleItem['display_board'] . "($slide_name)";
		echo ' <button class="remove-menu-board-in-rotation" type="button">Remove</button>';
		echo '</div>';
	}
	echo '</div>'; // /#menu-boards-in-rotation
	echo '</div>';
	echo '<select id="select-menu-board-rotation">';
	for ($i = 1; $i < 11; $i++) {
		echo '<option value="'.$i.'">Menu Board '.$i.'</option>';
	}
	echo '</select>';
	echo ' <button id="add-board-to-rotation" type="button">Add</button>';
	echo '</div><!-- /#rotation-schedule-settings -->';

	echo '</div><!-- /.menu-boards-schedule -->';

	echo '<div id="add_menu_board_to_schedule_modal" class="popup_modal">';
	echo '<a href="#" class="add_menu_board_to_schedule_modal_close modal_close_button"><img src="/images/x-15.png" width="15" height="15" /></a>';
	echo '<h3>Add Menu Board to Schedule</h3>';
	echo '<label>Menu Board: </label>';
	echo '<select id="add-to-schedule-board">';
	for ($i = 1; $i < 11; $i++) {
		echo '<option value="'.$i.'">Menu Board '.$i.'</option>';
	}
	echo '</select>';
	echo '<br>';
	echo '<br>';
	echo '<label>Switch Time: </label>';
	echo '<select id="add-to-schedule-hour">';
	for($i = 1; $i < 13; $i++) {
		$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
		echo '<option>'.$iDisplay.'</option>';
	}
	echo '</select>';
	echo ':';
	echo '<select id="add-to-schedule-minute">';
	echo '<option>00</option>';
	echo '<option>30</option>';
	echo '</select>';
	echo '<select id="add-to-schedule-meridiem">';
	echo '<option value="am">am</option>';
	echo '<option value="pm">pm</option>';
	echo '</select>';

	echo '<br>';
	echo '<br>';
	echo '<button id="save-button" class="add_menu_board_to_schedule_modal_close" type="button" onclick="addMenuBoardToSchedule()">Save</button>';
	echo '</div>'; // end modal

	echo '<div id="edit_menu_board_to_schedule_modal" class="popup_modal">';
	echo '<a href="#" class="edit_menu_board_to_schedule_modal_close modal_close_button"><img src="/images/x-15.png" width="15" height="15" /></a>';
	echo '<h3>Edit Menu Board in Schedule</h3>';
	echo '<label>Menu Board: </label>';
	echo '<select id="edit-schedule-board">';
	for ($i = 1; $i < 11; $i++) {
		echo '<option value="'.$i.'">Menu Board '.$i.'</option>';
	}
	echo '</select>';
	echo '<br>';
	echo '<br>';
	echo '<label>Switch Time: </label>';
	echo '<select id="edit-schedule-hour">';
	for($i = 1; $i < 13; $i++) {
		$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
		echo '<option>'.$iDisplay.'</option>';
	}
	echo '</select>';
	echo ':';
	echo '<select id="edit-schedule-minute">';
	echo '<option>00</option>';
	echo '<option>30</option>';
	echo '</select>';
	echo '<select id="edit-schedule-meridiem">';
	echo '<option value="am">am</option>';
	echo '<option value="pm">pm</option>';
	echo '</select>';

	echo '<br>';
	echo '<br>';
	echo '<button id="save-button" class="edit_menu_board_to_schedule_modal_close" type="button" onclick="updateMenuBoardToSchedule()">Save</button>';
	echo '</div>'; // end modal
	echo '<button id="trigger-edit-schedule-modal" class="edit_menu_board_to_schedule_modal_open" type="button" style="display:none;">&nbsp;</button>';

	// END Menu board schedule
//***********************************
	echo '</div> <!-- /#num-columns-wrapper -->';
}elseif($is_monitor){
	echo '<div id="add_menu_board_to_schedule_modal" class="popup_modal">';
	echo '<a href="#" class="add_menu_board_to_schedule_modal_close modal_close_button"><img src="/images/x-15.png" width="15" height="15" /></a>';
	echo '<h3>Add Menu Board to Schedule</h3>';
	echo '<label>Menu Board: </label>';
	echo '<select id="add-to-schedule-board">';
	for ($i = 1; $i < 11; $i++) {
		echo '<option value="'.$i.'">Menu Board '.$i.'</option>';
	}
	echo '</select>';
	echo '<br>';
	echo '<br>';
	echo '<label>Switch Time: </label>';
	echo '<select id="add-to-schedule-hour">';
	for($i = 1; $i < 13; $i++) {
		$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
		echo '<option>'.$iDisplay.'</option>';
	}
	echo '</select>';
	echo ':';
	echo '<select id="add-to-schedule-minute">';
	echo '<option>00</option>';
	echo '<option>30</option>';
	echo '</select>';
	echo '<select id="add-to-schedule-meridiem">';
	echo '<option value="am">am</option>';
	echo '<option value="pm">pm</option>';
	echo '</select>';

	echo '<br>';
	echo '<br>';
	echo '<button id="save-button" class="add_menu_board_to_schedule_modal_close" type="button" onclick="addMenuBoardToScheduleMonitor()">Save</button>';
	echo '</div>'; // end modal
	
	echo '<button id="trigger-edit-schedule-modal" class="edit_menu_board_to_schedule_modal_open" type="button" style="display:none;">&nbsp;</button>';
	
	echo '<button id="trigger-edit-popup-modal" class="edit_menu_board_modal_open" type="button" style="display:none;">&nbsp;</button>';
	
	// open edit_menu_board
	echo '<div id="edit_menu_board_modal" class="popup_modal">';
	
	
	echo '<a href="#" class="edit_menu_board_modal_close modal_close_button"><img src="/images/x-15.png" width="15" height="15" /></a>';
	echo '<h3>Popup-Ad Settings</h3>';
	?>
    <span style="width: 75px;display: inline-block;">Display time</span>
			<select name="ad_interval_new" id="ad_interval_new">
				<?php 
				for($i = 0; $i < 13; $i++) {
					$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
					?>
					<option value="<?php echo $iDisplay; ?>"><?php echo $iDisplay; ?></option>
			<?php } 
			?>
	        </select>
	        <?php echo ':'; ?>
			<select name="ad_duration_new" id="ad_duration_new">
				<?php 
				for($i = 0; $i < 60; $i++) {
					$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
					?>
					<option value="<?php echo $iDisplay; ?>"><?php echo $iDisplay; ?></option>
			<?php } 
			?>
			</select> 
	<select id="popup-meridiem">
	<option value="am">am</option>
	<option value="pm">pm</option>
	</select>
	<?php
	echo '<br>';
	echo '<br>';
	echo '<button id="save-button" class="edit_menu_board_to_schedule_modal_close" type="button" onclick="updateMenuBoardMonitor()">Save</button>';
	
	echo '</div>'; // end modal


	echo '<div id="edit_menu_board_to_schedule_modal" class="popup_modal">';
	echo '<a href="#" class="edit_menu_board_to_schedule_modal_close modal_close_button"><img src="/images/x-15.png" width="15" height="15" /></a>';
	echo '<h3>Edit Menu Board in Schedule</h3>';
	echo '<label>Menu Board: </label>';
	echo '<select id="edit-schedule-board">';
	for ($i = 1; $i < 11; $i++) {
		echo '<option value="'.$i.'">Menu Board '.$i.'</option>';
	}
	echo '</select>';
	echo '<br>';
	echo '<br>';
	echo '<label>Switch Time: </label>';
	echo '<select id="edit-schedule-hour">';
	for($i = 0; $i < 13; $i++) {
		$iDisplay = str_pad($i, 2, '0', STR_PAD_LEFT);
			echo '<option>'.$iDisplay.'</option>';
	}
	echo '</select>';
	echo ':';
	echo '<select id="edit-schedule-minute">';
	echo '<option>00</option>';
	echo '<option>30</option>';
	echo '</select>';
	echo '<select id="edit-schedule-meridiem">';
	echo '<option value="am">am</option>';
	echo '<option value="pm">pm</option>';
	echo '</select>';

	echo '<br>';
	echo '<br>';
	echo '<button id="save-button" class="edit_menu_board_to_schedule_modal_close" type="button" onclick="updateMenuBoardToScheduleMonitor()">Save</button>';
	echo '</div>'; // end modal



echo '<div id="num-columns-wrapper">';
		echo "<div>Monitor name: <input name='monitor_name' id='monitor_name' type='text' size='42' value='".$board['board_name']."'></div>";
?>

	<br>

	<div class="menu-board-settings">
		<h3>Schedule</h3>

		<?php
			$checktoggel="Select * from menu_boards where board_number='".$board['board_number']."'";
			$result=mysql_query($checktoggel);
			$boardSettings = mysql_fetch_assoc($result);
		?>
		<div style="margin-bottom:6px;"><label>
		<input type="checkbox"  value="use_schedule" <?php echo $boardSettings['use_schedule'] == 1 ? 'checked' : ''; ?> name="schedule" class="schedule-checkbox_monitor"> Change on time schedule</label></div>
		<div><label><input type="checkbox" value="toggle_boards" name="schedule" <?php echo $boardSettings['toggle_boards'] == 1 ? 'checked' : ''; ?> class="schedule-checkbox_monitor"> Use constant rotation </label></div>

		<br>
		<div>
		<input type="hidden" name="recKey" id="recKey" value="<?php echo $boardSettings['recordkey']; ?>">
		<label>Select Transition</label>
		<select name="transSchedule" id="transSchedule" class="s-box-jumpTo">
		    <option value="0" <?php if(0==$boardSettings['transition_schedule']) { echo 'selected'; } ?> > None </option>
		    <option value="1" <?php if(1==$boardSettings['transition_schedule']) { echo 'selected'; } ?> >Slide Left</option>
		 	<option value="2" <?php if(2==$boardSettings['transition_schedule']) { echo 'selected'; } ?> >Slide Right</option>
		 	<option value="3" <?php if(3==$boardSettings['transition_schedule']) { echo 'selected'; } ?>>Fade</option>
		 	<option value="4" <?php if(4==$boardSettings['transition_schedule']) { echo 'selected'; } ?>>Spinning</option>
		  </select>
	    </div>
	    <br>
		<h3>Popup-Ad Settings</h3>

		<div>
			<span style="width: 75px;display: inline-block;">Show every:</span>
			<select name="ad_interval" id="ad_interval">
				<?php for($i = 1; $i < 16; $i++) : ?>
					<option value="<?php echo $i; ?>" <?php echo $i == $boardSettings['ad_interval'] ? 'selected' : '' ?>>
						<?php echo $i; ?> minute<?php echo $i > 1 ? 's' : ''; ?>
					</option>
				<?php endfor; ?>
			</select>
		</div>

		<div>
			<span style="width: 75px;display: inline-block;">Show for:</span>
			<select name="ad_duration" id="ad_duration">
				<?php for($i = 3; $i < 31; $i++) : ?>
					<option value="<?php echo $i; ?>" <?php echo $i == $boardSettings['ad_duration'] ? 'selected' : '' ?>>
						<?php echo $i; ?> seconds
					</option>
				<?php endfor; ?>
			</select>
		</div>

		<div>
		<input type="hidden" name="recKey" id="recKey" value="<?php echo $boardSettings['recordkey']; ?>">
		<label>Select Transition</label>
		<select name="transSchedulePop" id="transSchedulePop" class="s-box-jumpTo">
		    <option value="0" <?php if(0==$boardSettings['transition_popup']) { echo 'selected'; } ?> > None </option>
		    <option value="1" <?php if(1==$boardSettings['transition_popup']) { echo 'selected'; } ?> >Slide Left</option>
		 	<option value="2" <?php if(2==$boardSettings['transition_popup']) { echo 'selected'; } ?> >Slide Right</option>
		 	<option value="3" <?php if(3==$boardSettings['transition_popup']) { echo 'selected'; } ?>>Fade</option>
		 	<option value="4" <?php if(4==$boardSettings['transition_popup']) { echo 'selected'; } ?>>Spinning</option>
		  </select>
	    </div>
	    <br>
	</div>

	<br>

	<div class="monitor_schedule_wrapper">
		<div id="rotation-schedule-settings" class="menu-board-schedule-settings">
			<h4><font color='white'>Slides in rotation</font></h4>

			<div id="menu-boards-in-rotation">
				<div data-column-number="1" class="column dd" id="column-1" style="width:100%">
					<?php
					$boardSchedule = getMenuBoardSchedule($board['board_number']);
					$monitor_toggle_count = 1;

					if(!empty($boardSchedule)){
						echo '<ol class="dd-list">';
					foreach ($boardSchedule as $boardScheduleItem) {

						echo '<li class="dd-item" data-type="slides" data-item-id="'.$boardScheduleItem['display_board'].'" data-item-num="'.$monitor_toggle_count.'">';
						echo '<input type="hidden" name="boards_in_rotation[]" value="'.$boardScheduleItem['display_board'].'">';
						$slideqry="Select board_name from menu_boards where add_on_slide='1' and board_number='".$boardScheduleItem['display_board']."' ";
						$rt=mysql_query($slideqry);
						while($data = mysql_fetch_array($rt)){$slide_name = $data['board_name'];}
						echo 'Slide ' .$boardScheduleItem['display_board'] . " ($slide_name)";
						echo ' <span class="remove-icon">
							<a class="remove-menu-board-in-monitor" href="#"><img src="../images/remove-icon.png" title="Remove from menu board"></a></span>';
						echo '</li>';
						$monitor_toggle_count++;
					}
					echo '</ol>';
					}else{
						echo '<div class="dd-empty"></div>';
					}

					?>
				</div>
			</div>
		</div>

		<div id="time-schedule-settings" class="menu-board-schedule-settings">
			<h4><font color='white'>Slides in rotation schedule for this monitor:</font></h4>

			<?php
				if (count($boardSchedule) == 0){
					echo "<h4><font color='white'>Drag slides Here</font></h4>";
				}
			?>

			<div id="menu-boards-in-schedule">
				<div data-column-number="1" class="column dd" id="column-1" style="width:100%">
					<?php
						$monitor_count = 1;

						if(!empty($boardSchedule)){
							echo '<ol class="dd-list">';
							if(count($boardSchedule) == 0){
								echo '<li><b><font>Drag slides Here</font></b></li>';
							}


						foreach ($boardSchedule as $boardScheduleItem) {
							$time = strtotime($boardScheduleItem['switch_time']);
							$hour = date('h', $time);
							$minute = date('i', $time);
							$meridiem = date('a', $time);
							echo '<li class="dd-item" data-type="slides" data-item-id="'.$boardScheduleItem['display_board'].'" data-item-num="'.$monitor_count.'">';
							echo '<input type="hidden" name="schedule_board" value="'.$boardScheduleItem['display_board'].'">';
							echo '<input type="hidden" name="schedule_hour" value="'.$hour.'">';
							echo '<input type="hidden" name="schedule_minute" value="'.$minute.'">';
							echo '<input type="hidden" name="schedule_meridiem" value="'.$meridiem.'">';
							$slideqry="Select board_name from menu_boards where add_on_slide='1' and board_number='".$boardScheduleItem['display_board']."' ";
							$rt=mysql_query($slideqry);
							while($data = mysql_fetch_array($rt)){$slide_name = $data['board_name'];}
							echo 'Slide '.$boardScheduleItem['display_board'].' ('.$slide_name.') '.$hour.':'.$minute.' '.$meridiem;

							echo '<span class="dd-handle">Menu Board 1</span><span class="edit_monitor_slide">
							<img src="images/gear-icon.png"></span><span class="remove-icon">
							<a class="remove-menu-board-in-monitor" href="#"><img src="../images/remove-icon.png" title="Remove from menu board"></a></span>';




							echo '</li>';
							$monitor_count++;


						}
						echo '	</ol>';
						} else {
							echo '<div class="dd-empty"></div>';
						}
					?>
				</div>
			</div>
		</div>
	</div>

	<?php
		$ads = [];
		$sql = "SELECT menu_board_ads.*, menu_boards.board_name 
				FROM menu_board_ads
			 	LEFT JOIN menu_boards on menu_board_ads.display_board = menu_boards.board_number
				WHERE menu_board = '".$board['board_number']."'";

		$result = mysql_query($sql) or die(mysql_error());
	
		while ($row = mysql_fetch_assoc($result)) {
			$ads[] = $row;
		}

	?>
	<div class="monitor_schedule_wrapper">
		<div id="menu-board-ads">
			<h4><font color='white'>Pop-up ads:</font></h4>

			<div id="menu-board-ads">
			<input type="hidden" name="boardNo" id="boardNo" value="<?php echo $board['board_number']; ?>">
		<input type="hidden" name="thisboardNo" id="thisboardNo" value="">
				<div data-column-number="1" id="column-1" style="width:100%" class="column ads dd">
					<?php if (empty($ads)) : ?>
						<div class="dd-empty"></div>
					<?php else: ?>
						<ol class="dd-list">
							<?php foreach ($ads as $ad) : ?>
								<li class="dd-item">
								<?php
								$ptime   = array();
								$ptime   = explode(':',$ad['display_time']);
								$phour   = $ptime[0];
								$pminute = $ptime[1];
								?>
									<span class="dd-handle">Slide <?php echo $ad['display_board']; ?> (<?php echo $ad['board_name']; ?>)
									<?php echo $phour.':',$pminute;
									echo '&nbsp'; 
									echo $ad['display_meridiem'];
									?>
									
									</span>
									<span class="edit_popUp_slide">
							        <img src="images/gear-icon.png"></span>
									<input type="hidden" name="ads[]" value="<?php echo $ad['display_board']; ?>" class="ads">
									<span class="remove-icon"><a class="remove-menu-board-in-monitor" href="#"><img src="../images/remove-icon.png" title="Remove from menu board"></a>
								</li>
							<?php endforeach; ?>
						</ol>
					<?php endif; ?>
				</div>
			</div>
		</div>
	</div>

</div>
<?php

}//End of is monitor condition
	if($is_slide==1){
		echo '<div id="upload-bg-image-wrapper"><div class="mb-bg-label"><label>Background Color:</label><input id="bkgd_color" type="text" name="bkgd_color" class="color" size="8" value="' . $board['bkgd_color'] . '" onchange="saveForm()"></div>';

			// Background image
		echo '';
		echo '<label>Background Image</label>';
		echo '<button id="upload-btn" type="button">Select Image</button>';
		echo '<div id="errormsg"></div>';
		echo '<div id="pic-progress-wrap" class="progress-wrap"></div>';
		echo '<div id="background-image-preview">';
		if (!empty($board) && !empty($board['image_name'])) {
			echo '<img src="/custom/images/menu-boards/' . $board['image_name'] . '">';
			$removeBtnStyles = '';
		} else {
			$removeBtnStyles = 'display:none;';
		}
		echo '</div>';

		echo '<div style="float:right;margin-left:12px;"><button type="button" id="delete-image" style="'.$removeBtnStyles.'">Remove Image</button></div>';
		echo '<input id="image_name" type="hidden" name="image_name" value="'.$board['image_name'].'" />';

		// Image as background
		echo '<div class="image-as-bkgd-fields" '.(!empty($board) && empty($board['image_name']) ? 'style="display:none;"' : '').'>';
		echo '<div style="margin-top:10px;">';
		echo '<label>';
		echo 'Image as Background: ';
		echo '<input id="image_as_bkgd" type="checkbox" name="image_as_bkgd" value="1"' . ((!empty($board) && ($board['image_as_bkgd'] == 1)) ? ' checked' : '') . ' />';
		echo '</label>';
		echo '</div>';
		echo '<div>';
		echo '<span class="image-note-enabled" '. ((!empty($board) && $board['image_as_bkgd'] == 0) ? 'style="display: none;"' : '') . '><span class="small-font">This image will be displayed as the background behind whatever content you select below.</span></span>';
		echo '<span class="image-note-disabled" '. ((!empty($board) && $board['image_as_bkgd'] == 1) ? 'style="display: none;"' : '') . '>This image will be displayed on your menu board, without any other content.</span>';
		echo '</div>';
		echo '</div>';
		echo '</div><!-- /.image-as-bkgd-fields -->';

}


	//show active Categories

	if($is_monitor == 1){

		echo '<div id="available-items">';

		// echo "<div class='preview-menu-board'><a href='slides.php' type='button'><p>Manage lnd slides</p></a></div>";
		echo '<div id="available-slides">';
		echo '<h2>Available Slides</h2>';
		echo '<div class="dd available monitor_slides available-slides expanded">';

		$items = '';
		$slides="Select * from menu_boards where add_on_slide='1' order by board_number";
		$rt=mysql_query($slides);
		$itemNum = 1;
		while($nt=mysql_fetch_array($rt)){
			$items .= "<li id='available-slide-".$itemNum."' class='dd-item available-slide' data-type='slides' data-item-id='".$nt['board_number']."' data-item-num='".$itemNum."'>";
			$items .= '<span class="dd-handle">';
			$items .= 'Slide '.$nt[board_number]. ' ('.$nt[board_name].')';
			$items .= '</span>';
			$items .= "</li>";
			$itemNum++;
		}



		if (!empty($items)) {
			echo "<ol id='ol-available-slides' class='dd-list'>";
			echo $items;
			echo '</ol>';
		} else {
			echo '<div class="dd-empty"></div>';
		}
		echo '</div> <!-- /.dd -->';

		echo '</div><!-- /#available-slides -->';
		echo '</div>';
	}


if($is_slide==1){
	echo '<div id="widgets-wrapper"'. ((!empty($board) && !empty($board['image_name']) && $board['image_as_bkgd'] == 0) ? 'style="display: none;"' : '') . '>';
	echo '<div id="menu-board" class="columns-'.$numColumns.'">';

	for ($columnNum = 1; $columnNum <= $numColumns; $columnNum++) {
		echo '<div id="column-'.$columnNum.'" class="column dd" data-column-number="'.$columnNum.'">';
		echo "<h2>Column $columnNum </h2>";

		// Get items for this column
		$sql = "SELECT *
				FROM menu_board_items
				WHERE board_number = '{$selected_board}' AND display_column = '$columnNum'
				ORDER BY position";
		$result = mysql_query($sql) or die(mysql_error());
		if (mysql_num_rows($result) < 1) {
			echo '<div class="dd-empty"></div>';
		} else {
			echo"<ol class='dd-list'>";
			while($boardItem = mysql_fetch_assoc($result)) {
				// Get category for this menu board
				$itemName = null;
				$customCategoryItems = '';
				if($boardItem['menu_category'] <> "0"){
					$itemType = 'category';
					$itemId = $boardItem['menu_category'];
					if ($boardItem['menu_category'] == 9999) {
						$itemName = $boardItem['custom_name'] . ' <span style="font-size:.8em;font-style:italic;color:red;">(Custom)</span>';

						// Get custom category items
						$customCategoryItems = array();
						foreach (getCustomCategoryItems($boardItem['recordkey']) as $customCategoryItem) {
							$customCategoryItems[] = $customCategoryItem['item_key'];
						}
						$customCategoryItems = implode(',', $customCategoryItems);
					} else {
						$itemName = getCategoryName($boardItem['menu_category']);
					}
				}
				if($boardItem['widget_id'] <> "0"){
					$itemType = 'widget';
					$itemId = $boardItem['widget_id'];
					$itemName = getWidgetName($boardItem['widget_id']);
				}

				if ($itemName != null) {
					echo '<li class="dd-item" data-recordkey="'.$boardItem['recordkey'].'" data-type="'.$itemType.'" data-item-id="'.$itemId.'" data-custom-name="'.$boardItem['custom_name'].'" data-custom-category-items="'.$customCategoryItems.'" data-price-grid-format="'.$boardItem['price_grid_format'].'">';
					echo '<span class="dd-handle">';
					echo $itemName;
					echo '</span>';
					if ($boardItem['menu_category'] == 9999) {
						echo '<span class="edit-custom-category">';
						echo '<img src="images/gear-icon.png">';
						echo '</span>';
					} else {
						echo ' <span class="remove-icon"><a class="remove-category" href="#"><img src="../images/remove-icon.png" title="Remove from menu"></a></span>';
					}
					echo '</li>';
				}
			}
			echo "</ol>";
		}
		echo '</div><!-- /.column -->';

	} //end of column loop
//} //end of slide loop
	echo '</div> <!-- /#menu-board -->';


	//show active Categories

	if($is_monitor == 1){
		echo '<div id="available-items">';
		echo '<div id="available-slides">';
		echo '<h2>Available Slides</h2>';
		echo '<div class="dd available available-slides expanded">';

		$items = '';
		$slides="Select * from menu_boards where add_on_slide='1' order by board_number";
		$rt=mysql_query($slides);
		$itemNum = 1;
		while($nt=mysql_fetch_array($rt)){
			$items .= "<li id='available-slide-".$itemNum."' class='dd-item available-slide' data-type='slides' data-item-id='".$nt['recordkey']."' data-item-num='".$itemNum."'>";
			$items .= '<span class="dd-handle">';
			$items .= 'Menu Board '.$nt[board_number];
			$items .= '</span>';
			$items .= "</li>";
			$itemNum++;
		}



		if (!empty($items)) {
			echo "<ol id='ol-available-slides' class='dd-list'>";
			echo $items;
			echo '</ol>';
		} else {
			echo '<div class="dd-empty"></div>';
		}
		echo '</div> <!-- /.dd -->';

		echo '</div><!-- /#available-slides -->';
		echo '</div>';

	}else{
		echo '<div id="available-items">';
		echo '<div id="available-categories">';
		echo '<h2>Available Categories</h2>';
		echo '<div class="dd available available-categories expanded">';

		$items = '';
		$catqry="Select * from menuCategory where active='1' order by CategoryName";
		$rt=mysql_query($catqry);
		$itemNum = 1;
		while($nt=mysql_fetch_array($rt)){
			$items .= "<li id='available-category-".$itemNum."' class='dd-item available-category' data-type='category' data-item-id='".$nt['RecordKey']."' data-item-num='".$itemNum."'>";
			$items .= '<span class="dd-handle">';
			$items .= $nt[CategoryName];
			$items .= '</span>';
			$items .= "</li>";
			$itemNum++;
		}

		//add custom category option

		$items .= "<li id='available-category-9999' class='dd-item available-category' data-type='category' data-item-id='9999' data-item-num='".$itemNum."'>";
		$items .= '<span class="dd-handle">';
		$items .= "<b><font color='red'>Custom</font></b>";
		$items .= '</span>';
		$items .= "</li>";


		if (!empty($items)) {
			echo "<ol id='ol-available-categories' class='dd-list'>";
			echo $items;
			echo '</ol>';
		} else {
			echo '<div class="dd-empty"></div>';
		}
		echo '</div> <!-- /.dd -->';

		echo '</div><!-- /#available-categories -->';
	}

	// Show Available Widgets
	echo '<div id="available-widgets">';
	echo '<h2>Available Widgets</h2>';
	echo '<div class="dd available available-widgets" style="display: none;">';

	$items = '';
	$sql = "SELECT recordkey, title 
			FROM widgets 
			WHERE active = 1
			ORDER BY title";
	$result = mysql_query($sql) or die(mysql_error());

	$itemNum = 1;
	while($row = mysql_fetch_array($result)){
		$items .= "<li id='available-widget-".$itemNum."' class='dd-item available-widget' data-type='widget' data-item-id='".$row['recordkey']."' data-item-num='".$itemNum."'>";
		$items .= '<span class="dd-handle">';
		$items .= $row['title'];
		$items .= '</span>';
		$items .= "</li>";
		$itemNum++;
	}

	if (!empty($items)) {
		echo "<ol id='ol-available-widgets' class='dd-list'>";
		echo $items;
		echo '</ol>';
	} else {
		echo '<div class="dd-empty"></div>';
	}
	echo '</div> <!--end dd class -->';
	echo '</div> <!-- /#available-widgets -->';
	echo '</div> <!-- /#available-items -->';
	echo '</div><!-- /#widgets-wrapper -->';
	}//end of if slide loop..
} else {
	echo "You have landed here by mistake. Please return to the <a href='?admin-page=5'><u><font color='blue'>home admin page</font></u></a>.";
}

function getMenuBoard($boardNumber) {
	$sql = "SELECT *
			FROM menu_boards
			WHERE board_number = '".$boardNumber."'
			LIMIT 1";
	$result = mysql_query($sql) or die(mysql_error());

	if (mysql_num_rows($result) > 0) {
		return mysql_fetch_assoc($result);
	} else {
		return addMenuBoardRow($boardNumber);
	}
}

function addMenuBoardRow($boardNumber) {
	$sql = "INSERT INTO menu_boards (
				board_number,
				column_count
			) VALUES (
				'".$boardNumber."',
				1
			)";
	mysql_query($sql) or die(mysql_error());
	return getMenuBoard($boardNumber);
}

function updateMenuBoardNumColumns($board, $numColumns) {
	$sql = "UPDATE menu_boards 
			SET column_count = '". mysql_real_escape_string($numColumns)."'
			WHERE board_number = '".$board['board_number']."'";
	mysql_query($sql) or die(mysql_error());
}

function getCategoryName($id) {
	// Get category name
	$qry2 = "SELECT CategoryName 
			FROM menuCategory 
			WHERE RecordKey = '".$id."'";
	$rt2 = mysql_query($qry2);

	if (mysql_num_rows($rt2) < 1) {
		return null;
	}

	$row = mysql_fetch_assoc($rt2);
	return $row['CategoryName'];
}

function getWidgetName($id) {
	// Get widget name
	$qry2 = "SELECT title 
			FROM widgets 
			WHERE recordkey = '".$id."'";
	$rt2 = mysql_query($qry2);

	if (mysql_num_rows($rt2) < 1) {
		return null;
	}

	$row = mysql_fetch_assoc($rt2);
	return $row['title'];
}

function getMenuCategories() {
	$categories = array();

	$sql = "SELECT *
			FROM menuCategory
			ORDER BY CategoryName";
	$result = mysql_query($sql) or die(mysql_error());

	while ($row = mysql_fetch_assoc($result)) {
		$categories[] = $row;
	}

	return $categories;
}

function getCustomCategoryItems($id) {
	$items = array();

	$sql = "SELECT *
			FROM mb_custom_cat
			WHERE cust_cat_key = '".mysql_real_escape_string($id)."'";
	$result = mysql_query($sql) or die(mysql_error());

	while ($row = mysql_fetch_assoc($result)) {
		$items[] = $row;
	}

	return $items;
}

function getMenuBoardSchedule($boardNumber) {
	$boardSchedule = [];

	$sql = "SELECT *
			FROM menu_board_schedule
			WHERE menu_board = '".mysql_real_escape_string($boardNumber)."'
			ORDER BY switch_time, display_board";
	$result = mysql_query($sql) or die(mysql_error());

	while ($row = mysql_fetch_assoc($result)) {
		$boardSchedule[] = $row;
	}

	return $boardSchedule;
}
?>


</div>

<div class='loader'></div>
<div id='backgroundPopup'></div>

<div class='toPopDiv' id='popup_custom_category'>
	<div class='close'></div>
	<span class='ecs_tooltip'>Esc to close <span class='arrow'></span></span>
	<div id='popup_content'> <!--your content start-->
		<h2>Add Custom Category</h2>
		<form id="custom-category-form">
			<h4>Custom Category Details</h4>
			<div>
				<label>Name: </label>
				<input type="text" name="name" value="">
			</div>
			<div style='margin-top:7px;'>
				<label>Price Grid Format: </label>
				<input type="checkbox" name="price_grid_format" value="1">
			</div>
			<div style='margin-top:7px;'>
				<div><strong>Selected Categories</strong></div>
				<div class="selected-categories-list">

				</div>
			</div>
		</form>
		<div class="choose-category-items">
			<h4>Add Category Items</h4>
			<div>
				<label>Category: </label>
				<select name="category">
					<?php foreach (getMenuCategories() as $category): ?>
						<option value="<?php echo $category['RecordKey']; ?>"><?php echo $category['CategoryName']; ?></option> 
					<?php endforeach; ?>
				</select>
			</div>
			<div id="category-items-list">

			</div>
		</div>
		<div class="clearfix"></div>

		<div>
			<button class="cancel-custom-category" type="button">Cancel</button>
			<button class="delete-custom-category" type="button">Delete</button>
			<button class="save-custom-category" type="button">Save</button>
		</div>
		<br />
	</div> <!--your content end-->
</div> <!--toPopup end-->



<!--<script type="text/javascript" src="/<?php echo $admin_folder; ?>/includes/simple-ajax-uploader/SimpleAjaxUploader.min.js"></script>-->
<script type="text/javascript" src="<?php echo $_SESSION['root_path']; ?>/cmsadmin/includes/simple-ajax-uploader/SimpleAjaxUploader.min.js"></script>
<!--<script type="text/javascript" src="../<?php echo $admin_folder; ?>/includes/simple-ajax-uploader/SimpleAjaxUploader.min.js"></script>-->

<script type="text/javascript">


//Code to update monitor-name in database
	$( "#monitor_name" ).change(function() {
  		var monitorName = $('#monitor_name').val();
  		var board = <?php echo $selected_board; ?> ;
  		$.ajax({
			type: 'post',
			url: 'save_menu_board_settings.php',
			data: {action: 'update-monitor-name', monitorName: monitorName, boardNo: board },
			dataType: 'json'
		}).done(function(response) {
		});
	});
//End Code
	var customFormListItem = null;
	var customCategoryFormAction = null;

	$(document).ready(function() {
		<?php if($is_slide){ ?>
		scrollToView();
		$(document).on('scroll', function() {
			scrollToView();
		});


		$(document).on('change', '.changeItemDEscpStat', function(event) {
			event.preventDefault();
			var recodrd = $(this).attr('data-recordkey');

			if( $(this).is(':checked') == true ){

				$.ajax({
					url      : '/cmsadmin/setItemDesc.php',
					type     : 'POST',
					dataType : 'json',
					data     : {
						recordId : recodrd
					},
				}).done(function(res) {
					console.log('check');
					console.log(res);
				});
				
			} else { 

				$.ajax({
					url      : '/cmsadmin/setItemDesc.php',
					type     : 'POST',
					dataType : 'json',
					data     : {
						recordId : recodrd,
						uncheck  : 'uncheck'
					},
				}).done(function(res) {
					console.log('uncheck');
					console.log(res);
				});
			}

		});

		$(document).on('click', '.deleteSlide', function(event) {
			event.preventDefault();
			/* Act on the event */
			if(confirm('Caution: Deleting this slide will remove it from all monitors. Do you wish to proceed?')){
				$.ajax({
					url      : '/cmsadmin/deleteSlide.php',
					type     : 'POST',
					dataType : 'json',
					data: {
						slideId : $(this).data('id')
					},
				}).done(function(res) {

					if(res.msg == 1 ){
						window.top.location.href = "/cmsadmin/index.php?admin-page=10"; 
					} else {
						alert('Something went wrong please try again');
					}

				});
			} else {
				alert('not confimrm');	
			}
		});

		// Init simpleupload
		var btn = document.getElementById('upload-btn'),
		    wrap = document.getElementById('pic-progress-wrap'),
		    picBox = document.getElementById('background-image-preview'),
		    errBox = document.getElementById('errormsg');

		var uploader = new ss.SimpleUpload({
		    button: btn,
		    url: 'upload_menu_board_bg.php',
		    sessionProgressUrl: '/<?php echo $admin_folder; ?>/includes/simple-ajax-uploader/extras/sessionProgress.php',
		    name: 'imgfile',
		    multiple: false,
		    allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
		    accept: 'image/*',
		    debug: true,
		    hoverClass: 'btn-hover',
		    focusClass: 'active',
		    disabledClass: 'disabled',
		    responseType: 'json',
		    onSubmit: function(filename, ext) {
		        var prog = document.createElement('div'),
		            outer = document.createElement('div'),
		            bar = document.createElement('div'),
		            size = document.createElement('div'),
		            self = this;

		        prog.className = 'prog';
		        size.className = 'size';
		        outer.className = 'progress';
		        bar.className = 'bar';

		        outer.appendChild(bar);
		        prog.appendChild(size);
		        prog.appendChild(outer);
		        wrap.appendChild(prog); // 'wrap' is an element on the page

		        self.setProgressBar(bar);
		        self.setProgressContainer(prog);
		        self.setFileSizeBox(size);

		        errBox.innerHTML = '';
		        btn.value = 'Choose another file';
		    },
		    onSizeError: function() {
		        errBox.innerHTML = 'Files may not exceed 500K.';
		    },
		    onExtError: function() {
		        errBox.innerHTML = 'Invalid file type. Please select a PNG, JPG, GIF image.';
		    },
		    onComplete: function(file, response) {
		        if (!response) {
		            errBox.innerHTML = 'Unable to upload file';
		        }
		        if (response.success === true) {
		            picBox.innerHTML = '<img src="/custom/images/menu-boards/' + response.file + '">';
		            $('#image_name').val(response.file);
		            $('#delete-image').show();
		            $('.image-as-bkgd-fields').show();
		            $('#image_as_bkgd').prop('checked', true);
		            toggleImageAsBackgroundContent();
		            saveForm();
		        } else {
		            if (response.msg) {
		                errBox.innerHTML = response.msg;
		            } else {
		                errBox.innerHTML = 'Unable to upload file';
		            }
		        }

		    }
		});

		$('#image_as_bkgd, #scroll_text, #scroll_position, #text_multiplier, #template').change(function() {
			saveForm();
		});
			<?php } ?>

		// Set up sortable lists
		$('.dd.available').nestable({
			maxDepth: 1,
			group: 1
		}).on('done', function(e, listItem, parentItem) {

			itemsUpdated(listItem, parentItem);
		});

		$('.dd.available.monitor_slides').nestable({
			maxDepth: 1,
			group: 1
		}).on('done', function(e, listItem, parentItem) {
			itemsUpdated(listItem, parentItem);
			var test = listItem.attr('data-item-id');
			$('#menu-boards-in-rotation .time_data').hide();
			$('#menu-boards-in-rotation .edit_monitor_slide').hide();

			saveForm_monitors();
		});

		$('.dd.column').nestable({
			maxDepth: 1,
			group: 1,

		}).on('done', function(e, listItem, parentItem) {
			itemsUpdated(listItem, parentItem);
			saveMenuBoard();
		});

		$('.menu-board-schedule-settings .dd.column').nestable({
			maxDepth: 1,
			group: 1,

		}).on('done', function(e, listItem, parentItem) {

			itemsUpdated(listItem, parentItem);
		});

		$('#menu-board-ads .dd.column').nestable({
			maxDepth: 1,
			group: 1,

		}).on('done', function(e, listItem, parentItem) {

			itemsUpdated(listItem, parentItem);
		});

		$(document).on('click', '.remove-category', function(e) {
			e.preventDefault();
			removeCategory($(this));
			return false;
		});

		$('#available-items h2').click(function(e) {
			expandList($(this).parent());
		});

		$('#num-columns').change(function() {
			updateNumColumns();
		});

		$('#delete-image').click(function() {
			deleteBgImage();
		});

		$('.choose-category-items select[name="category"]').change(function() {
			refreshCustomCategoryItem();
		});

		// Custom Categories
		$(document).on('click', '.add-category-item-btn', function() {
			var id = $(this).data('item-id');
			selectCategoryItem(id);
		});
		$(document).on('click', '.remove-selected-category-item', function() {
			var id = $(this).data('item-id');
			removeSelectedCategoryItem(id);
		});
		$('.cancel-custom-category').click(function() {
			cancelCustomCategory();
		});
		$('.save-custom-category').click(function() {
			saveCustomCategory();
		});
		$(document).on('click', '.edit-custom-category', function() {
			var listItem = $(this).parent('.dd-item');
			editCustomCategory(listItem);
		});

		$('#image_as_bkgd').change(function() {
			toggleImageAsBackgroundContent();
		});

		$('.delete-custom-category').click(function() {
			removeCustomCategory();
		});
	});

	function expandList(listObj) {
		var listContent = listObj.find('.dd');
		if (listContent.hasClass('expanded')) {
			listContent.slideUp(200).removeClass('expanded');
		} else {
			listContent.slideDown(200).addClass('expanded');
			$('#available-items .dd').each(function() {
				var id = $(this).parent().attr('id');
				if (id != listObj.attr('id')) {
					if ($(this).hasClass('expanded')) {
						$(this).slideUp(200).removeClass('expanded');
					}
				}
			});
		}
	}

	function updateNumColumns() {
		var numColumns = $('#num-columns').val();
		if (numColumns == $('#original-num-columns').val()) {
			return false;
		}

		saveMenuBoard(function() {
			window.location = '/cmsadmin/index.php?admin-page=8&slide=<?php echo $selected_board; ?>&num_columns='+numColumns;
		});
	}

	function itemsUpdated(listItem, parentItem) {
		initializeListItem(listItem, parentItem);
		checkForDuplicates();
		checkForEmptyBoards();
		if (listItem.data('item-id') == '9999' && !listItem.data('recordkey')) {
			createCustomCategory();
		} else {
			saveMenuBoard();
		}
	}

	function initializeListItem(listItem, parentItem) {
		checkIfOriginatedFromAvailableList(listItem, parentItem);

		// If list item was moved from a menu board to the available categories list, remove it
		if (parentItem.hasClass('available') && !listItem.hasClass('available-category') && !listItem.hasClass('available-slide') && !listItem.hasClass('available-widget')) {
			listItem.remove();
		}

		<?php if($is_monitor == 1) { ?>

			if (parentItem.hasClass('column') && listItem.find('.remove-icon').length < 1) {
				var newBoard = '';
				var schedule_board = listItem.attr('data-item-id');

				if (parentItem.hasClass('ads')) {
					//newBoard += '<input type="hidden" class="ads" name="ads[]" value="'+schedule_board+'">';
					listItem.append('<span class="edit_popUp_slide"><img src="images/gear-icon.png"></span><input type="hidden" class="ads" name="ads[]" value="'+schedule_board+'">');
				} else {
					if ($('.schedule-checkbox_monitor:checked').val() == 'use_schedule') {
						newBoard += '<input type="hidden" name="schedule_board" value="'+schedule_board+'">';
						newBoard += '<input type="hidden" name="schedule_hour" value="00">';
						newBoard += '<input type="hidden" name="schedule_minute" value="00">';
						newBoard += '<input type="hidden" name="schedule_meridiem" value="am">';
						newBoard += 'Menu Board '+schedule_board+'<span class="time_data"> - 00:00:am</span>';
						newBoard += '<input type="hidden" name="boards_in_rotation[]" value="'+schedule_board+'">';
						listItem.append('<span class="edit_monitor_slide"><img src="images/gear-icon.png"></span>');
					} else {
						newBoard += '<input type="hidden" name="boards_in_rotation[]" value="'+schedule_board+'">';
						newBoard += '<input type="hidden" name="schedule_board" value="'+schedule_board+'">';
					}
				}

				listItem.prepend(newBoard);

				listItem.append('<span class="remove-icon"><a class="remove-menu-board-in-monitor" href="#"><img src="../images/remove-icon.png" title="Remove from menu board"></a></span>');

			}

		<?php } else { ?>
		// If placed into a menu board, and doesn't have a delete button, add it
			if (parentItem.hasClass('column') && listItem.find('.remove-icon').length < 1) {
				if (listItem.data('item-id') == '9999') {
					listItem.append('<span class="edit-custom-category"><img src="images/gear-icon.png"></span>');
				} else {
					listItem.append('<span class="remove-icon"><a class="remove-category" href="#"><img src="../images/remove-icon.png" title="Remove from menu board"></a></span>');
				}
			}
		<?php } ?>
	}

	function checkIfOriginatedFromAvailableList(listItem, parentItem) {
		// If list item moved from available categories list to a menu board, 
		// make a copy of that list item and re-add it to the available 
		// categories in it's previous position
		if (!parentItem.hasClass('available-categories') && listItem.hasClass('available-category')) {
			var newListItem = listItem.clone();
			var itemNum = newListItem.data('item-num');
			if (itemNum == 1) {
				$('#ol-available-categories').prepend(newListItem);
			} else {
				var prevItemNum = itemNum - 1;
				$('#ol-available-categories').find('#available-category-'+prevItemNum).after(newListItem);
			}

			// Remove classes
			listItem.removeClass('new');
			listItem.removeClass('available-category');
			listItem.removeAttr('id');
		}

		if (!parentItem.hasClass('available-slides') && listItem.hasClass('available-slide')) {
			var newListItem = listItem.clone();
			var itemNum = newListItem.data('item-num');
			if (itemNum == 1) {
				$('#ol-available-slides').prepend(newListItem);
			} else {
				var prevItemNum = itemNum - 1;
				$('#ol-available-slides').find('#available-slide-'+prevItemNum).after(newListItem);
			}

			// Remove classes
			listItem.removeClass('new');
			listItem.removeClass('available-slide');
			listItem.removeAttr('id');
		}

		// Same for widgets
		if (!parentItem.hasClass('available-widgets') && listItem.hasClass('available-widget')) {
			var newListItem = listItem.clone();
			var itemNum = newListItem.data('item-num');
			if (itemNum == 1) {
				$('#ol-available-widgets').prepend(newListItem);
			} else {
				var prevItemNum = itemNum - 1;
				$('#ol-available-widgets').find('#available-widget-'+prevItemNum).after(newListItem);
			}

			// Remove classes
			listItem.removeClass('new');
			listItem.removeClass('available-widget');
			listItem.removeAttr('id');
		}

		customFormListItem = listItem;
	}

	function removeCategory(deleteButtonObj) {
		deleteButtonObj.closest('.dd-item').remove();
		checkForEmptyBoards();
		saveMenuBoard();
	}

	function removeCustomCategory() {
		if (!confirm('Are you sure you want to delete this category?')) {
			return false;
		}

		customFormListItem.remove();
		checkForEmptyBoards();
		saveMenuBoard();

		customFormListItem = null;
		customCategoryFormAction = null;

		disablePopup();
	}

	function checkForEmptyBoards() {
		$('.column').each(function() {
			if ($(this).find('.dd-list').length > 0 && $(this).find('.dd-item').length == 0) {
				$(this).find('.dd-list').remove();
				$(this).append('<div class="dd-empty"></div>');
			}
		});
	}

	function checkForDuplicates() {
		$('.column').each(function(i, menuBoard) {
			var categoryIds = [];
			var widgetIds = [];
			$(menuBoard).find('.dd-item').each(function(ii, listItem) {
				var id = $(listItem).data('item-id');
				if (id == 9999) {
					return 1;
				}
				if ($(listItem).data('type') == 'category') {
					if ($.inArray(id, categoryIds) > -1) {
						$(listItem).remove();
					} else {
						categoryIds.push(id);
					}
				}

				if ($(listItem).data('type') == 'widget') {
					if ($.inArray(id, widgetIds) > -1) {
						$(listItem).remove();
					} else {
						widgetIds.push(id);
					}
				}
			});
		});
	}

	function saveMenuBoard(onDoneCallback) {
		var boardNum = <?php echo $selected_board; ?>;
		//var show_descriptions = <? echo $_REQUEST['show_descriptions']; ?>;
		//alert ("triggered");
		var data = {
			board: boardNum,
			num_columns: $('#num-columns').val(),
			columns: {}
		};
		for (var i = 1; i <= <?php echo $numColumns; ?>; i++) {
			var items = [];
			var columnId = 'column-'+i;
			var column = $('#'+columnId);

			if (column.length > 0 && column.find('.dd-item').length > 0) {
				$.each(column.find('.dd-item'), function() {
					var item = {
						type: $(this).data('type'),
						id: $(this).data('item-id'),
						custom_name: $(this).data('custom-name'),
						custom_category_items: $(this).data('custom-category-items'),
						price_grid_format: $(this).data('price-grid-format')
					};
					items.push(item);
				});
			} else {
				items = null;
			}

			data['columns'][i] = items;
		}

		$.ajax({
			type: 'post',
			url: 'save_menu_board.php',
			data: data,
			dataType: 'json'
		}).done(function(response) {
			if (onDoneCallback && typeof(onDoneCallback) === "function") {
				onDoneCallback();
			}
		});
	}

	function deleteBgImage() {
		$('#image_name').val('');
		$('#image_as_bkgd').prop('checked', true);
		saveForm(function() {
			$('#background-image-preview').html('');
			$('#delete-image').hide();
			$('.image-as-bkgd-fields').hide();
			toggleImageAsBackgroundContent();
		});
	}


	function saveForm_monitors(onDoneCallback) {
		var boardNum = <?php echo $selected_board; ?>;
		var monitor_name =  $('#monitor_name').val();

		var data = {
			board: boardNum,
			image_name: '',
			scroll_text: '',
			scroll_position: '',
			text_multiplier: '',
			bkgd_color: '',
			template: '',
			monitor_name : monitor_name,
			isMonitor : 1,
			ad_interval: $('select[name="ad_interval"]').val(),
			ad_duration: $('select[name="ad_duration"]').val()
		}

		//if ($('#image_as_bkgd').prop('checked')) {
			data['image_as_bkgd'] = 1;
		//}

		if ($('.schedule-checkbox_monitor:checked').length > 0) {
			data['schedule'] = $('.schedule-checkbox_monitor:checked').val();
		}

		if($('.schedule-checkbox_monitor:checked').val() == 'use_schedule'){
			var i = 0;
			var j = 0;

			$('input[name="boards_in_rotation[]"').each(function() {

				data['boards_in_schedule['+j+'][board]'] = $(this).val();
				j++;

			});
			$('#time-schedule-settings .dd-list .dd-item').each(function() {
				//data['boards_in_schedule['+i+'][board]'] = $(this).find('input[name="schedule_board"]').val();

				data['boards_in_schedule['+i+'][hour]'] = $(this).find('input[name="schedule_hour"]').val();
				data['boards_in_schedule['+i+'][minute]'] = $(this).find('input[name="schedule_minute"]').val();
				data['boards_in_schedule['+i+'][meridiem]'] = $(this).find('input[name="schedule_meridiem"]').val();
				i++;
			});
		}else{
			var k = 0;
			data['boards_in_rotation'] = new Array();
			$('input[name="schedule_board"').each(function() {
				data['boards_in_rotation['+k+']'] = $(this).val();
				k++;
				//data['boards_in_rotation'].push($(this).find('input[name="schedule_board"]').val());
			});

		}

		data['ads'] = [];

		$('input[name="ads[]"]').each(function() {
			data['ads'].push($(this).val());
		});

		$.ajax({
			type: 'post',
			url: 'save_menu_board_settings.php',
			data: data,
			dataType: 'json'
		}).done(function(response) {
			if (response.hasOwnProperty('result') && response.result == 1) {
				if (onDoneCallback && typeof(onDoneCallback) === "function") {
					onDoneCallback();
				}
			} else {
				var message = 'Error saving menu board';
				if (response.hasOwnProperty('message') && response.message.length > 0) {
					message += ': ' + response.message;
				} else {
					message += '.';
				}
				alert(message);
			}
		});
	}


	function saveForm(onDoneCallback) {
		var boardNum = <?php echo $selected_board; ?>;
		var monitor_name =  $('#monitor_name').val();

		var data = {
			board: boardNum,
			image_name: $('#image_name').val(),
			scroll_text: $('#scroll_text').val(),
			scroll_position: $('#scroll_position').val(),
			text_multiplier: $('#text_multiplier').val(),
			bkgd_color: $('#bkgd_color').val(),
			template: $('#template').val(),
			monitor_name: monitor_name
		}

		if ($('#image_as_bkgd').prop('checked')) {
			data['image_as_bkgd'] = 1;
		}

		if ($('.schedule-checkbox:checked').length > 0) {
			data['schedule'] = $('.schedule-checkbox:checked').val();
		}

		data['boards_in_rotation'] = new Array();
		$('input[name="boards_in_rotation[]"').each(function() {
			data['boards_in_rotation'].push($(this).val());
		});

		var i = 0;
		$('.menu-board-in-schedule').each(function() {
			data['boards_in_schedule['+i+'][board]'] = $(this).find('input[name="schedule_board"]').val();
			data['boards_in_schedule['+i+'][hour]'] = $(this).find('input[name="schedule_hour"]').val();
			data['boards_in_schedule['+i+'][minute]'] = $(this).find('input[name="schedule_minute"]').val();
			data['boards_in_schedule['+i+'][meridiem]'] = $(this).find('input[name="schedule_meridiem"]').val();
			i++;
		});

		$.ajax({
			type: 'post',
			url: 'save_menu_board_settings.php',
			data: data,
			dataType: 'json'
		}).done(function(response) {
			if (response.hasOwnProperty('result') && response.result == 1) {
				if (onDoneCallback && typeof(onDoneCallback) === "function") {
					onDoneCallback();
				}
			} else {
				var message = 'Error saving menu board';
				if (response.hasOwnProperty('message') && response.message.length > 0) {
					message += ': ' + response.message;
				} else {
					message += '.';
				}
				alert(message);
			}
		});
	}

	function createCustomCategory() {
		clearCustomCategoryForm();
		refreshCustomCategoryItem();
		$('#popup_custom_category h2').text('Edit Custom Category');
		openPopup('custom_category');
		customCategoryFormAction = 'add';
	}

	function refreshCustomCategoryItem() {
		var categoryId = $('.choose-category-items select[name="category"]').val();

		$.ajax({
			type: 'post',
			url: 'get_menu_category_item.php',
			data: {action: 'get_items_in_category', category: categoryId},
			dataType: 'json'
		}).done(function(response) {
			if (response.hasOwnProperty('result') && response.result == 1 && response.hasOwnProperty('items')) {
				populateCategoryItemList(response.items);
			} else {
				alert('Error getting category items.');
				console.log(response);
			}
		});
	}

	function populateCategoryItemList(items) {
		var list = '';
		$.each(items, function() {
			list += '<div class="category-item">'+this.itemName+' <button class="add-category-item-btn" type="button" data-item-id="'+this.itemKey+'">Add</button></div>';
		});

		$('#category-items-list').html(list);
	}

	function selectCategoryItem(id) {
		$.ajax({
			type: 'post',
			url: 'get_menu_category_item.php',
			data: {action: 'get_item', id: id},
			dataType: 'json'
		}).done(function(response) {
			if (response.hasOwnProperty('result') && response.result == 1 && response.hasOwnProperty('item')) {
				addSelectedCategoryItem(response.item);
			} else {
				alert('Error getting category item.');
				console.log(response);
			}
		});
	}

	function addSelectedCategoryItem(item) {
		var content = '';
		content += '<div class="selected-category" id="selected-category-item-'+item.itemKey+'" data-item-id="'+item.itemKey+'">';
		content += item.itemName;
		content += ' <button class="remove-selected-category-item" data-item-id="'+item.itemKey+'">Remove</button>';
		content += '</div>';

		$('.selected-categories-list').append(content);
	}

	function removeSelectedCategoryItem(id) {
		$('#selected-category-item-'+id).remove();
	}

	function clearCustomCategoryForm() {
		$("#custom-category-form input[type='text']").val('');
		$("#custom-category-form input[type='checkbox']").prop('checked', 0);
		$("#custom-category-form input").val('');
		$('.selected-categories-list').html('');
	}

	function cancelCustomCategory() {
		disablePopup();
		clearCustomCategoryForm();
		if (customFormListItem && customFormListItem == 'add') {
			customFormListItem.remove();
			checkForEmptyBoards();
		}
		customFormListItem = null;
		customCategoryFormAction = null;
	}
	function saveCustomCategory() {
		var name = $('#custom-category-form input[name="name"]').val();

		// Check if name was entered
		if (name.length < 1) {
			alert('Please enter a name.');
			$('#custom-category-form input[name="name"]').focus();
			return false;
		}

		// Check if categories selected
		if ($('.selected-category').length < 1) {
			alert('Please select category items.');
			return false;
		}

		var items = [];

		$('.selected-category').each(function() {
			items.push($(this).data('item-id'));
		});

		items = items.join();

		// Price grid format
		var priceGridFormat = 0;
		if ($('#custom-category-form input[name="price_grid_format"]').prop('checked')) {
			priceGridFormat = 1;
		}

		$(customFormListItem).data('custom-name', name);
		$(customFormListItem).data('custom-category-items', items);
		$(customFormListItem).data('price-grid-format', priceGridFormat);
		$(customFormListItem).find('.dd-handle').html(name + ' <span style="font-size:.8em;font-style:italic;color:red;">(Custom)</span>');

		var editIcon = '<span class="edit-custom-category">';
		editIcon += '<img src="images/gear-icon.png">';
		editIcon += '</span>';

		$(customFormListItem).find('.dd-handle').after(editIcon);

		saveMenuBoard();

		disablePopup();
		clearCustomCategoryForm();
		customCategoryFormAction = null;
	}
	function editCustomCategory(listItem) {
		var name = $(listItem).data('custom-name');
		var priceGridFormat = listItem.data('price-grid-format');
		var selectedCategoryItems = listItem.data('custom-category-items');

		$('#popup_custom_category h2').text('Edit Custom Category');
		$('#custom-category-form input[name="name"]').val(name);
		if (priceGridFormat) {
			$('#custom-category-form input[name="price_grid_format"]').prop('checked', true);
		} else {
			$('#custom-category-form input[name="price_grid_format"]').prop('checked', false);
		}
		fillSelectedCategoryItemsFromIds(selectedCategoryItems);
		refreshCustomCategoryItem();

		openPopup('custom_category');
		customCategoryFormAction = 'edit';
		customFormListItem = listItem;
	}

	function fillSelectedCategoryItemsFromIds(ids) {
		$('.selected-categories-list').html('');
		$.ajax({
			type: 'post',
			url: 'get_menu_category_item.php',
			data: {action: 'get_items', ids: ids},
			dataType: 'json'
		}).done(function(response) {
			if (response.hasOwnProperty('result') && response.result == 1 && response.hasOwnProperty('items')) {
				$.each(response.items, function(i, item) {
					addSelectedCategoryItem(item);
				});
			} else {
				alert('Error getting category items.');
				console.log(response);
			}
		});
	}

	function toggleImageAsBackgroundContent() {
		var isChecked = $('#image_as_bkgd').prop('checked');
		var hasImage = ($('#image_name').val().length > 0) ? true : false;


		if (isChecked || !hasImage) {
			$('.image-note-enabled').show();
			$('.image-note-disabled').hide();
			$('#widgets-wrapper').show();
		} else {
			$('.image-note-enabled').hide();
			$('.image-note-disabled').show();
			$('#widgets-wrapper').hide();
		}
	}

	// Scroll to view
	var totalHeight = $('#content-one-column').height();
	<?php if($is_slide){ ?>
	function scrollToView() {
		var scrollingDiv = $("#menu-board");
		var margin = $(window).scrollTop();
		var iframeTop = $("#menu-board").position().top - 10;

		if(margin - iframeTop < 0) {
			margin = 0;
		} else {
			margin = margin - iframeTop;
		}
		if (margin < 15) {
			margin = 15;
		}

		if ((margin+scrollingDiv.height()) > totalHeight) {
			margin = totalHeight - scrollingDiv.height() + 55;
		}
		scrollingDiv
			.stop()
			.animate({"marginTop": margin + "px"}, 200 );
	}
	<?php } ?>
	function check(show_descriptions){
	    var cer=document.getElementById("show_descriptions").checked;
	    if(cer){

			//alert("checked");
		    window.location = '?admin-page=8&slide=<?php echo $selected_board; ?>&show_descriptions=yes';
	    } else {
	    	//alert("unchecked");
				window.location = '?admin-page=8&slide=<?php echo $selected_board; ?>&show_descriptions=no';
	    }
	}


	function toggle(show_item_descriptions){
	    var cer=document.getElementById("show_item_descriptions").checked;
	    if(cer){
	        //alert("checked");
				window.location = '?admin-page=8&slide=<?php echo $selected_board; ?>&show_item_descriptions=yes';
	    } else {
	    	//alert("unchecked");
				window.location = '?admin-page=8&slide=<?php echo $selected_board; ?>&show_item_descriptions=no';
	    }
	}


	/** Menu Board Schedule Scripts **/
	var boardsInScheduleNum = 0;
	var scheduleBoardEditing;
	$(document).ready(function() {
		showSelectedScheduleOptions();
		showSelectedScheduleOptions_monitor();

		$('.schedule-checkbox').change(function() {
			if ($(this).attr('value') == 'use_schedule') {
				$('.schedule-checkbox[value="toggle_boards"]').prop('checked', false);
			} else {
				$('.schedule-checkbox[value="use_schedule"]').prop('checked', false);
			}

			showSelectedScheduleOptions();

			saveForm();

		});

		$('.schedule-checkbox_monitor').change(function() {
			if ($(this).attr('value') == 'use_schedule') {
				$('.schedule-checkbox_monitor[value="toggle_boards"]').prop('checked', false);
			} else {
				$('.schedule-checkbox_monitor[value="use_schedule"]').prop('checked', false);
			}

			showSelectedScheduleOptions_monitor();
		});

		$('.menu-board-settings :input').not('#transSchedule').not('#transSchedulePop').change(function() {
			saveForm_monitors();
		});

		$('#add-board-to-rotation').click(function() {
			addBoardToRotation();
		});

		$(document).on('click', '.remove-menu-board-in-rotation', function() {
			$(this).closest('.menu-board-in-rotation').remove();
			saveForm();
		});

		$(document).on('click', '.remove-menu-board-in-schedule', function() {
			$(this).closest('.menu-board-in-schedule').remove();
			saveForm();
		});

		$(document).on('click', '.edit-menu-board-in-schedule', function() {
			scheduleBoardEditing = $(this).closest('.menu-board-in-schedule');
			editMenuBoardInSchedule();
		});

		$(document).on('click', '.edit_monitor_slide', function() {

			scheduleBoardEditing = $(this).closest('.dd-item');
			editMenuBoardInSchedule();
		});

		$(document).on('click', '.edit_popUp_slide', function(e) {
			
			//alert($(this).next('.ads').val());
			e.preventDefault();
			
			if($(this).next('.ads').val()==undefined){
				//$('#thisboardNo').val($(this).before('.ads').val());
			}else{
		       $('#thisboardNo').val($(this).next('.ads').val());
		    }
		        //$('#thisboardNo1').val($(this).next('.ads').val());
			    $.ajax({

	            url: "save_trans_val.php",
	            type: "POST",
	            dataType: 'json',
	            data: {
	                check_display_board : $('#thisboardNo').val(),
	                check_board_number  : $('#boardNo').val(),
	            },
	            success:function(data)
	            {
	            	var hours=data.hours;
	            	var min=data.min;
	            	var meridiem = data.meridiem;
	            	$('#ad_interval_new option[value="' + hours + '"]').prop('selected', true);
					$('#ad_duration_new option[value="' + min + '"]').prop('selected', true);
					$('#popup-meridiem option[value="' + meridiem + '"]').prop('selected', true);
	            	$('#trigger-edit-popup-modal').click();
	             }
            });
			
		});

		$(document).on('click', '.remove-menu-board-in-monitor', function() {
			$(this).closest('.dd-item').remove();

			if (! $(this).closest('.dd').hasClass('ads')) {
				var current_click = $(this).closest('.dd-item').attr('data-item-num');
				$(document).find(".column.dd [data-item-num='" + current_click + "']").remove();
			}
			//$('*[data-item-num="+'current_click'+"]').remove();
			saveForm_monitors();
		});


		$('#add_menu_board_to_schedule_modal').popup();
		$('#edit_menu_board_to_schedule_modal').popup();
		$('#edit_menu_board_modal').popup();
	});

	function showSelectedScheduleOptions() {
		if ($('.schedule-checkbox:checked').length > 0) {
			if ($('.schedule-checkbox:checked').val() == 'use_schedule') {
				$("#time-schedule-settings").show();
				$("#rotation-schedule-settings").hide();
			} else {
				$("#time-schedule-settings").hide();
				$("#rotation-schedule-settings").show();
			}
		} else {
			// None selected, hide both
			$("#time-schedule-settings").hide();
			$("#rotation-schedule-settings").hide();
		}
	}

	function showSelectedScheduleOptions_monitor() {
		if ($('.schedule-checkbox_monitor:checked').length > 0) {
			if ($('.schedule-checkbox_monitor:checked').val() == 'use_schedule') {
				$("#time-schedule-settings").show();
				$("#rotation-schedule-settings").hide();
			} else {
				$("#time-schedule-settings").hide();
				$("#rotation-schedule-settings").show();
			}
		} else {
			// None selected, hide both
			$("#time-schedule-settings").hide();
			$("#rotation-schedule-settings").hide();
		}
	}
	function addBoardToRotation() {
		var selectedBoard = $('#select-menu-board-rotation').val();

		var newBoard = '<div class="menu-board-in-rotation">';
		newBoard += '<input type="hidden" name="boards_in_rotation[]" value="'+selectedBoard+'">';
		newBoard += 'Menu Board ' + selectedBoard;
		newBoard += ' <button class="remove-menu-board-in-rotation" type="button">Remove</button>';
		newBoard += '</div>';

		$('#menu-boards-in-rotation').append(newBoard);

		saveForm();
	}
	function addMenuBoardToSchedule() {
		var board = $('#add-to-schedule-board').val();
		var hour = $('#add-to-schedule-hour').val();
		var minute = $('#add-to-schedule-minute').val();
		var meridiem = $('#add-to-schedule-meridiem').val();

		var newBoard = '<div class="menu-board-in-schedule">';
		newBoard += '<input type="hidden" name="schedule_board" value="'+board+'">';
		newBoard += '<input type="hidden" name="schedule_hour" value="'+hour+'">';
		newBoard += '<input type="hidden" name="schedule_minute" value="'+minute+'">';
		newBoard += '<input type="hidden" name="schedule_meridiem" value="'+meridiem+'">';
		newBoard += 'Menu Board '+board+' - '+hour+':'+minute+' '+meridiem;
		newBoard += ' <button class="edit-menu-board-in-schedule edit_menu_board_to_schedule_modal_open" type="button">Edit</button>';
		newBoard += ' <button class="remove-menu-board-in-schedule" type="button">Remove</button>';
		newBoard += '</div>';

		boardsInScheduleNum++;

		$('#menu-boards-in-schedule').append(newBoard);

		saveForm();
		$('#edit_menu_board_to_schedule_modal').popup();
	}


	function addMenuBoardToScheduleMonitor() {
		var board = $('#add-to-schedule-board').val();
		var hour = $('#add-to-schedule-hour').val();
		var minute = $('#add-to-schedule-minute').val();
		var meridiem = $('#add-to-schedule-meridiem').val();

		var newBoard = '<li class="dd-item" data-type="slides" data-item-id="'+board+'" data-item-num="">';
		newBoard += '<input type="hidden" name="schedule_board" value="'+board+'">';
		newBoard += '<input type="hidden" name="schedule_hour" value="'+hour+'">';
		newBoard += '<input type="hidden" name="schedule_minute" value="'+minute+'">';
		newBoard += '<input type="hidden" name="schedule_meridiem" value="'+meridiem+'">';
		newBoard += 'Menu Board '+board+' - '+hour+':'+minute+' '+meridiem;
		newBoard += ' <span class="edit_monitor_slide"><img src="images/gear-icon.png"></span>';
		newBoard += ' <span class="remove-icon"><a class="remove-menu-board-in-monitor" href="#"><img src="../images/remove-icon.png" title="Remove from menu board"></a></span>';
		newBoard += '</div>';

		boardsInScheduleNum++;

		$('#menu-boards-in-schedule').append(newBoard);

		saveForm_monitors();
		//$('#edit_menu_board_to_schedule_modal').popup();
	}

	 function updateMenuBoardMonitor() {
		
		var ad_interval = $('#ad_interval_new').val();
		var ad_duration = $('#ad_duration_new').val();
		var popup_meridiem = $('#popup-meridiem').val();
		var display_board= $('#thisboardNo').val();
		var board_number= $('#boardNo').val();
		
		$.ajax({

            url: "save_trans_val.php",
            type: "POST",
            data: {
                ad_interval   : ad_interval,
                ad_duration   : ad_duration,
                popup_meridiem: popup_meridiem,
                display_board : display_board,
                board_number  : board_number
            },
            success:function()
            {
              $("#edit_menu_board_modal").fadeOut();
		      window.location.reload();
		    }
        });
	}

	function updateMenuBoardToScheduleMonitor() {
		var board = $('#edit-schedule-board').val();
		var hour  = $('#edit-schedule-hour').val();
		var minute = $('#edit-schedule-minute').val();
		var meridiem = $('#edit-schedule-meridiem').val();

		newBoard = '';
		newBoard += '<input type="hidden" name="schedule_board" value="'+board+'">';
		newBoard += '<input type="hidden" name="schedule_hour" value="'+hour+'">';
		newBoard += '<input type="hidden" name="schedule_minute" value="'+minute+'">';
		newBoard += '<input type="hidden" name="schedule_meridiem" value="'+meridiem+'">';
		newBoard += 'Menu Board '+board+' - '+hour+':'+minute+' '+meridiem;
		newBoard += ' <span class="edit_monitor_slide"><img src="images/gear-icon.png"></span>';
		newBoard += ' <span class="remove-icon"><a class="remove-menu-board-in-monitor" href="#"><img src="../images/remove-icon.png" title="Remove from menu board"></a></span>';

		scheduleBoardEditing.html(newBoard);
		saveForm_monitors();
	}


	function updateMenuBoardToSchedule() {
		var board = $('#edit-schedule-board').val();
		var hour = $('#edit-schedule-hour').val();
		var minute = $('#edit-schedule-minute').val();
		var meridiem = $('#edit-schedule-meridiem').val();

		newBoard = '';
		newBoard += '<input type="hidden" name="schedule_board" value="'+board+'">';
		newBoard += '<input type="hidden" name="schedule_hour" value="'+hour+'">';
		newBoard += '<input type="hidden" name="schedule_minute" value="'+minute+'">';
		newBoard += '<input type="hidden" name="schedule_meridiem" value="'+meridiem+'">';
		newBoard += 'Menu Board '+board+' - '+hour+':'+minute+' '+meridiem;
		newBoard += ' <button class="edit-menu-board-in-schedule" type="button">Edit</button>';
		newBoard += ' <button class="remove-menu-board-in-schedule" type="button">Remove</button>';

		scheduleBoardEditing.html(newBoard);
	}
	function editMenuBoardInSchedule() {

		var boardNum = scheduleBoardEditing.find('input[name="schedule_board"]').val();
		var hour = scheduleBoardEditing.find('input[name="schedule_hour"]').val();
		var minute = scheduleBoardEditing.find('input[name="schedule_minute"]').val();
		var meridiem = scheduleBoardEditing.find('input[name="schedule_meridiem"]').val();
		$('#edit-schedule-board').val(boardNum);
		$('#edit-schedule-hour').val(hour);
		$('#edit-schedule-minute').val(minute);
		$('#edit-schedule-meridiem').val(meridiem);

		$('#trigger-edit-schedule-modal').click();
	}
/** End Menu board schedule scripts **/

</script>
<style type="text/css">
	<?php
	if($is_slide == 1){
		?>
		.menu-boards-schedule{
			display: none;
		}
		<?php
	}
if($is_monitor == 1){
	?>
	.dd-list li .remove-icon {
position: absolute;
right: 20px !important;
top: 7px;
}

.edit_monitor_slide {
position: absolute;
right: 50px !important;
top: 6px;
}
#menu-boards-in-schedule .dd-handle {
display: none;
}
#menu-boards-in-schedule  li.dd-item,#menu-boards-in-rotation li.dd-item{
line-height: 33px;
}

#available-items {
 width: 28%;
}
.monitor_schedule_wrapper {
background: #2077A1;
overflow: auto;
padding: 10px 34px;
margin-top: 11px;
border: 1px solid #cccfd2;
border-radius: 15px;
}
.monitor_schedule_wrapper h3,.monitor_schedule_wrapper label {
color: #fff !important;
}
	<?php
}
?>

</style>
<script type="text/javascript">
  $(document).ready(function() {

      
      $('#transSchedule').on('change',function(){
       
        $.ajax({

            url: "save_trans_val.php",
            type: "POST",
            data: {
                transSchedule: $("#transSchedule").val(),
                recKey       : $('#recKey').val(),
            }
        });
      
      });
      $('#transSchedulePop').on('change',function(){
        
        $.ajax({

            url: "save_trans_val.php",
            type: "POST",
            data: {
                transSchedulePop: $("#transSchedulePop").val(),
                recKey       : $('#recKey').val(),
            }
        });
      
      });

      $('#dayofweek').on('change',function(){
        $.ajax({

            url: "save_trans_val.php",
            type: "POST",
            data: {
                dayofweek: $("#dayofweek").val(),
                recKey       : $('#recKey').val(),
            }
        });
      
      });

      $("#start-meridiem").on('change', function() {
			$('#starttime').trigger('change');
	  });
      $('#starttime').on('change',function(){
      	
      	var start_meridiem=$("#start-meridiem").val();

	    $.ajax({

            url: "save_trans_val.php",
            type: "POST",
            data: {
                starttime     : $("#starttime").val(),
                recKey        : $('#recKey').val(),
                start_meridiem: start_meridiem,
            }
         });
      
      });

      $("#end-meridiem").on('change', function() {
			$('#endtime').trigger('change');
	  });
      $('#endtime').on('change',function(){

      	var end_meridiem=$("#end-meridiem").val();
	    
	        $.ajax({

	            url: "save_trans_val.php",
	            type: "POST",
	            data: {
	                endtime       : $("#endtime").val(),
	                recKey        : $('#recKey').val(),
	                end_meridiem  : end_meridiem,
	            }
	        });
       });
});
</script>


<div style="clear: both;">&nbsp;</div>
			  <div style="text-align:center;"><?php echo $bottom_links; ?></div>