<!--
// VOL WEB 2004

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function ordenarClassTable(idtr,cl01,cl02){

	trs = document.getElementsByTagName("tr");
	for (i=0; i < trs.length; i++){
		if (trs[i].getAttribute("id") == idtr){
			if (i % 2 == 0){
				trs[i].className = cl01;	
			}else{
				trs[i].className = cl02;	
			}
		}
	}
}


function replace(string,text,by) {
		var strLength = string.length, txtLength = text.length;
		if ((strLength == 0) || (txtLength == 0)) return string;
		var i = string.indexOf(text);
		if ((!i) && (text != string.substring(0,txtLength))) return string;
		if (i == -1) return string;
		var newstr = string.substring(0,i) + by;
		if (i+txtLength < strLength)
			newstr += replace(string.substring(i+txtLength,strLength),text,by);

		return newstr;
	}


function popupCentro(pUrl, pTitulo, pLargura, PAltura)
{

	//window.resizeTo(popup_largura, popup_altura); 
	var altura = window.screen.availHeight; 
	var largura = window.screen.availWidth; 
	var ponto_x = parseInt(largura / 2) - parseInt(pLargura / 2); 
	var ponto_y = parseInt(altura / 2) - parseInt(PAltura / 2); 
	//window.moveTo(ponto_x, ponto_y) 
	var parametros = 'width=' + pLargura + ',height= ' + PAltura + ', left=' + ponto_x +', top=' + ponto_y
	//alert(parametros)
	window.open(pUrl,pTitulo,parametros)
}

function popupCentro(pUrl, pTitulo, pLargura, PAltura, extras){

	//window.resizeTo(popup_largura, popup_altura); 
	var altura = window.screen.availHeight; 
	var largura = window.screen.availWidth; 
	var ponto_x = parseInt(largura / 2) - parseInt(pLargura / 2); 
	var ponto_y = parseInt(altura / 2) - parseInt(PAltura / 2); 
	//window.moveTo(ponto_x, ponto_y) 
	var parametros = 'width=' + pLargura + ',height= ' + PAltura + ', left=' + ponto_x +', top=' + ponto_y + ',' + extras
	//alert(parametros)
	window.open(pUrl,pTitulo,parametros)
}

function popupmensagem(pUrl, pTitulo, pLargura, PAltura, extras){

	//window.resizeTo(popup_largura, popup_altura); 
	var altura = window.screen.availHeight; 
	var largura = window.screen.availWidth; 
	//var ponto_x = parseInt(largura / 2) - parseInt(pLargura / 2); 
	//var ponto_y = parseInt(altura / 2) - parseInt(PAltura / 2); 
	var ponto_x = parseInt(largura) - parseInt(pLargura)-11; 
	var ponto_y = parseInt(altura) - parseInt(PAltura)-55; 
	//window.moveTo(ponto_x, ponto_y) 
	var parametros = 'width=' + pLargura + ',height= ' + PAltura + ', left=' + ponto_x +', top=' + ponto_y + ',' + extras;
	window.open(pUrl,pTitulo,parametros)
}

//função para formatar valores monetários com pontos em milhar e virgula de centavos
function FormataValor(obj, evento) {
	var tecla = evento.keyCode;

	tammax = obj.getAttribute("maxlength");

	vr = obj.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		obj.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		obj.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		obj.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		obj.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		obj.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		obj.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}
		

}

function isEmail(str) {
	return ((str != "") && (str.indexOf("@") != -1) && (str.indexOf(".") != -1));
}
    
function emBranco(str) {
    tamanho = str.length;
    contador = 0;
    for (x=0; x<tamanho; x++) {
		if (str.substring(x,x+1) == " ") { ++contador;}
    }
    return ((contador == tamanho) || (str == ""));
}


 
function calculadiarias(data1,hora1,data2,hora2){
	var teste1 = data1.split("/");
	var teste2 = data2.split("/");
	if (teste1[0] && teste2[0]){
		var diarias = 0;
		dataA= new Date(data1.substring(6,10),(data1.substring(3,5)-1),data1.substring(0,2),hora1.substring(0,2),hora1.substring(3,5),"00");
		dataB= new Date(data2.substring(6,10),(data2.substring(3,5)-1),data2.substring(0,2),hora2.substring(0,2),hora2.substring(3,5),"00");
		dataA= dataA.getTime();
		dataB= dataB.getTime();
		if (dataA > dataB) {
			alert("A data de saída deve ser igual ou posterior a data de entrada.");
		}else{
			var diferenca = (dataB-dataA)/1000/60/60/24;
			diarias = parseInt(Math.abs((dataB-dataA)/1000/60/60/24));
			if (diferenca - diarias > 0 ){
				diarias ++;
			}
			document.form1.n_dias.value = diarias;
		}
	}else{
		document.form1.n_dias.value = '';
	}
}

function instr(texto,c,posInicial)
{
	if (posInicial<0) posInicial=0;

	for(var i=posInicial; i<texto.length;i++)
	{
		if(texto.charAt(i)==c) return i;
	}
	return -1;
}

function trim(arg) {
	var trimvalue = "";
	arglen = arg.length;
	if (arglen < 1) return trimvalue;
	i = 0;
	pos = -1;
	while (i < arglen) 
	{
		if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
			pos = i;
			break;
		}
		i++;
	}
	var lastpos = -1;
	i = arglen;
	while (i >= 0)
	{
		if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) 
		{
			lastpos = i;
			break;
		}
		i--;
	}
	trimvalue = arg.substring(pos,lastpos + 1);
	return trimvalue;
}


function getPageSize(){
	
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
}

function abreRelatorio (relatorio) {
	//document.formDetalhar.action = relatorio;
	//popupCentro('','xx','800','650','scrollbars=yes,resizable=yes');
        //document.formDetalhar.target = 'xx';
	//document.formDetalhar.submit();			
	
	//popupCentro(relatorio, "relatorio", "800", "600", "scrollbars=yes,resizable=yes");
	document.formDetalhar.action = relatorio;
	document.formDetalhar.target = "_blank";	
	document.formDetalhar.submit();
}

function abreExcel (pagina) {
	document.formDetalhar.action = pagina ;
	//popupCentro('','xx','800','650','scrollbars=yes,resizable=yes');
	//document.formDetalhar.target = 'xx';
	document.formDetalhar.submit();
}


function isNumber(numero){
   var CaractereInvalido = false;

   for (i=0; i < numero.length; i++){
      var Caractere = numero.charAt(i);
      if(Caractere != "." && Caractere != "," && Caractere != "-"){
         if (isNaN(parseInt(Caractere))) CaractereInvalido = true;
      }
   }
   return !CaractereInvalido;
}


function incPopUp(tipo, tipoPag, largura, altura, pagina){

	document.form1.action = '../start/NewFuncionarioPesquisar.asp';
	popupCentro('', 'xx', largura, altura,'Scrollbars=no, Resizable=yes')
	document.form1.target = "xx";
	document.form1.submit();
}

//-->
