_editor_url = "editor/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }

function mOpOvr(src) {
  src.style.cursor = 'hand';
  src.style.background = '#000066';
  src.style.color = '#FFFFFF';
}

function mOpOut(src) {
src.style.cursor = 'default';
src.style.background = '#b0c4de';
src.style.color = '#3E5386';
}

function mSubOvr(src) {
  src.style.cursor = 'hand';
  src.style.color = '#FFFFFF';
//  src.children.texto.style.background = '#009999';
}

function mSubOut(src) {
src.style.cursor = 'default';
src.style.color = '#3E5386';
//src.children.texto.style.background = '#b0c4de';
}

function limpa(botao) {


if (botao==2) {
	filtro.reset();
	return false;
	}
else
	return true;
}

function confirmar(texto) {
	var volta = confirm(texto);
	return volta;
}

function confirmar_link(texto,onde) {
	var volta = confirm(texto);
	if (volta) { 
		window.open(onde,'_self');
	}
}

function ordena(base,ordem) {
	filtro2 = document.filtro;
	filtro2.alterar.value='N';
	filtro2.base.value = base;
	filtro2.ordem.value = ordem;
	filtro2.submit();
}

function altera(qual) {
	filtro2 = document.filtro;
	filtro2.alterar.value = qual;
	filtro2.submit();
}

function exclui(qual,texto) {
	var volta = confirm(texto);
	filtro2 = document.filtro;
	if (volta) {
		filtro2.excluir.value = qual;
		filtro2.submit();
	}
	return (volta);
}

function valida_traducao(theform) {

	if (theform.mtraduzir.value == "" ) {
		alert("Digite um valor para o campo Traduzir.");
		theform.mtraduzir.focus();
		return (false);
	}
	
	if (theform.mtraduzir.value.length > 50) {
		alert("Digite no máximo 50 caracteres no campo Traduzir.");
		theform.mtraduzir.focus();
		return (false);
	}

	if (theform.mtraducao.value == "" ) {
		alert("Digite um valor para o campo Tradução.");
		theform.mtraducao.focus();
		return (false);
	}
	
	if (theform.mtraducao.value.length > 50) {
		alert("Digite no máximo 50 caracteres no campo Tradução.");
		theform.mtraducao.focus();
		return (false);
	}

	return (true);
}

function valida_doc(theform) {

	if (theform.mnome_documento.value == "" ) {
		alert("Digite um valor para o Nome do Documento.");
		theform.mnome_documento.focus();
		return (false);
	}
	
	if (theform.mnome_documento.value.length > 50) {
		alert("Digite no máximo 50 caracteres para o Nome do Documento.");
		theform.mnome_documento.focus();
		return (false);
	}

	return (true);
}

function valida_menu(theform) {

	if (theform.mtraduzir.value == "" ) {
		alert("Digite um valor para o título da opção.");
		theform.mtraduzir.focus();
		return (false);
	}
	
	if (theform.mtraduzir.value.length > 50) {
		alert("Digite no máximo 50 caracteres o título da opção.");
		theform.mtraduzir.focus();
		return (false);
	}

	return (true);
}

// Formatação de Data

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
		}
	else 
		if(document.layers) { // Nestcape
			nTecla = evtKeyPress.which;
		}
		else {					// Outro Navegador (Anjosoft)
			return true;
		}

	sValue = objForm[strField].value;
	
	if ( document.selection.createRange().text == sValue ) {
		objForm[strField].value = "";
		return true;
	}
	
	// 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( " ", "" );
	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) == "/"))
		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)); } // números de 0 a 9
		else { // qualquer caracter...
			return true;
		} 
	}
	else {
		return true;
	}
}

function check_date(field) {
	var checkstr = "0123456789"; 
	var DateField = field; 
	var Datevalue = ""; 
	var DateTemp = ""; 
	var seperator = "/"; 
	var day; 
	var month; 
	var year; 
	var leap = 0; 
	var err = 0; 
	var i; 
	err = 0; 
	DateValue = DateField.value; 
	/* Deletando todos os caracteres exceto o 0..9 */ 
	for (i = 0; i < DateValue.length; i++) { 
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) { 
			DateTemp = DateTemp + DateValue.substr(i,1); 
		} 
	} 

	DateValue = DateTemp; 
	/* Exectutando a data para 8 digitos - string*/ 
	/* if entrada do ano com 2-digitos / exemplo 20xx */ 
	if (DateValue.length == 6) { 
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); 
	} 
	if (DateValue.length != 8) { 
			err = 19; 
	} 
	/* Se o ano for errado = 0000 */ 
	year = DateValue.substr(4,4); 
	if (year == 0) { 
			err = 20; 
	} 
	/* Validando o mês*/ 
	month = DateValue.substr(2,2); 
	if ((month < 1) || (month > 12)) { 
		err = 21; 
	} 
	/* Validando o dia*/ 
	day = DateValue.substr(0,2); 
	if (day < 1) { 
		err = 22; 
	} 
	/* Validando ano Bissexto / fevereiro / dia */ 
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { 
		leap = 1; 
	} 
	if ((month == 2) && (leap == 1) && (day > 29)) { 
		err = 23; 
	} 
	if ((month == 2) && (leap != 1) && (day > 28)) { 
		err = 24; 
	} 
	/* Validando o mês */ 
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { 
		err = 25; 
	} 
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { 
		err = 26; 
	} 
	/* if 00 houvendo entrada, sem erros */ 
	if ((day == 0) && (month == 0) && (year == 00)) { 
		err = 0; day = ""; month = ""; year = ""; seperator = ""; 
	} 
	/* if sem erros, escrevo a data completa no Input-Field (e.x. 13/12/2001) */ 
	if (err == 0) { 
		DateField.value = day + seperator + month + seperator + year; 
	} 
	/* Mensagem de erro if err != 0 */ 
	else { 
		alert("Atenção, a data está incorreta!"); 
		DateField.select(); 
		DateField.focus();
		return false; 
	} 
}

function fechamenu () {
	var menu = document.getElementById('menu');
	var cabecalho = document.getElementById('cabecalho');
	if (menu.style.display=="none") {
		menu.style.display = "block";
		cabecalho.style.display = "block";
	}
	else {
		menu.style.display = "none";
		cabecalho.style.display = "none";
	}
}

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;
	var tmp = fld.value;
	var volta = fld.value;
	
	if (whichCode == 13) return true;
	if ( whichCode >= 96 && whichCode <= 105 ) whichCode -= 48;
	key = String.fromCharCode(whichCode); 

	if ( document.selection.createRange().text == fld.value ) {
		return true;
	}
	
	if (strCheck.indexOf(key) == -1) {
		if ( whichCode == 8 || whichCode == 88  || whichCode == 9  || whichCode == 46 ) 	return true;
		else return true; 
	}
	if (tmp.substr(0,1) == "0") {
		volta = tmp.substr(1);
	}
	len = volta.length;
	for(i = 0; i < len; i++)
		if ((volta.charAt(i) != '0&#39;') && (volta.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(volta.charAt(i))!=-1) aux += volta.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) volta = '';
	if (len == 1) volta = decSep + '0' + aux;
	if (len == 2) volta = 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++;
		}
		volta = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		volta += aux2.charAt(i);
		volta += decSep + aux.substr(len - 2, len);
	}
	fld.value = volta.substring(0,volta.length-1);
	return true;
}

function excluip(seq) {
document.forms.filtro.excluirp.value = seq;
document.forms.filtro.submit();
return true;
}

function mandapu(lote,invoice) {
opener.filtro.invoicepb.value = invoice;
opener.filtro.lote.value=lote;
opener.filtro.embalagem.focus();
window.close();
}

