
window.onload=function(){
	//para el encabezado
	MM_preloadimages1('img/boton_2.2.jpg','img/boton_1.1.jpg');
	//Para el aviso de primera carga de contenido
	document.getElementById("cargando").style.display="none";
	botones('');
	document.getElementById("contenido").style.display="block";
	var idu = document.getElementById("idu").innerHTML;
	clave_mail(idu);
	validarusuario_inicio();
}

function clave_mail(identificador){
	if(identificador!=0){
	var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue > '0'){
					document.getElementById("cuerpo").innerHTML=document.getElementById("validacion_clave").innerHTML;
					document.getElementById("txt_email_clave").value=texto.getElementsByTagName("email")[0].firstChild.nodeValue;
				}else if (texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					alert("El link utilizado no es válido,\nverifiquelo e inténtelo de nuevo");
					botones('');
				}
			}
		}
		//generando y creando cookie
		conexion.send("acciones=registra_usuario&idusuario="+identificador);
	}
}
/*******************************************ACCIONES DE REGISTRO DE USUARIO**********************************************/
//Función para oacultar todos los formularios que no se están utilizando
function ocultando(i){
	for(y=0; y<=3; y++)
	{
		if(y!=i){
			document.getElementById("formulario"+y).style.display="none";
			document.getElementById("cargando"+y).style.display="none";
			document.getElementById("mas"+y)['onclick']=new Function("formulario"+y+"('mostrar')");
			document.getElementById("img"+y).src="img/plus.gif";
		}
	}
}

//EL REGISTRO DE USUARIO SE HARÁ POR PARTES
//----------------------------------------------------------->DATOS GENERALES
//Datos generales formulario
function formulario0(accion)
{
	if(accion=="mostrar"){
		document.getElementById("formulario0").style.display="block";
		document.getElementById("cargando0").style.display="none";
		document.getElementById("mas0")['onclick']=new Function("formulario0('ocultar')");
		document.getElementById("img0").src="img/minus.gif";
		ocultando(0);
	}
	
	if(accion=="ocultar"){
		document.getElementById("formulario0").style.display="none";
		document.getElementById("cargando0").style.display="none";
		document.getElementById("mas0")['onclick']=new Function("formulario0('mostrar')");
		document.getElementById("img0").src="img/plus.gif";
	}
}

//Ediciòn de datos generales despues de haber sido guardados la primera vez
function editar1(){
	setTimeout("",100);
	document.getElementById("txt_nombres_def").disabled=false;
	document.getElementById("txt_apellidos_def").disabled=false;
	document.getElementById("boton0")['onclick']=new Function("editar_datosgenerales();");
	document.getElementById("boton0").value="listo";
}

//Registro de datos generales
function editar_datosgenerales(){
	if(
	document.getElementById("txt_nombres_def").value!="" &&
	document.getElementById("txt_apellidos_def").value!=""){
		boletin='';
		if(document.getElementById("txt_boletin").checked==true){
			boletin='S';
		}else{
			boletin='N';
		}
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue=='1'){
					document.getElementById("boton0").value="editar";
					document.getElementById("boton0")['onclick']=new Function("editar1();");
					document.getElementById("txt_nombres_def").disabled="true";
					document.getElementById("txt_apellidos_def").disabled="true";
					document.getElementById("txt_email_def").disabled="true";
					document.getElementById("txt_login_def").disabled="true";
					setTimeout("formulario1('mostrar')",100);
				}
				//error de transacciòn
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
					document.getElementById("formulario0").style.display="block";
					document.getElementById("cargando0").style.display="none";
				}
				
			}else{
				document.getElementById("formulario0").style.display="none";
				document.getElementById("cargando0").style.display="block";
			}
		}
		var envio_datos='';
		envio_datos+='acciones=editar_datos1';
		envio_datos+="&txt_nombre="+document.getElementById("txt_nombres_def").value;
		envio_datos+="&txt_apellido="+document.getElementById("txt_apellidos_def").value;
		envio_datos+="&boletin="+boletin;
		envio_datos+="&idusuario="+document.getElementById("idu").innerHTML;
		conexion.send(envio_datos);
	}else{
		alert("Todos los campos marcados con ''(*)'' son obligatorios\n Para continuar ingrese la información faltante");
	}	
}

//Registro de datos generales
function guardar_datosgenerales(){
	if(
	document.getElementById("txt_nombres_def").value!="" &&
	document.getElementById("txt_apellidos_def").value!="" &&
	document.getElementById("txt_email_def").value!="" &&
	document.getElementById("txt_login_def").value!=""){
		boletin='';
		if(document.getElementById("txt_boletin").checked==true){
			boletin='S';
		}else{
			boletin='N';
		}
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue=='1'){
					document.getElementById("boton0").value="editar";
					document.getElementById("boton0")['onclick']=new Function("editar1();");
					document.getElementById("txt_nombres_def").disabled=true;
					document.getElementById("txt_apellidos_def").disabled=true;
					document.getElementById("txt_email_def").disabled=true;
					document.getElementById("txt_login_def").disabled=true;
					setTimeout("formulario1('mostrar')",100);
				}
				//error de transacciòn
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
					document.getElementById("formulario0").style.display="block";
					document.getElementById("cargando0").style.display="none";
				}
				
				//login duplicado
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '2'){
					alert("El nombre de usuario que ha colocado ya está siendo utilizado por otro usuario\nPor favor coloque otro nombre de usuario para continuar");
					document.getElementById("txt_login_def").value="";
					document.getElementById("formulario0").style.display="block";
					document.getElementById("cargando0").style.display="none";
				}
				
			}else{
				document.getElementById("formulario0").style.display="none";
				document.getElementById("cargando0").style.display="block";
			}
		}
		var envio_datos='';
		envio_datos+='acciones=ingresar_datos1';
		envio_datos+="&txt_nombre="+document.getElementById("txt_nombres_def").value;
		envio_datos+="&txt_apellido="+document.getElementById("txt_apellidos_def").value;
		envio_datos+="&txt_email="+document.getElementById("txt_email_def").value;
		envio_datos+="&txt_login="+document.getElementById("txt_login_def").value;
		envio_datos+="&boletin="+boletin;
		envio_datos+="&idusuario="+document.getElementById("idu").innerHTML;
		conexion.send(envio_datos);
	}else{
		alert("Todos los campos marcados con ''(*)'' son obligatorios\n Para continuar ingrese la información faltante");
	}	
}
//----------------------------------------------------------->DATOS PERSONALES
//Datos personales formulario
function formulario1(accion)
{
	if(accion=="mostrar" && document.getElementById("boton0").value=="editar"){
		document.getElementById("formulario1").style.display="block";
		document.getElementById("cargando1").style.display="none";
		document.getElementById("mas1")['onclick']=new Function("formulario1('ocultar')");
		document.getElementById("img1").src="img/minus.gif";
		listar_pais("paises1");
		ocultando(1);
	}
	
	if(document.getElementById("boton0").value!="editar"){
		alert("Debe llenar todos los campos para pasar al siguiente item");
	}
	
	if(accion=="ocultar"){
		document.getElementById("formulario1").style.display="none";
		document.getElementById("cargando1").style.display="none";
		document.getElementById("mas1")['onclick']=new Function("formulario1('mostrar')");
		document.getElementById("img1").src="img/plus.gif";
	}
}

function editar2()
{
	setTimeout("",100);
	document.getElementById("boton_1").value="listo";
	document.getElementById("boton_1")['onclick']=new Function("guardar_datospersonales();");
	document.getElementById("paises1").disabled=false;
	document.getElementById("estados1_select").disabled=false;
	document.getElementById("txt_ciudad").disabled=false;
	document.getElementById("txt_direccion").disabled=false;
}

function guardar_datospersonales(){
	if(
	document.getElementById("paises1").value!="" &&
	document.getElementById("estados1_select").value!="" &&
	document.getElementById("txt_ciudad").value!="" &&
	document.getElementById("txt_direccion").value!=""){
		
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue=='1'){
					document.getElementById("paises1").disabled=true;
					document.getElementById("estados1_select").disabled=true;
					document.getElementById("txt_ciudad").disabled=true;
					document.getElementById("txt_direccion").disabled=true;
					setTimeout("formulario2('mostrar')",110);
					document.getElementById('boton_1').value='editar';
					document.getElementById("boton_1")['onclick']=new Function("editar2();");
				}
				//error de transacciòn
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
					document.getElementById("formulario1").style.display="block";
					document.getElementById("cargando1").style.display="none";
				}
			
			}else{
				document.getElementById("formulario1").style.display="none";
				document.getElementById("cargando1").style.display="block";
			}
		}
		var envio_datos='';
		envio_datos+='acciones=ingresar_datos2';
		envio_datos+="&txt_pais="+document.getElementById("paises1").value;
		envio_datos+="&txt_estado="+document.getElementById("estados1_select").value;
		envio_datos+="&txt_ciudad="+document.getElementById("txt_ciudad").value
		envio_datos+="&txt_direccion="+document.getElementById("txt_direccion").value
		envio_datos+="&idusuario="+document.getElementById("idu").innerHTML;
		conexion.send(envio_datos);
	}else{
		alert("Todos los campos marcados con ''(*)'' son obligatorios\n Para continuar ingrese la información faltante");
	}
}

//----------------------------------------------------------->DATOS DE CLAVE
//Datos DE CLAVE formulario
function formulario2(accion)
{
	if(accion=="mostrar" && document.getElementById("boton_1").value=="editar"){
		document.getElementById("formulario2").style.display="block";
		document.getElementById("cargando2").style.display="none";
		document.getElementById("mas2")['onclick']=new Function("formulario2('ocultar')");
		document.getElementById("img2").src="img/minus.gif";
		listar_pais("paises1");
		ocultando(2);
	}
	
	if(document.getElementById("boton_1").value!="editar"){
		alert("Debe llenar todos los campos para pasar al siguiente item");
	}
	
	if(accion=="ocultar"){
		document.getElementById("formulario2").style.display="none";
		document.getElementById("cargando2").style.display="none";
		document.getElementById("mas2")['onclick']=new Function("formulario2('mostrar')");
		document.getElementById("img2").src="img/plus.gif";
	}
}

function editar3(){
	setTimeout("",100);
	document.getElementById("boton_2").value="listo";
	document.getElementById("boton_2")['onclick']=new Function("guardar_datosclave();");
	document.getElementById("txt_npassword").disabled=false;
	document.getElementById("txt_npassword2").disabled=false;
	document.getElementById("txt_preguntaclave").disabled=false;
	document.getElementById("txt_respuestaclave").disabled=false;
}

function guardar_datosclave(){
	if(
	document.getElementById("txt_npassword").value!="" &&
	document.getElementById("txt_npassword2").value!="" &&
	document.getElementById("txt_preguntaclave").value!="" &&
	document.getElementById("txt_respuestaclave").value!=""){
		if(document.getElementById("txt_npassword").value==document.getElementById("txt_npassword2").value){
			var conexion = conexionajax();
			conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
			conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
			conexion.onreadystatechange = function() {
				if (conexion.readyState==4) {
					var texto = conexion.responseXML;
					if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue=='1'){
						document.getElementById("boton_2").value="editar";
						document.getElementById("boton_2")['onclick']=new Function("editar3();");
						document.getElementById("txt_npassword").disabled=true;
						document.getElementById("txt_npassword2").disabled=true;
						document.getElementById("txt_preguntaclave").disabled=true;
						document.getElementById("txt_respuestaclave").disabled=true;
						setTimeout("formulario3('mostrar')",100);
					}
					//error de transacciòn
					if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
						alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
						document.getElementById("formulario2").style.display="block";
						document.getElementById("cargando2").style.display="none";
					}
				
				}else{
					document.getElementById("formulario2").style.display="none";
					document.getElementById("cargando2").style.display="block";
				}
			}
			var envio_datos='';
			envio_datos+='acciones=ingresar_datos3';
			envio_datos+="&txt_password="+document.getElementById("txt_npassword").value;
			envio_datos+="&txt_pregunta="+document.getElementById("txt_preguntaclave").value;
			envio_datos+="&txt_respuesta="+document.getElementById("txt_respuestaclave").value
			envio_datos+="&idusuario="+document.getElementById("idu").innerHTML;
			conexion.send(envio_datos);
		}else{
			alert("Los campos de nueva clave no coinciden.\nPor favor verifique e intente de nuevo");
			document.getElementById("txt_npassword2").value="";
			document.getElementById("txt_npassword").value="";
		}
	}else{
		alert("Todos los campos marcados con ''(*)'' son obligatorios\n Para continuar ingrese la información faltante");
	}
}

//----------------------------------------------------------->DATOS DE TELEFONO
//Datos DE TELEFONO formulario
function formulario3(accion)
{
	if(accion=="mostrar" && document.getElementById("boton_2").value=="editar"){
		listar_telefonos('lista_telefonos',document.getElementById("idu").innerHTML);
		document.getElementById("formulario3").style.display="block";
		document.getElementById("cargando3").style.display="none";
		document.getElementById("mas3")['onclick']=new Function("formulario3('ocultar')");
		document.getElementById("img3").src="img/minus.gif";
		ocultando(3);
	}
	
	if(document.getElementById("boton_2").value!="editar"){
		alert("Debe llenar todos los campos para pasar al siguiente item");
	}
	
	if(accion=="ocultar"){
		document.getElementById("formulario3").style.display="none";
		document.getElementById("cargando3").style.display="none";
		document.getElementById("mas3")['onclick']=new Function("formulario3('mostrar')");
		document.getElementById("img3").src="img/plus.gif";
	}
}


function listar_telefonos(div,idusuario){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseText;
			document.getElementById(div).innerHTML="";
			document.getElementById(div).innerHTML+=texto;
		}else{
			document.getElementById(div).innerHTML="Cargando listado de teléfonos";
		}
	}
	//generando y creando cookie
	conexion.send("acciones=listar_telefonos&idusuario="+idusuario);
}


function agregar_telefono(idusuario){
	
	tipo = document.getElementById("lst_telefonos").options[document.getElementById("lst_telefonos").selectedIndex].value;
	if(document.getElementById("txt_codigo").value !="" &&
	document.getElementById("txt_numero").value !=""&& 
	tipo !=""){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					//mensaje de registro satisfactorio
					alert("Nuevo teléfono agregado satisfactoriamente");
					document.getElementById("txt_codigo").value ="";
					document.getElementById("txt_numero").value =""; 
					listar_telefonos("lista_telefonos",idusuario);
				}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					//mensaje d eerror
					alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
				}
			}
		}
		conexion.send("acciones=agregar_telefono&txt_codigo="+document.getElementById("txt_codigo").value+"&txt_numero="+document.getElementById("txt_numero").value+"&tipo="+tipo+"&idusuario="+idusuario);
	}else{
		alert("Todos los campos para el ingreso de teléfono son obligatorios\n Para continuar ingrese la información faltante");
	}
}

function eliminar_telefono(num,idusuario){
	var conexion = conexionajax();
	var idtelefono='';
	for(var i=0; i< num; i++){
		if(document.getElementById("telf_"+i).checked==true){
			idtelefono+="@"+document.getElementById("telf_"+i).value;		
		}
	}
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				//mensaje de registro satisfactorio
				alert("Número de teléfono eliminado satisfactoriamente");
				listar_telefonos("lista_telefonos",idusuario);
			}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
				//mensaje d eerror
				alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
			}
		}
	}
	conexion.send("acciones=eliminar_telefono&idtelefono="+idtelefono);
}

//--------------------------------------------------------->TERMINANDO TODO EL REGISTRO DE NUEVO USUARIO
function culmina_registro(){
	var telefonos=document.getElementById("lista_telefonos").getElementsByTagName("input").length;
	if(telefonos!=0){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue=='1'){
				alert("Usted ha culminado satisfactoriamente su registro de usuario");
				botones('');				
			}
			//error de transacciòn
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
				alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
			}
		}else{
			document.getElementById("cuerpo").innerHTML=document.getElementById("cargando_general").innerHTML;
		}
	}
	var envio_datos='';
	envio_datos+='acciones=culmina_registro';
	envio_datos+="&idusuario="+document.getElementById("idu").innerHTML;
	conexion.send(envio_datos);
	}else{
		alert("Debe registra por lo menos un número de teléfono para culminar su registro");
	}
}

/*************************************************************************************************************/

function registro_usurario(identificador,pass){
	if(identificador!=0){
	var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue > '0'){
					document.getElementById("pass").innerHTML=document.getElementById("txt_nombres_def").value;
					document.getElementById("cuerpo").innerHTML=document.getElementById("registro_formulario").innerHTML;
					document.getElementById("txt_nombres_def").value=texto.getElementsByTagName("nombre")[0].firstChild.nodeValue;
					document.getElementById("txt_apellidos_def").value=texto.getElementsByTagName("apellido")[0].firstChild.nodeValue;
					document.getElementById("txt_email_def").value=texto.getElementsByTagName("email")[0].firstChild.nodeValue;
					listar_pais("lst_paises");
					listar_telefonos("lista_telefonos",identificador);
				}else if (texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					alert("El link utilizado no es válido,\nverifiquelo e inténtelo de nuevo");
					botones('');
				}
			}
		}
		conexion.send("acciones=registra_usuario&idusuario="+identificador+"&txt_pass="+pass);
	}
}

function validar_correo(){
	if(document.getElementById("txt_nombres1").value!="" && document.getElementById("txt_apellidos1").value!=""&& document.getElementById("txt_email").value!=""){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					//Mensaje de respuesta satisfactoria y vuelta al home sin logueo	
					alert("Sus datos han sido enviados satisfactoriamente\nPor favor verifique su buzón de correo electrónico\npara continuar con el proceso de registro");
					botones('');
				} 
				
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					//Mensaje de error, vaciado del campo mail
					alert("Se ha detectado un error al enviar sus datos\nPor favor verifique sus datos e intente de nuevo");					
					document.getElementById("txt_email").value="";
				}
				
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '2'){
					//Mensaje de error, mail duplicado
					alert("El correo electrónico que ingresó ya ha sido utilizado por otro usuario\nPara continuar coloque otra direeción");
					document.getElementById("txt_email").value="";
				}
			}else if(conexion.readyState==1){
				//mensaje de espera
				//validacion_correo
				document.getElementById("validacion_correo").style.display="none";
				document.getElementById("mensaje_registro").style.display="block";
				document.getElementById("mensaje_registro").innerHTML=document.getElementById("cargando").innerHTML;
			}
		}
		//generando y creando cookie
		conexion.send("acciones=valida_correo&txt_nombres="+document.getElementById('txt_nombres1').value+"&txt_apellidos="+document.getElementById('txt_apellidos1').value+"&txt_email="+document.getElementById('txt_email').value);
	}else{
		alert ("Debe llenar todos los campos para continuar");
	}
}

function pregunta_calve(){
	mail=document.getElementById("txt_email_recupera_clave").value;
	if(document.getElementById("txt_email_recupera_clave").value!=""){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue != '0'){
				document.getElementById("res_email").innerHTML=mail;
				document.getElementById("cuerpo").innerHTML=document.getElementById("recupera_clave_pregunta").innerHTML;
				document.getElementById("txt_pregunta_recupera_clave").innerHTML=texto.getElementsByTagName("resultado")[0].firstChild.nodeValue;
			}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0' || texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == ''){
				alert("Su cuenta de correo electrónico no se ha registrado en nuestro sistema\no usted no ha completado correctamente los pasos de registro de usuario\nPor favor, verifique sus datos e intente de nuevo");
				document.getElementById("txt_email_recupera_clave").value='';
				document.getElementById("cuerpo").innerHTML=document.getElementById("recupera_clave_principal").innerHTML;
			}
		}else{
			document.getElementById("cuerpo").innerHTML=document.getElementById("cargando").innerHTML;
		}
	}
	conexion.send("acciones=recupera_clave&email="+document.getElementById("txt_email_recupera_clave").value);
	}else{
		alert("Debe colocar su correo electrónico para procesar su solicitud");
	}
}

function rpclave(email){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue != '0'){
				alert("Hemos enviado a su correo electrónico una nueva clave");
				botones('');
			}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
				alert("Su respuesta no es correcta\n verifique e intente de nuevo");
				document.getElementById("txt_respuesta_recupera_clave").value='';
			}
		}else{
			document.getElementById("cuerpo").innerHTML=document.getElementById("cargando").innerHTML;
		}
	}
	conexion.send("acciones=respuesta_clave&respuesta="+document.getElementById("txt_respuesta_recupera_clave").value+"&email="+email+"&pregunta="+document.getElementById("txt_pregunta_recupera_clave").innerHTML);
}

function cambio_clave(){
	if(
	document.getElementById("txt_clave_anterior").value!="" &&
	document.getElementById("txt_clave_nueva").value!="" &&
	document.getElementById("txt_clave_nueva2").value!=""
	){
		if(document.getElementById("txt_clave_nueva").value==document.getElementById("txt_clave_nueva2").value){
			var conexion = conexionajax();
			conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/principal.php');
			conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
			conexion.onreadystatechange = function() {
				if (conexion.readyState==4) {
					var texto = conexion.responseXML;
					if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue != '0'){
						alert("Hemos enviado a su correo electrónico una nueva clave");
						salir();
					}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
						alert("Ha ocuerrido un error al procesar su solicitud.\nPor favor intente de nuevo");
					}
				}else{
					document.getElementById("cuerpo").innerHTML=document.getElementById("cargando").innerHTML;
				}
			}
			conexion.send("acciones=cambio_clave&anterior="+document.getElementById("txt_clave_anterior").value+"&nueva="+document.getElementById("txt_clave_nueva").value+"&idusuario="+getCookie("user"));
		}else{
			alert("Los campos de nueva contraseña no coinciden\nVerifique sus datos e intente de nuevo");
		}
	}else{
		alert("Es necesario que sea llenados todos los campos\npara procesar su solicitud");
	}
}