function openExternal(){
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++){
        var thisAnchor = anchors[i];
        if (thisAnchor.getAttribute("href") && thisAnchor.getAttribute("rel") == "external"){
            thisAnchor.target = "_blank";
            thisAnchor.title = "Abre en una nueva p\u00E1gina";
        }
    }
}
document.observe("dom:loaded", openExternal);

/* tabs */
function mostrarTab (arrTabs, strTabActual) {
	var intLenTabs = arrTabs.length;
	for (var i = 0; i < intLenTabs; i++) {
		if (arrTabs[i] == strTabActual) {
			var tabSeleccionado = $(arrTabs[i]);
			tabSeleccionado.show();
			tabSeleccionado.setOpacity(0);
			Effect.Appear($(arrTabs[i]), { duration: 0.5 });
			$(arrTabs[i] + "-btn").addClassName("seleccionado");
		} else {
			$(arrTabs[i]).hide();
			$(arrTabs[i] + "-btn").removeClassName("seleccionado");
		}
	}
}

/* enviar mensaje */

function agregarMensaje() {
	var opt = {
		method: 'post',
		postBody:  Form.serialize('formularioContactenos'),
		onSuccess: function(t) {
			if (t.statusText == 'OK') {
				success = t.responseXML.getElementsByTagName('success')[0].firstChild.data;
				if (success != "1" ) {
					$('formularioContactenos').enable();
					alert("Hubo un error al enviar el mensaje. Por intente de nuevo en un momento.");
					$('mensajeEnviando').hide();
				} else {
					$('formularioContactenos').reset();
					$('mensajeEnviando').update('Hemos recibido tu mensaje. Gracias por tu apoyo.');
					alert("Hemos recibido tu mensaje. Gracias por tu apoyo.");
				}
			} else {
				$('formularioContactenos').enable();
				alert('Hubo un problema al enviar el mensaje por favor intente nuevamente.');
			}
		},
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.');
			$('formularioContactenos').enable();
		},
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
			$('formularioContactenos').enable();
		}
	}
	$('formularioContactenos').disable();
	$('mensajeEnviando').show();
	var envio = new Ajax.Request('/ajax/mensajes.php', opt);
}