function LNKTRN(Url) {
	parent.location.href = Url;
}


/*
  ===========================================================
  Função para abrir janale tipo Pop-Up.
  ===========================================================
*/
function AbreJanela(URL, nome, width, height, left, top, scroll, fullscreen){

	var AvW        = screen.availWidth;
	var AvH        = screen.availHeight;
	var ModoJanela = '';
	
	if (left == "center") {
		left = ((AvW - width) / 2);
	} else {
		if (left == "left") {
			left = 5;
		} else {
			if (left == "end") {
				left = (AvW - width) - 15;
			} else {
				left = 0;
			};
		};
	};
	
	if (top == "center") {
		top = ((AvH - height) / 2)
	} else {
		if (top == "top") {
			top = 0;
		} else {
			if (top == "bottom") {
				top = (AvH - height) - 35
			} else {
				top = 0;
			};
		};
	};
	
	ModoJanela = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",scrollbars=" + scroll + ",fullscreen=" + fullscreen;
	// window.alert(ModoJanela);
	ModoJanela = ModoJanela + ",target=_top,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,dependent=no,alwaysraised=yes"
	
	janela = window.open(URL, nome, ModoJanela);
	janela.moveTo(0,0);

	janela.focus();
}


function PopUp(Url,Largura,Altura) {
 if (Largura == '' || Altura == '') {
  Largura = screen.AvailWidth;
  Altura  = screen.AvailHeight;
 }
 Parm = "top=100,left=100,width=" + Largura + ",height=" + Altura + ",scrollbars=yes";

 window.open(Url,'',Parm);
}

function PopUp2(Url,Largura,Altura,Parm1) {
 if (Largura == '' || Altura == '') {
  Largura = screen.AvailWidth;
  Altura  = screen.AvailHeight;
 }
 Parm = "top=100,left=100,width=" + Largura + ",height=" + Altura;
 Url  = Url + Parm1;
 window.open(Url,'',Parm);
}


/*
  ===========================================================
  Funções para mostrar mensagens rolando na tela (noticias)
  ===========================================================
*/

function regenerate(){
	window.location.reload()
}


function regenerate2(){
	if (document.layers)
		setTimeout("window.onresize=regenerate",500)
	}


function update(){
	BgFade(0xd7,0xdf,0xe1, 0xD7,0xDF,0xE1,10);
	if (document.layers){
		document.msgline.document.msgtext.document.write('<span class="msgtextfont">'+noticias[i]+'</span>')
		document.msgline.document.msgtext.document.close()
	}
	else
		document.all.msgtext.innerHTML=noticias[i]
	if (i<noticias.length-1)
		i++
	else
		i=0
		setTimeout("update()",speed)
}


function BgFade(red1, grn1, blu1, red2,grn2, blu2, steps) {
	sred = red1; sgrn = grn1; sblu = blu1;
	ered = red2; egrn = grn2; eblu = blu2;
	inc = steps;
	step = 0;
	MsgDither();
}


function MsgDither() {
	var epct = step/inc;
	var spct = 1 - epct;
	if (document.layers)
		tickerobject.bgColor =
		Math.floor(sred * spct + ered *epct)*256*256 + Math.floor(sgrn * spct + egrn * epct)*256 + Math.floor(sblu * spct + eblu * epct);
	else
		tickerobject.backgroundColor=Math.floor(sred * spct + ered *epct)*256*256 +Math.floor(sgrn * spct + egrn * epct)*256 +Math.floor(sblu * spct + eblu * epct);
	if ( step < inc ) {
		setTimeout('MsgDither()',50);
	}
	step++;
}



/*
  ===========================================================
  Funções para retornar Usuários e emails selecionados
  ===========================================================
*/
function fechar(UsrCodigos, UsrNomes) {
window.alert(UsrCodigos)
	opener.document.MAINFORM.MSGPRA.value = UsrCodigos;
	opener.document.MAINFORM.MSGCCP.value = UsrNomes; 
	window.close();
}
		
function FecharJanela() {
 self.close();
}
///

/*
  ===========================================================
  Funções para atualizar a janela anterior
  ===========================================================
*/ 
function AtualizarJanelaAnterior() {
 window.opener.document.MAINFORM.submit();
}

/*
  ===========================================================
  Funções display de mensagens no grid
  ===========================================================
*/
  function DivSetVisible(state, divp, divs)
  {
   var DivRef = document.getElementById(divp);
   var IfrRef = document.getElementById(divs);
   if(state)
   {
    DivRef.style.display = "block";
    IfrRef.style.width = DivRef.offsetWidth;
    IfrRef.style.height = DivRef.offsetHeight;
    IfrRef.style.top = DivRef.style.top;
    IfrRef.style.left = DivRef.style.left;
    IfrRef.style.zIndex = DivRef.style.zIndex - 1;
    IfrRef.style.display = "block";
   }
   else
  // {
    DivRef.style.display = "none";
    IfrRef.style.display = "none";
  // }
  }
/*
  ===========================================================
  Funções Mensagem
  ===========================================================
*/
  
  function Mensagem(Msg)
  {
	 alert(Msg);
  }
  
  /*
   Executar botom dentro do Form
  */
  function ExecutaBotao(NomeBotao) {
 window.parent.document.MAINFORM[NomeBotao].click();
}

/*
Ocultar Botao
*/
function OcultarBotao(NomeBotao) {
 document.MAINFORM[NomeBotao].style.display = "none";
}


//---- Auto Tab - Inicio
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
			return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
		return true;
}
//---- Auto Tab - Fim

//---- Função para bloquear todas as teclas - Inicio
function bloquea(tecla) {
	if(event.keyCode == 0) {}
	event.keyCode = 0;
}
//---- Função para bloquear todas as teclas - Fim

//---- Função para bloquear teclas não numéricas - Inicio
function Tecla(e) {
if (document.all) // Internet Explorer
	var tecla = event.keyCode;
else if(document.layers) // Nestcape
	var tecla = e.which;
	if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else
	{
		if (tecla != 8) // backspace
			event.keyCode = 0;
			//return false;
		else
			return true;
	}
}
//---- Função para bloquear teclas não numéricas - Fim

//---- Função para bloquear teclas não numéricas - Inicio
function Tecla_Num(e) {
if (document.all) // Internet Explorer
	var tecla = event.keyCode;
else if(document.layers) // Nestcape
	var tecla = e.which;
	if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		return false;
	else
	{
		if (tecla != 8) // backspace
			event.keyCode = 0;
			//return false;
		else
			return true;
	}
}
//---- Função para bloquear teclas não numéricas - Fim


//---- Função para contador de caracteres - Inicio
//  Programas que utilizam esta rotina:
function updateCounterAll(e, contador, campo) {
	var maxSize = contador;
	var size    = 0;
	var msize   = 0;
	size  = campo.value.length;
	msize = maxSize;
	if (size > maxSize) {
		campo.value = campo.value.substring(0, msize);
	}
	else {
		contador = maxSize - campo.value.length;
	}
}
//---- Função para contador de caracteres - Fim


// --- Posição X e Y do Mouse getMouseXY()
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
  if (IE) {
	tempX = event.clientX + document.body.scrollLeft;
	tempY = event.clientY + document.body.scrollTop;
  } else {
	tempX = e.pageX;
	tempY = e.pageY;
  }
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  tempX = tempX - 10;
  return true;
}
//---- Fim Função getMouseXY()

//---- Finção para checar todos os Check Box do grid. 
//     Parametros: - obj   = this ---- o próprio check que dispara o evento.
//				   - nome  = variável ou atributo		
//				   - posic = posição inicial que diferencia o check ex.: _VAR_AAA_0001, _VAR_BBB_0001 --- (posic 5 = "A")
//				   - casas = quantidade de characteres que irá andar ex.: da posição 5 andar 3
var cont_chk = 0; 
function ChecaTodos(obj, nome, posic, casas){
	len = document.MAINFORM.elements.length;
	for (cont_chk = 0; cont_chk < len; cont_chk++){
		var b = document.MAINFORM.elements[cont_chk].name
		var c = b.substr(posic-1, casas);
		if (c == nome){
			if (document.MAINFORM.elements[cont_chk].type == "checkbox" && document.MAINFORM.elements[cont_chk].tagName == "INPUT"){
				if (obj.checked == false){
					document.MAINFORM.elements[cont_chk].checked = false;
				}
				else {
					document.MAINFORM.elements[cont_chk].checked = true;
				}
			}
		}
	}
}
function MarcaDesmarca(obj, nome, nome2, nome3, posic, casas, msg){
	len = document.MAINFORM.elements.length;
	if (obj.checked == true){
		if (msg == 1) {
			var agree = confirm("Abertura e Fechamento Autom" + String.fromCharCode(225) + "tico de vendas ser" + String.fromCharCode(227) + "o desmarcados. Voc" + String.fromCharCode(234) + " tem certeza?");
		}
		else {
			var agree = confirm("Data Manual ser" + String.fromCharCode(225) + " desmarcada. Voc" + String.fromCharCode(234) + " tem certeza?");
		}
		if (agree){
			for (cont_chk = 0; cont_chk < len; cont_chk++){
				var b = document.MAINFORM.elements[cont_chk].name
				var c = b.substr(posic-1, casas);
				if (c == nome){
					if (document.MAINFORM.elements[cont_chk].type == "checkbox" && document.MAINFORM.elements[cont_chk].tagName == "INPUT"){
						if (obj.checked == false){
							document.MAINFORM.elements[cont_chk].checked = false;
						}
						else {
							document.MAINFORM.elements[cont_chk].checked = true;
						}
					}
				}
				if (c == nome2){
					if (document.MAINFORM.elements[cont_chk].type == "checkbox" && document.MAINFORM.elements[cont_chk].tagName == "INPUT"){
						if (obj.checked == true){
							document.MAINFORM.elements[cont_chk].checked = false;
						}
					}
				}
				if (c == nome3){
					if (document.MAINFORM.elements[cont_chk].type == "checkbox" && document.MAINFORM.elements[cont_chk].tagName == "INPUT"){
						if (obj.checked == true){
							document.MAINFORM.elements[cont_chk].checked = false;
						}
					}
				}
			}
		}
		else {
			obj.checked = false;
		}
	}
	else {
		for (cont_chk = 0; cont_chk < len; cont_chk++){
			var b = document.MAINFORM.elements[cont_chk].name
			var c = b.substr(posic-1, casas);
			if (c == nome){
				if (document.MAINFORM.elements[cont_chk].type == "checkbox" && document.MAINFORM.elements[cont_chk].tagName == "INPUT"){
					if (obj.checked == false){
						document.MAINFORM.elements[cont_chk].checked = false;
					}
					else {
						document.MAINFORM.elements[cont_chk].checked = true;
					}
				}
			}
		}
	}
}
//----Fim Função ChecaTodos

//---- Valida CNPJ - Inicio
//  Programas que utilizam esta rotina:
//  TEMP
//  TEPO
//  HEMPSLC
//  HEPOSLC
//  HEPOPRO
//  HEPMPRO
function valida_cnpj(CNPJ1, prox_campo)  { 
	CNPJ = CNPJ1.value;
	erro = new String;
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verifica" + String.fromCharCode(231,227) + "o de CNPJ suporta apenas n" + String.fromCharCode(250) + "meros!\n";
	if (CNPJ.length < 14) erro += "CNPJ deve conter 14 d" + String.fromCharCode(237) + "gitos!\n";
	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] = 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])){
		  erro += "CNPJ inv" + String.fromCharCode(225) + "lido!\n";
	}
	if (erro.length > 0){
		  alert(erro);
		  CNPJ1.value = "";
//		  CNPJ2.value = "";
//		  CNPJ3.value = "";
//		  CNPJ4.value = "";
//		  CNPJ5.value = "";
		  CNPJ1.focus();
		  return false;
	} else {
		  prox_campo.focus();
		  return true;
	}
 return true;
}
//---- Valida CNPJ - Fim
