﻿function fncRollOverFont(iThis,IOverB,IOverF){ 
var iOutB = iThis.style.backgroundColor;
var iOutF = iThis.style.color;
	iThis.style.backgroundColor=IOverB; 
	iThis.style.color=IOverF; 
	iThis.onmouseout=function(){ 
		iThis.style.backgroundColor=iOutB; 
		iThis.style.color=iOutF; 
	}
}
function fncRollOver(iThis,IOverB){
var iOutB = iThis.style.backgroundColor;
	iThis.style.backgroundColor=IOverB;
	iThis.onmouseout=function(){ 
		iThis.style.backgroundColor=iOutB;
	}
}
function fncButtonOver(iThis,iDir,iOver){
var iOut = iThis.src;
	iThis.src=iDir+iOver; 
	iThis.onmousedown=function(){
		iThis.src=iOut; 
	}
	iThis.onmouseout=function(){
		iThis.src=iOut; 
	}
}
function fncButtonClick(iThis,iDir,iOver,iClick){
var iOut = iThis.src;
	iThis.src=iDir+iOver;
	iThis.onmousedown=function(){
		iThis.src=iDir + iClick;
	}
	iThis.onmouseout=function(){
		iThis.src=iOut; 
	}
}
function fncBtn2(oThis,iPonto,IOver,IOut) { 
	oThis.src=iPonto+'img/button/' + IOver;
	oThis.onmouseout=function() {
		oThis.src=iPonto+'img/button/' + IOut;
	}
}
function fncBtn3(oThis,iPonto,IOver,IOut,IClick) {
	oThis.src=iPonto + 'img/button/' + IOver;
	oThis.onmousedown=function() {
		oThis.src=iPonto + 'img/button/' + IClick;
	}
	oThis.onmouseout=function() {
		oThis.src=iPonto + 'img/button/' + IOut;
	}
}

//---------------------------------------
//Funções para Verficação
//---------------------------------------
function fncEMailCheckChar(e){
	e = e.toLowerCase();
	var validChar = "0987654321abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ.-_@";
	for(var i = 0; i < e.length; i++){
		if (validChar.indexOf(e.charAt(i)) == -1) return false
	}
return true;
}
function fncEMailCheckCharKeyPress(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var caract = new RegExp(/^[a-z@.-_\d\b\t]*$/);
	var checkKey = caract.test(String.fromCharCode(keyCode));
	if(!checkKey){
		alert("Caracter inválido: " +String.fromCharCode(keyCode)+"\n Os caracteres especiais válidos: \n  _ (underline) e - (sinal de menos) ");
		keyCode=0;
		return false;
	}
}
function fncCheckCharKeyPress(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var caract = new RegExp(/^[-_ & \w\d\b\t]*$/);
	var checkKey = caract.test(String.fromCharCode(keyCode));
	if(!checkKey){
		alert("Caracter inválido: " +String.fromCharCode(keyCode)+"\n Os caracteres especiais válidos: \n  _ (underline) e - (sinal de menos) ");
		keyCode=0;
		return false;
	}
}
function fncBoqueiaTC(e) {
var BACKSPACE=8;
var DEL=46;
var TAB=9;
var tecla;
	
	if(window.event) {
		tecla = e.keyCode;
	}else if(e.which) {
		tecla = e.which;
	}
	if ((tecla == BACKSPACE )||(tecla == DEL)||(tecla == TAB)) {
		return true;
	}
	if ((tecla==45)||(tecla==46)||((tecla>47)&&(tecla<58))||((tecla>64)&&(tecla<91))||(tecla==95)||((tecla>96)&&(tecla<123))) {
		return true;
	}else{
		return false;
	}
}
function verificaChar(strg){
var validChar = "0987654321ABCDEFGHIJKLMNOPRSTUVWYXZabcdefghijklmnopqrstuvwyxz.-_@";
	for (i=0;i<strg.length;i++){
		if (validChar.indexOf(strg.charAt(i)) == -1) {return true}; 
	}
}
function fncCheckCampoByName(iNome,iText){
	var boo = document.getElementsByName(iNome)[0].value.length==0;
	var msg=IIF(boo,'Favor preencher no campo ' + iText + ' \n','');
	document.getElementsByName(iNome)[0].style.borderColor=IIF(boo,'red','');
	document.getElementsByName(iNome)[0].style.borderStyle=IIF(boo,'solid','');
	return msg;
}
function fncCheckCampoIsNaNByName(iNome,iText){
	if (document.getElementsByName(iNome)[0].value.length>0){
		var boo = isNaN(document.getElementsByName(iNome)[0].value.replace(',','.'));
		var msg=IIF(boo,'Favor preencher no campo ' + iText + ' em valor numérico \n','');
		document.getElementsByName(iNome)[0].style.borderColor=IIF(boo,'red','');
		document.getElementsByName(iNome)[0].style.borderStyle=IIF(boo,'solid','');
		return msg;
	}
	return '';
}
function fncCheckSelectByName(iNome,iText){
	var boo = document.getElementsByName(iNome)[0].value=='';
	var msg=IIF(boo,'Favor selecionar no ' + iText + ' \n','');
	document.getElementsByName(iNome)[0].style.borderColor=IIF(boo,'red','');
	document.getElementsByName(iNome)[0].style.borderStyle=IIF(boo,'solid','');
	return msg;
}
function IIF(boo,iTrue,iFalse){
	if (boo){return iTrue;}else {return iFalse;}
}

//---------------------------------------
//POPUP
//---------------------------------------
function PopUpFechar(){
    document.getElementById('divAviso').style.display = 'none';
}
function PopUpAbrir(){
    document.getElementById('divAviso').style.display = 'block';
    setTimeout ("PopUpFechar()", 9000);
}
//---------------------------------------
//Data
//---------------------------------------
function ajustar_data(input, evento){
var BACKSPACE=8;
var DEL=46;
var FRENTE=39;
var TRAS=37;
var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
	if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)) {
		return true;
	}
	if (tecla==13) return false;

	if ((tecla<48)||(tecla>57)) {
		evento.returnValue = false;
		return false;
	}else {
		if ((input.value.length==2)||(input.value.length==5)) {
			input.value=input.value + "/" ;
		}
	}

return true;
}

function editadata(strCampo,tam) {
var i;
var j=0;
var nTamanho=strCampo.length+1;
var szCampo="";
	for (i=nTamanho;i>=0;i--){
		if (isDigit(strCampo.charAt(i))){
			szCampo = strCampo.charAt(i) + szCampo;
		    j++;
			if (j > tam) break;
        }
	}
	if (szCampo.length < tam) {
		for (i = szCampo.length;i<tam;i++){
			szCampo = "0" + szCampo;
		}
	}
	if (j==0) return "";

return (szCampo.substr(2,2)+"/"+szCampo.substr(4,2)+"/"+szCampo.substr(6,2));
}
function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}
//---------------------------------------
//Another
//---------------------------------------

//Paginação das tabelas
function TablePaging(formName,pag){
document.forms[formName].action=formName + '.aspx?pag=' + pag;
document.forms[formName].submit();
}
//---------------------------------------
