<?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'];
$ufid=$_GET['ufid'];
$tipo=2;

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



if(isset($_GET['save'])){
$ugid=$_GET['ugid'];
$ufid=$_GET['ufid'];
$tipof=$_GET['tipof'];
$apep=$_GET['apep'];
$apem=$_GET['apem'];
$nom=$_GET['nom'];
$tsexo=$_GET['tsexo'];
$fnac=$_GET['fnac'];

if($tsexo==1){
$sexo='F';
}
if($tsexo==2){
$sexo='M';
}
//echo $sexo;

$uno=substr($fnac, 0, 2);
$dos=substr($fnac, 3, 2);
$tres=substr($fnac, 6, 4);
$fnac = ($tres."/".$dos."/".$uno);

$sqlupdate="update tb_usufamiliar set uf_apepat=upper('$apep'), uf_apemat=upper('$apem'), uf_nom=upper('$nom'), ";
$sqlupdate=$sqlupdate." uf_fechanac='$fnac', uf_sexo=upper('$sexo') ";
$sqlupdate=$sqlupdate." where ug_id='$ugid' and uf_id='$ufid' and uf_tipo='2'";
//echo $sqlupdate;
$resulupdate = mysql_query($sqlupdate);
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";
echo "<script type='text/javascript'> document.location='listarfamiliar.php?ugid=".$ugid."'; </script>";
}

$sqlfamiliar="SELECT uf_id as id, uf_apepat as apepat, uf_apemat as apemat, uf_nom as nombre, uf_sexo as sexo,date_format(uf_fechanac,'%d/%m/%Y') as fechanac FROM tb_usufamiliar where ug_id='$ugid' and uf_tipo='2' and uf_id='$ufid';"; 

//echo $sqlpersonal;
$resultfamiliar = mysql_query($sqlfamiliar);
while ($row= mysql_fetch_array($resultfamiliar)){
$iduf=$row['id'];
$fechanac=$row['fechanac'];
$sexo=$row['sexo'];
$apepat=$row['apepat'];
$apemat=$row['apemat'];
$nom=$row['nombre'];
if($fechanac=="00/00/0000"){
$fechanac="dd/mm/aaaa";
}
}
echo "<input type='hidden' id='cfam' name='cfam' value='".$iduf."'>";

$cadsexo = "<select id='tsexo' name='tsexo'>";
$cadsexo = $cadsexo."<option value='0'>Seleccione</option>";
$cadsexo = $cadsexo."<option value='1' "; 
if($sexo=='F'){
$cadsexo = $cadsexo." selected ";
}
$cadsexo = $cadsexo." >F</option>";
$cadsexo = $cadsexo."<option value='2' "; 
if($sexo=='M'){
$cadsexo = $cadsexo." selected ";
}
$cadsexo = $cadsexo." >M</option>";
$cadsexo = $cadsexo."</select>";

?>
<html>
<title>DATOS DEL FAMILIAR</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='' >
<table align='center' class='FacetFormTABLE'>
<tr><td colspan='2'align='center' class='FacetFieldCaptionTD'><b><font color='blue'>DATOS DEL FAMILIAR: <?php echo $destipo; ?></font></b></td></tr>
<?php
$error=$_GET['error'];
if($error =="1"){
echo "<tr><td colspan='2'  align='center'><font color='red'>LOS PASSWORDS NO SON IGUALES</font></td></tr>";
}
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";
echo "<input type='hidden' id='tfam' name='tfam' value='".$tipo."'>";
echo "<input type='hidden' id='ufid' name='ufid' value='".$ufid."'>";
setlocale(LC_TIME,"spanish"); 


?>
<br>
<tr><td colspan='2' align='center'>
<table align='center' class='FacetFormTABLE'>
<tr><td class='FacetFieldCaptionTD'width='110'>APE. PATERNO</td><td width='250'><input type='text' id='apep' class='FacetInput' size='30' value='<?php echo $apepat;?>'></td></tr>
<tr><td class='FacetFieldCaptionTD'>APE. MATERNO</td><td><input type='text' id='apem'class='FacetInput' size='30' value='<?php echo $apemat;?>'></td></tr>
<tr><td class='FacetFieldCaptionTD'>NOMBRES</td><td><input type='text' id='nom' class='FacetInput' size='40' value='<?php echo $nom;?>'></td></tr>
<tr><td class='FacetFieldCaptionTD'>TIPO DE SEXO</td><td><?php echo $cadsexo;?></td></tr>
<tr><td class='FacetFieldCaptionTD'>FECHA NAC</td><td><input type='text' id='fnac' name='fnac' class='FacetInput' onblur='validarFNac()' size='15' value='<?php echo $fechanac;?>'></td></tr>
</table>
</td></tr>
<tr><td align='center'><input type='button' value='Grabar'id='save' onCLick='GrabardatosHijo()' class='FacetButton'></td><td align='center'><input type='button' value='Cancelar' onCLick='ventanaClose()' id='cancel' class='FacetButton'></td></tr>
</table>
</form>
</body>
</html>