    /*Funciones de Javascript utilizadas en la validacion de registro de la pagina */

	/*Agrega una opcion a un combo segun el explorador */
	function agregarOpcion( objSelect, objOpcion )
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			objSelect.add(objOpcion);
		}
		
		else
		{
			objSelect.add(objOpcion,null);
		}
	}

	/*Funcion que inicializa el Combo de Años*/
	function setAnio()
	{
		var anioActual = (new Date()).getFullYear();		
		var sltAnio = document.getElementById('sltAnio');		
		
		for ( a = anioActual; a >= 1920; a--)
		{		
			
			var opcion   = document.createElement('option');
			opcion.text  = a;
			opcion.value = a;	
			agregarOpcion(sltAnio,opcion);
		}
		
		sltAnio.selectedIndex = 18;
	}
	
	/*Funcion que inicializa el Combo de Meses*/
	
	function setMes()
	{
		var arrMeses = new Array('Enero'
                                        ,'Febrero'
                                        ,'Marzo'
                                        ,'Abril'
                                        ,'Mayo'
                                        ,'Junio'
                                        ,'Julio'
                                        ,'Agosto'
                                        ,'Septiembre'
                                        ,'Octubre'
                                        ,'Noviembre'
                                        ,'Diciembre');

		var sltMes   = document.getElementById('sltMes');

		for (i=0; i<12; i++)
		{
			var opcion   = document.createElement('option');
			opcion.text  = arrMeses[i];
			opcion.value = i + 1;			
			agregarOpcion(sltMes,opcion);
		}
	}
        
        /*Funcion que Inicializa Los Días*/
	
	function setDias()
	{
		var sltDia = document.getElementById('sltDia');
		
		for ( i = 1; i < 32; i++)
		{
			var opcion   = document.createElement('option');
			opcion.text  = i;
			opcion.value = i;
			agregarOpcion(sltDia,opcion);		
			
		}
	}	
	

	/*Funcion que Valida Un Campo de Datos*/
	function campoValido(strId, strSpnId)
	{	
		var spnErr = document.getElementById(strSpnId);
			
		if ( document.getElementById(strId).value == "" )
		{
			spnErr.style.visibility = "visible";
			return false;
		}
		
		else if (spnErr.style.visibility != "hidden" )
		{
			spnErr.style.visibility = "hidden";
                }
		
		return true;
	}
	
	/*Obtiene el valor seleccionado en el radio button*/
	function getRadioButtonSelectedValue(strIdControl)
	{
		ctrl = document.getElementsByName(strIdControl);
		
    	for(i=0;i<ctrl.length;i++)
        	if(ctrl[i].checked) 
				return ctrl[i].value;
	}


	/*Funcion que valida la forma y en caso de ser correcta guarda los datos */
	function validarForma()
	{
		if (!campoValido('txtNombre','spnErrNombre'))
			return false;

		if (!campoValido('txtPaterno','spnErrPaterno'))
			return false;

		if (!campoValido('txtCorreo','spnErrCorreo'))
			return false;
		
		var Estado = document.getElementById("sltEstado");
		var Sector = document.getElementById("sltSector");
		
		$.ajax({
			type: "POST",
			url: "guardarRegistro.php",	
			data: "txtNombre=" + document.getElementById("txtNombre").value + "&" +
			      "txtPaterno=" + document.getElementById("txtPaterno").value + "&" +
			      "txtMaterno=" + document.getElementById("txtMaterno").value + "&" +
 			      "txtCorreo=" + document.getElementById("txtCorreo").value + "&" + 
		              "rdSexo=" + getRadioButtonSelectedValue("rdSexo") + "&" +
		              "sltAnio=" + document.getElementById("sltAnio").options[document.getElementById("sltAnio").selectedIndex].value + "&"+
                              "sltMes=" + document.getElementById("sltMes").options[document.getElementById("sltMes").selectedIndex].value +"&" +
                              "sltDia=" + document.getElementById("sltDia").options[document.getElementById("sltDia").selectedIndex].value +"&" +
                              "sltEstado=" + Estado.options[Estado.selectedIndex].value +"&" +                                    			      
                             "txtActividad=" + document.getElementById("txtActividad").value + "&"+
                             "txtOrganizacion=" + document.getElementById("txtActividad").value + "&"+
                             "sltSector=" + Sector.options[Sector.selectedIndex].value, 
			success: function(datos){
		       		alert( "Felicidades ya estas registrado en Flisol ");					
				limpiarDatos();
		      	}
		});

	}

	/*Funcion para limpiar los datos de la hoja*/
	function limpiarDatos()
	{
				document.getElementById("txtNombre").value  = "";
				document.getElementById("txtPaterno").value = "";
				document.getElementById("txtMaterno").value = "";
		 		document.getElementById("txtCorreo").value  = "";                 
				document.getElementById("sltEstado").selectedIndex = 0;
                document.getElementById("txtActividad").value = "";
				document.getElementById("txtOrganizacion").value = "";
                document.getElementById("sltSector").selectedIndex = 0; 		
	}
	