/**
 * @author 		= Luiz Gustavo Botardo
 * @copyright 	= Luiz Gustavo Botardo
 * @name 		= Funções JavaScript Suissa
 * @version 	= 9.04.01
 */

function correctPNG() {
	if (navigator.appName.indexOf('Microsoft') != -1){
		for(var i=0; i<document.images.length; i++) {
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}

if (window.attachEvent) { window.attachEvent("onload", correctPNG); }

function alteraMenuLateral() {

	var menuLateral    = document.getElementById('menulateral');
	var txtEscondeMenu = document.getElementById('txtEscondeMenu');
	if (menuLateral.style.display == "block") {
		menuLateral.style.display =  "none";
		txtEscondeMenu.innerHTML  = '<img src="imgs/abaesconde2.jpg" style="">';
		txtEscondeMenu.title = "Mostrar menu lateral.";
		return false;
	}
	if (menuLateral.style.display == "none") {
		menuLateral.style.display =  "block";
		txtEscondeMenu.innerHTML  = '<img src="imgs/abaesconde.jpg" style="">';
		txtEscondeMenu.title = "Esconder menu lateral.";
		return false;
	}
	
}


/* FORMAS DE USAR AS FUNÇÔES ABAIXO
function Valida(){
	if(document.formulario.nome.value == ""){
		alert("Preencha o nome da pessoa");
	}
	if(verificaData("data_nascimento", 1) == false){ return false }
	if(verificaHora("hora_compromisso", 1) == false){ return false }
	if(verificaCEP("cep", 0) == false){ return false }
	if(verificaEmail("email", 0) == false){ return false }
	if(verificaEmail("descricao", 4000) == false){ return false }
}

OU

<input name="data" type="text" id="data" maxlength="10" onKeypress="return ajustaData(this, event);"> 
<input name="hora" type="text" id="hora" maxlength="5" onKeypress="return ajustaHora(this, event);"> 
<input name="cep" type="text" id="cep" maxlength="9" onKeypress="return ajustaCEP(this, event);">
<input name="numero" type="text" id="numero" maxlength="20" onKeypress="return bloqueiaCaracteres(event);""> 
*/

//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 verificaData(data, obrigatorio){  
	//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 strdata = data.value;  
	if((obrigatorio == 1) || (obrigatorio == 0 && strdata != "")){  
		//Verifica a quantidade de digitos informada esta correta.  
		if (strdata.length != 10){  
			alert("Formato da data não é válido. Formato correto: dd/mm/aaaa.");  
			data.focus();  
			return false  
		}  
		//Verifica máscara da data  
		if ("/" != strdata.substr(2,1) || "/" != strdata.substr(5,1)){  
			alert("Formato da data não é válido. Formato correto: dd/mm/aaaa.");  
			data.focus();  
			return false  
		}  
		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){  
			alert("Formato do dia não é válido.");  
			data.focus();  
  			return false  
		}  
		if (mes == 4 || mes == 6 || mes == 9 || mes == 11){  
			if (dia == "31"){  
				alert("O mês informado não possui 31 dias.");  
				data.focus();  
				return false  
			}  
		}  
  		if (mes == "02"){  
			bissexto = ano % 4;  
			if (bissexto == 0){  
				if (dia > 29){  
				alert("O mês informado possui somente 29 dias.");  
				data.focus();  
				return false  
			}  
			}else{  
				if (dia > 28){  
					alert("O mês informado possui somente 28 dias.");  
					data.focus();  
					return false  
				}  
			}	  
		}  
		//Verifica o mês  
		if (isNaN(mes) || mes > 12 || mes < 1){  
			alert("Formato do mês não é válido.");  
			data.focus();  
			return false  
		}  
		//Verifica o ano  
		if (isNaN(ano)){  
			alert("Formato do ano não é válido.");  
			data.focus();  
  			return false  
  		}  
	}  
}  

function comparaDatas(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 verificaHora(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.value = '';
	 		hora.focus();  
		 	return false  
		}  
		if(hora.value.substr(0,2) > 23 || isNaN(hora.value.substr(0,2))){  
			alert("Formato da hora inválido.");  
	 		hora.value = '';
			hora.focus();  
	 		return false  
		}  
		if(hora.value.substr(3,2) > 59 || isNaN(hora.value.substr(3,2))){  
	 		alert("Formato do minuto inválido.");  
	 		hora.value = '';
	 		hora.focus();  
	 		return false  
	 	}  
	}  
} 

function verificaEmail(email, obrigatorio){  
	//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não  
	var email = document.getElementById(email);  
	if((obrigatorio == 1) || (obrigatorio == 0 && email.value != "")){  
		if(!email.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi)){  
			alert("Informe um e-mail válido");  
			email.focus();  
			return false  
		}  
	}  
}  

function verificaCPF(cpf, obrigatorio) {
	var numcpf = document.getElementById(cpf).value;
	
	for (i=0; i<cpf.length; i++) {
		numcpf = numcpf.replace(".","");
		numcpf = numcpf.replace("-","");
	}

	valor = true;
	alerta = new String;
	if (numcpf.length < 11) alerta += "São necessários 11 dígitos para verificação do CPF. \n"; 
	var nonNumbers = /\D/;
	if (numcpf == "00000000000" || numcpf == "11111111111" || numcpf == "22222222222" || numcpf == "33333333333" || numcpf == "44444444444" || numcpf == "55555555555" || numcpf == "66666666666" || numcpf == "77777777777" || numcpf == "88888888888" || numcpf == "99999999999"){
		  alerta += "Número de CPF inválido!"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = numcpf.charAt(i);
		if (i < 9) b += (a[i] *  --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((numcpf.charAt(9) != a[9]) || (numcpf.charAt(10) != a[10])){
		alerta += "CPF com dígito verificador inválido.";
	}
	if (alerta.length > 0) {
		alert(alerta);
		document.getElementById(cpf).focus();
		return false;			
	}
		return true;
}

function verificaCNPJ(cnpj, obrigatorio) { 
		var numcnpj = document.getElementById(cnpj).value;
		
		alerta = new String;
		if (numcnpj.length < 18) alerta += "Alerta: Preencha corretamente o campo CNPJ! \n";
		if ((numcnpj.charAt(2) != ".") || (numcnpj.charAt(6) != ".") || (numcnpj.charAt(10) != "/") || (numcnpj.charAt(15) != "-")){
			if (alerta.length == 0) alerta += "Alerta: Preencha corretamente o campo CNPJ! \n";
		}
		//substituir os caracteres que nao sao numeros
		if(document.layers && parseInt(navigator.appVersion) == 4){
			x  = numcnpj.substring(0,2);
			x += numcnpj.substring(3,6);
			x += numcnpj.substring(7,10);
			x += numcnpj.substring(11,15);
			x += numcnpj.substring(16,18);
			numcnpj = x;	
		} else {
			numcnpj = numcnpj.replace(".","");
			numcnpj = numcnpj.replace(".","");
			numcnpj = numcnpj.replace("-","");
			numcnpj = numcnpj.replace("/","");
		}
		var nonNumbers = /\D/;
		var a = [];
		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] = numcnpj.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 ((numcnpj.charAt(12) != a[12]) || (numcnpj.charAt(13) != a[13])){
			alerta +="Alerta: Dígito verificador com problema!";
		}
		if (alerta.length > 0) {
			alert(alerta);
			document.getElementById(cnpj).focus();
			return false;			
		}
		return true;
}
   
function verificaTamanho(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 verificaCEP(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 bloqueiaCaracteres(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 ajustaData(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 bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  
}  

function ajustaCPF(input, evnt){  
	//Ajusta máscara de CPF e só permite digitação de números  
	if (input.value.length == 3 || input.value.length == 7){  
	    if(clientNavigator == "IE"){  
			input.value += ".";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += ".";  
			}  
		}  
	} else if(input.value.length == 11) {
	    if(clientNavigator == "IE"){  
			input.value += "-";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += "-";  
			}  
		} 		
	}

	//Chama a função bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  
}

function ajustaCNPJ(input, evnt){   
	//Ajusta máscara de CNPJ e só permite digitação de números  
	if (input.value.length == 2 || input.value.length == 6){  
	    if(clientNavigator == "IE"){  
			input.value += ".";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += ".";  
			}  
		}  
	} else if(input.value.length == 10) {
	    if(clientNavigator == "IE"){  
			input.value += "/";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += "/";  
			}  
		} 		
	} else if(input.value.length == 15) {
	    if(clientNavigator == "IE"){  
			input.value += "-";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += "-";  
			}  
		} 		
	}

	//Chama a função bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  
}

function ajustaRG(input, evnt){  
	//Ajusta máscara de RG e só permite digitação de números  
	if (input.value.length == 2 || input.value.length == 6){  
	    if(clientNavigator == "IE"){  
			input.value += ".";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += ".";  
			}  
		}  
	} else if(input.value.length == 10) {
	    if(clientNavigator == "IE"){  
			input.value += "-";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += "-";  
			}  
		} 		
	}

	//Chama a função bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  
}

function ajustaPIS(input, evnt){  
	//Ajusta máscara de PIS e só permite digitação de números  
	if (input.value.length == 3 || input.value.length == 9){  
	    if(clientNavigator == "IE"){  
			input.value += ".";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += ".";  
			}  
		}  
	} else if(input.value.length == 12) {
	    if(clientNavigator == "IE"){  
			input.value += "-";  
		}else{  
			if(evnt.keyCode == 0){  
				input.value += "-";  
			}  
		} 		
	}

	//Chama a função bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  
}
 
function ajustaHora(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 bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  
} 

function ajustaCEP(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 bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  
}  

function ajustaSerie(input, evnt){  
	//Ajusta máscara do Nº de Série da Carteira
	if (input.value.length == 5){   
		if(clientNavigator == "IE" && evnt.keyCode != 45){  
			input.value += "-";  
		}else{  
			if(evnt.keyCode == 0 && evnt.charCode != 45){  
				input.value += "-";  
			}  
		}  
	}  
}
   
function atualizaOpener(){  
	//Atualiza a página opener da popup que chamar a função  
  	window.opener.location.reload();  
} 

function ajustaTelefone (input, evnt) {
	//Ajusta máscara de Telefone e só permite digitação de números  
	if (clientNavigator == "IE"){  
	    if (evnt.keyCode != 8){
			if (input.value.length == 0){
				input.value += '(';
			}
			if (input.value.length == 3){
				input.value += ')';
			}
			if (input.value.length == 8){
				input.value += '-';
			}			
		}
	} else	{  
		if (evnt.which != 8){  
			if (input.value.length == 0){
				input.value += '(';
			}
			if (input.value.length == 3){
				input.value += ')';
			}
			if (input.value.length == 8){
				input.value += '-';
			}			
		}
	}  
	//Chama a função bloqueiaCaracteres para só permitir a digitação de números  
	return bloqueiaCaracteres(evnt);  	
}


// INICIO MASACARA DE VALOR MONETARIO //////////////////////////////////////////////////////////////////////////////////////////
documentall = document.all;

function formatamoney(c){
    var t = this; if(c == undefined) c = 2;		
    var p, d = (t=t.split("."))[1].substr(0, c);
    for(p = (t=t[0]).length; (p-=3) >= 1;) {
	        t = t.substr(0,p) + "." + t.substr(p);
    }
    return t+","+d+Array(c+1-d.length).join(0);
}

String.prototype.formatCurrency=formatamoney

function deMaskValue(valor, currency){
	//Se currency é false, retorna o valor sem apenas com os números. Se é true, os dois últimos caracteres são considerados as casas decimais
	
	var val2 = '';
	var strCheck = '0123456789';
	var len = valor.length;
	if (len== 0){
		return 0.00;
	}

	if (currency == true){	
		//Elimina os zeros à esquerda a variável  <i> passa a ser a localização do primeiro caractere após os zeros e val2 contém os caracteres (descontando os zeros à esquerda)
		
		for(var i = 0; i < len; i++)
			if ((valor.charAt(i) != '0') && (valor.charAt(i) != ',')) break;
		
		for(; i < len; i++){
			if (strCheck.indexOf(valor.charAt(i))!=-1) val2+= valor.charAt(i);
		}

		if(val2.length==0) return "0.00";
		if (val2.length==1)return "0.0" + val2;
		if (val2.length==2)return "0." + val2;
		
		var parte1 = val2.substring(0,val2.length-2);
		var parte2 = val2.substring(val2.length-2);
		var returnvalue = parte1 + "." + parte2;
		return returnvalue;
		
	} else {
		//currency é false: retornamos os valores COM os zeros à esquerda, sem considerar os últimos 2 algarismos como casas decimais 
		val3 ="";
		for(var k=0; k < len; k++) {
			if (strCheck.indexOf(valor.charAt(k))!=-1) val3+= valor.charAt(k);
		}			
		return val3;
	}
}

function reais(obj,event){
	var whichCode = (window.Event) ? event.which : event.keyCode;
	//Executa a formatação após o backspace nos navegadores !document.all
	if (whichCode == 8 && !documentall){	
	//Previne a ação padrão nos navegadores
		if (event.preventDefault){ //standart browsers
				event.preventDefault();
		} else { // internet explorer
				event.returnValue = false;
		}
		var valor = obj.value;
		var x = valor.substring(0,valor.length-1);
		obj.value= deMaskValue(x,true).formatCurrency();
		return false;
	}
	//Executa o Formata Reais e faz o format currency novamente após o backspace
	formataReais(obj,'.',',',event);
}

function backspace(obj,event){
	/*
	Essa função basicamente altera o  backspace nos input com máscara reais para os navegadores IE e opera.
	O IE não detecta o keycode 8 no evento keypress, por isso, tratamos no keydown.
	Como o opera suporta o infame document.all, tratamos dele na mesma parte do código.
	*/
	
	var whichCode = (window.Event) ? event.which : event.keyCode;
	if (whichCode == 8 && documentall){	
		var valor = obj.value;
		var x = valor.substring(0,valor.length-1);
		var y = deMaskValue(x,true).formatCurrency();
	
		obj.value =""; //necessário para o opera
		obj.value += y;
		
		if (event.preventDefault){ //standart browsers
			event.preventDefault();
		} else { // internet explorer
			event.returnValue = false;
		}
		return false;
	}	
}




function formataReais(fld, milSep, decSep, 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;
	
	//if (whichCode == 8 ) return true; //backspace - estamos tratando disso em outra função no keydown
	if (whichCode == 0 )  return true;
	if (whichCode == 9 )  return true; //tecla tab
	if (whichCode == 13)  return true; //tecla enter
	if (whichCode == 16)  return true; //shift internet explorer
	if (whichCode == 17)  return true; //control no internet explorer
	if (whichCode == 27 ) return true; //tecla esc
	if (whichCode == 34 ) return true; //tecla end
	if (whichCode == 35 ) return true;//tecla end
	if (whichCode == 36 ) return true; //tecla home
	
	//O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script
	if (e.preventDefault){ //standart browsers
		e.preventDefault();
	} else { // internet explorer
		e.returnValue = false;
	}
	
	var key = String.fromCharCode(whichCode);  // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
	
	//Concatenamos ao value o keycode de key, se esse for um número
	fld.value += key;
	
	var len = fld.value.length;
	var bodeaux = deMaskValue(fld.value,true).formatCurrency();
	fld.value=bodeaux;
	
	//Essa parte da função tão somente move o cursor para o final no opera. Atualmente não existe como movê-lo no konqueror.
	if (fld.createTextRange){
		var range = fld.createTextRange();
		range.collapse(false);
		range.select();
	} else if (fld.setSelectionRange){
		fld.focus();
		var length = fld.value.length;
		fld.setSelectionRange(length, length);
	}
	return false;

}
// FIM MASCARA VALOR MONETARIO /////////////////////////////////////////////////////////////////////////////////////////////////


function popup(url,id,largura,altura,redimencionar) {
		largura = largura;
		altura = altura;
		w = screen.width;
		h = screen.height;
		meio_w = w/2;
		meio_h = h/2;
		altura2 = altura/2;
		largura2 = largura/2; 
		meio1 = meio_h-altura2;  
		meio2 = meio_w-largura2; 
		window.open(url,id,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable="+redimencionar+",width="+largura+",height="+altura+",top="+meio1+",left="+meio2+",fullscreen=0");
}


function goToPage(delta,total) {

	var count = obj.getRowCount();
	count = Math.round(((total/count)*100)/100);
	
	if (delta == 1) {
		var x = obj.getRowOffset();
		if ( x < (total-50)) {			    
			obj.setRowOffset(x+50);
			document.getElementById('pagina').value = parseFloat(document.getElementById('pagina').value) + 1;
		}
	}
	
	if (delta == -1) {
		var x = obj.getRowOffset();
		if ( x > 0) {
			if (document.getElementById('pagina').value == 2) {
				obj.setRowOffset(0);
				document.getElementById('pagina').value = 1;						
			} else {
				obj.setRowOffset(x-50);
				document.getElementById('pagina').value =  parseFloat(document.getElementById('pagina').value) - 1;
			}
		}
	}			
	
	if (delta == 'Infinity') {
		var x = obj.getRowOffset();
		if ( x < (total) && count != 1) {			    
			obj.setRowOffset((total-50));
			document.getElementById('pagina').value = count;
		}
	}
	
	if (delta == '-Infinity') {
		var x = obj.getRowOffset();
		if ( x > 0) {			    
			obj.setRowOffset(0);
			document.getElementById('pagina').value = 1;
		}
	}					
	
	var pagina = document.getElementById('pagina').value;
	
	document.getElementById('pageLabel').innerHTML = "P&aacute;gina <b>" + pagina + "</b> de " + count + " ";
	
	obj.refresh();
}

function validaAba(aba, cadastro_tipo) {
	var msg           = false;
	
	aba           = aba.toUpperCase();
	cadastro_tipo = cadastro_tipo.toUpperCase();

	if ((aba == 'IMAGEM'  || aba == 'CAMPO' ) && cadastro_tipo == 'DOWNLOAD'     ) { msg = true; }
	if ((aba == 'ARQUIVO' || aba == 'IMAGEM') && cadastro_tipo == 'REPRESENTANTE') { msg = true; }			
	if ((aba == 'ARQUIVO' || aba == 'CAMPO' ) && cadastro_tipo == 'SHOW ROOM'    ) { msg = true; }	

	if (msg) {
		alert('Não é possível cadastrar '+aba+' para o tipo de cadastro '+cadastro_tipo+'.');
		return false;
	}
	
	return true;
}

function proximaAba(caminho, id, tela, aba, cadastro_tipo) {
		
	if (document.getElementById(id).value == "") {
		alert('Favor selecionar um registro na tela de '+tela.toUpperCase()+'!');
		return false;
	}
	if (validaAba(aba, cadastro_tipo)) {		
		window.location=caminho+document.getElementById(id).value;
	}
}







// INICIO AUTOCOMPLETE /////////////////////////////////////////////////////////////////////////////////////////////////////////
function sair(div, evento) {
	
	if (evento == 9) {
		document.getElementById(div).style.display='none';
		return false;
	}
}

function valores(id, valor, total, campopesquisa, id_campo, valor_id, evento, div) {

		if ((evento == 9) || (evento == 27)) {
			document.getElementById(div).style.display = 'none';
			return false;
		}
		
		
		if (evento == 13) {
			document.getElementById(campopesquisa).value = valor;
			document.getElementById(id_campo).value      = valor_id;
			document.getElementById(id_campo).focus();
			return true;
		} else if (evento == 8) {
			document.getElementById(campopesquisa).focus();
			return true;
		}
} 

function setas(seta, id, div) {
	
	if (seta == 27) {
		document.getElementById(div).style.display='none';
		return false;
	}
	
		if (document.getElementById(id+'&1')) {
			if (seta == 40) {
				document.getElementById(id+'&1').focus();
				return false;
			}
		}
	return true;
}

function proximo(seta, total, proximo, id) {
	
	if (seta == 38) {

		id_valor = parseFloat(proximo)-1;
		id_campo = id+'&'+id_valor;

		if (document.getElementById(id_campo)) {
			document.getElementById(id_campo).focus();	
			document.getElementById(id+'&'+proximo).style.background='#fafafa';	
			return false;
		}
		
	}
	
	if (seta == 40) {
		
		id_valor = parseFloat(proximo)+1;
		id_campo = id+'&'+id_valor;

		if (document.getElementById(id_campo)) {
			document.getElementById(id_campo).focus();	
			document.getElementById(id+'&'+proximo).style.background='#fafafa';	
			return false;
		}
		
	}
	
}
// FIM AUTOCOMPLETE ////////////////////////////////////////////////////////////////////////////////////////////////////////////


// INICIO VERIFICA /////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (typeof(verificar) != 'undefined') {
	var campos_verificar = verificar.split(";"); 
	var qtde_verificar   = campos_verificar.length;
	var campo_preenchido = false;
}

function verifica() {
	campo_preenchido 	  = true;
	var campo_atual  	  = 0;
    var retornar_verifica = true;
	while (qtde_verificar > campo_atual) {
		var id_verificar = campos_verificar[campo_atual];
		if (document.getElementById(id_verificar)) {		
			if (document.getElementById(id_verificar).value == "") {
				document.getElementById(id_verificar).style.borderColor='#cc0000';
				document.getElementById('msg_erro').innerHTML = 'Favor preencher os campos destacados.';
				retornar_verifica = false;
			} else {
				document.getElementById(id_verificar).style.borderColor='#c7c7c7';
			}
		}
		campo_atual++;
	}
	if (retornar_verifica == true) {
		document.getElementById('msg_erro').innerHTML = '';
	}
	return retornar_verifica;
}

document.onkeyup = function tecla(e) {
  var keynum;
  if(window.event) // IE
    keynum = window.event.keyCode;
  else if(e.keyCode) // Netscape/Firefox/Opera
    keynum = e.keyCode;
    if (campo_preenchido == true) {
  		verifica(); 
    }
} 

document.onkeypress = function tecla(e) {
  var keynum;
  if(window.event) // IE
    keynum = window.event.keyCode;
  else if(e.keyCode) // Netscape/Firefox/Opera
    keynum = e.keyCode;
    if (campo_preenchido == true) {
  		verifica(); 
    }
} 

document.onchange = function tecla(e) {
  var keynum;
  if(window.event) // IE
    keynum = window.event.keyCode;
  else if(e.keyCode) // Netscape/Firefox/Opera
    keynum = e.keyCode;
    if (campo_preenchido == true) {
  		verifica(); 
    }
} 

document.onblur = function tecla(e) {
  var keynum;
  if(window.event) // IE
    keynum = window.event.keyCode;
  else if(e.keyCode) // Netscape/Firefox/Opera
    keynum = e.keyCode;
    if (campo_preenchido == true) {
  		verifica(); 
    }
} 



// FIM VERIFICA ////////////////////////////////////////////////////////////////////////////////////////////////////////////////