<script>
function checkFirstName(){
	if(document.getElementById("newEmployeeFirst").value!=""){
		if(!document.getElementById("newEmployeeFirst").value.match(/^[A-Za-záÁéÉíÍĺĹóÓŕŔúÚýÝčČďĎľĽňŇšŠťŤžŽäô]+$/)){
			document.getElementById("firstStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("firstError").innerHTML="Iba písmená abecedy!";	
			document.getElementById("firstChecker").innerHTML="0";						
		}else if(document.getElementById("newEmployeeFirst").value.length<3){
			document.getElementById("firstStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("firstError").innerHTML="Minimálne tri znaky!";	
			document.getElementById("firstChecker").innerHTML="0";					
		}else{
			document.getElementById("firstStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("firstError").innerHTML="";	
			document.getElementById("firstChecker").innerHTML="1";					
		}	
	}else{
		document.getElementById("firstStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
		document.getElementById("firstError").innerHTML="";	
		document.getElementById("firstChecker").innerHTML="0";	
	}	
}

function checkLastName(){
	if(document.getElementById("newEmployeeLast").value!=""){
		if(!document.getElementById("newEmployeeLast").value.match(/^[A-Za-záÁéÉíÍĺĹóÓŕŔúÚýÝčČďĎľĽňŇšŠťŤžŽäô]+$/)){
			document.getElementById("lastStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("lastError").innerHTML="Iba písmená abecedy!";	
			document.getElementById("lastChecker").innerHTML="0";						
		}else if(document.getElementById("newEmployeeLast").value.length<3){
			document.getElementById("lastStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("lastError").innerHTML="Minimálne tri znaky!";	
			document.getElementById("lastChecker").innerHTML="0";					
		}else{
			document.getElementById("lastStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("lastError").innerHTML="";	
			document.getElementById("lastChecker").innerHTML="1";					
		}	
	}else{
		document.getElementById("lastStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
		document.getElementById("lastError").innerHTML="";	
		document.getElementById("lastChecker").innerHTML="0";	
	}	
}

	

function checkEmail(){
	function isRealEmail(email) {
		var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		return re.test(email);
	}	
	if(document.getElementById("newEmail").value!=""){
		if(!isRealEmail(document.getElementById("newEmail").value)){
			document.getElementById("emailStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("emailError").innerHTML="Nesprávny formát emailu.";	
			document.getElementById("emailChecker").innerHTML="0";	
		}else{
			var status=0;
			var countemployees = parseInt(document.getElementById("countOldEmployees").innerHTML);
			for(i = 1; i < (countemployees+1); i++){
				if(document.getElementById("newEmail").value.toUpperCase()==document.getElementById("email"+i).innerHTML.toUpperCase()){
					status=1;	
				}
			}
			if(status==0){
				document.getElementById("emailStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("emailError").innerHTML="";	
				document.getElementById("emailChecker").innerHTML="1";		
			}else{
				document.getElementById("emailStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("emailError").innerHTML="Uživateľ s týmto emailom už existuje.";	
				document.getElementById("emailChecker").innerHTML="0";	
			}			
		}		
	}else{
		document.getElementById("emailStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
		document.getElementById("emailError").innerHTML="";	
		document.getElementById("emailChecker").innerHTML="0";	
	}
}

function checkBirthDate(){
	if(document.getElementById("newEmployeeBirth").value!=""){				
		if(!document.getElementById("newEmployeeBirth").value.match(/^[0-9/]+$/)){
			document.getElementById("birthStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("birthError").innerHTML="Iba číslice a lomka.";	
			document.getElementById("birthChecker").innerHTML="0";			
		}else if(document.getElementById("newEmployeeBirth").value.length!=11){
			document.getElementById("birthStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("birthError").innerHTML="Rodné číslo ma 11 znakov.";	
			document.getElementById("birthChecker").innerHTML="0";	
		}else if(!(document.getElementById("newEmployeeBirth").value.substring(0,6).match(/^[0-9]+$/) && (document.getElementById("newEmployeeBirth").value.substring(6,7)=="/") && document.getElementById("newEmployeeBirth").value.substring(7,11).match(/^[0-9]+$/))){
			document.getElementById("birthStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
			document.getElementById("birthError").innerHTML="Nesprávny formát rodného čísla. ( 123456/7890 )";	
			document.getElementById("birthChecker").innerHTML="0";	
		}else{
			var status=0;
			var countemployees = parseInt(document.getElementById("countOldEmployees").innerHTML);
			for(i = 1; i < (countemployees+1); i++){
				if(document.getElementById("newEmployeeBirth").value.toUpperCase()==document.getElementById("rodneCislo"+i).innerHTML.toUpperCase()){
					status=1;	
				}
			}
			if(status==0){
				document.getElementById("birthStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("birthError").innerHTML="";	
				document.getElementById("birthChecker").innerHTML="1";	
			}else{
				document.getElementById("birthStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
				document.getElementById("birthError").innerHTML="Uživateľ s týmto rodným číslom už existuje!";	
				document.getElementById("birthChecker").innerHTML="0";	
			}				
		}				
	}else{
		document.getElementById("birthStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
		document.getElementById("birthError").innerHTML="";	
		document.getElementById("birthChecker").innerHTML="0";	
	}
}

function checkType(){
 	if(document.getElementById("newEmployeeType").value!=99){
		document.getElementById("typeStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
		document.getElementById("typeError").innerHTML="";	
		document.getElementById("typeChecker").innerHTML="1";	 
	}else{
		document.getElementById("typeStatus").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";;	
		document.getElementById("typeError").innerHTML="";	
		document.getElementById("typeChecker").innerHTML="0";	
	}	
}

document.addEventListener("click", function(){
	if(document.getElementById("firstChecker").innerHTML=="1" && document.getElementById("lastChecker").innerHTML=="1" && document.getElementById("emailChecker").innerHTML=="1" && document.getElementById("birthChecker").innerHTML=="1" && document.getElementById("typeChecker").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ý zamestnanec</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ý zamestnanec</h3>";
	} 
});

document.addEventListener("keyup", function(){
	if(document.getElementById("firstChecker").innerHTML=="1" && document.getElementById("lastChecker").innerHTML=="1" && document.getElementById("emailChecker").innerHTML=="1" && document.getElementById("birthChecker").innerHTML=="1" && document.getElementById("typeChecker").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ý zamestnanec</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ý zamestnanec</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 "<table hidden>";
		echo "<td id='countOldEmployees'>".count($oldEmployees)."</td>";
		$count=0;
		foreach($oldEmployees as $oldEmployee){
			$count++;
			echo "<td id='idEmp".$count."'>".$oldEmployee->ID_ZAM."</td><td id='email".$count."'>".$oldEmployee->Email."</td><td id='rodneCislo".$count."'>".$oldEmployee->Rodne_cislo."</td>"	;
		}
		echo "</table>";
		
		echo form_open(base_url('manager/createEmployee'),'onkeypress="return event.keyCode != 13;"');			
		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ý zamestnanec</h3>";
			echo '</span>';
				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:130px'>";
						echo "Meno:";
					echo "</td>";
					echo "<td>";
						echo form_input("newEmployeeFirst",'' , 'onkeyup="checkFirstName()" id="newEmployeeFirst" class="login_textarea"');	
					echo "</td>";
					echo "<td id='firstStatus'>";
						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='firstError'>";
					echo "</td>";
					echo "<td id='firstChecker' hidden>";
						echo "0";
					echo "</td>";
				echo "</tr>";
				
				echo "<tr>";
					echo "<td>";
						echo "Priezvisko:";
					echo "</td>";
					echo "<td>";
						echo form_input("newEmployeeLast",'' , 'onkeyup="checkLastName()" id="newEmployeeLast" class="login_textarea"');	
					echo "</td>";
					echo "<td id='lastStatus'>";
						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='lastError'>";
					echo "</td>";
					echo "<td id='lastChecker' hidden>";
						echo "0";
					echo "</td>";
				echo "</tr>";
				
				echo "<tr>";
					echo "<td>";
						echo "Email:";
					echo "</td>";
					echo "<td>";
						echo form_input("newEmail",'' , 'onkeyup="checkEmail()" id="newEmail" class="login_textarea"');	
					echo "</td>";
					echo "<td id='emailStatus'>";
						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='emailError'>";
					echo "</td>";
					echo "<td id='emailChecker' hidden>";
						echo "0";
					echo "</td>";
				echo "</tr>";
				
				echo "<tr>";
					echo "<td>";
						echo "Rodné číslo:";
					echo "</td>";
					echo "<td>";
						echo form_input("newEmployeeBirth",'' ,'onkeyup="checkBirthDate()" id="newEmployeeBirth" class="login_textarea"');	
					echo "</td>";
					echo "<td id='birthStatus'>";
						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='birthError'>";
					echo "</td>";
					echo "<td id='birthChecker' hidden>";
						echo "0";
					echo "</td>";
				echo "</tr>";
					
				echo "<tr>";
					echo "<td>";
						echo "Typ zamestnanca:";
					echo "</td>";
					echo "<td>";
						$options = array(
							'99' => '',
                  			'2'  => 'Vedúci inventúr',
                  			'3'  => 'Šofér',
                  			'4'  => 'Zamestnanec',														  
                );
						echo form_dropdown('newEmployeeType', $options, '' , 'onclick="checkType()" id="newEmployeeType" class="login_textarea2"' );	
					echo "</td>";
					echo "<td id='typeStatus'>";
						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='typeError'>";
					echo "</td>";
					echo "<td id='typeChecker' hidden>";
						echo "0";
					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 href="javascript:window.history.go(-1);" class="button">Späť</a>';
			echo '<span id="submitSpan">';
			echo form_submit('create_employee_1' , 'Uložiť a vytvoriť ďalšieho', 'class="button"');
			echo form_submit('create_employee_2' , 'Uložiť a zobraziť zamestnancov', 'class="button"');
			echo '</span>';
		echo '</div>';
		
		echo "</div>";
		
		
		
		
			
			
			
			
			
	 
	
	
	} else {
		redirect(base_url('main/restricted'));
	}	
?>
	


