// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
	function add_more(node_name)
	{
		//var child_nodes = document.getElementById(node_name).childNodes;
		var child_nodes = document.getElementById(node_name).getElementsByTagName("input");
		var end_node;
		for(var i=1;i<child_nodes.length;i++)
		{
			if(child_nodes[i].style.display == "none")
			{
				child_nodes[i].style.display = "block";
				child_nodes[i].style.width = "205px";
				break;
			}
		}
	}
	
	function eval_revenue_split(id)
	{
		var rev_split_prod = document.getElementById(id).value;
		document.getElementById('revenue_split_moovieshoovie').value = 100 - rev_split_prod;
	}
	// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
// This isa all for the forum plugins
var TopicForm = {
  editNewTitle: function(txtField) {
    $('new_topic').innerHTML = (txtField.value.length > 5) ? txtField.value : 'New Topic';
  }
}

var LoginForm = {
  setToPassword: function() {
    $('openid_fields').hide();
    $('password_fields').show();
  },
  
  setToOpenID: function() {
    $('password_fields').hide();
    $('openid_fields').show();
  }
}

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());
    $('post_' + 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 = $('post_' + 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);
  }
}

function enforceLength(obj, maxLength)
{
 if (obj.value.length >= maxLength)
 {
 obj.value = obj.value.substring(0, maxLength);
 }
}

function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize)
{

 var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "countedTextBox";
 var countBody = opt_countBody ? opt_countBody : "countBody";
 var maxSize = opt_maxSize ? opt_maxSize : 1024;

 var field = document.getElementById(countedTextBox);
 
 if (field && field.value.length >= maxSize)
 {
 field.value = field.value.substring(0, maxSize);
 }
 var txtField = document.getElementById(countBody);
 if (txtField)
 {
 txtField.value =maxSize - field.value.length;
 }
 enforceLength(field,maxSize);
}


//Event.addBehavior({
 // '#search,#monitor_submit': function() { this.hide(); }
//})	