// JavaScript Document
var counter=1;
//Author: Yrvin Escorihuela
//Departament: IT Division
//Company: Fundación Misión Sucre

//validacion para la introduccion numerica unica en campos de texto
//funciona tanto para Internet Explorer y Mozilla Firefox
function numeros(evento)
			{
				patron_numeros=/[0-9]/;
				if(document.all)
					{
						tecla_press=evento.keyCode;
					} else {
						tecla_press=evento.which;
					}
				if(tecla_press==8 || tecla_press==0)
					{
						return true;
					}
				numero=String.fromCharCode(tecla_press);
				return (patron_numeros.test(numero));
			}
			
//validacion para la introduccion numerica unica en campos de texto
//funciona tanto para Internet Explorer y Mozilla Firefox			
function telefono(evento)
			{
				patron_numeros=/[0-9-]/;
				if(document.all)
					{
						tecla_press=evento.keyCode;
					} else {
						tecla_press=evento.which;
					}
				if(tecla_press==8 || tecla_press==0)
					{
						return true;
					}
				numero=String.fromCharCode(tecla_press);
				return (patron_numeros.test(numero));
			}
//funcion de validacion de caracteres en los campos de texto, solo para caracteres alfabeticos
//funciona tanto para Internet Explorer y Mozilla Firefox
function caracteres(evento)
			{				
				
				tecla=(document.all) ? evento.keyCode: evento.which;				
				if(tecla==8 || tecla==0)
					{
						return true; 
					}				
				patron=/[A-Za-zñÑ\s]/;
				te=String.fromCharCode(tecla);				
				return (patron.test(te));				
					
			}
function addElements(control,contador)	
	{				
		counter=document.getElementById(contador).value;		
		objControl=document.getElementById(control);
		counter++;
		
		//creacion de una tabla nueva
		//estilo y anchura de la tabla
		if(document.getElementById('cargo').value==1)
			{
					
				alert('Debe cargar datos personales antes de empezar a agregar datos academicos');
				document.getElementById('cedula').focus();
				counter--;				
				return false;
			}
		
		if(document.getElementById('cantidad').value>=2 && document.getElementById('cargo').value==2)
			{
				alert('Los preparadores solamente imparten clases maximo a 2 secciones');
				counter--;				
				return false;
			}
		document.getElementById(contador).value=counter;				
		tabla=document.createElement("table");
		tabla.id="tabla"+counter;	
		tabla.className="tabla_interna_relleno";
		tabla.style.width=100+"%";
		//cuerpo de la tabla el tbody es obligatorio para crear objetos 'onfly' en internet explorer
		cuerpo_tabla=document.createElement("tbody");
		fila=document.createElement("tr");
		
		for(x=1;x<=3;x++)
			{
				celda=document.createElement("td");
				celda.id="celda"+x+counter;				
				celda.style.width=25+"%";
				celda.style.textAlign="center";
				celda.style.verticalAlign="middle";
				//if(x==1 || x==2)
				if(x==1)
					{
						txtField=document.createElement("input");
						txtField.type="text";
						txtField.className="campos_texto";
						/*if(x==1)
							{
								txtField.name="seccion"+counter;
								txtField.id="seccion"+counter;
							}*/	
						//if(x==2)
							//{
								txtField.name="nro_alumnos"+counter;
								txtField.id="nro_alumnos"+counter;
						//	}		
						txtField.maxlength=8;
						txtField.size=8;
						//txtField.onkeypress=numeros;
						if(txtField.addEventListener)
							{
								txtField.addEventListener('keypress',numeros,false);
							}
						else
							{
								txtField.attachEvent('onkeypress',numeros);
							}
						celda.appendChild(txtField);
					}
				//if(x==3 || x==4)		
				if(x==2 || x==3)	
					{
						cmbField=document.createElement("select");						
						if(x==2)
							{
 								cmbField.name="unidad"+counter;
 								cmbField.id="unidad"+counter;
 								cmbField.className="combos";
								cmbField.style.width=300+"px";
							}
						if(x==3)
							{
								cmbField.name="horas"+counter;
								cmbField.id="horas"+counter;
								cmbField.className="combos";
								i=1;								
								for(var x=0;x<9;x++)
									{	
										cmbField.options[x]=new Option(i,i);	
										//cmbField.options[x].value=i;
										i++;
									}
							}			
						celda.appendChild(cmbField);	
					}
					
				fila.appendChild(celda);
			}
		cuerpo_tabla.appendChild(fila);
		tabla.appendChild(cuerpo_tabla)
		objControl.appendChild(tabla);	
		var cmbUnidad="unidad"+counter;
		var cmbHoras="horas"+counter;		
		//alert(counter);
		methodPost(cmbUnidad,1);
		
	} 
function methodPost(id_ps,valor)	
	{	
		//var url="http://localhost/nomina/processes/general.php";
		var url="processes/general.php";
		tag=document.getElementById(id_ps);
		var ajax;
		ajax=createAjaxObject();
		ajax.open('POST',url,true);		
		ajax.onreadystatechange=function()
			{
				if(ajax.readyState==4)
					{
						var datos=(ajax.responseXML).firstChild;
						tag.options.length=0;	
						for(var i=0;i<datos.getElementsByTagName('valor').length;i++)
							{								
								var valor=datos.getElementsByTagName('valor')[i].firstChild.data;
								var unidad=datos.getElementsByTagName('texto')[i].firstChild.data;
								tag.options[i]=new Option(unidad,valor);
								//tag.options[i].value=valor;								
							}
					}	
			}
		ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		ajax.send('valor='+valor);		
	}
	
function methodPostModified(id_ps,valor,var_nombre)
	{		
		var url="processes/general.php";		
		var objAjax;
		var valorCombo=valor;
		var objeto=id_ps;
		var criterio=var_nombre+"="+valor;
		var estado=var_nombre;
		objAjax=createAjaxObject();		
		objAjax.open('POST',url);				
		objAjax.onreadystatechange=function()
			{					
				if(objAjax.readyState==4 && objAjax.status==200)
					{		
						var tag=document.getElementById(objeto);
						var datos;
						try
							{
								datos=(objAjax.responseXML).firstChild;
							}
						catch(e)
							{
								alert("En esta entidad no existen datos para cargar");
								return false;
							}
						clearComboBox(objeto);						
						try
							{
								for(var i=0;i<datos.getElementsByTagName('valor').length;i++)
									{								
										var valor=datos.getElementsByTagName('valor')[i].firstChild.data;
										var unidad=datos.getElementsByTagName('texto')[i].firstChild.data;
										tag.options[i]=new Option(unidad,valor);
									}
							}
						catch(ex)
							{
								//alert("No existen datos para cargar");
								return false;
							}						
						if(estado=="estado")	
							{
								document.getElementById("aldea").options.length=0;
							}
					}
			}
		objAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objAjax.send(criterio);
	}
	
function methodPostModified_1(id_ps,valor,var_nombre,cedula)
	{		
		var url="processes/general.php";		
		var objAjax;
		var valorCombo=valor;
		var objeto=id_ps;
		var criterio=var_nombre+"="+valor+"&cedula="+cedula;
		var estado=var_nombre;
		objAjax=createAjaxObject();		
		objAjax.open('POST',url);				
		objAjax.onreadystatechange=function()
			{					
				if(objAjax.readyState==4 && objAjax.status==200)
					{		
						var tag=document.getElementById(objeto);
						var datos;
						try
							{
								datos=(objAjax.responseXML).firstChild;
							}
						catch(e)
							{
								alert("En esta entidad no existen datos para cargar");
								return false;
							}
						clearComboBox(objeto);						
						try
							{
								for(var i=0;i<datos.getElementsByTagName('valor').length;i++)
									{								
										var valor=datos.getElementsByTagName('valor')[i].firstChild.data;
										var unidad=datos.getElementsByTagName('texto')[i].firstChild.data;
										tag.options[i]=new Option(unidad,valor);
									}
							}
						catch(ex)
							{
								//alert("No existen datos para cargar");
								return false;
							}						
						if(estado=="estado")	
							{
								document.getElementById("aldea").options.length=0;
							}
					}
			}
		objAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objAjax.send(criterio);
	}
	
function methodPostModified_2(id_ps,valor,var_nombre)
	{		
		var url="processes/general.php";		
		var objAjax;
		var valorCombo=valor;
		var objeto=id_ps;
		var criterio=var_nombre+"="+valor;
		var estado=var_nombre;
		objAjax=createAjaxObject();		
		objAjax.open('POST',url);				
		objAjax.onreadystatechange=function()
			{					
				if(objAjax.readyState==4 && objAjax.status==200)
					{		
						var tag=document.getElementById(objeto);
						var datos;
						try
							{
								datos=(objAjax.responseXML).firstChild;
							}
						catch(e)
							{
								alert("En esta entidad no existen datos para cargar");
								return false;
							}
						clearComboBox(objeto);						
						try
							{
								for(var i=0;i<datos.getElementsByTagName('valor').length;i++)
									{								
										var valor=datos.getElementsByTagName('valor')[i].firstChild.data;
										var unidad=datos.getElementsByTagName('texto')[i].firstChild.data;
										tag.options[i]=new Option(unidad,valor);
									}
							}
						catch(ex)
							{
								alert("No existen datos para cargar");
								return false;
							}						
						if(estado=="estado")	
							{
								document.getElementById("aldea").options.length=0;
							}
					}
			}
		objAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objAjax.send(criterio);
	}
function clearComboBox(id_control)
	{
		var combo;
		combo=document.getElementById(id_control);
		combo.options.length=0;
	}
function camposRequeridos()
	{
		var agregados=document.getElementById('cantidad');		
		var cedula=document.getElementById('cedula');				
		var nombre1=document.getElementById('nombre1');		
		var apellido1=document.getElementById('apellido1');			
		var cargo=document.getElementById('cargo');				
		var banco=document.getElementById('banco');				
		var cuenta=document.getElementById('cuenta');		
		var estado=document.getElementById('estado');		
		var municipio=document.getElementById('municipio');
		var aldea=document.getElementById('aldea');
		var horas_acumuladas=0;
		
		if(cedula.value==0 || cedula.value=="")
			{
				alert('El numero de cedula es obligatorio');
				cedula.focus();
				return false;
			}
		if(nombre1.value=="" || nombre1.value==null)
			{
				alert('El primer nombre es obligatorio');				
				nombre1.focus();
				return false;
			}
			
		if(apellido1.value=="" || apellido1.value==null)
			{
				alert('El primer apellido es obligatorio');				
				apellido1.focus();
				return false;
			}
			
		if(cargo.value==1)
			{
				alert('La opcion de cargo es obligatoria, debe seleccionar un cargo antes de continuar');
				cargo.focus();
				return false;
			}
		if(banco.value==1)
			{
				alert('La opcion de banco es obligatoria, debe seleccionar un banco antes de continuar');
				banco.focus();
				return false;
			}
		
		if(estado.value==0 || (municipio.value=="" || municipio.value==0) || (aldea.value=="" || aldea.value==0))
			{
				alert('Debe seleccionar las opciones de estado, municipio y aldea antes de continuar')
				estado.focus();
				return false;
			}
		if(agregados.value==1)
			{
				seccion1=document.getElementById('seccion1');
				nro_alumnos1=document.getElementById('nro_alumnos1');
				unidad1=document.getElementById('unidad1');				
				horas1=document.getElementById('horas1');
				/*if(seccion1.value=="" || seccion1.value==0)
					{
						alert('Debe asignar el numero de la sección antes de continuar');						
						seccion1.focus();
						return false;
					}*/
				if(nro_alumnos1.value==0 || nro_alumnos1.value=="")	
					{
						alert('Debe asignar el numero de alumnos antes de continuar');
						/*nro_alumnos1.style.backgroundColor="red";
						nro_alumnos1.onkeypress=nro_alumnos1.style.backgroundColor="white";*/
						nro_alumnos1.focus();
						return false;
					}
				if(unidad1.value==0 || unidad1.value=="")
					{
						alert('Debe asignar la unidad curricular antes de continuar');
						/*unidad1.style.backgroundColor="red";
						unidad1.onkeypress=unidad1.style.backgroundColor="white";*/
						unidad1.focus();
						return false;
					}
				if(horas1.value=="" || horas1.value==0)	
					{
						alert('Debe asignar el numero de horas antes de continuar');
						/*horas1.style.backgroundColor="red";
						horas1.onkeypress=horas1.style.backgroundColor="white";*/
						horas1.focus();
						return false;
					}
				
			}
		if(agregados.value>1) 
			{
				var c;	
				
				for(c=1;c<=agregados.value;c++)
					{	
						//nombre_gen1="seccion"+c;
						nombre_gen2="nro_alumnos"+c;
						nombre_gen3="unidad"+c;
						nombre_gen4="horas"+c
								
						//var seccion=document.getElementById(nombre_gen1);
						//alert(seccion)
						var nro_alumnos=document.getElementById(nombre_gen2);
						var unidad=document.getElementById(nombre_gen3);
						var horas=document.getElementById(nombre_gen4);
						
						//if(seccion.value=="" || seccion.value==0)
//							{
//								alert('Debe asignar el numero de la sección antes de continuar');
//								/*seccion.style.backgroundColor="red";
//								seccion.onkeypress=seccion.style.backgroundColor="white";*/
//								seccion.focus();
//								return false;
//							}
						if(nro_alumnos.value==0 || nro_alumnos.value=="")	
							{
								alert('Debe asignar el numero de alumnos antes de continuar');
								/*nro_alumnos.style.backgroundColor="red";
								nro_alumnos.onkeypress=nro_alumnos.style.backgroundColor="white";*/
								nro_alumnos.focus();
								return false;
							}
						if(unidad.value==0 || unidad.value=="")
							{
								alert('Debe asignar la unidad curricular antes de continuar');
								/*unidad.style.backgroundColor="red";
								unidad.onkeypress=unidad.style.backgroundColor="white";*/
								unidad.focus();
								return false;
							}
						if(horas.value=="" || horas.value==0)	
							{
								alert('Debe asignar el numero de horas antes de continuar');
								/*horas.style.backgroundColor="red";
								horas.onkeypress=horas.style.backgroundColor="white";*/
								horas.focus();
								return false;
							}
						horas_acumuladas+=horas.value;
						alert(horas_acumuladas);
						if(horas_acumuladas>19)
							{
								alert('Total de horas no debe exceder de 19')
								return false;
							}
					}
			}
		//alert(counter);
		
		if(confirm('¿Esta segur@ en agregar los datos?'))
			{
				document.getElementById('formulario').submit();		
			}
		else
			{
				return false;
			}
		
	}
function consultaCedula(id_campo_cedula)
	{
		//url="http://localhost/nomina/processes/general.php";
		url="processes/general.php";
		object=document.getElementById(id_campo_cedula);		
		var cedula=object.value;
		if(cedula=="" || cedula==0)
			{
				return false;
			}	
		var objectAjax;
		objectAjax=createAjaxObject();
		objectAjax.open('POST',url,true);
		objectAjax.onreadystatechange=function()
			{
				if(objectAjax.readyState==4)
					{	
						var dat=(objectAjax.responseXML).firstChild;						
					}
			}	
		objectAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objectAjax.send('cedula='+cedula);
		
	}
function accesoCampo(id_campo,caller)	
	{
		if(document.getElementById(id_campo)!=null && document.getElementById(caller)!=null)
			{
				campo=document.getElementById(id_campo);
				check=document.getElementById(caller);
			}
		else
			{
				return false;
			}
		
		if(check.checked==true)
			{
				campo.disabled=true;
			}
			
		if(check.checked==false)
			{
				campo.disabled=false;
				campo.focus();
			}
	}
	
function methodGet(id_ps,valor)	
	{
		
		var id_ps;
		//var url="http://localhost/nomina/processes/general.php?valor="+valor;		
		var url="processes/general.php?valor="+valor;		
		tag=document.getElementById(id_ps);
		objectAjax=createAjaxObject();
		objectAjax.open('GET',url,true);		
		objectAjax.onreadystatechange=function()
			{				
				if(objectAjax.readyState==4 && objectAjax.status==200)
					{	
						var datos=objectAjax.responseText;
						tag.innerHTML=datos;
					}
			}
		objectAjax.send(null);			
	}

/*function createAjaxObject() 
	{ 
			//intento de carga del objeto cuando es internet explorer=>5.5
			try 
				{ 
					objectAjax = new ActiveXObject("Msxml2.XMLHTTP"); 
				} 
			catch (e) 
				{ 
					//carga con antiguos navegadores
					try 
						{ 
							objectAjax= new ActiveXObject("Microsoft.XMLHTTP"); 
						} 
					catch (E) 
						{ 
								objectAjax= false; 
						} 
				} 
			if (!objectAjax && typeof XMLHttpRequest!='undefined') 
				{ 
					objectAjax = new XMLHttpRequest();
				} 
			return objectAjax 
	}*/
function createAjaxObject()
	{
		var ajaxObject=null;
		try
			{
				ajaxObject=new XMLHttpRequest();	
			}
		catch(e)	
			{
				var ajaxObjectVersion=new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP');
				for(var i=0; i<ajaxObjectVersion.length && !ajaxObject;i++)
					{
						try
							{
								ajaxObject=new ActiveXObject(ajaxObjectVersion[i]);
								//alert(i);
							}
						catch(e)
							{
							}
					}
			}
		if(!ajaxObject)
			{
				alert('Error al crear el ajaxObject');
			}
		else
			{
				return ajaxObject;
			}
		
	}	
	
function avisar()	
	{
		alert(document.getElementById(this.id));
	}
function capitalizar(id_campo)	
	{
		var campo=document.getElementById(id_campo);
		campo.value=campo.value.toUpperCase();
	}

function validarInicio(id_login, id_pass, id_resp)
	{
		var login=document.getElementById(id_login);
		//var url="http://localhost/nomina/processes/validate.php"
		var url="processes/validate_reg.php"
		var pass=document.getElementById(id_pass);
		var resp=document.getElementById(id_resp);
		var objectAjax=createAjaxObject();
		if(login.value=="" || login.value==null || login.value==0)
			{
				alert('Debe colocar su login para iniciar sesion');
				login.focus();
				return false;
			}
		if(pass.value=="" || pass.value==null || pass.value==0)	
			{
				alert('Colocar su password para iniciar sesion');
				pass.focus();
				return false;
			}
		objectAjax=createAjaxObject();
		objectAjax.open('POST',url,true);
		objectAjax.onreadystatechange=function()
			{
				if(objectAjax.readyState==4)
					{	
						//alert(objectAjax.responseText)
						var dat=(objectAjax.responseText);		
						//alert(dat);
						//resp.style.width=250+"px";
						//resp.style.backgroundColor="#FFE9F3";
						//resp.style.fontFamily="Verdana";
						//resp.style.fontSize=12+"px";
						//resp.style.color="#114477";
						//resp.style.textAlign="center";
						//resp.style.verticalAlign="middle";
						if(dat==1)
							{
								alert('Iniciando sesion');
								window.location='menu.php';
								//alert(dat);
							}
						if(dat==0)
							{
								alert('Datos invalidos');
							}
					}
			}	
		objectAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objectAjax.send('login='+login.value+"&pass="+pass.value);
	}

function checkPass(id_clave1, id_clave2)
	{
		var clave1=document.getElementById(id_clave1);
		var clave2=document.getElementById(id_clave2);
		
		if(clave1.value!=clave2.value)
			{
				alert('La contraseña y su verificación deben ser iguales');
				clave2.focus();
				return false;
			}
		
	}
function sendData()
	{
		var filter=/@./;
		var hotmail=/hotmail/;
		var ajaxObject=createAjaxObject();		
		var flag=document.getElementById('flag');
		//var url="http://localhost/nomina/processes/proc_coord.php";
		var datos=null;
		var url="processes/proc_coord_reg.php";
		
		var nacionalidad=document.getElementById('nacionalidad');
		var mensaje=document.getElementById('respuesta');
		var cedula=document.getElementById('cedula');
				
		var nombre1=document.getElementById('nombre1');
		var nombre2=document.getElementById('nombre2');
		
		var apellido1=document.getElementById('apellido1');
		var apellido2=document.getElementById('apellido2');
		
		var username=document.getElementById('usuario');	
		//
		//var fechaUsuario=document.getElementById('fecha_ingreso');
		//var fechaSistema=document.getElementById('fecha_mysql');
		var anio=document.getElementById('anio');
		var mes=document.getElementById('mes');
		var dia=document.getElementById('dia');
		//
		var contrasena1=document.getElementById('clave1');
		var contrasena2=document.getElementById('clave2');
		
		var email=document.getElementById('email');		
		var telefono=document.getElementById('telefono');
		var estado=document.getElementById('estado');
		var fecha_ingreso="";
		
		if(nacionalidad.value==0)
			{
				alert('Debe seleccionar la nacionalidad del Coordinador');
				nacionalidad.focus();
				return false;
			}
		
		if(cedula.value=="")
			{
				alert('El numero de cédula es necesario');
				cedula.focus();
				return false;
			}
			
		if(nombre1.value=="")			
			{
				alert('El primer nombre es obligatorio');
				nombre1.focus();
				return false;
			}
			
		if(apellido1.value=="")
			{
				alert('El primer apellido es obligatorio');
				apellido1.focus();
				return false;
			}
		
		if (username.value=="")
			{
				alert('El nombre de usuario es obligatorio');
				username.focus();
				return false;
			}
			
		if(anio.value==0)	
			{
				alert('Debe seleccionar un año para continuar');
				anio.focus();
				return false;
			}
			
		if(mes.value==0)	
			{
				alert('Debe seleccionar un mes para continuar');
				mes.focus();
				return false;
			}
		if(dia.value==0)
			{
				alert('Debe seleccionar un dia para continuar');
				dia.focus();
				return false;
			}
		fecha_ingreso=anio.value+"-"+mes.value+"-"+dia.value;
		if((contrasena1.value!=contrasena2.value)|| (contrasena1.value=="" || contrasena2.value==""))
			{
				alert('El campo de la contraseña y su validación no pueden ir en blanco ni ser diferentes');
				contrasena1.focus();
				return false;
			}
		if(contrasena1.value.length<6 || contrasena2.value.length<6)	
			{
				alert('La contraseña debe tener minimo 6 caracteres');
				contrasena1.focus();
				return false;
			}
			
		if(email.value=="")	
			{
				alert('El campo de email es obligatorio');
				email.focus();
				return false;
			}
		if(!filter.test(email.value))			
			{
				alert('El campo de correo electronico debe contener una direccion de correo valida');
				email.focus();
				return false;
			}
		if(hotmail.test(email.value))	
			{
				alert('No es posible establecer direcciones de correo con hotmail por problemas de envio y bandeja de entrada');
				email.focus();
				return false;
			}
			
		if(telefono.value=="")
			{
				alert('El campo de telefono es obligatorio');
				telefono.focus();
				return false;
			}
		
		if(estado.value==0 || estado.value=="")
			{
				alert('Debe seleccionar un estado para asociar al coordinador');
				estado.focus();
				return false;
			}
			
		ajaxObject.open('POST',url,true);
		ajaxObject.onreadystatechange=function()
			{
				if(ajaxObject.readyState==4)
					{
						var result=ajaxObject.responseText;
						mensaje.innerHTML=result;						
					}
			}		
		datos="nacionalidad="+nacionalidad.value+"&cedula="+cedula.value+"&nombre1="+nombre1.value+"&nombre2="+nombre2.value+"&apellido1="+apellido1.value+"&apellido2="+apellido2.value+"&usuario="+username.value+"&clave="+contrasena1.value+"&fecha="+fecha_ingreso+"&email="+email.value+"&telefono="+telefono.value+"&estado="+estado.value+"&flag="+flag.value
		motorAjax.ejecutarEnvioSolicitudes('post',url,datos,null,motorAjax.manejarRespuesta);
		
		for(var x=0;x<document.getElementsByTagName('input').length;x++)
			{
				if(document.getElementsByTagName('input').item(x).type=="text")
					{
						document.getElementsByTagName('input').item(x).value="";
					}
				if(document.getElementsByTagName('input').item(x).type=="password")
					{
						document.getElementsByTagName('input').item(x).value="";
					}
			}		
		document.getElementById('estado').value=0;
		var elementos=document.getElementById('formulario2').childNodes.length;
		var principal=document.getElementById('formulario2');
		for(var x=0;x<elementos;x++)
			{
				principal.removeChild(principal.firstChild);
			}
	}
function postQuery(id_div,valor,bandera)
	{
		//var url="http://localhost/nomina/processes/query_data.php";
		var url="processes/proc_consulta_cedula.php";
		var object=document.getElementById(id_div);
		var valor=document.getElementById(valor).value;
		var flag=document.getElementById(bandera).value;
		var objectAjax=createAjaxObject();
		objectAjax.open('POST',url,true);
		objectAjax.onreadystatechange=function()
			{
				if(objectAjax.readyState==4)
					{
						var data=objectAjax.responseText;
						object.innerHTML=data;
					}
			}
		objectAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objectAjax.send('cedula='+valor+"&send_query="+flag);
	}	
function asignacion(id_div,valor,bandera)
	{
		//var url="http://localhost/nomina/processes/query_data.php";
		var url="processes/query_data.php";
		var object=document.getElementById(id_div);
		var valor=document.getElementById(valor).value;
		var flag=document.getElementById(bandera).value;
		var objectAjax=createAjaxObject();
		objectAjax.open('POST',url,true);
		objectAjax.onreadystatechange=function()
			{
				if(objectAjax.readyState==4)
					{
						var data=objectAjax.responseText;
						object.innerHTML=data;
					}
			}
		objectAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objectAjax.send('cedula='+valor+"&query="+flag);
	}
function salvar(id_div,valor,bandera)
	{
		var cedula=document.getElementById('cedula');		
		var municipio=document.getElementById('municipio');		
		var aldea=document.getElementById('aldea');
		var nro_alumnos=document.getElementById('alumnos');				
		var unidad=document.getElementById('unidad');
		var horas=document.getElementById('horas');
		if(cedula.value==0 || cedula.value=="")
			{
				alert('El numero de cedula con el que hizo la consulta no debe borrarse,para terminar de guardar los datos');
				cedula.focus();
				return false;
			}
		
		if(municipio.value==0)
			{
				alert('Debe seleccionar primero un municipio');
				municipio.focus();
				return false;
			}
			
		if(aldea.value==0)
			{
				alert('Debe seleccionar ahora una aldea');
				aldea.focus();
				return false;
			}
		if(nro_alumnos.value==0 || nro_alumnos=="")	
			{
				alert('Debe colocar el numero de alumnos');
				nro_alumnos.focus();
				return false;
			}
		if(unidad.value==0)
			{
				alert('Debe seleccionar una unidad curricular');
				unidad.focus();
				return false;
			}		
		//var url="http://localhost/nomina/processes/query_data.php";
		var url="processes/query_data.php";
		var object=document.getElementById(id_div);
		var valor=document.getElementById(valor).value;
		var flag=document.getElementById(bandera).value;
		var objectAjax=createAjaxObject();
		objectAjax.open('POST',url,true);
		objectAjax.onreadystatechange=function()
			{
				if(objectAjax.readyState==4)
					{
						var data=objectAjax.responseText;
						
						//object.childNodes.length=0;
						for(var x=0;x<object.childNodes.length;x++)
							{
								object.removeChild(object.firstChild);
							}							
						object.innerHTML=data;	
						cedula.focus();	
					}
			}
		objectAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		objectAjax.send('cedula='+valor+"&save="+flag+"&municipio="+municipio.value+"&aldea="+aldea.value+"&alumnos="+nro_alumnos.value+"&unidad="+unidad.value+"&horas="+horas.value);
		
	}