	(function($) {
	var k = (window.orientation != undefined), pasteEvent = (($.browser.opera || ($.browser.mozilla && parseFloat($.browser.version
			.substr(0, 3)) < 1.9)) ? 'input' : 'paste');
	$.event.special.paste = {
		setup : function() {
			if (this.addEventListener)
				this.addEventListener(pasteEvent, pasteHandler, false);
			else if (this.attachEvent)
				this.attachEvent(pasteEvent, pasteHandler)
		},
		teardown : function() {
			if (this.removeEventListener)
				this.removeEventListener(pasteEvent, pasteHandler, false);
			else if (this.detachEvent)
				this.detachEvent(pasteEvent, pasteHandler)
		}
	};
	function pasteHandler(e) {
		var a = this;
		e = $.event.fix(e || window.e);
		e.type = 'paste';
		setTimeout(function() {
			$.event.handle.call(a, e)
		}, 1)
	}
	;
	$
			.extend( {
				mask : {
					rules : {
						'z' : /[a-z]/,
						'Z' : /[A-Z]/,
						'a' : /[a-zA-Z]/,
						'*' : /[0-9a-zA-Z]/,
						'@' : /[0-9a-zA-Z������������������]/
					},
					keyRepresentation : {
						8 : 'backspace',
						9 : 'tab',
						13 : 'enter',
						16 : 'shift',
						17 : 'control',
						18 : 'alt',
						27 : 'esc',
						33 : 'page up',
						34 : 'page down',
						35 : 'end',
						36 : 'home',
						37 : 'left',
						38 : 'up',
						39 : 'right',
						40 : 'down',
						45 : 'insert',
						46 : 'delete',
						116 : 'f5',
						123 : 'f12',
						224 : 'command'
					},
					iphoneKeyRepresentation : {
						10 : 'go',
						127 : 'delete'
					},
					signals : {
						'+' : '',
						'-' : '-'
					},
					options : {
						attr : 'alt',
						mask : null,
						type : 'fixed',
						maxLength : -1,
						defaultValue : '',
						signal : false,
						textAlign : true,
						selectCharsOnFocus : false,
						autoTab : false,
						setSize : false,
						fixedChars : '[(),.:/ -]',
						onInvalid : function() {
						},
						onValid : function() {
						},
						onOverflow : function() {
						}
					},
					masks : {
						'quantidade' : {
							mask : '99'
						},
						'placa-veiculo' : {
							mask : 'aaa-9999'
						},
						'cnvs' : {
							mask : '9-9999999',
							type : 'reverse'
						},
						'tel' : {
							mask : '9999-9999'
						},
						'cnae' : {
							mask : '99999999999999'
						},
						'phone' : {
							mask : '(99) 9999-9999'
						},
						'phone-us' : {
							mask : '(999) 999-9999'
						},
						'cpf' : {
							mask : '999.999.999-99'
						},
						'cnpj' : {
							mask : '99.999.999/9999-99'
						},
						'date' : {
							mask : '39/19/9999'
						},
						'date-us' : {
							mask : '19/39/9999'
						},
						'cep' : {
							mask : '99.999-999'
						},
						'time' : {
							mask : '29:59'
						},
						'cc' : {
							mask : '9999 9999 9999 9999'
						},
						'integer' : {
							mask : '999.999.999.999',
							type : 'reverse'
						},
						'decimal' : {
							mask : '99,999.999.999.999',
							type : 'reverse',
							defaultValue : '000'
						},
						'decimal-us' : {
							mask : '99.999,999,999,999',
							type : 'reverse',
							defaultValue : '000'
						},
						'signed-decimal' : {
							mask : '99,999.999.999.999',
							type : 'reverse',
							defaultValue : '+000'
						},
						'signed-decimal-us' : {
							mask : '99,999.999.999.999',
							type : 'reverse',
							defaultValue : '+000'
						},
						'ano' : {
							mask : '9999'
						},
						'numeroContrato' : {
							mask : '999'
						},
						'valor' : {
							mask : '99999,99',
							type: 'reverse'
						},
						'valorTelefone' : {
							mask : '99,999',
							type : 'reverse'
						},
						'valorMonetario' : {
							mask : '99,999.999.999.999',
							type : 'reverse',
							defaultValue : '000'
						},
						'valorMonetarioMenor' : {
							mask : '99,9999',
							type : 'reverse',
							defaultValue : '000'
						},
						'valorNumerico' : {
							mask : '99,99' ,
							type : 'reverse' 
						},
						'valorTarifaTelefone' : {
							mask : '99999,9',
							type: 'reverse'
						},
						'ddd' : {
							mask: '999'
						},
						'telefone' : {
							mask: '9999-9999'
						},
						'limiteHoras' : {
							mask : '9999'
						},
						'numeroNotificacao' : {
							mask : '9999.99.99.9999'
						}
						
					},
					init : function() {
						if (!this.hasInit) {
							var b = this, i, keyRep = (k) ? this.iphoneKeyRepresentation
									: this.keyRepresentation;
							this.ignore = false;
							for (i = 0; i <= 9; i++)
								this.rules[i] = new RegExp('[0-' + i + ']');
							this.keyRep = keyRep;
							this.ignoreKeys = [];
							$.each(keyRep, function(a) {
								b.ignoreKeys.push(parseInt(a))
							});
							this.hasInit = true
						}
					},
					set : function(d, e) {
						var f = this, $el = $(d), mlStr = 'maxLength';
						e = e || {};
						
						this.init();
						return $el
								.each(function() {
									if (e.attr)
										f.options.attr = e.attr;
									var a = $(this), o = $.extend( {},
											f.options), attrValue = a
											.attr(o.attr), tmpMask = '';
									tmpMask = (typeof e == 'string') ? e
											: (attrValue != '') ? attrValue
													: null;
													
													
									
									o = $.extend(o, { nomeMascara: tmpMask } );		
									
									if (tmpMask)
										o.mask = tmpMask;
									if (f.masks[tmpMask])
									{
										o = $.extend(o, f.masks[tmpMask] );
									}
									if (typeof e == 'object'
											&& e.constructor != Array)
										o = $.extend(o, e);
									if ($.metadata)
										o = $.extend(o, a.metadata());
									if (o.mask != null) {
										if (a.data('mask'))
											f.unset(a);
										var b = o.defaultValue, reverse = (o.type == 'reverse'), fixedCharsRegG = new RegExp(
												o.fixedChars, 'g');
										if (o.maxLength == -1)
											o.maxLength = a.attr(mlStr);
										o = $
												.extend(
														{},
														o,
														{
															fixedCharsReg : new RegExp(
																	o.fixedChars),
															fixedCharsRegG : fixedCharsRegG,
															maskArray : o.mask
																	.split(''),
															maskNonFixedCharsArray : o.mask
																	.replace(
																			fixedCharsRegG,
																			'')
																	.split('')
														});
										if ((o.type == 'fixed' || reverse)
												&& o.setSize && !a.attr('size'))
											a.attr('size', o.mask.length);
										if (reverse && o.textAlign)
											a.css('text-align', 'left');
										if (this.value != '' || b != '') {
											var c = f
													.string(
															(this.value != '') ? this.value
																	: b, o);
											this.defaultValue = c;
											a.val(c)
										}
										if (o.type == 'infinite')
											o.type = 'repeat';
										a.data('mask', o);
										a.removeAttr(mlStr);
										a.bind('keydown.mask', {
											func : f._onKeyDown,
											thisObj : f
										}, f._onMask).bind('keypress.mask', {
											func : f._onKeyPress,
											thisObj : f
										}, f._onMask).bind('keyup.mask', {
											func : f._onKeyUp,
											thisObj : f
										}, f._onMask).bind('paste.mask', {
											func : f._onPaste,
											thisObj : f
										}, f._onMask).bind('focus.mask',
												f._onFocus).bind('blur.mask', {
											func : f._onBlur,
											thisObj : f
//										}, f._onMask)
//											Modificado
//										}, f._onMask).bind('change.mask', {
//											func : f._onChange,
//											thisObj : f
//										}, f._onMask)
										// Original
										 }, f._onMask).bind('change.mask',
										 f._onChange).bind(
										 'mouseover.mask', {
										 func : f._onMouse,
										 thisObj : f
										 }, f._onMask)
									}
								})
					},
					unset : function(c) {
						var d = $(c);
						return d.each(function() {
							var a = $(this);
							if (a.data('mask')) {
								var b = a.data('mask').maxLength;
								if (b != -1)
									a.attr('maxLength', b);
								a.unbind('.mask').removeData('mask')
							}
						})
					},
					string : function(a, b ) {
						this.init();
						var o = {};
						
						
					
						if( b.nomeMascara  == 'valorMonetarioMenor' )
						{
						 	a= parseFloat(a.replace( ',' , '.' ) ).toFixed( 2 );
						}
						
						
						if (typeof a != 'string')
							a = String(a);
						switch (typeof b) {
						case 'string':
							if (this.masks[b])
							{
							
								o = $.extend(o, this.masks[b]);
								}
							else
							{
							
								o.mask = b;
								}
							break;
						case 'object':
							o = b
						}
						if (!o.fixedChars)
							o.fixedChars = this.options.fixedChars;
						var c = new RegExp(o.fixedChars), fixedCharsRegG = new RegExp(
								o.fixedChars, 'g');
						if ((o.type == 'reverse') && o.defaultValue) {
							if (typeof this.signals[o.defaultValue.charAt(0)] != 'undefined') {
								var d = a.charAt(0);
								o.signal = (typeof this.signals[d] != 'undefined') ? this.signals[d]
										: this.signals[o.defaultValue.charAt(0)];
								o.defaultValue = o.defaultValue.substring(1)
							}
						}
						return this.__maskArray(a.split(''), o.mask.replace(
								fixedCharsRegG, '').split(''),
								o.mask.split(''), o.type, o.maxLength,
								o.defaultValue, c, o.signal)
					},
					_onFocus : function(e) {
						var a = $(this), dataObj = a.data('mask');
						dataObj.inputFocusValue = a.val();
						dataObj.changed = false;
						if (dataObj.selectCharsOnFocus)
							a.select()
					},
					_onBlur : function(e, o) {
						var a = $(this), dataObj = a.data('mask');
						var b = this.__maskArray(o.valueArray,
								o.data.maskNonFixedCharsArray,
								o.data.maskArray, o.data.type,
								o.data.maxLength, o.data.defaultValue,
								o.data.fixedCharsReg, o.data.signal);
						o.$this.val(b)
					},
					_onChange : function(e) {
						$(this).data('mask').changed = true
					},
					_onMask : function(e) {
						var a = e.data.thisObj, o = {};
						o._this = e.target;
						o.$this = $(o._this);
						if (o.$this.attr('readonly'))
							return true;
						o.data = o.$this.data('mask');
						o[o.data.type] = true;
						o.value = o.$this.val();
						o.nKey = a.__getKeyNumber(e);
						o.range = a.__getRange(o._this);
						o.valueArray = o.value.split('');
						return e.data.func.call(a, e, o)
					},
					_onKeyDown : function(e, o) {
						this.ignore = $.inArray(o.nKey, this.ignoreKeys) > -1
								|| e.ctrlKey || e.metaKey || e.altKey;
						if (this.ignore) {
							var a = this.keyRep[o.nKey];
							o.data.onValid.call(o._this, a ? a : '', o.nKey)
						}
						return k ? this._keyPress(e, o) : true
					},
					_onKeyUp : function(e, o) {
						if (o.nKey == 9 || o.nKey == 16)
							return true;
						if (o.data.type == 'repeat') {
							this.__autoTab(o);
							return true
						}
						return this._onPaste(e, o)
					},
					_onPaste : function(e, o) {
						if (o.reverse)
							this.__changeSignal(e.type, o);
						var a = this.__maskArray(o.valueArray,
								o.data.maskNonFixedCharsArray,
								o.data.maskArray, o.data.type,
								o.data.maxLength, o.data.defaultValue,
								o.data.fixedCharsReg, o.data.signal);
						o.$this.val(a);
						if (!o.reverse && o.data.defaultValue.length
								&& (o.range.start == o.range.end))
							this
									.__setRange(o._this, o.range.start,
											o.range.end);
						if (($.browser.msie || $.browser.safari) && !o.reverse)
							this
									.__setRange(o._this, o.range.start,
											o.range.end);
						if (this.ignore)
							return true;
						this.__autoTab(o);
						return true
					},
					_onMouse : function(e, o) {
						if (o.reverse)
							this.__changeSignal(e.type, o);
						var a = o.range.start, rawValue = o.value, maskArray = o.data.maskArray;
						if (o.reverse) {
							var b = rawValue.substr(0, a), valueEnd = rawValue
									.substr(o.range.end, rawValue.length);
							rawValue = b + valueEnd;
							if (o.data.signal && (a - o.data.signal.length > 0))
								a -= o.data.signal.length
						}
						var c = this.__maskArray(o.valueArray,
								o.data.maskNonFixedCharsArray,
								o.data.maskArray, o.data.type,
								o.data.maxLength, o.data.defaultValue,
								o.data.fixedCharsReg, o.data.signal);
						o.$this.val(c);
						if (this.ignore)
							return true;
						this.__autoTab(o);
						return (o.reverse) ? this._keyPressReverse(e, o)
								: (o.fixed) ? this._keyPressFixed(e, o) : true
					},
					_onKeyPress : function(e, o) {
						if (this.ignore)
							return true;
						if (o.reverse)
							this.__changeSignal(e.type, o);
						var c = String.fromCharCode(o.nKey), rangeStart = o.range.start, rawValue = o.value, maskArray = o.data.maskArray;
						if (o.reverse) {
							var a = rawValue.substr(0, rangeStart), valueEnd = rawValue
									.substr(o.range.end, rawValue.length);
							rawValue = a + c + valueEnd;
							if (o.data.signal
									&& (rangeStart - o.data.signal.length > 0))
								rangeStart -= o.data.signal.length
						}
						var b = rawValue.replace(o.data.fixedCharsRegG, '')
								.split(''), extraPos = this
								.__extraPositionsTill(rangeStart, maskArray,
										o.data.fixedCharsReg);
						o.rsEp = rangeStart + extraPos;
						if (o.repeat)
							o.rsEp = 0;
						if (!this.rules[maskArray[o.rsEp]]
								|| (o.data.maxLength != -1
										&& b.length >= o.data.maxLength && o.repeat)) {
							o.data.onOverflow.call(o._this, c, o.nKey);
							return false
						} else if (!this.rules[maskArray[o.rsEp]].test(c)) {
							o.data.onInvalid.call(o._this, c, o.nKey);
							return false
						} else
							o.data.onValid.call(o._this, c, o.nKey);
						var d = this.__maskArray(b,
								o.data.maskNonFixedCharsArray, maskArray,
								o.data.type, o.data.maxLength,
								o.data.defaultValue, o.data.fixedCharsReg,
								o.data.signal, extraPos);
						o.$this.val(d);
						return (o.reverse) ? this._keyPressReverse(e, o)
								: (o.fixed) ? this._keyPressFixed(e, o) : true
					},
					_keyPressFixed : function(e, o) {
						if (o.range.start == o.range.end) {
							if ((o.rsEp == 0 && o.value.length == 0)
									|| o.rsEp < o.value.length)
								this.__setRange(o._this, o.rsEp, o.rsEp + 1)
						} else
							this
									.__setRange(o._this, o.range.start,
											o.range.end);
						return true
					},
					_keyPressReverse : function(e, o) {
						if ($.browser.msie
								&& ((o.range.start == 0 && o.range.end == 0) || o.range.start != o.range.end)
								&& o.value.length != 0) {
							this.__setRange(o._this, o.value.length)
						}
						return false
					},
					__autoTab : function(o) {
						if (o.data.autoTab
								&& ((o.$this.val().length >= o.data.maskArray.length && !o.repeat) || (o.data.maxLength != -1
										&& o.valueArray.length >= o.data.maxLength && o.repeat))) {
							var a = this
									.__getNextInput(o._this, o.data.autoTab);
							if (a) {
								o.$this.trigger('blur');
								a.focus().select()
							}
						}
					},
					__changeSignal : function(a, o) {
						if (o.data.signal !== false) {
							var b = (a == 'paste') ? o.value.charAt(0) : String
									.fromCharCode(o.nKey);
							if (this.signals
									&& (typeof this.signals[b] != 'undefined')) {
								o.data.signal = this.signals[b]
							}
						}
					},
					__getKeyNumber : function(e) {
						return (e.charCode || e.keyCode || e.which)
					},
					__maskArray : function(a, b, c, d, e, f, g, h, i) {
						if (d == 'reverse')
							a.reverse();
						a = this.__removeInvalidChars(a, b, d == 'repeat'
								|| d == 'infinite');
						if (f)
							a = this.__applyDefaultValue.call(a, f);
						a = this.__applyMask(a, c, i, g);
						switch (d) {
						case 'reverse':
							a.reverse();
							return (h || '')
									+ a.join('').substring(a.length - c.length);
						case 'infinite':
						case 'repeat':
							var j = a.join('');
							return (e != -1 && a.length >= e) ? j.substring(0,
									e) : j;
						default:
							return a.join('').substring(0, c.length)
						}
						return ''
					},
					__applyDefaultValue : function(a) {
						var b = a.length, thisLen = this.length, i;
						for (i = thisLen - 1; i >= 0; i--) {
							if (this[i] == a.charAt(0))
								this.pop();
							else
								break
						}
						for (i = 0; i < b; i++)
							if (!this[i])
								this[i] = a.charAt(i);
						return this
					},
					__removeInvalidChars : function(a, b, c) {
						for ( var i = 0, y = 0; i < a.length; i++) {
							if (b[y] && this.rules[b[y]]
									&& !this.rules[b[y]].test(a[i])) {
								a.splice(i, 1);
								if (!c)
									y--;
								i--
							}
							if (!c)
								y++
						}
						return a
					},
					__applyMask : function(a, b, c, d) {
						if (typeof c == 'undefined')
							c = 0;
						for ( var i = 0; i < a.length + c; i++) {
							if (b[i] && d.test(b[i]))
								a.splice(i, 0, b[i])
						}
						return a
					},
					__extraPositionsTill : function(a, b, c) {
						var d = 0;
						while (c.test(b[a++])) {
							d++
						}
						return d
					},
					__getNextInput : function(a, b) {
						var c = a.form.elements, initialInputIndex = $.inArray(
								a, c) + 1, $input = null, i;
						for (i = initialInputIndex; i < c.length; i++) {
							$input = $(c[i]);
							if (this.__isNextInput($input, b))
								return $input
						}
						var d = document.forms, initialFormIndex = $.inArray(
								a.form, d) + 1, y, tmpFormEls = null;
						for (y = initialFormIndex; y < d.length; y++) {
							tmpFormEls = d[y].elements;
							for (i = 0; i < tmpFormEls.length; i++) {
								$input = $(tmpFormEls[i]);
								if (this.__isNextInput($input, b))
									return $input
							}
						}
						return null
					},
					__isNextInput : function(a, b) {
						var c = a.get(0);
						return c
								&& (c.offsetWidth > 0 || c.offsetHeight > 0)
								&& c.nodeName != 'FIELDSET'
								&& (b === true || (typeof b == 'string' && a
										.is(b)))
					},
					__setRange : function(a, b, c) {
						if (typeof c == 'undefined')
							c = b;
						if (a.setSelectionRange) {
							a.setSelectionRange(b, c)
						} else {
							var d = a.createTextRange();
							d.collapse();
							d.moveStart('character', b);
							d.moveEnd('character', c - b);
							d.select()
						}
					},
					__getRange : function(a) {
						if (!$.browser.msie)
							return {
								start : a.selectionStart,
								end : a.selectionEnd
							};
						var b = {
							start : 0,
							end : 0
						}, range = document.selection.createRange();
						b.start = 0 - range.duplicate().moveStart('character',
								-100000);
						b.end = b.start + range.text.length;
						return b
					},
					unmaskedVal : function(a) {
						return $(a).val().replace($.mask.fixedCharsRegG, '')
					}
				}
			});
	$.fn.extend( {
		setMask : function(a) {
			return $.mask.set(this, a)
		},
		unsetMask : function() {
			return $.mask.unset(this)
		},
		unmaskedVal : function() {
			return $.mask.unmaskedVal(this[0])
		}
	})
})(jQuery);

function maskTelefone(valor){
	if(valor.value.length<14){
		jQuery(valor).setMask('(99) 9999-9999');
	}else{
		jQuery(valor).setMask('(99) 99999-9999');
	}
}