<?php
if(!isset($_REQUEST['test'])){
	//header("Location: down.php");
	//die("El sistema de ordenes esta en proceso de mantenimiento. Disculpe los inconvenientes.");	
}

//$language = $_SESSION['Language'];
if (isset($_SESSION['isCustomer'])) {
	$isCustomer = $_SESSION['isCustomer'];	
}else {
	header("Location: login.php");
}

if ($isCustomer) {
	$customer = new Customer($_SESSION['AccountNumber']);	
	$language = $customer->Language;
	$pricePlanMode = false;
}else {
	
	$salesman = new Salesman($_SESSION['SalesmanID']);
	$language = $salesman->Language;
	$pricePlanMode = $_SESSION['pricePlanMode'];
	
}




include_once('./modules/savecart/savecart.addon.php');
?>
<div class="ajax-loading-modal"></div>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" />
<link rel="stylesheet" href="css/navbar.css" type="text/css" />
<link rel="stylesheet" href="css/swipebox.min.css" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" type="text/css"/>
<script src="js/lightbox.js" type="text/javascript"></script>
<script src="js/bootstrap-checkbox.min.js" type="text/javascript"></script>
<script src="js/jquery.fixedheadertable.min.js" type="text/javascript"></script>
<script src="js/jquery.redirect.js" type="text/javascript"></script>
<script src="js/navbar.js" type="text/javascript"></script>
<script src="js/functions.js"></script>
<script src="js/jquery.swipebox.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.10.6/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<style>
	.ajax-loading-modal {
		display:    none;
		position:   fixed;
		z-index:    9000;
		top:        0;
		left:       0;
		height:     100%;
		width:      100%;
		background: rgba( 255, 255, 255, .8 ) 
					url('/img/loading-web.gif') 
					50% 50% 
					no-repeat;
	}
	/* When the body has the loading class, we turn
	   the scrollbar off with overflow:hidden */
	body.loading {
		overflow: hidden;   
	}
	
	/* Anytime the body has the loading class, our
	   modal element will be visible */
	body.loading .ajax-loading-modal {
		display: block;
	}
</style>


<a href="javascript:$('#catalogsButton [data-toggle=dropdown]').dropdown('toggle');"><img src="img/banner.jpg?time=<?= time() ?>" id="stripHeader" class="navbar-fixed-top hidden-print" style=" width: 95%; margin: auto;  margin-top: 60px; display: block;" alt="" /></a>

<nav class="navbar navbar-default navbar-fixed-top" style="min-height: 50px;">
  <div class="container-fluid" style="min-height: 50px;">
<!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      
      <a class="navbar-brand" style="padding: 5px; padding-right: 160px;" href="index.php"><img class="img-responsive" style="width: 160px; position: absolute;" src="img/<?= $config['SmallLogo'] ?>" alt="" /></a>
    </div>
	
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" style="min-height: 50px;" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <?php
        if (basename($_SERVER['PHP_SELF']) != "index.php") {
        	if (isset($_SESSION['LastSearch'])) {
		        $url = "index.php?";
		        $url .= "sku=" . $_SESSION['LastSearch']['SKU'] . "&";
		        $url .= "line=" . $_SESSION['LastSearch']['Line'] . "&";
		        $url .= "group=" . $_SESSION['LastSearch']['Group'] . "&";
		        $url .= "wc=" . $_SESSION['LastSearch']['WC'] . "&";
		        $url .= "p=" . $_SESSION['LastSearch']['Page'];
		        if($_SESSION['LastSearch']['SKU'] != "" || $_SESSION['LastSearch']['Line'] != "" || $_SESSION['LastSearch']['Group'] != "" || $_SESSION['LastSearch']['WC'] != ""){
        ?>
        	<li><a href="<?= $url ?>">Back to Search</a></li>
        <?php	
        		}else{
        ?>
        	<li><a href="index.php">Back to Search</a></li>
        <?php
        		}
        	}
        }else{
        ?>
		
        <li style="margin-right: -7px; margin-left: -7px;" ><a href="index.php">Clear Screen</a></li>
		
					
					
		
		
        <?php 
        }
        $query = "SELECT COUNT(ID) As `Count` FROM ALTAS_HEAD WHERE Active = 1";
        $result = mysqli_query($con, $query);
        $row = mysqli_fetch_array($result);
        ?>
        
        <li style="display: none;" id="altasButton" style="margin-right: -7px; margin-left: -7px;" ><a href="#" onclick="openNewAltas();">
        <?php
        if ($language == "EN") {
        	echo "Just Received";	
        }else {
        	echo "Altas";
        }
        ?>
        <span style="background-color: #dc0d17;" class="badge"><?= $row['Count'] ?></span></a></li>
		<?php
		if(!$isCustomer && !$detect->isMobile()){
		?>
       	<li style="font-size: 40px;" ><a href="mod.php?p=payment&a=new">💰</a></li>
		<li style="font-size: 40px;" ><a onclick="$('#navbarClearCustomer').click();">👥</a></li>
		<li style="font-size: 40px;" ><a onclick="showCatalog();"><img src="img/catalog-icon.png" style="width: 50px;" /></a></li>
		<?php
		}
		?>
      </ul>
      <style>
      	.catalog-menu-item{
      		padding: 2px;
      	}
      	.catalog-menu-logo{
      		height: 40px;
      	}
      
      </style>
      
      
      
      <style>
      	.promo {
      		position: fixed;
      		top: -10px;
      		right: 45%;
      	}
		.grow { transition: all .2s ease-in-out; }
		.grow:hover { transform: scale(1.2); }
      </style>
      
              
      <ul class="nav navbar-nav navbar-right">
		<div id="billboardContainer">
		</div>
		<script>
		<?php
			if ( !$detect->isMobile() ) {
				
			
		?>
			$(document).ready(function(){
				$.get('mod.php?p=billboard&a=functions&f=getNavbarBillboardsCode<?= isset($_REQUEST['splash'])?"&splash=true":"" ?>', function(data){
					$('#billboardContainer').html(data);
					$('img[id^=promoModalContent]').css('max-height', (window.innerHeight * 0.72));
					$('img[id^=promoModalContent]').css('max-width', '100%');
					$('iframe[data-type=pdf]').css('height', (window.innerHeight * 0.72));
					$('iframe[data-type=pdf]').css('width', '100%');
					
					var catalogs_button = window.innerWidth-$('#catalogsButton').position().left;
					var altas_btn = window.innerWidth-$('#altasButton').position().left-$('#altasButton').width();
					var max_bb_size = (altas_btn-catalogs_button)/3
					$('#PromoButton1').css('height', '');
					$('#PromoButton1').css('max-height', '70px');
					$('#PromoButton1').css('max-width', max_bb_size + 'px');
					$('#PromoButton1').css('right', (altas_btn - max_bb_size * 1) + "px");
					
					
					$('#PromoButton2').css('height', '');
					$('#PromoButton2').css('max-height', '70px');
					$('#PromoButton2').css('max-width', max_bb_size + 'px');
					$('#PromoButton2').css('right', (altas_btn - max_bb_size * 2) + "px");
					
					
					$('#PromoButton3').css('height', '');
					$('#PromoButton3').css('max-height', '70px');
					$('#PromoButton3').css('max-width', max_bb_size + 'px');
					$('#PromoButton3').css('right', (altas_btn - max_bb_size * 3) + "px");


					
					$('.dropdownModal').modal('show');
				});
				
			});
			
			function showNewPromo(ID){
				$('#promoModal'+ ID).modal('toggle');
			}
			
			<?php
			}
			?>
		</script>
		
		
		<?php
		  
      	if (true) {
      		
      	
      ?>
		<li class=""><a onclick="$('#reorderModal').modal('toggle');return false;" href="#"><span class="glyphicon glyphicon-retweet" aria-hidden="true"></span> Reorder List</a></li>
		
      	<li id="catalogsButton" class="dropdown">
      		<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?= $language=="ES"?"Catalogos":"Catalogs" ?><span class="caret"></span></a>
      		<ul class="dropdown-menu scroll-menu" role="menu">
				<?php
					
						
					
						$queryCatalog = "SELECT * FROM SUPPLIER_CATALOG_LINK ORDER BY Position, Name";
						$resultCatalog = mysqli_query($con, $queryCatalog);
						while($row = mysqli_fetch_array($resultCatalog, MYSQLI_ASSOC)){
				?>
					<li class="centered catalog-menu-item"><a target="<?= $row['Target'] ?>" href="<?= $row['Link'] ?>"><img src="<?= $row['ButtonImage'] ?>"  style="max-width: 200px;" alt="<?= $row['Name'] ?>" /><?= ($row['AdditionalText'])?"<br>" . $row['AdditionalText']:"" ?></a></li>
				<?php
						}
				?>
      		</ul>
      	</li>
      	<?php 
      		}
      			
      	?>
      		<li>
      			<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Tools<span class="caret"></span></a>
      			<ul class="dropdown-menu multi-level" role="menu">
					<li><a onclick="orderHistoryDateSelect();">Order History</a></li>
					<?php
						if (!$isCustomer){
					?>
					<li><a onclick="invoiceHistoryDateSelect();">Invoice History</a></li>
					<li><a onclick="estimateHistoryDateSelect();">Estimate History</a></li>
					<!--<li class="dropdown-submenu">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">Pickups</a>
						<ul class="dropdown-menu">
							<li><a href="pickup.php">New Pickup Request</a></li>
							<li><a href="pickuphistory.php">Pickup History</a></li> 
						</ul>
					</li>-->
					<li><a href="#" id="navbarClearCustomer">Change Customer</a></li>
					<script>
						$('#navbarClearCustomer').on('click', function(){
							$.get('functions.php?action=clearSetCustomer', function(data) {
								data = JSON.parse(data);
								if (data.result) {
									location.reload();
								}else {
									alert("ERROR");
								}
							
							
							});
						});
						
					</script>
					<li class="dropdown-submenu">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">Payments</a>
						<ul class="dropdown-menu">
							<li><a href="mod.php?p=payment&a=new">New Payment</a></li>
							<li><a onclick="paymentHistoryDateSelect()">Payment History</a></li>
							<li><a onclick="$('#creditSearchModal').modal('toggle');">Credit Search</a></li>
						</ul>
					</li>
					<!--<li><a href="#" onclick="$('#weeklyPlannerSelectModal').modal('toggle')">Weekly Planner</a></li>-->
					<li><a href="#" onclick="openMyCustomers();">Customer Last Login</a></li>
					<li><a href="#" onclick="$('#pricePlanModal').modal('toggle');">Price Plan (Calculated)</a></li>
					<li><a href="#" onclick="openSalesmanQuota();">My Quota</a></li>
					<!--<li><a href="#" onclick="openCustomerActivity();">Customer Activity</a></li>-->
					<!--<li><a href="#" onclick="window.open('mod.php?p=payment&a=printcheck','PrintCheck','toolbar=no,width=415,height=1000')">Print Check</a></li>-->
					<!--<li><a style="color: blue;" href="offlineupdate/Eli-T%20Offline%20setup1.2.4.exe" onclick="">Eli-T Offline Download</a></li>-->
					
      				<!--<li><a href="../assets/Calculo de Cobros EJAS.xlsx">Calculadora de Cobros</a></li>-->
				    <?php
						}else{
					?>
					<li class="dropdown-submenu">
					<a href="#" class="dropdown-toggle" data-toggle="dropdown">Payments</a>
						<ul class="dropdown-menu">
							<li><a onclick="paymentHistoryDateSelect()">Payment History</a></li>
							<li><a href="mod.php?p=payment&a=aging">Aging</a></li>
						</ul>
					</li>
					<!--<li><a href="pickuphistory.php">Pickup History</a></li>-->
					
					<?php
						
						}
					?>
					
					<li class="dropdown-submenu">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="glyphicon glyphicon-globe" aria-hidden="true"></span> Language</a>
						<ul class="dropdown-menu" role="menu">
							<li><a onclick="setLanguage('EN')" href="#">English</a></li>
							<li><a onclick="setLanguage('ES')" href="#">Espa&ntilde;ol</a></li>
						</ul>
					</li>     				
      			</ul>
      		</li>
      		<?php 
      			
      		 ?>
      	<li class="dropdown">
      		<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?= ($isCustomer)?$customer->Name:$salesman->Name ?><span class="caret"></span></a>
      		<ul class="dropdown-menu" role="menu">
      			
      			<?php	
      				if (!$isCustomer) {
      			?>
      				
      			<?php
      				}
      			
      			 ?>
      	        <li><a onclick="clearPasswordForm()" href="#">Change Password</a></li>
      	        <li><a href="logout.php">Logout</a></li>
				<li><a href="https://showmypc.com/">Help</a></li>
      		</ul>
      	</li>
      	
      	
        
        <li class="<?= (basename($_SERVER['PHP_SELF']) == "cart.php")?"active":"" ?>"><a href="cart.php"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> <span id="cartTotal"><?= moneyFormat(getCartTotal()) ?></span>
		<?php
			if(!$isCustomer && $savedCartCount > 0){
		?>
		<span style="background-color: #dc0d17;" class="badge"><?= $savedCartCount ?></span>
		<?php
			}
		?>
		</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
    </nav>
    
    <script type="text/javascript">
    	$('.scroll-menu').css('max-height',$(window).height()-75);
    	$('.scroll-menu').css('overflow',"scroll");
		function showDaichiPromo() {
			$('#promoDaichiModal').modal('show');
     	
		}
		function showKYBPromo() {
			$("#myCarousel").carousel(0);
			$('#promoKYBModal').modal('show');
		}
		function showStreetLegalMPCPromo() {
			$('#promoStreeLegalMPCModal').modal('show');
		}
		function showPromoBazooka() {
			$('#promoBazookaIframe').attr('src', 'https://www.youtube.com/embed/iH25LGs8IBg?rel=0&autohide=1&autoplay=1&showinfo=0&html5=1');
			$('#promoBazookaModal').modal('show');
			$('#promoBazookaModal').on('hide.bs.modal', function (e) {
			$('#promoBazookaIframe').attr('src', '');
		  });
		}
		function showAvisoImportante() {
			$("#avisoImportanteCarousel").carousel(0);
			$('#avisoImportanteModal').modal('show');
		}
		$(document).ready(function(){
			$('.combobox').combobox();
			<?php
				$fromPromoDate = new DateTime("2016-10-10 20:00",new DateTimeZone("America/Puerto_Rico"));
				$toPromoDate = new DateTime("2016-10-21 22:00",new DateTimeZone("America/Puerto_Rico"));
				if(isset($_REQUEST['splash']) && $_REQUEST['splash'] == "true" && runBetweenDateRange($fromPromoDate,$toPromoDate)){
					echo "showStreetLegalMPCPromo();";
				}else{
				
				}
			
			
			?>
			if($(window).width() < 1320){
				$('#optionalPromo').hide();
			}	else{
				$('#optionalPromo').show();
			}
			
			$(window).resize(function(){
				if($(window).width() < 1320){
					$('#optionalPromo').hide();
				}	else{
					$('#optionalPromo').show();
				}
			});
		});
		
    </script>
    
    <?php 	

    include("modals.php"); ?>
    <br /><br />
	<?php
	/*
	$chatCustomers = array(
							"321394",
							"306327",
							"312283",
							"309104",
							"322391",
							"392453",
							"322338",
							"301394",
							"322360",
							"318390",
							"314176",
							"342289",
							"309101",
							"342186",
							"321379",
							"301381",
							"301233",
							"381740",
							"315221",
							"301204",
							"301297",
							"309116",
							"310122",
							"311136",
							"312285",
							"312551",
							"314161",
							"314624",
							"314686",
							"315221",
							"315319",
							"315322",
							"320111",
							"321867",
							"324122",
							"328916",
							"331623",
							"332389",
							"352387",
							"371393",
							"371801",
							"381142",
							"391426"
						   );
	*/
	$chatCustomers = array(
							"321394",
							"123456");
	
	if(isset($_SESSION['isCustomer']) && isset($customer)?in_array($customer->AccountNumber, $chatCustomers):false && false){
		
	?>
	<input type="hidden" id="ChatAlias" value="<?= isset($customer->Name)?$customer->Name:"Guest" . " (" . isset($customer->AccountNumber)?$customer->AccountNumber:"------" . ")" ?>">
	<!--<script type="text/javascript"> (function(d){ var s = d.getElementsByTagName('script'),f = s[s.length-1], p = d.createElement('script'); window.WidgetId = "USC_WIDGET"; p.type = 'text/javascript'; p.setAttribute('charset','utf-8'); p.async = 1; p.id = "ultimate_support_chat"; p.src = "ultimate_support_chat/widget/ultimate_chat_widget.js"; f.parentNode.insertBefore(p, f); }(document)); </script>-->

	
	<?php
	}
	?>
	<script>
		$body = $("body");
		$(document).on({
			ajaxStart: function() { $body.addClass("loading");    },
			 ajaxStop: function() { $body.removeClass("loading"); },
			 ajaxError: function() { $body.removeClass("loading"); }
		});
		$(document).ajaxError(function() { $body.removeClass("loading"); });
		
		
		
		//load required select customer
		<?php
		
		if (!$_SESSION['isCustomer']) {
     	if((isset($_SESSION['setCustomerMode']) && !$_SESSION['setCustomerMode']) || !isset($_SESSION['setCustomerMode'])) {
     	?>
		$(document).ready(function(){
			$('#RequiredSetCustomerModal').modal();	
		});
     		
		<?php
     	}
     }
		
		?>
	</script>
	<script src="js/jquery.fittext.js"></script>