/**
	* Flag para carregamento de dados
	*
	* Flag for load data. 
	*/
	var AJAX_LOADED = true;
	
function checkAjaxLoaded( strUrl )
{
	if( AJAX_LOADED == false )
	{
		return;	
	}
	else
	{
		if( strUrl.indexOf( '(' ) == -1 )
		{
			window.location = strUrl;
		}
		else
		{
			eval( strUrl );
		}
	}
}

function confirmDelete( strMessage, strUrlRedirection )
{
	var is_confirmed = confirm( strMessage );
	if ( is_confirmed )
	{
		document.location.href = strUrlRedirection;
	}
}

function confirmInsert( strMessage, strUrlRedirection )
{
	var is_confirmed = confirm( strMessage );
	if ( is_confirmed )
	{
		document.location.href = strUrlRedirection;
	}
}

function scrollHorizontal(sofreScroll,baseScroll)
{
	document.getElementById(sofreScroll).scrollLeft = document.getElementById(baseScroll).scrollLeft;
}

function geraInputHidden( objForm , name, value )
{
	objInput = document.createElement("input");
	objInput.type  = "hidden";
	objInput.name  = name;
	objInput.value = value;
	objForm.appendChild( objInput );
}

function submitForm( objForm , name, anchor, anchorSubmit )
{
	if( anchor == undefined )
	{
		anchor = "";	
	}
	anchor += "";
	
	geraInputHidden( objForm , name, "1" )
	if( anchor.length > 0 )
	{
		if( anchorSubmit )
		{
			geraInputHidden( objForm, 'anchor', anchor );
		}
		objForm.action += '#'+anchor;
	}
	objForm.submit();
}

function submitFormValue( objForm , name , value )
{
	geraInputHidden( objForm , name, value )
	objForm.submit();
}

function geraItensSelecionados( objForm, select, nomeLista )
{
	for( i = 0; i < select.length; i++)
	{
		geraInputHidden( objForm, nomeLista, select.options[i].value );
	}
}

function cleanForm( objForm )
{
	for( var i = 0; i < objForm.elements.length; i++ )
	{
		if( objForm.elements[i].type != "hidden"
		 && objForm.elements[i].type != "radio" 
		 && objForm.elements[i].type != "checkbox" 
		 && objForm.elements[i].type != "button" )
		{
			// apagar o conteudo dos elementos de formulario que nao 
			// sao hidden nem botoes
			objForm.elements[i].value = "";
		}
	}
	
	// se existir um tinyMCE no formulario
	if( document.getElementById("mce_editor_0") )
	{
		if( document.getElementById("mce_editor_0").Document )
		{ // maneira IE de acessar o conteudo do iframe 
			// apagar o conteudo do tinymce
			document.getElementById("mce_editor_0").Document.body.innerHTML = "";		
		}
		else
		{ // maneira OUTROS de acessar o conteudo do iframe 
			// apagar o conteudo do tinymce
			document.getElementById("mce_editor_0").contentDocument.body.innerHTML = "";		
		}
	}
	
}

function dirSimples( selectEsq, selectDir )
{
	for( i = 0; i < selectEsq.length; i++ ){
		if( selectEsq.options[i].selected == true ){
			//selectDir.options[selectDir.length] = new Option( selectEsq.options[i].text, selectEsq.options[i].value );
			newOp = new Option();
			newOp.text = selectEsq.options[i].text;
			newOp.value = selectEsq.options[i].value;	
			newOp.onmouseover = selectEsq.options[i].onmouseover;
			newOp.onmouseout = selectEsq.options[i].onmouseout;
			selectDir.options[selectDir.length] = newOp;		
			selectEsq.options[i] = null;
			i--;
		}
	}
}

function esqSimples( selectEsq, selectDir )
{
	for( i = 0; i < selectDir.length; i++ ){
		if( selectDir.options[i].selected == true ){
			//selectEsq.options[selectEsq.length] = new Option( selectDir.options[i].text, selectDir.options[i].value);
			newOp = new Option();
			newOp.text = selectDir.options[i].text;
			newOp.value = selectDir.options[i].value;	
			newOp.onmouseover = selectDir.options[i].onmouseover;
			newOp.onmouseout = selectDir.options[i].onmouseout;
			selectEsq.options[selectEsq.length] = newOp;
			selectDir.options[i] = null;
			i--;
		}
	}
}

function dirDupla( selectEsq, selectDir )
{
	while( selectEsq.options[0] != null ){		  
		//selectDir.options[selectDir.length] = new Option( selectEsq.options[0].text, selectEsq.options[0].value );
		newOp = new Option();
		newOp.text = selectEsq.options[0].text;
		newOp.value = selectEsq.options[0].value;	
		newOp.onmouseover = selectEsq.options[0].onmouseover;
		newOp.onmouseout = selectEsq.options[0].onmouseout;
		selectDir.options[selectDir.length] = newOp;
		selectEsq.options[0] = null;
	}
}

function esqDupla( selectEsq, selectDir )
{
	while( selectDir.options[0] != null ){		  
		//selectEsq.options[selectEsq.length] = new Option( selectDir.options[0].text, selectDir.options[0].value );
		newOp = new Option();
		newOp.text = selectDir.options[0].text;
		newOp.value = selectDir.options[0].value;	
		newOp.onmouseover = selectDir.options[0].onmouseover;
		newOp.onmouseout = selectDir.options[0].onmouseout;
		selectEsq.options[selectEsq.length] = newOp;
		selectDir.options[0] = null;
	}
}


function showHideMenu( elementId , indicatorId )
{
	//document.getElementById('conteudo').style.display='none';
	
	// estado do menu
	// true = aberto, false = fechado
	var estadoNovo;

    if(document.getElementById(elementId).style.display == "none"){
    	document.getElementById(elementId).style.display = "block";
    	document.getElementById(indicatorId).className = "seta setaCinzaCima";
    	estadoNovo = 1;
    } else {
    	document.getElementById(elementId).style.display = "none";
    	document.getElementById(indicatorId).className = "seta setaCinzaBaixo";
    	estadoNovo = 0;
    }

	//document.getElementById('conteudo').style.display='block';
	
	// registro do estado do menu no sistema por xmlrequest
	do_call_class_action( "default", "refreshMenu",  Array( elementId, estadoNovo ) , afterShowHideMenu);
}

// funcao que trata a resposta do xmlrequest
function afterShowHideMenu( strResult , objXml ){}

// funcao que retorna qual o formul?rio algum determinado objeto (elemento) pertence
function getFormByElement( objElement )
{
	// iniciando as variaveis internas
	var objForm = null;
	var objActual = objElement;
	
	// capturando o objeto formulario deste respectivo objeto (elemento)
	while( objForm == null && objActual.parentNode != document.body )
	{
		objActual = objActual.parentNode;
		var strTagName = objActual.tagName + '';
		if ( strTagName.toUpperCase() == 'FORM' )
		{
			objForm = objActual;
		}
	}
	
	// retorno da funcao
	return( objForm );
}

// funcao que direciona o ponteiro (foco) para o proximo input (atraves do tabindex)
function goToNextHtmlElement( Event , objElement )
{
    // captura qual tecla foi pressionada a partir do evento
	var intKeyCode = getIntKeyCode( Event );
	var strKeyType = getKeyType( intKeyCode );
    
    // captura o tabindex do elemento html atual
	var intActualIndex = objElement.getAttribute( "tabindex" );

    // incrementa o tabindex atual
	++intActualIndex;

    // caso seja o ENTER pressionado
    if ( strKeyType == 'enter' )
    {
		// capturando o objeto formulario deste respectivo objeto (elemento)
		objForm = getFormByElement( objElement );
		
		// caso encontre algum formulario
		if ( objForm != null )
		{    
	    	// captura os arrays de elementos input, select, textarea deste formulario
			var arrChildsInput       = document.body.getElementsByTagName( "input" );
			var arrChildsSelect      = document.body.getElementsByTagName( "select" );
			var arrChildsTextarea    = document.body.getElementsByTagName( "textarea" );
			
			// criacao do novo array contendo todos os arrays de elementos input, select e textarea
			var arrChilds = new Array();
			arrChilds = arrChilds.concat( parseArray( arrChildsInput ) , parseArray( arrChildsSelect ) , parseArray( arrChildsTextarea ) );
			
			// varrendo este novo array
			for( var i = 0; i < arrChilds.length; i++ )
			{
				// cada objeto (elemento) deste novo array
				var objChild = arrChilds[ i ];				
				if( !objChild )
				{
					continue;
				}

				// caso seja o objeto na qual se deve dar o foco
				if( objChild.getAttribute && objChild.getAttribute( "tabindex" ) == intActualIndex )
				{
					// focaliza o input correto
					objChild.focus();
					return( false );
				}
			}
			return( false );
		}
    }
    else
    {
    	// retorno da funcao
   		return( true );
   	}
}

// funcao que submete o formulario atraves da tecla ENTER
function submitThisHtmlElement( Event , objElement )
{
	// captura qual tecla foi apertada a partir do evento
    var intKeyCode = getIntKeyCode( Event );
	var strKeyType = getKeyType( intKeyCode );
    
    // caso seja apertado o ENTER, submeter este formulario
    if ( strKeyType == 'enter' )
    {	
 		// capturando o objeto formulario deste respectivo objeto (elemento)
		objForm = getFormByElement( objElement );
		
		// caso encontre algum formulario
		if ( objForm != null )
		{
			// submete o formulario
			objForm.submit();
		}
	}
    // retorno da funcao    
    return( true );
}

function changeUrl( strUrl )
{
	document.location.href = strUrl;
}

function validateSearch( objSearch )
{
	strValue = objSearch.search.value;
	if( strValue.length < 4 )
	{
		alert( "Favor inserir mais de três caracteres na sua busca." );
		return false
	}
	return true;
}