<!--
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
	var theCells = null;

	// 1. Pointer and mark feature are disabled or the browser can't get the
	//    row -> exits
	if ((thePointerColor == '' && theMarkColor == '')
		|| typeof(theRow.style) == 'undefined') {
		return false;
	}

	// 2. Gets the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	} else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	} else {
		return false;
	}

	// 3. Gets the current color...
	var rowCellsCnt = theCells.length;
	var domDetect = null;
	var currentColor = null;
	var newColor = null;
	// 3.1 ... with DOM compatible browsers except Opera that does not return
	//         valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined'
		&& typeof(theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[0].getAttribute('bgcolor');
		domDetect = true;
	}
		// 3.2 ... with other browsers
	else {
		currentColor = theCells[0].style.backgroundColor;
		domDetect = false;
	} // end 3

	// 4. Defines the new color
	// 4.1 Current color is the default one
	if (currentColor == ''
		|| currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
		if (theAction == 'over' && thePointerColor != '') {
			newColor = thePointerColor;
		} else if (theAction == 'click' && theMarkColor != '') {
			newColor = theMarkColor;
			marked_row[theRowNum] = true;
		}
	}
		// 4.1.2 Current color is the pointer one
	else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
		&& (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
		if (theAction == 'out') {
			newColor = theDefaultColor;
		} else if (theAction == 'click' && theMarkColor != '') {
			newColor = theMarkColor;
			marked_row[theRowNum] = true;
		}
	}
		// 4.1.3 Current color is the marker one
	else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
		if (theAction == 'click') {
			newColor = (thePointerColor != '')
				? thePointerColor
				: theDefaultColor;
			marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
				? true
				: null;
		}
	} // end 4

	// 5. Sets the new color...
	if (newColor) {
		var c = null;
		// 5.1 ... with DOM compatible browsers except Opera
		if (domDetect) {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', newColor, 0);
			} // end for
		}
			// 5.2 ... with other browsers
		else {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = newColor;
			}
		}
	} // end 5

	return true;
}

// end of the 'setPointer()' function


/****************************************************************
* VALIDA CAMPO VAZIO                                            *
*****************************************************************
* EstaVazio(nome)
*/

function EstaVazio(campo) {
	if (campo > "") {
		return false;
	} else {
		return true;
	}
}

/****************************************************************
* VALIDA CAMPO NUMERICO                                         *
*****************************************************************
* (checkNum(nr_endereco,false,"") == false) SO ACEITA NUMEROS
* (checkNum(nr_endereco,false,"-") == false) ACEITA TAMBEM O -
*/

function checkNum(campo, flgChar, charac) {
	for (var i = 0; i < campo.length; i++) {
		var ch = campo.substring(i, i + 1);
		if (flgChar == true) {
			if (ch != charac) {
				if (ch < "0" || ch > "9")
					return false;
			}
		} else {
			if (ch < "0" || ch > "9")
				return false;
		}
	}
	return true;
}

/****************************************************************
* VALIDACAO DE CPF                                              *
*****************************************************************
* checaCPF(document.cadastro.cpf.value)
*/

function checaCPF(CPF) {
	if (CPF.length != 11 ||
		CPF == "00000000000" || CPF == "11111111111" || CPF == "33333333333" ||
			CPF == "44444444444" || CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
				CPF == "88888888888" || CPF == "99999999999" || CPF == "01234567890") {
		return true;
	} else {
		soma = 0;
		for (i = 0; i < 9; i++) {
			soma += parseInt(CPF.charAt(i)) * (10 - i);
		}
		resto = 11 - (soma % 11);
		if (resto > 9) {
			resto = 0;
		}
		if (resto != parseInt(CPF.charAt(9))) {
			return true;
		} else {
			soma = 0;
			for (i = 0; i < 10; i++) {
				soma += parseInt(CPF.charAt(i)) * (11 - i);
			}
			resto = 11 - (soma % 11);
			if (resto > 9) {
				resto = 0;
			}
			if (resto != parseInt(CPF.charAt(10))) {
				return true;
			}
		}
	}
	return false;
}

/****************************************************************
* VALIDACAO DE CNPJ                                             *
*****************************************************************
* checaCNPJ(document.cadastro.cpf.value)
*/

function checaCNPJ(CNPJ) {
	if (CNPJ.length != 14 ||
		CNPJ == "11111111111111" || CNPJ == "22222222222222" || CNPJ == "33333333333333" ||
			CNPJ == "44444444444444" || CNPJ == "55555555555555" || CNPJ == "66666666666666" || CNPJ == "77777777777777" ||
				CNPJ == "88888888888888" || CNPJ == "99999999999999" || CNPJ == "01234567890123") {
		return true;
	} else {
		var dig1 = 0;
		var dig2 = 0;
		var x;
		var Mult1 = '543298765432';
		var Mult2 = '6543298765432';
		for (x = 0; x <= 11; x++) {
			dig1 = dig1 + (parseInt(CNPJ.slice(x, x + 1)) * parseInt(Mult1.slice(x, x + 1)));
		}
		for (x = 0; x <= 12; x++) {
			dig2 = dig2 + (parseInt(CNPJ.slice(x, x + 1)) * parseInt(Mult2.slice(x, x + 1)));
		}
		dig1 = (dig1 * 10) % 11;
		dig2 = (dig2 * 10) % 11;
		if (dig1 == 10) {
			dig1 = 0;
		}
		if (dig2 == 10) {
			dig2 = 0;
		}
		if (dig1 != parseInt(CNPJ.slice(12, 13))) {
			return true;
		} else {
			if (dig2 != parseInt(CNPJ.slice(13, 14))) {
				return true;
			} else {
				return false;
			}
		}
	}
}

/****************************************************************
* VALIDACAO DE EMAIL                                            *
*****************************************************************
* (!IsEmail(trim(document.cadastro.email.value)))
*/

function IsEmail(str) {
	//verifica se o e-mail digitado é válido 
	var strAlfa = "ABCDEFGHIJKLMNOPQRSTUWVXYZ";
	var strNum = "0123456789";
	var strSpecial = "_.-@/";
	var strValid = strAlfa + strNum + strSpecial;
	var email = str.toUpperCase();
	//verifica se os caracteres do e-mail são válidos
	for (i = 0; i < email.length; i++) {
		if (strValid.indexOf(email.charAt(i)) < 0) {
			return false;
		}
	}
	var strC = "@.";
	//verifica se o e-mail contém @ e . (caracteres obrigatórios)
	for (i = 0; i < strC.length; i++) {
		if (email.indexOf(strC.charAt(i)) < 0)
			return false;
	}
	if (email.indexOf("@") != email.lastIndexOf("@"))
		return false;
	if (email.indexOf("@") > email.lastIndexOf("."))
		return false;
	if (email.charAt(email.indexOf("@") + 1) == ".")
		return false;
	if (!(email.indexOf("@") != 0 && email.lastIndexOf(".") != email.length - 1))
		return false;
	return true;
}


/****************************************************************
* LIMPA ESPACOS NA VARIAVEL                                     *
*****************************************************************
* trim(document.cadastro.senha.value) != ""
*/

function trim(theString) {
	var aString = theString;
	var newString = "";
	var kBlank = " ";
	if (aString.indexOf(kBlank) >= 0) {
		for (var i = 0; i < aString.length; i++)
			if (aString.charAt(i) != kBlank)
				break;

		for (var j = aString.length - 1; j >= 0; j--)
			if (aString.charAt(j) != kBlank)
				break;

		if (i == aString.length && j == -1)
			newString = "";
		else if (i != 0 || j != aString.length - 1)
			newString = trim(aString.substring(i, j + 1));
		else
			newString = aString.charAt(i) + trim(aString.substring(i + 1, j + 1)) + aString.charAt(j + 1);
	} else
		newString = aString;

	return newString;
}

// VALIDA CARACTER

function IsStrValid(strToValidate, strValidChar) {
	var flag;
	var i;
	flag = true;

	if ((trim(strToValidate) != "") && (trim(strValidChar) != "")) {
		for (i = 0; i < strToValidate.length; i++) {
			if (strValidChar.indexOf(strToValidate.charAt(i).toLowerCase()) == -1) {
				flag = false;
				return flag;
			}
		}
	} else flag = false;

	return flag;
}

/****************************************************************
* LIMPA CAMPO DE EMAIL                                          *
*****************************************************************
*  onKeyUp="javascript:limpacampo(cadastro.email);"
*/
var mikExp1 = /[$\ \\\#%\^\&\*\(\)\[\]\+\{\}\`\~\=\|\:\;\'\"\,\>\<\!\/\\]/ ;
var mikExp2 = /[$\\\\#%\^\&\*\(\)\[\]\+\{\}\`\~\=\|\:\;\'\"\,\>\<\!\/\\]/ ;

function limpacampo(val, esp) {
	var strPass = val.value;
	var strLength = strPass.length;
	var lchar = val.value.charAt((strLength) - 1);
	if (esp == 1) {
		var mikExp = mikExp1;
	} else {
		var mikExp = mikExp2;
	}
	if (lchar.search(mikExp) != -1) {
		var tst = val.value.substring(0, (strLength) - 1);
		val.value = tst;
	}
}

/****************************************************************
* FORMATA CAMPOS                                                *
*****************************************************************
* 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:
* CEP -> 99999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* C/C -> 999999-!
* Tel -> (99) 9999-9999
***/

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla;

	var browser_type = navigator.appName;
	if (browser_type != "Microsoft Internet Explorer")
		return true;

	if (document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	} else if (document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	}
	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(")", "");
	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));
		} else { // qualquer caracter...
			return true;
		}
	} else {
		return true;
	}
}

/****************************************************************
* LIMPA CAMPO DE EMAIL                                          *
*****************************************************************
*  (!isHour(trim(document.cadastro.email.value)))
*/

function IsHour(lStrHorario) {
	var lHora, lMinuto, lSegundo, lPrimeiroSeparador, lSegundoSeparador;
	if (lStrHorario.length != 8) {
		return false;
	}
	lHora = lStrHorario.substring(0, 2);
	lPrimeiroSeparador = lStrHorario.substring(2, 1);
	if (lPrimeiroSeparador != ':') {
		return false;
	}
	lMinuto = lStrHorario.substring(3, 2);
	if (lStrHorario.length > 5) {
		lSegundoSeparador = lStrHorario.substring(5, 1);
		if (lSegundoSeparador != ':') {
			return false;
		}
		lSegundo = lStrHorario.substring(6, 2);
		if (lSegundo.length < 2) {
			return false;
		}
	}
	//Valida Hora
	if (!(fJSIsNumber(lHora))) {
		return false;
	}
	if (!(fJSInRange(lHora, 0, 23))) {
		return false;
	}
	//Valida Minuto
	if (!(fJSIsNumber(lMinuto))) {
		return false;
	}
	if (!(fJSInRange(lMinuto, 0, 59))) {
		return false;
	}
	//Valida Segundo
	if (lStrHorario.length > 5) {
		if (!(fJSIsNumber(lSegundo))) {
			return false;
		}
		if (!(fJSInRange(lSegundo, 0, 59))) {
			return false;
		}
	}
	return true;
}

//Funcoes utilizadas para validação do horario

function fJSInRange(inputStr, ini, fim) {
	var num = parseInt(inputStr, 10);
	if (num < ini || num > fim) {
		return false;
	}
	return true;
}

function fJSIsNumber(num) {
	var numeros = '0123456789,';
	var valor = num.toString();
	var lCount = 0;
	for (var i = 0; i < valor.length; i++) {
		if (numeros.indexOf(valor.substring(i, 1)) == -1) {
			return false;
		}
		if (valor.substring(i, 1) == ',') {
			lCount += 1;
			if (lCount > 1) {
				return false;
			}
		}
	}
	return true;
}

/****************************************************************
* VALIDA DATA                                                   *
*****************************************************************/

function IsDate(sdata) {
	day2 = sdata.substring(0, 2);
	month2 = sdata.substring(3, 2);
	year2 = sdata.substring(6, 4);
	if ((sdata.substring(2, 1) != "/") || (sdata.substring(5, 1) != "/")) {
		day2 = "";
		month2 = "";
		year2 = "";
	}
	var DayArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var MonthArray = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
	var inpDate = day2 + month2 + year2;
	var filter = /^[0-9]{2}[0-9]{2}[0-9]{4}$/ ;
	//Check ddmmyyyy date supplied
	if (!filter.test(inpDate)) {
		return false;
	}
	/* Check Valid Month */
	filter = /01|02|03|04|05|06|07|08|09|10|11|12/ ;
	if (!filter.test(month2)) {
		return false;
	}
	/* Check For Leap Year */
	var N = Number(year2);
	if ((N % 4 == 0 && N % 100 != 0) || (N % 400 == 0)) {
		DayArray[1] = 29;
	}
	/* Check for valid days for month */
	for (var ctr = 0; ctr <= 11; ctr++) {
		if (MonthArray[ctr] == month2) {
			if (day2 <= DayArray[ctr] && day2 > 0) {
				inpDate = day2 + '/' + month2 + '/' + year2;
				return true;
			}
			return false;
		}
	}
}

function FormataValor(fld, milSep, decSep, e) {
	var browser_type = navigator.appName;
	if (browser_type != "Microsoft Internet Explorer")
		return true;
	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;
	if (whichCode == 13) return true; // Enter
	key = String.fromCharCode(whichCode); // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false; // Not a valid key
	len = fld.value.length;
	if (len < 16) {
		for (i = 0; i < len; i++)
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
		aux = '';
		for (; i < len; i++)
			if (strCheck.indexOf(fld.value.charAt(i)) != -1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0' + decSep + '0' + aux;
		if (len == 2) fld.value = '0' + decSep + aux;
		if (len > 2) {
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--) {
				if (j == 3) {
					aux2 += milSep;
					j = 0;
				}
				aux2 += aux.charAt(i);
				j++;
			}
			fld.value = '';
			len2 = aux2.length;
			for (i = len2 - 1; i >= 0; i--)
				fld.value += aux2.charAt(i);
			fld.value += decSep + aux.substring(len - 2, len);
		}
	}
	return false;
}

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function printPage() {
	if (pr) // NS4, IE5
		window.print();
	else // other browsers
		alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
	return false;
}

// impede que outros sites insiram o site em frames
if (top.frames.length != 0) {
	top.location = self.document.location;
}

function mOvr(src, clrOver) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}

function mOut(src, clrIn) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}

function openPopup(windowURL, windowName, windowFeatures) {
	return window.open(windowURL, windowName, windowFeatures);
}

function getElement(e) {
	if (document.layers) {
		f = (f) ? f : self;
		if (f.document.layers[e]) {
			return f.document.layers[e];
		}
		for (W = 0; i < f.document.layers.length; W++) {
			return (getElement(e, f.document.layers[W]));
		}
	}

	if (document.all) {
		return document.all[e];
	}

	return document.getElementById(e);
}

function getElementContent(id) {
	return getElement(id).innerHTML;
}

var mikExp = /[$\-\@\?\¨\ÃÕÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÇãõáéíóúàèìòùâêîôûç\º\ª\#\%\^\&\*\(\)\[\]\+\_\{\}\`\´\~\=\|\:\;\'\"\.\,\>\<\!\/\\]/ ;

function blockchar(val) {
	var strPass = val.value;
	var strLength = strPass.length;
	var lchar = val.value.charAt((strLength) - 1);
	if (lchar.search(mikExp) != -1) {
		var tst = val.value.substring(0, (strLength) - 1);
		val.value = tst;
	}
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
} 
//-->
