// Sergi Meseguer http://zigotica.com/
// under CC license http://creativecommons.org/licenses/by-sa/2.0/


/*
	--------------------------------------------------------------------------
	$Id: spamspan.js 5 2007-09-29 15:56:26Z moltar $
	sfdf----------------------------------------------------------------------------
	Version: 1.03
	Release date: 13/05/2006
	Last update: 07/01/2007

	(c) 2006 SpamSpan (www.spamspan.com)

	This program is distributed under the terms of the GNU General Public
	Licence version 2, available at http://www.gnu.org/licenses/gpl.txt
	--------------------------------------------------------------------------
*/



document.getElementsByClassName=function(className) {
  var data = [];
  var node=(document.getElementById("wrapper"))? document.getElementById("wrapper"):document;
//var tags = node.getElementsByTagName("*") ? node.getElementsByTagName("*") : document.all;    
  var tags = (!document.all) ? node.getElementsByTagName("*") : document.all
  for(var i=0;i<tags.length;i++) { if(tags[i].className.match(className)) data[data.length]=tags[i];}
  return data;
}
// Aumentar y disminuir letra

var tamanoLetrapordefecto = 5;
var tamanoLetra = tamanoLetrapordefecto;
var tamanoLetraminimo = 3;
var tamanoLetramaximo = 7;
var identidadLetra;

function aumentaLetra() {
    if (tamanoLetra < tamanoLetramaximo) {
    tamanoLetra += 1;
    identidadLetra = document.getElementsByClassName('contenedor_articulo');    
    identidadLetra.style.display='none'; 
    }
}

function disminuyeLetra() {
    if (tamanoLetra > tamanoLetraminimo) {
    tamanoLetra -= 1;
    identidadLetra = document.getElementsByClassName('contenedor_articulo');
    identidadLetra.style.display='none'; 
    }
}

// FIN Aumentar y disminuir letra



var spamSpanMainClass		= 'spamspan';
var spamSpanUserClass		= 'u';
var spamSpanDomainClass		= 'd';
var spamSpanAnchorTextClass = 't';
var spamSpanParams			= new Array('subject', 'body');

/*
	--------------------------------------------------------------------------
	Do not edit past this point unless you know what you are doing.
	--------------------------------------------------------------------------
*/

// load SpamSpan
addEvent(window, 'load', spamSpan);

function spamSpan() {
	var allSpamSpans = getElementsByClass(spamSpanMainClass, document, 'span');
	for (var i = 0; i < allSpamSpans.length; i++) {
		// get data
		var user = getSpanValue(spamSpanUserClass, allSpamSpans[i]);
		var domain = getSpanValue(spamSpanDomainClass, allSpamSpans[i]);
		var anchorText = getSpanValue(spamSpanAnchorTextClass, allSpamSpans[i]);
		// prepare parameter data
		var paramValues = new Array();
		for (var j = 0; j < spamSpanParams.length; j++) {
			var paramSpanValue = getSpanValue(spamSpanParams[j], allSpamSpans[i]);
			if (paramSpanValue) {
				paramValues.push(spamSpanParams[j] + '=' +
					encodeURIComponent(paramSpanValue));
			}
		}
		// create new anchor tag
		var at = String.fromCharCode(32*2);
		var email = cleanSpan(user) + at + cleanSpan(domain);
		var anchorTagText = document.createTextNode(anchorText ? anchorText : email);
		var mto = String.fromCharCode(109,97,105,108,116,111,58);
		var hrefAttr = mto + email;
			hrefAttr += paramValues.length ? '?' + paramValues.join('&') : '';
		var anchorTag = document.createElement('a');
			anchorTag.className = spamSpanMainClass;
			anchorTag.setAttribute('href', hrefAttr);
			anchorTag.appendChild(anchorTagText);
		// replace the span with anchor
		allSpamSpans[i].parentNode.replaceChild(anchorTag, allSpamSpans[i]);
	}
}

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

function getSpanValue(searchClass, scope) {
	var span = getElementsByClass(searchClass, scope, 'span');
	if (span[0]) {
		return span[0].firstChild.nodeValue;
	} else {
		return false;
	}
}

function cleanSpan(string) {
	// string = string.replace(//g, '');
	// replace variations of [dot] with .
	//string = string.replace(/[\[\(\{]?[dD][oO0][tT][\}\)\]]?/g, '.');
	// replace spaces with nothing
	string = string.replace(/\s+/g, '');
	return string;
}

// http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent)
	{
		obj['e' + type + fn] = fn;
		obj[type + fn] = function() { obj['e' + type + fn](window.event); }
		obj.attachEvent('on' + type, obj[type + fn]);
	}
}


var  CSS = {
	
	setStyle : function(node,rule,value){
		if(typeof(node)=="string")  node = document.getElementById(node);
		node.style[rule] = value;
	},
	
	getStyle : function(node,rule){
		if(typeof(node)=="string")  node = document.getElementById(node);
		if(rule=="width") return CSS.getW(node);
		else if(rule=="height") return CSS.getH(node);
		else {
			if (window.getComputedStyle) return window.getComputedStyle(node, null)[rule];
			else return node.currentStyle[rule];
		}
	},

	getH : function(node){
		if(typeof(node)=="string")  node = document.getElementById(node);
		return node.offsetHeight;
	},

	getW : function(node){
		if(typeof(node)=="string")  node = document.getElementById(node);
		return node.offsetWidth;
	}
}


EXTRAS = {
	
	// listeners modified from John Resig
	// http://ejohn.org/projects/flexible-javascript-events/
	addEvent : function ( obj, type, fn, useCapture ) {
	  if ( obj.attachEvent ) {
	    obj['e'+type+fn] = fn;
	    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
	    obj.attachEvent( 'on'+type, obj[type+fn] );
	  } else obj.addEventListener( type, fn, useCapture );
	}, 
	
	removeEvent : function ( obj, type, fn, useCapture ) {
	  if ( obj.detachEvent ) {
	    obj.detachEvent( 'on'+type, obj[type+fn] );
	    obj[type+fn] = null;
	  } else obj.removeEventListener( type, fn, useCapture );
	}, 

	preventExplorerFlicker : function() {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	},
	
	popup : function(where,w,h,t,l) {
		if (!t) t=0;
		if (!l) l=0;
		window.open( where, 'popupwindow', 'width='+w+', height='+h+', top='+t+', left='+l+', scrollbars=no, resizable=no'); 
	},
	
	reTarget : function(){ 
		var external = document.getElementsByTagName("a"); 
		for (var k=0; k<external.length; k++){
			if (external[k].href) {
			var url = external[k].href; 
				if (url.indexOf(document.domain) == -1 && url.indexOf("javascript:") == -1 && url.indexOf("mailto:") == -1) 
				{
					var ExternalTxt = "(Enlace externo)";
					external[k].target = "_blank";
					external[k].title += " " + ExternalTxt;
				}
			}
		}
	},
	
	popThisUp : function(obj) {
		obj.onclick = function() {
			window.open(obj.href, '');
			return false;
		}
	},

	autoPopup : function() {
		var pops = EXTRAS.getElementsByClass('popup',null,0);
		for (var i = 0; i < pops.length; i++) {
				EXTRAS.popThisUp(pops[i]);
		}
	},
	
	blurAll : function(){ 
		var lincs = document.getElementsByTagName("a"); 
		function doBlur(e)  { this.blur(); } 
		for (var k=0; k<lincs.length; k++){
			lincs[k].onfocus = doBlur;
		}
	},
	
	addClass : function(elm, cn){ 
		if(elm.className.indexOf(cn) == -1) elm.className += " " + cn;
	},
	
	removeClass : function(elm, cn){ 
		var s = elm.className.split(" ");
		for (var k=0; k<s.length; k++) if(s[k]== cn) s[k]="";
		elm.className = s.join(" ");
	},
	
	// Method adapted from Dan Pupius (pupius.co.uk):
	getElementsByClass : function(className,node,equal,except) {
			if(!node) node=document;
			// follows UGLY hack to fix IE5
			if(navigator.appVersion.indexOf("MSIE 5")>-1) var refTags = document.all;
			else var refTags = node.getElementsByTagName("*") ? node.getElementsByTagName("*") : document.all;
		 
			var retVal = new Array(); 
			for(var z=0;z< refTags.length;z++) {
					if(
					(equal==1 && refTags[z].className == className)
					|| (equal==0 && !except && refTags[z].className.indexOf(className) != -1)
					|| (equal==0 && refTags[z].className.indexOf(className) != -1 && refTags[z].className.indexOf(except) == -1)
					)
					retVal.push(refTags[z]);
			}
			return retVal;
	}
}
// adds 1 or more elements to an array (IE only)
if(!Array.prototype.push)
{
	Array.prototype.push =  function()
	{
		var i;
		for(i=0; j=arguments[i]; i++) this[this.length] = j;
		return this.length;
	}
}

// ************************************************************
// (C) Andrea Giammarchi webreflection.blogspot.com
function onContent(f){
var a=onContent,b=navigator.userAgent,d=document,w=window,c="onContent",e="addEventListener",o="opera",r="readyState",
s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
a[c]=(function(o){return function(){a[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(a[c]);
if(d[e])d[e]("DOMContentLoaded",a[c],false);
if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))(function(){/loaded|complete/.test(d[r])?a[c]():setTimeout(arguments.callee,1)})();
else if(/MSIE/i.test(b))d.write(s);
};
// ************************************************************

// ************************************************************

