// BASIC DATA VALIDATION FUNCTIONS:
//
// isWhitespace (s)                    Check whether string s is empty or whitespace.
// isLetter (c)                        Check whether character c is an English letter 
// isDigit (c)                         Check whether character c is a digit 
// isLetterOrDigit (c)                 Check whether character c is a letter or digit.
// isInteger (s [,eok])                True if all characters in string s are numbers.
// isSignedInteger (s [,eok])          True if all characters in string s are numbers; leading + or - allowed.
// isPositiveInteger (s [,eok])        True if string s is an integer > 0.
// isNonnegativeInteger (s [,eok])     True if string s is an integer >= 0.
// isNegativeInteger (s [,eok])        True if s is an integer < 0.
// isNonpositiveInteger (s [,eok])     True if s is an integer <= 0.
// isFloat (s [,eok])				   True if string s is an unsigned floating point (real) number. (Integers also OK.)
// isSignedFloat (s [,eok])            True if string s is a floating point number; leading + or - allowed. (Integers also OK.)
// isAlphabetic (s [,eok])             True if string s is English letters 
// isAlphanumeric (s [,eok])           True if string s is English letters and numbers only.
// isEmail (s [,eok])                  True if string s is a valid email address.
// isYear (s [,eok])                   True if string s is a valid Year number.
// isIntegerInRange (s, a, b [,eok])   True if string s is an integer between a and b, inclusive.
// isMonth (s [,eok])                  True if string s is a valid month between 1 and 12.
// isDay (s [,eok])                    True if string s is a valid day between 1 and 31.
// daysInFebruary (year)               Returns number of days in February of that year.
// isDate (year, month, day)           True if string arguments form a valid date.
// checkLength (form,name,charLimit)   Check maxlength for textarea

// VARIABLE DECLARATIONS

var digits = "0123456789";

var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"

var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// navigators variable
var bname = navigator.appName;
var bver = parseInt(navigator.appVersion);
var blegal = ((bname == "Netscape" && bver >= 3) || (bname == "Microsoft Internet Explorer" && bver >= 4));


// whitespace characters
var whitespace = " \t\n\r";


// decimal point character differs by language and culture
var decimalPointDelimiter = "."
var decimalPointDelimiterVirgula = ","


// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";


// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;


// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";


// non-digit characters which are allowed in 
// Social Security Numbers
var SSNDelimiters = "- ";



// characters which are allowed in Social Security Numbers
var validSSNChars = digits + SSNDelimiters;


// non-digit characters which are allowed in ZIP Codes
var ZIPCodeDelimiters = "-";



// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"


// characters which are allowed in Social Security Numbers
var validZIPCodeChars = digits + ZIPCodeDelimiters


// non-digit characters which are allowed in credit card numbers
var creditCardDelimiters = " "


// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

// Global variable defaultEmptyOK defines default return value 
// for many functions when they are passed the empty string. 
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default, 
// these functions will do "strict" validation.  Function
// isInteger, for example, will only return true if it is
// passed a string containing an integer; if it is passed
// the empty string, it will return false.
//
// You can change this default behavior globally (for all 
// functions which use defaultEmptyOK) by changing the value
// of defaultEmptyOK.
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for 
// the duration of a function call.
//
// This functionality is useful because it is possible to
// say "if the user puts anything in this field, it must
// be an integer (or a phone number, or a string, etc.), 
// but it's OK to leave the field empty too."
// This is the case for fields which are optional but which
// must have a certain kind of content if filled in.

var defaultEmptyOK = false




// Attempting to make this library run on Navigator 2.0,
// so I'm supplying this array creation routine as per
// JavaScript 1.0 documentation.  If you're using 
// Navigator 3.0 or later, you don't need to do this;
// you can use the Array constructor instead.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}



var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;



// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}



// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}



// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}





// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isIntegerPreco (s)

{   var i;

    s = s.toString().replace(",", "")
    s = s.toString().replace(".", "")
    
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// isAlphabetic (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphabetic (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }

    // All characters are letters.
    return true;
}




// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}


// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}




// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var slength = s.length;

    // look for @
    while ((i < slength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= slength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < slength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= slength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}




// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkEmail (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, iEmail);
    else return true;
}




//********************************************************************************
//************** Validacao de CNPJ / CPF ******************************************
//********************************************************************************

// funcoes para verificacao de CPF e CNPJ

function CPF(a) {
	
	var numero = "";
	var multipli = 0;
	var soma = 0;
	var cont = 1;
	var cont1 = 10;

	for(cont=0;cont<9;cont++) {
        numero = a.charAt(cont);
        multipli = numero * cont1;
        soma = soma + multipli;
        cont1 = cont1 - 1;
        numero = "";
	}

	soma = soma % 11;
	soma = 11 - soma;
	numero = a.charAt(10);

	if(soma > 9 ) {
		if(numero != 0) {
			return (false);
		}
	}
	else {
		if(soma != numero) {
			return (false);
		}
	}

	multipli = 0;
	soma = 0;
	cont = 1;
	cont1 = 11;

	for(cont=0;cont<11;cont++) {
		numero = a.charAt(cont);
		if(numero != "-") {
			multipli = numero * cont1;
			soma = soma + multipli;
			cont1 = cont1 - 1;
		}
        numero = "";
	}

	soma = soma % 11;
	soma = 11 - soma;
	numero = a.charAt(11);

	if(soma > 9 ) {
		if(numero != 0) {
			return (false);
		}
	}
	else {
		if(soma != numero) {
			return (false);
		}
	}
	return (true);
}

function ValChar(ch) {

	if (ch=="0") return 0
	else if (ch=="1") return 1
	else if (ch=="2") return 2
	else if (ch=="3") return 3
	else if (ch=="4") return 4
	else if (ch=="5") return 5
	else if (ch=="6") return 6
	else if (ch=="7") return 7
	else if (ch=="8") return 8
	else if (ch=="9") return 9
	else return 10
}

//Verifica se o argumento é um CNPJ válido de 8 dígitos
function ChecaCNPJ8 (CKCNPJ) {
	
	var CNPJ = CKCNPJ;
	var NewCNPJ = "";
	//Elimina todos os espaços, pontos, barras e traços do CNPJ
	for (i=0;i<CNPJ.length;i++) { //>
		if (CNPJ.charAt(i) != " " && CNPJ.charAt(i) != "." && CNPJ.charAt(i) != "/" && CNPJ.charAt(i) != "-") {
			 NewCNPJ = NewCNPJ + CNPJ.charAt(i);
		}
	}
	//Verifica tamanho do CNPJ
	if (NewCNPJ.length!=8) {
		return false;
	}
	//verifica se todos os caracteres são numéricos
	var Numerico = false;
	var Numeros = "0123456789";
	for (i=0;i<NewCNPJ.length;i++) { //>
		Numerico = false;
		for (j=0;j<Numeros.length;j++) { //>
			if (NewCNPJ.charAt(i) == Numeros.charAt(j)) {
				Numerico = true;
				break;  
			}
		}
		if (!Numerico) {
			return false;
		}
	}
	//Calcula os dígitos verificadores
	var s1 = 0;
	aux = 0;
	soma = 0
	for (i=1;i<=8;i++) {
		//alert("i="+i+" - char(i-1)="+NewCNPJ.charAt(i-1));
		aux = (ValChar(NewCNPJ.charAt(i-1)))*((i % 2)+1);
		//alert ("aux="+aux);
		if (aux>9) {
			aux = aux-9;
			//alert ("aux="+aux);
			soma = soma + aux;
		}
		r1 = soma % 10;
		//alert("soma="+soma+" - resto="+r1);
		if (r1==0) {
			return (true)
		}
		else {
			return (false);
		}
	}
}

//Verifica se o argumento é um CNPJ válido
function ChecaCNPJ (CNPJ) {

		//ParametroCKCNPJ
		//CKCNPJ = '45445210000121'
		//var CKCNPJ = CNPJ1 + CNPJ2 +CNPJ3
		//var CNPJ = CKCNPJ;
		var NewCNPJ = "";
		//Verifica tamanho do CNPJ
		if (CNPJ.length!=14) {
		return false;
		}
	
	//Calcula os dígitos verificadores
	//Guarda os 12 primeiros digitos
	var DVCNPJ = CNPJ.substring(0,12);
	//calcula o primeiro digito verificador
	var s1 = 0;
	for (i=1;i<=4;i++) s1 = s1 + (ValChar(DVCNPJ.charAt(i-1))*(6-i));
	for (i=5;i<=12;i++) s1 = s1 + (ValChar(DVCNPJ.charAt(i-1))*(14-i));
	r1 = s1 % 11;
	if (r1<2) dv1=0;
	else dv1 = 11 - r1;
	//calcula o segundo digito verificador
	var s2 = dv1*2;
	for (i=1;i<=5;i++) s2 = s2 + (ValChar(DVCNPJ.charAt(i-1))*(7-i));
	for (i=6;i<=12;i++) s2 = s2 + (ValChar(DVCNPJ.charAt(i-1))*(15-i));
	r2 = s2 % 11;
	if (r2<2) dv2=0;
	else dv2 = 11 - r2;
	//junta os digitos verificadores
	var DV = "";
	DV = DV + dv1 + dv2;
	//guarda os digitos verificadores do CNPJ digitado (últimas duas posições no string)
	var NewDV = CNPJ.substring(12,14)
	if (NewDV==DV) { //se o DV calculado for igual ao digitado, retorna true
		return true
	}
	else {
		return false
	}

function ChecaForm(theField) {
	
	if (a!="") { //se o campo CNPJCPF tiver algum valor, verifica
	    if (a.length > 14) {  //verifica se o tamanho não é maior que 14
			alert("O CNPJ deve ter no máximo 14 dígitos.");
			//theField.focus();
			return (false);
		}
		// verifica se todos os caracteres digitados são numeros
		var checkOK = "0123456789-";
		var checkStr = a;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
		for (i = 0;  i < checkStr.length;  i++) {
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++) {
				if (ch == checkOK.charAt(j)) {
					break;
				}
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
				allNum += ch;
			}
		}
	}
    if (!allValid) {
		alert("Os campos do CNPJ devem conter apenas números.");
		//theField.focus();
		return (false);
    }
    //checa se o campo é CPF válido, retorna true e envia o formulário
    if (ChecaCNPJ(a)||ChecaCNPJ8(a)) {
		return (true);
	}
    else {
		return (false);
    }
  }
}

////////////////////////////////////////////////////////////////////////////
function datatest(dataent)
{
	var dia = dataent.substring(0,2);
	var mes = dataent.substring(3,5);
	var ano = dataent.substring(6,10);
	var barra_1 = dataent.substring(2,3);
	var barra_2 = dataent.substring(5,6);
		
	return (isDate(ano, mes, dia)) && (barra_1=="/") && (barra_2=="/");
	
}

/////////////////////////////////////////////////////////////////////////////

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters are numbers; 
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true 
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}



// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}


// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    //var num = parseInt (s); //Problemas ao avaliar 08 e 09....
    var num = eval (s);
    return ((num >= a) && (num <= b));
}





// isYear (STRING s [, BOOLEAN emptyOK])
// 
// isYear returns true if string s is a valid 
// Year number.  Must be 2 or 4 digits only.
// 
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// And yes, this function is not Year 10000 compliant, but 
// because I am giving you 8003 years of advance notice,
// I don't feel very guilty about this ...
//
// For B.C. compliance, write your own function. ;->
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}



// isDay (STRING s [, BOOLEAN emptyOK])
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}


// daysInFebruary (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day 
// form a valid date.
// 

function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Código para validação de textareas (Inserido em 03/01/2001 - Miklós ) ////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

bname = navigator.appName;
bver = parseInt(navigator.appVersion);
blegal = ((bname == "Netscape" && bver >= 3) || (bname == "Microsoft Internet Explorer" && bver >= 4));

////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Código para Mascara em Data (Inserido em 27/09/2002 - Icaro ) ////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////


//Mascara de data completa dd/mm/aaaa
function FormataDataComp(pForm,pCampo,pTamMax,pPos1,pPos2,pTeclaPres){
 var wTecla, wVr, wTam;
 
       // alert(pForm[pCampo].value);
  
 wTecla = pTeclaPres.keyCode;
 wVr = pForm[pCampo].value;
 wVr = wVr.toString().replace( "-", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( "/", "" );
 wVr = wVr.toString().replace( "/", "" );
 wTam = wVr.length ;

 if (wTam < pTamMax && wTecla != 8) { 
    wTam = wVr.length + 1 ; 
 }

 if (wTecla == 8 ) { 
    wTam = wTam - 1 ; 
 }
   
 if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
  if ( wTam <= 2 ){
    pForm[pCampo].value = wVr ;
  }
//  if (wTam > pPosTraco && wTam <= pTamMax) {
//        wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
// }
  if ( wTam == pTamMax){
        wVr = wVr.substr( 0, wTam - pPos1 ) + '/' + wVr.substr(wTam - pPos1, 2) + '/' + wVr.substr(wTam - pPos2, wTam);
  }
  pForm[pCampo].value = wVr;
 
 }

}
//Fim mascara data completa dd/mm/aaaa

////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Código para Mascara em Hora (Inserido em 23/10/2002 - Flavio ) ////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

//Mascara de hora completa hh:mm
function FormataHoraComp(pForm,pCampo,pTamMax,pPos,pTeclaPres){
 var wTecla, wVr, wTam;
 
       // alert(pForm[pCampo].value);
  
 wTecla = pTeclaPres.keyCode;
 wVr = pForm[pCampo].value;
 wVr = wVr.toString().replace( "-", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( ":", "" );
 wVr = wVr.toString().replace( ":", "" );
 wTam = wVr.length ;

 if (wTam < pTamMax && wTecla != 8) { 
    wTam = wVr.length + 1 ; 
 }

 if (wTecla == 8 ) { 
    wTam = wTam - 1 ; 
 }
   
 if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
  if ( wTam <= 2 ){
    pForm[pCampo].value = wVr ;
  }
//  if (wTam > pPosTraco && wTam <= pTamMax) {
//        wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
// }
  if ( wTam == pTamMax){
        wVr = wVr.substr( 0, wTam - pPos ) + ':' + wVr.substr(wTam - pPos, wTam);
  }
  pForm[pCampo].value = wVr;
 
 }

}
//Fim mascara hora completa hh:mm

////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Código para Mascara de preço (Inserido em 22/07/2003 - Flavio ) ////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

//Bloqueio de backspace e delete
function VerificarTecla(Form,Campo,Tecla)
{
  var CodigoTecla;
  
  CodigoTecla = Tecla.keyCode
  
  if (CodigoTecla == 8 || CodigoTecla == 46)
  {
    Form[Campo].value = "";
  }
  else if (CodigoTecla == 188)
  {
    Form[Campo].value = Form[Campo].value.toString().replace(",", "");
  }
  else if (CodigoTecla == 190)
  {
    Form[Campo].value = Form[Campo].value.toString().replace(".", "");
  }
}
//Fim do bloqueio de backspace e delete

//Limpar campo de preço
function ApagarPreco(Form,Campo)
{
  Form[Campo].value = ""
}
//Fim do limpar campo de preço

//Máscara de preço
function FormatarPreco(Form,Campo,TamanhoMaximo,TamanhoValor,Posicao,Tecla)
{
  var Valor;
  var CodigoTecla;
  Valor = Form[Campo].value;
  CodigoTecla = Tecla.keyCode
  
  if (TamanhoValor < 10)
  {
    Valor = Valor.toString().replace(".", "");
    Valor = Valor.toString().replace(",", "");
  }
  
  if (CodigoTecla == 8 || CodigoTecla >= 48 && CodigoTecla <= 57 || CodigoTecla >= 96 && CodigoTecla <= 105)
  {
    if (CodigoTecla <= 2)
    {
      Form[Campo].value = Valor;
    }
  }
  
  if (TamanhoValor > 1 && TamanhoValor < 10)
  {
    if (TamanhoValor > 2)
    {
      Posicao = 2
    }
    
    if (((TamanhoValor - 1) == 7) || ((TamanhoValor - 1) == 8))
    {
      Posicao = 3
    }
    
    Valor = Valor.toString().replace(".", "");
    Valor = Valor.toString().replace(",", "");
    Valor = Valor.substr(0, TamanhoValor - Posicao) + "," + Valor.substr(TamanhoValor - Posicao, TamanhoValor);
    
    if (TamanhoValor == 6)
    {
      Valor = Valor.substr(0, 1) + "." + Valor.substr(1, TamanhoValor);
    }
    else if ((TamanhoValor - 1) == 7)
    {
      Valor = Valor.substr(0, 2) + "." + Valor.substr(2, TamanhoValor);
    }
    else if ((TamanhoValor - 1) == 8)
    {
      Valor = Valor.substr(0, 3) + "." + Valor.substr(3, TamanhoValor);
    }
  }
  
  Form[Campo].value = Valor;
}
//Fim da máscara de preço

////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Códigos de data-hora (Inserido em 28/09/2002 - Icaro ) ////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////


//Funcao para checar data
function Checa_Data(FORMULARIO,CAMPO){
	if(!isEmpty(FORMULARIO[CAMPO].value)){
		if(!datatest(FORMULARIO[CAMPO].value)) {
			alert('Data inválida')
			FORMULARIO[CAMPO].select()  
			FORMULARIO[CAMPO].focus()
			return
		}
	}
	
}
//Fim da funcao para checar data

//Funcao para checar hora
function Checa_Hora(FORMULARIO,CAMPO){
	var tempo
	var hora
	var minuto	
	
	tempo = FORMULARIO[CAMPO].value
	if(!isEmpty(FORMULARIO[CAMPO].value)){	
		if (tempo.length != 5){
			alert('Hora inválida')
			FORMULARIO[CAMPO].select()  
			FORMULARIO[CAMPO].focus()
			return	
		}
		pontos = tempo.substr(2,1)
		if (pontos != ':'){
			alert('Hora inválida')
			FORMULARIO[CAMPO].select()  
			FORMULARIO[CAMPO].focus()
			return			
		}
		hora = tempo.substr(0,2)
		if(!isInteger(hora)){
			alert('Hora inválida')
			FORMULARIO[CAMPO].select()  
			FORMULARIO[CAMPO].focus()
			return			
		}
		minuto = tempo.substr(3,2)
		if(!isInteger(minuto)){
			alert('Hora inválida')
			FORMULARIO[CAMPO].select()  
			FORMULARIO[CAMPO].focus()
			return			
		}		
		if (hora < 0 || hora > 23){
			alert('Hora inválida')
			FORMULARIO[CAMPO].select()  
			FORMULARIO[CAMPO].focus()
			return	
		}
		if (minuto < 0 || minuto > 59){
			alert('Hora inválida')
			FORMULARIO[CAMPO].select()  
			FORMULARIO[CAMPO].focus()
			return	
		}
	}	
}
//Fim da funcao para checar hora

//Funcao que compara 2 datas, utilizar apos a funcao checa_data para ter
//certeza que as datas sao validas.
function Consiste_Datas(data1,data2){
	
	ano_data1 = data1.substr(6,4);
	ano_data2 = data2.substr(6,4);
	
	mes_data1 = data1.substr(3,2);
	mes_data2 = data2.substr(3,2);
	
	dia_data1 = data1.substr(0,2);
	dia_data2 = data2.substr(0,2);
	
	checa_ano = parseFloat(ano_data2) - parseFloat(ano_data1);
	checa_mes = parseFloat(mes_data2) - parseFloat(mes_data1);
	checa_dia = parseFloat(dia_data2) - parseFloat(dia_data1);
	
	if (checa_ano > 0){
		return true;
	}else if(checa_mes > 0){
		return true;
	}else if(checa_dia > 0){
		return true;
	}else{
		return false;
	}		
}
//Fim da funcao

//Função para delimitar caracteres no textarea
function checkLength(form,name,charLimit){
        var count = countChars(form,name);
        var rc = true;
        if( count > charLimit ){
                alert("Sua mensagem possui "+count+" e excede "+charLimit+" caracteres.  \nRevise sua mensagem.");
                rc = false;
        }
        return rc;
}

function countChars(form,name){
        if( blegal ){
				var count = form.item(name).value.length;
                return count;
        } else {
                return 0;
        }
}
//Fim da função