<?php
/*
Autor: Lic. Carlos Alberto Vaca Coronado
Version: 3.2.0
*/

session_name('portal_absa');
session_start();
require_once "conexion/conectar.php";

$conexion = new CONDB();
$conexion->conectar();

	$idReceptor=$_GET["idReceptor"];
	$rfc="";
	$tipodocto="";
	$rutaxml="";
	$rutapdf="";
	$usarRutaDistribuida="";
if(isset($_POST["id"]))
{
	$query="Select rfc from receptor where idReceptor='".$_GET["idReceptor"]."' LIMIT 1";
	
	
	$rquery=mysqli_query($conexion->CONEXION,$query);
	
	if(mysqli_num_rows($rquery) > 0){$temp=mysqli_fetch_array($rquery,MYSQLI_ASSOC); $rfc=$temp['rfc'];}
	
	$query="Select t.idReceptor as idReceptor, e.rfc as rfc, tipodocto, rutaxml_p, rutapdf_p, usarRutaDistribuida, adicional from tdoctos_r t, receptor e where t.idReceptor='".$_GET["idReceptor"]."' and tipodocto='".$_POST["id"]."' and t.idReceptor=e.idReceptor LIMIT 1";
	
	$rquery=mysqli_query($conexion->CONEXION,$query);
	
	if(mysqli_num_rows($rquery) == 1)
	{
		$temp=mysqli_fetch_assoc($rquery);
		$idReceptor=$temp["idReceptor"];
		$tipodocto=$temp["tipodocto"];
		$rutaxml=$temp["rutaxml_p"];
		$rutapdf=$temp["rutapdf_p"];
		$usarRutaDistribuida=$temp["usarRutaDistribuida"];
		$adicional=$temp["adicional"];
		$rfc=$temp['rfc'];

	}
}
?>
<script language="javascript" src="libs/Vanadium/vanadium.js"></script>
<script>
$j_6(document).ready(function() {
	$j_6('#loading').hide();
    $j_6().ajaxStart(function() {
        $j_6('#loading').show();
        $j_6('#result').hide();
    }).ajaxStop(function() {
        $j_6('#result').fadeIn('slow');
		$j_6('#loading').hide();
    });
	
	/*$j_3('#formDoc').ajaxForm(function(data) {
					if(data.indexOf('ERROR:') == -1){
						document.getElementById('tipodocto').readOnly=true;
					}
					$j_3('#result').html(data);
					$j_3('#loading').hide();
	});*/
	
	$j_6('#form, #fat, #formDoc').submit(function() {
        $j_6.ajax({
            type: 'POST',
            url: $j_6(this).attr('action'),
            data: $j_6(this).serialize(),
            success: function(data) {
					if(data.indexOf('ERROR:') == -1){
						document.getElementById('tipodocto').readOnly=true;
					}
					$j_6('#result').html(data);
					$j_6('#loading').hide();
            }
        })
        
        return false;
    });
	
   $j_6("#tipodocto").change(function () {
   		$j_6("#tipodocto").each(function () {
				var tipodocto=$j_6(this).val();
				$j_6.post("regresaDoc.php", { idReceptor: $j_6('#idReceptor').val(),tipodocto: tipodocto },function(data){
					if(data.indexOf("false:") != -1){
						var campos=data.replace('false:','').split('|');
						tipodocto=campos[0];
						alert('El documento '+tipodocto+' ya existe');
						$j_6("#tipodocto").val("<?=$tipodocto?>");
						$j_6("#tipodocto").focus();
						
					}
			}	);			
        });
   });
   
});
function maximo(campo,limite){
if(campo.value.length>=limite){
campo.value=campo.value.substring(0,limite);
 }
}

function pulsar(e) {
  tecla = (document.all) ? e.keyCode : e.which;
  return (tecla != 13);
}
</script>
<table>
		<tr>
		<td valign="top" class="txt_logindat" width="800" height="35"><div id="result"></div></td>
		</tr>
</table>
<table bgcolor="#FFFFFF">
		<tr>
			<td valign="top" class="txt_logindat" align="center"><center><h2>CONFIGURACION DE DOCUMENTO</h2></center></td>
		</tr>
</table>
        <form target="_self" action="altaDoc.php" method="post" name="formDoc" id="formDoc" onkeypress = "return pulsar(event)">
		<INPUT TYPE="hidden" NAME="reloadGridAfterSave" id="reloadGridAfterSave" value="<?=$_POST['reloadGridAfterSave']?>">
		<INPUT TYPE="hidden" NAME="valLiga" id="valLiga" value="<?=$_GET['valLiga']?>">
        <table class="td_general" bgcolor="#FFFFFF">
		<tr>
		<td valign="top" class="txt_logindat">
		<strong>RFC Receptor: * :</strong>
		<input type="hidden" name="idReceptor" value="<?=$idReceptor?>" id="idReceptor"/>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" size="23" maxlength="13" name="rfc" id="rfc" class=":required Logers" value="<?=$rfc?>" readOnly="true"/>
        </td>
        <td valign="top" class="txt_logindat">
        <strong>Documento * :</strong>
        </td>
        <td valign="top" class="txt_logindat">
        <input type="text" size="30" name="tipodocto" id="tipodocto" class=":required Logers" value="<?=$tipodocto?>" maxlength="30" <?if(isset($_POST['id']) && trim($_POST['id']) != ""){ echo "readOnly='true'";}?>/>
        <br><br>
        </td>
        </tr>
        <tr>
		<td valign="top" class="txt_logindat" colspan="3">
		<table>
		<tr>
        <td valign="top" class="txt_logindat" width="100">
        <strong>RutaXML * :</strong>
		</td>
		<td valign="top" class="txt_logindat" colspan="2">
		<input type="text" maxlength="255" size="60" name="rutaxml" id="rutaxml" class=":required Logers" value="<?=$rutaxml?>"/><br /><br />
		</td>
		</tr>
		<tr>
        <td valign="top" class="txt_logindat" width="75">
        <strong>RutaPDF * :</strong>
		</td>
		<td valign="top" class="txt_logindat" colspan="2">
		<input type="text" maxlength="255" size="60" name="rutapdf" id="rutapdf" class=":required Logers" value="<?=$rutapdf?>"/><br /><br />
		</td>
		</tr>
		<tr>
        <td valign="top" class="txt_logindat" width="75">
        <strong>Adicional :</strong>
		</td>
		<td valign="top" class="txt_logindat" colspan="2">
		<input type="text" maxlength="255" size="60" name="adicional" id="adicional" class="Logers" value="<?=$adicional?>"/><br /><br />
		</td>
		</tr>
		<tr>
        <td valign="top" class="txt_logindat" width="75">
        <strong>Ruta Distribuida * :</strong>
		</td>
		<td valign="top" class="txt_logindat" colspan="2">
		<select name="usarRutaDistribuida">
			<option value="SI" <?if($usarRutaDistribuida == "SI") echo "selected";?>>SI</option>
			<option value="NO" <?if($usarRutaDistribuida == "NO") echo "selected";?>>NO</option>
		</select><br /><br />
		</td>
		</tr>
		</table>
		</td>
        </tr>
        <tr>
        <td>
        <? echo btnNavegacion();?>
        </td>
        </tr>
		</table>
        </form>
<?
function btnNavegacion()
{
?>	
		<input type="submit" class="estilo_btn" value="GUARDAR"/>
<?
}