// Build the nav menus. Also add functionality for messages with the UI $(function() { $('#system_error_message').dialog({ bgiframe: true, autoOpen: true, height: 250, width: 400, modal: true, buttons: { Okay: function() { $(this).dialog('close'); } } }); // Setup basic message dialog. Call a message using roster.msg(title, message, [callback]) $('#msg_dialog').dialog({ bgiframe: true, autoOpen: false, height: 350, minHeight: 250, width: 400, modal: true, buttons: { Okay: function() { $(this).dialog('close'); } } }); // Setup basic confirm dialog. Call a message using roster.confirm(title, message, [callback_ok], [callback_cancel]) $('#confirm_dialog').dialog({ bgiframe: true, autoOpen: false, height: 250, width: 400, modal: true, buttons: { Cancel: function() { $(this).dialog('close'); }, Okay: function() { $(this).dialog('close'); } } }); //hover states and click animation on the static icons $('ul.icons li.icon').live('mouseover', function() { $(this).addClass('ui-state-hover'); }) .live('mouseout', function() { $(this).removeClass('ui-state-hover'); }) .live('mousedown', function(){ $(this).addClass("ui-state-active"); }) .live('mouseup', function(){ $(this).removeClass("ui-state-active");}); // Setup the quick search icon to submit the search form when clicked $('#quicksearch-icons > li.search').click(function() { $('#quicksearch-form').submit(); }); // When focusing on search form, set text to blank if it was greyed. When leaving the input field, if blank set greyed and text 'Search' $('#quicksearch-form > input').focus(function() { if($(this).hasClass('greyed')) { $(this).removeClass('greyed').val(''); } }).blur(function() { if($(this).val() == '') { $(this).addClass('greyed').val('Search'); } }); // Before submitting the quick search form, check if the input has a greyed class (no user search input was entered) or if the value is blank $('#quicksearch-form').submit(function() { var success = true; var inp = $(this).find('input'); if ((inp.hasClass('greyed')) || (inp.val() == '')) { success = false; } return success; }); // Add hovering effect to buttons and icons $('input.button, li.icon').hover(function() { $(this).addClass('button-hover'); }, function() { $(this).removeClass('button-hover'); }); // Type casting for input fields! $('input.int, input.integer').live('change', function() { var val = $(this).val(); var cast = sgx.int(val); $(this).val(cast.string); }).change(); $('input.float, input.decimal').live('change', function() { var val = $(this).val(); var cast = sgx.float(val); $(this).val(cast.string); }).change(); $('input.currency').live('change', function() { var val = $(this).val(); var cast = sgx.currency(val); $(this).val(cast.value); }).change(); $('input.datetime').datepicker({ yearRange: '-60:+20', changeYear: true, changeMonth: true, dateFormat: 'M d, yy 0:0:0', showAnim: 'slideDown' }).live('change', function() { var val = $(this).val(); var cast = sgx.cast_datetime(val); $(this).val(cast.string); }).change(); $('input.date').datepicker({ yearRange: '-60:+20', changeYear: true, changeMonth: true, dateFormat: 'M d, yy', showAnim: 'slideDown' }).live('change', function() { var val = $(this).val(); var cast = sgx.cast_date(val); $(this).val(cast.string); }).change(); $('input.phone').live('blur', function() { // Returns false if invalid or the properly formatted string if valid var $t = $(this); var str = $t.val(); var a = str.toLowerCase().split('x'); var l = a[0].length; var reg = /^[0-9x]$/; var phone = ''; var ext = ''; var i; var chr; var pre; // Clean phone number if(a.length >= 1) { for(i = 0; i < l; i++) { if(phone.length < 10) { chr = a[0].substr(i, 1); if (reg.test(chr)) { phone += chr; } } } } // Clean extension if(a.length == 2) { l = a[1].length; pre = ' x '; for(i = 0; i < l; i++) { if(ext.length < 8) { chr = a[1].substr(i, 1); if (reg.test(chr)) { ext += pre + chr; pre = ''; } } } } if (phone.length == 10) { $t.val(phone.substr(0, 3) + '-' + phone.substr(3, 3) + '-' + phone.substr(6, 4) + ext); } else { $t.val(''); } }).blur(); $('input.province').live('blur', function() { var val = sgx.string.trim($(this).val().toUpperCase()); if(val != '') { var msg = ''; if(val.length < 2) { $(this).val(''); } else { $(this).val(val.substr(0, 2)); } } }).blur(); $('input.postal').live('blur', function() { var val = sgx.string.trim($(this).val().toUpperCase()); if(val != '') { var reg = /^[A-Z][0-9][A-Z]\s?[0-9][A-Z][0-9]$/; var msg = ''; if(reg.test(val) == false) { $(this).val(''); //msg = roster.data.help.txt_validation_postal; } else { $(this).val(val); } } }).blur(); $('a.help, li.help').live('click', function(ev) { var $t = $(this); var $help = $t.next('.helptext'); if($help.length == 1) { var title = $help.attr('title'); title = title ? title : 'Help'; app.msg($help.html(), title); } ev.preventDefault(); }); $('input.email').live('blur', function() { var result = ''; var str = $(this).val().toLowerCase(); str = str.replace(/^\s+|\s+$/g,""); if(str.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) { result = str; } else { result = ''; } $(this).val(result); }).blur(); }); // Custom Functions for Theme $(function() { // Menu Handling - move submenus to the dialog-submenus div in dialogs $('body').append('
'); $('#menuMain .submenu').each(function() { $(this).detach().appendTo('#dialog-submenus'); }); // Handle submenu popups var submenu_hide_timeout = false; //* $('#menuMain .menu-link, #dialog-submenus .submenu').hover(function(ev) { var menuID = this.id.match(/\-([a-zA-Z0-9]+)$/); var menuJqSel = '#menu-selection-' + menuID[1]; var submenuJqSel = '#submenu-selection-' + menuID[1]; var parentPos = $(menuJqSel).offset(); if($(submenuJqSel).length && $(submenuJqSel).not('.showSubmenu').length) { // Element has a submenu and it is not the current menu clearTimeout(submenu_hide_timeout); $('.submenu').css('display', 'none').removeClass('showSubmenu'); $(submenuJqSel) .css('position', 'absolute') .css('left', parentPos.left + 15) .css('top', parentPos.top + 25) .addClass('showSubmenu') .fadeIn(); } else if($(submenuJqSel).length) { // Visible submenu, clear any timeout but don't hide anything clearTimeout(submenu_hide_timeout); } }, function(ev) { var menuID = this.id.match(/\-([a-zA-Z0-9]+)$/); var submenuJqSel = '#submenu-selection-' + menuID[1]; if($(submenuJqSel).length) { submenu_hide_timeout = setTimeout(function() { $(submenuJqSel).removeClass('showSubmenu').fadeOut(); }, 500); } }); //*/ $('button, input:button, input:reset, input:submit').button(); });