/*
 * Filtra el campo de texto al que se le asocia este método 
 * para no permitir la entrada de comillas.
 */
function FiltraComilla() {
	var code;
	if(window.event) 
	{
		code = window.event.keyCode;
	}
	else 
	{
		code = e.which;
	}
	
	return (code != 219);
}

// Eliminar los espacios en blanco del string
function rightTrim(sString) 
{
	while (sString.substring(sString.length-1, sString.length) == ' ') 
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
//Mostrar lista de externos implicados usando AJAX (RegActividadGrupal)
function MuestraExternos() 
{
	var elemento = document.getElementById("PanelExternos");
	if (elemento.style.visibility == false) elemento.style.visibility = true;
	else elemento.style.visibility = false;


	var elemento = document.getElementById("PanelExternos");
	if (document.getElementById("PanelExternos").style.visibility == false) document.getElementById("PanelExternos").style.visibility = true;
	else document.getElementById("PanelExternos").style.visibility = false;
}

/************************ FORMULARIO PREINSCRIPCIÓN/InfoPFJ **************************/
// Rellenar la lista de provincias usando AJAX (Preinscripción)
function RellenaDDLProvincias() 
{
	Preinscripcion.RellenarComboProvincias(RellenaDDLProvincias_CallBack);  
}
// Método callback para rellenar la lista de provincias
function RellenaDDLProvincias_CallBack(response) 
{
	var dt = response.value; 
	var html = new Array(); 
	var oSelect = document.getElementById("PROVINCIA");
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i = 0; i < dt.Rows.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = dt.Rows[i]["idProvincia"];
			oOption.text = rightTrim(dt.Rows[i]["descProvincia"]);
			
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
				
			// Si el campo oculto tiene valor lo marcamos
			var oselected = document.getElementById("ProvinciaOculto");
			if (oselected.value == oOption.value) {
				oOption.selected = true;
				RellenaDDLPoblaciones(oOption.value);
			}
		}
	}
}

// Rellenar la lista de poblaciones usando AJAX (Preinscripción)
function RellenaDDLPoblaciones(categoryID) 
{ 
	Preinscripcion.RellenarComboPoblaciones(categoryID,RellenarComboPoblaciones_CallBack);
}

// Método callback para rellenar la lista de poblaciones
function RellenarComboPoblaciones_CallBack(response) 
{
	var ds = response.value; 
	var oSelect = document.getElementById("POBLACION");
	
	oSelect.options.length = 0;
	// Vaciar los combos
	document.getElementById("DISTRITOSANITARIO").options.length = 0;
	document.getElementById("ZBS").options.length = 0;
	document.getElementById("CENTROSALUD").options.length = 0;
									
	if(ds!= null && typeof(ds) == "object" && ds.Tables!= null)
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0;i<ds.Tables[0].Rows.length;i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = ds.Tables[0].Rows[i].idMunicipio;
			oOption.text = rightTrim(ds.Tables[0].Rows[i].descMunicipio);
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
			
			// Si el campo oculto tiene valor lo marcamos
			var oselected = document.getElementById("PoblacionOculto");
			if (oselected.value == oOption.value) {
				oOption.selected = true;
				RellenaDDLDistritosSanitariosInfoPFJ(oOption.value);
			}
		}
	}
}

// Rellenar la lista de distritos sanitarios usando AJAX (Preinscripción)
function RellenaDDLDistritosSanitarios(categoryID) 
{ 
	Preinscripcion.RellenarComboDistritoSanitario(categoryID,RellenarComboDistritoSanitario_CallBack);
}

// Método callback para rellenar la lista de distritos sanitarios
function RellenarComboDistritoSanitario_CallBack(response) 
{
	var ds = response.value; 
	var oSelect = document.getElementById("DISTRITOSANITARIO");
	
	oSelect.options.length = 0;
	// Vaciar los combos
	document.getElementById("ZBS").options.length = 0;
	document.getElementById("CENTROSALUD").options.length = 0;
	
	if(ds!= null && typeof(ds) == "object" && ds.Tables!= null)
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0;i<ds.Tables[0].Rows.length;i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = ds.Tables[0].Rows[i].idDistrito;
			oOption.text = rightTrim(ds.Tables[0].Rows[i].descDistrito);
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
			
			// Si el campo oculto tiene valor lo marcamos
			var oselected = document.getElementById("DistritoOculto");
			if (oselected.value == oOption.value) {
				oOption.selected = true;
				RellenaDDLZBSInfoPFJ(oOption.value);
			}
		}
	}
}

// Rellenar la lista de ZBS usando AJAX (Preinscripción)
function RellenaDDLZBS(categoryID) 
{ 
	Preinscripcion.RellenarComboZBS(categoryID,RellenarComboZBS_CallBack);
}

// Método callback para rellenar la lista de ZBS
function RellenarComboZBS_CallBack(response) 
{
	var ds = response.value; 
	var oSelect = document.getElementById("ZBS");
	
	oSelect.options.length = 0;
	// Vaciar los combos
	document.getElementById("CENTROSALUD").options.length = 0;
	
	if(ds!= null && typeof(ds) == "object" && ds.Tables!= null)
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0;i<ds.Tables[0].Rows.length;i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = ds.Tables[0].Rows[i].idZBS;
			oOption.text = rightTrim(ds.Tables[0].Rows[i].descZBS);
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
			
			// Si el campo oculto tiene valor lo marcamos
			var oselected = document.getElementById("ZBSOculto");
			if (oselected.value == oOption.value) {
				oOption.selected = true;
				RellenaDDLCentrosInfoPFJ(oOption.value);
			}
		}
	}
}

// Rellenar la lista de centros usando AJAX (Preinscripción)
function RellenaDDLCentros(categoryID) 
{ 
	Preinscripcion.RellenarComboCentros(categoryID,RellenarComboCentros_CallBack);
}

// Método callback para rellenar la lista de centros
function RellenarComboCentros_CallBack(response) 
{
	var ds = response.value; 
	var oSelect = document.getElementById("CENTROSALUD");
	
	oSelect.options.length = 0;
					
	if(ds!= null && typeof(ds) == "object" && ds.Tables!= null)
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0;i<ds.Tables[0].Rows.length;i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = ds.Tables[0].Rows[i].idCentro;
			oOption.text = rightTrim(ds.Tables[0].Rows[i].descCentro);
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
			
			// Si el campo oculto tiene valor lo marcamos
			var oselected = document.getElementById("CentroOculto");
			if (oselected.value == oOption.value) oOption.selected = true;
		}
	}
}




/************* FORMULARIO REGACTIVIDADGRUPAL y REGACTIVIDADCONSULTAS ***************/
// Rellenar la lista de provincias usando AJAX (RegActividadGrupal)
function RellenaDDLTema() 
{
	RegActividadGrupal.RellenarComboTema(RellenaDDLTema_CallBack);  
}
// Rellenar la lista de provincias usando AJAX (RegActividadConsultas)
function RellenaDDLTemaRegActividadConsultas() 
{
	RegActividadConsultas.RellenarComboTema(RellenaDDLTema_CallBack);  
}
// Método callback para rellenar la lista de provincias
function RellenaDDLTema_CallBack(response) 
{
	var ds = response.value; 
	var html = new Array(); 
	var oSelect = document.getElementById("TEMA");
	
	oSelect.options.length = 0;			
	if(ds!= null && typeof(ds) == "object" && ds.Tables!= null)
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0;i<ds.Tables[0].Rows.length;i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = ds.Tables[0].Rows[i].idTema;
			oOption.text = rightTrim(ds.Tables[0].Rows[i].nombreTema);
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
		}
	}	
}

// Rellenar la lista de ZBS usando AJAX	(RegActividadGrupal)
function RellenaDDLEspecifico(categoryID) 
{ 
	RegActividadGrupal.RellenarComboEspecifico(categoryID,RellenarComboEspecifico_CallBack);
}
// Rellenar la lista de ZBS usando AJAX	(RegActividadConsultas)
function RellenaDDLEspecificoRegActividadConsultas(categoryID) 
{ 
	RegActividadConsultas.RellenarComboEspecifico(categoryID,RellenarComboEspecifico_CallBack);
}
// Método callback para rellenar la lista de ZBS
function RellenarComboEspecifico_CallBack(response) 
{
	var ds = response.value; 
	var oSelect = document.getElementById("ESPECIFICO");
	
	oSelect.options.length = 0;
	if(ds!= null && typeof(ds) == "object" && ds.Tables!= null)
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0;i<ds.Tables[0].Rows.length;i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = ds.Tables[0].Rows[i].idEspecifico;
			oOption.text = rightTrim(ds.Tables[0].Rows[i].nombreEspecifico);
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
		}
	}
}


// Rellenar la lista de ZBS usando AJAX	(RegActividadConsultas)
function RellenaDDLDerivacion() 
{ 
	RegActividadConsultas.RellenarComboDerivacion(RellenarComboDerivacion_CallBack);
}
// Método callback para rellenar la lista de ZBS
function RellenarComboDerivacion_CallBack(response)
{
	var ds = response.value; 
	var oSelect = document.getElementById("DERIVACION");
	
	oSelect.options.length = 0;
	if(ds!= null && typeof(ds) == "object" && ds.Tables!= null)
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0;i<ds.Tables[0].Rows.length;i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = ds.Tables[0].Rows[i].idDerivacion;
			oOption.text = rightTrim(ds.Tables[0].Rows[i].nombreDerivacion);
			if (oOption.text == "No") oOption.selected = true;
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
		}

		var oOption = document.createElement("OPTION");
		oOption.value = "otras";
		oOption.text = "Otras (especificar)";
				try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}
	}
}
/*********************************************************************************/


/*************************** FORMULARIO ZonaRegistro *****************************/
// Rellenar la lista de provincias usando AJAX
function RellenaDDLProvinciasZonaRegistro() 
{
	ZonaRegistro.RellenarComboProvincias(RellenaDDLProvinciasZonaRegistro_CallBack);  
}
// Método callback para rellenar la lista de provincias
function RellenaDDLProvinciasZonaRegistro_CallBack(response) 
{
	var dt = response.value; 
	var oSelect = document.getElementById("PROVINCIA");
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i = 0; i < dt.Rows.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = dt.Rows[i].idProvincia;
			oOption.text = rightTrim(dt.Rows[i].descProvincia);
			
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
		}
	}
}
// Rellenar la lista de Puntos Forma Joven usando AJAX
function RellenaDDLPFJZonaRegistro(categoryID) 
{ 
	ZonaRegistro.RellenarComboPFJ(categoryID, RellenarComboPFJZonaRegistro_CallBack);
}

// Método callback para rellenar la lista de poblaciones
function RellenarComboPFJZonaRegistro_CallBack(response) 
{
	var dt = response.value; 
	var oSelect = document.getElementById("PFJ");

	oSelect.options.length = 0;
									
	if(dt!= null && typeof(dt) == "object")
	{
		var oOption = document.createElement("OPTION");
		oOption.value = "";
		oOption.text = "";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i=0; i < dt.Rows.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = dt.Rows[i].CODIGO;
			oOption.text = rightTrim(dt.Rows[i].CENTRO);
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
		}
	}
}

// Rellenar la lista de tipos de profesionales usando AJAX
function RellenaDDLTipoZonaRegistro() 
{
	ZonaRegistro.RellenarComboTipo(RellenaDDLTipoZonaRegistro_CallBack);  
}
// Método callback para rellenar la lista de provincias
function RellenaDDLTipoZonaRegistro_CallBack(response) 
{
	var dt = response.value; 
	var oSelect = document.getElementById("TIPO");
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i = 0; i < dt.Rows.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = dt.Rows[i].idTipoProfesional;
			oOption.text = rightTrim(dt.Rows[i].descTipoProfesional);
			
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
		}
	}
}
/*********************************************************************************/

function validaCerrarSesion() {
	var valor = confirm('¿Seguro que desea salir?');
	return valor;
}

/*************************** FORMULARIO CambioRegistro *****************************/
// Rellenar la lista de tipos de profesionales usando AJAX
function RellenaDDLTipoCambioRegistro() 
{
	CambioRegistro.RellenarComboTipo(RellenaDDLTipoCambioRegistro_CallBack);  
}
// Método callback para rellenar la lista de provincias
function RellenaDDLTipoCambioRegistro_CallBack(response) 
{
	var dt = response.value; 
	var oSelect = document.getElementById("TIPO");
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
		var oOption = document.createElement("OPTION");
		oOption.value = 0;
		oOption.text = " ";
		try {
			oSelect.add(oOption, null); // Para cumplir con el estándar
		}
		catch(ex) {
			oSelect.add(oOption); // Para IE
		}

		for(var i = 0; i < dt.Rows.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = dt.Rows[i].idTipoProfesional;
			oOption.text = rightTrim(dt.Rows[i].descTipoProfesional);

			var oselected = document.getElementById("TipoOculto");
			if (oselected.value == oOption.value) oOption.selected = true;
			
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}

		}
	}
}

/*********************************************************************************/

/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////// PARA EL CALENDARIO ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////


    // Se llama cuando se pulsa sobre una fecha.
    function selected(cal, date) {
      cal.sel.value = date; // Se actualiza la fecha en el textbox.
      if (cal.dateClicked) // Se cierra cuando se pulsa una fecha.
        cal.callCloseHandler();
    }

    // Se llama cuando se pulsa sobre la cruceta de cerrar.
    // Tambien se puede llamar al seleccionar una fecha
    function closeHandler(cal) {
      cal.hide();                        // cierra el calendario
      _dynarch_popupCalendar = null;
    }

    // Esta funcion muestra el calendario bajo el elemento representado por su id.
    function showCalendar(id, format) {
      var el = document.getElementById(id);
      if (_dynarch_popupCalendar != null) {
        // si ya se ha creado un calendario.
        _dynarch_popupCalendar.hide();                 
      } else {
        // Se crea el calendario.
        var cal = new Calendar(1, null, selected, closeHandler);

        _dynarch_popupCalendar = cal;                  // lo pone en la variable global correspondiente
        cal.setRange(1900, 2070);        // minimo / maximo año a representar
        cal.create();
      }
      
      _dynarch_popupCalendar.setDateFormat(format);    // especifica el formato de la fecha
      _dynarch_popupCalendar.parseDate(el.value);      // se prueba a transformar el texto ya escrito
      _dynarch_popupCalendar.sel = el;

      _dynarch_popupCalendar.showAtElement(el, "Br");        // muestra el calendario

      return false;
    }

function cierraSesion() {
	InfoUsuario.cerrarSession();
	location.href = "Default.aspx";
}
function cierraSesionEstadistica() {
	estadistica.cerrarSession();
	location.href = "Default.aspx";
}
function cierraSesionProfesionales() {
	ListadoProfesionales.cerrarSession();
	location.href = "Default.aspx";
}

function compruebaEspecifico(valor) {
	if (valor == 14 || valor == 40 || valor == 37 || valor == 43 || valor == 52 || valor == 58) {
		document.getElementById('tdLblOtroEspecifico').style.display = 'block';
		document.getElementById('tdOtroEspecifico').style.display = 'block';
	}
	else {
		document.getElementById('tdLblOtroEspecifico').style.display = 'none';
		document.getElementById('tdOtroEspecifico').style.display = 'none';
	}
}

// TRATAMIENTO IMAGENES

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////EFECTOS/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function ponEfecto(id)
{
    document.getElementById(id).className = 'TRIluminado';
}

function quitaEfecto(id)
{
    document.getElementById(id).className = 'TRNormal';
}

function ponEfectoTd(id)
{
    document.getElementById(id).className = 'TDIluminado';
}

function quitaEfectoTd(id)
{
    document.getElementById(id).className = 'FumadoresOpcionesCentro';
}

function muestraAviso(id)
{
    document.getElementById(id).style.display = 'block';
        
}

function ocultaAviso(id)
{
    document.getElementById(id).style.display = 'none';
}



/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////VARIOS CON DDL//////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function rellenaDDLCentro(provincia)
{
    //var idProvincia = document.getElementById('ddlCentro').value;
    var res = ClaseSinHumo.datosDDLCentros(provincia);
    rellenaDDL(res, 'ddlCentro', false);
}

function rellenaDDL(res, elemento, conBlanco)
{
	var dt = res.value;
	var html = new Array();
	var oSelect = document.getElementById(elemento);
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
	    if (conBlanco) {
	        agregaBlanco(oSelect);
	    }
		for(var i = 0; i < dt.Rows.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = dt.Rows[i].codigo;
			oOption.text = dt.Rows[i].denominacion;
			
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
			    //alert('entra');
				oSelect.add(oOption); // Para IE
			}
        }
    }
}

function agregaBlanco(oSelect) {
    var oOption = document.createElement("OPTION");
    oOption.value = "";
    oOption.text = "";

    try {
        oSelect.add(oOption, oSelect.options[0]); // Para cumplir con el estándar
    }
    catch(ex) {
        oSelect.add(oOption, 0); // Para IE
    }
}



/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////CONTROLES TBX///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function formatoNumero()
{
    var key = window.event.keyCode;
    if(key >= 48 && key <=57)
        return true;
    else return false;
}

function formatoLetra()
{
    var key = window.event.keyCode;
    if((key >= 65 && key <= 90) || (key >= 97 && key <= 122) || key == 209 || key == 241 || key == 32)
        return true;
    else return false;
}



/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////AUTORELLENAR///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function calculaTotal(elemento1, elemento2, eResultado)
{
    var sum1;
    var sum2;
    var suma;
    
    sum1 = parseInt(document.getElementById(elemento1).value);
    sum2 = parseInt(document.getElementById(elemento2).value);
    
    if(isNaN(sum1))
        sum1 = 0;
    if(isNaN(sum2))
        sum2 = 0;
        
    suma = sum1 + sum2;

    document.getElementById(eResultado).innerHTML = suma;
}



/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////VALIDACIONES///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function validaDatosFormulario()
{
    var challenge = Recaptcha.get_challenge(); 
    var response = Recaptcha.get_response(); 
    var todo_ok = true;
    
    if(document.getElementById('tbxProfesor').value.length == 0)
    {   
        document.getElementById('txtProfesor').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('txtProfesor').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('tbxTelefono').value.length == 0)
    {
        document.getElementById('txtTelefono').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('txtTelefono').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('tbxCorreoContacto').value.length == 0)
    {
        document.getElementById('txtCorreoContacto').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('txtCorreoContacto').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('tbxClase').value.length == 0)
    {
        document.getElementById('txtClase').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('txtClase').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('tbxAlumnosNoFumado').value.length == 0)
    {
        document.getElementById('tbxAlumnosNoFumado').value = 0;
    }

    if(document.getElementById('tbxAlumnasNoFumado').value.length == 0)
    {
        document.getElementById('tbxAlumnasNoFumado').value = 0;
    }

    if(document.getElementById('tbxAlumnosNoFumarRegularmente').value.length == 0)
    {
        document.getElementById('tbxAlumnosNoFumarRegularmente').value = 0;
    }

    if(document.getElementById('tbxAlumnasNoFumarRegularmente').value.length == 0)
    {
        document.getElementById('tbxAlumnasNoFumarRegularmente').value = 0;
    }

    if(document.getElementById('tbxAlumnosFumanRegularmente').value.length == 0)
    {
        document.getElementById('tbxAlumnosFumanRegularmente').value = 0;
    }

    if(document.getElementById('tbxAlumnasFumanRegularmente').value.length == 0)
    {
        document.getElementById('tbxAlumnasFumanRegularmente').value = 0;
    }

    if(document.getElementById('tbxAlumnosCadaDia').value.length == 0)
    {
        document.getElementById('tbxAlumnosCadaDia').value = 0;
    }

    if(document.getElementById('tbxAlumnasCadaDia').value.length == 0)
    {
        document.getElementById('tbxAlumnasCadaDia').value = 0;
    }
    
    if(todo_ok == false)
        alert('Revise los errores (marcados en rojo).');
    else
        {
            var dev = insertaDatos(challenge,response);
            if(dev.value == 'OK') {
                document.getElementById('recaptcha_div').style.border = '0px';
                document.getElementById('recaptcha_span').style.display = 'none';
                alert('Datos guardados correctamente.');
            }
            else if(dev.value == 'Captcha Erróneo') {
                document.getElementById('recaptcha_div').style.border = 'solid 2px red';
                document.getElementById('recaptcha_span').style.display = 'block';
            }
            else
                location.href = 'Error.aspx?error=' + dev.value;
        }
    
    return false;
}

function insertaDatos(challenge,response)
{
    
    var Datos = new Array();
    var Tipos = new Array();
    var Nombres = new Array();

    var provincia = document.getElementById('ddlProvincia');
    var centro = document.getElementById('ddlCentro');
    var profesor = document.getElementById('tbxProfesor');
    var telefono = document.getElementById('tbxTelefono');
    var correo = document.getElementById('tbxCorreoContacto');
    var curso = document.getElementById('ddlCurso');
    var clase = document.getElementById('tbxClase');
    var alumnoNoFumado = document.getElementById('tbxAlumnosNoFumado');
    var alumnaNoFumado = document.getElementById('tbxAlumnasNoFumado');
    var alumnoNoRegular = document.getElementById('tbxAlumnosNoFumarRegularmente');
    var alumnaNoRegular = document.getElementById('tbxAlumnasNoFumarRegularmente');
    var alumnoFumaRegular = document.getElementById('tbxAlumnosFumanRegularmente');
    var alumnaFumaRegular = document.getElementById('tbxAlumnasFumanRegularmente');
    var alumnoCadaDia = document.getElementById('tbxAlumnosCadaDia');
    var alumnaCadaDia = document.getElementById('tbxAlumnasCadaDia');

    
    Nombres.push("@idProvincia"); Tipos.push("Int"); Datos.push(provincia.value); 
    Nombres.push("@idCentro"); Tipos.push("Int"); Datos.push(centro.value); 
    Nombres.push("@Profesor"); Tipos.push("VarChar"); Datos.push(profesor.value.toUpperCase()); 
    Nombres.push("@Tlf"); Tipos.push("VarChar"); Datos.push(telefono.value); 
    Nombres.push("@Mail"); Tipos.push("VarChar"); Datos.push(correo.value); 
    Nombres.push("@Curso"); Tipos.push("Bit"); Datos.push(curso.value); 
    Nombres.push("@Clase"); Tipos.push("VarChar"); Datos.push(clase.value.toUpperCase()); 
    Nombres.push("@N_Alumnos_No_Fumado"); Tipos.push("Int"); Datos.push(alumnoNoFumado.value); 
    Nombres.push("@N_Alumnas_No_Fumado"); Tipos.push("Int"); Datos.push(alumnaNoFumado.value); 
    Nombres.push("@N_Alumnos_No_Regular"); Tipos.push("Int"); Datos.push(alumnoNoRegular.value); 
    Nombres.push("@N_Alumnas_No_Regular"); Tipos.push("Int"); Datos.push(alumnaNoRegular.value); 
    Nombres.push("@N_Alumnos_Regular"); Tipos.push("Int"); Datos.push(alumnoFumaRegular.value); 
    Nombres.push("@N_Alumnas_Regular"); Tipos.push("Int"); Datos.push(alumnaFumaRegular.value); 
    Nombres.push("@N_Alumnos_Cada_Dia"); Tipos.push("Int"); Datos.push(alumnoCadaDia.value); 
    Nombres.push("@N_Alumnas_Cada_Dia"); Tipos.push("Int"); Datos.push(alumnaCadaDia.value); 
    
    var resultado;
    
    resultado = InscripcionPFJ.InsertaPeticion(Nombres.toJSONString(),Tipos.toJSONString(),Datos.toJSONString(), challenge,response);
    
    return resultado;

}
