/* FORMULÁRIO DE LOGIN */
$(document).ready( function(){
	$('#form-login').submit( function(event){
		error = 0;
		// INPUT TEXT
		$('input[@type=text]',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
			}
		});
		// INPUT PASSWORD
		$('input[@type=password]',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
			}
		});
		
		if(error == 1) {
			$(".login-error").fadeIn(1000);
			$(".login-error").css ('display', 'block');
			$(".login-error").css ('visibility', 'visible');
			return false;
		}
	});
});

/* FORMULÁRIO DE RECADOS */
$(document).ready( function(){
	$('#form-recado').submit( function(event){
		error = 0;
		// INPUT TEXT
		$('textarea',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
			}
		});
		$('input[@name=ccodigo]',this).each( function(){
			if($(this).val() != $('input[@name=ccodseg]').val()){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#c00');
				$(this).css ('color', '#fff');
				error = 1;
			}else{
				$(this).css ('color', '#333');
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
			}
		});
		
		if(error == 1) {
			$(".recado-error").fadeIn(1000);
			$(".recado-error").css ('display', 'block');
			$(".recado-error").css ('visibility', 'visible');
			return false;
		}
	});
});

/* FORMULÁRIOS EM GERAL */
$(document).ready( function(){
	$('#form-validar').submit( function(event){
		error = 0;
		// INPUT TEXT
		$('input[@type=text]',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				$(this).css ('color', '#000');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
				$(this).css ('color', '#000');
			}
		});
		// INPUT PASSWORD
		$('input[@type=password]',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				$(this).css ('color', '#000');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
				$(this).css ('color', '#000');
			}
		});
		// INPUT FILE
		$('input[@type=file]',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				$(this).css ('color', '#000');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
				$(this).css ('color', '#000');
			}
		});
		// TEXTAREA
		$('textarea',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				$(this).css ('color', '#000');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
				$(this).css ('color', '#000');
			}
		});
		// SELECT
		$('select',this).each( function(){
			if($(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#f7cbca');
				$(this).css ('color', '#000');
				error = 1;
			}else{
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
				$(this).css ('color', '#000');
			}
		});
		// CONFIRMANDO A SENHA
		$('input[@name=csenha]',this).each( function(){
			if($(this).val() != $('input[@name=cconfirma]').val() && $(this).val() == '' && $(this).attr("rel") == "obrigatoria"){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#c00');
				$(this).css ('color', '#fff');
				$('input[@name=cconfirma]').css ('border', "1px solid #c00");
				$('input[@name=cconfirma]').css ('background', '#c00');
				$('input[@name=cconfirma]').css ('color', '#fff');
				error = 1;
			}else{
				$(this).css ('color', '#333');
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
				$('input[@name=cconfirma]').css ('color', '#333');
				$('input[@name=cconfirma]').css ('background', '#fff');
				$('input[@name=cconfirma]').css ('border', '1px solid #000');
			}
		});
		// CÓDIGO DE SEGURANÇA
		$('input[@name=ccodigo]',this).each( function(){
			if($(this).val() != $('input[@name=ccodseg]').val()){
				$(this).css ('border', "1px solid #c00");
				$(this).css ('background', '#c00');
				$(this).css ('color', '#fff');
				error = 1;
			}else{
				$(this).css ('color', '#333');
				$(this).css ('background', '#fff');
				$(this).css ('border', '1px solid #000');
			}
		});

		if(error == 1){
			$(".validar-error").fadeIn(1000);
			$(".validar-error").css ('display', 'block');
			$(".validar-error").css ('visibility', 'visible');
			return false;
		}
	});
});
