
document.oncontextmenu = desabilitar;
document.ondragstart = desabilitar;
function desabilitar() { return false; }


// *****************  MENU **********************

var OpcaoPaiAtivo = null;
var OpcaoFilhoAtivo = null;

function destacaPai(item)
{ item.className = "OpcaoPaiOver"; }

function normalPai(item)
{ item.className = "OpcaoPai"; }

function selecionaPai(OpcaoPai, OpcaoFilho)
{ if (OpcaoFilho.style.display == 'none')
	{ if (OpcaoFilhoAtivo != null)
	{ OpcaoFilhoAtivo.style.display = 'none';
	    OpcaoPaiAtivo.childNodes[0].className = "imagem"; }
	OpcaoPai.childNodes[0].className = "imagemSelecionado";
	OpcaoFilho.style.display = '';
	OpcaoPaiAtivo = OpcaoPai;
	OpcaoFilhoAtivo = OpcaoFilho;
	} else {
	OpcaoFilho.style.display = 'none';
	OpcaoPai.childNodes[0].className = "imagem";
	OpcaoFilhoAtivo = null;
	OpcaoPaiAtivo = null;
	}
}

// *****************  GRID **********************

function ItemHover(item) { 
	item.className = "grid-header-hover"; 
}

function ItemOut(item) { 
	item.className = "grid-header"; 
}

function itemSelected(){ 
	if(document.forms(0).myradiogroup==undefined)
		return false				
	if(document.forms(0).myradiogroup.length==undefined){
		if (document.forms(0).myradiogroup.checked){
			return true
		}		
	}
	for (i=0;i<document.forms(0).myradiogroup.length;i++){ 
		if (document.forms(0).myradiogroup[i].checked){
			return true
		}
	} 
	alert("Selecione um item na lista!");
	return false
}

function itemDelete(){ 
	if(document.forms(0).myradiogroup==undefined)
		return false				
	if(document.forms(0).myradiogroup.length==undefined){
		if (document.forms(0).myradiogroup.checked){
			return confirm ('Você tem certeza que deseja excluir esse item?');
		}		
	}
	for (i=0;i<document.forms(0).myradiogroup.length;i++){ 
		if (document.forms(0).myradiogroup[i].checked){
			return confirm ('Você tem certeza que deseja excluir esse item?');
		}
	} 
	alert("Selecione um item na lista!");
	return false
}

//*******************  ADICIONAL ***********************

function validar_adicional() {
	if(document.getElementById("txtCodigo").value=='') {
		alert('O campo codigo é obrigatório!');
		document.getElementById("txtCodigo").focus();
		return false;
	}

	if(document.getElementById("txtDescricao").value=='') {
		alert('O campo desricao é obrigatório!');
		document.getElementById("txtDescricao").focus();
		return false;
	}			
	if(document.getElementById("txtValor").value=='') {
		alert('O campo valor é obrigatório!');
		document.getElementById("txtValor").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	if(document.getElementById("ddlFormulario").value==0) {
		alert('O campo formulario é obrigatório!');
		document.getElementById("ddlFormulario").focus();
		return false;
	}			
	return true;
}

//*******************  ANEXO ***********************

function validar_anexo() {
	if(document.getElementById("txtCodigo").value=='') {
		alert('O campo codigo é obrigatório!');
		document.getElementById("txtCodigo").focus();
		return false;
	}
	if(document.getElementById("ddlMontagem").value==0) {
		alert('O campo montagem é obrigatório!');
		document.getElementById("ddlMontagem").focus();
		return false;
	}
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	return true;
}


//******************** CARAVANA ******************************

function validar_caravana() {
	if(document.getElementById('txtNomeCompleto').value=='') {
		alert('O campo nome completo é obrigatório!');
		document.getElementById('txtNomeCompleto').focus();
		return false;
	}
	if(document.getElementById('txtTelefone').value=='') {
		alert('O campo telefone é obrigatório!');
		document.getElementById('txtTelefone').focus();
		return false;
	}	
	if(document.getElementById('txtEndereco').value=='') {
		alert('O campo endereço é obrigatório!');
		document.getElementById('txtEndereco').focus();
		return false;
	}
	if(document.getElementById('txtBairro').value=='') {
		alert('O campo bairro é obrigatório!');
		document.getElementById('txtBairro').focus();
		return false;
	}
	if(document.getElementById('txtCidade').value=='') {
		alert('O campo cidade é obrigatório!');
		document.getElementById('txtCidade').focus();
		return false;
	}
	if(document.getElementById('txtEstado').value=='') {
		alert('O campo estado é obrigatório!');
		document.getElementById('txtEstado').focus();
		return false;
	}			
	if(document.getElementById('txtCEP').value=='') {
		alert('O campo CEP é obrigatório!');
		document.getElementById('txtEndereco').focus();
		return false;
	}		
	if(document.getElementById('txtCPF').value=='') {
		alert('O campo CPF é obrigatório!');
		document.getElementById('txtCPF').focus();
		return false;
	}	
	if(document.getElementById('txtEmail').value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById('txtEmail').focus();
		return false;
	}
	if(!checkMail(document.getElementById("txtEmail").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("txtEmail").focus();	
		return false;
	}	
	if(document.getElementById('txtComponente').value=='') {
		alert('O campo quantidade de componentes é obrigatório!');
		document.getElementById('txtComponente').focus();
		return false;
	}
	if(document.getElementById('txtVeiculo').value=='') {
		alert('O campo quantidade de veículos é obrigatório!');
		document.getElementById('txtVeiculo').focus();
		return false;
	}		
	return true;
}

//*******************  CATALOGO ***********************

function validar_catalogo() {
	if(document.getElementById("txtRazaoSocial").value=='') {
		alert('O campo razão social é obrigatório!');
		document.getElementById("txtRazaoSocial").focus();
		return false;
	}
	if(document.getElementById("txtNomeFantasia").value=='') {
		alert('O campo nome fantasia é obrigatório!');
		document.getElementById("txtNomeFantasia").focus();
		return false;
	}
	if(document.getElementById("txtContato").value=='') {
		alert('O campo contato é obrigatório!');
		document.getElementById("txtContato").focus();
		return false;
	}
	if(document.getElementById("txtCargo").value=='') {
		alert('O campo cargo é obrigatório!');
		document.getElementById("txtCargo").focus();
		return false;
	}
	return true;
}

//******************* CIRCULAR ***********************

function validar_circular() {
	if(document.getElementById("txtCodigo").value=='') {
		alert('O campo codigo é obrigatório!');
		document.getElementById("txtCodigo").focus();
		return false;
	}
	if(document.getElementById("ddlMontagem").value==0) {
		alert('O campo montagem é obrigatório!');
		document.getElementById("ddlMontagem").focus();
		return false;
	}
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	return true;
}

//******************* CONTEUDO ***********************

function validar_conteudo() {
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}
	return true;
}



//******************** CREDENCIAMENTO ******************************

function configurar_credencial() {		
	
	if(document.getElementById('h_feira').value == 2 || document.getElementById('h_feira').value == 1) { 
		document.getElementById('linha_como_soube_principal').style.display = 'block';
		if(document.getElementById('h_feira').value == 2) { 
			document.getElementById('linha_setor_interesse_principal').style.display = 'block';
			document.getElementById('linha_ramo_atividade_principal').style.display = 'block';
		}
	}
	else { 
		document.getElementById('linha_como_soube_principal').style.display = 'none';
		document.getElementById('linha_setor_interesse_principal').style.display = 'none';
		document.getElementById('linha_ramo_atividade_principal').style.display = 'none';
	}

	if(document.getElementById('ddlComoSoube').value == 99) { 
		document.getElementById('linha_como_soube').style.display = 'block';
	}
	else { 
		document.getElementById('linha_como_soube').style.display = 'none';
	}
	
	if(document.getElementById('rdbRamoAtividade_7').checked) { 
		document.getElementById('linha_ramo_atividade').style.display = 'block';
	}
	else { 
		document.getElementById('linha_ramo_atividade').style.display = 'none';
	}
	
	if(document.getElementById('chkSetorInteresse_11').checked) { 
		document.getElementById('linha_setor_interesse').style.display = 'block'; 
	}
	else { 
		document.getElementById('linha_setor_interesse').style.display = 'none'; 
	}			
}	
function validar_credencial() {
	if(document.getElementById('txtNomeCompleto').value=='') {
		alert('O campo nome completo é obrigatório!');
		document.getElementById('txtNomeCompleto').focus();
		return false;
	}
	if(document.getElementById('txtNomeCracha').value=='') {
		alert('O campo nome pra crachá é obrigatório!');
		document.getElementById('txtNomeCracha').focus();
		return false;
	}
	if(document.getElementById('txtEmpresa').value=='') {
		alert('O campo empresa é obrigatório!');
		document.getElementById('txtEmpresa').focus();
		return false;
	}
	if(document.getElementById('rdbRamoAtividade_7').checked && document.getElementById("txtRamoAtividade").value=='' && document.getElementById("h_feira").value==2) {
		alert('O campo ramo de atividade - outros é obrigatório!');
		document.getElementById("txtRamoAtividade").focus();
		return false; 
	}
	if(document.getElementById('chkSetorInteresse_11').checked && document.getElementById("txtSetorInteresse").value=='' && document.getElementById("h_feira").value==2) {
		alert('O campo setor de interesse - outros é obrigatório!');
		document.getElementById("txtSetorInteresse").focus();
		return false;
	}
	if(document.getElementById('txtEmail').value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById('txtEmail').focus();
		return false;
	}
	if(!checkMail(document.getElementById("txtEmail").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("txtEmail").focus();	
		return false;
	}	
	if(document.getElementById('ddlComoSoube').value==0 && document.getElementById("h_feira").value==2) { 
		alert('O campo como soube é obrigatório!');
		document.getElementById('ddlComoSoube').focus();
		return false;
	}
	if(document.getElementById('ddlComoSoube').value==99 && document.getElementById('txtComoSoube').value=='' && document.getElementById("h_feira").value==2) {
		alert('O campo como soube - outros é obrigatório!');
		document.getElementById('txtComoSoube').focus();
		return false;
	}
	return true;
}

//******************* EXPOSITOR ***********************

function validar_expositor() {
	if(document.getElementById("txtCodigo_I").value=='') {
		alert('O campo codigo_I é obrigatório!');
		document.getElementById("txtCodigo_I").focus();
		return false;
	}
	if(document.getElementById("txtRazaoSocial").value=='') {
		alert('O campo razão social é obrigatório!');
		document.getElementById("txtRazaoSocial").focus();
		return false;
	}
	if(document.getElementById("txtNomeFantasia").value=='') {
		alert('O campo nome fantasia é obrigatório!');
		document.getElementById("txtNomeFantasia").focus();
		return false;
	}
	if(document.getElementById("txtUsuario").value=='') {
		alert('O campo usuário é obrigatório!');
		document.getElementById("txtUsuario").focus();
		return false;
	}
	if(document.getElementById("txtSenha").value=='') {
		alert('O campo senha é obrigatório!');
		document.getElementById("txtSenha").focus();
		return false;
	}		
	if(document.getElementById("txtMetragem").value=='') {
		alert('O campo metragem é obrigatório!');
		document.getElementById("txtMetragem").focus();
		return false;
	}
    if(document.getElementById('h_arquivo_temp').value != "" && (document.getElementById('t_largura_selecao').value == "0" || document.getElementById('t_altura_selecao').value == "0")){
        alert('Crie uma seleção na imagem');
        return false;
    }
	return true;
}

//******************* FORMULARIO ***********************

function validar_formulario() {
	if(document.getElementById("txtDescricao").value=='') {
		alert('O campo descricao é obrigatório!');
		document.getElementById("txtDescricao").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	return true;
}

//******************* IMAGEM ***********************

function validar_imagem() {
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	if(document.getElementById("txtImagem").value=='' && document.getElementById("h_imagem").value==0) {
		alert('O campo imagem é obrigatório!');
		document.getElementById("txtImagem").focus();
		return false;
	}	
	return true;
}

//*******************  IMPRENSA ***********************

function validar_imprensa() {
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}	
	if(document.getElementById("ddlArea").value==0) {
		alert('O campo área é obrigatório!');
		document.getElementById("ddlArea").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	return true;
}

//*******************  LOCAL ***********************

function validar_local() {
	if(document.getElementById("txtNome").value=='') {
		alert('O campo nome do local é obrigatório!');
		document.getElementById("txtNome").focus();
		return false;
	}	
	return true;
}

//*******************  LOGIN ***********************

function validar_login() {
	if(document.getElementById("txtUsuario").value=='') {
		alert('O campo usuário é obrigatório!');
		document.getElementById("txtUsuario").focus();
		return false;
	}
	if(document.getElementById("txtSenha").value=='') {
		alert('O campo senha é obrigatório!');
		document.getElementById("txtSenha").focus();
		return false;
	}	
	return true;
}

function ini() {
	document.getElementById("txtUsuario").focus();
}

//******************* MANUAL ***********************

function validar_manual() {
	if(document.getElementById("txtCodigo").value=='') {
		alert('O campo codigo é obrigatório!');
		document.getElementById("txtCodigo").focus();
		return false;
	}
	if(document.getElementById("ddlMontagem").value==0) {
		alert('O campo montagem é obrigatório!');
		document.getElementById("ddlMontagem").focus();
		return false;
	}
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	return true;
}

//******************* MENU_ADM ***********************

function validar_menu_adm() {
	if(document.getElementById("txtOrdem").value=='') {
		alert('O campo ordem é obrigatório!');
		document.getElementById("txtOrdem").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}	
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}
	if(document.getElementById("txtDescricao").value=='') {
		alert('O campo descrição é obrigatório!');
		document.getElementById("txtDescricao").focus();
		return false;
	}		
	return true;
}

//******************* MONTADORA ***********************

function validar_montadora() {
	if(document.getElementById("txtNome").value=='') {
		alert('O campo nome é obrigatório!');
		document.getElementById("txtNome").focus();
		return false;
	}
	if(document.getElementById("txtUsuario").value=='') {
		alert('O campo usuário é obrigatório!');
		document.getElementById("txtUsuario").focus();
		return false;
	}
	if(document.getElementById("txtSenha").value=='') {
		alert('O campo senha é obrigatório!');
		document.getElementById("txtSenha").focus();
		return false;
	}		
	return true;
}

//*******************  MONTADORA ***********************

function validar_montadora_dado() {
	if(document.getElementById("txtRazaoSocial").value=='') {
		alert('O campo razão social é obrigatório!');
		document.getElementById("txtRazaoSocial").focus();
		return false;
	}
	if(document.getElementById("txtContato").value=='') {
		alert('O campo contato é obrigatório!');
		document.getElementById("txtContato").focus();
		return false;
	}
	return true;
}


//*******************  NEWSLETTER ***********************

function validar_assinante() {
	if(document.getElementById("txtNome").value=='') {
		alert('O campo nome é obrigatório!');
		document.getElementById("txtNome").focus();
		return false;
	}
	if(document.getElementById("txtEmail").value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById("txtEmail").focus();
		return false;
	}
	if(!checkMail(document.getElementById("txtEmail").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("txtEmail").focus();	
		return false;
	}	
	if(document.getElementById("txtEmpresa").value=='') {
		alert('O campo empresa é obrigatório!');
		document.getElementById("txtEmpresa").focus();
		return false;
	}		
	if(document.getElementById("ddlIdioma").value==0) {
		alert('O campo idioma é obrigatório!');
		document.getElementById("ddlIdioma").focus();
		return false;
	}
	if(document.getElementById("ddlSituacao").value==0) {
		alert('O campo situação é obrigatório!');
		document.getElementById("ddlSituacao").focus();
		return false;
	}
	return true;
}

//*******************  PALESTRA ***********************

function verifica_hora() {
	HoraIni = document.all['ddlHoraIni'];
	MinIni = document.all['ddlMinIni'];
	HoraFim = document.all['ddlHoraFim'];
	MinFim = document.all['ddlMinFim'];
	if(HoraIni.value > HoraFim.value){
		alert('O horário Inicial não pode ser maior que o Final');
		return false;
	}else if(HoraIni.value == HoraFim.value){
		if(MinIni.value != MinFim.value){
			if(MinIni.value > MinFim.value){
	      		alert('O horário Inicial não pode ser maior que o Final');
	      		return false;
			}
		}else{
			alert('O horário Inicial não pode ser igual ao Final');
			return false;
		}
	}
	return true;
}

function validar_palestra(feira) {	
	if(document.getElementById("ddlPagina").value==0 && feira==1) {
		alert('O campo página é obrigatório!');
		document.getElementById("ddlPagina").focus();
		return false;
	}
	if(document.getElementById("ddlGrupo").value==0 && feira==1) {
		alert('O campo grupo é obrigatório!');
		document.getElementById("ddlGrupo").focus();
		return false;
	}	
	if(document.getElementById("txtTema").value=='') {
		alert('O campo tema é obrigatório!');
		document.getElementById("txtTema").focus();
		return false;
	}
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo título é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}	
	/*if(document.getElementById("ddlPalestrante").value==0) {
		alert('O campo palestrante é obrigatório!');
		document.getElementById("ddlPalestrante").focus();
		return false;
	}*/
	if(!verifica_hora()) {
		return false;
	}		
	if(document.getElementById("ddlLocal").value==0) {
		alert('O campo local é obrigatório!');
		document.getElementById("ddlLocal").focus();
		return false;
	}		
	if(document.getElementById("ddlIdioma").value==0) {
		alert('O campo idioma é obrigatório!');
		document.getElementById("ddlIdioma").focus();
		return false;
	}		
	return true;
}

//*******************  PALESTRANTE ***********************

function validar_palestrante() {
	if(document.getElementById("txtNome").value=='') {
		alert('O campo nome é obrigatório!');
		document.getElementById("txtNome").focus();
		return false;
	}
	return true;
}

//*******************  PLANTA ***********************

function validar_planta_pequena() {
	if(document.getElementById("txtDescricaoPP").value=='') {
		alert('O campo descricao da planta pequena é obrigatório!');
		document.getElementById("txtDescricaoPP").focus();
		return false;
	}
	if(document.getElementById("txtCaminhoPP").value=='') {
		alert('O campo caminho da planta pequena é obrigatório!');
		document.getElementById("txtCaminhoPP").focus();
		return false;
	}			
	return true;	
}		
function validar_planta_grande() {
	if(document.getElementById("txtDescricaoPG").value=='') {
		alert('O campo descricao da planta grande é obrigatório!');
		document.getElementById("txtDescricaoPG").focus();
		return false;
	}
	if(document.getElementById("txtCaminhoPG").value=='') {
		alert('O campo caminho da planta grande é obrigatório!');
		document.getElementById("txtCaminhoPG").focus();
		return false;
	}			
	return true;
}

//*******************  SELECIONA_FEIRA ***********************

function validar_feira() {
	if(document.getElementById("ddlFeira").value==0) {
		alert('O campo feira é obrigatório!');
		document.getElementById("ddlFeira").focus();
		return false;
	}
	return true;
}

function seleciona_feira_ini() {
	document.getElementById("ddlFeira").focus();
}

//*******************  SENHA_ALTERAR ***********************

function validar_senha_alterar() {
	if(document.getElementById("txtSenhaAtual").value=='') {
		alert('O campo senha atual é obrigatório!');
		document.getElementById("txtSenhaAtual").focus();
		return false;
	}
	if(document.getElementById("txtSenhaNova").value=='') {
		alert('O campo senha nova é obrigatório!');
		document.getElementById("txtSenhaNova").focus();
		return false;
	}
	if(document.getElementById("txtConfirmarSenha").value=='') {
		alert('O campo senha nova é obrigatório!');
		document.getElementById("txtConfirmarSenha").focus();
		return false;
	}	
	if(document.getElementById("txtSenhaNova").value!=document.getElementById("txtConfirmarSenha").value) {
		alert('O campo senha nova deve ser igual ao campo confirmar senha!');
		document.getElementById("txtSenhaNova").focus();
		return false;
	}			
	return true;
}

function senha_alterar_ini() {
	document.getElementById("txtSenhaAtual").focus();
}

//*******************  SENHA_LEMBRAR ***********************

function validar_senha_lembrar() {
	if(document.getElementById("txtEmail").value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById("txtEmail").focus();
		return false;
	}
	if(!checkMail(document.getElementById("txtEmail").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("txtEmail").focus();	
		return false;
	}	
	return true;
}

function senha_lembrar_ini() {
	document.getElementById("txtEmail").focus();
}

//*******************  UPLOAD ***********************

function validar_upload() {
	if(document.getElementById("txtNomeArquivo").value=='') {
		alert('O campo nome do arquivo é obrigatório!');
		document.getElementById("txtNomeArquivo").focus();
		return false;
	}
	if(document.getElementById("txtCaminho").value=='') {
		alert('O campo caminho do arquivo é obrigatório!');
		document.getElementById("txtCaminho").focus();
		return false;
	}	
	return true;
}

//*******************  USUARIO ***********************

function validar_usuario() {
	if(document.getElementById("txtUsuario").value=='') {
		alert('O campo usuário é obrigatório!');
		document.getElementById("txtUsuario").focus();
		return false;
	}
	if(document.getElementById("txtEmail").value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById("txtEmail").focus();
		return false;
	}
	if(!checkMail(document.getElementById("txtEmail").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("txtEmail").focus();	
		return false;
	}	
	if(document.getElementById("txtSenha").value=='') {
		alert('O campo senha é obrigatório!');
		document.getElementById("txtSenha").focus();
		return false;
	}
	if(document.getElementById("ddlPerfil").value==0) {
		alert('O campo perfil é obrigatório!');
		document.getElementById("ddlPerfil").focus();
		return false;
	}		
	return true;
}

//******************** PROMOCAO ******************************

function validar_promocao() {
	if(document.getElementById('txtNomeCompleto').value=='') {
		alert('O campo nome completo é obrigatório!');
		document.getElementById('txtNomeCompleto').focus();
		return false;
	}
	if(document.getElementById('txtProfissao').value=='') {
		alert('O campo profissão é obrigatório!');
		document.getElementById('txtProfissao').focus();
		return false;
	}
	if(document.getElementById('txtEmpresa').value=='') {
		alert('O campo empresa é obrigatório!');
		document.getElementById('txtEmpresa').focus();
		return false;
	}		
	if(document.getElementById('txtEndereco').value=='') {
		alert('O campo endereço é obrigatório!');
		document.getElementById('txtEndereco').focus();
		return false;
	}
	if(document.getElementById('txtBairro').value=='') {
		alert('O campo bairro é obrigatório!');
		document.getElementById('txtBairro').focus();
		return false;
	}
	if(document.getElementById('txtCidade').value=='') {
		alert('O campo cidade é obrigatório!');
		document.getElementById('txtCidade').focus();
		return false;
	}
	if(document.getElementById('txtEstado').value=='') {
		alert('O campo estado é obrigatório!');
		document.getElementById('txtEstado').focus();
		return false;
	}			
	if(document.getElementById('txtCEP').value=='') {
		alert('O campo CEP é obrigatório!');
		document.getElementById('txtCEP').focus();
		return false;
	}
	if(document.getElementById('txtTelefone').value=='') {
		alert('O campo telefone é obrigatório!');
		document.getElementById('txtTelefone').focus();
		return false;
	}				
	if(document.getElementById('txtEmail').value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById('txtEmail').focus();
		return false;
	}
	if(!checkMail(document.getElementById("txtEmail").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("txtEmail").focus();	
		return false;
	}	
	for (i=0;i<3;i++) { 
		var num = i + 1;
		if(document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoNome").value=='') {
			alert('O campo nome completo do profissional ' + num + ' é obrigatório!');
			document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoNome").focus();
			return false;		
		}
		if(document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoProfissao").value=='') {
			alert('O campo profissão do profissional ' + num + ' é obrigatório!');
			document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoProfissao").focus();
			return false;		
		}
		if(document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoEmpresa").value=='') {
			alert('O campo empresa do profissional ' + num + ' é obrigatório!');
			document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoEmpresa").focus();
			return false;		
		}
		if(document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoEmail").value=='') {
			alert('O campo e-mail do profissional ' + num + ' é obrigatório!');
			document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoEmail").focus();
			return false;		
		}	
		if(!checkMail(document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoEmail").value)) {
			alert('O e-mail do profissional ' + num + ' é inválido!');
			document.getElementById("r_indicacao__ctl"+i+"_txtIndicacaoEmail").focus();	
			return false;
		}									
	}	
	return true;
}

function validar_pergunta() {
	if(document.getElementById("txtDescricao").value=='') {
		alert('Digite uma pergunta para ser adicionada!');
		document.getElementById("txtDescricao").focus();
		return false;
	}
	return true;
}

function validar_resposta() {
	if(document.getElementById("txtDescricao").value=='') {
		alert('Digite uma resposta para ser adicionada!');
		document.getElementById("txtDescricao").focus();
		return false;
	}
	return true;
}

function validar_pesquisa() {
	if(document.getElementById("txtTitulo").value=='') {
		alert('O campo titulo é obrigatório!');
		document.getElementById("txtTitulo").focus();
		return false;
	}
	return true;
}

function validar_pesquisa_pergunta() {
	if(document.getElementById("ddlPergunta").value==0) {
		alert('Selecione uma pergunta para ser adicionada!');
		document.getElementById("ddlPergunta").focus();
		return false;
	}
	return true;
}

function validar_pesquisa_resposta() {
	if(document.getElementById("ddlResposta").value==0) {
		alert('Selecione uma resposta para ser adicionada!');
		document.getElementById("ddlResposta").focus();
		return false;
	}
	return true;
}

//****************** FUNCAO ***************************

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string") {
        if(er.test(mail)) { return true; }
	}
	else if(typeof(mail) == "object") {
		if(er.test(mail.value)) { return true; }
	}
    else {
        return false;
    }
}

function isNum(event) {
	var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (Key == 8 || Key == 13 || Key == 44 || Key == 127 || (Key >= 48 && Key <= 57)) return true;
	else return false;
}

//###################################################################################
function mostraimg(linha,campo,img) {
  var linha = document.getElementById(linha);
  var campo = document.getElementById(campo);
  if (campo.value != '' || img.src != '') {
    linha.style.display='';
  }else {
    linha.style.display='none';
  }
}
//###################################################################################
function VerImagem(campo,img) { 
    img.src = campo.value;
}



//###################################################################################

documentall = document.all;

function formatamoney(c) {
    var t = this; if(c == undefined) c = 2;		
    var p, d = (t=t.split("."))[1].substr(0, c);
    for(p = (t=t[0]).length; (p-=3) >= 1;) {
	        t = t.substr(0,p) + "." + t.substr(p);
    }
    return t+","+d+Array(c+1-d.length).join(0);
}

String.prototype.formatCurrency=formatamoney

function demaskvalue(valor, currency){
// Se currency é false, retorna o valor sem apenas com os números. Se é true, os dois últimos caracteres são considerados as casas decimais
var val2 = '';
var strCheck = '0123456789';
var len = valor.length;
	if (len== 0){
		return 0.00;
	}

	if (currency ==true){	
		// Elimina os zeros à esquerda a variável  <i> passa a ser a localização do primeiro caractere após os zeros e val2 contém os caracteres (descontando os zeros à esquerda)
		for(var i = 0; i < len; i++)
			if ((valor.charAt(i) != '0') && (valor.charAt(i) != ',')) break;
		
		for(; i < len; i++){
			if (strCheck.indexOf(valor.charAt(i))!=-1) val2+= valor.charAt(i);
		}

		if(val2.length==0) return "0.00";
		if (val2.length==1)return "0.0" + val2;
		if (val2.length==2)return "0." + val2;
		
		var parte1 = val2.substring(0,val2.length-2);
		var parte2 = val2.substring(val2.length-2);
		var returnvalue = parte1 + "." + parte2;
		return returnvalue;
		
	}
	else{
			// currency é false: retornamos os valores COM os zeros à esquerda, sem considerar os últimos 2 algarismos como casas decimais 
			val3 ="";
			for(var k=0; k < len; k++){
				if (strCheck.indexOf(valor.charAt(k))!=-1) val3+= valor.charAt(k);
			}			
	return val3;
	}
}

function reais(obj,event){

var whichCode = (window.Event) ? event.which : event.keyCode;
//Executa a formatação após o backspace nos navegadores !document.all
if (whichCode == 8 && !documentall) {	
//Previne a ação padrão nos navegadores
	if (event.preventDefault){ //standart browsers
			event.preventDefault();
		}else{ // internet explorer
			event.returnValue = false;
	}
	var valor = obj.value;
	var x = valor.substring(0,valor.length-1);
	obj.value= demaskvalue(x,true).formatCurrency();
	return false;
}
//Executa o Formata Reais e faz o format currency novamente após o backspace
FormataReais(obj,'.',',',event);
} // end reais


function backspace(obj,event){
//Essa função basicamente altera o  backspace nos input com máscara reais para os navegadores IE e opera.
//O IE não detecta o keycode 8 no evento keypress, por isso, tratamos no keydown.
//Como o opera suporta o infame document.all, tratamos dele na mesma parte do código.

var whichCode = (window.Event) ? event.which : event.keyCode;
if (whichCode == 8 && documentall) {	
	var valor = obj.value;
	var x = valor.substring(0,valor.length-1);
	var y = demaskvalue(x,true).formatCurrency();

	obj.value =""; //necessário para o opera
	obj.value += y;
	
	if (event.preventDefault){ //standart browsers
			event.preventDefault();
		}else{ // internet explorer
			event.returnValue = false;
	}
	return false;

	}// end if		
}// end backspace

function FormataReais(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;

//if (whichCode == 8 ) return true; //backspace - estamos tratando disso em outra função no keydown
if (whichCode == 0 ) return true;
if (whichCode == 9 ) return true; //tecla tab
if (whichCode == 13) return true; //tecla enter
if (whichCode == 16) return true; //shift internet explorer
if (whichCode == 17) return true; //control no internet explorer
if (whichCode == 27 ) return true; //tecla esc
if (whichCode == 34 ) return true; //tecla end
if (whichCode == 35 ) return true;//tecla end
if (whichCode == 36 ) return true; //tecla home


//O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script


if (e.preventDefault){ //standart browsers
		e.preventDefault()
	}else{ // internet explorer
		e.returnValue = false
}

var key = String.fromCharCode(whichCode);  // Valor para o código da Chave
if (strCheck.indexOf(key) == -1) return false;  // Chave inválida


//Concatenamos ao value o keycode de key, se esse for um número

fld.value += key;

var len = fld.value.length;
var bodeaux = demaskvalue(fld.value,true).formatCurrency();
fld.value=bodeaux;


//Essa parte da função tão somente move o cursor para o final no opera. Atualmente não existe como movê-lo no konqueror.

  if (fld.createTextRange) {
    var range = fld.createTextRange();
    range.collapse(false);
    range.select();
  }
  else if (fld.setSelectionRange) {
    fld.focus();
    var length = fld.value.length;
    fld.setSelectionRange(length, length);
  }
  return false;

}
