$(document).ready(function () { root = $('#root').attr('href'), marker = 0; $('#lo').remove(); /////////////////////////////////// ($('input[name=name]').val().length > 2) ? $('b#name').removeAttr('class').attr('class', 'green') : $('b#name').removeAttr('class').attr('class', 'red'); ($('input[name=subject]').val().length > 4) ? $('b#subject').removeAttr('class').attr('class', 'green') : $('b#subject').removeAttr('class').attr('class', 'red'); ($('textarea[name=msg]').val().length > 8) ? $('b#msg').removeAttr('class').attr('class', 'green') : $('b#msg').removeAttr('class').attr('class', 'red'); ($('input[name=kap4a]').val().length > 0) ? $('b#kap4a').removeAttr('class').attr('class', 'green') : $('b#kap4a').removeAttr('class').attr('class', 'red'); $.ajax({ type: 'POST', url: root + '/kontakti/valid_email', data: { valid_email: 1, email: $('input[name=email]').val() } }).done(function (data) { data == '1' ? $('b#email').removeAttr('class').attr('class', 'green') : $('b#email').removeAttr('class').attr('class', 'red'); }).fail(function () { alert('Сървърна грешка!'); }); ($('b.red').length == 0) ? $('button.sent').attr('disabled', false).css('cursor', 'pointer') : $('button.sent').attr('disabled', true).css('cursor', 'not-allowed'); $('button.sent').is(':disabled') ? $('button.sent').css('cursor', 'not-allowed') : $('button.sent').css('cursor', 'pointer'); /////////////////////////////////// $('input,textarea').bind('keyup change', function () { var name = $(this).attr('name'), val = $(this).val(), len = val.length; console.table({name, val, len}) if (name != 'email') { (name == 'name' && len > 2) || (name == 'subject' && len > 4) || (name == 'msg' && len > 8) || (name == 'kap4a' && len > 0) ? $('b#' + name).attr('class', 'green') : $('b#' + name).attr('class', 'red'); } else { if (/\./.test(val)) { $.ajax({ type: 'POST', url: root + '/kontakti/valid_email', data: { valid_email: 1, email: val } }).done(function (data) { data == '1' ? $('b#' + name).attr('class', 'green') : $('b#' + name).attr('class', 'red'); }).fail(function () { alert('Сървърна грешка!'); }); } } ($('b.red').length == 0) ? $('button.sent').attr('disabled', false).css('cursor', 'pointer') : $('button.sent').attr('disabled', true).css('cursor', 'not-allowed'); }); $('.sent').click(function () { var name = $('input[name=name]').val(), sub = $('input[name=subject]').val(), msg = $('textarea[name=msg]').val(), kap = $('input[name=kap4a]').val(), email = $('input[name=email]').val(); if (name.length > 2 && sub.length > 4 && msg.length > 8 && kap.length > 0) { $.ajax({ type: 'POST', url: root + '/kontakti/valid_email', data: { valid_email: 1, email: email } }).done(function (data) { if (data == '1') { $.ajax({ type: 'POST', url: root + '/kontakti/send', data: { send_email: 1, name: name, email: email, sub: sub, msg: msg, kap: kap } }).done(function (data) { if (data == '1') { alert('<< OK >>'); refresh(); } else { alert('<<< NO >>>'); } }).fail(function () { alert('Сървърна грешка!!!'); }); } else { alert('Невалиден имейл!!!'); } }).fail(function () { alert('Сървърна грешка!!!'); }); } }); });