// JavaScript Document
function focusInput(defaultText, inputElement) {
	if (inputElement.value==defaultText) {
		inputElement.value = '';
	}
}
function blurInput(defaultText, inputElement) {
	if (inputElement.value.length<1) {
		inputElement.value = defaultText;
	}
}
//mascara

function mascara(src, mascara) {
	var campo = src.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	if(texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}

   function NovaMascara(o,f){
       v_obj=o
       v_fun=f
       setTimeout("execmascara()",1)
   }
   
   /*Função que Executa os objetos*/
   function execmascara(){
       v_obj.value=v_fun(v_obj.value)
   }
   
   /*Função que Determina as expressões regulares dos objetos*/
   function leech(v){
       v=v.replace(/o/gi,"0")
       v=v.replace(/i/gi,"1")
       v=v.replace(/z/gi,"2")
       v=v.replace(/e/gi,"3")
       v=v.replace(/a/gi,"4")
       v=v.replace(/s/gi,"5")
       v=v.replace(/t/gi,"7")
       return v
   }
   
 
   /*Função que padroniza telefone (11) 4184-1241*/
   function Telefone(v){
       v=v.replace(/\D/g,"")                 
       v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
       v=v.replace(/(\d{4})(\d)/,"$1-$2")    
       return v
   }


//ajax form
$(document).ready(function() {
   //when submit form
   $(".ajax_form").submit(function() {
	   // here we show "working" on div#result
	   $(this).ajaxStart(function() {
		   $("#resultado").text("processando...").show();
	   });
	   // options
	   var options = {
		   target: "#resultado", // our hidden div#result
		   url: "ajax_form.php", // page that will send the passwoar
		   type: "post", // method (post ou get)
		   // if success
		   success: function(result) {
			   // show teh result
			   $("#resultado").html(result).show();
		   }
	   }
	  
	   // send data with options
	   $(this).ajaxSubmit(options);
	   // Who will send data is Ajax, not the form...
	   return false;
   });

});
   /*Função que padroniza valor monétario*/
    function Valor(v){
        v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
        v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2");
        //v=v.replace(/(\d{3})(\d)/g,"$1,$2")
        v=v.replace(/(\d)(\d{3})$/,"$1.$2") //Coloca ponto antes dos 2 últimos digitos
        return v
    }

	// show/hide div.mais (+ no topo do site)
	$(function(){
		$('.mais').toggle(function(){
			$('div#miaswiring').show("slow");
		},
		function(){
			$('div#miaswiring').hide("slow")
		});
	});
