Element.addMethods( { 
clone: function(element) {
var clone = new Element(element.tagName);
$A(element.attributes).each(function(attribute) {
if ( attribute.name != 'style' )
clone[attribute.name] = attribute.value; 
});
clone.setStyle( element.getStyles() );
element.classNames().each(function(c){clone.addClassName(c)});
clone.update(element.innerHTML);
return clone;
},
brothers: function(element) {
return element.up().childElements();
},
effectCancel: function(element) {
if (element.effect && element.effect.cancel)
element.effect.cancel();
},
morphUsingClass: function(element, className, options, removeClass) {
element.effectCancel();
var aux = element.clone();
aux.removeAttribute('style');
aux.removeClassName(removeClass);
aux.addClassName(className);

element.effect = new Effect.Morph(element, Object.extend({ style:aux.getStyles(), duration:1, beforeFinish:function(){element.removeAttribute('class');element.addClassName(className); element.removeAttribute('style');} }, options||{} ));
/* ex.:
elems = $$('form > table > tbody > tr');

var cresce = elems[0];
elems._each(function(elem){
if(elem != cresce)
elem.morphUsingClass('pequeno',{},'grande');
});
cresce.morphUsingClass('grande',{},'pequeno');
//
//.grande {
//	height: 100px;
//	overflow: auto;
//	font-size: 11px;
//}	
//.pequeno,
//.pequeno * {
//	height: 20px;
//	overflow: hidden;
//	font-size: 11px;
//}
//
element.immediateDescendants().each(function(subElement, index) {
if (aux.immediateDescendants() && aux.immediateDescendants().length > index) {
subStyle = aux.immediateDescendants()[index].getStyles();
subStyle['width'] = "";
subElement.effect = new Effect.Morph(subElement, Object.extend({ style:subStyle, duration:options['duration']||1, beforeFinish:function(){ element.removeAttribute('style');} }, {} ));
}
});
*/
}
}); 


argsToEval = function(args){return args.collect(function(arg){return (typeof arg == 'string')?"'"+arg+"'":arg;});}

/**
** Adiciona m�todos para Strings
**/
Object.extend(String.prototype,{
getLength:function(){return this.length;},
replaceAll:function(val,replace){while(this.indexOf("-")>0){elem=this.replace(val,replace);return elem.replaceAll(val,replace);}return ""+this;},
toInteger:function(){return parseInt(this!=""?this:0);},
toFloat:function(){return parseFloat(this!=""?this:0);},
toString:function(){return ""+this;},
toBoolean:function(){return eval(this.toString());},
toDate:function(){
var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
if(!regex.test(this.replaceAll("-","/"))) return false;
return new Date(this.replaceAll("-","/").replace(regex, '$2/$1/$3'));
},
concatBefore:function(str){return str.concat(this);}});

/**
** Adiciona m�todos para Number
**/
Object.extend(Number.prototype,{
toInteger:function(){return parseInt(this);},
toFloat:function(){return parseFloat(this);},
abs:function(){return Math.abs(this);},
pow:function(exp){return Math.pow(this,exp);},
roundDown:function(decimal){if(!decimal)decimal=0;return (this.toFloat()*Math.pow(10,decimal)).toInteger()/Math.pow(10,decimal).toFloat();},
round:function(decimal){if(!decimal)decimal=0;return ((this.toFloat()+0.5*((this>0)?1:-1)/Math.pow(10,decimal))*Math.pow(10,decimal)).toInteger()/Math.pow(10,decimal).toFloat();},
roundUp:function(decimal){if(!decimal)decimal=0;return ((this.toFloat()+1*((this>0)?1:-1)/Math.pow(10,decimal))*Math.pow(10,decimal)).toInteger()/Math.pow(10,decimal).toFloat();}});

/**
** Adiciona m�todos para Number
**/
Object.extend(Date.prototype,{
daysAfter:function(date){return ((this - new Date(date)).toInteger()/86400000).toInteger();},
daysBefore:function(date){return ((new Date(date) - this).toInteger()/86400000).toInteger();}});

/**
** Adiciona m�todos para vetores
**/
Object.extend(Array.prototype,{
max:function(){return Math.max.apply(null,this);},
min:function(){return Math.min.apply(null,this);},
sum:function(){return (!this.length) ? 0 : this.slice(1).sum() + ((typeof this[0] == 'number') ? this[0] : 0);},
checked:function(){return this.collect(function(elem){return (elem.checked)?elem:null;}).flatten().compact();},
get:function(selector,position){return this.collect(function(elem){return elem.select(selector)[(position?position:0)];}).compact();},
getAll:function(selector,position){return this.collect(function(elem){return elem.select(selector);}).flatten().compact();},
getFloat:function(){return this.collect(function(elem){return elem.value.toFloat();}).flatten().compact();},
childOf:function(parent){return this.collect(function(elem){return (elem.childOf(parent))?elem:null;}).flatten().compact();},
add:function(val){if(val.add){return this.addEach(val);}for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()+val.toFloat();}return this;},
subtract:function(val){if(val.subtract){return this.subtractEach(val);}for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()-val.toFloat();}return this;},
multiply:function(val){if(val.multiply){return this.multiplyEach(val);}for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()*val.toFloat();}return this;},
divide:function(val){if(val.divide){return this.divideEach(val);}for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()/val.toFloat();}return this;},
pow:function(val){if(val.pow){return this.powEach(val);}for(var i=0;i<this.size();i++){this[i]=Math.pow(this[i].toFloat(),val.toFloat());}return this;},
addEach:function(array){for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()+array[i].toFloat();}return this;},
subtractEach:function(array){for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()-array[i].toFloat();}return this;},
multiplyEach:function(array){for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()*array[i].toFloat();}return this;},
divideEach:function(array){for(var i=0;i<this.size();i++){this[i]=this[i].toFloat()/array[i].toFloat();}return this;},
powEach:function(array){for(var i=0;i<this.size();i++){this[i]=Math.pow(this[i].toFloat(),array[i].toFloat());}return this;},
setValueEach:function(array){for(var i=0;i<this.size();i++){this[i]=this[i].setValue(array[i]);}return this;},
serialize:function(array){ var serialized = $H(); this._each(function(elem){ if (elem.name) serialized.set(elem.name, elem.value);}); return serialized; }});

var elementFunctions =  $A("animate,visible,toggle,hide,show,remove,update,replace,inspect,recursivelyCollect,ancestors,descendants,immediateDescendants,previousSiblings,nextSiblings,siblings,match,up,down,previous,next,getElementsBySelector,getElementsByClassName,readAttribute,getHeight,getWidth,classNames,hasClassName,addClassName,removeClassName,toggleClassName,observe,stopObserving,cleanWhitespace,empty,descendantOf,scrollTo,getStyle,getOpacity,setStyle,setOpacity,getDimensions,makePositioned,undoPositioned,makeClipping,undoClipping,getHeight,getWidth,hover,check,getValue,setValue,getText,getLength,toInteger,toFloat,toDate,daysAfter,replaceAll,roundDown,round,roundUp,concatBefore,capitalize".split(","));
var eventFunctions = $A("blur,focus,load,resize,scroll,unload,click,dblclick,mousedown,mouseup,mousemove,mouseover,mouseout,change,submit,keydown,keypress,keyup,error".split(","));

/**
** Adiciona m�todos de evento e metodos de elementos HTML aos vetores para iterar��o
**/
eventFunctions.concat(elementFunctions).each(function(name){eval("Object.extend(Array.prototype,{"+name+":function(){var args=$A(arguments).slice(0);return this.collect(function(elem){return eval('elem."+name+"('+argsToEval(args)+');');}).flatten();}});");});

eventFunctions.capitalize().concatBefore('add').each(function(name){eval("Object.extend(Array.prototype,{"+name+":function(){var args=$A(arguments).slice(0);return this.collect(function(elem){return eval('elem."+name+"('+argsToEval(args)+');');}).flatten();}});");});

corrigeListagem = function(){
$$('.listagem > tbody > tr[class]').removeClassName('odd');
$$('.listagem > tbody > tr[class]').removeClassName('even');
var evenOdd = 'even';
$$('.listagem > tbody > tr[class]')._each(function(elem){
if (evenOdd == 'odd') 
evenOdd = 'even';
else 
evenOdd = 'odd';
elem.addClassName(evenOdd);
});
}