<!--

function limparRadios( radioObj )
{

	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			radioObj.checked = false;
		
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			radioObj[i].checked = false;
		}
	}

}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

//Limpar espacos vazios

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}



	function cor1(val){
	
		document.getElementById(val).ClassName='cor1'
	
	}


	function cor2(val){
	
		document.getElementById(val).ClassName='cor2'
	
	}


//Verifica qual o browser do visitante e armazena na variável púbica clientNavigator,   
//Caso Internet Explorer(IE) outros (Other)   
if (navigator.appName.indexOf('Microsoft') != -1){   
    clientNavigator = "IE";   
}else{   
    clientNavigator = "Other";   
}  

function SoNumeros(evnt) {   
//Função permite digitação de números
   
    if (clientNavigator == "IE"){   

        if ((evnt.keyCode < 48 || evnt.keyCode > 57 ) && (evnt.keyCode > 105 || evnt.keyCode < 96 )){              
		   
		   if (evnt.keyCode == 9 || evnt.keyCode == 13) { return evnt.keyCode = 9; } 
		   
		   else { if (evnt.keyCode == 8) { return evnt.keyCode = 8; } 
		   
		   else { return false }         	
 			 
	       }				       
        }
		   
    } else {   
        if ((evnt.charCode < 48 || evnt.charCode > 57) && evnt.keyCode == 0){   
            return false   
        }   
    }   
}   



function enter2tab(evnt) {

if (clientNavigator == "IE"){   
	
	if (evnt.keyCode == 13 ){  return evnt.keyCode = 9; }
		   
} else {   

	if (evnt.charCode == 13 ){ return evnt.charCode = 9;}   
	
}

}


function strpos( haystack, needle, offset){   
    // Finds position of first occurrence of a string within another     
    //    
    // version: 810.1317   
    // discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_strpos   
  
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)   
    // +   improved by: Onno Marsman       
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);   
    // *     returns 1: 14   
    var i = (haystack+'').indexOf( needle, offset );    
    return i===-1 ? false : i;   
}  
     

    
// Mensagem de ajuda com coloração do campo focado
// Como usar
//         <TR>
//           <td width="50" align="left" valign="top" height="40"></TD>
//             <td width="550" align="left" colspan="2" valign="top" height="40">

//              <font id="boxdescription" color="green" face="Verdana" size="1"></FONT>

//              </TD>

//        </TR>
// onfocus="movein(this,'')"  onblur="moveout(this)"

function movein(which,html){
 which.style.background='#E7F0F5'
 if (document.getElementById)
 document.getElementById("boxdescription").innerHTML=' '//html
 else
 boxdescription.innerHTML=html
 }

 function moveout(which){
 which.style.background='#FFFFFF'
 if (document.getElementById)
 document.getElementById("boxdescription").innerHTML=' '
 else
 boxdescription.innerHTML=' '
 }

//******************************************************************************************

function statusin(html){
 if (document.getElementById)
 document.getElementById("boxstatus").innerHTML='<b>' + html + '</b>'
 else
 boxdescription.innerHTML=html
 }

 function statusout(which){
 if (document.getElementById)
 document.getElementById("boxstatus").innerHTML=' '
 else
 boxdescription.innerHTML=' '
 }


/**
 * @author Márcio d'Ávila
 * @version 1.02, 2004-2007
 * http://www.mhavila.com.br/topicos/web/cpf_cnpj.html
 *
 * Licenciado sob os termos da licença Creative Commons,
 * Atribuição - Compartilhamento pela mesma licença 2.5:
 * http://creativecommons.org/licenses/by-sa/2.5/br/
 *
 * PROTÓTIPOS:
 * método String.lpad(int pSize, char pCharPad)
 * método String.trim()
 *
 * String unformatNumber(String pNum)
 * String formatCpfCnpj(String pCpfCnpj, boolean pUseSepar, boolean pIsCnpj)
 * String dvCpfCnpj(String pEfetivo, boolean pIsCnpj)
 * boolean isCpf(String pCpf)
 * boolean isCnpj(String pCnpj)
 * boolean isCpfCnpj(String pCpfCnpj)
 */


var NUM_DIGITOS_CPF  = 11;
var NUM_DIGITOS_CNPJ = 14;
var NUM_DGT_CNPJ_BASE = 8;


/**
 * Adiciona método lpad() à classe String.
 * Preenche a String à esquerda com o caractere fornecido,
 * até que ela atinja o tamanho especificado.
 */
String.prototype.lpad = function(pSize, pCharPad)
{
    var str = this;
    var dif = pSize - str.length;
    var ch = String(pCharPad).charAt(0);
    for (; dif>0; dif--) str = ch + str;
    return (str);
} //String.lpad


/**
 * Adiciona método trim() à classe String.
 * Elimina brancos no início e fim da String.
 */
String.prototype.trim = function()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim


/**
 * Elimina caracteres de formatação e zeros à esquerda da string
 * de número fornecida.
 * @param String pNum
 *      String de número fornecida para ser desformatada.
 * @return String de número desformatada.
 */
function unformatNumber(pNum)
{
    return String(pNum).replace(/\D/g, "").replace(/^0+/, "");
} //unformatNumber


/**
 * Formata a string fornecida como CNPJ ou CPF, adicionando zeros
 * à esquerda se necessário e caracteres separadores, conforme solicitado.
 * @param String pCpfCnpj
 *      String fornecida para ser formatada.
 * @param boolean pUseSepar
 *      Indica se devem ser usados caracteres separadores (. - /).
 * @param boolean pIsCnpj
 *      Indica se a string fornecida é um CNPJ.
 *      Caso contrário, é CPF. Default = false (CPF).
 * @return String de CPF ou CNPJ devidamente formatada.
 */
function formatCpfCnpj(pCpfCnpj, pUseSepar, pIsCnpj)
{
    if (pIsCnpj==null) pIsCnpj = false;
    if (pUseSepar==null) pUseSepar = true;
    var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
    var numero = unformatNumber(pCpfCnpj);

    numero = numero.lpad(maxDigitos, '0');
    if (!pUseSepar) return numero;

    if (pIsCnpj)
    {
        reCnpj = /(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/;
        numero = numero.replace(reCnpj, "$1.$2.$3/$4-$5");
    }
    else
    {
        reCpf  = /(\d{3})(\d{3})(\d{3})(\d{2})$/;
        numero = numero.replace(reCpf, "$1.$2.$3-$4");
    }
    return numero;
} //formatCpfCnpj


/**
 * Calcula os 2 dígitos verificadores para o número-efetivo pEfetivo de
 * CNPJ (12 dígitos) ou CPF (9 dígitos) fornecido. pIsCnpj é booleano e
 * informa se o número-efetivo fornecido é CNPJ (default = false).
 * @param String pEfetivo
 *      String do número-efetivo (SEM dígitos verificadores) de CNPJ ou CPF.
 * @param boolean pIsCnpj
 *      Indica se a string fornecida é de um CNPJ.
 *      Caso contrário, é CPF. Default = false (CPF).
 * @return String com os dois dígitos verificadores.
 */
function dvCpfCnpj(pEfetivo, pIsCnpj)
{
    if (pIsCnpj==null) pIsCnpj = false;
    var i, j, k, soma, dv;
    var cicloPeso = pIsCnpj? NUM_DGT_CNPJ_BASE: NUM_DIGITOS_CPF;
    var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
    var calculado = formatCpfCnpj(pEfetivo, false, pIsCnpj);
    calculado = calculado.substring(2, maxDigitos);
    var result = "";

    for (j = 1; j <= 2; j++)
    {
        k = 2;
        soma = 0;
        for (i = calculado.length-1; i >= 0; i--)
        {
            soma += (calculado.charAt(i) - '0') * k;
            k = (k-1) % cicloPeso + 2;
        }
        dv = 11 - soma % 11;
        if (dv > 9) dv = 0;
        calculado += dv;
        result += dv
    }

    return result;
} //dvCpfCnpj


/**
 * Testa se a String pCpf fornecida é um CPF válido.
 * Qualquer formatação que não seja algarismos é desconsiderada.
 * @param String pCpf
 *      String fornecida para ser testada.
 * @return <code>true</code> se a String fornecida for um CPF válido.
 */
function isCpf(pCpf)
{
    var numero = formatCpfCnpj(pCpf, false, false);
    var base = numero.substring(0, numero.length - 2);
    var digitos = dvCpfCnpj(base, false);
    var algUnico, i;

    // Valida dígitos verificadores
    if (numero != base + digitos) return false;

    /* Não serão considerados válidos os seguintes CPF:
     * 000.000.000-00, 111.111.111-11, 222.222.222-22, 333.333.333-33, 444.444.444-44,
     * 555.555.555-55, 666.666.666-66, 777.777.777-77, 888.888.888-88, 999.999.999-99.
     */
    algUnico = true;
    for (i=1; algUnico && i<NUM_DIGITOS_CPF; i++)
    {
        algUnico = (numero.charAt(i-1) == numero.charAt(i));
    }
    return (!algUnico);
} //isCpf


/**
 * Testa se a String pCnpj fornecida é um CNPJ válido.
 * Qualquer formatação que não seja algarismos é desconsiderada.
 * @param String pCnpj
 *      String fornecida para ser testada.
 * @return <code>true</code> se a String fornecida for um CNPJ válido.
 */
function isCnpj(pCnpj)
{
    var numero = formatCpfCnpj(pCnpj, false, true);
    var base = numero.substring(0, NUM_DGT_CNPJ_BASE);
    var ordem = numero.substring(NUM_DGT_CNPJ_BASE, 12);
    var digitos = dvCpfCnpj(base + ordem, true);
    var algUnico;

    // Valida dígitos verificadores
    if (numero != base + ordem + digitos) return false;

    /* Não serão considerados válidos os CNPJ com os seguintes números BÁSICOS:
     * 11.111.111, 22.222.222, 33.333.333, 44.444.444, 55.555.555,
     * 66.666.666, 77.777.777, 88.888.888, 99.999.999.
     */
    algUnico = numero.charAt(0) != '0';
    for (i=1; algUnico && i<NUM_DGT_CNPJ_BASE; i++)
    {
        algUnico = (numero.charAt(i-1) == numero.charAt(i));
    }
    if (algUnico) return false;

    /* Não será considerado válido CNPJ com número de ORDEM igual a 0000.
     * Não será considerado válido CNPJ com número de ORDEM maior do que 0300
     * e com as três primeiras posições do número BÁSICO com 000 (zeros).
     * Esta crítica não será feita quando o no BÁSICO do CNPJ for igual a 00.000.000.
     */
    if (ordem == "0000") return false;
    return (base == "00000000"
        || parseInt(ordem, 10) <= 300 || base.substring(0, 3) != "000");
} //isCnpj


/**
 * Testa se a String pCpfCnpj fornecida é um CPF ou CNPJ válido.
 * Se a String tiver uma quantidade de dígitos igual ou inferior
 * a 11, valida como CPF. Se for maior que 11, valida como CNPJ.
 * Qualquer formatação que não seja algarismos é desconsiderada.
 * @param String pCpfCnpj
 *      String fornecida para ser testada.
 * @return <code>true</code> se a String fornecida for um CPF ou CNPJ válido.
 */
function isCpfCnpj(pCpfCnpj)
{
    var numero = pCpfCnpj.replace(/\D/g, "");
    if (numero.length > NUM_DIGITOS_CPF)
        return isCnpj(pCpfCnpj)
    else
        return isCpf(pCpfCnpj);
} //isCpfCnpj


 //********************************************************************************//
// FUNCAO MASKARAR CAMPOS
//Resp: Michaell
//********************************************************************************//

function formatarmask(src, mask) {
  var i = src.value.length;
  var saida = "#";
//  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida)  {
	src.value += texto.substring(0,1);
  }
  
}

/*
Exemplos:
CEP
OnKeyPress="formatarmask(this, '#####-###')"
CPF
OnKeyPress="formatarmask(this, '###.###.###-##')"
DATA
OnKeyPress="formatarmask(this, '##/##/####')"
*/



function Verifica_Data(data) {   
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não   
//var data = document.getElementById(data);   
	var ret = new String("");
    var strdata =new String(data);   
	
	
       //Verifica a quantidade de digitos informada esta correta.   
        if (strdata.length != 10){   		
		
			  ret = "Formato da data não é válido.Formato correto:- dd/mm/aaaa.";
    
        }   
        //Verifica máscara da data   
        if ("/" != strdata.substr(2,1) || "/" != strdata.substr(5,1)){   
			  ret = "Formato da data não é válido. Formato correto: - dd/mm/aaaa.";

        }   
		
        dia = strdata.substr(0,2)   
        mes = strdata.substr(3,2);   
        ano = strdata.substr(6,4);   
        //Verifica o dia   
        if (isNaN(dia) || dia > 31 || dia < 1){   
			  ret = "Formato do dia não é válido.";

        }   
        if (mes == 4 || mes == 6 || mes == 9 || mes == 11){   
            if (dia == "31"){   
			  ret = "O mês informado não possui 31 dias.";

 
            }   
        }   
        if (mes == "02"){   
            bissexto = ano % 4;   
            if (bissexto == 0){   
                if (dia > 29){   
			 		ret = "O mês informado possui somente 29 dias.";

                }   
            }else{   
                if (dia > 28){   
			 		ret = "O mês informado possui somente 28 dias.";

                }   
            }   
        }   
    //Verifica o mês   
        if (isNaN(mes) || mes > 12 || mes < 1){   
	 		ret = "Formato do mês não é válido.";

        }   
        //Verifica o ano   
        if (isNaN(ano)){   
	 		ret = "Formato do ano não é válido.";

        }  
		
       		return ret  		
    }   
  
  
function Compara_Datas(data_inicial, data_final){   
    //Verifica se a data inicial é maior que a data final   
    var data_inicial = document.getElementById(data_inicial);   
    var data_final   = document.getElementById(data_final);   
    str_data_inicial = data_inicial.value;   
    str_data_final   = data_final.value;   
    dia_inicial      = data_inicial.value.substr(0,2);   
    dia_final        = data_final.value.substr(0,2);   
    mes_inicial      = data_inicial.value.substr(3,2);   
    mes_final        = data_final.value.substr(3,2);   
    ano_inicial      = data_inicial.value.substr(6,4);   
    ano_final        = data_final.value.substr(6,4);   
    if(ano_inicial > ano_final){   
        alert("A data inicial deve ser menor que a data final.");   
        data_inicial.focus();   
        return false   
    }else{   
    if(ano_inicial == ano_final){   
    if(mes_inicial > mes_final){   
    alert("A data inicial deve ser menor que a data final.");   
                data_final.focus();   
                return false   
            }else{   
                if(mes_inicial == mes_final){   
                    if(dia_inicial > dia_final){   
                        alert("A data inicial deve ser menor que a data final.");   
                        data_final.focus();   
                        return false   
                    }   
                }   
            }   
        }   
    }   
}   
  
function Verifica_Hora(hora, obrigatorio){   
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não   
    var hora = document.getElementById(hora);   
    if((obrigatorio == 1) || (obrigatorio == 0 && hora.value != "")){   
        if(hora.value.length < 5){   
            alert("Formato da hora inválido. Por favor, informe a hora no formato correto: hh:mm");   
            hora.focus();   
            return false   
        }   
        if(hora.value.substr(0,2) > 23 || isNaN(hora.value.substr(0,2))){   
            alert("Formato da hora inválido.");   
            hora.focus();   
            return false   
        }   
        if(hora.value.substr(3,2) > 59 || isNaN(hora.value.substr(3,2))){   
            alert("Formato do minuto inválido.");   
            hora.focus();   
            return false   
        }   
    }   
}   
  
function Verifica_Email(email){   
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não     
	var ret   = "";
        if(!email.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi)){   
            ret = "Informe um e-mail válido";   
    } 
	
	return ret;
}   
  
function Verifica_Tamanho(campo, tamanho){   
//usado para campos textarea onde não se tem o atributo maxlenght   
    var campo = document.getElementById(campo);   
    if(campo.value.length > tamanho){   
        alert("O campo suporta no máximo " + tamanho + " caracteres.");   
        campo.focus();   
        return false   
    }   
}   
  
function Verifica_Cep(cep, obrigatorio){   
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não   
    var cep    = document.getElementById(cep);   
    var strcep = cep.value;   
    if((obrigatorio == 1) || (obrigatorio == 0 && strcep != "")){   
        if (strcep.length != 9){   
            alert("CEP informado inválido.");   
            cep.focus();   
            return false   
        }else{   
            if (strcep.indexOf("-") != 5){   
                alert("Formato de CEP informado inválido.");   
                cep.focus();   
                return false   
            }else{   
                if (isNaN(strcep.replace("-","0"))){   
                    alert("CEP informado inválido.");   
                    cep.focus();   
                    return false   
                }   
            }   
        }   
    }       
}   
  
function Bloqueia_Caracteres(evnt){   
//Função permite digitação de números   
    if (clientNavigator == "IE"){   
        if (evnt.keyCode < 48 || evnt.keyCode > 57){   
            return false   
        }   
    }else{   
        if ((evnt.charCode < 48 || evnt.charCode > 57) && evnt.keyCode == 0){   
            return false   
        }   
    }   
}   
  
function Ajusta_Data(input, evnt){   
//Ajusta máscara de Data e só permite digitação de números   
    if (input.value.length == 2 || input.value.length == 5){   
        if(clientNavigator == "IE"){   
            input.value += "/";   
        }else{   
            if(evnt.keyCode == 0){   
                input.value += "/";   
            }   
        }   
    }   
//Chama a função Bloqueia_Caracteres para só permitir a digitação de números   
    return Bloqueia_Caracteres(evnt);   
}   
  
function Ajusta_Hora(input, evnt){   
//Ajusta máscara de Hora e só permite digitação de números   
    if (input.value.length == 2){   
        if(clientNavigator == "IE"){   
            input.value += ":";   
        }else{   
            if(evnt.keyCode == 0){   
                input.value += ":";   
            }   
        }   
    }   
//Chama a função Bloqueia_Caracteres para só permitir a digitação de números   
    return Bloqueia_Caracteres(evnt);   
}   
  
function Ajusta_Cep(input, evnt){   
//Ajusta máscara de CEP e só permite digitação de números   
    if (input.value.length == 5){   
        if(clientNavigator == "IE"){   
            input.value += "-";   
        }else{   
            if(evnt.keyCode == 0){   
                input.value += "-";   
            }   
        }   
    }   
//Chama a função Bloqueia_Caracteres para só permitir a digitação de números   
    return Bloqueia_Caracteres(evnt);   
}   
  
function Atualiza_Opener(){   
//Atualiza a página opener da popup que chamar a função   
    window.opener.location.reload();   
} 

function Retorna_principal(){   
//Atualiza a página opener da popup que chamar a função   
    window.location.href="index.php";   
}
/*function Valida(){   
    if(document.formulario.nome.value == ""){   
        alert("Preencha o nome da pessoa");   
    }   
    if(Verifica_Data("data_nascimento", 1) == false){ return false }   
    if(Verifica_Hora("hora_compromisso", 1) == false){ return false }   
    if(Verifica_Cep("cep", 0) == false){ return false }   
    if(Verifica_Email("email", 0) == false){ return false }   
    if(Verifica_Email("descricao", 4000) == false){ return false }   
} 

<input name="data" type="text" id="data" maxlength="10" onKeypress="return Ajusta_Data(this, event);">   
<input name="hora" type="text" id="hora" maxlength="5" onKeypress="return Ajusta_Hora(this, event);">   
<input name="cep" type="text" id="cep" maxlength="9" onKeypress="return Ajusta_Cep(this, event);">   
<input name="numero" type="text" id="numero" maxlength="20" onKeypress="return Bloqueia_Caracteres(event);"">   

*/
-->