// JavaScript Document

function atras(){
	history.go(-1)
}
function ver(pag,w,h){
	Navig=navigator.appName
	if(Navig=='Netscape'){
		var y=document.body.scrollHeight;
		var x=document.body.scrollWidth;
	}else{
		var y= document.body.clientHeight; 
		var x=document.body.clientWidth;
	}
	var l=(x/2)-(w/2)
	var t=(y/2)-(h/2)-100
	window.open(pag,'','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width='+w+',height='+h+',left='+l+',top='+t);
}
function validar(p,i) { 
	v=document.getElementById(p).value
	if(v.length>0){
		if (document.frmBuscador.radweb[1].checked){
			document.frmBuscador.target='_blank'
			document.frmBuscador.action='http://www.emekin.net/web/buscador.asp?busq='+v+'&idioma='+i+'&m=0'
			document.frmBuscador.submit();
		}else{
			document.frmBuscador.submit();
		}
	}
}
function mueveReloj(){
    momentoActual = new Date()
    hora = momentoActual.getHours()
    minuto = momentoActual.getMinutes()
    segundo = momentoActual.getSeconds()
    str_segundo = new String (segundo)
    if (str_segundo.length == 1){
		segundo = "0" + segundo
	}
    str_minuto = new String (minuto)
    if (str_minuto.length == 1){
		minuto = "0" + minuto
	}
    str_hora = new String (hora)
    if (str_hora.length == 1){
		hora = "0" + hora
	}
    horaImprimible = hora + ":" + minuto + ":" + segundo
    document.form_reloj.reloj.value = horaImprimible
    setTimeout("mueveReloj()",1000)
}

function tamanoLinks() {
	var a, b;
	a = document.getElementById("tamMenos");
	b = document.getElementById("tamMas");
	if (a) {
		a.onclick = function() {
			var titulo = getActiveStyleSheet();
			if (titulo) {
				var tamanio = titulo.charAt(4);
				var tamanio_menos = parseInt(tamanio) - 1;			
				if (tamanio_menos == 0) tamanio_menos = 1;
			}
			else {
				var tamanio_menos = 2;
			}
			setActiveStyleSheet("tam_" + tamanio_menos);
			return false;
		}
	}
	if (b) {
		b.onclick = function() {
			var titulo = getActiveStyleSheet();
			if (titulo) {
				var tamanio = titulo.charAt(4);
				var tamanio_mas = parseInt(tamanio) + 1;
				if (tamanio_mas == 6) tamanio_mas = 5;
			}
			else {
				var tamanio_mas = 2;
			}
			setActiveStyleSheet("tam_" + tamanio_mas);
			return false;
		}
	}
}
function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
			if (a.getAttribute("title").indexOf("tam_") != -1) {
				return a.getAttribute("title");
			}
		}
	}
	return null;
}
function setActiveStyleSheet(titulo) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			if (a.getAttribute("title").indexOf("tam_") != -1) {
				a.disabled = true;
				if(a.getAttribute("title") == titulo) a.disabled = false;
			}
		}
	}
	createCookie("dipuemprendestyle", titulo, 365);
	setActiveStyleSheetVisual(titulo);
}

function setActiveStyleSheetVisual(titulo) {
	if (titulo == "tam_1") {
		if (document.getElementById("letra_menos")) {
			document.getElementById("letra_menos").src = document.getElementById("letra_menos").src.replace(/1/gi, "2");
		}
	}
	else {
		if (document.getElementById("letra_menos")) {
			document.getElementById("letra_menos").src = document.getElementById("letra_menos").src.replace(/2/gi, "1");
		}
	}
	if (titulo == "tam_5") {
		if (document.getElementById("letra_mas")) {
			document.getElementById("letra_mas").src = document.getElementById("letra_mas").src.replace(/1/gi, "2");
		}
	}
	else {
		if (document.getElementById("letra_mas")) {
			document.getElementById("letra_mas").src = document.getElementById("letra_mas").src.replace(/2/gi, "1");
		}
	}
}
function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) {
			if (a.getAttribute("title").indexOf("tam_") != -1) {
				return a.getAttribute("title");
			}
		}
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function iniciar_tamano(){
	var cookie = readCookie("dipuemprendestyle");
	var titulo = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(titulo);
}

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;
};

attachEventListener(window, "load", iniciar_tamano, false);
attachEventListener(window, "load", tamanoLinks, false);
attachEventListener(window, "load", mueveReloj, false);
