var MOCA_HOME_ID = 1; var MOCA_BASE_URL = 'http://www.agtrader.co.nz/'; var MOCA_HOME_URL = 'http://www.agtrader.co.nz/home'; // Default table listing row bg colour var MOCA_TABLE_BG_DEFAULT = '#fff'; // Used to stripe listing tables for readability var MOCA_TABLE_BG = '#eee'; var MOCA_TABLE_BG_BLUE = '#eceff5'; // Highlight record being edited var MOCA_TABLE_HIGHLIGHT = '#ffc'; // Highlight just-created field var MOCA_TABLE_NEW_ROW = 'pink'; // Global ajax error handler: $.ajaxSetup({'error':function(req,msg,err){ mocaAlert("

" + req.responseText + "
Error: " + msg + '

', 'AJAX Error' );}}); /* var str = req.responseText ? ('XMLHttpRequest: ' + req.responseText) : ('Text status: ' + msg + '\nError thrown: ' + err); mocaAlert('AJAX system error:\n\n' + str);}}); */ $(document).ready(function(){ $('#statusMessage').bind('click',function(){$('#statusMessage').html('');}); $('#statusCell').bind('click',function(){$('#statusMessage').html('');}); }); // Populated by MocaForm::initJavascript() var Help = {}; // Whether fckeditor should use default fe stylesheet var MocaFckStyles = true; function logout(){ window.location.href = MOCA_BASE_URL + 'sitemgr/logout.php'; } function highlightRows(table_id, no_header_row,skip){ /* Given the ID of a table element, set every alternate row's background colour to MOCA_TABLE_BG colour. Unless no_header_row is set, the first row will be left untouched. Apply the class 'nonList' to any rows you want skipped */ var odd = false; var first = true; $('TABLE#' + table_id + ' TR:not(.nonList)').map( function(){ if(!no_header_row && first){skip--;first = false;return;} if($(this).css('display')!='none'){ $('TD',$(this)).map(function(){if(skip){odd=true;skip--;return;}this.style.backgroundColor = odd ? MOCA_TABLE_BG : '';}); odd = !odd; } }) } function highlightOptions(select_id,colour ){ /* Given the ID of a select element, set every alternate option's background colour to given colour.MOCA_TABLE_BG colour. */ colour = colour ? colour : MOCA_TABLE_BG; var odd = false; $('SELECT#' + select_id + ' OPTION:not(.nonList)').map( function(){ if($(this).css('display')!='none'){ this.style.backgroundColor = odd ? colour : ''; odd = !odd; } }) } function FCKeditor_OnComplete(ed){ // Called by editor onLoad, change internal // stylesheet to that initialised by moca.form if(!MocaFckStyles){return;} //var ht = ed.GetData(); if($('#moca_browser').val()){ ed.Config['ImageBrowserWindowWidth'] = ed.Config['ScreenWidth'] * 0.4; ed.Config['ImageBrowserWindowHeight'] = ed.Config['ScreenHeight'] * 0.4; ed.Config['LinkBrowserWindowWidth'] = ed.Config['ScreenWidth'] * 0.5; ed.Config['LinkBrowserWindowHeight'] = ed.Config['ScreenHeight'] * 0.5; ed.Config['LinkBrowserURL'] = ed.Config['BasePath'] + 'filemanager/browser/link/fe_browser.php' ; } } function deleteFromListing(frm,ids){ // Delete records from listing page - ids is either array or // comma-separated string of ids. Form is DOM element frm.id_list.value = typeof ids == 'string' ? ids : ids.join(','); frm.func.value = 'delete'; frm.submit(); } // Convenience func for use in mocaConfirm & ilk function goto(href){window.location.href=href;} function showHelp(id){ if((Help == undefined) || !Help[id]){return;} mocaAlert(Help[id],'Help'); } function mocaConfirm(str,func,title){ title = arguments[2] ? arguments[2] : 'Please Confirm'; switch('jquidialog'){ case 'jquidialog': str = str.indexOf('<')>-1 ? str : '

' + str + '

'; $('BODY').append('
' + str + '
'); $('#mocaDialog').dialog({ 'close':function(){$('#mocaDialog').remove();}, 'buttons': { 'Ok': function() {func(); $(this).dialog("close");}, 'Cancel': function() {$(this).dialog("close");} } }); break; case 'jqalert': return jAlert(str,title); break; default: return alert(str); break; } } function mocaAlert(str){ title = arguments[1] ? arguments[1] : 'Alert'; switch('jquidialog'){ case 'jquidialog': str = str.indexOf('<')>-1 ? str : '

' + str + '

'; $('BODY').append('
' + str + '
'); $('#mocaDialog').dialog({ 'close':function(){$('#mocaDialog').remove();}, 'buttons': { 'Ok': function() { $(this).dialog('close'); } } }); if(jQuery().easydrag){ $('.ui-dialog').easydrag(); //$('.ui-dialog').setHandler('.ui-dialog-titlebar'); } break; case 'jqalert': return jAlert(str,title); break; default: return alert(str); break; } } String.prototype.mocaCamelCase = function(){ var s = $.trim( this.toLowerCase() ); return s.replace( / ([a-z])/g, function(t,b) { return b.toUpperCase(); } ); }; String.prototype.mocaCapitalize = function(){ return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } ); }; String.prototype.mocaZeroPad = function(){ return this.length==1 ? ('0'+this) : this; }; Array.prototype.mocaRemove = function(x) { var pos = -1; for(var i=0; imax){max=this[i];} } return max; }; Date.prototype.mocaToString=function() { // 03-12-2010 var d = String(this.getDate());var m = String(this.getMonth()+1); var y = String(this.getYear()+1900); return d.mocaZeroPad() + '-' + m.mocaZeroPad() + '-' + y; }; $(document).ready(function(){ (function($){ $.fn.positionCenter = function(options) { var pos = { sTop : function() { return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop; }, wHeight : function() { return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight; } }; return this.each(function(index) { if (index == 0) { var $this = $(this); var elHeight = $this.outerHeight(); var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2); $this.css({ position: 'absolute', margin: '0', top: elTop, left: (($(window).width() - $this.outerWidth()) / 2) + 'px' }); } }); }; })(jQuery); }) // DEV tool function dump(obj){ var str=''; for(p in obj){ str = str + p + ' = ' + obj[p] + "\n"; } return str; }