//Conversao de float para monetário
function floattomoney(valor){
  var novo = String(valor);
  var partes = novo.split(".");
  if(partes[1]){
    if(partes[1].length<2){
      partes[1] = partes[1]+"00";
    }
  }else{
    partes[1] = "00";
  }
  partes[1] = partes[1].substr(0,2);
  novo = partes[0]+","+partes[1];
  return novo;
}

//Conversão de monetário para float
function moneytofloat(valor){
  var partes = valor.replace(/\,/,".");
  return parseFloat(partes);
}

//Cidade por estado por país
function ajaxestados(id,idselect){
  if(id && id!=0){
    $("#estado").empty();
    $("#estado").load("ajaxsources/estados.php?id="+id+"&sele="+idselect);
  }
}
function ajaxestados_uf(id,idselect){
  if(id && id!=0){
    $("#estado").empty();
    $("#estado").load("ajaxsources/estados.php?id="+id+"&sele="+idselect);
  }
}
function ajaxcidades(id,idselect){
  if(id && id!=0){
    $("#cidade").empty();
    $("#cidade").load("ajaxsources/cidades.php?id="+id+"&sele="+idselect);
  }
}

//Mascarador
//Exemplo para cep: onkeypress="return formato(event,this,'#####-###');"
function formato(e,src,mask) {
   if(window.event) {
     _TXT = e.keyCode;
   }else if(e.which) {
     _TXT = e.which;
   }
   if(_TXT > 47 && _TXT < 58 && src.value.length<mask.length) {
     var i = src.value.length;
     var saida = mask.substring(0,1);
     var texto = mask.substring(i)
     if (texto.substring(0,1) != saida) {
       src.value += texto.substring(0,1);
     }
     return true;
   } else {
     if (_TXT != 8) {
       return false;
     }else{
       return true;
     }
   }
}