(function($) { $(function() { $("#reg-dialog").dialog({ autoOpen:false, modal: true, width: 768, height: 480 }); ProcessURL(); // Set the last access date in reg // don't think i care what gets returned since nothing is going to be done $.post('/ps/reg/reg.cgi', {action: 'update_last_access'}, function(data) {}, 'json'); $(".registration").click(function(e) { e.preventDefault(); var valid_session = VerifySession(); var ref = $(this).get(0).href; var type = $(this).get(0).type; if(type == 'register') { ShowRegistration(ref, valid_session); } else { if(valid_session == 0) { ShowLogin(ref); } else { window.location.href = ref; } } }); $(".edit_profile").click(function(e) { e.preventDefault(); var valid_session = VerifySession(); if (valid_session==0) ShowLogin("javascript:window.location.href='/ps/reg/reg.cgi'"); else { $("#reg-dialog").dialog("option", "title", "Edit MyTNB Profile" ); $("#reg-dialog").find("iframe").get(0).src = '/ps/reg/reg.cgi'; $("#reg-dialog").dialog("open"); } }); }); function ShowLogin(ref) { var source = "/ps/reg/reg.cgi?action=login&referer=" + encodeURIComponent(ref); $("#reg-dialog").dialog( "option", "title", "Login" ); $("#reg-dialog").find("iframe").get(0).src = source; $("#reg-dialog").dialog("open"); } function ShowRegistration(ref, session) { var source = "/ps/reg/reg.cgi?"; if(session == 0) { source = source + "action=new_user"; } source = source + "&referer=" + encodeURIComponent(ref); $("#reg-dialog").dialog( "option", "title", "Register" ); $("#reg-dialog").find("iframe").get(0).src = source; $("#reg-dialog").dialog("open"); } function VerifySession() { var valid_session = -1; jQuery.ajax ({ type: 'POST', url: '/ps/reg/reg.cgi', data: 'action=check_session', async: false, success: function(e) { if(e.toLowerCase() == 'generic') valid_session = 0; else valid_session = 1; }, fail: function(e) { alert("ajax failed attempting to verify session"); valid_session = 0; } }); return valid_session; } function ProcessURL() { var url = window.location.search; url=url.replace(/^\?/, ''); // parse the URL to see if we have any commands we need to use var vars = url.split("&"); var ref = ''; var show = 0; for(var i=0; i < vars.length; i++) { var pair = vars[i].split("="); if(pair[0] == 'login_show') { show = 1; } else if(pair[0] == 'login_ref') { ref = pair[1]; } } if(show) { if(VerifySession()) { window.location.href = ref; } else { ShowLogin(ref); } } } }) (jQuery); function CloseLogin(ref) { jQuery("#reg-dialog").dialog("close"); if(ref) window.location.href = ref; }