function attachEventListener(target, eventType, functionRef, capture) {
    if (typeof target.addEventListener != "undefined") {
        target.addEventListener(eventType, functionRef, capture);
    } else if (typeof target.attachEvent != "undefined") {
        target.attachEvent("on" + eventType, functionRef);
    } else {
        return false;
    }
    return true;
}

function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if (node == null) node = document;
	if (tag == null) tag = "*";
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className)) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function target_blank() {
	if (!document.getElementsByTagName) return;
	var i;
	var enlaces = document.getElementsByTagName("a");
	var cuantos = enlaces.length;
	for (i = 0; i < cuantos; i++) {
		if (enlaces[i].getAttribute("href") && enlaces[i].getAttribute("rel") == "external") enlaces[i].target = "_blank";
	}
}

function reset_form() {
	if (!document.getElementsByTagName) return;
	var i, cuantos;
	var los_inputs = document.getElementsByTagName("input");
	var los_textareas = document.getElementsByTagName("textarea");
	cuantos = los_inputs.length;
	for (i = 0; i < cuantos; i++) {
		if (los_inputs[i].getAttribute("type").toLowerCase() == "text" || los_inputs[i].getAttribute("type").toLowerCase() == "password") {
			los_inputs[i].onfocus = function() {
				if ((this.value.charCodeAt(0) == 32 || this.value.charCodeAt(0) == 160) && this.value.length == 1) this.value = "";
			};
		}
	}
	cuantos = los_textareas.length;
	for (i = 0; i < cuantos; i++) {
		los_textareas[i].onfocus = function() {
			if (this.value.charCodeAt(0) == 32 || this.value.charCodeAt(0) == 160 && this.value.length == 1) this.value = "";
		};
	}
}

function mmn() {
	if (!document.getElementById) return;
	if (!document.getElementsByTagName) return;
	var elementos, cuantos, i;
	
	// Array con cada uno de los menús multinivel.
	var elementos = getElementsByClass("mmn",document,"ul");
	// Si hay menús multinivel, procesamos cada uno.
	if (elementos) {
		cuantos = elementos.length;
		for (i = 0; i < cuantos; i++) {
			mmn_procesar_menu(elementos[i]);
		}
	}
}

function mmn_procesar_menu(menu) {
	if (!document.getElementById) return;
	if (!document.getElementsByTagName) return;
	var lis, submenu, enlaces, cuantos, i;

	// Inicializar el menú (abrir los submenús que procedan).
	lis = menu.getElementsByTagName("li");
	cuantos = lis.length;
	for (i = 0; i < cuantos; i++) {
		if (lis[i].className.indexOf("seleccionado") >= 0) {
			submenus = lis[i].getElementsByTagName("ul");
			if (submenus.length > 0) {
				submenus[0].style.display = "block";
			}
		}
	}

	// Aplicar comportamiento a todos los enlaces (abrir/cerrar submenú).
	enlaces = menu.getElementsByTagName("a");
	cuantos = enlaces.length;
	for (i = 0; i < cuantos; i++) {
		enlaces[i].onclick = function() {
			return mmn_procesar_enlace(this);
		}
	}
}

function mmn_procesar_enlace(enlace) {
	if (!document.getElementById) return;
	if (!document.getElementsByTagName) return;
	var padre_enlace, submenus, cuantos, i, sublis;
	
	padre_enlace = enlace.parentNode;
	submenus = padre_enlace.getElementsByTagName("ul");
	cuantos = submenus.length;
	if (padre_enlace.className.indexOf("seleccionado") >= 0) {
		if (cuantos == 0) {
			// Por no tener submenú y estar seleccionado no se hace nada.
		} else {
			if (padre_enlace.className == "") {
				padre_enlace.className = "";
			} else {
				padre_enlace.className = padre_enlace.className.replace("seleccionado","");
			}
			
		}
		for (i = 0; i < cuantos; i++) {
			submenus[i].style.display = "none";
		}
		sublis = padre_enlace.getElementsByTagName("li");
		cuantos = sublis.length;
		for (i = 0; i < cuantos; i++) {
			sublis[i].className = "";
		}
	} else {
		if (cuantos == 0) {
			// Por no tener submenú y estar seleccionado no se hace nada.
			return true;
		} else {
			if (padre_enlace.className == "") {
				padre_enlace.className = "seleccionado";
			} else {
				padre_enlace.className = "seleccionado " + padre_enlace.className;
			}
			submenus = padre_enlace.getElementsByTagName("ul");
			submenus[0].style.display = "block";
		}
	}
	enlace.blur();
	return false;
}

function MM_CheckFlashVersion(reqVerStr,msg){
with(navigator){
var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
if (!isIE || !isWin){  
var flashVer = -1;
if (plugins && plugins.length > 0){
var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
if (desc == "") flashVer = -1;
else{
var descArr = desc.split(" ");
var tempArrMajor = descArr[2].split(".");
var verMajor = tempArrMajor[0];
var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
flashVer =  parseFloat(verMajor + "." + verMinor);
}
}
// WebTV has Flash Player 4 or lower -- too low for video
else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

var verArr = reqVerStr.split(",");
var reqVer = parseFloat(verArr[0] + "." + verArr[2]);

if (flashVer < reqVer){
if (confirm(msg))
window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
}
}
} 
}

attachEventListener(window, "load", target_blank, false);
attachEventListener(window, "load", reset_form, false);
attachEventListener(window, "load", mmn, false);