function setLoginMessage(msg='',colour='') { var $msgDiv = $('#loginmessage'); if (msg==='') { msg='Access all the pest management service data and reports for your sites via the MyEcolab portal.'; } $msgDiv.html(msg); if (colour==='') { $msgDiv.css({'color':'black','text-align':'left','vertical-align':'top'}); } else { $msgDiv.css({'color':colour,'text-align':'center','vertical-align':'middle'}); } } function isEmpty(val) { if (val) { return ((val===null) || val.length==0 || /^\s+$/.test(val)); } else { return true; } } function stopHRefEvent(e) { if (e) { if (e.preventDefault) { e.preventDefault(); } else if (e.stopPropagation) { e.stopPropagation(); } e.returnValue = false; } } function login_submit(e, $element) { stopHRefEvent(e); var lstep = $($element).data('step'); login_submit_helper(lstep); } function login_submit_helper(lstep) { var custno = $('input#login_custno').val(); var user = $('input#login_username').val(); var pwd = $('input#login_password').val(); if (lstep == 1) { setLoginMessage(); } else if (lstep == 5 && isEmpty(pwd)) { setLoginMessage('Password cannot be left blank','red'); return; } else if (isEmpty(custno) || isEmpty(user)) { setLoginMessage('Fields cannot be left blank','red'); lstep = 1; } else if (lstep == 3 || lstep == 4) { if (lstep == 3) { setLoginMessage('An email has been sent with your temporary password. It may take several minutes to reach you.','blue'); } else { setLoginMessage('Please enter your password','blue'); } var submitbutton = $('#loginsubmit'); submitbutton.val('Log in'); submitbutton.data('step','5'); submitbutton.show(); $('.loginstep5').show(); $('#loginsubmitblock').show(); $('#login_password').focus(); return; } if (lstep == 1) { $('.loginstep1').prop('readonly', false); // $('.loginstep1').css('background-color', ''); $('.loginstep5').hide(); var submitbutton = $('#loginsubmit'); submitbutton.val('Next'); submitbutton.data('step','2'); submitbutton.show(); $('#loginsubmitblock').show(); } else { $('.loginstep1').prop('readonly', true); // $('.loginstep1').css('background-color', '#999'); $('#loginsubmitblock').hide(); setLoginMessage('Loading...','blue'); if ((lstep == 2) || (lstep == 5)) { var jsonData; if (lstep == 2) { jsonData = {op:"prechkuser", login_custno: custno, login_username:user}; } else { jsonData = {op:"chklogin", login_custno: custno, login_username:user, login_password:pwd}; } $.ajax({ type: "POST", url: 'index.php', data: jsonData, dataType: "json", async: true } ).done(function (json) { if (json.success == 1) { if (lstep == 2) { if (json.sndeml) { sendTmpPassword(custno,user); } else { login_submit_helper(4); } } else { if (json.newpwd) { if(typeof document.MyEcolabJSLoaded == "undefined") { $.getScript('resources/scripts/myecolab.js.php', function() { window.pwdChange(true,'Index.php','Index.php?logout=1'); }); } else { window.pwdChange(true,'Index.php','Index.php?logout=1'); } } else { window.location.replace('Index.php'); } } } else { if (! isEmpty(json.errormessage)) { setLoginMessage(json.errormessage,'red'); } else { setLoginMessage('Server Error','red'); } $('#loginsubmitblock').show(); } } ).fail(function (jqXHR, textStatus, errorThrown) { setLoginMessage('Server Error','red'); $('#loginsubmitblock').show(); } ); } } } function sendTmpPassword(custno,user) { setLoginMessage('Sending password email...','blue'); var jsonData = {op:"resetpwd", login_custno: custno, login_username:user}; $.ajax({ type: "POST", url: 'index.php', data: jsonData, dataType: "json", async: true } ).done(function (json) { if (json.success == 1) { login_submit_helper(3); } else { setLoginMessage('Server Error','red'); } } ).fail(function (jqXHR, textStatus, errorThrown) { setLoginMessage('Server Error','red'); } ); } function loadResetModal(e) { stopHRefEvent(e); var custno = $('input#login_custno').val(); var user = $('input#login_username').val(); var $pg = "index.php?op=resetmodal&login_custno="+encodeURIComponent(custno)+"&login_username="+encodeURIComponent(user); $('.reset_24928FE2_1647_4C27_BA34_8DEFA089F4F3').remove(); var $dialog = $('
loading
') .load($pg) .dialog({ autoOpen: false, title: 'Reset your Password', width: 800, height: 475, closeOnEscape: true, modal: true, buttons: { "Close": function () {$(this).dialog("close"); $('.reset_24928FE2_1647_4C27_BA34_8DEFA089F4F3').remove();$('#login_password').focus();} } }); $dialog.dialog('open'); return false; } function setResetMessage(msg='',colour='') { var $msgDiv = $('#reset_msgdiv'); if (msg==='') { msg = 'A temporary password has been requested.
If you do not receive the email within 10 minutes '; msg += 'please check the login details and try again or call our Customer Service Centre on 0800 789 600. '; msg += 'Alternatively you can send an email to MyEcolabHelp.UK@ecolab.com'; if (colour==='') { colour='blue'; } } $msgDiv.html(msg); if (colour!=='') { $msgDiv.css({'color':colour}); } } function resetLoginPwd(e) { stopHRefEvent(e); $btn = $('#reset_submit_btn'); $btn.hide(); var custno = $('input#reset_custno').val(); var user = $('input#reset_username').val(); var jsonData = {op:"resetpwd", login_custno: custno, login_username:user}; setResetMessage('Requesting password email...','blue'); $.ajax({ type: "POST", url: 'index.php', data: jsonData, dataType: "json", async: true } ).done(function (json) { if (json.success == 1) { setResetMessage(); } else { setResetMessage('Server Error','red'); $btn.show(); } } ).fail(function (jqXHR, textStatus, errorThrown) { setResetMessage('Server Error','red'); $btn.show(); } ); }