//========================================================
//VALIDAÇÃO DE FORMULÁRIO
//========================================================
//--------------------------------------------------------
//Formatação e validação de CNPJ
//Colocar onKeyUp="cnpjnumber(this)" no campo do formulário
//Formatar o campo com 18 caracteres
//Mesclar esta função com a função com a formatação de
//campo somente numérico
//--------------------------------------------------------
function cnpjnumber(elemento){
var cnpjnumber
if (elemento.value.length > 0 )
{
if (elemento.value.length == 2)
{
cnpjnumber = elemento.value;
elemento.value = cnpjnumber + '.';
elemento.focus();
}
if (elemento.value.length == 6)
{
cnpjnumber = elemento.value;
elemento.value = cnpjnumber + '.';
elemento.focus();
}
if (elemento.value.length == 10)
{
cnpjnumber = elemento.value;
elemento.value = cnpjnumber + '/';
elemento.focus();
}
if (elemento.value.length == 15)
{
cnpjnumber = elemento.value;
elemento.value = cnpjnumber + '-';
elemento.focus();
}
}
return 0;
}
//--------------------------------------------------------
//Formatação e validação de CPF
//Colocar onKeyUp="cpfnumber(this)" no campo do formulário
//Formatar o campo com 14 caracteres
//Mesclar esta função com a função com a formatação de
//campo somente numérico
//--------------------------------------------------------
function cpfnumber(elemento){
var cpfnumber
if (elemento.value.length > 0 )
{
if (elemento.value.length == 3)
{
cpfnumber = elemento.value;
elemento.value = cpfnumber + '.';
elemento.focus();
}
if (elemento.value.length == 7)
{
cpfnumber = elemento.value;
elemento.value = cpfnumber + '.';
elemento.focus();
}
if (elemento.value.length == 11)
{
cpfnumber = elemento.value;
elemento.value = cpfnumber + '-';
elemento.focus();
}
}
return 0;
}
//--------------------------------------------------------
//Formatação e validação de número de telefone
//Colocar onKeyUp="tel(this)" no campo do formulário
//Formatar o campo com 14 caracteres
//Mesclar esta função com a função com a formatação de
//campo somente numérico
//--------------------------------------------------------
function tel(elemento){
var telefone
if (elemento.value.length > 0 )
{
if (elemento.value.length == 1)
{
telefone = elemento.value;
elemento.value = '(' + telefone;
elemento.focus();
}
if (elemento.value.length == 3)
{
telefone = elemento.value;
elemento.value = telefone + ') ';
elemento.focus();
}
if (elemento.value.length == 9)
{
telefone = elemento.value;
elemento.value = telefone + '-';
elemento.focus();
}
}
return 0;
}
//--------------------------------------------------------
//Formatação e validação de datas
//Colocar onKeyUp="data(this)" no campo do formulário
//Formatar o campo com 10 Caracteres
//Mesclar esta função com a função com a formatação de
//campo somente numérico
//--------------------------------------------------------
function data(elemento){
var data
if (elemento.value.length > 0 )
{
if (elemento.value.length == 2)
{
data = elemento.value;
elemento.value = data + '/';
elemento.focus();
}
if (elemento.value.length == 5)
{
data = elemento.value;
elemento.value = data + '/';
elemento.focus();
}
}
return 0;
}
//--------------------------------------------------------
//Campo somente numérico
// Colocar onkeypress='return numerico(event)' no campo do formulário
//--------------------------------------------------------
function numerico(e) { 
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }if(tecla != 9){
		return false;
	}else{
		return true;
	}
    
} 
//--------------------------------------------------------
//Campo Float
// Colocar onKeyPress="return(formataMoeda(this,'.',',',event))" no campo do formulário
//--------------------------------------------------------
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;
}




//--------------------------------------------------------
//Mascara para CEP
//--------------------------------------------------------
function ceps(elemento){
var data;
	if (elemento.value.length == 5)
{
data = elemento.value;
elemento.value = data + '-';
elemento.focus();
}
}
function display(div){
	if(document.getElementById(div).style.display=="block"){
		document.getElementById(div).style.display="none";
		}else{
		document.getElementById(div).style.display="block";
	}
	
}



//========================================================
//INCLUSÃO DE ARQUIVOS SWF
//========================================================
//--------------------------------------------------------
//Na página, incluir os arquivos SWF desta maneira:
//<script> 
//EscreveFlash(LARGURA, ALTURA, "arquivo.swf");
//< / script>  (sem os espaços)
//--------------------------------------------------------
function EscreveFlash(piWid, piHei, psSrc, psId)
{
var strSwf;

strSwf = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" id="+psId+" width="+piWid+" height="+piHei+">";
strSwf += "<param name=\"movie\" value=\""+psSrc+"\"' />";
strSwf += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
strSwf += "<param name=\"quality\" value=\"high\" />";
strSwf += "<param name=\"wmode\" value=\"transparent\" />";
strSwf += "<embed id="+psId+" name="+psId+" allowScriptAccess=\"sameDomain\" swLiveConnect=\"true\" src=\""+psSrc+"\" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width="+piWid+" height="+piHei+"></embed></object>";

this.document.write(strSwf);
} 
function validaSenha(campo1,campo2){
	if(document.getElementById(campo1).value != document.getElementById(campo2).value){
		document.getElementById(campo1).value="";
		document.getElementById(campo2).value ="";
		document.getElementById(campo1).focus();
		return alert('A senha nao confere!');
	}else{
		return "";
	}
}


//========================================================
//EXIBE OCULTA ID
//========================================================
function mostraID(div){
			
	if(document.getElementById(div).style.display=='block'){
		document.getElementById(div).style.display='none'
		}else{
		document.getElementById(div).style.display='block'	
	}
}

