//File: global.js var bn_global = { //Set this to see more detailed error messages for Javascript development: false, recently_viewed: {}, random_poll: {}, password_min_length: 6, password_max_length: 25, password_regex_validator: /^([a-zA-Z0-9!@#$%^&*()\-_+=\[\]\{\}\:\;\.\<\>\\\/\'\",]*)$/, nickname_regex_validator: /^([a-zA-Z0-9\-_]*)$/, email_regex_validator: /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])+/, months: new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), days: new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'), states: {'AL':'Alabama','AK':'Alaska', 'AZ':'Arizona','AR':'Arkansas', 'CA':'California','CO':'Colorado', 'CT':'Connecticut','DE':'Delaware', 'DC':'District Of Columbia','FL':'Florida', 'GA':'Georgia','HI':'Hawaii', 'ID':'Idaho','IL':'Illinois', 'IN':'Indiana','IA':'Iowa', 'KA':'Kansas','KY':'Kentucky', 'LA':'Louisiana','ME':'Maine', 'MD':'Maryland','MA':'Massachusetts', 'MI':'Michigan','MN':'Minnesota', 'MS':'Mississippi','MO':'Missouri', 'MT':'Montana','NE':'Nebraska', 'NV':'Nevada','NH':'New Hampshire', 'NJ':'New Jersey','NY':'New York', 'NC':'North Carolina','ND':'North Dakota', 'OH':'Ohio','OK':'Oklahoma', 'OR':'Oregon','PA':'Pennsylvania', 'RI':'Rhode Island','SC':'South Carolina', 'SD':'South Dakota','TN':'Tennessee', 'TX':'Texas','UT':'Utah', 'VT':'Vermont','VA':'Virginia', 'WA':'Washington','WV':'West Virginia', 'WI':'Wisconsin','WY':'Wyoming'}, error_feedback_icon: '/images/error.gif', success_feedback_icon: '/images/success.gif', unknown_error_message: '

Oops! An error occured. One of our programmers will be dispatched to deal with this issue.

Thank you for your patience.', /** * Random poll cloud */ display_random_poll: function() { if (!bn_global.random_poll.NAME) return; poll_html = '

Please Vote

'; poll_html += '

'; poll_html += bn_global.random_poll.NAME.length > 30 ? bn_global.random_poll.NAME.substr(0,30) + '...' : bn_global.random_poll.NAME; poll_html += '

'; poll_html += ''; poll_html += '
' poll_html += ''; poll_html += '

View all polls

'; poll_html += '
'; poll_html += '
'; poll_html += '
'; poll_html += ''; poll_html += '
'; poll_html += '
'; poll_html += '
'; $('#RANDOM_POLL').html(poll_html); }, /** * Stax call to get a random poll */ get_random_poll: function( ) { _get_random_poll(function(ret){ data = JSON.parse(ret); bn_global.stax_fail(data); if (data.success) { bn_global.random_poll=data.POLL_DATA; bn_global.display_random_poll(); } }); }, stax_fail: function(data) { if (!data.success && typeof(data.user_logged_in) != 'undefined' && !data.user_logged_in) { bn_user.after_slay = function() {}; bn_user.slay(); $('#MESSAGE_WINDOW').jqm({onHide:function(){location.href='/search';}}); bn_global.display_modal_message('You have been logged out. Please login again.'); } else if (!data.success) { bn_global.display_modal_message(); } }, /** * Checks if the user is logged in, then redirects to the poll creation page */ create_new_poll: function() { if (!bn_user.check_login(true)) { return; } return(location.href='/poll'); }, /** * Generate alphabetical listings on the page * @return void */ letter_list: function() { if (typeof(bn_search) != 'undefined') for (var x = 65; x < 91; x++) { char = String.fromCharCode(x); css_style = 'letters'; if ($('#SEARCH').val().length == 1 && char == $('#SEARCH').val()) { css_style = 'letter_selected'; } $('#LETTER_LIST').append('
'+ char +'
'); $('#FILTER_BEGINS_WITH').append(''); $('#FILTER_NOT_BEGINS_WITH').append(''); $('#FILTER_ENDS_WITH').append(''); $('#FILTER_NOT_ENDS_WITH').append(''); } else for ( var x = 65; x < 91; x++) { $('#LETTER_LIST').append('
' + String.fromCharCode(x) + '
'); } }, /** * Standard message display for the site */ display_modal_message: function(message, error) { var error_colour = '#f69679'; var message_div = $('#MESSAGE_WINDOW'); var message_html = ''; if (typeof(message) == 'undefined') { message = bn_global.unknown_error_message; error = true; } if (typeof(error) != 'undefined') { message_div.removeClass('std_message_modal'); message_div.addClass('error_message_modal'); //message_html += '
'; //message_html += ''; //message_html += '
'; } else { message_div.removeClass('error_message_modal'); message_div.addClass('std_message_modal'); } message_html += '
'+message+'
'; //message_html += '
Close'; message_div.html(message_html).jqmShow(); }, /** * Displays human readable date in relationship to the current date */ smart_date: function(time_stamp) { var given_date = new Date(); given_date.setTime(time_stamp); if (given_date.getHours() == 0) given_hour = '12:' + (given_date.getMinutes() < 10 ? '0' + given_date.getMinutes() : given_date.getMinutes()) + 'am'; else if(given_date.getHours() < 12) given_hour = given_date.getHours() + ':' + (given_date.getMinutes() < 10 ? '0' + given_date.getMinutes() : given_date.getMinutes()) + 'am'; else if(given_date.getHours() == 12) given_hour = '12:' + (given_date.getMinutes() < 10 ? '0' + given_date.getMinutes() : given_date.getMinutes()) + 'pm'; else given_hour = given_date.getHours() - 12 + ':' + (given_date.getMinutes() < 10 ? '0' + given_date.getMinutes() : given_date.getMinutes()) + 'pm'; var current_date = new Date(); var last_week = new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() - 6); var yesterday = new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() - 1); var today = new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate()); if (new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate()) <= given_date) return ('Today at ' + given_hour); if (new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() - 1) <= given_date) return ('Yesterday at ' + given_hour); if (new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() - 6) <= given_date) return ('Last ' + bn_global.days[given_date.getDay()] + ' at ' + given_hour); if (given_date.getFullYear() == current_date.getFullYear() && given_date.getMonth() == current_date.getMonth()) { numeric_suffix = 'th'; switch(given_date.getDate()) { case 1: case 21: case 31: numeric_suffix = 'st'; break; case 2: case 22: numeric_suffix = 'nd'; break; case 3: case 23: numeric_suffix = 'rd'; break; } return ('On ' + bn_global.days[given_date.getDay()] + ' the ' + given_date.getDate() + numeric_suffix + ' at ' + given_hour); } return ('On ' + bn_global.days[given_date.getDay()] + ', ' + bn_global.months[given_date.getMonth()] + ' '+ given_date.getDate() + ', ' + given_date.getFullYear() + ' at ' + given_hour); }, /** * Cloud to display recently viewed with text size proportional to its view amount */ generate_recent_viewed: function() { if(bn_global.recently_viewed == null) return; for(var i = 0; i < bn_global.recently_viewed.length; i++) { switch(bn_global.recently_viewed[i].GENDER) { case ('M'): classname = 'boyname'; break; case ('F'): classname = 'girlname'; break; default: classname = 'unisexname'; } $('#RECENT_GLOBAL_VIEWS').append('' + this.recently_viewed[i].NAME + ' '); } } }; $(document).ready(function() { bn_global.letter_list(); //set up the jq modal windows $('#MESSAGE_WINDOW').jqm(); $("#LOGIN_WINDOW").jqm(); $("#FORGOT_PASSWORD_WINDOW").jqm(); bn_global.generate_recent_viewed(); bn_global.display_random_poll(); if($.browser.msie) $('#LOGIN_FORM').children().keyup(function(e) { //alert(e.which); if (e.which == 13) $('#LOGIN_FORM').submit(); }); if ($.browser.msie && $.browser.version.substr(0,1)<7) { $('.LOGIN_CLOSE').attr('src', '/images/login-close.gif'); } //$(document).pngFix(); }); //File: favourite.js var bn_favourite = { favimg: '/images/favourite.png', nonfavimg: '/images/nonfav.png', confirm_add_delete: true, /** * Stax call to delete a favourite if viewing it within a users profile(i.e. not search or detail page) */ delete_favourite_by_id: function(id, name_id, category, confirm) { if (bn_favourite.confirm_add_delete && typeof(confirm) == 'undefined'){ $('#DELETE_FAVOURITE').jqmShow(); $('#FAVOURITE_DELETE_YES').unbind('click').click(function(){$('#DELETE_FAVOURITE').jqmHide(); bn_favourite.delete_favourite_by_id(id, name_id, category, true);return false;}); return; } _delete_favourite_by_id(id, function(ret) { data = JSON.parse(ret); bn_global.stax_fail(data); //Remove li from MSN if (data.success && typeof(bn_mysavednames) != 'undefined') { bn_user.favourites = data.favourites; $("li#name_div_" + id).remove(); //if the user removed this name but still has another somewhere still_exists = false; for (var z in bn_user.favourites) { if (bn_user.favourites[z].NAME == name_id) { still_exists = true; break; } } if (!still_exists) $('#RECENT_ADD_' + name_id).text('Save Name'); if (category == 2) { bn_mysavednames.build_middle_names_list(); if (!$('#FAVOURITE_MIDDLE_NAMES li').size()) $('#MIDDLE_NAME_CONTAINER').hide(); } $('select[id^=MIDDLE_NAME_SELECT_] option:selected[value="' + id + '"]').parents('span').empty(); } }); }, /* * Stax call to delete a favourite from the database based on the name(for when outside of profile views) */ delete_favourite: function (id, confirm) { if (bn_favourite.confirm_add_delete && typeof(confirm) == 'undefined'){ $('#DELETE_FAVOURITE').jqmShow(); $('#FAVOURITE_DELETE_YES').unbind('click').click(function(){$('#DELETE_FAVOURITE').jqmHide(); bn_favourite.delete_favourite(id, true);}); return; } if (confirm == true) { _delete_favourite(id, function(ret){ var data = JSON.parse(ret); bn_global.stax_fail(data); if (data.success) { if (typeof(bn_search) != 'undefined') { $('#FAVIMG_' + id).attr('src', bn_favourite.nonfavimg); $('#EXACT_FAVIMG_' + id).attr('src', bn_favourite.nonfavimg); } $('#RECENT_ADD_' + id).text('Save Name'); bn_user.favourites = data.favourites; if (typeof(bn_mysavednames) != 'undefined') { bn_mysavednames.build_middle_names_list(); bn_mysavednames.list_mysavednames(); $('#FAVOURITE_NAMES select option:selected[name="' + id + '"]'); } bn_user.generate_my_saved_names(); if (typeof(bn_detail) != 'undefined') { bn_detail.set_favourite_action(); } } }); } }, /** * Add a favourite to the database */ add_favourite: function(id, comment, delete_if_exists, category) { if ($('#ADD_NAME_STATUS')) { $('#ADD_NAME_STATUS').removeClass('ADD_NAME_SUCCESS','ADD_NAME_FAIL'); $('#ADD_NAME_STATUS').html(''); } if (id.length == 0) { $('#ADD_NAME_STATUS').html('Please enter a name.'); $('#ADD_NAME_STATUS').addClass('ADD_NAME_FAIL'); $('#ADD_NAME_STATUS').show(); return false; } if (category == 2) { for(var i in bn_user.favourites) { if (bn_user.favourites[i]['CATEGORY'] == 2 && bn_user.favourites[i]['NAME_TEXT'].toLowerCase() == id.toLowerCase()) { bn_global.display_modal_message('

You cannot have duplicate middle names.', true); return; } } } if (!bn_user.check_login(true)) return; //if the name already exists, user is calling to delete the name if(typeof(delete_if_exists) != 'undefined' && delete_if_exists) for (var x in bn_user.favourites){ if (id == bn_user.favourites[x].NAME) { bn_favourite.delete_favourite(id); return; } } // if (bn_favourite.confirm_add_delete && typeof(comment) == 'undefined') { // // $('#FAVOURITE_ERROR').hide(); // // $('#FAVOURITE_SUBMIT').unbind('click').click(function(){bn_favourite.add_favourite(id, $('#FAVOURITES_COMMENT').val());}); // // $('#ADD_FAVOURITE').jqmShow(); // // return; // } if (typeof(category) == 'undefined') category = 1; if (typeof(comment) == 'undefined') comment = ''; _add_favourite(id, comment, category, function(ret) { var data = JSON.parse(ret); bn_global.stax_fail(data); if (data.success) { //fewafwea $('#ADD_FAVOURITE').jqmHide(); bn_user.favourites = data.favourites; for (var z in data.added) { $('#RECENT_ADD_' + data.added[z].NAME).text('Delete name'); } var new_fav_count = parseInt($('#FAV_COUNT').html()) + 1; $('#FAV_COUNT').empty(); $('#FAV_COUNT').append(new_fav_count); bn_user.generate_my_saved_names(); if (typeof(bn_detail) != 'undefined') { bn_detail.set_favourite_action(); } if (typeof(bn_search) != 'undefined') { $('#FAVIMG_' + id).attr('src', bn_favourite.favimg); $('#EXACT_FAVIMG_' + id).attr('src', bn_favourite.favimg); } if (typeof(bn_mysavednames) != 'undefined') { if (category == 2) { bn_mysavednames.build_middle_names_list(); $('#MIDDLE_NAME_CONTAINER').show(); } bn_mysavednames.list_mysavednames(); if (isNaN(data.added)) { // names = new Array(); // names = id.split(','); name_feedback = new Array(); for (var i in data.added) { name_feedback.push(data.added[i].NAME.replace(/^\s+|\s+$/g,"") + ' added.'); } $('#ADD_NAME_FEEDBACK').html(name_feedback.join('
')); setTimeout(function(){$('#ADD_NAME_FEEDBACK').empty();}, 5000); } } if ($('#ADD_NAME_STATUS')) { $('#ADD_NAME_STATUS').addClass('ADD_NAME_SUCCESS'); $('#ADD_NAME_STATUS').html(''+ id +' added.'); $('#ADD_NAME_STATUS').show(); $('#ADD_NAME_NAME').val(''); } } else { if (typeof(data.user_logged_in) != 'undefined' && data.user_logged_in == false) { bn_user.slay(); bn_user.check_login(true); } else if (typeof(data.error_message) != 'undefined') { $('#FAVOURITE_ERROR').empty(); $('#FAVOURITE_ERROR').append(data.error_message); $('#FAVOURITE_ERROR').show(); } } }); } }; //File: user.js var bn_user = { favourites: new Array(), user: null, nickname: null, recently_viewed: {length: 0}, avatar: 'nobody', public_profile: 0, //do_after_login: null, //arguments_after_login: null, //Overridable functions for what to do on each page after login or slay after_login: function() {}, after_slay: function() {}, after_logout: function() {}, /** * Destroy the session then slay the user */ logout: function() { // Reason for the next bit of code: //We need to make sure that no matter what all privledges are taken away //that is why we use the slay. Inside the slay is a call to an overridable //function called after_slay, and here is a call to after_logout which is //also overridable. This means that each page can set what these actions //do. We need to do both after_slay and after_logout because the page should //never be redirected until the stax logout has completed because if the //next page loads and the user is still logged in(the stax call has not yet //completed) the user will appear to be logged in on the next page but then //the stax will complete destroying the session. Bad. //The solution is to continue with the slay no matter what, but only logout //after the stax call is finished. HENCE: IF YOUR LOGOUT ON A PAGE REQUIRES //A REDIRECT TO A NEW PAGE, YOU MUST ___MUST___ USE AFTER LOGOUT!! THIS IS //YOUR WARNING. IF YOU HAVE SIMILAR ISSUES, YOU DID NOT READ THIS FIRST OR //DID NOT PROPERLY HEED MY WARNING TO REMEMBER THIS WARNING! _logout(function(ret){ bn_user.after_logout(); data = JSON.parse(ret); if (data.success) { } }); bn_user.slay(); }, /** * Takes away user priveleges in javascript * @return void */ slay: function(){ bn_user.user = null; bn_user.nickname = null; bn_user.recently_viewed = {}; bn_user.avatar = 'nobody'; bn_user.public_profile = 0; bn_user.generate_greeting(); this.favourites = ''; return bn_user.after_slay(); }, /** * Checks if a user is logged in and logs the user in * @param recall boolean: recall the calling function on successful login * @return boolean */ check_login: function(recall, cb) { if (this.user == null) { if (recall) { do_after_login = arguments.callee.caller; arguments_after_login = arguments.callee.caller.arguments; } else { $("#LOGIN_ERROR").empty(); } $('#LOGIN_FORM').submit(function(){ $("#LOGIN_ERROR").empty(); if ($('#LOGIN_USERNAME').val() == '' || $('#LOGIN_PASSWORD').val() == '') { $("#LOGIN_ERROR").html('You must enter a username and a password.
'); $("#LOGIN_ERROR").show(); return false; } _do_login($('#LOGIN_USERNAME').val(), $('#LOGIN_PASSWORD').val(), $('#LOGIN_REMEMBER').attr('checked'), function(ret){ data = JSON.parse(ret); if (data.success) { $("#LOGIN_WINDOW").jqmHide(); bn_user.user = data.user; bn_user.nickname = data.nickname; bn_user.public_profile = data.public; bn_user.avatar = data.avatar; //Build the top link area //$('#GREETING').empty(); //$('#GREETING').append('Welcome, ' + bn_user.nickname + '. Sign Out'); //$('#MY_SAVED_NAMES_TOPLINK').show(); bn_user.favourites = data.favourites; if (typeof(do_after_login) != 'undefined' && do_after_login != null) { do_after_login.apply(this, arguments_after_login); do_after_login = null; } bn_user.recently_viewed = data.recent; bn_user.generate_greeting(); bn_user.after_login(); if($('input#LOGIN_REMEMBER').attr('checked')) { $.cookie('REMEMBER_USER', $('#LOGIN_USERNAME').val(), {expires: 365}); } } else { if (data.auth_code == 'LOCKED') { $("#LOGIN_ERROR").html('Your account has been lock please try again in 20 minutes.
'); } else { $("#LOGIN_ERROR").html('Could not log you in. Please check your credentials.
'); } $("#LOGIN_ERROR").show(); } }); return false; }); //cookie for remembering user login id if($.cookie('REMEMBER_USER')) $('#LOGIN_USERNAME').val($.cookie('REMEMBER_USER')); else $('#LOGIN_USERNAME').val(''); $('#LOGIN_PASSWORD').val(''); $('#LOGIN_WINDOW').jqmShow(); if($.cookie('REMEMBER_USER')) { $('input#LOGIN_REMEMBER').attr('checked', true); if($('#LOGIN_PASSWORD').val() != '') $('input#LOGIN_SUBMIT').focus(); else $('input#LOGIN_PASSWORD').focus(); } return false; } else { return true; } }, /** * Generates the top link area for logout/login and recently viewed */ generate_greeting: function() { $('#GREETING').empty(); $('#RECENT').empty(); $('#RECENT').append('

Recently Viewed

'); if (bn_user.recently_viewed.length) { $('#RECENT').append('