window.onload = function() {
    if (navigator.userAgent.match('MSIE') != null) {
        styleSubmits();
    }
}

function showEl(elid) {
    $(elid).style.display = 'inline';
}

function hideEl(elid) {
    $(elid).style.display = 'none';
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function removeClass(el, classe) {
  var re = new RegExp("(\\b|^)" + classe + "(\\b|$)", "gi");
  if (re.test(el.className)) {
        el.className = el.className.replace(re, '');
        return true;
  }
  return false;
}

function styleSubmits() {
    allInps = document.getElementsByTagName('input');
    for (var i = 0; i < allInps.length; i++) {
        if (allInps[i].type == 'submit') {
            allInps[i].onmouseover = function() {
                this.className += ' active';
            }
            allInps[i].onmouseout = function() {
                removeClass(this, 'active');
            }
        }
    }
}
function lineBreakCount(str){
  	/* counts \n */
  	try {
 		return((str.match(/[^\n]*\n[^\n]*/gi).length));
 	} catch(e) {
  		return 0;
  	}
 }
var ResizingTextArea = Class.create();
ResizingTextArea.prototype = {
	line_height: 16,
	defHeight:0,	
    initialize: function(field)
    {
    	field.id='asd111';
    	this.defHeight = $('asd111').getHeight();
        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 new_h=0;
		var count=lineBreakCount(t.value);
		new_h=count*this.line_height+this.line_height;
		//console.log(new_h);
		//console.log(new_h);
        if(this.defHeight <= new_h){
	        if ( (t.getHeight() < new_h) || (new_h < t.getHeight()) ){
	        	  t.setStyle({height: new_h+"px"}); 
	        }
        }
        else if(this.defHeight!=t.getHeight()) {
        	 t.setStyle({height: this.defHeight+"px"}); 
        }
    }
}