function validar_buscador()
{
	var form = document.getElementById('buscador');
	if(form.palabra.value != '') form.submit();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}
var ie52mac = (
	navigator.userAgent.indexOf('MSIE 5.2') != -1 &&
	navigator.userAgent.indexOf('Mac') != -1
);
function getStyleById(id, style)
{
	var elm = document.getElementById(id);
	return getStyle(elm, style);
}
function getStyle(elm, style)
{
	if(typeof(document.defaultView) == 'object') return document.defaultView.getComputedStyle(elm, null).getPropertyValue(style);
	else if(elm.currentStyle) return elm.currentStyle[style];
}
function setStyleById(id, style, value)
{
	var elm = document.getElementById(id);
	if(elm) setStyle(elm, style, value);
}
function setStyle(elm, style, value)
{
	elm.style[style] = value;
}
var window_onload = [];
window.onload = function()
{
	for(var i in window_onload) {
		eval(window_onload[i]);
	}
}
function setOpacityById(id, alfa)
{
	var elm = document.getElementById(id);
	return setOpacity(elm, alfa);
};
function setOpacity(elm, alfa)
{
	if(alfa == 0) {
		elm.style.visibility = 'hidden';
	} else if(elm.style.visibility != 'inherit') {
		elm.style.visibility = 'inherit';
	}
	if(typeof(elm.style.opacity) != 'undefined') elm.style.opacity = (alfa == 1) ? '0.999' : alfa;
	else if(typeof(elm.style.MozOpacity) != 'undefined') elm.style.MozOpacity = (alfa == 1) ? '0.999' : alfa;
	else if(typeof(elm.style.KhtmlOpacity) != 'undefined') elm.style.KhtmlOpacity = alfa;
	else if(!ie52mac && typeof(elm.style.filter) != 'undefined') elm.style.filter = (alfa == 1) ? '' : 'alpha(opacity=' + (alfa*100) + ')';
};
function BlendById(id, alfa0, alfa1)
{
	var elm = document.getElementById(id);
	return Blend(elm, alfa0, alfa1);
};
var blend_elm = null;
var blend_alfa1 = 0;
var blend_tmr = null;
var blend_t = 50;
function Blend(elm, alfa0, alfa1)
{
	if(blend_tmr) {
		clearTimeout(blend_tmr);
		blend_tmr = null;
	}
	if(blend_elm) {
		setOpacity(blend_elm, blend_alfa1);
	}
	blend_elm = elm;
	blend_alfa1 = alfa1;
	blend_tmr = setTimeout('cicloBlend(' + alfa0 + ')', blend_t);
};
function cicloBlend(alfa0)
{
	blend_tmr = null;
	if(blend_elm) {
		setOpacity(blend_elm, alfa0);
		var tmp = 0.333 * (blend_alfa1 - alfa0);
		if(Math.abs(tmp) <= 0.01) {
			setOpacity(blend_elm, blend_alfa1);
			blend_elm = null;
		} else {
			alfa0 += tmp;
			blend_tmr = setTimeout('cicloBlend(' + alfa0 + ')', blend_t);
		}
	}
};
function AbrirVentana(url, target, width, height, left, top, resizable, scrollbars)
{
	if(typeof(url) == 'undefined' || url == null) url = '';
	if(typeof(target) == 'undefined' || target == null) target = '';

	if(typeof(width) == 'undefined' || width == null) width = 275;
	if(typeof(height) == 'undefined' || height == null) height = 275;

	if(typeof(window.screen) == 'undefined') {
		var sw = 800;
		var sh = 600;
	} else {
		var sw = window.screen.width;
		var sh = window.screen.height;
	}

	if(typeof(left) == 'undefined' || left == null) left = Math.round(0.5 * (sw - width));
	if(typeof(top) == 'undefined' || top == null) top = Math.round(0.5 * (sh - height));

	if(typeof(resizable) == 'undefined' || resizable == 'no' || !resizable) resizable = 0;
	else resizable = 1;

	if(typeof(scrollbars) == 'undefined' || scrollbars == 'yes' || scrollbars) scrollbars = 1;
	else scrollbars = 0;

	var win = window.open(url, target, 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',directories=0,location=0,menubar=0,resizable=' + resizable +',scrollbars=' + scrollbars + ',status=0,toolbar=0');
	win.focus();
}
var g_activo = [null,null,null];
var b_activo = [null,null,null];
function ver(donde,grupo,que,colapsar)
{
	var elm1 = document.getElementById(donde);
	var elm2 = document.getElementById(que);
	if(elm1 && elm2) {
		if(b_activo[grupo] != null && b_activo[grupo] != elm1) {
			b_activo[grupo].className = 'off';
			b_activo[grupo] = null;
			setStyle(g_activo[grupo], 'zIndex', '1');
			setTimeout("setOpacityById('" + g_activo[grupo].id + "', 0)", 650);

			g_activo[grupo] = null;
		}
		if(b_activo[grupo] == elm1 && colapsar) {
			elm1.className = 'off';
			b_activo[grupo] = null;
			setStyle(elm2, 'zIndex', '1');
			// setTimeout("setOpacityById('" + elm2.id + "', 0)", 650);

			Blend(elm2, 1, 0);

			g_activo[grupo] = null;
		} else if(b_activo[grupo] != elm1) {
			elm1.className = 'on';
			b_activo[grupo] = elm1;
			setOpacity(elm2, 0);
			setStyle(elm2, 'zIndex', '3');
			Blend(elm2, 0, 1);
			g_activo[grupo] = elm2;
		}
	}
}
function ValidarRequerido(campo, titulo, formulario)
{
	if(typeof(formulario) == 'undefined') formulario = 'formulario';
	var form = document.getElementById(formulario);
	if(form[campo].value == '') {

		if(errores == '') form[campo].focus();
		errores += '- ' + titulo + '.\n';
		setStyle(form[campo], 'backgroundColor', '#FDD');
		setStyle(form[campo], 'color', '#000');
	} else {
		setStyle(form[campo], 'backgroundColor', '');
		setStyle(form[campo], 'color', '');
	}
};

function ValidarEmail(campo, titulo, formulario)
{
	if(typeof(formulario) == 'undefined') formulario = 'formulario';
	var form = document.getElementById(formulario);
	if(form[campo].value == '' || !isEmail(form[campo].value)) {
		if(errores == '') form[campo].focus();
		errores += '- ' + titulo + '.\n';
		setStyle(form[campo], 'backgroundColor', '#FDD');
		setStyle(form[campo], 'color', '#000');
	} else {
		setStyle(form[campo], 'backgroundColor', '');
		setStyle(form[campo], 'color', '');
	}
};

// Función para comprobar el formato de una dirección de correo
function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if(window.RegExp) {
		var tempStr = 'a';
		var tempReg = new RegExp(tempStr);
		if(tempReg.test(tempStr)) supported = 1;
	}
	if(!supported) return (str.indexOf('.') > 2) && (str.indexOf('@') > 0);
	var r1 = new RegExp('(@.*@)|(\\.\\.)|(@\\.)|(^\\.)');
	var r2 = new RegExp('^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$');
	return (!r1.test(str) && r2.test(str));
};

function ValidarCamposIguales(campo1,campo2, titulo, formulario)
{
	if(typeof(formulario) == 'undefined') formulario = 'formulario';
	var form = document.getElementById(formulario);

	if(form[campo1].value != form[campo2].value) {
		if(errores == '') form[campo1].focus();
		errores += '- ' + titulo + '.\n';
		setStyle(form[campo1], 'backgroundColor', '#FDD');
		setStyle(form[campo1], 'color', '#000');
		setStyle(form[campo2], 'backgroundColor', '#FDD');
		setStyle(form[campo2], 'color', '#000');
	} else {
		setStyle(form[campo1], 'backgroundColor', '');
		setStyle(form[campo1], 'color', '');
		setStyle(form[campo2], 'backgroundColor', '');
		setStyle(form[campo2], 'color', '');
	}
};

/*
*	Funciones AHAH
*	http://microformats.org/wiki/rest/ahah
*/
function ahah(url, target) {
	document.getElementById(target).innerHTML = 'sending... ' + url;
	if(window.XMLHttpRequest) {
		var req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(req) {
		req.onreadystatechange = function() { ahahDone(req, target); };
		req.open("GET", url, true);
		req.send(null);
	}
}
function ahahDone(req, target) {
	if(req.readyState == 4) {
		if(req.status == 200 || req.status == 304) {
			document.getElementById(target).innerHTML = req.responseText;
		} else {
			document.getElementById(target).innerHTML = "ahah error:\n" + req.statusText;
		}
	}
}