window.onDomReady = DomReady;
function DomReady(fn){
	if(document.addEventListener)
		document.addEventListener("DOMContentLoaded", fn, false);
	else
		document.onreadystatechange = function(){readyState(fn)}
}
function readyState(fn){
	if(document.readyState == "interactive") fn();
}


function clearText(field) {
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}

var newCaptcha = function(){
thesrc = document.getElementById("captcha").src;
thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
document.getElementById("captcha").src = thesrc+"?"+Math.round(Math.random()*100000);
};

function kH(e) {
var pK = e ? e.which : window.event.keyCode;
return pK != 13;
}

function contarCaracteres(entrada, saida, texto, chars) {
var entradaObj = document.getElementById(entrada); var saidaObj = document.getElementById(saida);
var tam = chars - entradaObj.value.length;
if(tam <= 0) { tam = 0;
texto = '<span class="disable"> '+texto+' </span>';
entradaObj.value = entradaObj.value.substr(0,chars); }
saidaObj.innerHTML = texto.replace("{CHAR}",tam);
}

function zoomText(acao,el){
obj=document.getElementById(el);	
if (obj.style.fontSize=="")	obj.style.fontSize="13px";
atual=parseInt(obj.style.fontSize);
inc=2; maxVal = 19; minVal = 9;
if(acao=="reestablecer"){ obj.style.fontSize="1em" }	
if(acao=="aumentar"){ val=atual+inc; if(val <= maxVal) obj.style.fontSize=val+"px" }	
if(acao=="diminuir"){ val=atual-inc; if(val >= minVal) obj.style.fontSize=val+"px"; }
} 

function GeraSWF(arquivo,largura,altura,id,transp){
var incTransp = '';
document.writeln('<object align="middle" id="globalnav-object" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="'+id+'" name="'+id+'">');
if(transp == "yes"){ document.writeln('<param name="wmode" value="transparent" />'); incTransp = 'wmode="transparent"'; }
document.writeln('<param name="allowScriptAccess" value="always" />');
document.writeln('<param name="quality" value="high" />');
document.writeln('<param name="scaleMode" value="noScale" />');
document.writeln('<param name="menu" value="false" />');
document.writeln('<param name="movie" value="'+arquivo+'" />');
document.writeln('<embed id="globalnav-embed" src="'+arquivo+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="loc=en_US&htmlApp=false&gatewayURL=gwurl" menu="false" align="middle" quality="high" allowscriptacess="always" scale="noscale" id="'+id+'" width="'+largura+'" height="'+altura+'" '+incTransp+'></embed>');
document.writeln('</object>');
}

function hideLayer(obj, timeOut){ setTimeout("showHideLayers('"+obj+"','','hide')", timeOut); }

var flg1 = true; var flg2 = true; var txtorig1; var txtorig2;

function inn(txt,i) {
if (eval('flg'+i)){ eval('txtorig'+i+'=txt.value;'); eval('flg'+i+'=false;');}	
if (txt.value == eval('txtorig'+i)) txt.value = '';
}

function out(txt,i) { if (txt.value == '') txt.value = eval('txtorig'+i); }

function newWindow(mypage, w, h, scroll) {
var winl = (screen.width - w) / 2; var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',status=yes, resizable=false';
win = window.open(mypage, '', winprops);
if (parseInt(navigator.appVersion) >= 4) win.window.focus();
}

function MM_changeProp(objName,x,theProp,theValue) {
var obj = MM_findObj(objName);
if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
if (theValue == true || theValue == false) eval("obj."+theProp+"="+theValue);
else eval("obj."+theProp+"='"+theValue+"'");}
}

function MM_findObj(n, d) {
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenu(targ,selObj,restore){
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

function showHideLayers() {
var i,p,v,obj,args=showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) 
if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v}
obj.visibility=v;}
}

function pad(number, length)
{
  var str = '' + number;

  while (str.length < length)
  {
      str = '0' + str;
  }

  return str;
}

function mascaraSimples(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execMascaraSimples()",1)
}
function execMascaraSimples(){
	v_obj.value=v_fun(v_obj.value)
}
function soNumeros(v)
{
	v=v.replace(/\D/g,"");
	return v;
}

/*
	PLUGINS
*/

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
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;
	}
});


(function($) {

  $.fn.example = function(text, args) {

    /* Merge the arguments and given example text into one options object. */
    var options = $.extend({}, args, {example: text});

    return this.each(function() {
      /* Reduce method calls by saving the current jQuery object. */
      var input = $(this);

      input.data('example', options.example);
      
      if (input.val() == '')
      {
        input.attr('value', options.example);
      }

      input.bind('focus.examplePlugin', function() {
        if (input.data('example') == $(this).val()) {
          $(this).val('');
        }
      });

      /* Make the example text reappear if the input is blank on blurring. */
      input.bind('blur.examplePlugin', function() {
        if ($(this).val() == '') {
          $(this).val(input.data('example'));
        }
      });
      
      input.parents('form').one('submit.examplePlugin', function() {
        var inputs = $(this).find(':input');
        
        $(this).find('input[type=text], textarea').each(function(i) {
          if ($(this).val() == $(this).data('example'))
          {
            $(this).val('');
          }
        })
      });
    });
}})(jQuery);