/* VARIOS *******************************/
function limpiarBusqueda(div){
	if(div.value=="Buscar...") div.value="";
}

function textoMiniLinks(txt){
	document.getElementById('txt_mini_links').innerHTML=txt;
}
/****************************************/


/* VALIDAR ******************************/
function comentar(){
	ok=1;
	errores = new Array();
	if(!validacion_simple("comentario_autor","")){ ok=0; errores.push("Debes escribir tu nombre."); }
	if(!valida_mail("comentario_email")){ ok=0; errores.push("Debes ingresar tu email."); }
	if(!validacion_simple("comentario_texto","")){ ok=0; errores.push("Debes escribir un comentario."); }
	
	if(ok==0){ mostrar_errores(errores); }
	else{ document.comentario.submit(); }
}

function validacion_simple(id,min_digitos){
	var ok=1;
	casilla=document.getElementById(id);

	if(min_digitos!=""){
		if(casilla.value.length<min_digitos) { ok=0; }
	}
	else{
		if(casilla.value.length<1) { ok=0; }
	}
	
	return ok;
}

function valida_mail(id){
	casilla=document.getElementById(id);
	var ok=1;
	var es_email=/^(.+\@.+\..+)$/;
	if(!es_email.test(casilla.value)) { ok=0; }
	
	return ok;
}

function mostrar_errores(error){
	txt="Por favor, revisa los siguientes datos:\n\n";
	for(i=0;i<error.length;i++){
		txt=txt+"- "+error[i]+"\n";
	}
	alert(txt);
}
/****************************************/



/* LINK EXTERNOS ************************/
function aExternal() {
   var a,l,i,d=document;
   if (!d.getElementsByTagName) return;
   a = d.getElementsByTagName("a");
    for (i=0;i<a.length;i++) {
         l = a[i];
         if (l.getAttribute("href") && l.getAttribute("rel") == "external") l.target = "_blank";
   }
}
/****************************************/




/* TOOLTIP ******************************/
/* CONFIG */
var qTipTag=["a","input","img"];
var qTipX = 15;
var qTipY = 15;
/* CONFIG */


tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle;

	var anchors=[];
	for(i=0;i<qTipTag.length;i++){
		var els=document.getElementsByTagName(qTipTag[i]);
		for(j=0;j<els.length;j++){
			anchors.push(els[j]);
		}
	}

	for (var i = 0; i < anchors.length; i ++) {
		a = anchors[i];
		sTitle = a.getAttribute("title");
		if(sTitle) {
			a.setAttribute("tiptitle", sTitle);
			a.removeAttribute("title");
			a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
			a.onmouseout = function() {tooltip.hide()};
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}
/***********************************/





/* niceScroll **********************/
var ubicacionActual=-1, destino, velocidad, t;
function niceScroll(dest, vel){
	if(!vel){ vel=10; }
	destino=dest;
	velocidad=vel;
	ir();
}
function ir(){
	donde=findPos(document.getElementById(destino),'y');
	if(navigator.appName=="Netscape"){ ubi=window.pageYOffset; }
	else{ ubi=document.documentElement.scrollTop; }
	if((ubi>donde || ubi<donde) && ubicacionActual!=ubi){
		ubicacionActual=ubi;
		dest=ubicacionActual+((donde-ubicacionActual)/8);
		window.scroll(0,dest);
		setTimeout(ir,velocidad);
	}
	else{
		ubicacionActual=-1;
	}
}
function findPos(obj) {
	var curTop=0;
	if (obj.offsetParent) {
		curTop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curTop += obj.offsetTop;
		}
	}
	return curTop;
}
/***********************************/






/* ADMIN ***************************/
function activar_desactivar(checkbox,casilla){
  if(checkbox.checked==true){ document.getElementById(casilla).disabled=true; }
  else { document.getElementById(casilla).disabled=false; }
}


function preguntar_eliminar(url){
  respuesta=confirm("¿Está seguro que desea eliminar este elemento?");
  if(respuesta==true){ window.location=url; }
}


function recomendarId(origen,destino){
	uni225="a";uni233="e";uni237="i";uni243="o";uni241="n";uni250="u";
	acentos=/[áéíóúñ]/g;
	convertir=origen.value.replace(/ /g,"_").toLowerCase();
	convertir2=convertir.replace(acentos, function($1){return eval("uni"+$1.charCodeAt(0));} );
	document.getElementById(destino).value=convertir2.replace(/\W/g,"_");
}
/***********************************/