var paso1=true;
var paso2=false;
var paso3=false;
function habilitarPaso3(rd){
	if(paso2==true){
		error=false;
		if(!rd){
			if(window.document.getElementById("nombre").value==""){window.document.getElementById("Ina2").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ina2").style.color="#FFFFFF";}
			if(window.document.getElementById("apellido").value==""){window.document.getElementById("Ina3").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ina3").style.color="#FFFFFF";}
			if(window.document.getElementById("celular").value==""){window.document.getElementById("Ina6").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ina6").style.color="#FFFFFF";}
			if(window.document.getElementById("telefono").value==""){window.document.getElementById("Ina7").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ina7").style.color="#FFFFFF";}
			if(window.document.getElementById("correo").value==""){window.document.getElementById("Ca2").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ca2").style.color="#FFFFFF";}
			if(window.document.getElementById("contrasena").value==""){window.document.getElementById("Ca3").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ca3").style.color="#FFFFFF";}
			if(window.document.getElementById("repcontrasena").value==""){window.document.getElementById("Ca4").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ca4").style.color="#FFFFFF";}
			if(window.document.getElementById("repcontrasena").value!=window.document.getElementById("contrasena").value){error=true;window.document.getElementById("resultado").innerHTML="<strong style='color=#FF0000;border:1px solid #FF0000'>Error las contrasenas no coinciden</strong>";}
			
			if(!error){
				var element=document.getElementById("sexo");
				var cualSexo=element.options[element.selectedIndex].value;
				var element2=document.getElementById("ubicacion");
				var cualubicacion=element.options[element.selectedIndex].value;
				var ajax = new PhpConnection();
				ajax.executeQueryMejorado("php/validarUsuarios.php",callbackMessage2,"Modo=nuevousuario&correo="+window.document.getElementById("correo").value+"&contrasena="+window.document.getElementById("contrasena").value+"&nombre="+window.document.getElementById("nombre").value+"&apellido="+window.document.getElementById("apellido").value+"&celular="+window.document.getElementById("celular").value+"&telefono="+window.document.getElementById("telefono").value+"&sexo="+cualSexo+"&ubicacion="+cualubicacion);
			}
		}
		if(!error){
			paso3=true;
			CambiarImagen("step3","images/step3.gif");
			CambiarImagen("prgStep","images/stepsPG3.gif");
			
			window.document.getElementById("Re1").style.color="#333333";
			window.document.getElementById("Re2").style.color="#333333";
			window.document.getElementById("Re3").style.color="#333333";
			window.document.getElementById("Re4").style.color="#333333";
			window.document.getElementById("Re6").style.color="#333333";
		
			window.document.getElementById("Rea3").style.color="#FFFFFF";
			window.document.getElementById("Rea4").style.color="#FFFFFF";
			
			window.document.getElementById("homenajeado").disabled="";
			
			deshabilitarPaso2();
		}
	}
}

function habilitarPaso1(){
	CambiarImagen("step1","images/step2.gif");
	CambiarImagen("sg1","images/siguiente.gif");
	paso1=true;
	window.document.getElementById("Cr1").style.color="#333333";
	window.document.getElementById("Cr2").style.color="#333333";
	window.document.getElementById("Cr3").style.color="#333333";
	window.document.getElementById("Cr4").style.color="#333333";

	
	window.document.getElementById("Ca2").style.color="#FFFFFF";
	window.document.getElementById("Ca3").style.color="#FFFFFF";
	window.document.getElementById("Ca4").style.color="#FFFFFF";
	
	window.document.getElementById("correo").disabled="";
	window.document.getElementById("contrasena").disabled="";
	window.document.getElementById("repcontrasena").disabled="";
}

function habilitarPaso2(){
	if(paso1==true){
		error=false;
		if(window.document.getElementById("correo").value==""){window.document.getElementById("Ca2").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ca2").style.color="#FFFFFF";}
		if(window.document.getElementById("contrasena").value==""){window.document.getElementById("Ca3").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ca3").style.color="#FFFFFF";}
		if(window.document.getElementById("repcontrasena").value==""){window.document.getElementById("Ca4").style.color="#FF0000"; error=true;}else{window.document.getElementById("Ca4").style.color="#FFFFFF";}
		if(window.document.getElementById("repcontrasena").value!=window.document.getElementById("contrasena").value){error=true;window.document.getElementById("resultado").innerHTML="<strong style='color=#FF0000;border:1px solid #FF0000'>Error las contrasenas no coinciden</strong>";}
		
		if(!error){
			CambiarImagen("step2","images/step2.gif");
			CambiarImagen("prgStep","images/stepsPG2.gif");
			CambiarImagen("sg2","images/siguiente.gif");
			window.document.getElementById("In1").style.color="#333333";
			window.document.getElementById("In2").style.color="#333333";
			window.document.getElementById("In3").style.color="#333333";
			window.document.getElementById("In4").style.color="#333333";
			window.document.getElementById("In5").style.color="#333333";
			window.document.getElementById("In6").style.color="#333333";
			window.document.getElementById("In7").style.color="#333333";
		
			window.document.getElementById("Ina2").style.color="#FFFFFF";
			window.document.getElementById("Ina3").style.color="#FFFFFF";
			window.document.getElementById("Ina6").style.color="#FFFFFF";
			window.document.getElementById("Ina7").style.color="#FFFFFF";
			
			window.document.getElementById("telefono").disabled="";
			window.document.getElementById("celular").disabled="";
			window.document.getElementById("ubicacion").disabled="";
			window.document.getElementById("sexo").disabled="";
			window.document.getElementById("apellido").disabled="";
			window.document.getElementById("nombre").disabled="";
			paso2=true;
			deshabilitarPaso1();
		}
		else{
		}
	}
}

function callbackMessage2(resp){
	if(resp.responseText=='noexiste'){
		paso3=true;
		window.document.getElementById("resultado").innerHTML="";
	}
	else{
		window.document.getElementById("correo").value="";
		window.document.getElementById("contrasena").value="";
		window.document.getElementById("repcontrasena").value="";
		window.document.getElementById("resultado").innerHTML="<strong style='color=#FF0000;border:1px solid #FF0000'>Error usuario ya existe, digitar otro</strong>";
		deshabilitarPaso2();
		deshabilitarPaso3();
		habilitarPaso1();
	}
}

function deshabilitarPaso1(){
	paso1=false;
	CambiarImagen("step1","images/step1inactivo.gif");
	CambiarImagen("sg1","images/siguienteInactivo.gif");
	window.document.getElementById("Cr1").style.color="#999999";
	window.document.getElementById("Cr2").style.color="#999999";
	window.document.getElementById("Cr3").style.color="#999999";
	window.document.getElementById("Cr4").style.color="#999999";

	
	window.document.getElementById("Ca2").style.color="#FFFFFF";
	window.document.getElementById("Ca3").style.color="#FFFFFF";
	window.document.getElementById("Ca4").style.color="#FFFFFF";
	
	window.document.getElementById("correo").disabled="true";
	window.document.getElementById("contrasena").disabled="true";
	window.document.getElementById("repcontrasena").disabled="true";
}

function deshabilitarPaso2(){
	paso2=false;
	CambiarImagen("step2","images/step2inactivo.gif");
	CambiarImagen("sg2","images/siguienteInactivo.gif");
	window.document.getElementById("In1").style.color="#999999";
	window.document.getElementById("In2").style.color="#999999";
	window.document.getElementById("In3").style.color="#999999";
	window.document.getElementById("In4").style.color="#999999";
	window.document.getElementById("In5").style.color="#999999";
	window.document.getElementById("In6").style.color="#999999";
	window.document.getElementById("In7").style.color="#999999";

	window.document.getElementById("Ina2").style.color="#FFFFFF";
	window.document.getElementById("Ina3").style.color="#FFFFFF";
	window.document.getElementById("Ina6").style.color="#FFFFFF";
	window.document.getElementById("Ina7").style.color="#FFFFFF";
			
	window.document.getElementById("telefono").disabled="true";
	window.document.getElementById("celular").disabled="true";
	window.document.getElementById("ubicacion").disabled="true";
	window.document.getElementById("sexo").disabled="true";
	window.document.getElementById("apellido").disabled="true";
	window.document.getElementById("nombre").disabled="true";
}

function deshabilitarPaso3(){
	paso3=false;
	CambiarImagen("step3","images/step3inactivo.gif");
	CambiarImagen("fin","images/finalizarInactivo.gif");
	window.document.getElementById("Re1").style.color="#999999";
	window.document.getElementById("Re2").style.color="#999999";
	window.document.getElementById("Re3").style.color="#999999";
	window.document.getElementById("Re4").style.color="#999999";
	window.document.getElementById("Re6").style.color="#999999";

	window.document.getElementById("Rea3").style.color="#FFFFFF";
	window.document.getElementById("Rea4").style.color="#FFFFFF";
			
	window.document.getElementById("homenajeado").disabled="true";
	window.document.getElementById("fecha").disabled="true";
	window.document.getElementById("hora").disabled="true";
	window.document.getElementById("evento").disabled="true";
}

function Finalizar(valor){
	if(paso3==true){
		error=false;
		if(window.document.getElementById("homenajeado").value==""){window.document.getElementById("Rea4").style.color="#FF0000"; error=true;}else{window.document.getElementById("Rea4").style.color="#FFFFFF";}
		if(!error){
			var ajax = new PhpConnection();
			ajax.executeQueryMejorado("php/registrarEvento.php",callbackMessage3,"Modo=registrarEvento&evento="+window.document.getElementById("evento").value+"&fecha="+window.document.getElementById("fecha").value+"&hora="+window.document.getElementById("hora").value+"&homenajeado="+window.document.getElementById("homenajeado").value);
			valor.submit();
		}
		else{
			return false;
		}
	}
}

function transaccionTemp(){
}
function callbackMessage3(resp){
	if(resp.responseText=='correct'){
		window.location.href="miBusqueda.php";
	}
	else{
		window.document.getElementById("resultado").innerHTML="<strong style='color=#FF0000;border:1px solid #FF0000'>Error fecha no disponible</strong>";
	}
}
function Inicializar(variable){
	if(variable=='pasotres'){
		deshabilitarPaso2();
		deshabilitarPaso1();
		paso2=true;
		habilitarPaso3(true);
	}
	else{
		deshabilitarPaso3();
		deshabilitarPaso2();
		habilitarPaso1();
		CambiarImagen("prgStep","images/stepsPG1.gif");
	}
}

function MostrarCuenta(cuenta){
	switch(cuenta){
		case 'bp':
			window.document.getElementById("lblCuenta").innerHTML="Banco Popular: 100-15545545-522-0";
			break;
		case 'bcr':
			window.document.getElementById("lblCuenta").innerHTML="BCR: 001-0-191721-8";
			break;
		case 'bac':
			window.document.getElementById("lblCuenta").innerHTML="BAC: 802020330";
			break;
		case 'bn':
			window.document.getElementById("lblCuenta").innerHTML="BN: 200-01-000-174765-7";
			break;
	}
}

/*******************/
/*Clase Ajax*/
function Ajax (){
	this.XMLHttpRequestObject=false;
	//ejecuta una consulta en php, y retorna dependiendo del modo
	this.executeQuery=function(mode,dataSource, divID) {
		//crea el objeto xmlHTTP
		if (window.XMLHttpRequest) {
			XMLHttpRequestObject = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) {
			XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if(XMLHttpRequestObject) {
			var obj = document.getElementById(divID);
			XMLHttpRequestObject.open("GET", dataSource);
			XMLHttpRequestObject.onreadystatechange = function(){
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					
				}
			}
			XMLHttpRequestObject.send(null);
		}
	}
}