// JavaScript Document
var contenedorFichas = new Array();
var consultaRapida = function(nombreCuadro,nombreFicha){
	var nombre = document.getElementById("nombreConsulta");
	var direccion = document.getElementById("direccionConsulta");
	var telefono = document.getElementById("telefonoConsulta");
	var email = document.getElementById("emailConsulta");
	var consulta = document.getElementById("consultaConsulta");
	var blockeador = document.getElementById("blockeadorConsulta");
	var cuadro = document.getElementById(nombreCuadro);
	var ficha = document.getElementById(nombreFicha);
	var blockeadorFicha = document.getElementById("blockeadorFichaConsulta");
	var archivo = "requests/cargarHTMLProducto.php";
	var totalErrores = 0;
	var oClase = this;
	var enviar = document.getElementById("enviarConsulta");
	var enviando = document.getElementById("enviandoConsulta");
	var exito = document.getElementById("exitoConsulta");
	var fallo = document.getElementById("falloConsulta");
	var cerrar = document.getElementById("cerrarConsulta");
	var errorConsulta = $('errorConsulta');
	
	var dirImagenes = "img/";
	this.req = new Request(oClase);

		
	if(Nav.esIE || Nav.esIE7) blockeador.style.filter = 'alpha(opacity=45)';
	else blockeador.style.MozOpacity = ".45";
	this.centrarContenido = function(objeto){
		var pos = getScrollPos();
		var scrn = getBodyWHAvaible();
		var dim = getBodyWHAvaible();
		objeto.style.top = (Math.round((dim.h - objeto.offsetHeight)/2)+pos.y)+"px";
		objeto.style.left = (Math.round((scrn.w - objeto.offsetWidth)/2)+pos.x)+"px";
	}
	var crearError = function(campo,mensaje,expresion){
		var contenido = document.createElement("div");
		contenido.className = "contenidoError";
		if(!(Nav.esIE || Nav.esIE7))contenido.style.width = "180px";
		var flecha = document.createElement("img");
		flecha.src = dirImagenes+"redArrow.gif";
		var mens = document.createElement("mensaje");
		mens.innerHTML = mensaje;
		mens.className = "mensajeError";
		contenido.appendChild(flecha);
		contenido.appendChild(mens);
		campo.parentNode.appendChild(contenido);
		campo.contenido = contenido;
		campo.expresion = expresion;

		campo.onblur = function(){
			if(!campo.expresion.test(campo.value.toLowerCase()))mostrarError(campo);
			else ocultarError(campo);
		}
	}
	var crearError2 = function(campo,mensaje,expresion){
		campo.expresion = expresion;
		campo.onblur = function(){
			if(!campo.expresion.test(campo.value.toLowerCase())){
				campo.className = "inputError";
				return mensaje;
			}
			else{ 
				campo.className = "inputConsulta";
				return "";
			}
		}
	}	
	var crearErrores = function(){
		crearError2(nombre,'Ingrese su nombre<br/>',ER_STR);
		crearError2(email,'Email incorrecto<br/>',ER_EMAIL);
		crearError2(consulta,'Ingrese la consulta<br/>',ER_STR);		
	}
	var mostrarError = function(campo){
		totalErrores++;
		campo.contenido.style.display = "inline";
		campo.className = "inputError";
	}
	var ocultarError = function(campo){
		campo.contenido.style.display = "none";
		campo.className = 'inputConsulta';
	}
	var mostrarBlockeador = function(valor){
		if(valor){
			var scrn = getBodyDims();
			var pant = getBodyWHAvaible();
			var dim = getWindowDims();
			var pos = getScrollPos();
			blockeador.style.display = "block";
			if(Nav.esIE)blockeador.style.height = (scrn.h)+"px";
			else blockeador.style.height = (scrn.h)+"px";

			blockeador.style.width = dim.w+"px";
		}
		else blockeador.style.display = "none";
	}
	var ocultarCuadro = function(){
		mostrarBlockeador();	
		limpiarCampos();
		cuadro.style.visibility = "hidden";
		cuadro.style.top = "-1000px";
	}
	this.mostrarCuadro = function(idRegistro,e){
		limpiarCampos();
		this.idRegistro = idRegistro;
		if(!contenedorFichas[idRegistro]){
			this.req.pedir(archivo,"idRegistro|=|"+idRegistro+"|&|");
			ficha.style.display = "none";
			blockeadorFicha.style.display = "block";
			mostrarBlockeador(true);
			cuadro.style.visibility = "visible";
			oClase.centrarContenido(cuadro);
		}
		else{
			ficha.innerHTML = contenedorFichas[idRegistro].html;
			cuadro.style.visibility = "visible";
			oClase.centrarContenido(cuadro);
			mostrarBlockeador(true);
			ficha.style.display = "block";	
			blockeadorFicha.style.display = "none";
		}
		if(e) StopEvent(e);		
	}
	var limpiarCampos = function(){
		nombre.value = "";
		direccion.value = "";
		telefono.value = "";
		email.value = "";
		consulta.value = "";
		
		nombre.className = "";
		direccion.className = "";
		telefono.className = "";
		email.className = "";
		consulta.className = "";
		
		errorConsulta.innerHTML = "";
		errorConsulta.style.display = "none";
		
	}
	
	var blockearCampos = function(blockeo){
		nombre.disabled = blockeo;
		email.disabled = blockeo;
		direccion.disabled = blockeo;
		telefono.disabled = blockeo;
		consulta.disabled = blockeo;
		
		
		
		
	}	
	this.onRequestLoad = function(){
		if(!this.req.respuestaXML){
			alert(this.req.respuestaHTML);
			return false;
		}
		switch(this.req.respuestaXML.getAttribute("tipo")){
			case "html":
				ficha.innerHTML = this.req.respuestaXML.firstChild.data;
				contenedorFichas[this.idRegistro] = new Object();
				contenedorFichas[this.idRegistro].html = this.req.respuestaXML.firstChild.data;
				
				ficha.style.display = "block";
				blockeadorFicha.style.display = "none";
				this.centrarContenido(cuadro);
			break;
			case "exito":
				this.centrarContenido(exito);
				exito.style.visibility = "visible";
				enviando.style.visibility = "hidden";
				enviando.style.top = "-1000px";	
			break;
			default:
				this.centrarContenido(fallo);
				fallo.style.visibility = "visible";
				enviando.style.visibility = "hidden";
				enviando.style.top = "-1000px";	
			break;
		}
	}
	this.enviarConsulta = function(e){
		var errores = "";
		errores += nombre.onblur();
		errores += email.onblur();
		errores += consulta.onblur();
		if(errores == ""){
			errorConsulta.innerHTML = "";
			errorConsulta.style.display = "none";

			this.centrarContenido(enviando);
			enviando.style.visibility = "visible";
			blockearCampos(true);
			mostrarBlockeador(true);
			var v = "nombre|=|"+nombre.value+"|&|email|=|"+email.value+"|&|direccion|=|"+direccion.value+"|&|telefono|=|"+telefono.value+"|&|consulta|=|"+consulta.value+"|&|"+"|&|idRegistro|=|"+this.idRegistro+"|&|";
			this.req.pedir("requests/consultaRapida.php",v);
		}
		else{
			errorConsulta.innerHTML = errores;
			errorConsulta.style.display = "block";
		}
		if(e) StopEvent(e);			
	}
	exito.onclick = function(){
		limpiarCampos();
		blockearCampos(false);
		exito.style.visibility = "hidden";
		exito.style.top = "-1000px";
	}
	fallo.onclick = function(){
		blockearCampos(false);
		fallo.style.visibility = "hidden";
		fallo.style.top = "-1000px";
	}		
	cerrar.onclick = function(){
		ocultarCuadro();
	}
	crearErrores();		
}

var Comprar = function(nombreCuadro,nombreFicha){
	
	var nombre = document.getElementById("nombreCompra");
	var direccion = document.getElementById("direccionCompra");
	var telefono = document.getElementById("telefonoCompra");
	var email = document.getElementById("emailCompra");
	var cantidad = document.getElementById("cantidadCompra");
	var nombreDetalle = document.getElementById("nombreDetalle");
	var direccionDetalle = document.getElementById("direccionDetalle");
	var telefonoDetalle = document.getElementById("telefonoDetalle");
	var emailDetalle = document.getElementById("emailDetalle");
	var productoDetalle = document.getElementById("productoDetalle");
	var cantidadDetalle = document.getElementById("cantidadDetalle");
	var totalEuro = document.getElementById("totalEuro");
	var totalPeseta = document.getElementById("totalPeseta");
	var listaCompra = document.getElementById("listaCompra");
	var datosCompra = document.getElementById("datosCompra");
	var volver = document.getElementById("volverCompra");
	var comentario = document.getElementById("comentarioCompra");
	var blockeador = document.getElementById("blockeadorCompra");
	var cuadro = document.getElementById(nombreCuadro);
	var ficha = document.getElementById(nombreFicha);
	var blockeadorFicha = document.getElementById("blockeadorFichaCompra");
	var archivo = "requests/cargarHTMLProducto.php";
	var totalErrores = 0;
	var oClase = this;
	var enviar = document.getElementById("enviarCompra");
	var continuar = document.getElementById("continuarCompra");
	var enviando = document.getElementById("enviandoCompra");
	var exito = document.getElementById("exitoCompra");
	var fallo = document.getElementById("falloCompra");
	var cerrar = document.getElementById("cerrarCompra");
	var errorCompra = $('errorCompra');
	var enviandoDatos = 0;

	var usuario = $('usuarioCompra');
	var contrasenia = $('contraseniaCompra');
	var errorLogueo = $('errorLogueoCompra');


	var nombreRegistro = $('nombreRegistroCompra');
	var apellidoRegistro = $('apellidoRegistroCompra');
	var usuarioRegistro = $('usuarioRegistroCompra');
	var contraseniaRegistro = $('contraseniaRegistroCompra');
	var direccionRegistro = $('direccionRegistroCompra');
	var telefonoRegistro = $('telefonoRegistroCompra');
	var emailRegistro = $('emailRegistroCompra');
	var movilRegistro = $('movilRegistroCompra');
	var poblacionRegistro = $('poblacionRegistroCompra');
	var cpRegistro = $('cpRegistroCompra');
	var masculino = $('masculinoRegistroCompra');
	var femenino = $('femeninoRegistroCompra');
	var suscribeSi = $('suscribeSiRegistroCompra');
	var suscribeNo = $('suscribeNoRegistroCompra');
	var errorRegistro = $('errorRegistro');
	var errorCompra = $('errorCompra');
	var contenedorIzquierda = $('contenedorIzquierda');
	var confirmacionRegistro = $('confirmacionRegistroCompra');
	var titTienda = $('titTienda');

	AddEvent(emailRegistro, "blur", function(){
		usuarioRegistro.innerText = emailRegistro.value;
 	});	

	var precioEuro = "";
	var precioPeseta = "";
	
	
	var dirImagenes = "img/";
	this.req = new Request(oClase);

		
	if(Nav.esIE || Nav.esIE7) blockeador.style.filter = 'alpha(opacity=45)';
	else blockeador.style.MozOpacity = ".45";
	this.centrarContenido = function(objeto){
		var pos = getScrollPos();
		var scrn = getBodyWHAvaible();
		var dim = getBodyWHAvaible();
		objeto.style.top = (Math.round((dim.h - objeto.offsetHeight)/2)+pos.y)+"px";
		objeto.style.left = (Math.round((scrn.w - objeto.offsetWidth)/2)+pos.x)+"px";
	}
	var crearError = function(campo,mensaje,expresion){
		var contenido = document.createElement("div");
		contenido.className = "contenidoError";
		if(!(Nav.esIE || Nav.esIE7))contenido.style.width = "180px";
		var flecha = document.createElement("img");
		flecha.src = dirImagenes+"redArrow.gif";
		var mens = document.createElement("mensaje");
		mens.innerHTML = mensaje;
		mens.className = "mensajeError";
		contenido.appendChild(flecha);
		contenido.appendChild(mens);
		campo.parentNode.appendChild(contenido);
		campo.contenido = contenido;
		campo.expresion = expresion;

		campo.onblur = function(){
			if(!campo.expresion.test(campo.value.toLowerCase()))mostrarError(campo);
			else ocultarError(campo);
		}
	}
	var crearError2 = function(campo,mensaje,expresion){
		campo.expresion = expresion;
		campo.onblur = function(){
			if(!campo.expresion.test(campo.value.toLowerCase())){
				campo.className = "inputError";
				return mensaje;
			}
			else{ 
				campo.className = "inputConsulta";
				return "";
			}
		}
	}	
	var crearErrores = function(){
		crearError2(direccion,'Direcci&oacute;n Incorrecta<br />',ER_STR);
		crearError2(telefono,'Telefono Incorrecto<br />',ER_STR);
	
		crearError2(cantidad,'Cantidad Incorrecta<br />',ER_NATURAL_NOCERO);
		crearError2(email,'Email incorrecto<br />',ER_EMAIL);
				
		crearError2(nombreRegistro,'Ingrese el nombre<br />',ER_STR);
		crearError2(apellidoRegistro,'Ingrese el apellido<br />',ER_STR);
		crearError2(direccionRegistro,'Ingrese la direccion<br />',ER_STR);
		crearError2(telefonoRegistro,'Ingrese el telefono<br />',ER_STR);		
		crearError2(contraseniaRegistro,'Ingrese la contrase&ntilde;a<br />',ER_STR);		
		crearError2(poblacionRegistro,'Ingrese la población<br />',ER_STR);
		crearError2(emailRegistro,'Email incorrecto<br />',ER_EMAIL);
		
	}
	var mostrarError = function(campo){
		totalErrores++;
		campo.contenido.style.display = "inline";
		campo.className = "inputError";
	}
	var ocultarError = function(campo){
		campo.contenido.style.display = "none";
		campo.className = 'inputConsulta';
	}
	mostrarBlockeador = function(valor){
		if(valor){
			var scrn = getBodyDims();
			var pant = getBodyWHAvaible();
			var dim = getWindowDims();
			var pos = getScrollPos();
			blockeador.style.display = "block";
			if(Nav.esIE)blockeador.style.height = (scrn.h)+"px";
			else blockeador.style.height = (scrn.h)+"px";

			blockeador.style.width = scrn.w+"px";
		}
		else blockeador.style.display = "none";
	}
	var ocultarCuadro = function(){
		mostrarBlockeador();	
		contenedor.style.visibility = "hidden";
		contenedor.style.top = "-1000px";
	}
	this.mostrarCuadro = function(idRegistro,valPrecioEuro,valPrecioPeseta,e){
		limpiarCampos();
		precioEuro = valPrecioEuro;
		precioPeseta = valPrecioPeseta;
		this.idRegistro = idRegistro;
		if(!contenedorFichas[idRegistro]){

			this.req.pedir(archivo,"idRegistro|=|"+idRegistro+"|&|");
			ficha.style.display = "none";
			blockeadorFicha.style.display = "block";
			mostrarBlockeador(true);
			cuadro.style.visibility = "visible";
			oClase.centrarContenido(cuadro);
		}
		else{
			ficha.innerHTML = contenedorFichas[idRegistro].html;			
			ficha.style.display = "inline";	
			blockeadorFicha.style.display = "none";
			cuadro.style.visibility = "visible";
			oClase.centrarContenido(cuadro);
			mostrarBlockeador(true);			
		}
		if(e) StopEvent(e);		
	}
	var limpiarCampos = function(){
		cantidad.value = "";
		comentario.value = "";
		
		
		direccion.className = "";
		telefono.className = "";
		
		errorCompra.innerHTML = "";
		errorCompra.style.display = "none";
		
		
		nombreRegistro.value = "";
		apellidoRegistro.value = "";
		direccionRegistro.value = "";
		telefonoRegistro.value = "";
		movilRegistro.value = "";
		poblacionRegistro.value = "";
		cpRegistro.value = "";
		emailRegistro.value = "";
		usuarioRegistro.innerHTML = "&nbsp;";
		contraseniaRegistro.value = "";
		confirmacionRegistro.value = "";
		masculino.checked = true;
		
		
		cantidad.className = "inputConsulta";
		comentario.className = "inputConsulta";
		
		nombreRegistro.className = "inputConsulta";
		apellidoRegistro.className = "inputConsulta";
		direccionRegistro.className = "inputConsulta";
		telefonoRegistro.className = "inputConsulta";
		movilRegistro.className = "inputConsulta";
		poblacionRegistro.className = "inputConsulta";
		cpRegistro.className = "inputConsulta";
		emailRegistro.className = "inputConsulta";
		usuarioRegistro.className = "inputConsulta";
		contraseniaRegistro.className = "inputConsulta";
		confirmacionRegistro.className = "inputConsulta";
		
		
		
		usuario.value = "";
		contrasenia.value = "";
		errorLogueo.innerText = "";
		errorLogueo.style.display = "none";
		errorRegistro.style.display = "none";
		errorRegistro.innerText = "";
		
		
	}
	
	var ocultarCuadro = function(){
		mostrarBlockeador();	
		limpiarCampos();
		cuadro.style.visibility = "hidden";
		cuadro.style.top = "-1000px";
	}	
	var blockearCampos = function(blockeo){
		cantidad.disabled = blockeo;
		email.disabled = blockeo;
		direccion.disabled = blockeo;
		telefono.disabled = blockeo;
		comentario.disabled = blockeo;
		
		usuario.disabled = blockeo;
		contrasenia.disabled = blockeo;
		
		
		nombreRegistro.disabled = blockeo;
		apellidoRegistro.disabled = blockeo;
		usuarioRegistro.disabled = blockeo;
		contraseniaRegistro.disabled = blockeo;
		direccionRegistro.disabled = blockeo;
		telefonoRegistro.disabled = blockeo;
		emailRegistro.disabled = blockeo;
		movilRegistro.disabled = blockeo;
		poblacionRegistro.disabled = blockeo;
		cpRegistro.disabled = blockeo;
		masculino.disabled = blockeo;
		femenino.disabled = blockeo;
		
		
	}	
	this.onRequestLoad = function(){
		if(!this.req.respuestaXML){
			alert(this.req.respuestaHTML);
			return false;
		}
		switch(this.req.respuestaXML.getAttribute("tipo")){
			case "html":
				ficha.innerHTML = this.req.respuestaXML.firstChild.data;
				contenedorFichas[this.idRegistro] = new Object();
				contenedorFichas[this.idRegistro].html = this.req.respuestaXML.firstChild.data;
				
				ficha.style.display = "inline";
				blockeadorFicha.style.display = "none";
				this.centrarContenido(cuadro);
			break;
			case "exito":
				exito.style.visibility = "visible";
				this.centrarContenido(exito);
				enviando.style.visibility = "hidden";
				enviando.style.top = "-1000px";	
				enviandoDatos = 0;
				limpiarCampos();
				this.volverAtras();
			break;
			case "exitoRegistro":
				errorRegistro.innerHTML = "";
				enviando.style.visibility = "hidden";
				enviando.style.top = "-1000px";	
				enviandoDatos = 0;
				limpiarCampos();
				blockearCampos(false);
				$('nombreyapellido').innerHTML = "Bienvenido !! "+this.req.respuestaXML.firstChild.data;
				$('nombreDetalle').innerHTML = this.req.respuestaXML.firstChild.data;
				telefono.value = this.req.respuestaXML.childNodes[1].data;
				email.value = this.req.respuestaXML.childNodes[2].data;
				direccion.value = this.req.respuestaXML.childNodes[3].data;
				
				$('logueoCompra').style.display = "none";
				$('registroCompra').style.display = "none";
				$('datosCompra').style.display = "inline";	
				contenedorIzquierda.style.display = "inline";
				titTienda.innerText = "HACER PEDIDO";
			break;
			case "falloRegistro":
				errorRegistro.innerHTML = this.req.respuestaXML.firstChild.data;
				errorRegistro.style.display = "block";
				blockearCampos(false);
				enviando.style.visibility = "hidden";
				enviando.style.top = "-1000px";	
				enviandoDatos = 0;
				
			break;
			case "logout":
			
			break;
			

			case "exitoLogueo":
				$('nombreyapellido').innerHTML = "Bienvenido !! "+this.req.respuestaXML.firstChild.data;
				$('nombreDetalle').innerHTML = this.req.respuestaXML.firstChild.data;
				$('logueoCompra').style.display = "none";
				telefono.value = this.req.respuestaXML.childNodes[1].data;
				email.value = this.req.respuestaXML.childNodes[2].data;
				direccion.value = this.req.respuestaXML.childNodes[3].data;
				$('datosCompra').style.display = "inline";
				
			break;
			case "falloLogueo":
				errorLogueo.innerHTML = this.req.respuestaXML.firstChild.data;
				errorLogueo.style.display = "block";
				usuario.disabled = false;
				contrasenia.disabled = false;
			break;
			default:
				this.centrarContenido(fallo);
				fallo.style.visibility = "visible";
				enviando.style.visibility = "hidden";
				enviando.style.top = "-1000px";	
				enviandoDatos = 0;
			break;
		}
		
	}
	this.enviarCompra = function(e){

			if(enviandoDatos == 0){
				enviando.style.visibility = "visible";
				this.centrarContenido(enviando);
				blockearCampos(true);
				mostrarBlockeador(true);
				var v = "email|=|"+email.value+"|&|direccion|=|"+direccion.value+"|&|telefono|=|"+telefono.value+"|&|comentario|=|"+comentario.value+"|&|"+"|&|idRegistro|=|"+this.idRegistro+"|&|";
				v += "cantidad|=|"+cantidad.value+"|&|precioEuro|=|"+precioEuro+"|&|precioPeseta|=|"+precioPeseta+"|&|";
				enviandoDatos = 1;
				this.req.pedir("requests/compra.php",v);
			}
			if(e) StopEvent(e);			
	}
	this.continuar = function(e){
		if(enviandoDatos == 0){
			var errores = "";
			errores = direccion.onblur();
			errores += telefono.onblur();
			errores += cantidad.onblur();
			errores += email.onblur();
			if(errores == ""){
				errorCompra.innerHTML = "";
				errorCompra.style.display = "block";
				direccionDetalle.innerHTML = direccion.value;
				telefonoDetalle.innerHTML = telefono.value;
				emailDetalle.innerHTML = email.value;
				cantidadDetalle.innerHTML = cantidad.value;
				totalEuro.innerHTML = (parseInt(cantidad.value)*precioEuro);
				totalEuro.innerHTML = "&euro; "+totalEuro.innerHTML.replace(".",",")
				if(totalEuro.innerHTML.indexOf(",")<0)totalEuro.innerHTML += ",00";
				totalPeseta.innerHTML = (parseInt(cantidad.value)*precioPeseta);
				totalPeseta.innerHTML = "&#8359; "+totalPeseta.innerHTML.replace(".",",");
				if(totalPeseta.innerHTML.indexOf(",")<0)totalPeseta.innerHTML += ",00";			
				datosCompra.style.display = "none";	
				listaCompra.style.display = "block";

			}
			else{
				errorCompra.innerHTML = errores;
				errorCompra.style.display = "block";
			}
		}
		if(e) StopEvent(e);
	}
	this.volverAtras = function(e){
		listaCompra.style.display = "none";
		datosCompra.style.display = "block";	
		if(e) StopEvent(e);		
	}
	exito.onclick = function(){
		limpiarCampos();
		blockearCampos(false);
		exito.style.visibility = "hidden";
		exito.style.top = "-1000px";
	}
	fallo.onclick = function(){
		blockearCampos(false);
		fallo.style.visibility = "hidden";
		fallo.style.top = "-1000px";
	}	
	cerrar.onclick = function(){
		ocultarCuadro();	
	}
	crearErrores();		
	
	this.enviarLogueo = function(e){
		if(!usuario)usuario = $('usuarioCompra');	
		if(!contrasenia)contrasenia = $('contraseniaCompra');
		if(!errorLogueo)errorLogueo = $('errorLogueoCompra');
		var error = "";
		if(usuario.value == ""){
			error = "Debe ingresar el usuario.<br/>";
			usuario.style.border = "1px solid #FF0000";
		}
		else usuario.style.borderColor = "";
		if(contrasenia.value == ""){
			error += "Debe ingresar la contrasenia.";
			contrasenia.style.border = "1px solid #FF0000";
		}
		else contrasenia.style.borderColor = "";
		if(error == ""){
			this.req.pedir("requests/loguearCompra.php",'usuario' + SEP_IGUAL + usuario.value + SEP_AND + 'contrasenia' + SEP_IGUAL + contrasenia.value +SEP_AND);	
			usuario.disabled = true;
			contrasenia.disabled = true;
			errorLogueo.innerHTML = "";
		}
		else{
			errorLogueo.innerHTML = error;
			errorLogueo.style.display = "block";
		}
		if(e) StopEvent(e);		
		
	}
	this.registrarse = function(e){
		$('logueoCompra').style.display = "none";
		$('registroCompra').style.display = "inline";
		contenedorIzquierda.style.display = "none";
		titTienda.innerText = "COMPLETE EL FORMULARIO Y REGISTRESE";
		this.centrarContenido(cuadro);
		if(e) StopEvent(e);		
	}
	this.volverALogueo = function(e){
		$('registroCompra').style.display = "none";
		$('logueoCompra').style.display = "block";
		contenedorIzquierda.style.display = "block";
		titTienda.innerText = "HACER PEDIDO";
		if(e) StopEvent(e);
	}
	
	this.logout = function(){
		blockearCampos(false);
		limpiarCampos();
		$('datosCompra').style.display = "none";
		$('listaCompra').style.display = "none";		
		$('logueoCompra').style.display = "block";
		this.req.pedir("requests/loguearCompra.php","logout|=|1|&|");
	}
	this.enviarRegistro = function(e){
			
			if(enviandoDatos == 0){
				var errores = "";
				
				errores = nombreRegistro.onblur();
				errores += apellidoRegistro.onblur();
				errores += direccionRegistro.onblur();
				errores += telefonoRegistro.onblur();				
				errores += poblacionRegistro.onblur();
				errores += emailRegistro.onblur();
				errores += contraseniaRegistro.onblur();
				if(contraseniaRegistro.value != confirmacionRegistro.value){
					errores += "La contrase&ntilde;a y su confirmaci&oacute;n son distintas.<br />";
					confirmacionRegistro.className = "inputError";
				}
				else confirmacionRegistro.className = "inputConsulta";
				if(errores == 0){
					errorRegistro.innerHTML = "";
					errorRegistro.style.display = "none";
					this.centrarContenido(enviando);
					enviando.style.visibility = "visible";
					blockearCampos(true);
					mostrarBlockeador(true);
					var sexo = 'm';
					var susc = 1;
					if(femenino.checked)sexo = 'f';
					if(suscribeNo.checked)susc = 0;
					var v = "nombre|=|"+nombreRegistro.value+"|&|apellido|=|"+apellidoRegistro.value+"|&|"+"|&|email|=|"+emailRegistro.value+"|&|direccion|=|"+direccionRegistro.value+"|&|telefono|=|"+telefonoRegistro.value+"|&|usuario|=|"+emailRegistro.value+"|&|"+"contrasenia|=|"+contraseniaRegistro.value+"|&|";
						v += "movil|=|"+movilRegistro.value+"|&|poblacion|=|"+poblacionRegistro.value+"|&|"+"|&|cp|=|"+cpRegistro.value+"|&|sexo|=|"+sexo+"|&|suscribe|=|"+susc+"|&|";
					enviandoDatos = 1;
					this.req.pedir("requests/registroCompra.php",v);
				}
				else{
					errorRegistro.innerHTML = errores;
					errorRegistro.style.display = "block";
				}
			}
			if(e) StopEvent(e);			
	}	
	
}

var oTienda = new function(){
	var oEle = null;
	
	//OBJs
	var req = new Request();
	req.listener = function(){
		var d = req.respuestaXML;
		$('tiendaFichaLoader').style.display = 'none';
		
		if(!d) alert(req.respuestaHTML);
		//
		else $('FichaCont').innerHTML = (Nav.esIE)? d.firstChild.text : d.firstChild.textContent;
		//
	}.closure(this);
	
	//METs
	var setEle = function(i){
		if(!!oEle) oEle.className = '';
		oEle = $('categoriaProducto' + i);
		if(oEle)oEle.className = 'noticiasCategoriaOn';
	}
	
	this.verFicha = function(i, e,pagina){
		setEle(i);
		//
		if(e == 'init') return true;
		//
		$('tiendaFichaLoader').style.display = 'block';
		var anex = "";
		if(pagina)anex = "&pagina="+pagina;
		req.pedir('requests/cargar.php?idC='+i+anex, 'file|=|productosListado.php|&|');
		//
		if(e) StopEvent(e);
	}
	
		
}



						
						