(function () {

if (u('#formLogin').length) {

u("#access-submit")[0].value = "";
u('#formLogin input[type=text]').on('focus', function () {
	this.value = '';
	if (this.id == 'access-password' && this.type == 'text') {
		u(this).after("input#access-password[type=password][name=password]")[0].focus();
		u(this).remove(); }
});

}

if (u('#contato').length) {

u.require('form_validation');

function cleanPhone(str) {
	return str.replace(/\D/g, '');
}

u('#contato').validation(
{
	name: 'required,max(50)',
	email: 'required,email,max(40)',
	're-password': 'match(password)',
	company: 'max(50)',
	occupation: 'max(30)',
	office: 'max(30)',
	phone: 'digits,length(10)',
	mobile: 'digits,length(10)',
	city: 'max(30)',
	subject: 'max(60)',
	message: 'max(500)'
},
{
	filters: {
		'*': [u.clean],
		phone: [cleanPhone], mobile: [cleanPhone]
	},
	errorMessages: {
		'*': {
			required: 'O campo não deve ficar vazio.',
			max: 'O valor excede limite de caracteres.'
		},
		're-password': { match: "As chaves digitadas em ambos os campos devem ser idênticas." },
		email: { email: 'Por favor, insira um e-mail válido.' },
		phone: { length: 'Insira um número de telefone válido (2 dígitos DDD + 8 dígitos).' },
		mobile: { length: 'Insira um número de celular válido (2 dígitos DDD + 8 dígitos).' }
	},
	callbacks: [
		u.FormValidation.HIGHLIGHT_FIELDS,
		u.FormValidation.FOCUS_FIRST,
		u.FormValidation.SHOW_ERROR_LIST
	]
});

var NAV_CHARS = [8,9,13,32,35,36,37,38,39,40,46],
	PHONE_CHARS = [40,41,45,48,49,50,51,52,53,54,55,56,57].concat(NAV_CHARS);

u('#phone,#mobile').keypress(function (e) {
	u.index(PHONE_CHARS, e.keyCode || e.which) < 0 && e.preventDefault();
});

var pwds = u("p:has(#password,#re-password)").hide();

u("#want-password").click(function () {
	this.checked ?
		pwds.css('opacity', 0).slideDown({ duration: 100, callback: function () {
			u(this).fadeIn({ duration: 300 });
		} }) :
		pwds.hide();
})[0].checked = !1;

u("#option-other").hide()[0].disabled = !0;
u("#option-other-toggle").click(function () {
	var o = u("#option-other").show()[0];
	o.disabled = !this.checked;
	o.focus();
})[0].checked = !1;

}

})()