// Sergi Meseguer http://zigotica.com/
// under CC license http://creativecommons.org/licenses/by-sa/2.0/
 
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'); 
	},
	
	prepareConfirmLinks : function(){ 
		var confimLinks = EXTRAS.getElementsByClass("confirm", null, 1);
		for (var k=0; k<confimLinks.length; k++) EXTRAS.confirmLink(confimLinks[k]);
	},
	
	confirmLink : function(link){ 
		link.onclick = function() {
			var t = link.title;
			if(!confirm(t)) return false;
		}
	},
	
	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(" ");
	},
	
	hasClass : function(elm, cn){ 
		var s = elm.className.split(" ");
		for (var k=0; k<s.length; k++) if(s[k]== cn) return true;
	},
	
	doesNotHaveClass : function(elm, cn){ 
		var s = elm.className.split(" ");
		var dnhc = 1;
		for (var k=0; k<s.length; k++) 	if(s[k]== cn) dnhc = 0;
		if(dnhc == 1) return true;
		
	},
	
	// 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 && EXTRAS.hasClass(refTags[z],className)&& !except)
					|| (equal==0 && EXTRAS.hasClass(refTags[z],className) && EXTRAS.doesNotHaveClass(refTags[z],except))
					)
					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);
};
// ************************************************************

