$(document).ready( function(){
    
    // Validação do formulário, conforme atributo rel passado para os campos a serem validadados
    $('#form').submit( function(event){
    error =0;
    var campos = '\n';
    $('input[@type=text]',this).each( function(){
                if($(this).val() == '' && $(this).attr("rel") == "obrigatoria") {
                    $(this).css ('background' , "#CCC");
                    error = 1;
                    campos = campos + '\n - ' + $(this).attr("id");
                }else{
                    $(this).css ('background', '#FFF');    
                    
                }
    });
	$('input[@type=hidden]',this).each( function(){
                if(!$(this).val() && $(this).attr("rel") == "obrigatoria") {
                    error = 1;
                    campos = campos + '\n - ' + $(this).attr("id");
                }
    });
        if(error == 1) {
            alert('Verifique o preenchimento dos campos em destaque:'+campos);
            return false;
        }
    
    
    });
	
	$('#aceito').click(function(){
		if($('#termos')){
			$('#termos').val(false);
		}else{
			$('#termos').val(true);
		}
	});
});

function limparPadrao(campo) {
    if (campo.value == campo.defaultValue) {
        campo.value = "";
    }
}

function escreverPadrao(campo) {
    if (campo.value == "") {
        campo.value = campo.defaultValue;
    }
}

function login(){
    var usuario = document.getElementById('usuario');
    var senha = document.getElementById('senha');
    
    missinginfo = "";
                                                
    if(usuario.value == "" || usuario.value == "login"){
        missinginfo += "\n     -  Login";
    }
    
    if(senha.value == "" || senha.value == "senha"){
        missinginfo += "\n     -  Senha";
    }
    
    if (missinginfo != "") {
        missinginfo ="Favor preencher o(s) seguinte(s)\n    campo(s) obrigatrio(s):     \n" +missinginfo;
        alert(missinginfo);
        return false;
    }
    else{
    return true;
    }
}

function news(){
    var nome = document.getElementById('nome');
    var email = document.getElementById('email');
    
    missinginfo = "";
                                                
    if(nome.value == "" || nome.value == "nome"){
        missinginfo += "\n     -  Nome";
    }
    
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value))){
			missinginfo += "\n     -  E-mail";
	}
    
    if (missinginfo != "") {
        missinginfo ="Favor preencher o(s) seguinte(s)\n    campo(s) obrigatrio(s):     \n" +missinginfo;
        alert(missinginfo);
        return false;
    }
    else{
    return true;
    }
}
