function ajaxFormCheck ($el, $callback)
{
if (jQuery.type( $el ) === 'string')
{
$el = $($el);
}
if ($el.validationEngine('validate'))
{
if ($callback)
{
$callback.call();
}
return true;
}
return false;
}
function callbackAction ($array)
{
return $.ajax({
type: 'POST',
url: '/ajax/callback.php',
dataType: 'json',
data: $.param ($array['json']),
error: function()
{
alert ('Error');
}
});
}
function loadModal($html, $class)
{
delModal();
var winW = document.body.offsetWidth,
$body =
'
'
+ ''
+ '
';
$('body').append($body);
$('.modal-box .inside').html($html);
$('.modal-box').css('left', ((winW - $('.modal-box').width()) / 2) + 'px');
}
function delModal()
{
$('.modal-box').remove();
$('.modal-box-overlay').remove();
}
$(document).ready(function()
{
$("#callback-button").click(function ()
{
callbackAction ({
'json': {
'jaction': 'getForm'
}
}).done(function ($result)
{
loadModal($result.html, 'callback');
})
});
if (typeof jQuery.fn.live == 'function' && jQuery.isFunction(jQuery.fn.live))
{
$(".modal-box-close").live('click', function()
{
delModal();
});
$("#callback-form .submit").live('click', function(e)
{
e.preventDefault();
ajaxFormCheck('#callback-form', function()
{
callbackAction ({
'json': $.extend(
{
'jaction': 'save',
},
transForm.serialize('#callback-form')
)
}).done(function ($result)
{
loadModal($result.html, 'callback');
});
})
});
}
});