function legenda(texto,mostra,campo){
	div = document.all("legenda");
	if (mostra==1 && texto!="") {
		div.style.visibility="visible";
		div.style.left=event.clientX+20;
		div.style.top=event.clientY+document.body.scrollTop;		
		campo.style.cursor="default";
		//div.innerHTML=texto;
	} else {
		div.style.visibility="hidden";
	}
}

function leg(texto,vis,con){
	di = document.all("le");

	if (vis==1 && texto!="") {
		
		di.style.visibility="visible";
		di.style.left=event.clientX+20;
		di.style.top=event.clientY+document.body.scrollTop;		
		con.style.cursor="default";
		di.innerHTML=texto;

	} else {

		di.style.visibility="hidden";

	}
}

function Janela_Principal(url,tit,w,h,sc) {
w = window.screen.width - 12;
h = window.screen.height - 78;
janela = window.open(url, tit,"toolbar=0,scrollbars=" + sc + ",top=1,left=1,status=1,width=" + w + ",height=" + h + ",resizable=1");
}

function abrir(url,tit,w,h,sc) {

r=0;
if (sc==1) r=1;
	jan = window.open(url, tit,"toolbar=0,scrollbars=" + sc + ",status=0,width=" + w + ",height=" + h + ",resizable=" + r);
	if (parseInt(navigator.appVersion)>=4){
		jan.moveTo((window.screen.width-w)/2,(window.screen.height-h)/2);
	}
	jan.focus();
}

function SaltaCampo (campo,prox,tammax,teclapres){
	//SaltaCampo(3,4,8,event)
	var tecla = teclapres.keyCode;
	var vr,tam
	vr = document.forms[0].elements[campo].value;
	tam = vr.length;
	if (tecla != 0 && tecla != 9 && tecla != 16 ) {
		if ( tam == tammax )
			document.forms[0].elements[prox].focus() ;
	}
}

function FormataData(campo,teclapres) {
	//FormataData(this,event)
	var tecla = teclapres.keyCode;
	var vr,tam;
	vr=campo.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

function FormataHora(campo,teclapres) {
	//FormataHora(this,event)
	var tecla = teclapres.keyCode;
	var vr,tam;
	vr=campo.value;	
	//vr=document.forms[0].elements[campo].value;
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 4 )
			document.forms[0].elements[campo].value = vr.substr( 0, tam - 1  ) + ':' + vr.substr( tam - 1, tam );
	}
}


function checkDate(textField) 
{
	v = textField.value;
	i1 = v.indexOf("/");
	day = v.substring(0,i1);
	i2 = v.indexOf("/",i1+1);
	month = v.substring(i1+1,i2);
	year = v.substring(i2+1);
	if ( month=="" || day=="" || year=="" || year.length!=4 || day<=0 ||
		month<=0 || year<0 || i2<i1 || isNaN(day) || isNaN(month) || isNaN(year))
		{
		textField.focus();
		window.alert("Digite a data no formato dd/mm/aaaa");
		textField.focus();
		return false;
	}
	else {
		monthsMax=new Array(12);
		monthsMax[0]=31; monthsMax[1]=28; monthsMax[2]=31;
		monthsMax[3]=30; monthsMax[4]=31; monthsMax[5]=30; monthsMax[6]=31;
		monthsMax[7]=31; monthsMax[8]=30; monthsMax[9]=31; monthsMax[10]=30;
		monthsMax[11]=31;
		if ((year%4)==0) monthsMax[1]=29;
		if (month>12) {
			textField.focus();
			window.alert("Mês Invalido");
			textField.focus();
			return false;
		}
		else if(day>monthsMax[month-1]) {
			months=new Array(12);
			months[0]="Janeiro"; months[1]="Fevereiro";
			months[2]="Março"; months[3]="Abril"; months[4]="Maio";
			months[5]="Junho"; months[6]="Julho"; months[7]="Agosto";
			months[8]="Setembro"; months[9]="Outubro"; months[10]="Novembro";
			months[11]="Dezembro";
			textField.focus();
			window.alert(months[month-1] + " só possui " +
			monthsMax[month-1] + " dias.");
			textField.focus();
			return false;
			}
		}
	return true;
}

function FormataTextoHTML(campo) {
	var texto;
	texto=campo.value;	
	texto = texto.replace("á","a");
	texto = texto.replace("é","e");
	texto = texto.replace("í","i");
	texto = texto.replace("ó","o");
	texto = texto.replace("ú","u");
	
	texto = texto.replace("â","a");
	texto = texto.replace("ê","e");
	texto = texto.replace("î","i");
	texto = texto.replace("ô","o");
	texto = texto.replace("û","u");
	
	texto = texto.replace("à","a");
	texto = texto.replace("è","e");
	texto = texto.replace("ì","i");
	texto = texto.replace("ò","o");
	texto = texto.replace("ù","u");

	texto = texto.replace("ã","a");
	texto = texto.replace("õ","o");
	texto = texto.replace("ü","u");
	texto = texto.replace("ç","c");

	texto = texto.replace("Á","A");
	texto = texto.replace("É","E");
	texto = texto.replace("Í","I");
	texto = texto.replace("Ó","O");
	texto = texto.replace("Ú","U");
	
	texto = texto.replace("À","A");
	texto = texto.replace("È","E");
	texto = texto.replace("Ì","I");
	texto = texto.replace("Ò","O");
	texto = texto.replace("Ù","U");
	
	texto = texto.replace("Â","A");
	texto = texto.replace("Ê","E");
	texto = texto.replace("Î","I");
	texto = texto.replace("Ô","O");
	texto = texto.replace("Û","U");

	texto = texto.replace("Ã","A");
	texto = texto.replace("Õ","O");
	texto = texto.replace("Ü","U");
	texto = texto.replace("Ç","C");
	var vbCrLf = String.fromCharCode( 13, 10 );
	//texto = texto.replace("\r\n","<br>");
	//texto = texto.replace("\n","<br>");
	texto = texto.replace(vbCrLf,"LI");
	
	return texto;
}

function Troca(campo,teclapres) {
	var texto;
	var tecla = teclapres.keyCode;
	texto=campo.value;
	if (tecla==13){
		texto= texto+"<Enter>";
	}
	//campo.value = texto;

	//return texto;
}

		
window.defaultStatus = "CimTech - Center for Information Management and Technology"

