//FUNCIONES IMPORTANTES
function ob(obj) {
  return document.getElementById(obj);
}
function muestraflash(urlflash, ancho, alto, transparencia, base, color, ident, align, valores) {
         document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' WIDTH='" + ancho + "' HEIGHT='" + alto + "' id='" + ident + "' ALIGN='" + align + "'>");
         document.write("<PARAM NAME=wmode VALUE=" + transparencia + ">");
         document.write("<PARAM NAME=base VALUE='" + base + "'>");
         document.write("<PARAM NAME=FlashVars VALUE='" + valores + "'>");
         document.write("<PARAM NAME=quality VALUE=high>");
         document.write("<PARAM NAME=bgcolor VALUE=#" + color + ">");
         document.write("<PARAM NAME=movie VALUE='" + urlflash + "'>");
         document.write("<EMBED FlashVars='" + valores + "' base='" + base + "' quality=high bgcolor=#" + color + " WIDTH='" + ancho + "' HEIGHT='" + alto + "' NAME='" + ident + "' ALIGN='" + align + "' TYPE='application/x-shockwave-flash' wmode=" + transparencia + " PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer' src='" + urlflash + "'></EMBED>");
         document.write("</OBJECT>");
}
function linea(alineacion,ancho){
 document.write('<div align="'+alineacion+'">');
 document.write('<hr color="#009933" width="'+ancho+ '" style="height:1px" />');
 document.write('</div>');
 }
function cuentacaracteres() {
            var limite = 1500;
            var caracterestotal = parseInt(ob("comentario").value.length);
            var t = limite - caracterestotal;
            if ((t > 15) && (t < 1500)) {
              var resp = "Caracteres disponibles: <b>" + t + "</b>.";
            } else if ((t <= 15) && (t >= 0)) {
              var resp = "<font color=#0BE000><b>¡Atención!</b></font>Caracteres disponibles: <b>" + t + "</b>.";
            } else if (t == -1) {
              var resp = "<font color=red><b>¡Atención!</b></font> Te has excedido en <b>1</b> caracter.";
            } else if (t < -1) {
              var resp = "<font color=red>Te has excedido en <b>" + (t * -1) + "</b> caracteres.</font>";
            } else if (t == 1500) {
              var resp = "Caracteres disponibles: <b>1500</b>.";
            }
            ob("infocaracteres").innerHTML = resp + "<br />";
            return t;
          }
function ltrim(s){
	return s.replace(/^\s+/, "");
}
function rtrim(s){
	return s.replace(/\s+$/, "");
}
function trimAll(s){
	return rtrim(ltrim(s));
}
function verperfil(idusuario,nombreusuario){
 var p = confirm('¿Deseas ver el perfil de '+nombreusuario+'?');
 if(p){
   top.location = 'index.php?perfil='+idusuario;
     }
 else{
   return false;}
  }
function limitecomentario(){
ob("comentario").value = trimAll(ob("comentario").value);
if( ob("comentario").value == ''){
	alert('Debes escribir un comentario.');
	ob("comentario").focus();
	ob("comentario").select();
	return false;  
	}
else if(ob("comentario").value.length > 1500){
	alert('Te has pasado del límite permitido de caracteres en tu comentario, por favor redúcelo.');
	ob("comentario").focus();
	ob("comentario").select();
	return false; 
	}
else{
	 ob("infocaracteres").innerHTML = '<em>Enviando el comentario...</em>';
	 ob("btnenviar").disabled = true;
	 return true;
  }
}
//TECLA 'CONTROL'
var MF = (navigator.appVersion == 'Netscape')?true:false;
var tecla1 = false;
var tecla2 = false;
window.onload = function() {
 document.onkeydown = verbarra;
 document.onkeyup = function(evento){
  var evento = window.event || evento;
  var teclaactual = evento.keyCode;
  if(teclaactual == 17){ tecla1 = false; }
  if(teclaactual == 18){ tecla2 = false; }
    }
}
function verbarra(evento){
 var evento = window.event || evento;
 var teclaactual = evento.keyCode;
 if(ob('barrapt')){
  if(teclaactual == 17){ tecla1 = true; }
  if(teclaactual == 18){ tecla2 = true; }
  if(tecla1 == true && tecla2 == true){ abrecierrabarra();}
 }
}
//BARRA PUNTOTRIPLE.ORG
function abrecierrabarra(){
	if(ob('barrapt').style.display == 'none'){
		ob("barrapt").style.display = '';
	    ob("barrapt_abre").style.display = 'none';
	}
	else{
		ob("barrapt").style.display = 'none';
		muestraprecarga(0);
	    ob("barrapt_abre").style.display = '';
	}
}
function muestraprecarga(o){
	if(o != 0){
	 ob("lineadiv").style.display = '';
         ob("opciones_barra").style.display = '';
         ob("opciones_barra").innerHTML = 'Cargando información, espere un momento...';
         ob("carga_opcion").src = "secciones/opciones.php?seccion="+o;
        }else{
	     ob("lineadiv").style.display = 'none';
         ob("opciones_barra").style.display = 'none';
	 }
}
//OTRAS FUNCIONES
function borde(id){
var prin = document.getElementById(id);
var borde = prin.border;
if(borde == 0){
  prin.border = 1;
  prin.borderColor = "red";}
else{
 prin.border = 0;}
}
//MENU DESPLEGABLE
//******************************************************************
function Browser() {
  var ua, s, i;
  this.isIE    = false;  
  this.isNS    = false;  
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {
  var el;
  if (activeButton == null)
    return;

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  if (el == activeButton)
    return;

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

function buttonClick(event, menuId) {
  var button;

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  button.blur();

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    menuInit(button.menu);
  }

  if (activeButton != null)
    resetButton(activeButton);

  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {
  var button;

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {
  var x, y;

  button.className += " menuButtonActive";

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";
}

function resetButton(button) {
  removeClassName(button, "menuButtonActive");

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}


function menuMouseover(event) {
  var menu;
  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  if (menu.activeItem != null)
    closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {
  var item, menu, x, y;
  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;
  menu = getContainerWith(item, "DIV", "menu");

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

  item.className += " menuItemHighlight";

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    menuInit(item.subMenu);
  }

  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);

  var maxX, maxY;

  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  if (browser.isIE && browser.version < 6) {
    maxX = document.body.scrollLeft + document.body.clientWidth;
    maxY = document.body.scrollTop  + document.body.clientHeight;
  }
  if (browser.isIE && browser.version >= 6) {
    maxX = document.documentElement.scrollLeft + document.documentElement.clientWidth;
    maxY = document.documentElement.scrollTop  + document.documentElement.clientHeight;
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));

  item.subMenu.style.left = x + "px";
  item.subMenu.style.top  = y + "px";
  item.subMenu.style.visibility = "visible";

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function closeSubMenu(menu) {
  if (menu == null || menu.activeItem == null)
    return;

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

function menuInit(menu) {
  var itemList, spanList
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN")
    textEl  = null
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null)
      textEl.style.paddingRight = (itemWidth 
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
  }

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }
}

function getContainerWith(node, tagName, className) {
  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {
  var i, list;
  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {
  var i, curList, newList;
  if (el.className == null)
    return;
  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {
  var x;
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {
  var y;
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

