/*
	Biblioteca javascript destinada ao uso específico da aplicação. Assim, quando existirem especifidades da aplicação, essas espeficidades poderão ser colocadas aqui.

/*

if (isGecko()){
	document.captureEvents(Event.ONKEYPRESS);
	document.captureEvents(Event.ONKEYUP);
	document.captureEvents(Event.ONKEYDOWN);
}

/************************************************************************************************
*  Imprime o Caracteres restantes de um TextArea												*
*  Autor: Thiago Moesch																			*
*  Data/Hora: 17/02/2004																		*
************************************************************************************************/
function showCharsLeft(obj, maxLen){
	field       = obj;
	objOutput   = document.getElementById(field.name + '_output');
	maxChars    = maxLen * 1;
	typedChars  = field.value.length;
	outputValue = maxChars - typedChars;

	if (outputValue < 0) {
		field.style.color = "red";
		field.value = field.value.substr(0,maxChars);
		field.scrollTop = field.scrollHeight;

	} else if (outputValue >= 0) {
		objOutput.innerHTML = outputValue.toString() + ' caracteres restantes.';
		if (outputValue > 0)
			field.style.color = "#C33333";
	}

}



/************************************************************************************************
*  aceita apenas valores numericos. deve ser usada em onkeypress								*
*  Autor: Carlos Eduardo Maciel																	*
*  Data/Hora: 29/08/2003 - 10:32																*
************************************************************************************************/
function stripNaN(objeto, ev) {
	campo = objeto;

	var ignoreKeys = Array(0,8,9,13,16,17);

	keyPress = (isGecko() ? ev.which : ev.keyCode);

	if(keyPress == 13){
		if (isGecko()) {
			return false;
		} else {
			ev.returnValue = false;
		}
	}

	chr = String.fromCharCode(keyPress);
	if ( chr.match(/^\d$/) ){
		campo.value = campo.value;
	} else if ( !inArray(ignoreKeys, keyPress) ) {
		if (isGecko()) {
			return false;
		} else {
			ev.returnValue = false;
		}
	}
}

 function  replacePathScript(path){
    try {
      path = path.replace(/\t/g,'\\t');
      path = path.replace(/\r/g,'\\r');
      path = path.replace(/\n/g,'\\n');
      path = path.replace(/\\/g,'\\\\');
      return path;
    } catch (exc) {
    }
  }

/************************************************************************************************
*  aceita apenas valores alfa-numericos. deve ser usada em onkeypress							*
*  Autor: Thiago F. Moesch																		*
*  Data/Hora: 20/02/2004																		*
************************************************************************************************/
function stripNaA(objeto, ev) {
	campo = objeto;

	var ignoreKeys = Array(0,8,9,13,16,17,35,36,37,39,46);
	keyPress = (isGecko() ? ev.which : ev.keyCode);
	chr = String.fromCharCode(keyPress);
	if ( chr.match(/^\w$/) ){
		campo.value = campo.value;
	} else if ( !inArray(ignoreKeys, keyPress) ) {
		if (isGecko()) {
			return false;
		} else {
			ev.returnValue = false;
		}
	}
}
/************************************************************************************************
*  Seta o foco no campo onde ocorreu o erro														*
*  Autor: Carlos Eduardo Maciel																	*
*  Data/Hora: 11/12/2002 - 14:40																*
************************************************************************************************/
function setFocus(oFld) {
	try {
		var strType = oFld.type.toLowerCase();
		if ( strType == 'text' ) oFld.select();
		if ( strType != 'hidden' ) oFld.focus();
	} catch (err) {
		return false;
	}
}


/************************************************************************************************
*  auto-complete para campos de Hora															*
*  Autor: Thiago Fernandes Moesch																*
*  Data/Hora: 19/02/2004 - 09:49																*
************************************************************************************************/
function maskTime(fld) {
	if ( !fld.onkeypress ) alert('Evento OnkeyPress deve estar definido com "return stripNaN(this, event)"');
	fld.maxLength = 5;
	maskNumber(fld, '00:00');
}


/************************************************************************************************
*  auto-complete para campos de Data															*
*  Autor: Thiago Fernandes Moesch																*
*  Data/Hora: 19/02/2004 - 09:49																*
************************************************************************************************/
function maskDate(fld) {
	if ( !fld.onkeypress ) alert('Evento OnkeyPress deve estar definido com "return stripNaN(this, event)"');
	fld.maxLength = 10;
	maskNumber(fld, '00/00/0000');
}

/************************************************************************************************
*  auto-complete para campos CPF															*
*  Autor: Thiago Fernandes Moesch																*
*  Data/Hora: 20/02/2004 - 09:49																*
************************************************************************************************/
function maskCPF(fld) {
	if ( !fld.onkeypress ) alert('Evento OnkeyPress deve estar definido com "return stripNaN(this, event)"');
  if(!(fld.maxLength > 0)) {
	  fld.maxLength = 14;
  }
	maskNumber(fld, '000.000.000-00');
}

/************************************************************************************************
*  auto-complete para campos CNPJ															*
*  Autor: Thiago Fernandes Moesch																*
*  Data/Hora: 20/02/2004 - 09:49																*
************************************************************************************************/
function maskCNPJ(fld) {
	if ( !fld.onkeypress ) alert('Evento OnkeyPress deve estar definido com "return stripNaN(this, event)"');
  if(!(fld.maxLength > 0)) {
  	fld.maxLength = 18;
  }
	maskNumber(fld, '00.000.000/0000-00');
}

/************************************************************************************************
*  auto-complete para campos de Telefone														*
*  Autor: Thiago Fernandes Moesch																*
*  Data/Hora: 19/02/2004 - 09:40																*
************************************************************************************************/
function maskPhone(fld) {
	if ( !fld.onkeypress ) alert('Evento OnKeyPress deve estar definido com "return stripNaN(this, event)"');
	fld.maxLength = 14;
	maskNumber(fld, '(00) 0000-0000');
}

/************************************************************************************************
*  auto-complete para campos de Data e hora														*
*  Autor: Thiago Fernandes Moesch																*
*  Data/Hora: 16/02/2004																		*
************************************************************************************************/
function maskDateTime(fld) {
	if ( !fld.onkeypress ) alert('Evento OnKeyPress deve estar definido com "return stripNaN(this, event)"');
	fld.maxLength = 16;
	maskNumber(fld, '00/00/0000 00:00');
}

/************************************************************************************************
*  auto-complete para campos CEP															*
*  Autor: Thiago Fernandes Moesch																*
*  Data/Hora: 20/02/2004 - 09:49																*
************************************************************************************************/
function maskCEP(fld) {
	if ( !fld.onkeypress ) alert('Evento OnkeyPress deve estar definido com "return stripNaN(this, event)"');
	fld.maxLength = 9;
	maskNumber(fld, '00000-000');
}

/************************************************************************************************
*  auto-complete para campos float																*
*  usar no onKeyUp do campo																		*
*  Autor: Carlos Eduardo Maciel																	*
*  Data/Hora: 29/08/2003 - 10:32																*
************************************************************************************************/
function maskFloat(campo, precision, ev) {

	if ( !precision || isNaN(precision) ) {
		precision = 2;
	}

	if ( !campo.onkeypress ) {
		campo.onkeypress = stripNaN;
	}

	var tammax = 18;
	var result;

	vr = campo.value.replace(/\D/g, '');
	tam = (vr.length <= tammax ? vr.length : tammax);

	if ( tam <= precision) {
		result = vr;
	} else {
		result = '';
		init = tam - precision - 1;
		for (var i = init; i >= 0; i--) {
			result = vr.charAt(i) + result;
			if ( ((init-i+1) % 3 == 0) && (i != 0) ) {
				result = '.' + result;
			}
		}
		result += ',' + vr.substr(init + 1);
		campo.value = result;
	}

	if ( tam > tammax ) {
		if (isGecko()) {
			return false
		} else {
			ev.returnValue = false;
		}
	}
}


/************************************************************************************************
*  Seta mascara em campos texto																	*
*  Autor: Carlos Eduardo Maciel																	*
*  Data/Hora: 15/01/2004 - 20:12																*
************************************************************************************************/
function maskNumber(field, strMask) {

	var strMask     = strMask.replace(/\d/g, '0');
	var size        = strMask.length;
	var strValue    = field.value.replace(/\D/g, '');
	var digPointer  = 0;
	var maskPointer = 0;

	for (i=0; i<size; i++) {
		if (strMask.charAt(i) == '0' && digPointer < strValue.length) {
			tmp = strMask.substr(0, i) + strValue.charAt(digPointer++) + strMask.substr(i+1, size);
			strMask = tmp;
			maskPointer = i;
		}
	}

	// Se digitou alguma coisa
	if (maskPointer) {
		for (i=maskPointer+1; i<size; i++) {
			if (strMask.charAt(i) != '0') {
				maskPointer++;
			} else {
				break;
			}
		}
	}

	field.value = ( strValue ? strMask.substr(0, maskPointer+1) : '');

//	if (field.value.length == size) {
//		jumpNextField(field);
//	}
}



/************************************************************************************************
*  Verifica a existencia de um valor em um array												*
*  Autor: Carlos Eduardo Maciel																	*
*  Data/Hora: 20/11/2001 - 12:07																*
************************************************************************************************/
function inArray(theArray, theValue) {
	for (var i=0; i<theArray.length; i++) {
		if ( theArray[i].toString().toLowerCase() == theValue.toString().toLowerCase() )
			return true;
	}
	return false;
}



/************************************************************************************************
*  Coloca um TextArea com limitador de caracteres												*
*  Autor: Thiago Fernandes Moesch																*
*  Data: 05/02/2004																				*
************************************************************************************************/
function showLimitedTextArea(name, value, cols, rows, maxSize, classname) {

	var s = '';

	s += '<textarea class="'+ classname +'" \n';
	s += ' id="id_'+ name +'" \n';
	s += ' name="'+ name +'" cols="'+ cols +'" rows="'+ rows +'" \n';
	s += ' onchange="return showCharsLeft(this, '+ maxSize +');" \n';
	s += ' onfocus="return showCharsLeft(this, '+ maxSize +');" \n';
	s += ' onkeyup="return showCharsLeft(this, '+ maxSize +');" \n';
	s += ' onkeydown="return showCharsLeft(this, '+ maxSize +');" \n';
	s += ' onkeypress="return showCharsLeft(this, '+ maxSize +');">'+ value +'</textarea>\n';
	s += '<div align="left" id="'+ name +'_output" style="color:silver; font-size: 9px; font-family: verdana;">'+ (maxSize - value.toString().length) +' caracteres restantes customiza.</div>\n\n';
	document.write(s);
}



/************************************************************************************************
*  Retira um item de um select e o coloca em outro												*
*  Autor: Thiago Fernandes Moesch																*
*  Data: 10/02/2004																				*
*																								*
*  "from" e "to" devem ser campos select de um form												*
************************************************************************************************/
function moveItem(from, to) {

	var size = from.length;
	for (i=size-1; i>=0; i--) {
		if (from.options[i].selected) {
			to.options[to.length] = new Option(from.options[i].text, from.options[i].value);
			from.options[i] = null;
		}
	}

}

/************************************************************************************************
*  Abre um popUp com os tamanhos definidos e sem barras de menu e navegação						*
*  Autor: Thiago Fernandes Moesch																*
*  Data: 11/02/2004																				*
************************************************************************************************/
function windowOpen(url, name, width, height) {

	var left = centerWidth(width);
	var top = centerHeight(height);

	wParam = 'width='+ width +',height='+ height + ', top=' +top+ ', left=' +left+ ',status=no,toolbar=no,menubar=no,location=no,scrollbars=auto';
	var wnd = window.open(url, name, wParam);

}

/************************************************************************************************
*  Coloca a janela no meio da tela																*
*  Autor: Thiago Fernandes Moesch																*
*  Data: 11/02/2004																				*
************************************************************************************************/
function centerWindow(wnd, scrW, scrH) {
	var left = 10;
	var top = 10;

	try	{
		if(scrW != null && scrW > 0 && scrH != null && scrH > 0 ) {
			left = (screen.availWidth - scrW)/2;
			top  = (screen.availHeight - scrH)/2;
		} else {
			left = (screen.availWidth - wnd.document.body.scrollWidth)/2;
			top  = (screen.availHeight - wnd.document.body.scrollHeight)/2;
		}
	}
	catch (e) {
		left = 10;
		top  = 10;
	}
	wnd.moveTo(left, top);
}

/************************************************************************************************
*  Devolve o meio da tela na horizontal (Width)													*
*  Autor: Renato Caetano Diogo																	*
*  Data: 05/03/2004																				*
************************************************************************************************/

function centerWidth(scrW) {
	var left = 10;

	try	{
		left = (screen.availWidth - scrW)/2;
	}
	catch (e) {
		left = 10;
	}
	return left;
}

/************************************************************************************************
*  Devolve o meio da tela na vertical (Height)													*
*  Autor: Renato Caetano Diogo																	*
*  Data: 05/03/2004																				*
************************************************************************************************/

function centerHeight(scrH) {
	var top = 10;

	try	{
		top = (screen.availHeight - scrH)/2;
	}
	catch (e) {
		top = 10;
	}
	return top;
}

/************************************************************************************************
*                                             													*
*                                             													*
*                                             													*
************************************************************************************************/

function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}


/************************************************************************************************
* Descrição: exibe/oculta um elemento
* Parâmetros de Entrada:
* theID (string) - id do objeto a ser ocultado/exibido
* action (char) - 'S' para  exibir e 'H' para ocultar. caso nao seja informado, nega o status atual
* Parâmetros de saída: [NENHUM]
************************************************************************************************/
var show = 'S';
var hide = 'H';

function showHide(theID, action) {
	var strDsp;
	var obj = document.getElementById(theID);
	if (obj) {
		if (action) {
			strDsp = (action == show ? '' : 'none');
		} else {
			var aux = (obj.length ? obj[0] : obj).style.display;
			strDsp = (aux == 'block' || !aux ? 'none' : '');
		}

		if (obj.length && !obj.type) {
			for (var i=0; i<obj.length; i++) {
				obj[i].style.display = strDsp;
			}
		} else {
			obj.style.display = strDsp;
		}
	}
//	alert(obj.outerHTML);
 //return ( (strDsp == 'block') ? true : false);
}


/************************************************************************************************
* Descrição: transforma a querystring em variável do  JavaScript
*
* Autor: Thiago F. Moesch
* Data: 16/02/2004
************************************************************************************************/
function getRequestVariables() {
	var vars = document.location.search.split('&');
	if (vars.length > 0) {
		for (i=0; i<vars.length ; i++) {
			if (vars[i]) {
				tmp = vars[i].split('=');
				alert(vars[i]);
				eval(tmp[0] + ' = "'  + tmp[1] + '";');
			}
		}
	}
}


/************************************************************************************************
* Descrição: formata a String passada com a data e hora desejada
*
* %d - dia com um digito 1 - 31
* %D - dia com dois digitos 01 - 31
* %m - mes com num digito 0 - 12
* %M - mês com dois digitos 01 - 12
* %y - ano com dois digitos
* %Y - ano com quatro digitos
* %h - hora 0 - 24
* %H - hora 00 - 24
* %i - minuto 0 - 59
* %I - minuto 00 - 59
* %s - segundos 0 - 59
* %S - segundos 00 - 59

* Autor: Thiago F. Moesch
* Data: 16/02/2004
************************************************************************************************/

function dateFormat(fmt, fdate) {

	var result = fmt;

	if (!fdate) {
		var fdate = new Date();
	}


	result = result.replace(/%d/g, fdate.getDate().toString());
	result = result.replace(/%D/g, strPad(fdate.getDate(), '0', 2, true));


	result = result.replace(/%m/g, fdate.getMonth().toString());
	result = result.replace(/%M/g, strPad(fdate.getMonth(), '0', 2, true));

	result = result.replace(/%y/g, fdate.getFullYear().toString().substr(2,2));
	result = result.replace(/%Y/g, fdate.getFullYear().toString());

	result = result.replace(/%h/g, fdate.getHours().toString());
	result = result.replace(/%H/g, strPad(fdate.getHours(), '0', 2, true));

	result = result.replace(/%i/g, fdate.getMinutes().toString());
	result = result.replace(/%I/g, strPad(fdate.getMinutes(), '0', 2, true));

	result = result.replace(/%s/g, fdate.getSeconds().toString());
	result = result.replace(/%S/g, strPad(fdate.getSeconds(), '0', 2, true));

	return result;
}



/************************************************************************************************
* Descrição: Insere simbolos à direita ou esquerda de uma string
* Autor: Thiago F. Moesch
* Data: 16/02/2004
************************************************************************************************/
function strPad(value, mask, size, toRight) {

	var str = '';
	if (value.toString().length < size) {
		var diff = size - value.toString().length;
		for (i=0; i < diff; i++) {
			str += mask;
		}

		if (toRight) {
			return mask + value.toString();
		} else {
			return value.toString() + mask;
		}
	} else {
		return value;
	}

}


/************************************************************************************************
* Descrição: Verifica se o Browser é Gecko (Netscape, Mozilla, FireFox)
* Autor: Thiago F. Moesch
* Data: 16/02/2004
************************************************************************************************/
function isGecko(event) {
	return (navigator.appName=="Netscape");
}


/************************************************************************************************
* Descrição: Pula para o Proximo Campo do formulário
* Autor: Thiago F. Moesch
* Data: 20/02/2004
************************************************************************************************/
function jumpNextField(fld){
	var oForm = fld.form;
	var proxCampo = null;

	// Procura nos elementos do form o campo passado como parametro e retorna o proximo campo
	for (i=0; i<oForm.elements.length; i++) {
		//alert(oForm.elements[i].name + "  " + fld.name);
		if (oForm.elements[i] == fld) {
			for (j=i+1; j<oForm.elements.length; j++) {
				if ((oForm.elements[j] != null) && (oForm.elements[j].type != 'hidden') && (oForm.elements[j].disabled == false)){
					proxCampo =  oForm.elements[j];
					proxCampo.focus();
					return;
				}
			}
		}
	}
}

/************************************************************************************************
* Descrição: Funções de Data
* Autor: Renato Caetano Diogo
* Data: 20/02/2004
************************************************************************************************/

function arrayOfDaysInMonths(isLeapYear){
	  this[0] = 31;
	  this[1] = 28;
	  if (isLeapYear)
			this[1] = 29;
	  this[2] = 31;
	  this[3] = 30;
	  this[4] = 31;
	  this[5] = 30;
	  this[6] = 31;
	  this[7] = 31;
	  this[8] = 30;
	  this[9] = 31;
	  this[10] = 30;
	  this[11] = 31;
}

function daysInMonth(month, year){
   var isLeapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
   var monthDays  = new arrayOfDaysInMonths(isLeapYear);
   return monthDays[month];
}

/************************************************************************************************
* Descrição: Funções de Imagem
* Autor: Renato Caetano Diogo
* Data: 13/09/2004
************************************************************************************************/

function updateImg(what,widimg,hegimg,ratio,idw,idh) {
	if(widimg <= idw){
		what.width = widimg / ratio;
	}	else {
		what.width = idw;
	}

	if(hegimg <= idh){
		what.height = hegimg / ratio;
	}	else {
		what.height = idh;
	}
}

/*
var nextfield;
var cont=0;
function proximo(){
	cont = 0;
	nextfield.focus();
}

netscape = "";
ver = navigator.appVersion; len = ver.length;
var nextlinha;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
	netscape = (ver.charAt(iln+1).toUpperCase() != "C");

	function keyDown(DnEvents) {
		// ve quando e o netscape ou IE
		k = (netscape) ? DnEvents.which : window.event.keyCode;
		//alert(k);
		if (k == 13) {
			cont=0;
			nextlinha.focus();
			//return false;
		}
	}

document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
*/

function diferencaHoras(horaentrada,horasaida){
	var total;

	date1 = new Date("07/10/2003" + " " +horaentrada);
	date2 = new Date("07/10/2003" + " " +horasaida);

	diff = new Date();
	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();
	hours = Math.floor((timediff / (1000 * 60 *60)));
	timediff -= hours * (1000 * 60 * 60);
	mins = Math.floor(timediff / (1000 * 60));
	timediff -= mins * (1000 * 60);
	secs = Math.floor(timediff / 1000);
	timediff -= secs * 1000;
	total = hours+":"+mins+":"+secs;

	return total;
}

/************************************************************************************************
*  Exibe mensagem de erro																		*
*  Autor: Carlos Eduardo Maciel																	*
*  Data/Hora: 11/12/2002 - 14:40																*
************************************************************************************************/
function errorMsg(oFld, alias, strMsg) {
	if ( strMsg || !this.erro) {
		var customized = strMsg;
		if ( this.joinMessages ) {
			this.strMessages += (this.strMessages && customized ? '\n' : '') + (customized ? customized : '');
			if ( lastField ) {
				alert(this.strMessages);
			}
		} else {
			alert(customized);
			oFld.value = ""
			setFocus(oFld);
		}
	}
}

function isTime(campo, alias){

	this.erro = true;
	var msg;
	var hour = campo.value;
	if ( campo.value ) {
		if(hour.indexOf(":")) {
			arrParts = hour.split(":")
			if(arrParts.length == 2){
				hora = (arrParts[0]*1);
				mins = (arrParts[1]*1);
				if(!(isNaN(hora)) && !(isNaN(mins))){
					if( (hora<24) && (hora>=0) ) {
						if( (mins<60) && (mins>=0) ){
							this.erro = false;
						}
					}
				}
			}
		}

	} else {
		this.erro = false;
	}
	if (this.erro) {
		if (alias) msg = "O campo '"+ alias +"' deve conter um horário válido.";
		this.errorMsg(campo, alias, msg);
	}

	return !this.erro;
}

function calcula(indice_dia,startday,endday){
	var TXT_MANHA_ENTRADA = 0, TXT_MANHA_SAIDA = 0, TXT_MANHA_TOTAL = 0;
	var TXT_TARDE_ENTRADA = 0, TXT_TARDE_SAIDA = 0, TXT_TARDE_TOTAL = 0;
	var TXT_NOITE_ENTRADA = 0, TXT_NOITE_SAIDA = 0, TXT_NOITE_TOTAL = 0;
	var TXT_EXTRA_ENTRADA = 0, TXT_EXTRA_SAIDA = 0, TXT_EXTRA_TOTAL = 0;
	var TXT_TOT_HORAS = 0, TXT_TOT_MIN = 0, TXT_TOTAL = 0, TXT_ALMOCO = 0;
	var ARR_HOR_1 = 0, ARR_HOR_2 = 0, ARR_HOR_3 = 0, ARR_HOR_4 = 0, ARR_ALMOCO = 0;
	var TXT_TMP = 0;

	/* Calcula parciais por periodo MANHA */

	if(! (document.all('TXT_MANHA_ENTRADA'+indice_dia).value == "" && document.all('TXT_MANHA_SAIDA'+indice_dia).value == "")){
		TXT_MANHA_ENTRADA = document.all('TXT_MANHA_ENTRADA'+indice_dia).value;
		TXT_MANHA_SAIDA   = document.all('TXT_MANHA_SAIDA'+indice_dia).value;

		if(isTime(document.all('TXT_MANHA_ENTRADA'+indice_dia), "do dia " + indice_dia + ", entrada da manhã") && isTime(document.all('TXT_MANHA_SAIDA'+indice_dia), "do dia " + indice_dia + ", saída da manhã")){
			TXT_MANHA_TOTAL = diferencaHoras(TXT_MANHA_ENTRADA, TXT_MANHA_SAIDA);
			ARR_HOR_1 = TXT_MANHA_TOTAL.split(":");
			TXT_TOT_HORAS += parseInt(ARR_HOR_1[0],10);
			TXT_TOT_MIN += parseInt(ARR_HOR_1[1],10);
		}
	} else {
		TXT_MANHA_TOTAL = "0";
	}

	/* Calcula parciais por periodo TARDE */

	if(! (document.all('TXT_TARDE_ENTRADA'+indice_dia).value == "" && document.all('TXT_TARDE_SAIDA'+indice_dia).value == "")){
		TXT_TARDE_ENTRADA = document.all('TXT_TARDE_ENTRADA'+indice_dia).value;
		TXT_TARDE_SAIDA   = document.all('TXT_TARDE_SAIDA'+indice_dia).value;
		if(isTime(document.all('TXT_TARDE_ENTRADA'+indice_dia), "do dia " + indice_dia + ", entrada da tarde") && isTime(document.all('TXT_TARDE_SAIDA'+indice_dia), "do dia " + indice_dia + ", saída da tarde")){
			TXT_TARDE_TOTAL = diferencaHoras(TXT_TARDE_ENTRADA,TXT_TARDE_SAIDA);
			ARR_HOR_2 = TXT_TARDE_TOTAL.split(":");
			TXT_TOT_HORAS += parseInt(ARR_HOR_2[0],10);
			TXT_TOT_MIN += parseInt(ARR_HOR_2[1],10);
/*			TXT_ALMOCO = diferencaHoras(TXT_MANHA_SAIDA,TXT_TARDE_ENTRADA);
			ARR_ALMOCO = TXT_ALMOCO.split(":");
			TXT_ALMOCO=parseInt(ARR_ALMOCO[0],10);
			if(TXT_ALMOCO<1){
				alert("entre " +TXT_ALMOCO);
				TXT_TOT_HORAS -=1;
				TXT_TOT_MIN+=parseInt(ARR_ALMOCO[1],10);
			}
*/		}
	} else {
		TXT_TARDE_TOTAL = "0";
	}

	/* Calcula parciais por periodo NOITE */
	if(! (document.all('TXT_NOITE_ENTRADA'+indice_dia).value == "" && document.all('TXT_NOITE_SAIDA'+indice_dia).value == "")){
		TXT_NOITE_ENTRADA = document.all('TXT_NOITE_ENTRADA'+indice_dia).value;
		TXT_NOITE_SAIDA   = document.all('TXT_NOITE_SAIDA'+indice_dia).value;
		if(isTime(document.all('TXT_NOITE_ENTRADA'+indice_dia), "do dia " + indice_dia + ", entrada da noite") && isTime(document.all('TXT_NOITE_SAIDA'+indice_dia), "do dia " + indice_dia + ", saída da noite")){
			TXT_NOITE_TOTAL = diferencaHoras(TXT_NOITE_ENTRADA,TXT_NOITE_SAIDA);
			ARR_HOR_3 = TXT_NOITE_TOTAL.split(":");
			TXT_TOT_HORAS += parseInt(ARR_HOR_3[0],10);
			TXT_TOT_MIN += parseInt(ARR_HOR_3[1],10);
		}
	} else {
		TXT_NOITE_TOTAL = "0";
	}

	/* Calcula parciais por periodo EXTRA */
	if(! (document.all('TXT_EXTRA_ENTRADA'+indice_dia).value == "" && document.all('TXT_EXTRA_SAIDA'+indice_dia).value == "")){
		TXT_EXTRA_ENTRADA = document.all('TXT_EXTRA_ENTRADA'+indice_dia).value;
		TXT_EXTRA_SAIDA   = document.all('TXT_EXTRA_SAIDA'+indice_dia).value;
		if(isTime(document.all('TXT_EXTRA_ENTRADA'+indice_dia), "do dia " + indice_dia + ", entrada da extra") && isTime(document.all('TXT_EXTRA_SAIDA'+indice_dia), "do dia " + indice_dia + ", saída da extra")){
			TXT_EXTRA_TOTAL = diferencaHoras(TXT_EXTRA_ENTRADA,TXT_EXTRA_SAIDA);
			ARR_HOR_4 = TXT_EXTRA_TOTAL.split(":");
			TXT_TOT_HORAS += parseInt(ARR_HOR_4[0],10);
			TXT_TOT_MIN += parseInt(ARR_HOR_4[1],10);
		}
	} else {
		TXT_EXTRA_TOTAL = "0";
	}

	//fim parciais

	if (TXT_TOT_MIN >= 60){
		TXT_TOT_MIN-=60;
		TXT_TOT_HORAS++;
	}
	TXT_TMP = Math.floor((TXT_TOT_MIN*100)/60)/100;
	document.all('TXT_TOTAL_DECIMAL'+indice_dia).value = parseFloat(parseInt(TXT_TOT_HORAS,10) + parseFloat(TXT_TMP));
	if (TXT_TOT_HORAS < 10) TXT_TOT_HORAS = "0" + TXT_TOT_HORAS;
	if (TXT_TOT_MIN   < 10) TXT_TOT_MIN   = "0" + TXT_TOT_MIN;
	document.all('TXT_TOTAL_NORMAL'+indice_dia).value = TXT_TOT_HORAS + ":" + TXT_TOT_MIN;
	calculaTotalMes(startday,endday);

}

function calculaTotalMes(startday,endday){
	var ARR_ACUM,TXT_TOT_HORAS=0,TXT_TOT_MIN=0,TXT_TOT=0,TXT_TOT_DEC=0;
	for(var indice_dia=startday; indice_dia<endday; indice_dia++){
		TXT_TOT = document.all('TXT_TOTAL_NORMAL'+indice_dia).value;
		if(TXT_TOT.length > 0){
			ARR_ACUM = TXT_TOT.split(":");
			TXT_TOT_HORAS += parseInt(ARR_ACUM[0],10);
			TXT_TOT_MIN += parseInt(ARR_ACUM[1],10);
			if(TXT_TOT_MIN >= 60){
				TXT_TOT_MIN-=60;
				TXT_TOT_HORAS++;
			}
		}
		if(document.all('TXT_TOTAL_DECIMAL'+indice_dia).value.length > 0){
			TXT_TOT_DEC += parseFloat(document.all('TXT_TOTAL_DECIMAL'+indice_dia).value);
		}

	}
	if (TXT_TOT_HORAS < 10) TXT_TOT_HORAS = "0" + TXT_TOT_HORAS;
	if (TXT_TOT_MIN   < 10) TXT_TOT_MIN   = "0" + TXT_TOT_MIN;
	document.all('TXT_TOTAL_NORMAL').value = TXT_TOT_HORAS+":"+TXT_TOT_MIN;
	document.all('TXT_TOTAL_DECIMAL').value = TXT_TOT_DEC;
	//calculaRestante(document.all('TXT_TOTAL_NORMAL').value);
}

function calculaRestante(tempo){
	var ARR_ACUM,TXT_TOT_HORAS=0,TXT_TOT_MIN=0,TXT_TOT="";
	ARR_ACUM = tempo.split(":");
	TXT_TOT_HORAS =  parseInt(ARR_ACUM[0],10)-160;
	TXT_TOT_MIN = 60 - parseInt(ARR_ACUM[1],10);
	document.all.saldomes.value = TXT_TOT_HORAS+":"+TXT_TOT_MIN;
}

function toUpper(field){
	field.value = field.value.toUpperCase();
}

//----------------------------------------------------------------------------------

var resolucao="";
var browser="";

selecionaBrowser();
defineResolucao();

function selecionaBrowser(){
	browser = window.navigator.appName;
}

/*	Busca a definição da resolução	*/
function defineResolucao(){
	var eh800x600;

	if (browser == "Netscape") {
		widthTela = window.innerWidth;
		heightTela = window.innerHeight;
	} else {
		heightTela = window.screen.Height;
		widthTela = window.screen.Width
	}
	if (widthTela > "815" || heightTela > "615") { //deixa uma folga
		eh800x600 = false
	} else  {
		eh800x600 = true
	}

	if (eh800x600){
		resolucao = "800x600";

	}else{
		resolucao = "1024x768";
	}
}

function getResolucao(img,ext){
	return '<img src="'+ img + resolucao + ext + '">';
}

function eh800x600() {
	if (resolucao == "800x600") {
    return true;
	}
  return false;
}

//----------------------------------------------------------------------------------

function disable(ev) {
/**/
	if ( !ev ) {
		ev = window.event;
	}

	returnValue = true;

	switch (ev.type ) {
		// botao direito
		//==============================================
		case 'contextmenu':
				ev.returnValue = false;
				returnValue =  false;
				break;

		// botao direito
		//==============================================
		case 'keypress':
		case 'keydown':
		case 'keypup':
				if ( ev.ctrlKey || ev.altKey ) {
					ev.returnValue = false;
					returnValue =  false;
				}
				break;
	}
	return returnValue;
/**/
//  return ev.returnValue;
}

//----------------------------------------------------------------------------------
  function isCpf(fld){
  	strValue    = fld.value.replace(/\D/g, '');
    if(strValue.length <= 11){
      return true;
    }
    return false;
  }

  function isCgc(fld){
  	strValue    = fld.value.replace(/\D/g, '');
    if(strValue.length > 11){
      return true;
    }
    return false;
  }
//----------------------------------------------------------------------------------
  function escolheMask(fld){
  	strValue    = fld.value.replace(/\D/g, '');
    if(strValue.length <= 11){
      maskCPF(fld);
    } else {
      maskCNPJ(fld);
    }
  }
//----------------------------------------------------------------------------------
  function limpaMask(fld){
    fld.value = fld.value.replace(/\D/g, '');
  }
//----------------------------------------------------------------------------------
  function colocaMask(fld){
    if(fld.value.length <= 14){
      maskCPF(fld);
    } else {
      maskCNPJ(fld);
    }
  }
//----------------------------------------------------------------------------------
  function ate(texto, valor){
    if(texto.length > valor){
      texto = texto.substr(0,valor) + '...';
    }
    return texto;
  }
//----------------------------------------------------------------------------------
  function escolheCheck(value, truevalue){
    return (value == truevalue);
  }
//----------------------------------------------------------------------------------
function checkBrowser() {

  var MSIE,Gecko,Netscape,Versao,Posicao,Navegador = navigator.userAgent;

  if((Posicao = Navegador.lastIndexOf("MSIE")) != -1) {
	Versao = Navegador.substr(Posicao+5,1);
	if(Versao < "5") {
	  alert("Versão não suportada !\n\nÉ necessário usar a versão 6.0 ou superior.");
	  return;
	}
	MSIE = true;
  } else if(Navegador.indexOf("Gecko") != -1) {
	Posicao = Navegador.indexOf("rv:");
	Versao = Navegador.substr(Posicao+3,3);
	if(Versao < "1.0") {
	  alert("Versão não suportada !\n\nÉ necessário usar Netscape versão 7.0 ou superior ou outro browser baseado no Mozilla.");
	  return;
	}
	Gecko = true;
  } else if(Navegador.indexOf("Mozilla") != -1) {
	if(Navegador.substring(8,9) < "4") {
	  alert("Versão não suportada !\n\nÉ necessário usar a versão 4.3 ou superior\nou preferencialmente a versão 6.1 ou superior.");
	  return;
	}
	Netscape = true;
  }

  if(!(MSIE || Gecko || Netscape)) {
	alert("Browser não suportado !\n\nÉ necessário usar Internet Explorer 5.0 ou superior\nNetscape 4.3 ou superior ou 7.0 ou superior\nou um browser baseado no Mozilla 1.0 ou superior.");
	return false;
  } else {
	return true;
  }
}
//----------------------------------------------------------------------------------

function getOpcoes(){
  var Largura, Altura, Opcoes;
  Largura = window.screen.width - 10;
  Altura =  window.screen.height;
  Opcoes = "top=0,left=0,height=" + Altura + ",width=" + Largura + ",status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no";
}
//----------------------------------------------------------------------------------