<?php use_helper('UrlFunctions'); ?>
<script>
findControl = function(){
  
  concatValueStr();
  
}

exportFindControl = function(action){
  strFormSerialize = returnQueryStringForm();
  executeFind(strFormSerialize, action);
}

executeFind = function(str, action){
  if(typeof(action) == 'undefined'){
	  url = "<?=buildUrl('cli/gridTelefonosTelefonos', "block=".$block)?>";
	}else{
	  switch (action){
	    case 'excel': parent.objMainTab.reqBody('<?=buildUrl('cli/excel')?>','001&'+str); break;
	    case 'pdf': parent.objMainTab.reqBody('<?=buildUrl('cli/pdf')?>','001&'+str); break;	    
	  }
	  
	  return;
	}
  //str = str + '&block=001';
  url = "<?=buildUrl('cli/gridTelefonos', "block=".$block)?>";
	var myAjax  = new Ajax.Updater(
                                	"resultGrtid",
                                	url,
                                	{
                                		asynchronous:	true,
                                		method			: 'get',
                                		parameters	: str,
                                		evalScripts	: true,
                                		onLoading   : cargandoImagenSerch(),
                                		onComplete	: function(){
                                			//objMainTab.showMenu();
                                		}
                                	});
}

concatValueStr = function(){
  strFormSerialize = returnQueryStringForm();
  if(arguments[0]){
    strFormSerialize += '&'+arguments[0];
  }
  executeFind(strFormSerialize);
}

function returnQueryStringForm(){
  cadenaFormulario = $('form1').serialize();
             var posicion = new Array();
             var a_pars = new Array();
             var miArray = new Array();
             posicion=[];
             a_pars=[];
             miArray=[];
             miArray = cadenaFormulario.split('&');
             x=0;
             for (i = 0; i < miArray.length; i++){
            	   posicion[i] = miArray[i].indexOf('=');
            	   if(typeof(miArray[i-1])!='undefined'){
            				if(miArray[i].substring(posicion[i],0)== miArray[i-1].substring(posicion[i-1],0) ){
           					 porcion = miArray[i].substring((1+posicion[i]));
           					 a_pars[x-1]+='@'+porcion;
           				}else{
          					 a_pars[x]= miArray[i];
         					 x++;
          				}
          		}else{
          			 a_pars[x]= miArray[i];
          			  x++;
          		}
           }
  cadenaFormulario = a_pars.join('&');
  cadenaFormulario += '&id_form=frmFindFedu';
  return(cadenaFormulario);
}

function cargandoImagenSerch(){
	//disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
}

</script>
<script>
findControl = function(){
  
  var pars = $('form1').serialize();
  
	disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
  
	url = "<?=buildUrl('cli/gridTelefonos', "block=".$block)?>";
	var myAjax  = new Ajax.Updater(
	"resultGrtid",
	url,
	{
		asynchronous:	true,
		method			: 'get',
		parameters	: pars,
		evalScripts	: true,
		onLoading		: function(){
			//$('contentMenu').innerHTML = $('messageLoadMenu').innerHTML;
		},
		onComplete	: function(){
			//objMainTab.showMenu();
		}
	});
  
}

deleteRegistro = function(id,numero){
  //buildUrl('cli/delete/id/'block=001'
  if(confirm("Esta seguro de eliminar el Telefono con : "+numero+ " ?")){
      //objMainTab.reqBody('<? //=buildUrl('cli/add')?>','block=001&delete=1&id='+id);   
      parent.objMainTab.reqBody('<?=buildUrl('cli/deleteTelefono')?>','&delete=1&cod=jj&id='+id+'&idCliente=<?php echo $id;?>');
  }
  
}

acutalizarEspecialidad = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrl('ajax/request')?>';
  var pars = 'type=getEspecialidad&nombreElm='+destino+'&value='+elm.value;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}

</script>
<script>
actualizaJSON = function(request, json){
  var numeroElementos = json.length;
  for (var i = 0; i < numeroElementos; i++){
    if($(json[i][0])){
  	  switch ($(json[i][0]).tagName){
  	    case 'TD'      : Element.update(json[i][0], json[i][1]); break;
  	    case 'INPUT'   : $(json[i][0]).value=json[i][1]; break;
  	    case 'SELECT'  : 
  	      var objDDL = $(json[i][0]);
  	      if(typeof(cont) == 'undefined'){
  	        var cont = 0;
  	        objDDL.options.length = 1;
  	      }
  	      var a_contentValues = json[i][1].split("_;_");
      		var value	= a_contentValues[0];
      		var text	= a_contentValues[1];
  	      var option	= new Option(text,value);
      		try{
      			objDDL.add(option,null);
      		}catch (e){
      			objDDL.add(option,-1);
      		}
  	      cont++;
  	    break;
  	  }
    }else{
      if(json[i][0].indexOf("function") > -1){
        eval("scriptEval = "+json[i][0]);
        scriptEval();
      }
    }
  }
}
</script>
<?php

//Lista de Operadores
$o_OperadorFN = new CrTelefonoOperadorFN();
$o_OperadorFN->setEstado('A');
$a_o_OperadorFN = $o_OperadorFN->select();

//Lista de Fuentes
$o_TipoFN = new CrTelefonoTipoFN();
$o_TipoFN->setEstado('A');
$a_o_TipoFN = $o_TipoFN->select();
	
if($idcliente) $id = $idcliente;

$o_ClienteBean = new ClienteBean();
$o_ClienteBean->setIdCliente($id);
$o_class = new ClienteBL();
$a_ObjectBean = $o_class->busquedaCliente($o_ClienteBean);

//Cargar Documento
 $o_ClienteSystemClass = new ClienteSystemClass(new DocumentoBean());
 $a_o_Documento = $o_ClienteSystemClass->getDocumento();
  
$o_DocumentoClienteBean = new DocumentoClienteBean();
$o_DocumentoClienteBean->setIdCliente($id);
$o_DocumentoClienteBL = new DocumentoClienteBL();
$a_o_documento = $o_DocumentoClienteBL->busquedaDocumentoClienteDetalle($o_DocumentoClienteBean);
if(is_array($a_o_documento)){
	foreach ($a_o_documento as $key =>$o_documento){
		$a_id_documento[] = $o_documento->getIdDocumento();
	}
}

if(is_array($a_ObjectBean)){
  while(list($key,$o_ObjectBean) = each($a_ObjectBean)){
  	if(!$nofiltro)
  	
  	
?>

<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="0">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody">
            <li>Cliente<span class="subtitle"><I>&nbsp;:::&nbsp;Tel&eacute;fonos</I></span></li>
            </td>
          <td align="right" valign="baseline">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td valign="top">
     <form id="form1" name="form1" method="POST">
      <input type="hidden" value="<?php echo $id;?>"	name="IdCliente" />
      <input type="hidden" value="<?php echo $nofiltro;?>"	name="nofiltro" />
      <input type="hidden" name="control" value="1">
      
      	<?php
	    $s_Param = '';
	    if( isset( $id ) )
	    {
	        $s_Param = 'id='.$id;
	    }
	    if(!$sinTabs)
	    {
	    ?>
	    <table id="tabShowScan" cellpadding="0" cellspacing="0" class="" style="margin-top: 5px;">
	        <tr>
	          <td class="mnuInactivoIzq" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="7"></td>
	          <td class="mnuInactivoTxt" type='maintTabguiaGeneral' nowrap onclick="location.href='<?php echo buildUrl('cli/edit', $s_Param) ?>';">Datos Personales</td>
	          <td class="mnuInactivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>
	          <?php if( isset( $id ) && $id != "" ){ ?>
	          <td class="mnuInactivoIzq" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="7"></td>
	          <td class="mnuInactivoTxt" type='maintTabguiaGeneral' nowrap onclick="location.href='<?php echo buildUrl('cli/datAval', $s_Param) ?>';">Datos del Garante</td>
	          <td class="mnuInactivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>
	          
	          <td class="mnuInactivoIzq" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="7"></td>
	          <td class="mnuInactivoTxt" type='maintTabguiaGeneral' nowrap onclick="location.href='<?php echo buildUrl('cli/datCony', $s_Param) ?>';">Datos del Conyuge</td>
	          <td class="mnuInactivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>
	          
	          <td class="mnuActivoIzq" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="7"></td>
	          <td class="mnuActivoTxt" type='maintTabguiaGeneral' nowrap onclick="location.href='<?php echo buildUrl('cli/telefonos', $s_Param) ?>';">Telefonos</td>
	          <td class="mnuActivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>
	          
	          <?php } ?>
	        </tr>
	    </table>
	    <?php } ?>
        <table hspace="20px" class="marco" width="96%">
          <tr>
            <td valign="top">
	
              <table width="100%" border="0" cellpadding="5" cellspacing="0" style="background: #E3E9E2">
          		<tr>
    				  <td height="0">
    				  
    					 <table width="100%" border="0" cellspacing="6" cellpadding="0">
    					 	<tr>
	    					 	<td colspan="2">
	    					 		<fieldset>
    									<legend class="fielsettex"><I>Cliente</I></legend>
				    					 	<table cellpadding="2" cellspacing="0">
				    					 		  <tr>
													<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtDniCliente" >DNI </label></td>
													<td colspan="5" nowrap="nowrap"><label class="label"><?php echo $o_ObjectBean->getDni();?></label></td>
													 
													 
												   </tr>
												   <tr>
													<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtNombres" >Nombres </label></td>
													<td nowrap="nowrap"><label class="label"><?php echo $o_ObjectBean->getNombres();?></label></td>
													
													<td nowrap="nowrap"  class="cabecera"><label class="label" for="txtApellidoPaterno">Apellido Paterno </label></td>
													<td nowrap="nowrap" ><label class="label"><?php echo $o_ObjectBean->getApellidoPaterno();?></label></td>
												 
													<td nowrap="nowrap" class="cabecera"><label class="label" for="txtApellidoMaterno" >Apellido Materno </label></td>
													<td nowrap="nowrap"><label class="label"><?php echo $o_ObjectBean->getApellidoMaterno();?></label></td>
												  </tr>
											  
											  </table>
										</fieldset> 
										<fieldset  style="background:#ffffff">
    										<legend class="fielsettex"><I></I></legend>
    										<table border="0" cellpadding="0" cellspacing="0" width="100%" >
									        <tr>
									          <td class="titleBody" background="#FFFFFF" ><li>&nbsp;&nbsp;Lista de Telefonos</li></td>
									          <td align="right" valign="baseline">
									            <!--<img name="add" title="Nuevo Cliente" src="/images/common/buttons/btnAdd.gif" onClick="parent.objMainTab.modalDialog('<?=buildUrl('cli/add')?>','001')" style="cursor:pointer">-->
									            <?php
											       if(!$nofiltro)
												    {?>
									            <img name="add" src="/images/common/buttons/btnAdd.gif" onClick="objMainTab.modalDialog('<?=buildUrl("cli/addEditTelefono","IdCliente=".$id)?>',{title:'Nuevo telefono',width:510,height:230})" style="cursor:pointer">
									            <?php } ?>
									          </td>
									        </tr>
									      </table>
									      <?php
									       if(!$nofiltro)
										    {?>
				    					 	<table cellpadding="2" cellspacing="0" >
				    					 		  <tr>
													<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtDniCliente" >Fuente </label></td>
													<td colspan="5" nowrap="nowrap">
														<select class="combo " name="IdPertenece" id="IdPertenece" >
						                  				  <option value="" > - Seleccionar - </option>
						                  				  <option value="Cliente">Cliente</option>
						                  				  <option value="Garante">Garante</option>
						                  				  <option value="Conyuge">Conyuge</option>
						                				</select>
													</td>
												  
													<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtNombres" >Operador </label></td>
													<td nowrap="nowrap">
														<select class="combo " name="IdOperador" id="IdOperador" >
						                  				  <option value="" > - Seleccionar - </option>
						                 				  <?php foreach ($a_o_OperadorFN as $iKey => $o_OperadorFN){ ?>
						                  				  <option value="<?=$o_OperadorFN->getIdOperador()?>">
						                    			 <?=$o_OperadorFN->getDescripcion()?>
						                   	              </option>
						                  					<?php } ?>
						                				</select>
						                				
													</td>
													<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtDniCliente" >Tipo </label></td>
													<td colspan="5" nowrap="nowrap">
														<select class="combo" name="IdTipo" id="IdTipo" >
						                  				  <option value="" > - Seleccionar - </option>
						                 				  <?php foreach ($a_o_TipoFN as $iKey => $o_TipoFN){ ?>
						                  				  <option value="<?=$o_TipoFN->getIdTipoTelefono()?>">
						                    			 <?=$o_TipoFN->getDescripcion()?>
						                   	              </option>
						                  					<?php } ?>
						                				</select>
													</td>
													<td align="right" style="vertical-align:top" colspan="5"><input class="button" type="button" value="Buscar" onclick="findControl();"/></td>
												  </tr>
											  
											  </table>
											 <?php } ?>
										</fieldset> 
										 
								  </td>
							  </tr>
							  
							  <tr>
	    					 	<td colspan="2" style="background:#ffffff">
	    					 		 <div id="resultGrtid">
      								</div>
								  </td>
							  </tr>
						</table>
    							
    				</td>
                </tr>
                <?php
											       if(!$nofiltro)
												    {?>
    			<tr>
    			
  				  <td height="0" width="100%">
				   
    			 	 
  				   <table width="100%" border="0" cellspacing="0" cellpadding="0">
				  	<tr>
					<td><img src="/images/common/spacer.gif" width="10"></td>
					 </tr>
						<tr>
						 <td align="center">
						  <input type="hidden" name="typeSubmit" id="typeSubmit">
						  
						   <input class="button" type="button" value="Anterior" onclick="location.href='<?=buildUrl('cli/datAval', $s_Param)?>'"/>
						   <input class="button" type="button" value="Cancelar" onclick="location.href='<?=buildUrl('cli/list','&block=001')?>'"/>
						  </td>
						</tr>
						<tr>
					<td height="10">&nbsp;</td>
				 </tr>
			    </table>
			    </td>
			   </tr>
			   <?php } ?>
        		</tr>
				<tr>
      			</table>
     		</form>
			
			</td>
  		  </tr>
		</table>
    </td>
  </tr>
</table>
<?php
  }
}
?>
<script>
	elementLoad.show(undefined,"Cargando............");
	setTimeout("elementLoad.hide()",1000);   
	findControl();
</script>
