﻿//Autor:	 VANNON DIRECT
//Data:      29/10/2007
//Descrição: JScript File - Funções genericas

function onPostBack(sender, e){ 
    __doPostBack(sender,e); 
}
   function abrePromocao()
        {
            window.open("Cadastro_Promocao.aspx",null,
    "height=280,width=440,status=no,toolbar=no,menubar=no,location=no");
        }
function SelectOne(rdo,gridName)
{
    all = document.getElementsByTagName("input");/* Getting an array of all the "INPUT" controls on the form.*/
    for(i = 0; i < all.length; i++)
    {
        if(all[i].type=="radio")/*Checking if it is a radio button*/
        {
            var count=all[i].id.indexOf(gridName); 
            if(count!=-1)
            {
                all[i].checked=false;
            }
        }
    }
    rdo.checked = true;/* Finally making the clicked radio button CHECKED */
}

// Bloqueia a digitação de Letras
function BloquearLetras(e){
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
    	keynum = e.which
	}
    else
	{
	    keynum = e.keyCode;
	}
    if (!TeclaPermitida(keynum))
	{
		if (keynum < 48 || keynum > 57){
			return false;
		}
	}
}

// Bloqueia a digitação de Números
function BloquearNumeros(e){
    if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
    	keynum = e.which
	}
	else
	{
	    keynum = e.keyCode;
	}
	if ((!TeclaPermitida(keynum)) && (keynum != 32))
	{
        var keyval = String.fromCharCode(keynum);
        if (((keyval < "A") || (keyval > "Z")) && ((keyval < "a") || (keyval > "z")))
        {
            return false;
        }
    }
}

// Bloqueia a digitação de Caracteres Especiais
function BloquearChrEsp(e){
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
    	keynum = e.which
	}
    else
	{
	    keynum = e.keyCode;
	}
    if ((!TeclaPermitida(keynum)) && (keynum != 32))
    {
    	var keyval = String.fromCharCode(keynum);
		if ((keynum < 48 || keynum > 57) && 
		    ((keyval < "A") || (keyval > "Z")) && ((keyval < "a") || (keyval > "z")))
		{
			return false;
		}
	}
}

/* Verifica se é uma tecla permitida.
8  - Backspace
9  - Tab
35 - End
36 - Home
37 - Seta 
39 - Seta
46 - Delete
*/
function TeclaPermitida(keynum)
{
    if ((keynum == 8)  || (keynum == 9)  || (keynum == 35) || (keynum == 36) ||
        (keynum == 37) || (keynum == 39) || (keynum == 46)){
        return true;
    }else{
        return false;
    }
}

function FormataCampo(campo)
{
    var aspasS = /'/g;
    var aspasD = /"/g;
	var tio = /~/g;
	var agudo = /´/g;
	var crase = /`/g;
	var porcent = /%/g;
	var ecom = /&/g;
	var sust = /#/g;
	var sifr = /\$/g;
	//var trac = /-/g;
	
    valor = campo.value;
    valor = valor.replace(aspasS,"");
    valor = valor.replace(aspasD,"");
	valor = valor.replace(tio, "");
	valor = valor.replace(agudo, "");
	valor = valor.replace(crase, "");
	valor = valor.replace(porcent, "");
	valor = valor.replace(ecom, "");
	valor = valor.replace(sust, "");
	valor = valor.replace(sifr, "");
	//valor = valor.replace(trac, "");

    // Retira espaço no inicio
    espaco = valor.substr(0,1);
    while(espaco == " ")
    {
	    valor = valor.substr(1,valor.length);
	    espaco = valor.substr(0,1);
    }
    // Retira espaço no fim
    espaco = valor.substr((valor.length-1),valor.length);
    while(espaco == " ")
    {
	    valor = valor.substr(0,(valor.length-1));
	    espaco = valor.substr((valor.length-1),valor.length);
    }
    // Retira espaço entre os caracteres
    var branco    = 0;
    var novoValor = "";
    for(i=0;i<valor.length; i++)
    {
	    letra = valor.substring(i,(i+1));
	    if(i == 1)
	    {
		    novoValor = novoValor + letra;
	    }
	    else if(letra == " ")
	    {
		    if(valor.substring((i-1),(i+1)) != " " && valor.substring((i+1),(i+2)) != " ")
		    {
			    novoValor = novoValor + letra;
		    }
	    }else
	    {
		    novoValor = novoValor + letra;
	    }
    }
    valor = novoValor;
    campo.value = valor;
}

// Valida data preenchida no formato (dd/mm/aaaa) em campos separados, retorna true ou false.
function ValidaData(d,m,a,campo){
	var meses = new Array("","Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
	
	//d = parseInt(d);
	//m = parseInt(m);
	data_atual = new Date();
    ano_atual = data_atual.getFullYear(); 

    //verifica se é um mês válido
    if ((m < 1) || (m > 12)){
        return "O mês deve conter um valor entre 1 e 12.";
	//verifica se os meses 4,6,9 e 11 tem até 30 dias
	}else if ((m==4 || m==6 || m==9 || m==11) && d>30){
		return meses[m] +" deve ter até 30 dias no campo " + campo + ".";
    //verifica se os meses 1,3,5,7,8,10 e 12 tem até 31 dias
    }else if ((m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) && d>31) {
		return meses[m] +" deve ter até 31 dias no campo " + campo + ".";
	//verifica se fevereiro tem até 28 ou 29 dias dependendo do ano
	}else if ((a%4)>0 && m==2 && d>28){
		return meses[m] +" de "+ a +" deve ter até 28 dias no campo " + campo + ".";
	}else if ((a%4)==0 && m==2 && d>29){
		return meses[m] +" de "+ a +" deve ter até 29 dias no campo " + campo + ".";
	} else if (a > (ano_atual - 10)){
	    return "O ano deve ser menor que " + (ano_atual - 9) + " no campo " + campo + ".";
    } else if (a < (ano_atual - 100)){
	    return "O ano deve ser maior que " + (ano_atual - 101) + " no campo " + campo + ".";
	}	
	else {
		return "";
	}
}
// Valida data preenchida no formato (dd/mm/aaaa) em campos separados, retorna true ou false.
function ValidaDataCompleto(d,m,a,campo){
	var meses = new Array("","Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
	
	//d = parseInt(d);
	//m = parseInt(m);
	data_atual = new Date();
    ano_atual = data_atual.getFullYear(); 

    //verifica se é um mês válido
    if ((m < 1) || (m > 12)){
        return "O mês deve conter um valor entre 1 e 12.";
	//verifica se os meses 4,6,9 e 11 tem até 30 dias
	}else if ((m==4 || m==6 || m==9 || m==11) && d>30){
		return meses[m] +" deve ter até 30 dias no campo " + campo + ".";
    //verifica se os meses 1,3,5,7,8,10 e 12 tem até 31 dias
    }else if ((m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) && d>31) {
		return meses[m] +" deve ter até 31 dias no campo " + campo + ".";
	//verifica se fevereiro tem até 28 ou 29 dias dependendo do ano
	}else if ((a%4)>0 && m==2 && d>28){
		return meses[m] +" de "+ a +" deve ter até 28 dias no campo " + campo + ".";
	}else if ((a%4)==0 && m==2 && d>29){
		return meses[m] +" de "+ a +" deve ter até 29 dias no campo " + campo + ".";
	} else if (a > (ano_atual - 10)){
	    return "O ano deve ser menor que " + (ano_atual - 9) + " no campo " + campo + ".";
    } else if (a < (ano_atual - 100)){
	    return "O ano deve ser maior que " + (ano_atual - 101) + " no campo " + campo + ".";
	}	
	else {
		return "";
	}
}
// Valida um email, retornando true ou false Retorno: true ou false
function VerificaEmail(email){
	var bMail, ind_at, tam_mail, str_esp, i, j;
	bMail = true;
	str_esp = "~!`;:#@$%^&*()+=\|,'áÄÁäàÀËëéèÈíÍìÌóÖÓÒòúÜÚùÙ[]{}/ <>";
	email = email.trim();
	tam_mail = email.length;
	
	if(tam_mail  < 5)
		bMail = false;
	else
	{
		ind = email.indexOf("@");
		if(ind == -1 || ind < 1 || ind > tam_mail-4)
			bMail = false;
		else
		{
			email =  email.substring(0, ind) + email.substring(ind+1, tam_mail);
			for(i = 0; i < email.length; i++) 
				for(j = 0; j < str_esp.length && bMail; j++)
				{
					if(email.charAt(i) == str_esp.charAt(j))
						bMail = false; 
				}
		}
	}	
	return bMail;
}

function validaCNPJ(cnpj){ 
    var a = new Array(); 
    var b = new Number; 
    var c = [6,5,4,3,2,9,8,7,6,5,4,3,2]; 
    for (i=0; i<12; i++){ 
        a[i] = cnpj.charAt(i); 
        b += a[i] * c[i+1]; 
    } 
    if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x } 
    b = 0; 
    for (y=0; y<13; y++) { 
        b += (a[y] * c[y]); 
    } 
    if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; } 
    if ((cnpj.charAt(12) != a[12]) || (cnpj.charAt(13) != a[13])){ 
        return false; 
    } 
    return true; 
} 

function validaCPF(cpf){
   var soma;
   var resto;
   var i;

   if ( (cpf.length != 11) ||
     (cpf == "00000000000") || (cpf == "11111111111") ||  (cpf == "22222222222") || (cpf == "33333333333") ||
     (cpf == "44444444444") || (cpf == "55555555555") ||  (cpf == "66666666666") || (cpf == "77777777777") ||
     (cpf == "88888888888") || (cpf == "99999999999") ) {
     return false;
   }

   soma = 0;
   for (i = 1; i <= 9; i++) {
     soma += Math.floor(cpf.charAt(i-1)) * (11 - i);
   }

   resto = 11 - (soma - (Math.floor(soma / 11) * 11));
   if ( (resto == 10) || (resto == 11) ) {
     resto = 0;
   }

   if ( resto != Math.floor(cpf.charAt(9)) ) {
     return false;
   }

   soma = 0;
   for (i = 1; i<=10; i++) {
     soma += cpf.charAt(i-1) * (12 - i);
   }

   resto = 11 - (soma - (Math.floor(soma / 11) * 11));
   if ((resto == 10) || (resto == 11)){
     resto = 0;
   }

   if (resto != Math.floor(cpf.charAt(10))){
     return false;
   }
   return true;
}

//Função para validar o número do cartão de crédito.
//No parametro cardNumber deverá passar o número do cartão.
//No parametro cardType deverá passar o tipo de cartão. ele poderá assumir os seguintes valores:
//  - mastercard
//  - visa
//  - amex
/*function isValidCreditCardNumber_backup(cardNumber, cardType)
{
    var isValid = false;
    var ccCheckRegExp = /[^\d ]/;
    isValid = !ccCheckRegExp.test(cardNumber);
    
    if (isValid){
        var cardNumbersOnly = cardNumber.replace(/ /g,"");
        var cardNumberLength = cardNumbersOnly.length;
        var lengthIsValid = false;
        var prefixIsValid = false;
        var prefixRegExp;
    switch(cardType){
        case "mastercard":
            lengthIsValid = (cardNumberLength == 16);
            prefixRegExp = /^5[1-5]/;
        break;
        case "visa":
            lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
            prefixRegExp = /^4/;
        break;
        case "amex":
            lengthIsValid = (cardNumberLength == 15);
            prefixRegExp = /^3(4|7)/;
        break;
        case "dbclub":
            lengthIsValid = (cardNumberLength == 14);
            prefixRegExp = /^3/;
        break;
        case "hyper":
            lengthIsValid = (cardNumberLength == 19);
            prefixRegExp = /^[0-9]/;
            return lengthIsValid
        break;
        default:
            prefixRegExp = /^$/;
            alert("Código não encontrado");
    }

    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;
    }
    if (isValid){
        var numberProduct;
        var numberProductDigitIndex;
        var checkSumTotal = 0;
        for (digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter--){
            checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
            digitCounter--;
            numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
            for (var productDigitCounter = 0; productDigitCounter < numberProduct.length; productDigitCounter++){
                checkSumTotal += parseInt(numberProduct.charAt(productDigitCounter));
            }
        }
        isValid = (checkSumTotal % 10 == 0);
    }

    return isValid;
}
*/
function isMesValid(mes)
{
    if ((mes < 1) || (mes > 12))
    {
        return false;
    }
    return true;
}

function isAnoValid(ano)
{
    ano_atual = new Date().getFullYear(); 
    if ((ano < ano_atual) || (ano > (ano_atual + 500)))
    {
        return false;
    }
    return true;
}

function ValidaPgtoDebito()
{
    document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "";
    document.getElementById('div_Real').style.display = 'none';
    document.getElementById('div_Falso').style.display = 'block';
}

function ValidaPgtoCredito(tipoCartao, args)
{
    document.getElementById(recuperaNomeControle("vldPgtoDebito")).innerHTML = "";
    var numCartao  = document.getElementById(recuperaNomeControle("txt_num_cartao_credito")).value;
    var numCodSeguranca = document.getElementById(recuperaNomeControle("txt_cartao_credito_codigo_seguranca")).value;
    try
    {
        if (numCartao.trim().length == 0)
        {
            document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Preencha o campo Número corretamente.";
            args.IsValid = false;
            return;
        }
        if(tipoCartao != '800')
        {
            if (numCodSeguranca.trim().length == 0)
            {
                document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Preencha o campo Cód. de Segurança corretamente.";
                args.IsValid = false;
                return;
            }
        }
    }
    catch(err)
    {
        if (numCartao.length == 0)
        {
            document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Preencha o campo Número corretamente.";
            args.IsValid = false;
            return;
        }
         if (numCodSeguranca.trim().length == 0)
        {
            document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Preencha o campo Cód. de Segurança corretamente.";
            args.IsValid = false;
            return;
        }  
    }
    if (!isValidCreditCardNumber(numCartao, tipoCartao))
    {
        document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Cartão Inválido.";
        args.IsValid = false;
        return;
    }
    
    //Valida a Data de Validade
    var dt_validade_mm = document.getElementById(recuperaNomeControle("txt_validade_mm")).value;
    var dt_validade_aa = document.getElementById(recuperaNomeControle("txt_validade_aa")).value;
    try
    {
        if ((dt_validade_mm.trim().length == 0) || (dt_validade_aa.trim().length == 0))
        {
            document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Preencha o campo Data de Validade corretamente.";
            args.IsValid = false;
            return;
        }
    }
    catch(err)
    {
        if ((dt_validade_mm.length == 0) || (dt_validade_aa.length == 0))
        {
            document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Preencha o campo Data de Validade corretamente.";
            args.IsValid = false;
            return;
        }
    }
    
    if (!( isMesValid(dt_validade_mm) && isAnoValid(dt_validade_aa) ))
    {
        document.getElementById(recuperaNomeControle("vldPgtoCredito")).innerHTML = "Data de Validade inválida.";
        args.IsValid = false;
        return;
    }
    document.getElementById('div_Real').style.display = 'none';
    document.getElementById('div_Falso').style.display = 'block';
    args.IsValid = true;   
    return;
}

function ValidaFormaPgto(oSrc, args)
{

    if (document.getElementById(recuperaNomeControle("rdb_forma_pgto1")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto1")).checked == true){
        ValidaPgtoDebito();
    }else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto2")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto2")).checked == true){
        ValidaPgtoDebito();
    }else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto3")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto3")).checked == true){
        ValidaPgtoDebito();
    }else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto4")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto4")).checked == true){
        ValidaPgtoDebito();
    }
    
    var elementRef = document.getElementById(recuperaNomeControle("tabela_Cartoes"));
    var radioButtonListArray = elementRef.getElementsByTagName('input');
    for (var i=0; i<radioButtonListArray.length; i++)
    {
        var radioButtonRef = radioButtonListArray[i];
        if(radioButtonRef.checked)
        {
            ValidaPgtoCredito(radioButtonRef.value, args);
            return;
        }
    }
    
    /*else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto5")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto5")).checked == true){
        ValidaPgtoCredito("visa", args);
    }else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto6")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto6")).checked == true){
        ValidaPgtoCredito("mastercard", args);
    }else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto7")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto7")).checked == true){
        ValidaPgtoCredito("amex", args);
    }else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto8")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto8")).checked == true){
        ValidaPgtoCredito("dbclub", args);  
    }else if(document.getElementById(recuperaNomeControle("rdb_forma_pgto9")) && document.getElementById(recuperaNomeControle("rdb_forma_pgto9")).checked == true){
        ValidaPgtoCredito("hyper", args);  
    }  */
}

//aceitar apenas numeros
function Numero(e)
{
    navegador = /msie/i.test(navigator.userAgent);
    if (navegador)
        var tecla = event.keyCode;
    else
        var tecla = e.which;

    if(tecla > 47 && tecla < 58) // numeros de 0 a 9
        return true;
    else
    {
        if (tecla != 8) // backspace
            return false;
        else
            return true;
    }
}

function mascaraData(campoData)
{
/*
    var data = campoData.value; 
    
    if (data.length == 2){                  
        data = data + '/';                  
        document.forms[0].data.value = data;      
        return true;                            
    }              
    if (data.length == 5){                  
        data = data + '/';                  
        document.forms[0].data.value = data;                  
        return true;              
    }
    */        
}
function cpagamento(prod_id)
{
    window.open('cPagamento.aspx?pCh='+prod_id,'Onofre',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=350,top=50,left=50");
}
function pdf(pdf)
{
    window.open('pdf.aspx?pdf='+pdf,'Onofre',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=15,height=15,top=0,left=0");
}

function MascaraMoeda(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;
}

function tabEnter(event, field){

    var keyCode = event.keyCode ? event.keyCode : window.event.which ? event.which : event.charCode;
    
    if ( keyCode == 13 ){
        document.getElementById(field).focus();
        return false;
    }else{
        if ( (keyCode != 13)){
            return true;
        }
    }
}
function numericOnly(field){
    var keyCode = window.event.keyCode ? window.event.keyCode : window.event.which ? window.event.which : window.event.charCode;
    
    if ( keyCode <= 47 || keyCode >= 59 )
        return false;
}
function abrePopUpRemember(pagina, x, y){
            window.open(pagina,null,"height=" + y + ",width=" + x + ",status=no,toolbar=no,menubar=no,scrollbar=no");
}
function setVisibility(id, visibility)
{
    document.getElementById(id).style.display = visibility;
}
function buscaAvancada(id)
{
    var div = document.getElementById(id);
    
    if(div != null)
    {
        if(div.style.display == 'none')
            div.style.display = 'block';
        else    
            div.style.display = 'none';
    }

}

function Formatadata(Campo, teclapres) {
    var tecla = teclapres.keyCode;
    var vr = new String(Campo.value);
    vr = vr.replace("/", "");
    tam = vr.length + 1;
    
    if (tecla != 8) {
        if (tam > 0 && tam < 2) 
            Campo.value = vr.substr(0, 2);
        if (tam > 2 && tam < 4)
            Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2);
        if (tam > 4 && tam < 7) 
            Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 7);            
        
    }    
}

function ValidaData(campo) {
    var vr = new String(campo);
    if (vr.length == 10) {
        data = new Date();
        anoAtual = data.getFullYear();
        var dia = vr.substr(0, 2);
        var mes = vr.substr(3, 2);
        var ano = vr.substr(6, 4);
        if (dia < 1 || dia > 31) {
            alert("Corrija o dia da data digitada !");
        }
        if (mes < 1 || mes > 12) {
            alert("Corrija o mês da data digitada !");
        }
        if (ano > anoAtual) {
            alert("Corrija o ano da data digitada !");            
        }
    } else {
        alert("Corrija o campo data !");
    }
}

//função para checar se os campos posologia e quantidade estão recebendo valores maiores que 0
function ChecaValor(valor) {
    if (valor.value <= 0)
        alert("Favor informar corretamente a posologia e a quantidade de caixa.");
}

///////////
function validarCPF(cpfN) {
    var cpf = new String(cpfN.value);
    
    if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999") {
        window.alert("CPF inválido. Tente novamente.");
        return false;
    }

    soma = 0;
    for (i = 0; i < 9; i++)
        soma += parseInt(cpf.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(cpf.charAt(9))) {
        window.alert("CPF inválido. Tente novamenteB.");
        return false;
    }
    soma = 0;
    for (i = 0; i < 10; i++)
        soma += parseInt(cpf.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(cpf.charAt(10))) {
        window.alert("CPF inválido. Tente novamenteC.");
        return false;
    }
}

///////////


