String.prototype.trim = function() {return this.replace(/(^\s*)|(\s*$)/g, "")}

Event.observe(window, 'load', body_load, false);
Event.observe(window, 'load', DHlinkStatus.create, false);

function body_load() {
  var ptd_top = $('diapo')
  if (ptd_top) {
    var path ='img/portada/promo'
    if ($('multimedia')) path= '/' + path
    diaporama($('menu'), $('diapo'), path, 5, 'appear', 2, 4)
  }

  var tabs = $('tabs')
  if(tabs) {
    var newnodes = []
    var mh = 0;
    var t  = tabs.getElementsByTagName('A')
    var dt = tabs.getElementsByTagName('DT')[0];

    for (var x = 0; x < t.length; x++) {
      var tx = t[x]
      if (tx.parentNode.tagName == 'DT') {
        var ty = $(tx.href.substr(tx.href.indexOf('#') + 1))
        tx.onclick = tab_click
        if (x != 0) tx.parentNode.style.border = "none";
        newnodes.push([tx, ty])
      }
    }

    for (var x = 0; x < newnodes.length; x++) {
      var nx = newnodes[x]
      if ((nx[1].innerHTML.trim() != '') && (x != 0)){
         dt.appendChild(nx[0].parentNode.removeChild(nx[0]))
      }
    }
  }
/*
  var video = $('player')
  if(video) {
    var v = location.href.substring(location.href.lastIndexOf('.') - 1, location.href.length-5)
    var FO = { movie:"/video/flvplayer.swf",width:"400",height:"320",
               majorversion:"8",build:"0",bgcolor:"#FFFFFF",
               flashvars:"file=video" + v + ".flv&showdigits=true&autostart=false&overstretch=true&image=/video/video" + v + ".jpg" };
    UFO.create(FO,"playerObj");
  }
*/
  if (location.search.indexOf('msgok') > -1) alert('El mensaje se ha enviado correctamente, en breve contactaremos con usted')
  else if (location.search.indexOf('msgko') > -1) alert('No se ha podido enviar el formulario, por favor inténtelo más tarde')
}

function diaporama(e, i, base, counter, eff, dur, inter) {
  var count = counter + 1

  do {
   count --
   var img = document.createElement("img")
   img.src = base + count + ".jpg"
   img.id  = 'img' + count
   img.style.position = 'absolute'
   img.style.marginTop = "-15.05em"
   img.style.marginLeft = document.all? "16.1em" : '16.15em'
   img.style.display = (count == 1)? 'inline' : 'none'
   e.appendChild(img)
  } while (count != 1)

  e.style.backgroundImage = 'none'

  setInterval(function() {
    Effect.toggle('img' + ((count == 0)? 1 : count), eff,  { duration: dur })
    Effect.toggle('img' + ((count == 0)? counter : count + 1), eff, { duration: dur })
    count = (count == (counter - 1))? 0 : count +1
  },inter * 1000);
}

function tab_click() {
  var a = document.getElementsByClassName('active')
  if ((a[0] != this)){
    a[0].className = ''
    $(a[0].href.substr(a[0].href.indexOf('#') + 1)).style.display = 'none'

    this.className='active'
    $(this.href.substr(this.href.indexOf('#') + 1)).style.display = 'block'
  }
  window.focus();
  return false
}

