var v = 
{
	cor_fundo : "#FCFBB4",
	cor_fonte : "#000000",
	msg : "",
	
	r_campo : function(name)
	{
		return document.getElementById(name);
	},
	
	vazio : function(name,label)
	{
		var campo = v.r_campo(name);
		//alert(name+" - "+label);
		if(campo.value == "")
		{
			v.msg += 'O campo '+label+' é obrigatório.\n';
			campo.style.backgroundColor = v.cor_fundo;
			campo.style.color = v.cor_fonte;
			
			return false;
		}
		else
		{
			return true;
		}
	},
	
	p_erro : function(form_name)
	{
		if(v.msg != "")
		{
			alert(v.msg);
			return false;
		}
		else
		{
			document.getElementById(form_name).submit();
		}
	}
}


var user = 
{
	salvar : function(tipo)
	{
		v.msg = '';
		v.vazio('id_emp','Empresa');
		v.vazio('tipo','Tipo');
		v.vazio('nome','Nome');
		v.vazio('login','Login');
		
		if(tipo == 'u') {
			var alt = v.r_campo('alterar_senha');
			
			if(alt.checked == true && alt.value == 'sim') {
				v.vazio('senha','Senha');
			}
		} 
		if(tipo == 'i') {
			v.vazio('senha','Senha');
		}
		
		v.p_erro('form1');	
	}
}

