function refund_test() {
if ( $('#refund_email' ).prev('.error-box').hasClass('glyphicon-ok') &&
$('#refund_name' ).prev('.error-box').hasClass('glyphicon-ok') &&
$('#refund_phone' ).prev('.error-box').hasClass('glyphicon-ok') &&
$('#refund_order_id' ).prev('.error-box').hasClass('glyphicon-ok') &&
$('#refund_product_article').prev('.error-box').hasClass('glyphicon-ok') &&
$('#refund_reason' ).prev('.error-box').hasClass('glyphicon-ok')) {
$('#refund_main').addClass('send_ready').removeClass('send_not_ready');
$('#infomessage').css('display', 'none'); return 1;}
else {$('#refund_main').addClass('send_not_ready').removeClass('send_ready'); return 0;}
}
$('#refund_main').click(function(){
if ($('#refund_main').hasClass('clicked')) return false;
if(refund_test()) {
loadingAnimation(true); $('#refund_main').val('Обработка...'); $('#refund_main').addClass('clicked');
var email=$('#refund_email').val();
var name= $('#refund_name').val();
var phone=$('#refund_phone').val();
var orderid=$('#refund_order_id').val();
var article=$('#refund_product_article').val();
var isused=$('#refund_used').prop("checked") ? 1 : 0;
var reason=$('option[name=reason]:selected').text();
var comment=$('#refund_comments').val();
comment= comment.length>0 ? comment : 'нет';
$.post('/site/refundsave', {name: name, email: email, phone: phone, orderid: orderid, article: article, isused: isused, reason: reason, comment: comment})
.done(function(res){loadingAnimation(false); if(!res) alert('Ошибка!Пустой результат'); location.reload()})
.fail(function(res){loadingAnimation(false); alert(res['responseText'])});
}
else {
$('#refund_main').val('Оформить заявку на возврат');
var infomessage='Не заполнены обязательные поля:
';
var email= $('#refund_email').prev('.error-box').hasClass('glyphicon-ok') ? '' : '- E-mail
';
var name= $('#refund_name').prev('.error-box').hasClass('glyphicon-ok') ? '' : '- Ф.И.О.
';
var phone= $('#refund_phone').prev('.error-box').hasClass('glyphicon-ok') ? '' : '- Номер телефона
';
var orderid= $('#refund_order_id').prev('.error-box').hasClass('glyphicon-ok') ? '' : '- Номер заказа
';
var article= $('#refund_product_article').prev('.error-box').hasClass('glyphicon-ok') ? '' : '- Артикул и количество
';
var reason= $('#refund_reason').prev('.error-box').hasClass('glyphicon-ok') ? '' : '- Причина
';
infomessage += name+ email+phone+orderid+article+reason;
$('#infomessage').html(infomessage).css('display', 'inline-block');
setTimeout(function(){$('#infomessage').fadeOut('fast')},8000); //30000 = 30 секунд
}
});
$('input#refund_name, input#refund_phone, input#refund_email, input#refund_order_id, input#refund_product_article,select#refund_reason, input#refund_comments').unbind().blur( function(){
var val = $(this).val(); var errorText=$(this).attr('error_message'); var defaultFlag=1;
switch($(this).attr('id')) { // После того, как поле потеряло фокус, перебираем значения id, совпадающее с id данного поля
case 'refund_email':
var rv_email = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/; errorText= !(val != '' && rv_email.test(val) && val.length < 40 ) ? errorText : ''; break;
case 'refund_name': // Проверка поля "Имя"
var rv_name = /^[a-zA-Zа-яА-ЯёЁ\s]+$/; errorText= !(val.length > 2 && val != '' && rv_name.test(val) && val.length < 255) ? errorText :''; break;
case 'refund_phone':
var rv_phone = /^((8|0|\+\d{1,2})[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/; errorText= !(val != '' && rv_phone.test(val) && val.length < 40) ? errorText :''; break;
case 'refund_order_id':
var rv_phone = /^[0-9]+$/; errorText= !(val != '' && val.length >= 4 && rv_phone.test(val) && val < 2147483647) ? errorText :''; break;
case 'refund_product_article':
var rv_phone = /^[a-zA-Zа-яА-ЯёЁ0-9\s\-\/\,\.]+$/; errorText= !(val != '' && val.length >= 4 && rv_phone.test(val) && val.length < 255) ? errorText :''; break;
case 'refund_reason':
var rv_phone = $('option[name=reason]:selected').text(); errorText= !(rv_phone != 'Укажите причину') ? errorText :''; break;
default: errorText=''; defaultFlag=0; break;
} // end switch(...)
if (errorText==="" && defaultFlag!=0) $(this).prev('.error-box').html('').css('color','green').addClass('glyphicon glyphicon-ok').attr('status', 'OK');
else $(this).prev('.error-box').html(errorText).css('color','red').removeClass('glyphicon glyphicon-ok').animate({'paddingLeft':'10px'},400).animate({'paddingLeft':'5px'},400).attr('status', '');
refund_test();
}); // end blur()