var ie = false;
if (document.all) ie = true;

function obj(nam) { return document.getElementById(nam); }

function mostrarOcultar(oNam) {
	var o;
	
	if (ie) o = document.all[oNam];
	else o = document.getElementById(oNam);
	
	o.style.display = (o.style.display?"":"none");
}

function resetForm() {
	obj("formMsg").innerHML = "";
	obj("form_contacto_error1").style.display = "none";	
	obj("form_contacto_error2").style.display = "none";	
	
	obj("contacto_form").reset();
	
	obj("contacto_form").nombre.disabled = false;
	obj("contacto_form").email.disabled = false;	
	obj("contacto_form").telefono.disabled = false;	
	obj("contacto_form").consulta.disabled = false;	
	obj("botonEnviar").disabled = false;	
}

function checkForm() {
	var error = false;
	
	obj("formMsg").innerHML = "";
	obj("formMsg").style.display = ""
	
	form = obj("contacto_form");
	
	obj("form_contacto_error1").style.display = "none";	
	obj("form_contacto_error2").style.display = "none";	
	
	if (!form.nombre.value) { obj("form_contacto_error1").style.display = ""; error = true; }
	if (!form.email.value || form.email.value.indexOf('@') == -1  || form.email.value.indexOf('.') == -1) { obj("form_contacto_error2").style.display = ""; error = true; }

	if (!error) {
		form.submit();
		obj("formMsg").style.display = ""
		obj("formMsg").innerHTML = "Enviando formulario ...";
	}
}

function formOk() {
	obj("formMsg").style.display = ""
	obj("formMsg").innerHTML = "Su formulario ha sido enviado. Gracias por contactar con nosotros.";
	
	obj("contacto_form").nombre.disabled = true;
	obj("contacto_form").email.disabled = true;	
	obj("contacto_form").telefono.disabled = true;	
	obj("contacto_form").consulta.disabled = true;	
	obj("botonEnviar").disabled = true;		
}

function formError() {
	obj("formMsg").style.display = "none";
	alert("Ocurrió un error al enviar el formulario. Por favor, inténtelo más tarde.");
}

function autoHeight(objs, sourc) {

	if (!sourc) sourc = objs;

	var o, maxH = 400;
	var items = sourc.split(",");
	
	for (var nam in items) {
		if (ie) o = document.all[items[nam]];
		else o = document.getElementById(items[nam]);
		
		if (o) maxH = Math.max(maxH, o.offsetHeight)
	}
	
	var items = objs.split(",");
	
	for (var nam in items) {
		if (ie) o = document.all[items[nam]];
		else o = document.getElementById(items[nam]);
		
		if (o) o.style.height = maxH + "px";
	}
	
	return false;
}

function visorLeft() { dirVisor = -1; }
function visorRight() { dirVisor = 1; }
function visorStop() { dirVisor = 0; }

function desplazarListaVisor() {

	var o, c, x;
	
	if (ie) {
		o = document.all['visor_listado_content'];
		c = document.all['visor_listado'];
	} else { 
		o = document.getElementById('visor_listado_content');
		c = document.getElementById('visor_listado');
	}
	
	velVisor += (dirVisor-velVisor) / 3;
	if (Math.abs(velVisor) < 1/10) velVisor = 0; // snap to 0
	
	if (o && c) {
		x = parseInt(o.style.left)?parseInt(o.style.left):0;
		x = x-velVisor*10;
		
		if (ie) {
			x = x-velVisor*10;
			x = Math.max(Math.min(0, x), -(o.width?o.width:o.offsetWidth)+(c.width?c.width:c.offsetWidth)-10);
		} else {
			x = Math.max(Math.min(0, x), -5000);
			x = x-velVisor*10;
		}
		
		if (parseInt(o.style.left) !=  Math.round(x)) o.style.left = Math.round(x)+"px";
	}
}

function enterFrame() {
	autoHeight('cuerpo,columna_l,columna_r', 'cuerpo_content,columna_l_content,columna_r_content');
	if (visorActivo) desplazarListaVisor();
}

var dirVisor = 0, velVisor = 0, visorActivo = false;;
setInterval("enterFrame()", 50);