function createRequestObject(){
	var peticion;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		peticion = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		peticion = new XMLHttpRequest();
	}
	return peticion;
}

var http = new Array();
function ObtDatosGET(url,name){
	var act = new Date();
	http[act] = createRequestObject();
	http[act].open('get', url);
	http[act].onreadystatechange = function() {
		if (http[act].readyState == 4) {
			if (http[act].status == 200 || http[act].status == 304) {
				var texto;
				texto = http[act].responseText;
				if(texto.length > 0){
					var DivDestino = document.getElementById("Div-"+ name);
					
					DivDestino.className ='diverror';
					DivDestino.innerHTML = texto;
					if(typeof Effect == 'undefined') {
						DivDestino.style.display = 'block';
					} else {
						new Effect.Appear("Div-"+name, {duration : 1 });
					}
				}
				else{
					var DivDestino = document.getElementById("Div-"+ name);
					
					DivDestino.className ='divcorrecto';
					DivDestino.innerHTML = '<img src="/img/pixel.gif" width="18" height="19" border="0" alt="Correcto"/>';
					if(typeof Effect == 'undefined') {
						DivDestino.style.display = 'block';
					} else {
						new Effect.Appear("Div-"+name, {duration : 1 });
					}
				}
			}
		}
	}
	http[act].send(null);
}
function ObtDatosPOST(url,name){
	var act = new Date();
	http[act] = createRequestObject();
	http[act].open('get', url);
	http[act].onreadystatechange = function() {

		if (http[act].readyState == 4) {
			if (http[act].status == 200 || http[act].status == 304) {
				var texto;
				texto = http[act].responseText;
				if(texto.length > 0){
					var DivDestino = document.getElementById("Div-"+ name);
					DivDestino.className ='diverror';
					//alert('Respuesta AJAX: '+texto);
					DivDestino.innerHTML = texto;
					if(typeof Effect == 'undefined') {
						DivDestino.style.display = 'block';
					} else {
						new Effect.Appear("Div-"+name, {duration : 1 });
					}
				}
			}
		}
	}


	http[act].send(null);
}
function compCampoUP(Tecla,name,codUsuario) {
	Tecla = (Tecla) ? Tecla: window.event;
	input = document.getElementById(name);
	if (Tecla.type == "keyup") {
		var DivDestino = document.getElementById('Div-'+name);
		DivDestino.innerHTML = "";
		DivDestino.style.display = 'none';
		if (input.value) {
			if (codUsuario != null){
				ObtDatosGET("/registro/index.phtml?campo=NICK" + "&q=" + input.value + "&codUsuario=" + codUsuario,name);
			}
			else{
				ObtDatosGET("/registro/index.phtml?campo=" + name + "&q=" + input.value,name);
			}
		}
	}
}

function compCampoCHANGE(name,codUsuario) {
	input = document.getElementById(name);
	var DivDestino = document.getElementById('Div-'+name);
	DivDestino.innerHTML = "";
	DivDestino.style.display = 'none';
	if (codUsuario != null){
		ObtDatosGET("/registro/index.phtml?campo=NICK" + "&q=" + input.value + "&codUsuario=" + codUsuario,name);
	}
	else{
		ObtDatosGET("/registro/index.phtml?campo=" + name + "&q=" + input.value,name);
	}
}

function compCamposIgualesCHANGE(name1,name2){
	input1 = document.getElementById(name1);
	input2 = document.getElementById(name2);
	var DivDestino1 = document.getElementById('Div-'+name1);
	DivDestino1.innerHTML = "";
	DivDestino1.style.display = 'none';
	if ((input1.value) || (input2.value)) {
		ObtDatosGET("/registro/index.phtml?campo="+ name1 +"&q=" + input1.value + "&campo2=" + name2+"&q2="+input2.value,name1);
	}
}


