var CMailform = function () { $(function () { this.init() }.bind(this)); this.selectors = { poster: '#you-are-select', companyName: '#company', emailForm: '#email-form', formKeyField: '#form-key', translateSelLang: 'data-l-sel', translatedElements: '[data-translate=1]' } this.lang = "ru"; this.translate = function (lang) { var me = this; $('[' + this.selectors.translateSelLang + ']').each(function () { if ($(this).attr(me.selectors.translateSelLang) == lang) { $(this).hide(); } else { $(this).show(); } }); $(this.selectors.translatedElements).each(function () { var translatedText = $(this).attr('data-l-' + lang); if (translatedText) { $(this).html(translatedText); } console.log(lang, this, translatedText); }); return false; }; this.init = function () { $(this.selectors.emailForm).submit(function () { return this.onFormSubmit(); }.bind(this)); this.translate(this.lang); } this.onFormSubmit = function () { var formValidationPassed = true; $(this.selectors.emailForm + ' .required').each(function (index, element) { if (!$(element).val()) { $(element).parents('.control-group').addClass('error'); formValidationPassed = false; } else { $(element).parents('.control-group').removeClass('error'); } }); if (formValidationPassed) { $(this.selectors.formKeyField).val(parseInt($(this.selectors.formKeyField).val()) + 10); } return formValidationPassed; } }; var Mailform = new CMailform();