/*if (window.netscape)
	window.captureEvents(Event.KEYDOWN);

var lineaux = "";
*/









function toJuliano(dia,mes,ano) {

  	var dia = eval(dia);
	var mes = eval(mes);
	var ano = eval(ano);

	if(mes < 3) {
	    ano = ano-1;
		mes = mes+12;
	}

	var a = parseInt(ano/100);
	var b = parseInt(a/4);
	var c = 2 - a + b;
	
	var d = parseInt(365.25 * parseFloat(ano + 4716));
	var e = parseInt(30.6001 * parseFloat(mes + 1));
	
	var dj = parseInt(parseFloat(d+e+dia+c)+0.5 - 1524.5);

	return dj;
}

function formataTel(obj,e) {
	var nTecla = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	var tel = obj.value;
	if (nTecla==8 || nTecla==46 || nTecla==9) {
		return true;			
	}
	if ((nTecla > 47 && nTecla < 58 && tel.length < 14)==false){
		return false;			
	}

	if (tel.length == 0) obj.value = "("+ tel;
	if (tel.length == 3) obj.value = tel + ") ";
	if (tel.length == 9) obj.value = tel + "-";
	return true;                                               
}








function formataHora(obj,e) {
	var whora = obj.value;

	if (whora.length == 2) obj.value =  whora + ":";
	return true;
}



function formataData(obj,e) {
	var nTecla = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	var wdata = obj.value;
	if (nTecla==8 || nTecla==46 || nTecla==9) {
		return true;			
	}
	if ((nTecla > 47 && nTecla < 58 && wdata.length < 14)==false){
		return false;			
	}
	if (wdata.length == 2) obj.value =  wdata + "/";
	if (wdata.length == 5) obj.value = wdata + "/";
	return true;	
}

function formataCompet(obj,e) {
	var nTecla = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	var comp = obj.value;
	if (nTecla==8 || nTecla==46 || nTecla==9) {
		return true;
	}
	if ((nTecla > 47 && nTecla < 58 && comp.length < 14)==false){
		return false;			
	}
	if (comp.length == 2) obj.value = comp + "/";
	return true;	
}

function pad(number,length,caracter) {
    var str = '' + number;
    while (str.length < length)
        str = caracter + str;
    return str;
}
/*
function isDate(campo){
  DateToCheck = campo.value;
	if(DateToCheck==""){return true;}
  var a_month = new Array(12);
	a_month[1] = "Jan";
	a_month[2] = "Feb";
	a_month[3] = "Mar";
	a_month[4] = "May";
	a_month[5] = "Apr";
	a_month[6] = "Jun";
	a_month[7] = "Jul";
	a_month[8] = "Aug";
	a_month[9] = "Sep";
	a_month[10] = "Oct";
	a_month[11] = "Nov";
	a_month[12] = "Dec";
	var m_strDate = DateToCheck;
  var m_arrDate = m_strDate.split("/");

  var myDayStr = m_arrDate[0];
  var myMonthInt = parseInt(m_arrDate[1]);
  var myMonthStr = a_month[myMonthInt];
  var myYearStr = m_arrDate[2];
  var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;

  var myDate = new Date( myDateStr );
	var myDate_string = myDate.toGMTString();
  var myDate_array = myDate_string.split( ' ' );
  if ( myDate_array[2] != myMonthStr ) {
    alert( 'Data inválida' );
		campo.focus()
  } 
}//end function

function formataHora(obj,e) {
	if (navigator.userAgent.indexOf("IE") != -1)
	{
		var keypress = window.event.keyCode;
		if(keypress==8 || keypress==46 || keypress==9) {
			return;
		}

		if (((keypress > 47 && keypress < 58) || (keypress > 94 && keypress < 106)) && obj.value.length < 14) {
			if (obj.value.length == 2) 
			   obj.value = obj.value + ":";
		}
		else {
		  if(keypress == 8 || keypress == 9) {
			  event.returnValue = true;
		  }
			else {
			  event.returnValue = false;
			}
		}
	}
	else {
		lineaux = obj.value;
		var keypress = e.which;
		if (keypress == 8)
			return true;
		if ((keypress < 48 || keypress > 57) || obj.value.length >= 14)
			return false;
		if (lineaux.length == 2)
			lineaux = lineaux + ":";
		lineaux = lineaux + (keypress - 48);
		obj.value = lineaux;
		return false;				
	}
	return true;
}
*/
function saltaCampo(campo,tam,prox) {
	if(campo.value.length >= tam) {
		document.getElementById(prox).focus();
	}
}


/*function FormataData(campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}*/

function FormataDespesa(campo,teclapres) {
  var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "-", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
    if (tam == 3) {
	    document.form[campo].value = vr + "-";
	  }
		if (tam >= 3 && tam <= 5 ) {
		  document.form[campo].value = vr.substr(0,2) + "-" + vr.substr(2,tam-3);
		}
		if (tam == 6) {
		  document.form[campo].value = vr.substr(0,2) + "-" + vr.substr(2,3) + "-" + vr.substr(5,1);
		}
	}
}
function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	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 (tecla != 0 && tecla != 9 && tecla != 16 ){
		
			if ( tam == tammax ){
			  if(campo==0) {
				  AbreBusca(campo,1);
				}
				else { 
					document.form[prox].focus();
				}
			}
		}
	}
}

function SaltaCampoCombo(campo,prox) {
  if(campo==1) {
	  AbreBusca(campo,2);
	}
}
function AbreBusca(campo,tipo) {
	window.open("/servicos/pcs/busca.php?tipo="+tipo+"&dados="+document.form[campo].value,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height=60,width=294,left=185,top=215') //height = 60
}
function AbreBusca2(valor,tipo) {
	window.open("/servicos/pcs/busca.php?tipo="+tipo+"&dados="+valor,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height=60,width=294,left=185,top=215') //height = 60
}

