// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


////////////////////////////////////////////////////////////////////
function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}
function zoomText(Accion,Elemento){
//inicializaciones
 obj=document.getElementById(Elemento);
 if (obj.style.fontSize==""){
  obj.style.fontSize="100%";
 }
 actual=parseInt(obj.style.fontSize); //valor actual del tama?o del texto
 incremento=10;// el valor del incremento o decremento en el tama?o

 //accion sobre el texto
 if(Accion=="reestablecer"){
  if(Elemento=="contenido")
   obj.style.fontSize="110%";
  else
  obj.style.fontSize="100%";
 }
 if(Accion=="aumentar"){
  valor=actual+incremento;
  obj.style.fontSize=valor+"%"
 }
 if(Accion=="disminuir"){
  valor=actual-incremento;
  obj.style.fontSize=valor+"%"
 }
}

// Beast functions
var TopicForm = {
  editNewTitle: function(txtField) {
    $('new_topic').innerHTML = (txtField.value.length > 5) ? txtField.value : 'New Topic';
  }
}

var EditForm = {
  // show the form
  init: function(postId) {
    $('edit-post-' + postId + '_spinner').show();
    this.clearReplyId();
  },

  // sets the current post id we're editing
  setReplyId: function(postId) {
    $('edit').setAttribute('post_id', postId.toString());
    $('posts-' + postId + '-row').addClassName('editing');
    if($('reply')) $('reply').hide();
  },

  // clears the current post id
  clearReplyId: function() {
    var currentId = this.currentReplyId()
    if(!currentId || currentId == '') return;

    var row = $('posts-' + currentId + '-row');
    if(row) row.removeClassName('editing');
    $('edit').setAttribute('post_id', '');
  },

  // gets the current post id we're editing
  currentReplyId: function() {
    return $('edit').getAttribute('post_id');
  },

  // checks whether we're editing this post already
  isEditing: function(postId) {
    if (this.currentReplyId() == postId.toString())
    {
      $('edit').show();
      $('edit_post_body').focus();
      return true;
    }
    return false;
  },

  // close reply, clear current reply id
  cancel: function() {
    this.clearReplyId();
    $('edit').hide()
  }
}

var ReplyForm = {
  // yes, i use setTimeout for a reason
  init: function() {
    EditForm.cancel();
    $('reply').toggle();
    $('post_body').focus();
    // for Safari which is sometime weird
//    setTimeout('$(\"post_body\").focus();',50);
  }
}
