 /*
 * @author Renan Vaz
 * @version 1.0
 * @example
 * $("element").focusInOut({
 *
 * 		textIn: 'texto inicial',
 *		textOut: 'texto com focus'
 *
 * });
 * @obs With no arguments, the default is above
 * @license free
 * @param text textIn, text textOut
 * @contribution Renan Vaz
 *
 */
function Verifica_CPF(CPF) {
	CPF = CPF.replace(/\D/g,"");
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" || CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" || CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" || CPF == "88888888888" || CPF == "99999999999" || CPF == "00000000191")
	return false;
	// Aqui começa a checagem do CPF
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
	
	// Desemembra o número do CPF na array DIGITO
	for (I=0; I<=8; I++) {
	  DIGITO[I] = CPF.substr( I, 1);
	}
	
	// Calcula o valor do 10º dígito da verificação
	POSICAO = 10;
	SOMA = 0;
	   for (I=0; I<=8; I++) {
		  SOMA = SOMA + DIGITO[I] * POSICAO;
		  POSICAO = POSICAO - 1;
	   }
	DIGITO[9] = SOMA % 11;
	   if (DIGITO[9] < 2) {
			DIGITO[9] = 0;
	}
	   else{
		   DIGITO[9] = 11 - DIGITO[9];
	}
	
	// Calcula o valor do 11º dígito da verificação
	POSICAO = 11;
	SOMA = 0;
	   for (I=0; I<=9; I++) {
		  SOMA = SOMA + DIGITO[I] * POSICAO;
		  POSICAO = POSICAO - 1;
	   }
	DIGITO[10] = SOMA % 11;
	   if (DIGITO[10] < 2) {
			DIGITO[10] = 0;
	   }
	   else {
			DIGITO[10] = 11 - DIGITO[10];
	   }
	
	// Verifica se os valores dos dígitos verificadores conferem
	DV = DIGITO[9] * 10 + DIGITO[10];
	   if (Number(DV) != Number(DV_INFORMADO)) {
		  return false;
	   }else return true;
}
function saudacao(){
	var data = new Date();
	hora = data.getHours();
	if(hora < 12){
		return 'Bom dia';
	}else if(hora < 18){
		return 'Boa tarde';
	}else return 'Boa noite';
}
function validaEmail(email){
	return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email);
}
function validaEmailList(email,separator){
	email = email || 'nada';
	var emails = email.split(separator);
	for (i in emails){
	if(!validaEmail($.trim(emails[i])))
	return false;
	}
	return true;
}
function validaEmailList2(email,separator){
	return /^([a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4})(, ?([a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}))*?$/.test(email);
}
function $r(id){
	return document.getElementById(id);
}
jQuery.fn.focusInOut = function(params) {
	var options = {
		
		textIn: '',
		textOut: ''

	}
	op = jQuery.extend(options, params);

   return this.each(function(){
		//initializing variables
		var $self = jQuery(this);
		 $self.attr('textIn',op.textIn);
		 $self.attr('textOut',op.textOut);
		 if($self.val()=='')
		 $self.val(op.textIn);
		 $self.focus(function (){ if(jQuery.trim($(this).val()) == jQuery.trim($(this).attr('textIn'))) $(this).val(jQuery.trim($(this).attr('textOut')))});
		 $self.blur(function (){ if(jQuery.trim($(this).val()) == jQuery.trim($(this).attr('textOut'))) $(this).val(jQuery.trim($(this).attr('textIn')))});
   });
};

/**
 * @author Renan Vaz
 * @version 1.0
 * @example
 * $("input[@type=checkbox]").check(); $("input[@type=radio]").uncheck();
 * 
 * @contribution Renan Vaz
 *
 */
jQuery.fn.extend({ 
	check: function() { 
	return this.each(function() { 
	this.checked = true; }); }, 
	uncheck: function() {
	return this.each(function() { 
	this.checked = false; }); } 
}); 
/**
 * @author Renan Vaz
 * @version 1.0
 * @example
 * $("input").countChars(40);
 * @obs With no arguments, the default is 30, the span have like id='id input'+limit
 * @license free
 * @param number p (max chars)
 * @contribution Renan Vaz
 *
 */
jQuery.fn.countChars = function(p) {
	var params = {
			limit: p
		}
	var options = {
			limit: 30
		}
		var fnCount = function($this){
				var tamanho = $this.value.length;
				var resto   = Number(jQuery($this).attr('MaxCh')) - tamanho;
				resto 		= resto > 0 ?resto : '0'; 
				var obj     = jQuery($this).attr('id')+'limit';
				jQuery('#'+obj).html(resto);
			};
		op = jQuery.extend(options, params);
   return this.each(function(){
		//initializing variables
		var $self   = jQuery(this);
		$self.attr('MaxCh',op.limit);
		$self.attr('maxlength',op.limit);
		fnCount(this);
	$self.keyup(function (){fnCount(this)});
	$self.blur(function (){fnCount(this)});
	$self.parents("form").each(function() {
		//Bind parent form submit
		$self.submit(function() {
			if($self.val()==text) {
				$self.val('');
			}
		});
	});
   });
};
jQuery.fn.extend({
  scrollTo : function(speed, easing) {
    return this.each(function() {
      var targetOffset = jQuery(this).offset().top;
      jQuery('html,body').animate({scrollTop: targetOffset}, speed, easing);
    });
  }
});

/**
 * @author Renan Vaz
 * @version 1.0
 * @example
 * $("input").countChars(40);
 * @obs With no arguments, the default is 30, the span have like id='id input'+limit
 * @license free
 * @param borderColor String (hex) e.g default is '#c00'
 * @param borderOut   String (hex) e.g default is '2px'
 * @param borderOver  String (hex) e.g default is '4px'
 * @param clear		  String (hex) e.g default is 'both' clear float
 * @contribution Renan Vaz
 * usage:
 * $(function(){
 * $('a').innerBorder({clear:'right'});
 * });
 */

jQuery.fn.innerBorder = function(params) {
		var options = {
			borderColor: '#c00',
			borderOut: '2px',
			borderOver: '4px',
			clear: 'both'
		}
		op = jQuery.extend(options, params);
	 return this.each(function() {
		var $self = jQuery(this);
		$self.attr('innerBorder','yes');
		jQuery(this).css({float: 'left', overflow:'hidden',clear:op.clear});
		jQuery('[innerBorder=yes]').hover(function(){jQuery('img',this).css('margin','-'+op.borderOver);jQuery(this).css({border:op.borderOver+' solid '+op.borderColor})},function(){jQuery('img',this).css('margin','-'+op.borderOut);jQuery(this).css({border:op.borderOut+' solid '+op.borderColor})});
		jQuery('img',this).css('margin','-'+op.borderOut);
		jQuery(this).css({border:op.borderOut+' solid '+op.borderColor})
	});
}

jQuery.fn.isChrome = function(){
	return  navigator.userAgent.toLowerCase().indexOf("chrome") > -1;
}

//-------------------------------------------------------------------------
//@param font = font path  ex: fonts/arial.swf
//@param css array [ font-style:italic; display: inline;] apenas adicionar mais atributos a classe principal 
//@param cssAdd array [em { font-style:italic; display: inline;}] adicionar novas classes
// depende do plugin flash do jquery
jQuery.fn.sifrRvaz = function(params) {
	var options = {
			css 	: [],
			cssAdd  : [],
			font 	: null,
			debug	:false
	}
	op = jQuery.extend(options, params);
	if(op.debug)
	jQuery('body').append('<div id="debugSifrRvaz"></div>');

	return this.each(function() {
		var $self 			= jQuery(this);
		var cssDefault 		= new String();
		var color 			= 'color:'			+ toHex($self.css('color'))		+';';
		var size  			= 'font-size:'		+ ($self.css('font-size'))		+';';
		var font_weight 	= 'font-weight:'	+ ($self.css('font-weight'))	+';';
		var font_style 		= 'font-style:'		+ ($self.css('font-style'))		+';';
		var line_height 	= 'line-height:'	+ ($self.css('line-height'))	+';';
		var margin_top 		= 'margin-top:'		+ ($self.css('margin-top'))		+';';
		var margin_right 	= 'margin-right:'	+ ($self.css('margin-right'))	+';';
		var margin_bottom 	= 'margin-bottom:'	+ ($self.css('margin-bottom'))	+';';
		var margin_left		= 'margin-left:'	+ ($self.css('margin-left'))	+';';
		var padding_top 	= 'padding-top:'	+ ($self.css('padding-top'))	+';';
		var padding_right 	= 'padding-right:'	+ ($self.css('padding-right'))	+';';
		var padding_bottom 	= 'padding-bottom:'	+ ($self.css('padding-bottom'))	+';';
		var padding_left	= 'padding-left:'	+ ($self.css('padding-left'))	+';';
		var index = -1;
		for(i = 0; i<op.css.length; i++){
			var str = op.css[i];
			if(str.indexOf('font-size') > -1){
				index = i;
				break;
			}
		}
		if(index > -1 )
		$self.css('font-size',op.css[index].replace(/\D/g,'')+'px');
		var height			= Number($self.css('font-size').replace(/\D/g,''));
		var margin 			= margin_top+'	'+margin_right+'	'+margin_bottom+'	'+margin_left;
		var padding 		= padding_top+'	'+padding_right+'	'+padding_bottom+'	'+padding_left;//'+margin+' '+padding+'
		cssDefault 			= '* { '+color+' '+size+' '+font_weight+' '+font_style+' '+line_height+'  '+(op.css.join(' '))+' }';
		if(op.debug)
		jQuery('#debugSifrRvaz').html(jQuery('#debugSifrRvaz').html()+'('+this.id+')<div>'+cssDefault+'</div>');
		$self.flash(
			{ 
				src: op.font || 'default.swf', 
				flashvars: { 
					css: cssDefault + 'em { font-style:italic; display: inline;} strong { font-weight:bold; display: inline; } ' + (op.cssAdd.join(' '))
				}
			},
			{ version: 8 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = jQuery(this).html();
				jQuery(this).html('<div>'+this.innerHTML+'</div>');
				var $alt = jQuery(this.firstChild);
				htmlOptions.height = ($alt.height() == 0 ? $alt.css('font-size'):$alt.height()) +15;
				htmlOptions.width  = $alt.width();
				htmlOptions.scale  = 'noscale';
				htmlOptions.wmode  = 'transparent';
				$alt.addClass('alt');
				jQuery(this)
					.addClass('flash-replaced')
					.prepend(jQuery.fn.flash.transform(htmlOptions));						
			}
   		 );
	});
};

/////////////////////////////////////////////////////////////////////
var toHex = function (c) {
				var h = function (n) {
					if (n === 0 || isNaN(n)) {
						return '00';
					}
					n = Math.round(Math.min(Math.max(0, n), 255));
					return '0123456789ABCDEF'.charAt((n - n % 16) / 16) + '0123456789ABCDEF'.charAt(n % 16);
				};
				c = (c) ? c.replace(/rgb|\(|\)|#$/g, '') : false;
				if (!c) {
					return false;
				}
				if (c.indexOf(',') > -1) {
					c = c.split(', ');
					return '#' + h(c[0]) + h(c[1]) + h(c[2]);
				}
				if (c.search('#') > -1 && c.length <= 4) {
					c = c.split('');
					return '#' + c[1] + c[1] + c[2] + c[2] + c[3] + c[3];
				}
				return c;
		}

$.extend({
  	formatDate: function(params){
		var data = params.date.split('/');
		if(params.pt)
		return data[0]+'/'+data[1]+'/'+data[2];
		else
		return data[2]+'/'+data[1]+'/'+data[0];
	}
 });
$.extend({

ie6CSSHover:function(){   
	if($.browser.msie && /6.0/.test(navigator.userAgent)){			
		var len=document.styleSheets.length;				
		for(z=0;z<len;z++){			
			var sheet=document.styleSheets[z];					
			var css =sheet.cssText;					
			var r=new RegExp(/[a-zA-Z0-9\.-_].*:hover\s?\{.[^\}]*\}/gi);					
			var m=css.match(r);					
			if(m!=null && m.length>0){					
				for(i=0;i<m.length;i++){   								
					var c=m[i].match(/\{(.[^\}]*)}/);							
					if(c[1]){							
						var seljq=m[i].replace(':hover','').replace(c[0],'');							
						var selcss=m[i].replace(':hover','.hover').replace(c[0],'');								
						var rule=c[1].replace(/^\s|\t|\s$|\r|\n/g,'');								
						document.styleSheets[z].addRule(selcss,rule);								
						var grp=$(seljq);								
						$(seljq).hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});							
					}					
				}				
			}   		
		}   	
} 
}

})(jQuery);
$.fn.charCounter = function (max, settings) {
		max = max || 100;
		settings = $.extend({
			container: "<span></span>",
			classname: "charcounter",
			format: "%1",
			pulse: false,
			delay: 0
		}, settings);
		var p, timeout;
		
		function count(el, container) {
			el = $(el);
			if (el.val().length > max) {
			    el.val(el.val().substring(0, max));
			    if (settings.pulse && !p) {
			    	pulse(container, true);
			    };
			};
			if (settings.delay > 0) {
				if (timeout) {
					window.clearTimeout(timeout);
				}
				timeout = window.setTimeout(function () {
					container.html(settings.format.replace(/%1/, (max - el.val().length)));
				}, settings.delay);
			} else {
				container.html(settings.format.replace(/%1/, (max - el.val().length)));
			}
		};
		
		function pulse(el, again) {
			if (p) {
				window.clearTimeout(p);
				p = null;
			};
			el.animate({ opacity: 0.1 }, 100, function () {
				$(this).animate({ opacity: 1.0 }, 100);
			});
			if (again) {
				p = window.setTimeout(function () { pulse(el) }, 200);
			};
		};
		
		return this.each(function () {
			var container = (!settings.container.match(/^<.+>$/)) 
				? $(settings.container) 
				: $(settings.container)
					.insertAfter(this)
					.addClass(settings.classname);
			$(this)
				.bind("keydown", function () { count(this, container); })
				.bind("keypress", function () { count(this, container); })
				.bind("keyup", function () { count(this, container); })
				.bind("focus", function () { count(this, container); })
				.bind("mouseover", function () { count(this, container); })
				.bind("mouseout", function () { count(this, container); })
				.bind("paste", function () { 
					var me = this;
					setTimeout(function () { count(me, container); }, 10);
				});
			if (this.addEventListener) {
				this.addEventListener('input', function () { count(this, container); }, false);
			};
			count(this, container);
		});
	};
    
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

