var LoginHandler = new function() { this.submit = function(username, password, rememberMe, onError) { Ars.ajax({ type: 'POST', url: 'https://secure.kalmbach.com/Ars/ValidateUser', dataType: 'json', timeout: 10000, data: JSON.stringify({ username: username, password: password }), success: function (data) { Sessions.StartSession(data.SessionId, rememberMe); location.reload(); }, error: onError }); } } function ShowLogin(){ var width = $(document).width() > 530 ? 500: $(document).width() - 30; var left = ($(document).width() - 26 - width) / 2; var top = $(window).height() > 600 ? '10%': '10px'; jQuery.blockUI({message: $('.login'), css: {width: width, left: left, top: top}}); return false; } function ShowSpinner(){ var width = $(document).width() > 530 ? 500: $(document).width() - 30; var left = ($(document).width() - 26 - width) / 2; var top = $(window).height() > 600 ? '10%': '10px'; jQuery.blockUI({message: $('#loginSpinner'), css: {width: width, left: left, top: top, textAlign: 'center'}}); } function Login(){ var timeout = window.setTimeout(ShowSpinner, 200); LoginHandler.submit( $('#username').val(), $('#password').val(), $('#rememberMe').is(':checked'), function(error){ window.clearTimeout(timeout); if(error == 'forbidden') { ShowAlert('Invalid Login', 'Username or Password was incorrect. Re-enter them and try again.', ShowLogin); }else if(error == 'timeout' || error == 'failed') { ShowAlert('Server Error', 'Server is not responding. Please try again later.', jQuery.unblockUI); } } ); return false; } function ShowAlertDialog(){ var width = $(document).width() > 530 ? 500: $(document).width() - 30; var left = ($(document).width() - 26 - width) / 2; var top = $(window).height() > 600 ? '10%': '10px'; jQuery.blockUI({message: $('#alertDialog'), css: {width: width, left: left, top: top}}); } function ShowAlert(title, message, onOK){ $('#alertTitle').text(title); $('#alertText').text(message); $('#alertOK').off('click'); $('#alertOK').click(function() { onOK(); return false; }); ShowAlertDialog(); } var curWidth; $(document).ready(function () { $('.signInLink').click(ShowLogin); $('#signInButton').click(Login); $('.login .form input[type="text"]').keypress(function(e) { if(e.which == 13) { Login(); return false; } }); $('.closeDialog').click(jQuery.unblockUI); $('.login').hide(); if(document.cookie.indexOf('Ars=') != -1){ $('#logoutLinks').show(); $('.signOutLink').show(); $('#loginLinks').hide(); $('.signInLink').hide(); } jQuery.blockUI.defaults.css = { padding: '10px', margin: 0, border: '3px solid #AAA', backgroundColor: '#F7F7F7' }; jQuery.blockUI.defaults.fadeIn = 0; jQuery.blockUI.defaults.fadeOut = 0; curWidth = $(window).width() $(window).resize(function(){ if($(this).width() != curWidth){ curWidth = $(this).width(); if($('.login').is(':visible')){ jQuery.unblockUI(); ShowLogin(); }else if($('#loginSpinner').is(':visible')){ jQuery.unblockUI(); ShowSpinner(); }else if($('#alertText').is(':visible')){ jQuery.unblockUI(); ShowAlertDialog(); } } }); }); function ShowLoading(){ var width = $(document).width() > 530 ? 500: $(document).width() - 30; var left = ($(document).width() - 26 - width) / 2; var top = $(window).height() > 600 ? '10%': '10px'; jQuery.blockUI({message: $('#loadingSpinner'), css: {width: width, left: left, top: top, textAlign: 'center'}}); } function ShowEmailForm(){ var width = $(document).width() > 530 ? 500: $(document).width() - 30; var left = ($(document).width() - 26 - width) / 2; var top = $(window).height() > 600 ? '10%': '10px'; jQuery.blockUI({message: $('#emailPassForm'), css: {width: width, left: left, top: top}}); } function ShowRegisterForm(){ var width = $(document).width() > 530 ? 500: $(document).width() - 30; var height = $(window).height() > 810 ? 790: $(window).height() - 50; var left = ($(document).width() - 26 - width) / 2; var top = $(window).height() > 885 ? '5%': '10px'; jQuery.blockUI({message: $('#registerForm'), css: {width: width, left: left, top: top}, onBlock: function(){ $('.blockMsg').css({height: height, overflowY:'auto'}); } }); } $(document).on('click', '.registerLink', function(){ if($('.regForm').length > 0){ ShowRegisterForm(); } else{ var regFormTimeout = window.setTimeout(ShowLoading, 200); Ars.ajax({ url: 'https://secure.kalmbach.com/Ars/Forms/register.aspx?d=1', type: 'GET', dataType: 'html', success: function(data){ window.clearTimeout(regFormTimeout); $('#registerForm').html(data); $('.regForm form').append(''); $('#regButton').before('
'); $('#regButton').after('
'); ShowRegisterForm(); } }); } return false; }); $(document).on('click', '.forgotPassword', function(){ if($('.emailPassForm').length > 0) ShowEmailForm(); else{ var emailFormTimeout = window.setTimeout(ShowLoading, 200); if(!$.fn.validate){ $('head').append(''); } Ars.ajax({ url: 'https://secure.kalmbach.com/Ars/Forms/emailPassword.aspx?d=1', type: 'GET', dataType: 'html', success: function(data){ window.clearTimeout(emailFormTimeout); $('#emailPassForm').html(data); $('#emailPassForm label[for="username"]').after($('#emailPassForm .emailPassErrors')); ShowEmailForm(); } }); } return false; }); $(document).on('click', '.dialogClose', function(){ jQuery.unblockUI(); }); $(document).on('regLoad', function(){ function onError(error){ function showForm(){ if($('#registerForm .regForm').length > 0){ ShowRegisterForm(); } else if($('#quickRegisterForm .regForm').length > 0){ ShowQuickRegisterForm(); } } if(error == 'forbidden' || error == 'timeout' || error == 'failed') { ShowAlert('Server Error', 'Server is not responding. Please try again later.', showForm); } else if(error != 'nomessage') { ShowAlert('Registration Error', error, showForm); } } RegistrationHandler.onError = onError; });