// --------------------------------------------------------------- +
// - FUNÇÕES ADMIN
// - Desenvolvido por Adriano Fernandes [ Eurodance.com.br ]
// --------------------------------------------------------------- +

// -------------------------------- +
// - Seta um elemento
// -------------------------------- +
function $( nome ) {
	
	var nome = nome;
		
	if( document.getElementById( nome ) == undefined ) {
		
		alert( 'o elemento '+ nome +' não existe' );	
		return false;
		
	} else {
		
		return document.getElementById( nome );
		
	}
	
}

// -------------------- +
// - Funções Padrões
// -------------------- +
var sys = {

	// --------------------------------------------------- +
	// - Mostrar/Esconder Elemento
	// --------------------------------------------------- +	
	mostrarEsconder : function( numeroElemento ) {
			
		this.numeroElemento = parseInt( numeroElemento );
		this.elemento       = $( "descItemListagem" + this.numeroElemento );
		this.btMais 	    = $( "btMais"           + this.numeroElemento ); 
		
		if( this.elemento.style.display == "" ) {
			
			this.btMais.src 		    = arrDir[ 'RAIZ' ] + "_img/icoMenos.gif";
			this.elemento.style.display = "block";
			
		} else if( this.elemento.style.display == "block" ) {
			
			this.btMais.src 		    = arrDir[ 'RAIZ' ] +  "_img/icoMais.gif";
			this.elemento.style.display = "";		
			
		}		
		
	},
	
	// --------------------------------------------------- +
	// - função para alinhar um objeto no centro da tela
	// --------------------------------------------------- +	
	centralizarObjeto : function( nomeObjeto, heightObjeto, widthObjeto ) {
		
		this.nomeObjeto   = nomeObjeto;
		this.heightObjeto = parseInt( heightObjeto );	
		this.widthObjeto  = parseInt( widthObjeto  );		
		this.objeto       = $( this.nomeObjeto );
		this.heightTela   = ( screen.height / 2 ) - ( this.heightObjeto * 2 );
		
		if( this.widthObjeto != "" ) {
			
			this.widthTela = ( screen.width / 2 ) - ( this.widthObjeto / 2 );		
			
		}
		
		this.objeto.style.top     = this.heightTela + "px";	
		this.objeto.style.display = "block";			
		
	},
	
	// -------------------------------- +
	// - Função de Controle JSON
	// -------------------------------- +	
	controlerJson : function( request ) {
		
		this.request  = request;
		this.jsonData = eval( '(' + this.request + ')' );
		
		if( this.jsonData.erro != undefined && this.jsonData.erro != "" ) {
			return "erro";
		}
		if( this.jsonData.redirect != undefined && this.jsonData.redirect != "" ) {
			window.location = this.jsonData.redirect;
		}
		
		return "";
		
	},
	
	// -------------------------------- +
	// - Função de Controle
	// -------------------------------- +		
	controler : function( request ) {
		
		this.request    = request;
		this.arrRequest = this.request.split( "::::" );
		
		if( this.request.indexOf( "Erro::::" ) != -1 ) {
			return "erro";
		}
		if( this.request.indexOf( "Redirect::::" ) != -1 ) {
			window.location = this.arrRequest[ 1 ];
		}
		
		return "";
		
	},
	
	// -------------------------------- +
	// - Upload de Arquivos
	// -------------------------------- +		
	upload : function( formulario, id ) {
		
		this.formulario = formulario;
		this.id         = parseInt( id ); 
		
		// - insere campo oculto no form
		this.input = document.createElement( "input" );						
		this.input.setAttribute( "type" , "hidden"     );
		this.input.setAttribute( "id"   , "idRegistro" );
		this.input.setAttribute( "name" , "idRegistro" );
		this.input.setAttribute( "value", this.id      );
		
		$( this.formulario ).appendChild( this.input );
		
		// - faz upload das imagens
		$( this.formulario ).submit();	
		
		objAjax = new ajax();
		objAjax.carregandoAjax( "loadingEnvioForm", "<span style='color: #FF0000'>fazendo upload da(s) imagem(s)...</span>" );		
		
	},
	
	// -------------------------------- +
	// - Controla CSS das abas do form
	// -------------------------------- +			
	abasForm : function( elemento ) {
		
		this.base     = $( "abasFormCadastro" );
		this.abas     = this.base.getElementsByTagName( "li" );
		this.elemento = elemento;
		
		for( this.x = 0; this.x < this.abas.length; this.x++ ) {
			if( this.abas[ this.x ].id == this.elemento ) {
				this.abas[ this.x ].className = "abaSelecionada";
			} else {
				this.abas[ this.x ].className = "";				
			}
		}
		
	}
	
}