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 items(id){
	document.getElementById('enlace_1').style.color = "#6E6B5C";
	document.getElementById('enlace_2').style.color = "#6E6B5C";
	document.getElementById('enlace_3').style.color = "#6E6B5C";
	document.getElementById('enlace_4').style.color = "#6E6B5C";
	document.getElementById('enlace_5').style.color = "#6E6B5C";
	document.getElementById('enlace_6').style.color = "#6E6B5C";
	document.getElementById('enlace_7').style.color = "#6E6B5C";
	document.getElementById('enlace_' + id).style.color = "#41A8FF";
	document.getElementById('enlace_' + id).blur();
	document.getElementById('enlace_1').style.textDecoration = "underline";
	document.getElementById('enlace_2').style.textDecoration = "underline";
	document.getElementById('enlace_3').style.textDecoration = "underline";
	document.getElementById('enlace_4').style.textDecoration = "underline";
	document.getElementById('enlace_5').style.textDecoration = "underline";
	document.getElementById('enlace_6').style.textDecoration = "underline";
	document.getElementById('enlace_7').style.textDecoration = "underline";
	document.getElementById('enlace_' + id).style.textDecoration = "none";

	var obj = document.getElementById('item_' + id);
	listado = document.getElementById('direcciones');
	
	if (listado) {
		contenedores = listado.getElementsByTagName('div');
		numContenedores = contenedores.length;
		listado.style.display='none';
		for (m = 0; m < numContenedores; m++) {
			if (contenedores[m].id.indexOf('item_') == 0) contenedores[m].style.display = 'none';
		}
		
	}
	if (obj) {
		if (obj.style.display == 'block') {
			obj.style.display = 'none';
		} else {
			obj.style.display = 'block';
		}
	}
}

function ocultaItems(){
	listado = document.getElementById('direcciones');
	
	if (listado) {
		contenedores = listado.getElementsByTagName('div');
		numContenedores = contenedores.length;
		for (m=1; m < numContenedores; m++) {
			if(contenedores[m].id.indexOf('item_') == 1) contenedores[m].style.display = 'none';
		}
	}
}
	   
function ver (id) {
	d = document.getElementById("extra");
	e = document.getElementById(id);

	if (e.style.display == 'none' || e.style.display == "") {
		e.style.display = 'block';
		d.innerHTML = 'Ocultar información';
	} else {
		e.style.display = 'none';
		d.innerHTML = 'Más información';
	}
}

attachEventListener(window, "load", ocultaItems, false);
attachEventListener(window, "load", target_blank, false);
// attachEventListener(window, "load", reset_form, false);

