$('#nome, #empresa, #email').each(function(){
	var self = $(this), label = self.val();
	self
		.focus(function(){ if (self.val() == label) self.val(''); })
		.blur(function(){ if (self.val() == '') self.val( label ); });
});

/*$('#nome').focus(function(){ if($(this).val() == 'Nome') $(this).val(''); });
$('#nome').blur(function(){ if($(this).val() == '') $(this).val('Nome'); });
$('#empresa').focus(function(){ if($(this).val() == 'Empresa') $(this).val(''); });
$('#empresa').blur(function(){ if($(this).val() == '') $(this).val('Empresa'); });
$('#email').focus(function(){ if($(this).val() == 'E-mail') $(this).val(''); });
$('#email').blur(function(){ if($(this).val() == '') $(this).val('E-mail'); });*/

$('#fone').each(function(){
	var self = $(this), label = self.val();
	self
		.mask('(99) 99999999')
		.val( label )
		.blur(function(){ if (self.val() == '') self.val( label ); });
});

/*$('#fone').mask('(99) 99999999');
$('#fone').val('Fone');
$('#fone').blur(function(){ if($(this).val() == '') $(this).val('Fone'); });*/

$('#msg').each(function(){
	var self = $(this), label = self.html();
	self
		.focus(function(){ if (self.html() == label) self.html(''); })
		.blur(function(){ if (self.html() == '') self.html( label ); });
});

/*$('#msg').focus(function(){ if($(this).html() == 'Mensagem') $(this).html(''); });
$('#msg').blur(function(){ if($(this).html() == '') $(this).html('Mensagem'); });*/

function validaForm(){
	var msg = '';
	for(i=0;i<campos.length;i++){
		if(!obrig[i]) continue;
		if($('#'+campos[i]).val().length == 0 || $('#'+campos[i]).val() == label[i]) msg += "- "+label[i]+"\n";
		else if(campos[i] == 'email' && !validateEmail($('#email').val())) msg += "- E-mail inválido\n";
	}
	if(msg){ alert("Os seguintes campos devem ser preenchidos: \n\n"+msg); return false; }
	else return true;
}

function validateEmail(email) {
	var at = email.lastIndexOf("@");

	if (at < 1 || (at + 1) === email.length) return false;
	if (/(\.{2,})/.test(email)) return false;

	var local = email.substring(0, at);
	var domain = email.substring(at + 1);

	if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255) return false;
	if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain)) return false;
	if (!/^"(.+)"$/.test(local))
		if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local)) return false;
	if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1) return false;	

	return true;
}