<?php

//error_reporting(E_ALL);
//echo "test";
?>


 <!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
     <title><?= $config['CompanyName'] ?></title>
 
     <!-- Bootstrap -->
     <link href="../css/bootstrap.min.css" rel="stylesheet">
     <link rel="stylesheet" href="../css/bootstrap-combobox.css" />
 
     <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
     <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
     <!--[if lt IE 9]>
       <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
       <script src="../js/functions.js"></script>
       <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
       <script src="../js/functions.js"></script>
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
           <!-- Include all compiled plugins (below), or include individual files as needed -->
           <script src="../js/bootstrap.min.js"></script>
       	 <script src="../js/bootstrap-combobox.js"></script>
       	 <script src="../js/excellentexport.js"></script>
           <script type="text/javascript">
             $(document).ready(function(){
             
             });
           </script>
					<link rel="stylesheet" href="../css/jquery.filthypillow.css" type="text/css" />
					<script src="../js/jquery.filthypillow.min.js" type="text/javascript"></script>
					<script src="../js/moment.js" type="text/javascript"></script>
     <![endif]-->
	<link rel="stylesheet" href="../css/styles.css"/>
   </head>
   <body>
<?php 
	include("navbar.php");
?>
        <br /><br /><br /><br /><br />
   <!-- Stack the columns on mobile by making one full-width and the other half-width -->
    
	<div class="container" style="padding-top: 10px;">
		<link href="../css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
		<script src="../js/fileinput.js" type="text/javascript"></script>
		
		<div class="panel panel-default">
			<div class="panel-heading form-inline">
				<a class="btn btn-success" role="button" style="float: right;" href="#" download="Billboards<?= "(" . date("m.d.Y") . ")" ?>.xls" href="#" onclick="return ExcellentExport.excel(this, 'catalog', 'Catalog');" data-toggle="tooltip" data-placement="left" title="Does not work with Internet Explorer">Export To Excel</a>
				<div style="margin-right: 10px; float: right;">
					<div class="input-group">
						<div id="clearButton" style="display: none;" class="input-group-addon" onclick="clearFilter()">
							<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
						</div>
						<input type="text"   class="form-control" name="filter" placeholder="Filter" value="" />
						<div class="input-group-addon" onclick="filter()">
							<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
						</div>
					</div>
					<button class="btn btn-primary" onclick="addBillboard()" >Add New Billboard</button>
				</div>
				<h3 class="panel-title">Billboards</h3>
				<small>Click on a row to edit the Item</small>
			</div>
			<div class="panel-body">
				<table class="table table-hover">
					<thead>
						<tr>
							<th>Title</th>
							<th>Type</th>
							<th>Position</th>
							<th>Active</th>
						</tr>
					</thead>
					<tbody>
						<?php 
						 $query = "SELECT * FROM `BILLBOARD` ORDER BY Title ASC";
						 $result = mysqli_query($con, $query);
						 while ($row = mysqli_fetch_array($result)) {
							if($row['Position'] == -1){
								$position = 'Dropdown';
							}elseif($row['Position'] == 0){
								$position = 'None';
							}else{
								$position = $row['Position'];
							}
						?>
							 <tr onclick="editBillboard('<?= $row['ID'] ?>')">
								 <td><?= $row['Title'] ?></td>
								 <td><?= $row['Type'] ?></td>
								 <td><?= $position ?></td>
								 <td><?= $row['Active']?"True":"False" ?></td>
								 <!--  -->
							 </tr>
						<?php		
						 }
						 ?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	
	
	<div class="container " style="padding-top: 10px;">
	<div class="panel panel-default">
		<div class="panel-heading form-inline">
			
		   	<h3 class="panel-title">Billboard Positions</h3>
		   	<small>Click on a row to edit the Item</small>
		 </div>
		 <div class="panel-body">
		 	<table class="table table-hover">
		   		<thead>
			   		<tr>
				   		<th>Position</th>
				   		<th>Title</th>
							<th>Start Date</th>
							<th>End Date</th>
					</tr>
		   		</thead>
		   		<tbody>
		  <?php
			$positions = array();
		   $query = "SELECT * FROM `BILLBOARD` WHERE Position != 0 ORDER BY Position ASC";
		   $result = mysqli_query($con, $query);
		   while ($row = mysqli_fetch_array($result)) {
					$positions[$row['Position']] = new Billboard($row['ID']);
			 }
		  ?>
			   <tr onclick="editBillboardPosition('-1', <?php echo isset($positions['-1'])?$positions['-1']->ID:0 ?>)">
				   <td>Dropdown</td>
				   <td><?= isset($positions['-1'])?$positions['-1']->Title:"None" ?></td>
				   <td><?= isset($positions['-1'])?date("m/d/Y h:i A", strtotime($positions['-1']->StartDate)):"None" ?></td>
					 <td><?= isset($positions['-1'])?date("m/d/Y h:i A", strtotime($positions['-1']->EndDate)):"None" ?></td>
				   <!--  -->
			   </tr>
				 <tr onclick="editBillboardPosition('1', <?php echo isset($positions['1'])?$positions['1']->ID:0; ?>)">
				   <td>1</td>
				   <td><?= isset($positions['1'])?$positions['1']->Title:"None" ?></td>
					 <td><?= isset($positions['1'])?date("m/d/Y h:i A", strtotime($positions['1']->StartDate)):"None" ?></td>
					 <td><?= isset($positions['1'])?date("m/d/Y h:i A", strtotime($positions['1']->EndDate)):"None" ?></td>
				   
				   <!--  -->
			   </tr>
				 <tr onclick="editBillboardPosition('2', <?php echo isset($positions['2'])?$positions['2']->ID:0; ?>)">
				   <td>2</td>
				   <td><?= isset($positions['2'])?$positions['2']->Title:"None" ?></td>
					 <td><?= isset($positions['2'])?date("m/d/Y h:i A", strtotime($positions['2']->StartDate)):"None" ?></td>
					 <td><?= isset($positions['2'])?date("m/d/Y h:i A", strtotime($positions['2']->EndDate)):"None" ?></td>
				   
				   <!--  -->
			   </tr>
				 <tr onclick="editBillboardPosition('3', <?php echo isset($positions['3'])?$positions['3']->ID:0; ?>)">
				   <td>3</td>
				   <td><?= isset($positions['3'])?$positions['3']->Title:"None" ?></td>
					 <td><?= isset($positions['3'])?date("m/d/Y h:i A", strtotime($positions['3']->StartDate)):"None" ?></td>
					 <td><?= isset($positions['3'])?date("m/d/Y h:i A", strtotime($positions['3']->EndDate)):"None" ?></td>
				   
				   <!--  -->
			   </tr>
		  	</tbody>
		   </table>
		 </div>
	</div>
</div>
	   
	   <div class="modal fade" id="AddEditBillboard">
		 <div class="modal-dialog">
		   <div class="modal-content">
			 <div class="modal-header">
			   <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			   <h4 class="modal-title" id="AddEditTitle">Edit Billboard Item</h4>
			 </div>
			 <div class="modal-body">
			   <form class="catalogItem">
				   <input type="hidden" id="isNew" name="isNew" value="" />
				   <input type="hidden" id="BillboardID" name="BillboardID" value="" />
				   <div class="form-group">
					   <label for="BillboardTitle">Title</label>
						 <input class="form-control" id="BillboardTitle" name="BillboardTitle" />
				   </div>
					 <div class="form-group" id="BillboardButtonDiv" >
							<div id="imageButtonPreviewDiv" style="height: 150px; text-align: center; vertical-align: middle;" id="">
								<img id="imageButtonPreview" style="max-height: 100%; max-width: 100%;"src="" alt="" />
							</div>
							<div class="alert alert-info" style="display: none;" id="uploadButtonSuccess" role="alert">
								File has been uploaded successfully!
							</div>
						 
					   <label for="BillboardButtonImage">Button Image</label>
					   <input type="file" class="file form-control" name="BillboardButtonImage" autocomplete="off" id="BillboardButtonImage">
				   </div>
				   <div class="form-group">
					   <label for="BillboardType">Type</label>
					   <select id="BillboardType" class="form-control">
								<option value="image">Image</option>
								<option value="pdf">PDF</option>
								<option value="special">Special</option>
								<option value="video">Video</option>
						 </select>
				   </div>
				   
					 <div class="form-group" id="BillboardVideoDiv" style="display: none;">
					   <div id="videoPreviewDiv" style="height: 150px; text-align: center; vertical-align: middle;" id="">
						   <iframe id="videoPreview"  src="" frameborder="0" allowfullscreen="0"></iframe>
					   </div>
					   
					   <label for="BillboardVideo">Youtube Video ID<small> Ex. https://www.youtube.com/watch?v=<strong><mark>pjgj5EyTvs8</mark></strong></small></label>
					   <input type="text" class="form-control" name="BillboardVideo" autocomplete="off" id="BillboardVideo" placeholder="pjgj5EyTvs8">
						 <button class="btn btn-primary" onclick="loadVideoPreview()" type="button">Preview</button>
						 <button class="btn btn-danger" onclick="clearVideoPreview()" type="button">Clear</button>
				   </div>
					 
					 
					 
				   <div class="form-group" id="BillboardImageDiv" >
							<div id="imagePreviewDiv" style="height: 150px; text-align: center; vertical-align: middle;" id="">
								<img id="imagePreview" style="max-height: 100%; max-width: 100%;"src="" alt="" />
							</div>
							<div class="alert alert-info" style="display: none;" id="uploadSuccess" role="alert">
								File has been uploaded successfully!
							</div>
						 
					   <label for="BillboardImage">Image</label>
					   <input type="file" class="file form-control" name="BillboardImage" autocomplete="off" id="BillboardImage">
				   </div>
					 
					 <div class="form-group" id="BillboardPDFDiv" style="display: none;">
							<div id="pdfPreviewDiv" style="height: 220px; text-align: center; vertical-align: middle;" id="">
								<iframe id="pdfPreview" style="height: 220px; width: 100%;"src="" alt=""></iframe>
							</div>
							<div class="alert alert-info" style="display: none;" id="uploadSuccess" role="alert">
								File has been uploaded successfully!
							</div>
						 
					   <label for="BillboardPDF">PDF</label>
					   <input type="file" class="file form-control" name="BillboardPDF" autocomplete="off" id="BillboardPDF">
				   </div>
					 
					 <div class="form-group">
					 <label for="BillboardText">Text To Display Bellow Image</label>
					   <input type="text" class="form-control" name="BillboardText" autocomplete="off" id="BillboardText" placeholder="Haga Click aqui para comprar...">
					 </div>
					 <div class="form-group">
					 <label for="BillboardLink">Link for the Text</label>
					   <input type="text" class="form-control" name="BillboardLink" autocomplete="off" id="BillboardLink" value="?line=&group=&sku=" placeholder="http://orders.empresasvelazquez.com/">
					 </div>
					 
					 <div class="form-group">
					 <label for="BillboardStartDate">Start Date</label>
					   <input type="text" class="form-control fpdatefield" name="BillboardStartDate" autocomplete="off" id="BillboardStartDate" placeholder="">
					 </div>
					 <div class="form-group">
					 <label for="BillboardEndDate">End Date</label>
					   <input type="text" class="form-control fpdatefield" name="BillboardEndDate" autocomplete="off" id="BillboardEndDate" placeholder="">
					 </div>
					 <div class="form-group">
						<label for="isActive">Active</label>
						<input type="checkbox" class="form-control" name="isActive" id="isActive" />
					 </div>
			   </form>
			 </div>
			 <div class="modal-footer">
			   <button type="button" class="btn btn-danger" id="deleteButton" onclick="deleteBillboardItem()" >Delete</button>
			   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			   <button type="button" class="btn btn-primary" id="saveButton" onclick="saveBillboardItemInfo()">Save</button>
			 </div>
		   </div><!-- /.modal-content -->
		 </div><!-- /.modal-dialog -->
	   </div><!-- /.modal -->
		 
		 
		 
		 <!-- Billboard Position Modal -->
	<div class="modal fade" id="BillboardPositionModal">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="BillboardPositionTitle">Billboard Position</h4>
	      </div>
	      <div class="modal-body">
			<div class="form">
				<div class="form-group">
					<label for="PositionPlace">Position</label>
					<input type="text" class="form-control"  name="PositionPlace" id="PositionPlace" value="" readonly />
				</div>
				<!--<div class="form-group">
					<label for="InvoiceCustomer">Customer</label>
					<input type="text" class="form-control" readonly name="InvoiceCustomer" id="InvoiceCustomer" readonly />
				</div>-->
				<div class="form-group">
					<label for="PositionBillboard">Billboard</label>
					<select id="PositionBillboard" class="form-control">
						<option value="0">None</option>
						<?php
							
							$query = "SELECT * FROM `BILLBOARD` WHERE Active = True ORDER BY ID DESC";
							$result = mysqli_query($con, $query);
							while($row = mysqli_fetch_array($result)){
									
							
						 ?>
							<option value="<?= $row['ID'] ?>"><?= ($row['Position'] != 0)?$row['Title'] . "* (" . $row['Position'] . ")":$row['Title'] ?></option>
						 <?php
							}
							?>
							
					</select>
				</div>
			</div>
			
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
	        <button type="button" id="saveBillboardPosition" class="btn btn-success" >Save</button>
	      </div>
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
		 
		 
		 
	   <script type="text/javascript">
		   $('[name=filter]').on('keypress', function(e) {
			   if (e.which == 13) {
				   filter();
			   }
		   
		   });
		   
		   function clearFilter() {
			   $('[name=filter]').val("");
			   $('#clearButton').css('display', 'none');
			   $('tr').css('display', '');
			   
		   }
		   function filter() {
			   var	name = $('[name=filter]').val();
			   filterByName(name);
		   }
		   function filterByName(name) {
			   $('#clearButton').css('display', '');
			   for (var i = 0; i < $('tr').length; i++) {
				   if (i != 0) {
					   var result = $('tr')[i].innerText.toUpperCase().indexOf(name.toUpperCase());
					   if (result < 0) {
						   $($('tr')[i]).css('display', 'none');
					   }else {
						   $($('tr')[i]).css('display', '');
					   }
				   }
			   }
		   }
			 function editBillboardPosition(position, originalBB){
					$('#PositionPlace').val(position);
					$('#BillboardPositionModal').modal('show');
					$('#saveBillboardPosition').unbind('click');
					$('#saveBillboardPosition').on('click', function(){
						var billboardID = $('#PositionBillboard').val();
						$.get('./mod.php?p=billboard&a=functions&f=saveBillboardPosition&bid=' + billboardID + '&obid=' + originalBB + '&pos=' + position, function(data){
								location.reload();
							});	
						
					});
				
			 }
		   function clearModal() {
			   $('#isNew').val("0");
			   $('#BillboardID').val("-1");
			   $('#BillboardTitle').val("");
			   $('#BillboardType').val("image");
				 $('#imageButtonPreview').attr('src', '');
			   $('#videoPreview').attr("src","");
			   $('#imagePreview').attr("src", "");
				 $('#pdfPreview').attr("src", "");
			   $('#BillboardText').val("");
				 $('#BillboardLink').val("");
			   $('#saveButton').css('display', '');
				 $('#deleteButton').css('display', '');
			   $("#uploadSuccess").css('display', 'none');
				  $('#isActive').prop('checked', false);
					$('#BillboardStartDate').val('');
					$('#BillboardEndDate').val('');
			   
		   }
		   function addBillboard() {
			   clearModal();
			   $('#isNew').val("1");
			   $('#AddEditTitle').text("Add New Billboard");
			   $('#deleteButton').css('display', 'none');
				 $('#BillboardVideoDiv').css('display', 'none');
			   $('#AddEditBillboard').modal('toggle');
				
		   }
		   function editBillboard(ID) {
			   clearModal();
			   $.get("./mod.php?p=billboard&a=functions&f=getBillboardData&id=" + ID, function(data){
				   var billboardData = JSON.parse(data);
					 console.log(billboardData);
				   $('#isNew').val("0");
				   $('#AddEditTitle').text("Edit Billboard Item");
				   $('#BillboardID').val(ID);
					 $('#BillboardType').val(billboardData.Type);
					 if(billboardData.Button === '.'){
						$('#imageButtonPreview').attr('src', "../img/no_image_available.png");
					 }else{
							$('#imageButtonPreview').attr('src', "." + billboardData.Button);
					 }
					 if(billboardData.Type == "image"){
							$('#imagePreview').attr("src", "." + billboardData.Content);
							$('#BillboardImageDiv').css('display', '');
							$('#BillboardVideoDiv').css('display', 'none');
					 }else if(billboardData.Type == "video"){
							$('#videoPreview').attr("src", "https://www.youtube.com/embed/" + billboardData.Content + "?rel=0&autohide=1&autoplay=1&showinfo=0&html5=1");
							$('#BillboardVideo').val(billboardData.Content);
							$('#BillboardImageDiv').css('display', 'none');
							$('#BillboardVideoDiv').css('display', '');
					 }else if(billboardData.Type == 'pdf'){
							$('#pdfPreview').attr("src", "." + billboardData.Content);
							$('#BillboardImageDiv').css('display', 'none');
							$('#BillboardPDFDiv').css('display', '');
							$('#BillboardVideoDiv').css('display', 'none');
					 }else if(billboardData.Type == 'special'){
							$('#BillboardImageDiv').css('display', 'none');
							$('#BillboardPDFDiv').css('display', 'none');
							$('#BillboardVideoDiv').css('display', 'none');
					 }
					$('#BillboardTitle').val(billboardData.Title);
					$('#BillboardText').val(billboardData.Text);
					$('#BillboardLink').val(billboardData.Link);
					$('#saveButton').css('display', '');
					$("#uploadSuccess").css('display', 'none');
					$('#BillboardStartDate').val(billboardData.StartDate);
					$('#BillboardEndDate').val(billboardData.EndDate);
					$('#isActive').prop('checked', billboardData.Active);
					 
				   $('#AddEditBillboard').modal('toggle');
			   });
		   }
			 $('#BillboardType').on('change',function(){
					if($('#BillboardType').val() == "image"){
							$('#BillboardVideoDiv').css('display', 'none');
							$('#BillboardImageDiv').css('display', '');
							$('#BillboardPDFDiv').css('display', 'none');
					}else if($('#BillboardType').val() == "video"){
						$('#BillboardImageDiv').css('display', 'none');
						$('#BillboardPDFDiv').css('display', 'none');
						$('#BillboardVideoDiv').css('display', '');
					}else if($('#BillboardType').val() == "special"){
						$('#BillboardImageDiv').css('display', 'none');
						$('#BillboardPDFDiv').css('display', 'none');
						$('#BillboardVideoDiv').css('display', 'none');
					}else if($('#BillboardType').val() == "pdf"){
						$('#BillboardPDFDiv').css('display', '');
						$('#BillboardVideoDiv').css('display', 'none');
						$('#BillboardImageDiv').css('display', 'none');
					}
					
				});
			 function deleteBillboardItem(){
					if(prompt('Are you sure you want to delete this billboard')){
						var ID = $('#BillboardID').val();
						$.get('mod.php?p=billboard&a=functions&f=deleteBillboard&bid=' + ID, function(data){
								if(data.trim() == "true"){
									location.reload();
								}
							});	
					}
			 }
		   function saveBillboardItemInfo() {
				var billboardItem = "";
				if($('#BillboardType').val() == "video" ){
					billboardItem = '{ "BillboardID" : "' + $('#BillboardID').val() + '", "Title" : "' + $('#BillboardTitle').val() + '", "IsNew" : "' + $('#isNew').val() + '", "Type" : "' + $('#BillboardType').val() + '", "Content" : "' + $('#BillboardVideo').val() + '", "BillboardText" : "' + $('#BillboardText').val() + '", "BillboardLink" : "' + $('#BillboardLink').val() + '", "StartDate" : "' + $('#BillboardStartDate').val() + '", "EndDate" : "' + $('#BillboardEndDate').val() + '", "Button" : "' + $('#imageButtonPreview').attr('src').replace("../", "./") + '", "Active" : "' + $('#isActive').prop('checked') + '"}';
				}else if($('#BillboardType').val() == "image"){
					billboardItem = '{ "BillboardID" : "' + $('#BillboardID').val() + '", "Title" : "' + $('#BillboardTitle').val() + '", "IsNew" : "' + $('#isNew').val() + '", "Type" : "' + $('#BillboardType').val() + '", "Content" : "' + $('#imagePreview').attr('src').replace("../", "./") + '", "BillboardText" : "' + $('#BillboardText').val() + '", "BillboardLink" : "' + $('#BillboardLink').val() + '", "StartDate" : "' + $('#BillboardStartDate').val() + '", "EndDate" : "' + $('#BillboardEndDate').val() + '", "Button" : "' + $('#imageButtonPreview').attr('src').replace("../", "./") + '", "Active" : "' + $('#isActive').prop('checked') + '"}';
				}else if($('#BillboardType').val() == "pdf"){
					billboardItem = '{ "BillboardID" : "' + $('#BillboardID').val() + '", "Title" : "' + $('#BillboardTitle').val() + '", "IsNew" : "' + $('#isNew').val() + '", "Type" : "' + $('#BillboardType').val() + '", "Content" : "' + $('#pdfPreview').attr('src').replace("../", "./") + '", "BillboardText" : "' + $('#BillboardText').val() + '", "BillboardLink" : "' + $('#BillboardLink').val() + '", "StartDate" : "' + $('#BillboardStartDate').val() + '", "EndDate" : "' + $('#BillboardEndDate').val() + '", "Button" : "' + $('#imageButtonPreview').attr('src').replace("../", "./") + '", "Active" : "' + $('#isActive').prop('checked') + '"}';
				}else if($('#BillboardType').val() == "special"){
					billboardItem = '{ "BillboardID" : "' + $('#BillboardID').val() + '", "Title" : "' + $('#BillboardTitle').val() + '", "IsNew" : "' + $('#isNew').val() + '", "Type" : "' + $('#BillboardType').val() + '", "Content" : "", "BillboardText" : "' + $('#BillboardText').val() + '", "BillboardLink" : "' + $('#BillboardLink').val() + '", "StartDate" : "' + $('#BillboardStartDate').val() + '", "EndDate" : "' + $('#BillboardEndDate').val() + '", "Button" : "' + $('#imageButtonPreview').attr('src').replace("../", "./") + '", "Active" : "' + $('#isActive').prop('checked') + '"}';
				}
			   
			   billboardItem = JSON.parse(billboardItem);
			   $.post( "mod.php?p=billboard&a=functions&f=saveBillboardData", billboardItem)
						 .done(function( data ) {
						   data = JSON.parse(data);
						   if (data.result === true) {
							   clearModal();
							   $('#AddEditBillboard').modal('toggle');
							   location.reload();
							 }else {
							   alert("There has been an error saving the billboard data.\r\n\r\nMySQL Error: " + data.error);
							 }
						   });
			   
			   
			   
			   
		   }
		   function loadVideoPreview(){
					if($('#BillboardVideo').val() != ""){
						$('#videoPreview').attr('src', "https://www.youtube.com/embed/" + $('#BillboardVideo').val() + "?rel=0&autohide=1&autoplay=1&showinfo=0&html5=1");
					}else{
						$('#videoPreview').attr('src', "");	
					}
			 }
			 function clearVideoPreview(){
					$('#videoPreview').attr('src', "");	
			 }
			 
			 function deleteCatalogItem() {
			   if (confirm("Are you sure you want to delete this item from the Price List? This cannot be undone.")) {
				   var itemID = $('#CatalogItemID').val();
				   $.post( "functions.php?action=deleteCatalogItem&ID=" + itemID, null)
					 .done(function( data ) {
					 data = $.parseJSON(data);
					   if (data.result == true) {
						   clearModal();
						   //$('#AddEditCatalogItem').modal('toggle')
						   location.reload(true);
					   }else {
						   alert("There has been an error deleting the item.");
					   }
					 });
				 }
			   
		   }
		   
		   $("#BillboardButtonImage").fileinput({
			   'showUpload':true, 
			   'showPreview': false,
			   'uploadUrl':"mod.php?p=billboard&a=upload_image&target=btn",
			   'fileTypeSettings':'image',
			   'elErrorContainer':'#uploadError',
		   });
		   $('#BillboardButtonImage').on('filebatchuploadsuccess', function(event, data, previewId, index) {
			   response = data.response;
			   if(response.fileuploaded == true){
			   console.log(response);
				   $("#uploadButtonSuccess").text(response.message);
				   $("#uploadButtonSuccess").css('display', "");
				   $('#imageButtonPreviewDiv').css('display', '');
				   $('#imageButtonPreview').attr('src', response.url);				   
			   }
		   });
			 
			 $("#BillboardImage").fileinput({
			   'showUpload':true, 
			   'showPreview': false,
			   'uploadUrl':"mod.php?p=billboard&a=upload_image&target=image",
			   'fileTypeSettings':'image',
			   'elErrorContainer':'#uploadError',
		   });
		   $('#BillboardImage').on('filebatchuploadsuccess', function(event, data, previewId, index) {
			   response = data.response;
			   if(response.fileuploaded == true){
			   console.log(response);
				   $("#uploadSuccess").text(response.message);
				   $("#uploadSuccess").css('display', "");
				   $('#imagePreviewDiv').css('display', '');
				   $('#imagePreview').attr('src', response.url);				   
			   }
		   });
		   
			 $("#BillboardPDF").fileinput({
			   'showUpload':true, 
			   'showPreview': false,
			   'uploadUrl':"mod.php?p=billboard&a=upload_image&target=pdf",
			   'elErrorContainer':'#uploadError',
		   });
		   $('#BillboardPDF').on('filebatchuploadsuccess', function(event, data, previewId, index) {
			   response = data.response;
			   if(response.fileuploaded == true){
			   console.log(response);
				   $("#uploadSuccess").text(response.message);
				   $("#uploadSuccess").css('display', "");
				   $('#pdfPreviewDiv').css('display', '');
				   $('#pdfPreview').attr('src', response.url);				   
			   }
		   });
		   
			 
				var fp1 = $( "#BillboardStartDate" ),
				now = moment().subtract(1,"seconds"),
				oneweek = moment().add(1, "weeks");
				fp1.filthypillow( { 
					initialDateTime: function( ) {
						return moment();
					}
				} );
				fp1.on( "focus", function( ) {
					fp1.filthypillow( "show" );
				} );
				fp1.on( "fp:save", function( e, dateObj ) {
					fp1.val( dateObj.format( "MM/DD/YYYY hh:mm A" ) );
					fp1.filthypillow( "hide" );
				} );
				
				
				var fp2 = $( "#BillboardEndDate" );
				fp2.filthypillow( { 
					initialDateTime: function( ) {
						return oneweek;
					}
				} );
				fp2.on( "focus", function( ) {
					fp2.filthypillow( "show" );
				} );
				fp2.on( "fp:save", function( e, dateObj ) {
					fp2.val( dateObj.format( "MM/DD/YYYY hh:mm A" ) );
					fp2.filthypillow( "hide" );
				} );
				$('#AddEditBillboard').on('hide.bs.modal', function(){
						$('#videoPreview').attr('src', "");	
				});
				
		   </script>
	
	 </div>    
     
   </body>
 </html>