function confirmaLogout( caminho ) {
	if ( confirm("Voc\xEA tem certeza que deseja sair do Painel de Controle?") )
		window.location.replace( caminho );
}
function confirmaLogout_en( caminho ) {
	if ( confirm("Are you sure that you wish to leave the Control Panel?") )
		window.location.replace( caminho );
}
function confirmaLogout_pt( caminho ) {
	confirmaLogout( caminho );
}

function confirmaExclusao( msg, caminho ) {
	if ( confirm("Voc\xEA tem certeza que deseja excluir "+msg+"?") )
		window.location.replace( caminho );
}
function confirmaExclusao_en( msg, caminho ) {
	if ( confirm("Are you sure about the deletion of "+msg+"?") )
		window.location.replace( caminho );
}
function confirmaExclusao_pt( msg, caminho ) {
	confirmaExclusao( msg, caminho );
}
function confirmaExclusaoEmCascata( msg, msg2, caminho ) {
	if ( confirm("Voc\xEA tem certeza que deseja excluir "+msg+"?\n"+
				 "\n"+
				 msg2) )
		window.location.replace( caminho );
}
function confirmaExclusaoEmCascata_en( msg, msg2, caminho ) {
	if ( confirm("Are you sure about the deletion of "+msg+"?\n"+
				 "\n"+
				 msg2) )
		window.location.replace( caminho );
}
function confirmaExclusaoEmCascata_pt( msg, msg2, caminho ) {
	confirmaExclusaoEmCascata( msg, msg2, caminho );
}

function getById( elemento ) {
	return document.getElementById( elemento );
}
function elemento( elemento ) {
	return getById( elemento );
}

function isVisivel( elemento ) {
	return getById( elemento ).style.display == 'block';
}

function mostra( elemento ) {
	getById( elemento ).style.display = 'block';
}
function esconde( elemento ) {
	getById( elemento ).style.display = 'none';
}

function mostraEsconde( elemento ) {
	if ( isVisivel(elemento) )
		esconde( elemento );
	else
		mostra( elemento );
}

function escondeArray( elementos ) {
	for ( i=0 ; i < elementos.length ; i++ )
		esconde( elementos[i] );
}
function mostraArray( elementos ) {
	for ( i=0 ; i < elementos.length ; i++ )
		mostra( elementos[i] );
}

function escondeObjeto( elemento ) {
	elemento.style.display = 'none';
}
function mostraObjeto( elemento ) {
	elemento.style.display = 'block';
}

function numeroAleatorio( limInf, limSup ) {
	return Math.floor( Math.random()*(1 + limSup - limInf) + limInf );
}

function getRequestAJAX() {
	if ( window.XMLHttpRequest )
		return new XMLHttpRequest();
	else if ( window.ActiveXObject )
		return new ActiveXObject( "Microsoft.XMLHTTP" );
	else {
		 alert( "Seu browser n\xE3o suporta AJAX!" );
		return null;
	}
}

/** Retorna o objeto flash.
 */
function getObjetoFlash( objetoFlash ) {
	if ( navigator.appName == "Netscape" )
		return document.embeds[0];
	else
		return window[ objetoFlash ];
}
function abreMenu( objetoFlash, quadro ) {
	// Vai para o quadro especificado pelo Numero
	//getObjetoFlash( objetoFlash ).GotoFrame( quadro );

	// Vai para o quadro especificado pelo Label
	getObjetoFlash( objetoFlash ).TGotoLabel( "_root", quadro );
	//getObjetoFlash( objetoFlash ).Play();
}

/** Elemento visivel. */
var elementoVisivel = null;
/** Esconde o elemento visivel atualmente, exibe outro elemento e atualiza a variavel 'elementoVisivel'.
 */
function escondeVisivelEMostra( elemento ) {
	if ( elementoVisivel != null )
		esconde( elementoVisivel );
	mostra( elemento );
	elementoVisivel = elemento;
}

function insereFlash( caminho, largura, altura, wmode, bgcolor, align ) {
	document.write(
		"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\""+largura+"\" height=\""+altura+"\" id=\"topo\" align=\""+align+"\">"+
			"<param name=\"allowScriptAccess\" value=\"sameDomain\"/><param name=\"movie\" value=\""+caminho+"\"/><param name=\"quality\" value=\"high\"/><param name=\"scale\" value=\"noscale\"/><param name=\"wmode\" value=\""+wmode+"\"/><param name=\"bgcolor\" value=\""+bgcolor+"\"/>"+
			"<embed src=\""+caminho+"\" quality=\"high\" scale=\"noscale\" wmode=\""+wmode+"\" bgcolor=\""+bgcolor+"\" width=\""+largura+"\" height=\""+altura+"\" name=\"topo\" align=\""+align+"\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"/>"+
		"</object>"
	);
}

function algumMarcado( campo ) {
	if ( campo.length == undefined )
		return campo.checked;
	else
		for ( i=0 ; i < campo.length ; i++ )
			if ( campo[i].checked )
				return true;
	return false;
}

function vazio( str ) {
	return trim( str ) == "";
}

function trim( str ) {
	return str.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

function imagemValida( str ) {
	return str.toLowerCase().match( /^.+((\.gif)|(\.jpg)|(\.jpeg)|(\.png))$/g ) ? true : false;
}

function flashValido( str ) {
	return str.toLowerCase().match( /^.+((\.swf))$/g ) ? true : false;
}

function PDFValido( str ) {
	return str.toLowerCase().match( /^.+((\.pdf))$/g ) ? true : false;
}

function TXTValido( str ) {
	return str.toLowerCase().match( /^.+((\.txt))$/g ) ? true : false;
}

function horaCompleta( str ){
	return str.match( /^\d+:[0-5]\d:[0-5]\d$/ ) ? true : false;
}

function dataCompletaValida( str ) {
 	return str.match( /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/(19|20)?\d{2}$/ ) ? true : false;
}

function CEPValido( str ) {
	return str.match( /^\d{5}-\d{3}$/g ) ? true : false;
}

function horaValida( str ) {
	return str.match( /^\d{2}:\d{2}$/g ) ? true : false;
}

function emailValido( str ) {
	return str.match( /^(([^\W]([\w_\.\-])*[^\W])|(\w))@(([\w_\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ) ? true : false;
}

function somenteNumeros( str ) {
	return str.match( /^\d+$/g ) ? true : false;
}

function precoValido( str ) {
	return str.match( /^\d{1,3}((\.){0,1}\d{1,3})*([,]\d{1,2}){0,1}$/g ) ? true : false;
}

function DDDValido( str ){
	return somenteNumeros( str ) && str.length == 2;
}

function telefoneValidoSemDDD( str ){
	return str.match( /^\d{3,4}[\s|-]*\d{4}$/g ) ? true : false;
}

function telefoneValidoComDDD( str ){
	return str.match( /\(\d{2}\)\ \d{4}\-\d{4}$/g ) ? true : false;
}

function substituiAspasSimplesEmTodosCampos( formulario ) {
	for ( var i=0 ; i<formulario.elements.length ; i++ )
		if ( formulario.elements[i].value != "" )
			formulario.elements[i].value = formulario.elements[i].value.replace( /[']/g, "`" );
}

/*CLASSE PARA VALIDACAO DE FORMULARIOS*/

function ValidadorDeFormulario() {
	this.limpaCampoObrigatorio = function(elemento,botao_enviar) {
		elemento.value = "";
		botao_enviar.disabled = true;
	}
	this.validaTexto = function(elemento,botao_enviar) {
		if ( vazio(elemento.value) ) {
			elemento.style.border = "1px solid #ff0000";
			elemento.style.color = "#ff0000";
			elemento.value = "Campo vazio!";
			botao_enviar.disabled = true;
		}else if( somenteNumeros(elemento.value) ) {
			elemento.style.border = "1px solid #ff0000";
			elemento.style.color = "#ff0000";
			elemento.value = "Não insira apenas números!";
			botao_enviar.disabled = true;
		}else{
			elemento.style.border = "";
			elemento.style.color = "";
			botao_enviar.disabled = false;
		}
	}
	this.validaEmail = function(elemento,botao_enviar) {
		if ( vazio(elemento.value) ) {
			elemento.style.border = "1px solid #ff0000";
			elemento.style.color = "#ff0000";
			elemento.value = "Campo vazio!";
			botao_enviar.disabled = true;
		}else if( !emailValido(elemento.value) ) {
			elemento.style.border = "1px solid #ff0000";
			elemento.style.color = "#ff0000";
			elemento.value = "E-mail inválido!";
			botao_enviar.disabled = true;
		}else{
			elemento.style.border = "";
			elemento.style.color = "";
			botao_enviar.disabled = false;
		}
	}
	this.validaTelefone = function(elemento,botao_enviar) {
		if ( vazio(elemento.value) ) {
			elemento.style.border = "1px solid #ff0000";
			elemento.style.color = "#ff0000";
			elemento.value = "Campo vazio!";
			botao_enviar.disabled = true;
		}else if( !telefoneValidoComDDD(elemento.value) ) {
			elemento.style.border = "1px solid #ff0000";
			elemento.style.color = "#ff0000";
			elemento.value = "Preencha corretamente o telefone com DDD!";
			botao_enviar.disabled = true;
		}else{
			elemento.style.border = "";
			elemento.style.color = "";
			botao_enviar.disabled = false;
		}
	}
}
var validador = new ValidadorDeFormulario();

