<script>
	function checkName(){
		if(document.getElementById("newNazovVozidla").value!=""){
			if(document.getElementById("newNazovVozidla").value.length<3){
				document.getElementById("nameStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("nameError").innerHTML="Minimálne tri znaky!";	
				document.getElementById("nameChecker").innerHTML="0";	
			}else{
				document.getElementById("nameStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("nameError").innerHTML="";	
				document.getElementById("nameChecker").innerHTML="1";	
			}			
		}else{
			document.getElementById("nameStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("nameError").innerHTML="";	
			document.getElementById("nameChecker").innerHTML="0";	
		}
	}
	//document.getElementById("newSPZVozidla").value.substring(0,2).match(/^[A-Z]+$/)
	//document.getElementById("newSPZVozidla").value.substring(0,1)!=""
	//document.getElementById("newSPZVozidla").value.substring(1,2)!=""
	function checkSPZ(){
		if(document.getElementById("newSPZVozidla").value!=""){
			if(document.getElementById("newSPZVozidla").value.length!=9){
				document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("SPZError").innerHTML="ŠPZ sa skladá z 9 znakov. (AA-123-BB)";	
				document.getElementById("SPZChecker").innerHTML="0";
			}else if(!(document.getElementById("newSPZVozidla").value.substring(0,2).match(/^[A-Z]+$/))){
				document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("SPZError").innerHTML="Prvé dva znaky musia byť písmena veľkej abecedy.";	
				document.getElementById("SPZChecker").innerHTML="0";									
			}else if(!(document.getElementById("newSPZVozidla").value.substring(2,3).match(/^[-]+$/))){
				document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("SPZError").innerHTML="Tretím znakom musí byť pomlčka.";	
				document.getElementById("SPZChecker").innerHTML="0";									
			}else if(!(document.getElementById("newSPZVozidla").value.substring(3,6).match(/^[0-9]+$/))){
				document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("SPZError").innerHTML="Trojčíslie musí obsahovať iba číslice.";	
				document.getElementById("SPZChecker").innerHTML="0";									
			}else if(!(document.getElementById("newSPZVozidla").value.substring(6,7).match(/^[-]+$/))){
				document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("SPZError").innerHTML="Po trojčísli musí byť pomlčka.";	
				document.getElementById("SPZChecker").innerHTML="0";									
			}else if(!(document.getElementById("newSPZVozidla").value.substring(7,9).match(/^[A-Z]+$/))){
				document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("SPZError").innerHTML="Posledné dva znaky musia byť veľké písmená abecedy.";	
				document.getElementById("SPZChecker").innerHTML="0";									
			}else{
				document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("SPZError").innerHTML="";	
				document.getElementById("SPZChecker").innerHTML="1";			
			}		
		}else{
			document.getElementById("SPZStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("SPZError").innerHTML="";	
			document.getElementById("SPZChecker").innerHTML="0";	
		}
	}
	
	function checkSeats(){
		if(document.getElementById("newPocetMiestVozidla").value!=""){
			if(!(document.getElementById("newPocetMiestVozidla").value.match(/^[0-9]+$/))){
				document.getElementById("seatsStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("seatsError").innerHTML="Iba číslice!";	
				document.getElementById("seatsChecker").innerHTML="0";	
			}else{
				document.getElementById("seatsStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("seatsError").innerHTML="";	
				document.getElementById("seatsChecker").innerHTML="1";	
			}			
		}else{
			document.getElementById("seatsStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("seatsError").innerHTML="";	
			document.getElementById("seatsChecker").innerHTML="0";	
		}
	}	

document.addEventListener("keyup", function(){
	if(document.getElementById("nameChecker").innerHTML=="1" && document.getElementById("SPZChecker").innerHTML=="1" && document.getElementById("seatsChecker").innerHTML=="1"){
		document.getElementById("submitSpan").style.visibility = "visible";	
		document.getElementById("finallyCheckerEmployee").innerHTML="<h3 style='padding-top:12px'><img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='20' width='20' align='middle' style='padding-bottom:12px;padding-right:15px'>Nové vozidlo</h3>";					
	}else{
		document.getElementById("submitSpan").style.visibility = "hidden";
		document.getElementById("finallyCheckerEmployee").innerHTML="<h3 style='padding-top:12px'><img src='http://martinbendik.studenthosting.sk/pictures/Exclamation.png' height='20' width='20' align='middle' style='padding-bottom:12px;padding-right:15px'>Nové vozidlo</h3>";
	} 
});	
</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 '<span id="finallyCheckerEmployee">';
				echo "<h3 style='padding-top:12px'><img src='http://martinbendik.studenthosting.sk/pictures/Exclamation.png' height='20' width='20' align='middle' style='padding-bottom:12px;padding-right:15px'>Nové vozidlo</h3>";
			echo '</span>';
			echo form_open(base_url('manager/createNewVehicle'),'onkeypress="return event.keyCode != 13;"');	
				echo '<div id="errors" >';
					echo validation_errors();
				echo "</div>";
			echo '<table id="newCustomerInfoTable" style="margin-left:50px; margin-top:10px">';				
				echo "<tr>";
					echo "<td  style='width:160px'>";
						echo "Názov vozidla: ";
					echo "</td>";
					echo "<td>";										
						echo form_input("newNazovVozidla",'' , 'onkeyup="checkName()" id="newNazovVozidla" class="login_textarea"');
					echo "</td>";
					echo "<td id='nameStatus'>";
						echo "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
					echo "</td>";
					echo "<td id='nameError' style='padding-left:10px'>";
					echo "</td>";
					echo "<td id='nameChecker' hidden>";
						echo "0";
					echo "</td>";					
				echo "</tr>";
				echo "<tr>";
					echo "<td>";
						echo "ŠPZ vozidla: ";
					echo "</td>";
					echo "<td>";										
						echo form_input("newSPZVozidla",'' , 'onkeyup="checkSPZ()" id="newSPZVozidla" class="login_textarea"');
					echo "</td>";
					echo "<td id='SPZStatus'>";
						echo "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
					echo "</td>";
					echo "<td id='SPZError' style='padding-left:10px'>";
					echo "</td>";
					echo "<td id='SPZChecker' hidden>";
						echo "0";
					echo "</td>";					
				echo "</tr>";
				echo "<tr>";
					echo "<td>";
						echo "Počet miest vozidla: ";
					echo "</td>";
					echo "<td>";										
						echo form_input("newPocetMiestVozidla",'' , 'onkeyup="checkSeats()" id="newPocetMiestVozidla" class="login_textarea"');
					echo "</td>";
					echo "<td id='seatsStatus'>";
						echo "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
					echo "</td>";
					echo "<td id='seatsError' style='padding-left:10px'>";
					echo "</td>";
					echo "<td id='seatsChecker' hidden>";
						echo "0";
					echo "</td>";					
				echo "</tr>";
				echo "<tr>";
					echo "<td>";
						echo "Aktivita vozidla: ";
					echo "</td>";
					echo "<td>";
						$options = array(
                  			'1'  => 'Aktívne',
                  			'0'  => 'Neaktívne');										
						echo form_dropdown('newAktivitaVozidla', $options,'' , 'class="login_textarea" style="width:228px"');
					echo "</td>";					
				echo "</tr>";			
			echo "</table>";
		echo "<div class='vehicle_div' style='align:center; margin-top:15px;'></div>";											
			echo '<div class="button-group" style="margin-left:50px;margin-top:20px">';
			echo '<a class="button" href="javascript:window.history.go(-1); ">Späť</a>';
			echo '<span id="submitSpan">';
				echo form_submit('input_form_submit' , 'Vytvoriť' ,'class="button"' );
			echo '</span>';
			echo '</div>';
			
		echo "</div>";		
	} else {
		redirect(base_url('main/restricted'));
	}	
?>
	


