<script>

function checkSearchArea(){
	if(document.getElementById("searchStatus").innerHTML==0){		
		if(document.getElementById("searchArea").value==""){
			document.getElementById("searchButton").value="Resetuj";	
		}else{
			document.getElementById("searchButton").value="Hľadať";	
		}
	}else{
		document.getElementById("searchButton").value="Hľadať";
	}		
}
	
window.onload = function(){
	checkSearchArea();	
};

document.addEventListener("keyup", function(){
	checkSearchArea();
});
</script>		
<?php
	if ($this->session->userdata('permisson')==1) {		
		$CI =& get_instance();
		$CI->load->library('libraryprofile');		
		$CI->libraryprofile->showMenuBarManager($this->session->userdata('meno'),$this->session->userdata('priezvisko')); 	
			
  					
		echo '<div id="default_container">';
		echo '<div class="button-group" style="margin-left:50px;margin-top:10px;">';
			echo '<a href="' . base_url() . 'manager/redirectCreateNewInventory/0" class="button" >Nový zákazník</a>';
		echo '</div>';
		echo '<div class="button-group" style="margin-left:50px;margin-top:10px;">';
		  echo form_open(base_url() . 'manager/searchCustomer','onkeypress="return event.keyCode != 13;"');	  			
    			echo form_submit('submit_search', 'Hľadať', 'class="button" id="searchButton"');
				echo form_input('search' ,'', 'class="search_area" id="searchArea"');				
			  echo form_close(); 
			  echo '</div>';		
		if(count($Customers)==0){
			echo "<div class='vehicle_div' style='align:center; margin-top:15px; margin-bottom:0px'></div>";
			echo "<h3 style='margin-top:-10px'>Žiadna zhoda hľadaného výrazu.</h3>";
			echo "<div id='searchStatus' hidden>0</div>";	
		}else{
			echo "<div class='vehicle_div' style='align:center; margin-top:15px; margin-bottom:5px'></div>";
			echo "<div id='searchStatus' hidden>1</div>";
		echo "<table>";
			echo "<thead style='text-align:left'>";		
				echo "<th>";
				echo "</td>";
				echo "<th>";
					echo "ID zákazníka";
				echo "</th>";
				echo "<th>";
					echo "Názov spoločnosti";
				echo "</th>";
				echo "<th>";
					echo "Mesto";
				echo "</th>";
				echo "<th>";
					echo "Ulica a číslo";
				echo "</th>";
			echo "<tbody class='zoznamTable'>";	
			echo "<tr class='nothing'>";
				echo "<td colspan='7' class='nothing'>";
				echo "<div class='vehicle_div' style='align:center; margin-top:5px; margin-bottom:5px'></div>";
				echo "</td>";
			echo "</tr>";
				foreach ($Customers as $Customer){
					echo '<tr>';
						echo '<td width="250px" height="30px">';
						echo '</td>';
						echo '<td width="100px">';
							if (strlen($Customer->ID_Zakaznik)==1) {
							echo "0000";
							echo $Customer->ID_Zakaznik;
						} elseif (strlen($Customer->ID_Zakaznik)==2) {
							echo "000";
							echo $Customer->ID_Zakaznik;
						} elseif (strlen($Customer->ID_Zakaznik)==3) {
							echo "00";
							echo $Customer->ID_Zakaznik;
						} elseif (strlen($Customer->ID_Zakaznik)==4) {
							echo "0";
							echo $Customer->ID_Zakaznik;
						} else {
							$Customer->ID_Zakaznik;
						}
						echo '</td>';
						echo '<td width="150px">';
							echo $Customer->Nazov_spolocnosti; 
						echo '</td>';
						echo '<td style="width:160px">';
							echo $Customer->Mesto;
						echo '</td>';
						echo '<td width="180px">';
							echo $Customer->Ulica;
							echo ' ';
							echo $Customer->Cislo;
						echo '</td>';
						echo '<td>';
							echo '<a href="'.base_url('manager/redirectCreateNewInventory/'.$Customer->ID_Zakaznik).'" class="button">Vybrať</a>'	;					
						echo '</td>';
						echo '<td width="243px">';
						echo '</td>';						
					echo '</tr>';
				}	
			echo '</tbody>';
		echo '</table>';
		echo "<div class='vehicle_div' style='align:center; margin-top:15px;'>";
			echo "</div>";
		}
		
		echo '<div id="buttonsId" class="button-group" style="margin-left:50px;margin-top:15px">';
				echo '<a href="'.base_url('manager/showInventories/1').'" class="button">Späť</a>';								
			echo '</div>';
		echo "</div>";
		
		echo $this->pagination->create_links();
		
		
			
			
			
			
			
	
	
	
	} else {
		redirect(base_url('main/restricted'));
	}	
?>
	


