/****************************************************************
/ Nombre: getHTTPObject
/ Implentacion: 
/ Revision: 301106
/ Descripcion: Manejo del AJAX
'***************************************************************/
function getHTTPObject() {
	var xmlhttp;      
  
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/
  
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {  
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	}
	return xmlhttp;
}
    
//--
var http = getHTTPObject(); 


function comprobarDatos(usuario,email){
	
	url="comprobar-datos.asp?usuario=" + usuario + "&email=" + email;
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseDatos;
	http.send(null);
}



function handleHttpResponseDatos() {
	if (http.readyState == 4) {    
		//document.getElementById("capaFlechas").innerHTML = http.responseText;
		var respuesta=http.responseText;
		
		if (respuesta=="no"){
			document.getElementById("formulario").submit();
		}else{
			document.getElementById("buscando").style.display="none";
			alert(respuesta);	
		}
	}    
}


function comprobarDatos2(usuario,email,id){
	
	url="comprobar-datos2.asp?usuario=" + usuario + "&email=" + email + "&id=" + id;
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseDatos2;
	http.send(null);
}

function handleHttpResponseDatos2() {
	if (http.readyState == 4) {    
		//document.getElementById("capaFlechas").innerHTML = http.responseText;
		var respuesta=http.responseText;
		
		if (respuesta=="no"){
			document.getElementById("formulario").submit();
		}else{
			alert(respuesta);	
		}
	}    
}


function validarForo(){
	var texto="";
	
	if(document.getElementById("formulario").usuario.value==""){
		texto+="* Debe insertar su nombre de usuario.\n"	
	}
	
	if(document.getElementById("formulario").clave.value==""){
		texto+="* Debe insertar su clave de acceso.\n"	
	}
	
	if(texto!=""){
		alert(texto)	
	}else{
		url="login-foro.asp?usuario=" + document.getElementById("formulario").usuario.value + "&clave=" + document.getElementById("formulario").clave.value;
		http.open("GET", url , true);
		http.onreadystatechange = handleHttpResponseLoginForo;
		http.send(null);	
	}
}

function handleHttpResponseLoginForo() {
	if (http.readyState == 4) {    
		var respuesta=http.responseText;
		if (respuesta=="no"){
			alert("Datos de acceso incorrectos.");	
		}else{
			if (respuesta=="inactivo"){
				alert("Usuario inactivo.");			
			}else{
				document.location="foro.asp"	
			}
		}
	}    
}

function cerrarSesionForo(){
	url="cerrar-sesion-foro.asp"
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseCerrarSesionForo;
	http.send(null);	
}

function handleHttpResponseCerrarSesionForo() {
	if (http.readyState == 4) {    
		document.location="foro.asp";
	}    
}

function crearTema(){
	document.location="crear-tema.asp";
}

function validarTema(){
	var texto="";
	
	if(document.getElementById("formularioTema").titulo.value==""){
		texto+="* Debe insertar un titulo.\n"	
	}
	
	if(document.getElementById("formularioTema").mensaje.value==""){
		texto+="* Debe insertar un mensaje.\n"	
	}
	
	if(texto!=""){
		alert(texto)	
	}else{
		document.getElementById("capaCargaTema").style.display="block";
		document.getElementById("formularioTema").submit();
	}
}

function responderForo(id){
	document.location="responder-tema.asp?id=" + id
}

function validarRespuesta(){
	if(document.getElementById("formularioRespuesta").respuesta.value==""){
		alert("* Debe incluir la respuesta al mensaje.")	
	}else{
		document.getElementById("capaCargaRespuesta").style.display="block";
		document.getElementById("formularioRespuesta").submit();
	}	
}
