// JavaScript Document

function EnvPres(formulario){
	emailenvia = prompt("Digite o e-mail de quem deseja presentear","");
	if(emailenvia==""){
	return false;	
	}else{
	
	$("#"+formulario+" #email").attr('value',emailenvia);
	$("#"+formulario).submit();
	
	}
}

function MostraDiv(divalvo){ $(document).ready(function(){ $("#"+divalvo).slideToggle(); }); 
}

function AbreUnsubscr(){
var emailalvo = prompt("Insira seu e-mail no campo abaixo:","");
if(emailalvo==""){
}else{
document.location.href="?pagina=unsubscribe&mailalvo="+emailalvo;
}
}

function EscondeDiv(divalvo){ //$(document).ready(function(){ $("#"+divalvo).hide('slow'); }); 
$(document).ready(function(){ $("#"+divalvo).slideUp(); }); }

function Formatadata(Campo, teclapres){
var tecla = teclapres.keyCode; var vr = new String(Campo.value);
vr = vr.replace("/", ""); vr = vr.replace("/", ""); vr = vr.replace("/", ""); tam = vr.length + 1;
if (tecla != 8 && tecla != 8){
if (tam > 0 && tam < 2)
Campo.value = vr.substr(0, 2);
if (tam > 2 && tam < 4)
Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2);
if (tam > 4 && tam < 7)
Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 7);
}
}

function SubmitChat(event){ var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13){ document.chat.submit(); }else{ return true; }}

	
//-----------
function getEndereco(){
if($.trim($("#cep").val()) != ""){  
$.getScript("http://cep.republicavirtual.com.br/web_cep.php?formato=javascript&cep="+$("#cep").val(), function(){  
if(resultadoCEP["resultado"]){  
$("#endereco").val(unescape(resultadoCEP["logradouro"]));
$("#bairro").val(unescape(resultadoCEP["bairro"]));  
$("#cidade").val(unescape(resultadoCEP["cidade"]));  
$("#estado").val(unescape(resultadoCEP["uf"]));  
}else{  
alert("Endereço não encontrado");  
}});}}
//----------

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}
//----------------
function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1)$2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function hora(v){
 v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"$1:$2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{2})(\d)/,"$1:$2")    //Coloca hífen entre o quarto e o quinto dígitos
	return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function ValidaEmail(email){
          er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
          
          if(er.exec(email))
                {
                  
				  $("#email").css("border","1px #BED553 solid");
				  $("#ok").fadeIn(800);
                
				} else {
                
				$("#email").css("border","1px #c00 solid");
				  $("#ok").fadeOut(800);
                
				}
        }
		
		
		function ValidaEmailLogin(email){
          er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
          
          if(er.exec(email))
                {
                  
				  $("#emailz").css("border","1px #BED553 solid");
				  $("#okz").fadeIn(800);
                
				} else {
                
				$("#emailz").css("border","1px #c00 solid");
				  $("#okz").fadeOut(800);
                
				}
        }
		
		
		function number_format(number, decimals, dec_point, thousands_sep) {
  // Formats a number with grouped thousands  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/number_format    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');    // *    returns 13: '100 050.00'
    number = (number+'').replace(',', '').replace(' ', '');
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }    return s.join(dec);
}


function Formatadata(Campo, teclapres){
var tecla = teclapres.keyCode; var vr = new String(Campo.value);
vr = vr.replace("/", ""); vr = vr.replace("/", ""); vr = vr.replace("/", ""); tam = vr.length + 1;
if (tecla != 8 && tecla != 8){
if (tam > 0 && tam < 2)
Campo.value = vr.substr(0, 2);
if (tam > 2 && tam < 4)
Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2);
if (tam > 4 && tam < 7)
Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 7);
}
}


function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789';
var aux = aux2 = ''; var whichCode = (window.Event) ? e.which : e.keyCode;    
// 13=enter, 8=backspace as demais retornam 0(zero)
// whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
return true;
key = String.fromCharCode(whichCode); // Valor para o código da Chave
if (strCheck.indexOf(key) == -1) 
return false; // Chave inválida
len = objTextBox.value.length;
for(i = 0; i < len; i++)
if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
break; aux = '';
for(; i < len; i++)
if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
aux += objTextBox.value.charAt(i); aux += key; len = aux.length;
if (len == 0) 
objTextBox.value = '';
if (len == 1) 
objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
if (len == 2) 
objTextBox.value = '0'+ SeparadorDecimal + aux;
if (len > 2){
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--){
if (j == 3){
aux2 += SeparadorMilesimo; j = 0;
}
aux2 += aux.charAt(i); j++;
}
objTextBox.value = ''; len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
objTextBox.value += aux2.charAt(i); objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len); } return false; }



function Alterna(divalvo){ $(document).ready(function(){ $("#"+divalvo).slideToggle(); }); }
