<?php
include("../bd/sql_variables.php");

$db_conexion= mysql_connect("$sql_host", "$sql_usuario", "$sql_pass") or die(header ("No Disponible Servidor de Base de Datos"));
mysql_select_db("$sql_db");

$ugid=$_GET['ugid'];
//$tipo=$_GET['tipo'];

if($tipo==1){
$destipo=' ESPOSO(A)';}
if($tipo==2){
$destipo=' HIJOS(AS)';}

?>
<html>
<title>LISTADO DE HIJOS</title>
<head>
<script type="text/javascript"> 
function ventanaClose(){ 
   //alert("hola mundo");
    window.close();
}

function validaFechaDDMMAAAA(fecha){    
var dtCh= "/";    
var minYear=1900;
var maxYear=2100;
        function isInteger(s){
        var i;     
		for (i = 0; i < s.length; i++){ 
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
        }
        return true;
		}
		function stripCharsInBag(s, bag){
        var i;
        var returnString = ""; 
		for (i = 0; i < s.length; i++){ 
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;        }
        return returnString;    }
		function daysInFebruary (year){
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );    }
		function DaysArray(n) {
        for (var i = 1; i <= n; i++) { 
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}        
		} 
		return this
		}    
		function isDate(dtStr){
        var daysInMonth = DaysArray(12) 
		var pos1=dtStr.indexOf(dtCh) 
		var pos2=dtStr.indexOf(dtCh,pos1+1) 
		var strDay=dtStr.substring(0,pos1)
        var strMonth=dtStr.substring(pos1+1,pos2)
        var strYear=dtStr.substring(pos2+1)
        strYr=strYear
        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)        
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)        
		for (var i = 1; i <= 3; i++) {            
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }        
		month=parseInt(strMonth)        
		day=parseInt(strDay)        
		year=parseInt(strYr)        
		if (pos1==-1 || pos2==-1){            
		return false        }        
		if (strMonth.length<1 || month<1 || month>12){            
		return false        }       
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{            return false        }        
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){ 
		return false        }        
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		{            return false        }        
		return true    }    
		if(isDate(fecha))
		{        return true;    }
		else{        return false;    }
}

function validarFNac(){ 
var fnac = document.getElementById('fnac').value;	
	if(fnac != "" )
	{
		if(validaFechaDDMMAAAA(fnac) == false){
		alert("La Fecha No Esta Escrita Correctamente");
		document.getElementById('fnac').value='dd/mm/aaaa';
		document.getElementById('fnac').focus();
		}
	}
}

function LimpiarFNac(){
document.getElementById('fnac').value="";
//document.getElementById('fnac').focus();
}


function validarSiNumero(numero){
    if (!/^([0-9])*$/.test(numero))
      return false;
}

function mis_datos(){
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}}

</script>
<link rel="stylesheet" type="text/css" href="styles/Style.css">
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
<link rel="stylesheet" type="text/css" href="styles/Style.css">
<link type="text/css" rel="stylesheet" href="src/css/jscal2.css" />
    <link type="text/css" rel="stylesheet" href="src/css/border-radius.css" />
    <!-- <link type="text/css" rel="stylesheet" href="src/css/reduce-spacing.css" /> -->

    <link id="skin-win2k" title="Win 2K" type="text/css" rel="alternate stylesheet" href="src/css/win2k/win2k.css" />
    <link id="skin-steel" title="Steel" type="text/css" rel="alternate stylesheet" href="src/css/steel/steel.css" />
    <link id="skin-gold" title="Gold" type="text/css" rel="alternate stylesheet" href="src/css/gold/gold.css" />
    <link id="skin-matrix" title="Matrix" type="text/css" rel="alternate stylesheet" href="src/css/matrix/matrix.css" />

    <link id="skinhelper-compact" type="text/css" rel="alternate stylesheet" href="src/css/reduce-spacing.css" />

    <script src="src/js/jscal2.js"></script>
	<!--script src="src/js/lang/en.js"></script-->
    <!-- you actually only need to load one of these; we put them all here for demo purposes -->
     <script src="src/js/lang/es.js"></script>
    
    <link type="text/css" rel="stylesheet" href="demopage.css" />
	
</head>
<body>
<form action='' >
<br>
<?php
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";

$cadena = $cadena."<table align='center' class='FacetFormTABLE'>";
$cadena = $cadena."<tr><td colspan='5'align='center' class='FacetFieldCaptionTD'><b><font color='blue'>LISTADO DE HIJOS DEL PERSONSAL ASISTENCIAL</font></b></td></tr>";
$cadena = $cadena."<tr><td align='center' class='FacetFieldCaptionTD' width='250'>APELLIDOS Y NOMBRES</td><td align='center' class='FacetFieldCaptionTD' width='40'><b>SEXO</b></td><td align='center' class='FacetFieldCaptionTD' width='80'><b>FECHA NAC.</b></td><td align='center' class='FacetFieldCaptionTD' width='20' ><b>EDAD</b></td><td align='center' class='FacetFieldCaptionTD' width='30' ><b>EDITAR</b></td></tr>";

$sqlask = "select uf_id as id, concat(uf_apepat,' ',uf_apemat,' ',uf_nom) as nombre, uf_sexo as sexo, date_format(uf_fechanac,'%d/%m/%Y') as fechanac,  (datediff(now(), uf_fechanac)) div 365 AS edad from tb_usufamiliar where ug_id='$ugid' and uf_tipo='2' ";
$resultask = mysql_query($sqlask);
if(mysql_num_rows($resultask)!=0){
while ($row= mysql_fetch_array($resultask)){
$cadena = $cadena."<tr><td align='center'>".$row['nombre']."</td><td align='center'>".$row['sexo']."</td><td align='center' >".$row['fechanac']."</td><td align='center'>".$row['edad']."</td><td align='center'><input type='button' class='FacetButton' value='Editar' onCLick=editarhijo(".$row['id'].")></td></tr>";
}
$cadena = $cadena."</table>";
echo $cadena;
}else{
echo "<center><b><font color='blue'>No existe ningun registro</font></b></center>";
}
?>
</form>
</body>
</html>