// JavaScript Document
// Constantes
var COD_CENTRO_JUB = 0, 
    DESC_CENTRO_JUB = 1,
    COD_UGL_CENTRO = 2, 
    CALLE = 3, 
    COD_POSTAL = 4,
    LOCALIDAD = 5, 	
    RNEJP = 6,
    TELEFONO = 7,	
    SERVICIOS = 8,
	LST_SERVICIOS = 9;

var COD_UGL = 0, 
    DESC_UGL = 1;
	
var CODIG_SERV = 0,
    NOMBR_SERV = 1,
    PROFR_SERV = 2,
	HRATE_SERV = 3,
	PERIO_SERV = 4,
	MONTO_SERV = 5,
	FECHA_SERV = 6;
	
var	MONTO_TURISMO = 2,
	FECHA_TURISMO = 3;
	

// Variables Globales
var centrosJubilados = new Array();


// Manejadores de Eventos
function verInformacion() {
var errorMsg = validaIngreso();

   	if (errorMsg=='') {  
      centrosJubilados = getData('getCentrosJub()');	  
      if (centrosJubilados.length == 0) {
         alert('No hay Centros de Jubilados con las condiciones ingresadas\t');
	  }
	  else if (centrosJubilados.length == 1) {
         detalleCentroJub(0);
	  }
	  else if (centrosJubilados.length > 1) {
         listaCentrosJub();
	  }
   }
   else {
      alert(errorMsg);
   }
}

// Rutinas Auxiliares
function getData(phpFunc) {
var datos = new Array();
var opciones;

    document.getElementById('accion').value = phpFunc;
    opciones = {
       method:'post',
 	   parameters: $(document.getElementById('Form1')).serialize(),
	   asynchronous: false,
       onSuccess: function(t) {
                     datos = eval(t.responseText);
                  }, 
	   onFailure: function(t) {
                     alert('Error ' + t.status + ' -- ' + t.statusText);
                  }
    }
    new Ajax.Request('php/modulos/consCentrosJub.php',opciones);
	return datos;
}

function validaIngreso() {	
var codUGL = document.getElementById('LSTUgl').value;
var localidad = document.getElementById('TXTLocalidad').value;
var calle = document.getElementById('TXTCalle').value;
var codPostal = document.getElementById('TXTCodPostal').value;
var errorMsg = '';

   if (codUGL=='00' && localidad=='' && calle=='' && codPostal=='') {
      errorMsg = 'Debe ingresar una UGL, Localidad, Calle o Codigo Postal.\t\n';
   }
   return errorMsg
}


function initPage() {   	
   formIngreso();
}

function initListaUgls() {
var anOption;
var listaUgls = getListaUgls();
var aSelect = document.getElementById('LSTUgl');
var ugl;
   for (var i=0; i < listaUgls.length; i++) {
      anOption = document.createElement('option');	   	  
      ugl = listaUgls[i];
	  anOption.value = ugl[COD_UGL];
      anOption.text = ugl[DESC_UGL];  
	  agregarOpcion(aSelect, anOption);
   }  
}

function getListaUgls() {
var datos = new Array();
var opciones = {
	   method:'post',
	   postBody:'accion=getListaUgls()',
	   asynchronous:false,
       onSuccess: function(t) {
                     datos = eval(t.responseText);
                  }, 
	   onFailure: function(t) {
                     alert('Error ' + t.status + ' -- ' + t.statusText);
                  }
    }
    new Ajax.Request('php/modulos/consCentrosJub.php',opciones);
	return datos;
	
}

function agregarOpcion(aSelect, anOption) {
   try {
      aSelect.add(anOption, null); // standards compliant
   }
   catch(ex) {
      aSelect.add(anOption); // IE only
   }
}

function formIngreso() {
   document.getElementById('btnVolver').style.display="block";
   document.getElementById('LayerPpal').style.display="block";
   document.getElementById('LayerPpal').style.backgroundColor = "#EEEEEE";
   var innerHTML; 
   centrosJubilados = new Array();
   innerHTML =  '<form id="Form1" name="Form1" action="" method="post">'
   innerHTML += '<table width="500" border="0" id="Table1" class="textField">';
   innerHTML += '<tr>';
   innerHTML += '  <td width="21">&nbsp;</td>';
   innerHTML += '  <td width="86">&nbsp;</td>';
   innerHTML += '  <td width="320">&nbsp;</td>';
   innerHTML += '  <td width="55">&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>UGL</td>';
   innerHTML += '  <td><select id="LSTUgl" name="LSTUgl" class="inputTextField"></select></td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '<td>Localidad</td>';
   innerHTML += '<td><input id="TXTLocalidad" name="TXTLocalidad" type="text" class="inputTextField" size="38" maxlength="30"></td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>Calle</td>';
   innerHTML += '  <td><input id="TXTCalle" name="TXTCalle" type="text" class="inputTextField" size="60" maxlength="85"></td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td nowrap>C&oacute;digo postal </td>';
   innerHTML += '<td><input id="TXTCodPostal" name="TXTCodPostal" type="text" class="inputTextField" size="9" maxlength="8"></td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td colspan="4" align="left" style="padding-left:25px;">'
   innerHTML += '   <input id="BTNConsultar" type="image" src="../../images/botones/boton_verinfo.jpg" onClick="verInformacion()">';
   innerHTML += '  </td>';
   innerHTML += '</tr>';   
   innerHTML += '</table>';
   innerHTML += '<input id="accion" name="accion" type="hidden">';
   innerHTML += '</form>';
    if(navigator.appName == "Netscape") {
    if(navigator.platform == "MacIntel" ) {
//    t.style.marginLeft = "155px";
    document.getElementById('btnVolver').style.display="block";
    document.getElementById('LayerPpal').style.display="block";
    document.getElementById('LayerPpal').style.backgroundColor = "#EEEEEE";
    document.getElementById('LayerPpal').style.marginLeft = "250px";
    }
	}
   var t = document.createElement('div');
   t.innerHTML = innerHTML;

   document.getElementById('LayerPpal').innerHTML = "";
   document.getElementById('LayerPpal').appendChild(t);
   initListaUgls();
}

function listaCentrosJub() {
	document.getElementById('btnVolver').style.display="none";
var innerHTML; 
   innerHTML = '<div class="LayerLstCentrosJub">'; //  id="LayerLstCentrosJub"
   innerHTML += '<table id="lstCentrosJub" border="0" cellpadding="2" cellspacing="0" >';
   innerHTML += '<tr class="textField">';
   innerHTML += '  <td width="50" nowrap class="bordeaux">Ugl</td>';
   innerHTML += '  <td width="280" nowrap class="bordeaux">Nombre</td>';
   innerHTML += '  <td width="250" nowrap class="bordeaux">Calle</td>';
   innerHTML += '  <td width="100" nowrap class="bordeaux">CP</td>';
   innerHTML += '  <td width="170" nowrap class="bordeaux">Localidad</td>';
   innerHTML += '  <td width="135" nowrap class="bordeaux">Nº Inscripci&oacute;n</td>';
   innerHTML += '  <td width="250" nowrap class="bordeaux">Servicios</td>';
   innerHTML += '</tr>';
   
   var clase="gris";
   for (var i=0; i < centrosJubilados.length; i++) {
      centroJub = centrosJubilados[i];	 
      innerHTML += '<tr class="inputTextField" style="cursor:pointer" onClick="detalleCentroJub('+i+')">';
      innerHTML += '  <td width="50" nowrap class='+clase+'>'+centroJub[COD_UGL_CENTRO].substr(0,2)+'</td>';
      innerHTML += '  <td width="280" nowrap class='+clase+'>'+centroJub[DESC_CENTRO_JUB]+'</td>';
      innerHTML += '  <td width="250" nowrap class='+clase+'>'+centroJub[CALLE]+'</td>';
      innerHTML += '  <td width="100" nowrap class='+clase+'>'+centroJub[COD_POSTAL]+'</td>';
      innerHTML += '  <td width="170" nowrap class='+clase+'>'+centroJub[LOCALIDAD]+'</td>';
      innerHTML += '  <td width="135" nowrap class='+clase+'>'+centroJub[RNEJP]+'</td>';
      innerHTML += '  <td width="250" nowrap class='+clase+'>'+centroJub[SERVICIOS]+'</td>';
      innerHTML += '</tr>';
   if (clase == "gris") {
		clase = "blanco";
   } else if (clase = "blanco") {
		clase = "gris";
   }
   }  	      
   innerHTML += '</table>';   
   innerHTML += '</div>';
   
   innerHTML += '<table width="750">';         
   innerHTML += '<tr>';
   innerHTML += '  <td colspan="3" align="center">';
   innerHTML += '    <img src="../../images/botones/boton_volveraconsultar.jpg" onClick="formIngreso()" class="imgLink" style="cursor:hand; cursor: pointer;"/>';
   innerHTML += '  </td>';
   innerHTML += '</tr>';   
   innerHTML += '</table>';         
   var t = document.createElement('div');
   t.innerHTML = innerHTML;
   document.getElementById('LayerPpal').innerHTML = "";
   document.getElementById('LayerPpal').appendChild(t);
   
}

function detalleCentroJubOriginal(index) {
var innerHTML; 	
var centroJub = centrosJubilados[index];
   innerHTML  = '<table id="CentroJub" width="750" border="0" class="textField" cellpadding="5">';
   innerHTML += '<tr>';
   innerHTML += '  <td width="24">&nbsp;</td>';
   innerHTML += '  <td width="131">UGL</td>';
   innerHTML += '  <td width="331" class="inputTextField">'+centroJub[COD_UGL_CENTRO]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td nowrap="nowrap">Centro de Jubilados</td>';
   innerHTML += '  <td class="inputTextField">'+centroJub[DESC_CENTRO_JUB]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>Calle</td>';
   innerHTML += '  <td class="inputTextField">'+centroJub[CALLE]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>C&oacute;digo Postal </td>';
   innerHTML += '  <td class="inputTextField">'+centroJub[COD_POSTAL]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>Localidad</td>';
   innerHTML += '  <td class="inputTextField">'+centroJub[LOCALIDAD]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>N&ordm; Inscripci&oacute;n </td>';
   innerHTML += '  <td class="inputTextField">'+centroJub[RNEJP]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';   
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td nowrap="nowrap">Teléfono</td>';
   innerHTML += '  <td class="inputTextField">'+centroJub[TELEFONO]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';   
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td nowrap="nowrap">Servicios</td>';
   innerHTML += '  <td class="inputTextField">'+centroJub[SERVICIOS]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td colspan="3" align="center">';
   innerHTML += '    <img src="../../images/botones/boton_volveraconsultar.jpg" onClick="formIngreso()" class="imgLink" style="cursor:hand; cursor: pointer;"/>';
   innerHTML += '  </td>';
   innerHTML += '</tr>';   
   innerHTML += '</table>';   
   var t = document.createElement('div');
   t.innerHTML = innerHTML;
   document.getElementById('LayerPpal').innerHTML = "";
   document.getElementById('LayerPpal').appendChild(t);
}

function detalleCentroJub(index) {
	document.getElementById('LayerPpal').style.backgroundColor = "#FFFFFF";
var innerHTML; 	
var centroJub = centrosJubilados[index];
var serviciosCentro = centroJub[LST_SERVICIOS];
var nombreServicio;

   innerHTML  = '<table id="CentroJub" width="450" border="0" class="textField" cellpadding="2" style="margin-left: 1px; border-collapse: collapse; border: solid 1px #cacab;">';
   innerHTML += '<tr>';
   innerHTML += '  <td width="60" class="gris">UGL</td>';
   innerHTML += '  <td width="360" class="crema">'+centroJub[COD_UGL_CENTRO]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td class="gris">N&ordm; Inscripci&oacute;n </td>';
   innerHTML += '  <td class="grisClaro">'+centroJub[RNEJP]+'</td>';
   innerHTML += '</tr>';   
   innerHTML += '<tr>';
   innerHTML += '  <td nowrap="nowrap" class="gris">Centro de Jubilados</td>';
   innerHTML += '  <td class="crema">'+centroJub[DESC_CENTRO_JUB]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td class="gris">Domicilio</td>';
   innerHTML += '  <td class="grisClaro">'+centroJub[CALLE]+' ('+centroJub[COD_POSTAL]+'), '+centroJub[LOCALIDAD]+'</td>';
   innerHTML += '</tr>';
   innerHTML += '<tr>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '  <td>&nbsp;</td>';
   innerHTML += '</tr>';
   innerHTML += '</table>';   
   
   innerHTML += '<div class="LayerLstSubsidios">';
   innerHTML += '<table width="650" cellspacing="0" style="margin-top: 1px; margin-left: 1px; border-collapse: collapse; border: solid 1px #cacacb; ">';
   innerHTML += '  <tr class="textField">';
   innerHTML += '    <td width="135" class="gris">Servicio</td>';
   innerHTML += '    <td width="202" class="gris">Profesional</td>';
   innerHTML += '    <td width="233" class="gris">Hr. Atenci&oacute;n </td>';
   innerHTML += '    <td width="140" class="gris">Per&iacute;odo</td>';
   innerHTML += '  </tr>';
   clase="crema";
   for (var i=0; i < serviciosCentro.length; i++) {
   	  if (clase=="crema") { 
			clase="grisClaro";
		} else if (clase=="grisClaro") {
			clase="crema";
		}
	  innerHTML += detalleServicio(serviciosCentro[i], clase);
   }
   innerHTML += '</table>';
   innerHTML += '</div>';

   innerHTML += '<table width="750" border="0" class="textField" cellpadding="2">';
   innerHTML += '<tr>';
   innerHTML += '  <td align="center">';
   innerHTML += '    <img src="../../images/botones/boton_volveraconsultar.jpg" onClick="formIngreso()" class="imgLink" style="cursor:hand; cursor: pointer;"/>';
   innerHTML += '  </td>';
   innerHTML += '</tr>';   
   innerHTML += '</table>';      
	var t = document.createElement('div');
   t.innerHTML = innerHTML;
   document.getElementById('LayerPpal').innerHTML = "";
   document.getElementById('LayerPpal').appendChild(t);
}

function detalleServicio(servicio, clase) {
   var innerHTML = '';
   var codServicio = servicio[CODIG_SERV];

   innerHTML += '  <tr class="inputTextField">';
   innerHTML += '    <td class='+clase+'>'+servicio[NOMBR_SERV]+'</td>';
   if (codServicio=='ENFERMERIA') {
      innerHTML += '    <td class='+clase+'>'+servicio[PROFR_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[HRATE_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[PERIO_SERV]+'</td>';	   
   }
   else if(codServicio=='PEDICURIA') {
      innerHTML += '    <td class='+clase+'>'+servicio[PROFR_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[HRATE_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[PERIO_SERV]+'</td>';	   	   
   }
   else if(codServicio=='ACT_RECREATIVA') {
      innerHTML += '    <td class='+clase+'>'+servicio[PROFR_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[HRATE_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[PERIO_SERV]+'</td>';	   	   
   }   
   else if(codServicio=='AUTO_CUIDADO') {
      innerHTML += '    <td class='+clase+'>'+servicio[PROFR_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[HRATE_SERV]+'</td>';
      innerHTML += '    <td class='+clase+'>'+servicio[PERIO_SERV]+'</td>';	   	   
   }
   else if(codServicio=='TURISMO') {
      innerHTML += '    <td colspan="3">&nbsp;</td>';
   }   
   else {
      innerHTML += '    <td colspan="3">&nbsp;</td>';	   	   	   
   }
   innerHTML += '  </tr>';	   
   
   return innerHTML
}
	   


