<script>
	function checkName(){
		if(document.getElementById("editNazovSpolocnosti").value!=""){
			if(document.getElementById("editNazovSpolocnosti").value.length<2){
				document.getElementById("nameError").innerHTML="Minimálne 2 znaky.";
				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("nameChecker").innerHTML="0";
			}else{
				document.getElementById("nameError").innerHTML="";
				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("nameChecker").innerHTML="1";
			};	
		}else{
			document.getElementById("nameError").innerHTML="";
			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("nameChecker").innerHTML="0";
		};
	};
	
	function checkCity(){
		if(document.getElementById("editMesto").value!=""){
			if(document.getElementById("editMesto").value.length<2){
				document.getElementById("cityError").innerHTML="Minimálne 2 znaky.";
				document.getElementById("cityStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";			
				document.getElementById("cityChecker").innerHTML="0";
			}else{
				document.getElementById("cityError").innerHTML="";
				document.getElementById("cityStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
				document.getElementById("cityChecker").innerHTML="1";
			};	
		}else{
			document.getElementById("cityError").innerHTML="";
			document.getElementById("cityStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
			document.getElementById("cityChecker").innerHTML="0";
		};
	};
	
	function checkStreet(){
		if(document.getElementById("editUlica").value!=""){
			if(document.getElementById("editUlica").value.length<2){
				document.getElementById("streetError").innerHTML="Minimálne 2 znaky.";
				document.getElementById("streetStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";			
				document.getElementById("streetChecker").innerHTML="0";
			}else{
				document.getElementById("streetError").innerHTML="";
				document.getElementById("streetStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
				document.getElementById("streetChecker").innerHTML="1";
			};	
		}else{
			document.getElementById("streetError").innerHTML="";
			document.getElementById("streetStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
			document.getElementById("streetChecker").innerHTML="0";
		};
	};
	
	function checkNumber(){
		if(document.getElementById("editCislo").value!=""){			
				document.getElementById("numberError").innerHTML="";
				document.getElementById("numberStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
				document.getElementById("numberChecker").innerHTML="1";	
		}else{
			document.getElementById("numberError").innerHTML="";
			document.getElementById("numberStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
			document.getElementById("numberChecker").innerHTML="0";
		};
	};
	
	function checkCustomerPostCode(){
		if(document.getElementById("editPSC").value!=""){		
			if(isNaN(document.getElementById("editPSC").value)===true) {
				document.getElementById("PSCError").innerHTML="Iba číslice.";
				document.getElementById("PSCStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";			
				document.getElementById("PSCChecker").innerHTML="0";		
			}else if(document.getElementById("editPSC").value.length!=5){
				document.getElementById("PSCError").innerHTML="5 číslic.";
				document.getElementById("PSCStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";			
				document.getElementById("PSCChecker").innerHTML="0";
			}else{
				document.getElementById("PSCError").innerHTML="";
				document.getElementById("PSCStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
				document.getElementById("PSCChecker").innerHTML="1";
			}		
		}else{
			document.getElementById("PSCError").innerHTML="";
			document.getElementById("PSCStatus").innerHTML = "<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='18' style='margin-left:10px;margin-top:6px'>";	
			document.getElementById("PSCChecker").innerHTML="0";
		}
	};
	
document.addEventListener("keyup", function(){
	if(document.getElementById("nameChecker").innerHTML=="1"){
		
		document.getElementById("finallyGengeralCustomer").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'>Editácia zákazníka</h3>";			
		document.getElementById("finallyStatusCustomer").innerHTML="1";
	}else{
		document.getElementById("finallyGengeralCustomer").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'>Editácia zákazníka</h3>";	
		document.getElementById("finallyStatusCustomer").innerHTML="0";
	}
});

document.addEventListener("keyup", function(){
	if(document.getElementById("cityChecker").innerHTML=="1" && document.getElementById("streetChecker").innerHTML=="1" && document.getElementById("numberChecker").innerHTML=="1" && document.getElementById("PSCChecker").innerHTML=="1"){		
		document.getElementById("finallyAdressCustomer").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'>Adresa spoločnosti</h3>";			
		document.getElementById("finallyStatusAdress").innerHTML="1";
	}else{
		document.getElementById("finallyAdressCustomer").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'>Adresa spoločnosti</h3>";	
		document.getElementById("finallyStatusAdress").innerHTML="0";
	}
});

document.addEventListener("keyup", function(){
	if(document.getElementById("finallyStatusCustomer").innerHTML=="1" && document.getElementById("finallyStatusAdress").innerHTML=="1"){
		document.getElementById("submitSpan").style.visibility = "visible";	
	}else{
		document.getElementById("submitSpan").style.visibility = "hidden";	
	}
});
</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 id="finallyStatusCustomer" hidden>1</div>';
		echo '<div id="finallyStatusAdress" hidden>1</div>';
		
		echo form_open(base_url('manager/saveEditedCustomer/'. $Customer->ID_Zakaznik),'onkeypress="return event.keyCode != 13;"');
			echo '<span id="finallyGengeralCustomer">';
				echo "<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'>Editácia zákazníka</h3>";
			echo '</span>';
			echo '<table id="newCustomerInfoTable" style="margin-left:50px; margin-top:10px">';	
			echo '<tr>';
					echo '<td style="width:200px;padding-bottom:5px">';
						echo 'Identifikačné číslo: ';
					echo '</td>';
					echo '<td style="padding-bottom:5px">';
						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 {
								echo $Customer->ID_Zakaznik;
							}
					echo '</td>';
				echo '</tr>';
			
			echo "<tr>";
				echo "<td>";
					echo "Názov spoločnosti: ";
				echo "</td>";						
				echo "<td>";										
					echo form_input("editNazovSpolocnosti", $Customer->Nazov_spolocnosti , 'onkeyup="checkName()" id="editNazovSpolocnosti" class="login_textarea"');
				echo "</td>";
				echo "<td id='nameStatus'>";
					echo "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
				echo "</td>";
				echo "<td id='nameError'>";

				echo "</td>";
				echo "<td id='nameChecker' hidden>";
					echo "1";
				echo "</td>";
			echo "</tr>";	
			echo "<tr>";
				echo "<td>";
					echo "Typ spoločnosti: ";
				echo "</td>";						
				echo "<td>";										
					$options = array(
                  			'1'  => 'Lekáreň',
                  			'2'  => 'Hračkárstvo',
                  			'3'  => 'Kníhkupectvo',
                  			'4'  => 'Supermarket',
							'5'  => 'Pošta',
							'6'  => 'Odevy', 
							'7'  => 'Papierníctvo',
							'8'  => 'Kvetinárstvo',
							'9'  => 'Potraviny',
							'10'  => 'Železiarstvo',
							'11'  => 'Drogéria',	
							'12'  => 'Iné',						  
                );
						echo form_dropdown('editDruhSpolocnosti', $options, $Customer->ID_TYP_I , 'class="login_textarea" style="width:228px"');
				echo "</td>";
				echo "<td id='typeStatus'>";
					echo "<img src='http://martinbendik.studenthosting.sk/pictures/yes.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 "1";
				echo "</td>";
			echo "</tr>";	
			echo '</table>';
			echo "<div class='vehicle_div' style='align:center; margin-top:15px;margin-bottom:10px'>";
			echo "</div>";
			
			echo '<span id="finallyAdressCustomer">';
				echo "<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'>Adresa spoločnosti</h3>";
			echo '</span>';
			
			echo '<table id="newCustomerInfoTable" style="margin-left:50px; margin-top:10px">';	
			echo "<tr>";
				echo "<td  style='width:200px'>";
					echo "Mesto:";
				echo "</td>";						
				echo "<td>";										
					echo form_input("editMesto", $Customer->Mesto, 'onkeyup="checkCity()" id="editMesto" class="login_textarea"');
				echo "</td>";
				echo "<td id='cityStatus'>";
					echo "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
				echo "</td>";
				echo "<td id='cityError'>";

				echo "</td>";
				echo "<td id='cityChecker' hidden>";
					echo "1";
				echo "</td>";
			echo "</tr>";	
			echo "<tr>";
				echo "<td>";
					echo "Ulica: ";
				echo "</td>";						
				echo "<td>";										
					echo form_input("editUlica", $Customer->Ulica, 'onkeyup="checkStreet()" id="editUlica" class="login_textarea"');
				echo "</td>";
				echo "<td id='streetStatus'>";
					echo "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
				echo "</td>";
				echo "<td id='streetError'>";

				echo "</td>";
				echo "<td id='streetChecker' hidden>";
					echo "1";
				echo "</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td>";
					echo "Číslo domu: ";
				echo "</td>";						
				echo "<td>";										
					echo form_input("editCislo", $Customer->Cislo, 'onkeyup="checkNumber()" id="editCislo" class="login_textarea"');
				echo "</td>";
				echo "<td id='numberStatus'>";
					echo "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
				echo "</td>";
				echo "<td id='numberError'>";

				echo "</td>";
				echo "<td id='numberChecker' hidden>";
					echo "1";
				echo "</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td>";
					echo "Poštové smerovacie šíslo: ";
				echo "</td>";						
				echo "<td>";										
					echo form_input("editPSC", $Customer->PSC, 'onkeyup="checkCustomerPostCode()" id="editPSC" class="login_textarea"');
				echo "</td>";
				echo "<td id='PSCStatus'>";
					echo "<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='18'  style='margin-left:10px;margin-top:6px'>";
				echo "</td>";
				echo "<td id='PSCError'>";

				echo "</td>";
				echo "<td id='PSCChecker' hidden>";
					echo "1";
				echo "</td>";
			echo "</tr>";
			echo '</table>';
			echo "<div class='vehicle_div' style='align:center; margin-top:15px;margin-bottom:0px'>";
			echo "</div>";
			echo '<div class="button-group" style="margin-left:50px;margin-top:15px">';
				echo '<a href="javascript:window.history.go(-1);" class="button">Späť</a>';	
				echo '<span id="submitSpan" style="visibility:visible">';		
					echo form_submit('m_saveCustomer/'. $Customer->ID_Zakaznik  , 'Uložiť', 'class="button"');	
				echo '<span>';					
			echo '</div>';	
		echo '</div>';	
	} else {
		redirect(base_url('main/restricted'));
	}	
?>
	


