//============================================================================
// Função Trim
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

//============================================================================
function popup(url,name,windowWidth,windowHeight){
	myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	mytop=mytop-150;
	properties = "width="+windowWidth+",height="+windowHeight+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no, top="+mytop+",left="+myleft;
	newwindow=window.open(url,name,properties);
	if (window.focus) {newwindow.focus()}
}

//============================================================================
//---> Envia um form por post
function EnviaFormAcao(NomeDoForm,NomeDaAcao)
{

    document.getElementById('acao').value = NomeDaAcao;
    document.getElementById(NomeDoForm).submit();
}


//============================================================================
//---> Desabilita um form de nome formulario
function disableAll(){
	var el = document.formulario.elements;
	for(var i=0;i<el.length;i++){
		el[i].setAttribute('disabled',true)
		}
	}

//============================================================================
//---> Função mudar de campo automaticamente
function tabAutom(quem, e) 
{
	var MudarCampo = true;
	document.onkeypress = HabilitarTABAutom;


	if ( ( quem.value.length == quem.maxLength ) && ( MudarCampo ) ){
		var i=0,j=0, indice=-1;
		// vf_localiza em qual form está o input no documento
		for (i=0; i<document.forms.length; i++) {
			for (j=0; j<document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}

		// vf_localiza o input no documento e verifica se existe outro input para receber o foco
		for (i=0; i<document.forms[indice].elements.length; i++) 
		{
			if (document.forms[indice].elements[i].name == quem.name) 
			{
				while ( ((i+1) < document.forms[indice].elements.length) && 
				        ( (document.forms[indice].elements[(i+1)].type == "hidden") || 
					  (document.forms[indice].elements[(i+1)].name == "Lim") ) )
				{
							i++;
				}
				if ( (i+1) < document.forms[indice].elements.length )
				{
					document.forms[indice].elements[(i+1)].focus();
					MudarCampo = false;
				}
				break;
			} 
		}
	} 
}

//============================================================================
function HabilitarTABAutom(evt)
{
	var codTecla;

 	var e = evt ? evt : window.event; 

	if(e.keyCode)  // IE
	{
		codTecla = e.keyCode;
	}
	else // Netscape/Firefox/Opera
	{
		codTecla = e.which;
	}

	if ( (codTecla < 48) || (codTecla >  255) )
		MudarCampo = false;
	else
		MudarCampo = true;

}


