function $WR(a) {
	return document.getElementById(a);
}

function $WRV(a) {
	return $WR(a).value;
}

function valida_busca() {
	if ( $WRV('busca') == "" ) {
		alert("O campo Busca é campo obrigatório!");
		$WR('busca').focus();
		return false;
	}
}

function valida_altera_senha() {
	if ( $WRV('senhaatual') == "" ) {
		alert("A Senha atual é campo obrigatório!");
		$WR('senhaatual').focus();
		return false;
	}
	if ( $WRV('novasenha') == "" ) {
		alert("A Nova Senha é campo obrigatório!");
		$WR('novasenha').focus();
		return false;
	}
	if ( $WRV('novasenha_repet') == "" ) {
		alert("A repetiçao da Nova Senha é campo obrigatório!");
		$WR('novasenha_repet').focus();
		return false;
	}
	if ( $WRV('novasenha') != $WRV('novasenha_repet') ) {
		alert("O campo Nova Senha é diferente da repetiçao da Nova Senha");
		return false;
	}
	return true;
}

function altera_segmento( element ) {
	if ( element.value ) {
		window.location=element.value;
	} else {
		alert("Por favor, selecione um segmento!");
	}
}

function altera_modulo( element ) {
	var titulo = element.options[element.selectedIndex].text;
	element.blur();
	document.getElementById('login').focus();
	Modal(titulo, element.value);
}

function Modal( titulo, id ) {
	TB_show(titulo, 'solucao_popup.php?modulo='+id+'&amp;keepThis=true&amp;TB_iframe=true&amp;height=330&amp;width=700', false);
}

function ModalItem( titulo, id ) {
	TB_show(titulo, 'solucao_popup_item.php?item='+id+'&keepThis=true&TB_iframe=true&height=330&width=700', false);
}

function ModalItemS( titulo, id, sub_item ) {
	TB_show(titulo, 'solucao_popup_item.php?item='+id+'&sub_item='+sub_item+'&keepThis=true&TB_iframe=true&height=330&width=700', false);
}

function getFile(url){
	var downloadWindow = window.open(url, 'Download' ,'menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,width=400,height=200,top=100,left=100');
	if(downloadWindow == null){
		alert("Seu navegador está com suporte a popups desabilitado.");
	}
}

function valida_esqueci_senha() {
	if ( $WRV('email') == "" ) {
		alert("O E-mail é campo obrigatório!");
		$WR('email').focus();
		return false;
	}
	return true;
}

function valida_busca_simples() {
	if ( $WRV('palavra_chave') == "" ) {
		alert("O campo de busca é campo obrigatório!");
		$WR('palavra_chave').focus();
		return false;
	}
	else {
		//$WR('FormBuscaSimples').submit();
		document.getElementById("FormBuscaSimples").submit()
	}
	return true;
}

function valida_busca_completa() {
	if ( $WRV('estado') == "" ) {
		alert("O Estado é campo obrigatório!");
		$WR('estado').focus();
		return false;
	}
	else {
		$WR('FormBuscaCompleta').submit();
	}
	return true;
}

function valida_login() {
	if ( $WRV('login') == "" ) {
		alert("O Login é campo obrigatório!");
		$WR('login').focus();
		return false;
	}
	if ( $WRV('senha') == "" ) {
		alert("A Senha é campo obrigatório!");
		$WR('senha').focus();
		return false;
	}
	return true;
}

function valida_curriculo() {
	if ( $WRV('nome') == "" ) {
		alert("O Nome é campo obrigatório!");
		$WR('nome').focus();
		return false;
	}
	if ( $WRV('dt_nascimento') == "" ) {
		alert("A Data de Nascimento é campo obrigatório!");
		$WR('dt_nascimento').focus();
		return false;
	}
	if ( $WRV('rg') == "" ) {
		alert("O RG é campo obrigatório!");
		$WR('rg').focus();
		return false;
	}
	if ( $WRV('cpf') == "" ) {
		alert("O CPF é campo obrigatório!");
		$WR('cpf').focus();
		return false;
	}
	if ( $WRV('area_atuacao') == "" ) {
		alert("A Área de atuaçao é campo obrigatório!");
		$WR('area_atuacao').focus();
		return false;
	}
	if ( $WRV('apresentacao') == "" ) {
		alert("A Apresentaçao é campo obrigatório!");
		$WR('apresentacao').focus();
		return false;
	}
	if ( $WRV('email') == "" ) {
		alert("O E-mail é campo obrigatório!");
		$WR('email').focus();
		return false;
	} else {
		if ( !valida_email($WR('email')) ) {
			return false;
		}
	}
	if ( $WRV('tel_residencial') == "" ) {
		alert("O Telefone Residencial é campo obrigatório!");
		$WR('tel_residencial').focus();
		return false;
	}
	if ( $WRV('tel_celular') == "" ) {
		alert("O Telefone Celular é campo obrigatório!");
		$WR('tel_celular').focus();
		return false;
	}
	if ( $WRV('endereco') == "" ) {
		alert("O Endereço é campo obrigatório!");
		$WR('endereco').focus();
		return false;
	}
	if ( $WRV('numero') == "" ) {
		alert("O Número é campo obrigatório!");
		$WR('numero').focus();
		return false;
	}
	if ( $WRV('bairro') == "" ) {
		alert("O Bairro é campo obrigatório!");
		$WR('bairro').focus();
		return false;
	}
	if ( $WRV('cidade') == "" ) {
		alert("A Cidade é campo obrigatório!");
		$WR('cidade').focus();
		return false;
	}
	return true;
}

function valida_cadastro_bp() {
	if ( $WRV('nome') == "" ) {
		alert("O Nome é campo obrigatório!");
		$WR('nome').focus();
		return false;
	}
	if ( $WRV('contato') == "" ) {
		alert("O Contato é campo obrigatório!");
		$WR('contato').focus();
		return false;
	}
	if ( $WRV('atividades') == "" ) {
		alert("A Atividade é campo obrigatório!");
		$WR('atividades').focus();
		return false;
	}
	if ( $WRV('email') == "" ) {
		alert("O E-mail é campo obrigatório!");
		$WR('email').focus();
		return false;
	} else {
		if ( !valida_email($WR('email')) ) {
			return false;
		}
	}
	if ( $WRV('fone') == "" ) {
		alert("O telefone é campo obrigatório!");
		$WR('fone').focus();
		return false;
	}
	if ( $WRV('endereco') == "" ) {
		alert("O Endereço é campo obrigatório!");
		$WR('endereco').focus();
		return false;
	}
	if ( $WRV('bairro') == "" ) {
		alert("O Bairro é campo obrigatório!");
		$WR('bairro').focus();
		return false;
	}
	if ( $WRV('cep') == "" ) {
		alert("O CEP é campo obrigatório!");
		$WR('cep').focus();
		return false;
	}
	if ( $WRV('cidade') == "" ) {
		alert("A Cidade é campo obrigatório!");
		$WR('cidade').focus();
		return false;
	}
	return true;
}

function valida_newsletter() {
	if ( $WRV('news_nome') == "" ) {
		alert("O Nome é campo obrigatório!");
		$WR('news_nome').focus();
		return false;
	}
	if ( $WRV('news_email') == "" ) {
		alert("O E-mail é campo obrigatório!");
		$WR('news_email').focus();
		return false;
	} else {
		if ( !valida_email($WR('news_email')) ) {
			return false;
		}
	}
	return true;
}

function valida_contato() {
	var telefone = "";
	var comentario = "";
	
	if (TrimJS($WRV('nome')) == "" ) {
		alert("O Nome é campo obrigatório!");
		$WR('nome').focus();
		return false;
	}
	if ( $WRV('email') == "" ) {
		alert("O E-mail é campo obrigatório!");
		$WR('email').focus();
		return false;
	} else {	
		if ( !valida_email($WR('email')) ) {
			return false;
		}
	}
	if (TrimJS($WRV('comentario')) == "") {
		alert("O Comentário é campo obrigatório!");
		$WR('comentario').focus();
		return false;
	} else {
		words = $WRV('comentario').split("\n");
		for ( i = 0; i < words.length; i++ )
			if ( words[i] != "undefined" )
				comentario += "@@"+words[i];
	}
	
	if ( $WRV('fone') != "" )
		telefone = $WRV('fone');
	
	if ( navigator.appName.indexOf("Microsoft Internet Explorer") == 0 )
		is_ie = 1;
	else
		is_ie = 0;
	
	var url = 'ajax/envia_contato.php';
	var pars = 'nome='+$WRV('nome')+'&email='+$WRV('email')+'&cidade='+$WRV('cidade')+'&estado='+$WRV('estado')+'&telefone='+telefone+'&comentario='+TrimJS(comentario)+'&is_ie='+is_ie;
	
	var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: showEnvioContato });	
	return false;
}

function showEnvioContato(originalRequest) {
	var resultado = originalRequest.responseText;
	var mensagem = "";
	var botao = '<input type="image" src="imagens/botoes/bt_fechar.gif" name="fechar_contato" id="fechar_contato" value="Fechar" title="Fechar" onclick="javascript:FecharContato(); return false;" />';
	
	if ( resultado == 1 ) {
		mensagem = "<strong>Sua mensagem foi enviada com sucesso!<br />Será respondido(a) em breve.</strong><br />";
		$WR('ResultadoContato').className = "sucess";
	} else if ( resultado == 2 ) {
		mensagem = "<strong>Ocorreu um erro e sua mensagem nao foi enviada.<br />Por favor, tente novamente.</strong><br />";
		$WR('ResultadoContato').className = "error";
	} else {
		mensagem = "<strong>Por favor, verifique os campos obrigatórios e preencha-os.<br />Por favor, tente novamente.</strong><br />";
		$WR('ResultadoContato').className = "error";
	}
	$WR('ResultadoContato').innerHTML = mensagem;// + botao;
	$WR('ResultadoContato').style.display = '';
	document.FormContato.reset();
	//Element.show('ResultadoContato');
}

function FecharContato() {
	//Element.hide('ResultadoContato');
	$WR('ResultadoContato').style.display = 'none';
	document.FormContato.reset();
}

function valida_descadastro_newsletter() {
	if ( $WRV('email') == "" ) {
		alert("O E-mail é obrigatório!");
		$WR('email').focus();
		return false;
	}
	return true;
}
