// JavaScript Document
/*FUNÇÃO DE MÁSCARAS GERAIS */
/*Descrição.: formata um campo do formulário de
acordo com a máscara informada...
Parâmetros: - objForm (o Objeto Form)
- strField (string contendo o nome do textbox)

- sMask (mascara que define o formato que o dado será apresentado, usando o algarismo "9" para definir números e o símbolo "!" para qualquer caracter... 
- evtKeyPress (evento)
Uso.......: <input type="textbox" name="xxx" onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
- Observação: As máscaras podem ser representadas como os exemplos abaixo:
CBO -> 9999-99
CEP -> 99.999-999
CPF -> 999.999.999-99
CNPJ -> 99.999.999/9999-99
Data -> 99/99/9999
Telefone -> (99) 9999-9999
Processo -> 99.999999999/999-99
C/C -> 999999-!
* E por aí vai... ***/

function txtBoxFormat(objForm, strField, 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 = objForm[strField].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( " ", "" );
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++;
}

objForm[strField].value = sCod;
if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas números...
    return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
    return true;
}
} else {
    return true;
}
}

/*AUTO TAB - ao prencher o campo, automaticamente manda o foco para o próximo!*/
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }

function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
        found = true;
    else
        index++;
        return found;
    }

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
    return true;
}

/*LIMITAR CARACTERES*/
function limitaText( p_objCampo, p_permitido ) {

   if (  p_objCampo.value.length > p_permitido ) {
      alert(  "A quantidade de caracteres digitados ultrapassou "+p_permitido+". Os caracteres excedidos serão retirados.");
      p_objCampo.value =  p_objCampo.value.substr( 0, p_permitido )

      if ( p_objCampo.value.length > p_permitido )  
         p_objCampo.value =  p_objCampo.value.substr( 0, p_permitido-1 )
   }
}
////USAR onKeyUp="limitaText( this, 100 )" onKeyDown="limitaText( this, 100 );"

/*****
ABRE POPUP CENTRALIZADA NA PÁGINA 
*****/
var win = null;
function NewWindow(mypage,myname,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(mypage,myname,settings)
}
//chamar assim: javascript:"NewWindow('arquivo.php','','500','510','no')"


/*SOMENTE NÚMEROS*/
//Verifica se é um número
function SoNumero(txtAtual)
{
    if(isNaN(txtAtual.value))
    {
        alert("Só pode ser inserido números!");
        txtAtual.select();
        txtAtual.focus();
    }
}

function Enviar(Botao) {
if (Botao==1) {
document.getElementById("form_informativo").action="informativo.php";
} else {
document.getElementById("form_informativo").action="informativo_excluir.php";
}
document.getElementById("form_informativo").submit;}

/*Abrir janela extrato TEMPORÁRIO*/
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Submeter(){
with (document.inicial) {
method = "POST";
var x = document.inicial.usuario.value;
if (isNaN(x)){ 
action="http://www.asufepar.org.br/admin/operador_logar.php";
jan="http://www.asufepar.org.br/admin/operador_logar.php";
} else {
action="http://www.asufepar.org.br/admin/extrato/login.php";
jan="http://www.asufepar.org.br/admin/extrato/login.php"; 
target="_blank";
}
submit();
}
return true;
}

function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "meu_comentario";
var countBody = opt_countBody ? opt_countBody : "countBody";
var maxSize = opt_maxSize ? opt_maxSize : 1024;

var field = document.getElementById(countedTextBox);

if (field && field.value.length >= maxSize) {
field.value = field.value.substring(0, maxSize);
}
var txtField = document.getElementById(countBody);
if (txtField) {
txtField.innerHTML = field.value.length;
}
}

function Enquete(){
with (document.form_enquete) {
method = "POST";
action="http://www.asufepar.org.br/enquete_votacao.php";
jan=window.open('http://www.asufepar.org.br/enquete_votacao.php','enquete','width=400,height=300,scrollbar=yes');
target='enquete';
submit();
}
return true;
}

function imagens(qual){
var img = document.getElementById("imagem");
img.src = qual;
}

/*SLIDESHOW
<!-- Original:  CodeLifter.com (support@codelifter.com) -->
<!-- Web Site:  http://www.codelifter.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin*/
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 4000;
// Duration of crossfade (seconds)
var crossFadeDuration = 4;
// Specify the image files
var Pic = new Array();
// to add more images, just continue
// the pattern, adding to the array below
Pic[0] = 'imagens/animacao/vista_aerea.jpg'
Pic[1] = 'imagens/animacao/piscinas_externas.jpg'
Pic[2] = 'imagens/animacao/sede_nova.jpg'
Pic[3] = 'imagens/animacao/hidro.jpg'
Pic[4] = 'imagens/animacao/salao_de_festas.jpg'
Pic[5] = 'imagens/animacao/academia.jpg'
Pic[6] = 'imagens/animacao/sede_central.jpg'
Pic[7] = 'imagens/animacao/atividades_piscina_interna.jpg'

// do not edit anything below this line
var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
function runSlideShow() {
if (document.all) {
document.images.SlideShow.style.filter="blendTrans(duration=2)";
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply();
}
document.images.SlideShow.src = preLoad[j].src;
if (document.all) {
document.images.SlideShow.filters.blendTrans.Play();
}
j = j + 1;
if (j > (p - 1)) j = 0;
t = setTimeout('runSlideShow()', slideShowSpeed);
}
//  End -->


/*resolução de video*/
function detect(){
if(screen.width<1280||screen.height<1024){
location.href('highres.html');
}else{
location.href('lowres.html');
}

}
