// JavaScript Document
var globalZIndex = 200;
var ER_EMAIL = /^[a-z0-9_\.\-]+@[a-z0-9_\-]+(\.[a-z0-9_\-]{2,20})*\.[a-z]{2,4}$/;
var ER_NATURAL_NOCERO = /^[1-9]+[0-9]*$/;
var ER_STR = /^([^ \t\n\r]([ \t\n\r]|[^ \t\n\r])*[^ \t\n\r])+$|^[^ \t\n\r]$/;
var ER_DECIMAL = /^\-{0,1}[0-9]+\.{0,1}([0-9]{0,3})$/;
var ER_DECIMAL_FORMATEADO = /^([1-9][0-9]{0,2}){1}((\.[0-9]{3})|[0-9]{3})*(,[0-9]{0,2})?$/;
Navegador = function(){
	this.esIE = false;// Internet Explorer
	this.esIE6 = false;
	this.esIE7 = false;
	this.esMz = false;// Mozilla
	this.esOp = false;// Opera
	this.esNs = false;// Netscape
	
	if(window.navigator.appVersion.search(RegExp("MSIE","im"))!=-1){
		this.esIE = true;
		if(window.navigator.appVersion.search(RegExp("6","im"))!=-1) this.esIE6 = true;
		else if(window.navigator.appVersion.search(RegExp("7","im"))!=-1) this.esIE7 = true;		
	}
	else if(window.navigator.appName.search(RegExp("Opera","im"))!=-1) this.esOp = true;
	else if(window.navigator.appName.search(RegExp("Netscape","im"))!=-1) this.esMz = true;
};
var Nav = new Navegador();
function getScrollPos(){
	if(Nav.esOp) return {y:window.pageYOffset, x:window.pageXOffset};
	else if(Nav.esMz || Nav.esIE) return {y:document.documentElement.scrollTop, x:document.documentElement.scrollLeft};
	else return {x:0, y:0};
}
function getWindowDims(){
	if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight};
	else if(Nav.esMz) return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
	else if(Nav.esIE) return {w:document.body.clientWidth, h:document.body.clientHeight};
	else return {w:0, h:0}
}
function getBodyWHAvaible(){
	if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight};
	else if(Nav.esIE || Nav.esMz) return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
	else return {w:0, h:0}
}
function getBodyDims(){
	if(Nav.esOp) return {w:document.body.clientWidth, h:document.body.clientHeight};
	else if(Nav.esIE || Nav.esMz) return {w:document.body.offsetWidth, h:document.body.offsetHeight};
	else return {w:0, h:0}
}

/***************************************/
//Func:  Add/Remove/Fire Event
AddEvent = function(o, e, f){
	if(Nav.esIE) o.attachEvent('on'+e, f);
	else if(Nav.esMz || Nav.esOp) o.addEventListener(e, f, true);
};
RemEvent = function(o, e, f){
	if(Nav.esIE) o.detachEvent('on'+e, f);
	else if(Nav.esMz || Nav.esOp) o.removeEventListener(e, f, true);
};
FireEvent = function(o, e){
	if(Nav.esIE) o.fireEvent('on'+e);
	else{
		var evt = document.createEvent("Events");
		evt.initEvent(e, true, false);
		o.dispatchEvent(evt);
	}
}
StopEvent = function(e){
	if(Nav.esIE){
		e.returnValue = false;
		e.cancelBubble = true;
	}
	else{
		e.preventDefault();
		e.stopPropagation();
	}
}

var ConsultaRapida = function(dirImagenes){
	var oClase = this;
	var dirImg = dirImagenes
	this.req = new Request(oClase);
	this.idRegistro = 0;
	var contenedor = document.getElementById("contenedorConsulta");
	var nombre = document.getElementById("nombreConsulta");
	var direccion = document.getElementById("direccionConsulta");
	var telefono = document.getElementById("telefonoConsulta");
	var email = document.getElementById("emailConsulta");
	var mensaje = document.getElementById("mensajeConsulta");
	var contPrincipal = document.getElementById("principal");
	var blockeador = document.getElementById("blockeadorConsulta"); 
	var cerrar = document.getElementById("cerrarConsulta");
	var enviar = document.getElementById("enviarConsulta");
	var loading = document.getElementById("loadingConsulta");
	var enviando = document.getElementById("enviandoConsulta");
	var exitoCons = document.getElementById("exitoConsulta");
	var falloCons = document.getElementById("falloConsulta");
	var loading = document.getElementById("loadingConsulta");
	var contImagen = document.getElementById("contImagenConsulta");
	var imagenDefecto = document.getElementById("conImagenDefecto");
	var producto = document.getElementById("productoConsulta");
	var imagen = document.getElementById("imagenConsulta");
	var codigo = document.getElementById("codigoConsulta");
	var descripcion = document.getElementById("descripcionConsulta");
	
	var totalErrores = 0;
	var mensajeContacto = document.getElementById("mensajeContacto");
	var ER_EMAIL = /^[a-z0-9_\.\-]+@[a-z0-9_\-]+(\.[a-z0-9_\-]{2,20})*\.[a-z]{2,4}$/;
	var ER_STR = /^([^ \t\n\r]([ \t\n\r]|[^ \t\n\r])*[^ \t\n\r])+$|^[^ \t\n\r]$/;

	
	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 = getWindowDims();
		objeto.style.top = (Math.round((scrn.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 = "contenidoErrorConsulta";
		if(!(Nav.esIE || Nav.esIE7))contenido.style.width = "280px";
		var flecha = document.createElement("img");
		flecha.src = dirImagenes+"redArrow.gif";
		var mens = document.createElement("mensaje");
		mens.innerHTML = mensaje;
		mens.className = "mensajeErrorConsulta";
		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 crearErrores = function(){
		crearError(nombre,'Debe ingresar su nombre',ER_STR);
		crearError(email,'Email incorrecto',ER_EMAIL);
		crearError(mensaje,'Debe ingresar la consulta',ER_STR);		
	}
	var mostrarError = function(campo){
		totalErrores++;
		campo.contenido.style.display = "inline";
		campo.className = "inputErrorConsulta";
	}
	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 || Nav.esIE7)blockeador.style.height = (dim.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";
	}
	var imagenListo = function(){
		contImagen.style.display = "block";
		loading.style.display = "none";
		oClase.centrarContenido(contenedor);		
	}
	
	this.mostrarCuadro = function(idRegistro,nombre,pathImagen,codigoProd){
		this.idRegistro = idRegistro;
		producto.innerHTML = nombre;
		loading.style.display = "block";
		contImagen.style.display = "none";
		RemEvent(imagen,"load",imagenListo);
		AddEvent(imagen, "load", imagenListo)
		if(pathImagen != ""){
			imagen.src = pathImagen;
			imagen.style.display = "";
			imagenDefecto.style.display = "none";
		}
		else{
			imagen.style.display = "none";
			imagenDefecto.style.display = "block";
			loading.style.display = "none";			
		}
		if(codigoProd != ""){
			codigo.innerHTML = codigoProd;
			codigo.style.display = "block";
		}
		else codigo.style.display = "none";
		var desc = document.getElementById("producto"+idRegistro);
		if(desc)descripcion.innerHTML = "<div>"+desc.value+"</div>";
		else descripcion.innerHTML = "<div>&nbsp;</div>";
		descripcion.style.height = descripcion.firstChild.offsetHeight+"px";
		descripcion.className = "descripcionConsulta";
		if(descripcion.firstChild.offsetHeight > 200){
			descripcion.className = "descripcionConsultaScroll";
		}
		contenedor.style.visibility = "visible";
		contenedor.style.zIndex = "2100";
		mostrarBlockeador(true);	
		limpiarCampos();
		oClase.centrarContenido(contenedor);
	}
	this.enviarConsulta = function(){
		totalErrores = 0;
		nombre.onblur();
		email.onblur();
		mensaje.onblur();
		if(totalErrores == 0){
			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|=|"+mensaje.value+"|&|"+"|&|idRegistro|=|"+this.idRegistro+"|&|";
			this.req.pedir("xmlHttpRequest/consultaRapida.php",v);
		}
	}
	var blockearCampos = function(blockeo){
		nombre.disabled = blockeo;
		email.disabled = blockeo;
		direccion.disabled = blockeo;
		telefono.disabled = blockeo;
		mensaje.disabled = blockeo;
		
	}
	cerrar.onclick = function(){
		ocultarCuadro();	
	}
	enviar.onclick = function(){
		oClase.enviarConsulta();
	}
	exitoCons.onclick = function(){
		limpiarCampos();
		blockearCampos(false);
		exitoCons.style.visibility = "hidden";
		exitoCons.style.top = "-1000px";
	}
	falloCons.onclick = function(){
		blockearCampos(false);
		falloCons.style.visibility = "hidden";
		falloCons.style.top = "-1000px";
	}	
	var limpiarCampos = function(){
		nombre.value = "";
		email.value = "";
		direccion.value = "";
		telefono.value = "";
		mensaje.value = "";
		ocultarError(nombre);
		ocultarError(email);
		ocultarError(mensaje);
	}
	this.onRequestLoad = function(){
		var nodo = this.req.respuestaXML;
		if(!nodo){
			alert(this.req.respuestaHTML);	
			return false;
		}
		if(nodo.getAttribute("exito") == ""){
			this.centrarContenido(falloCons);
			falloCons.style.visibility = "visible";
		}
		else{
			this.centrarContenido(exitoCons);
			exitoCons.style.visibility = "visible";
		}
		enviando.style.visibility = "hidden";
		enviando.style.top = "-1000px";
	}
	crearErrores();
	this.mostrarCuadro(0,'','','','');
	ocultarCuadro();
}

var Consulta = function(dirImagenes,idRegistro){
	var oClase = this;
	var dirImg = dirImagenes
	this.req = new Request(oClase);
	this.idRegistro = idRegistro;
	var contenedor = document.getElementById("contenedorConsulta");
	var nombre = document.getElementById("nombreConsulta");
	var apellido = document.getElementById("apellidoConsulta");
	var direccion = document.getElementById("direccionConsulta");
	var telefono = document.getElementById("telefonoConsulta");
	var email = document.getElementById("emailConsulta");
	var mensaje = document.getElementById("mensajeConsulta");
	var contPrincipal = document.getElementById("principal");
	var blockeador = document.getElementById("blockeadorConsulta"); 
	var cerrar = document.getElementById("cerrarConsulta");
	var enviar = document.getElementById("enviarConsulta");
	var loading = document.getElementById("loadingConsulta");
	var enviando = document.getElementById("enviandoConsulta");
	var exitoCons = document.getElementById("exitoConsulta");
	var falloCons = document.getElementById("falloConsulta");
	var consultarProducto = document.getElementById("consultarProducto");
	var hijosConsulta = document.getElementById("hijosConsulta");
	
	var totalErrores = 0;
	var mensajeContacto = document.getElementById("mensajeContacto");
	var ER_EMAIL = /^[a-z0-9_\.\-]+@[a-z0-9_\-]+(\.[a-z0-9_\-]{2,20})*\.[a-z]{2,4}$/;
	var ER_STR = /^([^ \t\n\r]([ \t\n\r]|[^ \t\n\r])*[^ \t\n\r])+$|^[^ \t\n\r]$/;

	
	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 = getBodyDims();
		var vent = getWindowDims();
		objeto.style.top = (Math.round((scrn.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 = "contenidoErrorConsulta";
		if(!(Nav.esIE || Nav.esIE7))contenido.style.width = "280px";
		var flecha = document.createElement("img");
		flecha.src = dirImagenes+"redArrow.gif";
		var mens = document.createElement("mensaje");
		mens.innerHTML = mensaje;
		mens.className = "mensajeErrorConsulta";
		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 crearErrores = function(){
		crearError(nombre,'Debe ingresar su nombre',ER_STR);
		crearError(apellido,'Debe ingresar su apellido',ER_STR);		
		crearError(email,'Email incorrecto',ER_EMAIL);
		crearError(mensaje,'Debe ingresar la consulta',ER_STR);		
	}
	var mostrarError = function(campo){
		totalErrores++;
		campo.contenido.style.display = "inline";
		campo.className = "inputErrorConsulta";
	}
	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 || Nav.esIE7)blockeador.style.height = (dim.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";
	}
	var imagenListo = function(){
		contImagen.style.display = "block";
		loading.style.display = "none";
		oClase.centrarContenido(contenedor);		
	}
	this.mostrarCuadro = function(){
		mostrarBlockeador(true);	
		limpiarCampos();
		oClase.centrarContenido(contenedor);
		contenedor.style.visibility = "visible";
	}
	this.enviarConsulta = function(){
		totalErrores = 0;
		nombre.onblur();
		apellido.onblur();
		email.onblur();
		mensaje.onblur();
		if(totalErrores == 0){
			this.centrarContenido(enviando);
			enviando.style.visibility = "visible";
			blockearCampos(true);
			mostrarBlockeador(true);
			var idsHij = "";
			if(hijosConsulta){
				for(i in hijCons){
					if(hijCons[i] && hijCons[i].checked)idsHij += i+",";
				}
				idsHij = idsHij.substr(0,idsHij.length-1);
			}
			var v = "nombre|=|"+nombre.value+"|&|apellido|=|"+apellido.value+"|&|email|=|"+email.value+"|&|direccion|=|"+direccion.value+"|&|telefono|=|"+telefono.value+"|&|consulta|=|"+mensaje.value+"|&|"+"|&|idRegistro|=|"+this.idRegistro+"|&|idsHijos|=|"+idsHij+"|&|";
			this.req.pedir("xmlHttpRequest/consulta.php",v);
		}
	}
	var blockearCampos = function(blockeo){
		nombre.disabled = blockeo;
		apellido.disabled = blockeo;
		email.disabled = blockeo;
		direccion.disabled = blockeo;
		telefono.disabled = blockeo;
		mensaje.disabled = blockeo;
		
	}
	AddEvent(cerrar, "click", function(){ocultarCuadro();});
	AddEvent(enviar, "click", function(){oClase.enviarConsulta();});
	AddEvent(consultarProducto, "click", function(){oClase.mostrarCuadro();});	
	AddEvent(exitoCons, "click", function(){
		limpiarCampos();
		blockearCampos(false);
		exitoCons.style.visibility = "hidden";
		exitoCons.style.top = "-1000px";
	});
	AddEvent(falloCons, "click", function(){
		blockearCampos(false);
		falloCons.style.visibility = "hidden";
		falloCons.style.top = "-1000px";
	});										  
	var limpiarCampos = function(){
		nombre.value = "";
		apellido.value = "";
		email.value = "";
		direccion.value = "";
		telefono.value = "";
		mensaje.value = "";
		ocultarError(nombre);
		ocultarError(apellido);		
		ocultarError(email);
		ocultarError(mensaje);
	}
	this.onRequestLoad = function(){
		var nodo = this.req.respuestaXML;
		if(!nodo){
			alert(this.req.respuestaHTML);	
			return false;
		}
		if(nodo.getAttribute("exito") == ""){
			this.centrarContenido(falloCons);
			falloCons.style.visibility = "visible";
		}
		else{
			this.centrarContenido(exitoCons);
			exitoCons.style.visibility = "visible";
		}
		enviando.style.visibility = "hidden";
		enviando.style.top = "-1000px";
	}
	crearErrores();
}
var Recomendar = function(dirImagenes,idRegistro){
	var oClase = this;
	var dirImg = dirImagenes
	this.req = new Request(oClase);
	this.idRegistro = idRegistro;
	var contenedor = document.getElementById("contenedorRecomendar");
	var nombre = document.getElementById("nombreRecomendar");
	var email = document.getElementById("emailRecomendar");
	var amigo = document.getElementById("amigoRecomendar");
	var emailAmigo = document.getElementById("emailAmigoRecomendar");
	var mensaje = document.getElementById("mensajeRecomendar");
	var contPrincipal = document.getElementById("principal");
	var blockeador = document.getElementById("blockeadorRecomendar"); 
	var cerrar = document.getElementById("cerrarRecomendar");
	var enviar = document.getElementById("enviarRecomendar");
	var enviando = document.getElementById("enviandoRecomendar");
	var exitoCons = document.getElementById("exitoRecomendar");
	var falloCons = document.getElementById("falloRecomendar");
	var btnRec = document.getElementById("recomendarProducto");

	var totalErrores = 0;
	var ER_EMAIL = /^[a-z0-9_\.\-]+@[a-z0-9_\-]+(\.[a-z0-9_\-]{2,20})*\.[a-z]{2,4}$/;
	var ER_STR = /^([^ \t\n\r]([ \t\n\r]|[^ \t\n\r])*[^ \t\n\r])+$|^[^ \t\n\r]$/;

	
	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 = getBodyDims();
		objeto.style.top = (Math.round((scrn.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 = "contenidoErrorConsulta";
		if(!(Nav.esIE || Nav.esIE7))contenido.style.width = "100%";
		var flecha = document.createElement("img");
		flecha.src = dirImagenes+"redArrow.gif";
		var mens = document.createElement("mensaje");
		mens.innerHTML = mensaje;
		mens.className = "mensajeErrorConsulta";
		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 crearErrores = function(){
		crearError(nombre,'Debe ingresar su nombre',ER_STR);
		crearError(email,'Email incorrecto',ER_EMAIL);
		crearError(amigo,'Ingrese el nombre del amigo',ER_STR);
		crearError(emailAmigo,'Email del amigo incorrecto',ER_EMAIL);
	}
	var mostrarError = function(campo){
		totalErrores++;
		campo.contenido.style.display = "inline";
		campo.className = "inputErrorConsulta";
	}
	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";
			blockeador.style.height = (scrn.h)+"px";
			blockeador.style.width = scrn.w+"px";
			//loading.style.top = Math.round(((contenedor.offsetTop+((contenedor.offsetHeight-Math.round(loading.offsetHeight/2))/2)))+pos.y)+"px";
			//loading.style.left = Math.round(((contPrincipal.offsetWidth-loading.offsetWidth)/2)+pos.x)+"px";			
			//loading.style.display = "block";
		}
		else{
			blockeador.style.display = "none";
			//loading.style.display = "none";
		}
	}
	var ocultarCuadro = function(){
		mostrarBlockeador();	
		contenedor.style.visibility = "hidden";
		contenedor.style.top = "-1000px";
	}
	var imagenListo = function(){
		contImagen.style.display = "block";
		loading.style.display = "none";
		oClase.centrarContenido(contenedor);		
	}
	this.mostrarCuadro = function(idRegistro){
		this.idRegistro = idRegistro;
		contenedor.style.visibility = "visible";
		contenedor.style.zIndex = "2100";
		mostrarBlockeador(true);	
		limpiarCampos();
		oClase.centrarContenido(contenedor);
	}
	this.enviarRecomendacion = function(){
		
		totalErrores = 0;
		nombre.onblur();
		email.onblur();
		amigo.onblur();
		emailAmigo.onblur();
		if(totalErrores == 0){
			this.centrarContenido(enviando);
			enviando.style.visibility = "visible";
			blockearCampos(true);
			mostrarBlockeador(true);
			var v = "nombre|=|"+nombre.value+"|&|email|=|"+email.value+"|&|amigo|=|"+amigo.value+"|&|emailAmigo|=|"+emailAmigo.value+"|&|mensaje|=|"+mensaje.value+"|&|"+"|&|idRegistro|=|"+this.idRegistro+"|&|";
			this.req.pedir("xmlHttpRequest/recomendar.php",v);
		}
	}
	var blockearCampos = function(blockeo){
		nombre.disabled = blockeo;
		email.disabled = blockeo;
		amigo.disabled = blockeo;
		emailAmigo.disabled = blockeo;
		mensaje.disabled = blockeo;
		
	}
	if(btnRec)AddEvent(btnRec, "click", oClase.mostrarCuadro);
	
	cerrar.onclick = function(){
		ocultarCuadro();	
	}
	enviar.onclick = function(){
		oClase.enviarRecomendacion();
	}
	exitoCons.onclick = function(){
		limpiarCampos();
		blockearCampos(false);
		exitoCons.style.visibility = "hidden";
		exitoCons.style.top = "-1000px";
	}
	falloCons.onclick = function(){
		blockearCampos(false);
		falloCons.style.visibility = "hidden";
		falloCons.style.top = "-1000px";
	}	
	var limpiarCampos = function(){
		nombre.value = "";
		email.value = "";
		amigo.value = "";
		emailAmigo.value = "";
		mensaje.value = "";
		ocultarError(nombre);
		ocultarError(email);
		ocultarError(amigo);
		ocultarError(emailAmigo);
	}
	this.onRequestLoad = function(){
		var nodo = this.req.respuestaXML;
		if(!nodo){
			alert(this.req.respuestaHTML);	
			return false;
		}
		if(nodo.getAttribute("exito") == ""){
			this.centrarContenido(falloCons);
			falloCons.style.visibility = "visible";
		}
		else{
			this.centrarContenido(exitoCons);
			exitoCons.style.visibility = "visible";
		}
		enviando.style.visibility = "hidden";
		enviando.style.top = "-1000px";
	}
	crearErrores();
}

var masInfo = function(tipoCliente){
	var oClase = this;
	this.tipoCliente = tipoCliente;
	var comodin = "";
	var btnImprimir = document.getElementById("btnImprimir");
	this.vistos = new Array();
	var columnas = document.getElementById("columnasTablaFamilia");
	var idsHijos = document.getElementById("idsHijos");
	if(columnas){
		for(i=0;i<parseInt(columnas.value);i++){
			var col = document.getElementById("colgroup"+i);
			if(col)col.width = col.offsetWidth;
		}
	}
	this.mostrarCuadro = function(idRegistro){
		var cuad = document.getElementById("contTodoInfo"+idRegistro);
		if(cuad){
			if(this.tipoCliente == "mayorista" && !this.vistos[idRegistro]){
				this.vistos[idRegistro] = true;
			}
			if(comodin == ""){
				var com = document.getElementById("comodinTabla");	
				if(com)comodin = com.style.display;
			}
			cuad.parentNode.parentNode.style.display = comodin;
			if(cuad.className != "todoMasInfoDesp"){
				cuad.className = "todoMasInfoDesp";
			}
			else{
				cuad.parentNode.parentNode.style.display = "none";
				cuad.className = "todoMasInfo";
			}
			controlAltosDisparado("derecha,izquierda",",");			
				
		}
	}
	var imprimir = function(){
		if(idsHijos){
			var part = idsHijos.value.split(",");
			if(comodin == ""){
				var com = document.getElementById("comodinTabla");	
				if(com)comodin = com.style.display;
			}	

			for(i=0;i<part.length;i++){
				var cuad = document.getElementById("contTodoInfo"+part[i]);
				if(cuad){
					cuad.parentNode.parentNode.style.display = comodin;
					cuad.className = "todoMasInfoDesp";
				}
			}
			controlAltosDisparado("derecha,izquierda",",");	
		}
		window.print();
		
	}
	if(btnImprimir)AddEvent(btnImprimir,"click",function(){imprimir();});
	
}

var mostrarContenido = function(id, event){
	if(event){
		event.cancelBubble = true;
		event.returnValue = false;
	}
	
	var desde = hasta = 0, obj = document.getElementById(id);
	//
	if(parseInt(obj.style.height) == 0 || obj.style.height=='') desde = 0, hasta = obj.scrollHeight;
	else if(parseInt(obj.style.height) == obj.scrollHeight) desde = obj.scrollHeight, hasta = 0;
	
	if(desde != hasta){
		var tm = new Tween(obj.style, 'height', Tween.strongEaseOut, desde, hasta, 2, 'px');
		tm.start();
	}
}

function opacidad(e, n){
	var o = (typeof(e)=='object')? e : document.getElementById(e);
	if(!!o){
		if(Nav.esIE) o.style.filter = 'alpha(opacity='+n+')';
		else if(Nav.esMz) o.style.MozOpacity = (n < 100)? '.'+n : 1;
		else if(Nav.esOp) o.style.opacity = (n < 100)? '.'+n : 1;
	}
	o = null;
}
function popupAbrir(obj){
	//solapas
	
	obj.l.style.display = "block";
	obj.f.style.display = "block";
	//
	obj.l.style.position = 'absolute';
	obj.c.style.position = 'absolute';
	obj.f.style.position = 'absolute';
	obj.l.style.zIndex = globalZIndex;
	obj.c.style.zIndex = globalZIndex-1;
	obj.f.style.zIndex = globalZIndex-2;
	obj.c.style.display  = 'block';
	//
	globalZIndex = globalZIndex+3;
	//
	var pos = getScrollPos();
	var scrn = getBodyWHAvaible();
	var dim = getBodyDims();
	//
	if(scrn.h - obj.c.offsetHeight <= 0) obj.l.style.top = pos.y + "px";
	else obj.l.style.top = (pos.y + ((scrn.h - obj.c.offsetHeight)/2)) + "px";
	obj.l.style.left = ((scrn.w - obj.c.offsetWidth) / 2) + "px";
	//
	obj.f.style.top 		= 0;
	obj.f.style.left 		= 0;
	obj.f.style.width 		= scrn.w + 'px';
	//
	obj.l.style.visibility 	= "visible";
	obj.f.style.visibility 	= "visible";
	//
	if((parseInt(obj.l.style.top) + obj.c.offsetHeight) < dim.h) obj.f.style.height = (dim.h + ((Nav.esIE)? 18:0)) + "px";
	else obj.f.style.height = (obj.c.offsetHeight + parseInt(obj.l.style.top) + 10) + "px";
}
function popupCerrar(obj){
	obj.f.style.visibility 	= "hidden";
	obj.l.style.visibility 	= "hidden";
	obj.f.style.display 	= "none";
	obj.l.style.display 	= "none";
	
}

var logeo = function(nombreFormulario,nombreUsuario,nombrePassword,nombreAccion,nombreErrorLogeo){
	var form = document.getElementById(nombreFormulario);
	var usuario = document.getElementById(nombreUsuario);
	var password = document.getElementById(nombrePassword);
	var accion  = document.getElementById(nombreAccion);
	var bLogeo = document.getElementById("btnLogeo");
	var bDeslogeo = document.getElementById("btnDeslogeo");
	var errorLogeo = document.getElementById(nombreErrorLogeo);
	var mensa = document.getElementById("mensajeDescarga");	
	if(Nav.esIE){
		var opacity = 100;
		var velocidad = 10;
	}
	else{
		var opacity= 1;
		var velocidad = 0.1;
	}

	var enviarLogeo = function(){
		var err = "";
		if(usuario.value == ""){
			usuario.style.border = "1px solid #FF0000";
			err = "Debe ingresar el usuario.<br />";
		}
		else usuario.style.border = "1px solid #9B9542";
		if(password.value == ""){
			password.style.border = "1px solid #FF0000";
			err += "Debe ingresar el password.<br />";
		}
		else password.style.border = "1px solid #9B9542";
		errorLogeo.innerHTML = err;
		if(err == ""){
			accion.value = "logeo";	
			form.submit();
		}
		controlAltosDisparado("derecha,izquierda",",");	
	}
	var deslogear = function(){
		accion.value = "logout";
		form.submit();
	}
	this.analizarTecla = function(event){
		if(event.keyCode == 13)enviarLogeo();								  
  	}
	var ocultarDescarga = function(){
		
		if(opacity < 0){
			mensa.style.display = "none";	
		}
		else{
			opacity = opacity-velocidad;
			if(Nav.esIE)mensa.style.filter = "alpha(opacity="+(opacity)+")";
			else mensa.style.MozOpacity = (opacity);
			setTimeout(function(){ocultarDescarga();},100);
			
		}
		
	}
	
	
	AddEvent(bLogeo, "click", enviarLogeo);
	AddEvent(bDeslogeo, "click", deslogear);	
	setTimeout(function(){ocultarDescarga();},5000);
	
}
var anteriorSiguiente = function(idAnterior,nombreAnterior,imagenAnterior,idSiguiente,nombreSiguiente,imagenSiguiente){
	var flechaAnterior = document.getElementById("flechaAnterior");
	var flechaSiguiente = document.getElementById("flechaSiguiente");
	var flechaAnteriorOff = document.getElementById("flechaAnteriorOff");
	var flechaSiguienteOff = document.getElementById("flechaSiguienteOff");

	var idAnt = idAnterior;
	var nomAnt = "<b>"+nombreAnterior+"</b>";
	var idSigu = idSiguiente;
	var nomSigu = "<b>"+nombreSiguiente+"</b>";
	
	if(imagenAnterior != "")nomAnt += '<br/> '+imagenAnterior;	
	if(imagenSiguiente != "")nomSigu += '<br/> '+imagenSiguiente;	
	
	this.mostrarAnterior = function(event){
		if(event)oToolTip.mostrar(event,nomAnt);
	}
	this.mostrarSiguiente = function(event){
		if(event)oToolTip.mostrar(event,nomSigu);
	}

	if(nombreAnterior == "" && nombreSiguiente == ""){
		flechaAnterior.style.display = "none";
		flechaAnteriorOff.style.display = "none";
		flechaSiguiente.style.display = "none";
		flechaSiguienteOff.style.display = "none";
			
	}
	else{
	
	
		if(flechaAnterior){
			if(nombreAnterior != ""){
				AddEvent(flechaAnterior,"mouseout",function(){oToolTip.ocultar()});
				AddEvent(flechaAnterior,"click",function(){document.location = '?se=productosFicha&idP='+idAnt});
			}
			else{
				flechaAnterior.style.display = "none";
				flechaAnteriorOff.style.display = "inline";
			}
		}
		if(flechaSiguiente){
			if(nombreSiguiente != ""){
				AddEvent(flechaSiguiente,"mouseout",function(){oToolTip.ocultar()});
				AddEvent(flechaSiguiente,"click",function(){document.location = '?se=productosFicha&idP='+idSigu});			
			}
			else{
				flechaSiguiente.style.display = "none";
				flechaSiguienteOff.style.display = "inline";
			}
		}
	}
}



var controlAltos = function(nombres,separador){
	var nom = nombres;
	var sep = separador;
	AddEvent(window,"load",function(){controlAltosDisparado(nom,sep)});
}

var controlAltosDisparado = function(nombres,separador){
	var part = nombres.split(separador);
	var altoMax = 0; 
	var columnas = new Array();
	var indice = 0;

	for(i=0;i<part.length;i++){
		var col = document.getElementById(part[i]);
		if(col){
			col.style.height = "auto";
			if(altoMax < col.offsetHeight)altoMax = col.offsetHeight;
			columnas[indice] = col;
			indice++;
		}
	}
	for(i=0;i<indice;i++){
		columnas[i].style.height = altoMax+"px";	
	}
}



var descargarXls = function(e){
	iFrame = document.getElementById("xlsIframe");	
	if(Nav.esIE6) document.location = "admin/funciones/descargaForzada.php";
	else iFrame.src = "admin/funciones/descargaForzada.php";
	if(e)StopEvent(e);
}
