$(document).ready(function() { $('table tr').hover(function() {$(this).toggleClass('hover');}, function() {$(this).toggleClass('hover');}); window.setTimeout(function() {$('.notification-notification').fadeOut();}, 5000); //window.setTimeout(function() { $('.notification-error').fadeOut(); }, 20000); cdInt = window.setInterval(function() { if ($('#countdown').length == 1) { intCur = $('#countdown').attr('rel'); if (intCur < 1) { clearInterval( cdInt ); window.location = '/logout'; } else { intCur -= 1; datDate = new Date( intCur*1000 ); secs = datDate.getSeconds(); if (new String(secs).length == 1) secs = '0'+secs; $('#countdown_time').html( datDate.getMinutes()+':'+secs ); $('#countdown').attr('rel', intCur); } } }, 1000); }); var site = { submitForm : function(e) { // Start out positively formStatus = true; // Run through each of the form elements that has the required tag $('input[class*=required],select[class*=required],textarea[class*=required]').each(function() { // Remove any old and lingering errors $(this).removeClass('formError'); $('#'+$(this).attr('id')+'_container').removeClass('formError'); // Plain old required if ($(this).hasClass('required')) { if ($(this).val() == '') { formStatus = false; $(this).addClass('formError'); } } // Or maybe it's a mandatory email field else if ($(this).hasClass('required-email')) { if (/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test($(this).val()) == false ) { formStatus = false; $(this).addClass('formError'); } } // Or maybe a 'cant be null' type else if ($(this).hasClass('required-notnull')) { if ($(this).val() == 'null' || $(this).val() == null ) { formStatus = false; $(this).addClass('formError'); } } // Or maybe it should be a proper date else if ($(this).hasClass('required-date')) { // TODO Needs additions, only checks for 0000-00-00 type dates now if (/^([0-9]+){4}([^0-9]+)([0-9]+){2}([^0-9]+)([0-9]+){2}/.test($(this).val()) == false && /^([0-9]+){2}([^0-9]+)([0-9]+){2}([^0-9]+)([0-9]+){4}/.test($(this).val()) == false) { formStatus = false; $(this).addClass('formError'); } } if ($(this).hasClass('required-editor')) { if ($(this).val() == '') { formStatus = false; $('#'+$(this).attr('id')+'_container').addClass('formError').css({display:'block'}); } } if ($(this).hasClass('required-oneoff')) { els = $('input[rel='+$(this).attr('rel')+']', $(this).parent()); subStatus = false; for(i = 0; i < els.length; i++) { if (els[i].checked == true) { subStatus = true; } } if (subStatus == false) { formStatus = subStatus; $('#'+$(this).attr('id')+'_container').addClass('formError') } } }); // And finally submit or fail on submit if (formStatus == true) { $(e).parents('form').submit(); } else { return false; } }, toggleContent : function(elOn, elOff) { $('#'+elOff).hide(); $('#'+elOn).fadeIn('normal'); }, alertBox : function(msg, uri) { box = confirm(msg); if (box) { window.location = uri; } else { return false; } } }; var input = { toggleAll : function(elmList) { var stat = $('input.'+elmList+':first').attr('checked'); newstat = true; if (stat == true) newstat = false; $('input.'+elmList).each(function() { $(this).attr('checked', newstat); }); } };