//MÁSCARA DE VALORES
function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); }
      else { // qualquer caracter...
        return true;
      }
    }
    else {
      return true;
    }
  }
//UTLIZANDO A FUNCTION
//onkeypress="return txtBoxFormat(this, '99.999.999/9999-999', event);" maxlength="18"

//FUNÇÃO PARA VALIDAR FORMULÁRIO
function ValidaForm(theForm){

if (theForm.nome.value == ""){
    alert("Por favor, informe seu nome.");
    theForm.nome.focus();
    return (false);
  }
if (theForm.dia.value == ""){
    alert("Por favor, informe o dia de seu nascimento.");
    theForm.dia.focus();
    return (false);
  }
if (theForm.mes.value == ""){
    alert("Por favor, informe o mês de seu nascimento.");
    theForm.mes.focus();
    return (false);
  }
if (theForm.ano.value == ""){
    alert("Por favor, informe o ano de seu nascimento.");
    theForm.ano.focus();
    return (false);
  }
if (theForm.rg.value == "")
  {
    alert("Por favor, informe seu RG.");
    theForm.rg.focus();
    return (false);
  }
if (theForm.cpf.value == "")
  {
    alert("Por favor, informe seu CPF.");
    theForm.cpf.focus();
    return (false);
  }
if (theForm.endereco.value == "")
  {
    alert("Por favor, informe seu endereco.");
    theForm.endereco.focus();
    return (false);
  }
if (theForm.bairro.value == "")
  {
    alert("Por favor, informe o bairro.");
    theForm.bairro.focus();
    return (false);
  }
if (theForm.cidade.value == "")
  {
    alert("Por favor, informe sua cidade.");
    theForm.cidade.focus();
    return (false);
  }
if (theForm.estado.value == "")
  {
    alert("Por favor, informe seu estado.");
    theForm.estado.focus();
    return (false);
  }
if (theForm.telefone.value == "")
  {
    alert("Por favor, informe seu telefone.");
    theForm.telefone.focus();
    return (false);
  }
if (theForm.email.value == "")
  {
    alert("Por favor, informe seu email.");
    theForm.email.focus();
    return (false);
  }

var bOption=false;
//validar os options custo
bOption=validaOption(theForm.escolaridade);
if (bOption==false) return false; //c for falso, sai da validação

//validar os options caract
bOption=validaOption(theForm.experiencia);
if (bOption==false) return false; //c for falso, sai da validação

//retornar valor true para o formulario
return true; 

}

function validaOption(obj){
totOp=obj.length;

var i=0, totsel=0;

for (i=0;i<totOp;i++)
{
  if (obj[i].checked==false)
  totsel+=1;
}

if (totsel==totOp)
{
  alert("Selecione uma opção.");
  return false;
}
else
  return true;
}

//ABRIR POP CENTRALIZADO
var win = null;
function NovaJanela(pagina,nome,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	win = window.open(pagina,nome,settings);
}
