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_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 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;
}

function TrimJS(str){
	return str.replace(/^\s+|\s+$/, '');
}

function validaForm(formId){	
	
	for(i=0; i < $WR(formId).elements.length; i++)
	{
		if ($WR(formId).elements[i].className.indexOf("validate")>=0){
			if (TrimJS($WR(formId).elements[i].value) == ""){
				$WR(formId).elements[i].style.border 	 = "solid 1px #FFBBC6";
				$WR(formId).elements[i].style.background = "#FFE6EA";
				$WR(formId).elements[i].focus();
				alert("Preencha todos os campos obrigatórios!");
				return false;
			}
		}
			
		if ($WR(formId).elements[i].className.indexOf("email")>=0){
			if (!valida_email($WR(formId).elements[i])){
				$WR(formId).elements[i].style.border 	 = "solid 1px #FFBBC6";
				$WR(formId).elements[i].style.background = "#FFE6EA";
				$WR(formId).elements[i].focus();
				return false;
			}
		}
	}
}

function AlteraAcompanhe( campo_selecionado ) {
	url = 'cronograma.php?id=' + campo_selecionado.value;
	location=(url);
}