$(document).ready( function() {
$('.lnk_login').click( function(e) {
e.preventDefault();
// $.get(DIR_STATIC_SKIN+'/modal/login.html', function(data) {
$.modal.close();
$('
').modal({close:false});
$.get(DIR_WEB_ROOT+'/login/', function(data) {
$.modal.close();
$(data).modal({
opacity: 25,
onOpen: login.open,
onShow: login.show
});
});
});
// preload images for modal window
var img = [ 'modal-lt.png', 'modal-rt.png',
'modal-lb.png', 'modal-rb.png',
'modal-l.png', 'modal-r.png',
'modal-t.png', 'modal-b.png',
'modal-lb.png'];
$(img).each(function () {
var i = new Image();
i.src = DIR_STATIC_SKIN+'/images/modal/' + this;
});
$('.lnk_exit').click(function(e) {
e.preventDefault();
$.modal.close();
$('').modal({close:false});
$.get(DIR_WEB_ROOT+'/login/exit/', function(data) {
location.reload();
});
});
});
var login = {
fields: [ {name: 'login', type: 'text', req: true},
{name: 'password', type: 'text', req: true} ],
messages: {'empty': 'Поле обязательно для заполнения',
'email': 'Некорректный адрес электронной почты!'
},
open: function(dialog) { // It need to correct height and position of modal window
dialog.overlay.show();
dialog.container.show();
dialog.data.show();
login.resetHeight();
},
resetHeight: function() {
$('#simplemodal-container').height( $('.simplemodal-data').height());
$.modal.impl.setPosition();
},
show: function() {
$('.simplemodal-container .error-ico').click(function(e) {
e.preventDefault();
fieldset = $(this).parent().parent();
if ( !$('.error_msg', fieldset).html() ) {
fieldset.append('');
$('.error_msg', fieldset).html($(this).attr('rel'));
} else {
$('.error_msg', fieldset).remove();
}
});
},
validate: function() {
b = true;
$('#simplemodal-container .error_msg').remove();
for ( i in login.fields) {
f = login.fields[i];
field = $('#simplemodal-container form input[name="'+f.name+'"]');
login.clearErrors(field);
if (f.req) { // if field is reqired - check
if ( (field.val()) && (f.type=='email') ) { // if field not empty and have should be email - check
if ( !validateEmail( field.val() ) ) { // if not check not passed put error
login.fieldError(field, 'email');
b = false;
}
} else if ( !field.val() ) { // if field required and empty put empty error
if ( f.type=='captcha') {
login.fieldError(field, 'captcha');
} else {
login.fieldError(field, 'empty');
}
b = false;
}
}
else { // if field is not required but have email type and have value - check for email type
if ( (field.val()) && (f.type == 'email') ) {
if ( !validateEmail( field.val() ) ) { // if check is failed put error
login.fieldError(field, 'email');
b = false;
}
}
}
}
return b;
},
fieldError: function(field, type) {
field_container = field.parent().parent().parent();
if ( !field_container.hasClass('error') ) {
field_container.addClass('error');
l = $('#simplemodal-container form label[for="'+ field.attr('name') +'"] .error-ico')
l.show().attr('rel', l.attr('rel') + login.messages[type]+'
');
}
},
clearErrors: function(field) {
field.parent().parent().parent().removeClass('error');
$('#simplemodal-container form label[for="'+ field.attr('name') +'"] .error-ico').hide().attr('rel','');
},
error: function() {
// alert('All of us will die!!!');
}
}
/* Forgot modal window class */
var forgot = {
fields: [ {name: 'mail', type: 'email', req: true} ],
messages: {'empty': 'Поле обязательно для заполнения',
'email': 'Некорректный адрес електронной почты!',
'captcha': 'вы робот?!'
},
open: function(dialog) { // It need to correct height and position of modal window
dialog.overlay.show();
dialog.container.show();
dialog.data.show();
forgot.resetHeight();
},
resetHeight: function() {
$('#simplemodal-container').height( $('.simplemodal-data').height());
$.modal.impl.setPosition();
},
show: function() {
$('.simplemodal-container .error-ico').click(function(e) {
e.preventDefault();
fieldset = $(this).parent().parent();
if ( !$('.error_msg', fieldset).html() ) {
fieldset.append('');
$('.error_msg', fieldset).html($(this).attr('rel'));
} else {
$('.error_msg', fieldset).remove();
}
});
},
validate: function() {
b = true;
$('#simplemodal-container .error_msg').remove();
for ( i in forgot.fields) {
f = forgot.fields[i];
field = $('#simplemodal-container form input[name="'+f.name+'"]');
forgot.clearErrors(field);
if (f.req) { // if field is reqired - check
if ( (field.val()) && (f.type=='email') ) { // if field not empty and have should be email - check
if ( !validateEmail( field.val() ) ) { // if not check not passed put error
forgot.fieldError(field, 'email');
b = false;
}
} else if ( !field.val() ) { // if field required and empty put empty error
if ( f.type=='captcha') {
forgot.fieldError(field, 'captcha');
} else {
forgot.fieldError(field, 'empty');
}
b = false;
}
}
else { // if field is not required but have email type and have value - check for email type
if ( (field.val()) && (f.type == 'email') ) {
if ( !validateEmail( field.val() ) ) { // if check is failed put error
forgot.fieldError(field, 'email');
b = false;
}
}
}
}
return b;
},
fieldError: function(field, type) {
field_container = field.parent().parent().parent();
if ( !field_container.hasClass('error') ) {
field_container.addClass('error');
l = $('#simplemodal-container form label[for="'+ field.attr('name') +'"] .error-ico')
l.show().attr('rel', l.attr('rel') + forgot.messages[type]+'
');
}
},
clearErrors: function(field) {
field.parent().parent().parent().removeClass('error');
$('#simplemodal-container form label[for="'+ field.attr('name') +'"] .error-ico').hide().attr('rel','');
},
error: function() {
// alert('All of us will die!!!');
}
}