window.onload = function() {
	initTbxBuscar();
	animarFondo();
	activarMenuContextual(false);
}

function initTbxBuscar() {
	var tbxBuscar = document.getElementById('tbx_buscar');
	if (tbxBuscar) {
		if (tbxBuscar.value != 'Buscar') {
			tbxBuscar.style.color = 'black';
		}
		tbxBuscar.onfocus = function() {
			if (tbxBuscar.value == 'Buscar') {
				tbxBuscar.style.color = 'black';
				tbxBuscar.value = '';
			}
		}
		tbxBuscar.onblur = function() {
			if (tbxBuscar.value == '') {
				tbxBuscar.style.color = '#c0c0c0';
				tbxBuscar.value = 'Buscar';
			}
		}
	}
}

function animarFondo() {
	var fondo = document.getElementById('fondo_nubes');
	var posicion = fondo.style.backgroundPosition;
	var imgSize = 1080;
	var x;
	if (posicion) {
		x = posicion.split(' ')[0];
		x = parseInt(x.replace('px', ''));
	} else {
		x = 0;
	}
	if (x < imgSize) x++;
	else x = 0;
	fondo.style.backgroundPosition = x + 'px 0';
	setTimeout('animarFondo();', 50);
}

function activarMenuContextual(activar) {
	document.body.oncontextmenu = function() {return activar;}
}

//function addTargetBlank() {
//	var pattern = /bmp|cgm|gif|ief|jpeg|jpg|jpe|png|svg|tiff|tif|djvu|djv|wbmp|ras|ico|pnm|pbm|pgm|ppm|qtif|qti|rgb|xbm|xpm|xwd|php/;
//	var links = document.getElementsByTagName('a');
//	for (var i = 0; i < links.length; i++) {
//		if (links[i].href.match(/^http:\/\/.+\.\w+[^\/]$/)) {
//			var pos = links[i].href.lastIndexOf('.');
//			var ext = links[i].href.substr(pos + 1);
//			if (!ext.match(pattern)) {
////				alert(links[i].href + ' es un fichero');
//				links[i].target = '_blank';
//			}
//		}
//	}
//}

function popup(url, name) {
	window.open(url, name, 'width=380, height=480, top=200, location=no, menubar=no, status=no, toolbar=no');
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}

function msgIE6() {
	if (!getCookie('msgIE6')) {
		var fondo = document.createElement('div');
		var msg = document.createElement('div');
		var btn = document.createElement('div');
		fondo.id = 'ie6_fondo';
		fondo.className = 'ie6_fondo';
		fondo.style.height = document.documentElement.clientHeight + 'px';
		fondo.style.width = document.documentElement.clientWidth + 'px';
		msg.className = 'ie6';
		msg.innerHTML = 'Está usando una <b>versión antigua</b> de <b>Internet Explorer</b>, por lo que no podrá ver correctamente algunas partes de nuestra web. Le recomendamos que use un navegador de última generación como <a href="http://www.opera.com/browser/">Opera</a>, <a href="http://www.mozilla-europe.org/es/firefox/">Firefox</a>, <a href="http://www.apple.com/es/safari/">Safari</a> o <a href="http://www.google.com/chrome/">Chrome</a>, o actualice su navegador a la <a href="http://www.microsoft.com/spain/windows/internet-explorer/">última versión</a>.';
		msg.style.top = parseInt((document.documentElement.clientHeight / 2) - 130) + 'px';
		msg.style.left = parseInt((document.documentElement.clientWidth / 4) - 20) + 'px';
		btn.className = 'ie6_btn';
		btn.innerHTML = 'Si desea continuar de todas formas, haga click aquí <input style="position:relative;top:4px;" type="button" value="Continuar" onclick="document.getElementById(\'ie6_fondo\').onclick();" />';
		document.body.appendChild(fondo);
		setTimeout(function() {msg.appendChild(btn);}, 5000);
		document.body.appendChild(msg);
		setTimeout(function() {
			fondo.onclick = function() {
				document.body.removeChild(fondo);
				document.body.removeChild(msg);
			}
		}, 5000);
		setCookie('msgIE6', '1', 1);
	}
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
