<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">						
<html>
	<head>
	
	<link rel="stylesheet" href="css/dragcss.css" media="screen" type="text/css" />
	<link rel="stylesheet" href="css/font-awesome.min.css">
	<link rel="stylesheet" href="css/styles.css">
	<script src="js/jquery-3.6.3.min.js"></script>
	<script type="text/javascript">
	/**
	$(document).ready(function() {	
		$('#player_name').on('blur', function() {
			$('#result-playername').html('<img src="images/loader.gif" />').fadeOut(1000);
	 
			//var query = 'buscar';
			var player_name = $(this).val();		
			var dataString = 'player_name='+player_name;
			var params = {
				query : 'buscar',
				//dataString : 'player_name='+player_name
				player_name : player_name
			}
			
	 
			$.ajax({
				type: "POST",
				url: "_functions_aux.php",
				data: params,

				success: function(data) {
					$('#result-playername').fadeIn(1000).html(data);
				}
			});
		});              
	});
**/
function validarForm(formlist)
{
	//$('#result-playername').html('<img src="images/loader.gif" />').fadeOut(1000);
	if(formlist.res_x.value.length > 0)
	{
		
		if(formlist.res_y.value.length > 0)
		{
			
			if(formlist.x0.value.length > 0)
			{
				
				if(formlist.y0.value.length > 0)
				{
					if(formlist.player_name.value.length > 0)
					{	
				
				
						//var query = 'buscar';
						var player_name = $('#player_name').val();		
						var dataString = 'player_name='+player_name;
						var params = {
							query : 'buscar',
							//dataString : 'player_name='+player_name
							player_name : player_name
						}
						
				 
						$.ajax({
							type: "POST",
							url: "_functions_aux.php",
							data: params,

							success: function(data) {
								if(data == 'true')
								{
									formlist.player_name.focus();
									//$('#result-playername').html(data);
									$('#result-playername').html('El nombre del Reproductor existe, favor intente con otro nombre.');
									//return false;
								}
								else
								{	
									if(data == 'false')
									{
										$('#result-playername').html('else'+data);
										formlist.submit();
									}
									
								}
							}
						});
					}
					else
					{
						formlist.player_name.focus();
						$('#result-playername').html('El campo de "Nombre de Reproductor" no puede estar vacio.');
					}
				}
				else
				{
					formlist.y0.focus();
					$('#result-playername').html('El campo de "Eje Y" no puede estar vacio.');
				}
			}
			else
			{
				formlist.x0.focus();
				$('#result-playername').html('El campo de "Eje X" no puede estar vacio.');
			}
		}
		else
		{
			formlist.res_y.focus();
			$('#result-playername').html('El campo de "Alto" no puede estar vacio.');
		}
	}
	else
	{
		formlist.res_x.focus();
		$('#result-playername').html('El campo de "Ancho" no puede estar vacio.');
	}
}
	</script>
	
<?php

			
			function escribir_horainicio()
			{
				$horarios = "";
				for($h=0; $h<=23; $h++)
				{
					if($h < 10)
					{
						$h = "0".$h;
					}
					for($m=0; $m<=59; $m=$m+15)
					{
						if($m < 10)
						{
							$m = "0".$m;
						}
						if(($h == '07')&&($m == '00'))
						{
							$horarios .= "<option value='".$h.":".$m."' selected >".$h.":".$m."</option>";
						}
						else
						{
							$horarios .= "<option value='".$h.":".$m."'>".$h.":".$m."</option>";
						}
					}
				}
				$horarios .= "<option value='23:59'>23:59</option>";
				return $horarios;
			}
			
			function escribir_horafin()
			{
				$horarios = "";
				for($h=0; $h<=23; $h++)
				{
					if($h < 10)
					{
						$h = "0".$h;
					}
					for($m=0; $m<=59; $m=$m+15)
					{
						if($m < 10)
						{
							$m = "0".$m;
						}
						$horarios .= "<option value='".$h.":".$m."'>".$h.":".$m."</option>";
					}
				}
				$horarios .= "<option value='23:59' selected >23:59</option>";
				return $horarios;
			}
?>
	</head>
	<body>
		<form method='post' action='_player_new.php' name='formlist' id='formlist' >
			Nombre de Reproductor : <input type='text' name='player_name' id='player_name' size='40' required /><br>
			<div id="result-playername"></div>
			<label>Resolución de reproducción</label><br>
			Ancho x Alto ( px )<br>
			<input type='number' name='res_x' id='res_x' size='5' required />&nbsp;&nbsp;x&nbsp;&nbsp;<input type='number' name='res_y' id='res_y' size='5' required />px<br>
			
			Posicion Inicial de Reproducción( Vértice Superior Izquierdo )<br>
			Eje X    Eje Y  ( Cero, cero (0, 0) o vacio )<br>
			<input type='number' name='x0' id='x0' size='5' required />&nbsp;&nbsp;x&nbsp;&nbsp;<input type='number' name='y0' id='y0' size='5' required />px<br>
			
			<br>
			
			Hora Inicio  : <select id="hour_start" name='hour_start' onChange="calcular(document.getElementById('time3').value, document.getElementById('time4').value);"/><?php echo escribir_horainicio(); ?></select><br>
			Hora Termino : <select id="hour_end" name='hour_end' onChange="calcular(document.getElementById('time3').value, document.getElementById('time4').value);"/><?php echo escribir_horafin(); ?></select><br>
			<!-- Horas de Reproducción : <input type="text" id="dif" name='dif' size="10" style='color: #444;' value="16:59" /> -->
			<br>
		<input type="button" value="Enviar" onClick='validarForm(formlist);'>
		</form>
	</body>
</html>