/****************************************************************
/ 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(); 

var posX,posY;
posX=0;
posY=0;


function siguiente(id,pos,total){
	
	url="foto-siguiente.asp?id=" + id + "&pos=" + pos + "&total=" + total
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseSiguiente;
	http.send(null);
}

function anterior(id,pos,total){
	
	url="foto-anterior.asp?id=" + id + "&pos=" + pos + "&total=" + total
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseSiguiente;
	http.send(null);
}


function handleHttpResponseSiguiente() {
	if (http.readyState == 4) {    
		document.getElementById("capaFlechas").innerHTML = http.responseText;
	}    
}

//**** PARA LAS CARAS 
function selCara(cara){
	url="SessionFace.asp?face=" + cara;
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseCaras;
	http.send(null);
}

function handleHttpResponseCaras() {
	if (http.readyState == 4) {    
		document.getElementById("capaCaras").style.display = "none";
	}    
}

//**** PARA cajas accesos
function cargarAccesos(){
	url="accesos2.asp"
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseAccesos;
	http.send(null);
}

function handleHttpResponseAccesos() {
	if (http.readyState == 4) {    
		document.getElementById("lateral").innerHTML=http.responseText;
		
		//ahora cargamos las cajas de abajo
		cargarCajas();
	}    
}

function cargarCajas(){
	url="cajas.asp"
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseCajas;
	http.send(null);
}

function handleHttpResponseCajas() {
	if (http.readyState == 4) {    
		document.getElementById("contenidoAbajo").innerHTML=http.responseText;
	}    
}

function abrirRegistro(){
	document.getElementById("capaNick").style.display="block";	
}

function cerrarNick(){
	document.getElementById("capaNick").style.display="none";	
	document.getElementById("textoRespuesta").innerHTML="";	
	document.getElementById("formularioNick").reset();
}

function registrarNick(){
	var texto=""
	
	if (document.getElementById("formularioNick").nombre.value==""){
		texto+=" - Debe insertar su nombre.\n"	
	}
	
	if (document.getElementById("formularioNick").nick.value==""){
		texto+=" - Debe insertar el nick a registrar.\n"	
	}
	
	if (document.getElementById("formularioNick").email.value==""){
		texto+=" - Debe insertar su email.\n"	
	}
	
	if (texto!=""){
		alert(texto);
	}else{
		var nombre=document.getElementById("formularioNick").nombre.value;
		var nick=document.getElementById("formularioNick").nick.value;
		var email=document.getElementById("formularioNick").email.value;
		url="registrarNick.asp?nombre=" + nombre + "&nick=" + nick + "&email=" + email
		http.open("GET", url , true);
		http.onreadystatechange = handleHttpResponseNick;
		http.send(null);
	}
}

function handleHttpResponseNick() {
	if (http.readyState == 4) {    
		var respuesta=http.responseText;
		if (respuesta=="email"){
			document.getElementById("textoRespuesta").innerHTML="El email introducido ya está registrado."	
			document.getElementById("formularioNick").reset();
		}else{
			if (respuesta=="nick"){
				document.getElementById("textoRespuesta").innerHTML="El nick introducido ya está registrado."	
				document.getElementById("formularioNick").reset();
			}else{
				document.getElementById("textoRespuesta").innerHTML="El nick se ha registrado con éxito."
				document.getElementById("formularioNick").reset();
			}
		}
	}    
}