function godoc(doc) {
	document.location.href = doc;
}

function displaymenu(elem) {
	if(document.getElementById("ulmenu"+elem).style.display == 'inline') {
		document.getElementById("ulmenu"+elem).style.display = 'none';
	} else {
		document.getElementById("ulmenu"+elem).style.display = 'inline';
	}
}

var categoria = "";
var elemento = 0;

function muestra(elem) {
	if (categoria=="menu" && elemento==0) {
		document.getElementById("ulmenu"+elem).style.display= 'none';
	}
	if (categoria=="submenu") {
		if (elemento==0) {
			document.getElementById("ulmenu"+elem).style.display= 'none';
		} else {
			document.getElementById("ulmenu"+elem).style.display= 'inline';
		}
	}
}

function min(elem) {
	categoria = "menu";
	elemento = 1;
	document.getElementById("ulmenu"+elem).style.display= 'inline';
	document.getElementById("menu1").style.cursor = 'pointer';
}

function mout(elem) {
	elemento = 0;
	setTimeout ("muestra("+elem+");", 1500);
	document.getElementById("menu1").style.cursor = 'auto';
}

function smin() {
	elemento = 1;
	categoria = "submenu";
}

function smout(elem) {
	elemento = 0;
	setTimeout ("muestra("+elem+");", 900); 
}

function showrank(dato) {
	for(var i=1;i<4;i++) {
		if(dato==i) {
			document.getElementById("rank_"+i).style.display = 'inline';
			document.getElementById("rank_p"+i).className = 'rankactivo';
		} else {
			document.getElementById("rank_"+i).style.display = 'none';
			document.getElementById("rank_p"+i).className = 'rankgris';
		}
	}
}

function votarnoticia(id) {
	ajaxurl = "/web/votarnoticia.asp?id="+id;
	if (window.XMLHttpRequest) { // code for Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange=alertavoto;
		xmlhttp.open("GET",ajaxurl,true);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) { // code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
			xmlhttp.onreadystatechange=alertavoto;
			xmlhttp.open("GET",ajaxurl,true);
			xmlhttp.send();
		}
	}
}

function alertavoto() {
	var nuevoTexto = "";
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			if (xmlhttp.responseText!="") {
				respuesta = xmlhttp.responseText;
				if(respuesta==0) {
						alert("¡Gracias por participar!");
				}
				if(respuesta==1) {
					alert("No puedes volver a votar esta noticia en esta sesión.");
				}
			}
		} else {
			alert("Ha ocurrido un error al intentar recuperar los datos.");
		}
	}
}

function URLEncode(strEncode) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = strEncode;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
	return false;
}

function URLDecode(strDecode) {
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = strDecode;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
   return false;
}

function loadUrl(strurl,strdest) {
	ajaxurl = strurl;
	ajaxtarget = strdest;
	if (window.XMLHttpRequest) { // code for Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange=xmlhttpChange;
		xmlhttp.open("GET",ajaxurl,true);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) { // code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
			xmlhttp.onreadystatechange=xmlhttpChange;
			xmlhttp.open("GET",ajaxurl,true);
			xmlhttp.send();
		}
	}
}

function xmlhttpChange() {
	var nuevoTexto = "";
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			if (xmlhttp.responseText!="") {
				nuevoTexto = xmlhttp.responseText;
				document.getElementById(ajaxtarget).innerHTML = URLDecode(nuevoTexto);
			}
		} else {
			alert("Ha ocurrido un error al intentar recuperar los datos.");
		}
	}
}

function sendcomment() {
	if(document.getElementById("comnombre").value=="") {
		alert("Tienes que introducir un nombre.");
	} else {
		if(document.getElementById("comemail").value=="") {
			alert("Tienes que introducir una dirección de correo electrónico.");
		} else {
			if(document.getElementById("comcomentario").value=="") {
				alert("Tienes que introducir un comentario.");
			} else {
				if(document.getElementById("comcaptcha").value=="") {
					alert("Por favor, indica los 5 dígitos del código de seguridad.");
				} else {
					if(document.getElementById("checkuso").checked==false) {
						alert("Por favor, lee y acepta las condiciones de uso.");
					} else {
						document.fcomentario.submit();
					}
				}
			}				
		}
	}
}

function cond_uso() {
	if(document.getElementById("condiciones_uso").style.display == 'block') {
		document.getElementById("condiciones_uso").style.display = 'none';
	} else {
		document.getElementById("condiciones_uso").style.display = 'block';
	}
}


function comfocus() {
	document.getElementById("botres").focus();
	document.getElementById("comnombre").focus();
}

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 50;
PositionY = 50;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

function img1(id,fichero) {
	imagen1  = document.getElementById(id);
	imagen1.src = '/imagenes/'+fichero;
}

function img0(id,fichero) {
	imagen0  = document.getElementById(id);
	imagen0.src = '/imagenes/'+fichero;
}

function checkforblanks() {
	for (var i=0; i<arguments.length; i+=2) {
		if (!arguments[i]) {
			alert("El campo " + arguments[i+1] + " es obligatorio.");
			return false;
		}
	}
	return true;
}

function validate_send_url() {
	var isFull = checkforblanks(document.getElementById("de").value, "[De (nombre)]",
		document.getElementById("origen").value, "[De (e-mail)]",
		document.getElementById("para").value, "[Para (nombre)]",
		document.getElementById("destino").value, "[Para (e-mail)]");
	if (!isFull) {
		return false;
	}
	var mailde = document.getElementById("origen").value;
	var mailpara = document.getElementById("destino").value;
	var filter = /^.+@.+\..{2,4}$/;
	if (!filter.test(mailde)) {
		alert("La dirección de correo electrónico (De) no es correcta.");
		return false;
	}
	if (!filter.test(mailpara)) {
		alert("La dirección de correo electrónico (Para) no es correcta.");
		return false;
	}
}

function trim(cadena) {
	for(i=0; i<cadena.length;) {
		if(cadena.charAt(i)==" ") {
			cadena=cadena.substring(i+1, cadena.length);
		} else {
			break;
		}
	}
	for(i=cadena.length-1; i>=0; i=cadena.length-1) {
		if(cadena.charAt(i)==" ") {
			cadena=cadena.substring(0,i);
		} else {
			break;
		}
	}
	return cadena;
}

function validate_suscripcion() {
	var isFull = checkforblanks(trim(document.getElementById("persona").value), "[Persona de Contacto]",
		trim(document.getElementById("nbempresa").value), "[Empresa]",		
		trim(document.getElementById("cargo").value), "[Cargo]");
	if (!isFull) {
		return false;
	}
	if (document.getElementById("xpapel").checked==false && document.getElementById("xemail").checked==false) {
		alert("Debe marcar al menos una casilla.");
		return false;
	}
	if (document.getElementById("xpapel").checked==true) {
		var isFull = checkforblanks(trim(document.getElementById("direccion").value), "[Dirección]",
		trim(document.getElementById("poblacion").value), "[Población]",
		trim(document.getElementById("provincia").value), "[Provincia]",
		trim(document.getElementById("cp").value), "[Cod. Postal]");
		if (!isFull) {
			return false;
		}
	}
	if (document.getElementById("xemail").checked==true) {
		var isFull = checkforblanks(trim(document.getElementById("email").value), "[E-mail]");
		if (!isFull) {
			return false;
		} else {
			var dirmail = document.getElementById("email").value;
			var filter = /^.+@.+\..{2,4}$/;
			if (!filter.test(dirmail)) {
				alert("La dirección de correo electrónico no es correcta.");
				return false;
			}
		}
	}
}

function validate_consulta() {
	var isFull = checkforblanks(document.getElementById("autor").value, "Autor",
		document.getElementById("pais").value, "País",
		document.getElementById("email").value, "[E-mail]",
		document.getElementById("consulta").value, "[consulta");
	if (!isFull) {
		return false;
	}
	var mailde = document.getElementById("email").value;
	var filter = /^.+@.+\..{2,4}$/;
	if (!filter.test(mailde)) {
		alert("La dirección de correo electrónico no es correcta.");
		return false;
	}
	alert("Gracias por participar.");
}

function slideit(steps) {
	//if browser does not support the image object, exit.
	if (!document.images) {
		return;
	} else {
		document.images.slide.src=eval("image"+step+".src");
		if (step<steps) {
			step++;
		} else {
			step=1;
		}
		//call function "slideit()" every x seconds
		setTimeout("slideit("+steps+")",7000);
	}
}

function muestrapdf(id) {
	var idmenos = id-1;
	var idmas = id+1;
	if(document.getElementById("pdf"+idmenos)) {
		document.getElementById("pdf"+idmenos).style.display = 'none';
	}
	if(document.getElementById("pdf"+idmas)) {
		document.getElementById("pdf"+idmas).style.display = 'none';
	}
	document.getElementById("pdf"+id).style.display = 'inline';
}

function encuesta_voto() {
	if(document.getElementById("opcx").value>0) {
		document.form_encuesta.submit();
	} else {
		alert("Tienes que elegir una de las opciones para votar.");
	}
}

function encuesta_click(valor,posicion,total) {
	for(var i=1;i<=total;i++) {
		document.getElementById("encimg"+i).src = "/imagenes/check0.gif";
	}
	document.getElementById("encimg"+posicion).src = "/imagenes/check1.gif";
	document.getElementById("opcx").value = valor;
}

function encuesta_resultado(id) {
	document.location.href = '/web/encuesta2.asp?err=0';
}

function pdfanteriores() {
	document.getElementById("pdfactual").style.display='none';	
	document.getElementById("pdfanteriores").style.display='block';	
}

function pdfactual() {
	document.getElementById("pdfactual").style.display='block';	
	document.getElementById("pdfanteriores").style.display='none';	
}

function getScrollX() {
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' ) {
    scrOfX = window.pageXOffset;
  } else if( document.body && document.body.scrollLeft ) {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && document.documentElement.scrollLeft ) {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function veragenda(id) {
	newf = document.getElementById("capaagenda");
	var newposX = getScrollX()+170;
	var newposY = getScrollY()+80;
	newf.style.top = newposY+'px';
	newf.style.left = newposX+'px';
	newf.style.display = 'block';
	loadUrl('/web/_agendadata.asp?id='+id,'capaagenda');
}

function ocultaragenda() {
	document.getElementById("capaagenda").style.display = 'none';
	/*var parent = document.getElementById("fichas");
	var children = parent.getElementsByTagName("div");
	for(var i=0;i<children.length;i++) {
		children[i].style.display = 'none';
	}*/
}

var strdocs0 = "0";
var strdocs1 = "1";
var strdocs2 = "2";
var strdocs3 = "3";

function docsover(num) {
	switch (num) {
		case "00": strdocs = "Ver todos los documentos del cooperativismo";
		break;
		case "14": strdocs = "Mensaje de la Alianza Cooperativa Internacional sobre el 87º Día Internacional de las Cooperativas";
		break;
		case "13": strdocs = "Informe Toia";
		break;
		case "12": strdocs = "Las cooperativas de trabajo más cerca";
		break;
		case "11": strdocs = "Estudio de diagnóstico sobre intercooperación para el proyecto Avanza E-Intercoopera";
		break;
		case "10": strdocs = "Qué es una cooperativa";
		break;
		case "09": strdocs = "Guía de buenas prácticas para prevenir los trastornos músculo-esqueléticos";
		break;
		default: strdocs = "";
	}
	document.images.slide.src=eval("image"+step+".src");
	document.getElementById("imgdocs"+num).src = "/imagenes/docs"+num+"01.gif";
	document.getElementById("textodocs").innerHTML = strdocs;
}

function docsout(num) {
	document.getElementById("imgdocs"+num).src = "/imagenes/docs"+num+"00.gif";
	document.getElementById("textodocs").innerHTML = "";
}

function weml(usuario,dominio,tld,texto) { //write email
	var arroba = '@';
	var punto = '.';
	var etiqueta = 'ma' + '' + 'il';
	var dospuntos = 'to:';
	var localizador = usuario;
	localizador = localizador + arroba + dominio;
	localizador = localizador + punto + tld;
	if(texto!='') {
		muestra = texto;
	} else {
		muestra = localizador;
	}
	document.write('<a href="' + etiqueta + dospuntos + localizador + '">' + muestra + '</a>');
}

/*
var min=8;
var max=18;

function increaseFontSize() {
   var p = document.getElementById('noticia').getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
	   alert(p[i].style.fontFamily);
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function maxFont() {
	document.getElementsByTagName('body')[0].style.fontSize = '40px';
}
*/
