/* 
 * Desc:    Collection of custom javascript functions for Buzzoo.net
 *
/*--------------------------------------------------------------------------*/


/* The following is an auto-resize function for textarea as Prototype component
   taken from: http://jroller.com/page/rmcmahon?entry=resizingtextarea_with_prototype */

var textareaAutoResize = Class.create();

textareaAutoResize.prototype = {
    defaultRows: 1,

    initialize: function(field)
    {
        this.defaultRows = Math.max(field.rows, 1);
        this.resizeNeeded = this.resizeNeeded.bindAsEventListener(this);
        Event.observe(field, "click", this.resizeNeeded);
        Event.observe(field, "keyup", this.resizeNeeded);
    },

    resizeNeeded: function(event)
    {
        var t = Event.element(event);
        var lines = t.value.split('\n');
        var newRows = lines.length + 1;
        var oldRows = t.rows;
        for (var i = 0; i < lines.length; i++)
        {
            var line = lines[i];
            if (line.length >= t.cols) newRows += Math.floor(line.length / t.cols);
        }
        if (newRows > t.rows) t.rows = newRows;
        if (newRows < t.rows) t.rows = Math.max(this.defaultRows, newRows);
    }
}

function writeLayer(ID,parentID,sText) {
 if (document.layers) {
   var oLayer;
   if(parentID){
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
   }else{
     oLayer = document.layers[ID].document;
   }
   oLayer.open();
   oLayer.write(sText);
   oLayer.close();
 }
 else if (parseInt(navigator.appVersion)>=5&&navigator.
appName=="Netscape") {
   document.getElementById(ID).innerHTML = sText;
 }
 else if (document.all) document.all[ID].innerHTML = sText
} 