var MOCA_HOME_ID = 0;
var MOCA_BASE_URL = 'https://www.columbiatools.co.nz/';
var MOCA_HOME_URL = 'https://www.columbiatools.co.nz/';
// Default table listing row bg colour
var MOCA_TABLE_BG_DEFAULT = 'transparent';
// Used to stripe listing tables for readability
var MOCA_TABLE_BG = 'transparent';
var MOCA_TABLE_BG_BLUE = '#eceff5';
var MOCA_TABLE_BG_DARK = '#B3B3B3';
// 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'
);}});
*/
$.ajaxSetup({
error:function(x,e){
if(x.status==0){
mocaAlert('No network found', 'AJAX Error');
}else if(x.status==404){
mocaAlert('Requested url not found', 'AJAX Error');
}else if(x.status==500){
mocaAlert('Internel server error', 'AJAX Error');
}else if(e=='parsererror'){
mocaAlert('Parsing JSON request failed', 'AJAX Error');
}else if(e=='timeout'){
mocaAlert('Request time out', 'AJAX Error');
}else {
mocaAlert('Unknown Ajax Error:\\n'+x.responseText, 'AJAX Error');
}
}
});
// Click status messages to dismiss:
$(document).ready(function(){
$('#statusMessage').bind('click',function(){$('#statusMessage').html('');});
$('#statusCell').bind('click',function(){$('#statusMessage').html('');});
});
// Populated by MocaForm::initJavascript()
var Help = {};
// External stylesheet to be used by fck_editor. Initialised
// as required in MocaForm->initJavascript()
var MocaFckStyles = '';
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(skip){odd=true;skip--;return;}
if($(this).css('display')!='none'){
$('TD',$(this)).map(function(){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 ckeditorInit(){
// Called by page onLoad MocaForm.initJavascript(): change internal
// stylesheet to that initialised by moca.form
if(MocaFckStyles){
CKEDITOR.on( 'instanceReady', function( ev ) {
ev.editor.config.contentsCss = MocaFckStyles;
ev.editor.setData(ev.editor.getData());});
}
}
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){
/* Custom alert. First arg is message string. Second is title. Third is
function to be executed on close. Only the first is mandatory */
var title = arguments[1] ? arguments[1] : '';
var func = arguments[2] ? arguments[2] : null;
switch('jquidialog'){
case 'jquidialog':
str = str.indexOf('<')>-1 ? str : '' + str + '
';
$('BODY').append('' + str + '
');
$('#mocaDialog').dialog({
'close':function(){if(func){func();}else{$(this).remove();}},
'buttons': {
'Ok': function() {
if(func){func();}
else {$(this).remove();}
}
}
});
if(jQuery().easydrag){
$('.ui-dialog').easydrag();
}
break;
case 'jqalert':
return jAlert(str,title);
break;
default:
return alert(str);
break;
}
}
function is_numeric(el){
return (typeof(el) === 'number' || typeof(el) === 'string') && el !== '' && !isNaN(el);
}
function plural(num){
return num==1 ? '' : 's';
}
String.prototype.mocaPluralise = function(num){
return this + (num==1? '' : 's');
};
String.prototype.mocaStartsWithVowel = function(){
return this.match(/^[aeiou]/i)
};
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);
})
var MocaCookiesEnabled = false;
function clientCookieCheck(){
// Call in form pages reliant on sessions
setCookie('test_name','test_value',0);
var ck = getCookie('test_name');
if(!ck || (ck != 'test_value')) {
return mocaAlert('Your browser and/or network is not configured '+
'to use "cookies". To use this site you must be able to send and receive cookies '+
'from our server. Until you can do so you will not be able to continue.');
}
else {
MocaCookiesEnabled = true;
deleteCookie('test_name');
}
}
function setCookie(name,
value,
expires // in X days
){
/*
OPTIONAL PARAMS:
path - where valid, usually '/'
domain - all crossing of subdomain
secure
*/
var today = new Date();
today.setTime( today.getTime() );
var expires_date = new Date( today.getTime() + (expires ? expires*1000*60*60*24 : 0) );
document.cookie = name+'='+escape( value ) +
(expires ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
(arguments[3]? ';path=' + arguments[3] : '' ) +
(arguments[4]? ';domain=' + arguments[4] : '' ) +
(arguments[5]? ';secure' : '' );
}
function getCookie(name) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if (!start && name != document.cookie.substring( 0, name.length )) {return null;}
if (start == -1) {return null;}
var end = document.cookie.indexOf( ';', len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function deleteCookie(name){
if (getCookie(name)){
document.cookie = name + '=' +
(arguments[1] ? ';path=' + arguments[1] : '') +
(arguments[2] ? ';domain=' + arguments[2] : '' ) +
';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
}
// DEV tool
function dump(obj){
var str='';
for(p in obj){
str = str + p + ' = ' + obj[p] + "\n";
}
return str;
}