/** * * Base64 encode / decode * http://www.webtoolkit.info/ * **/ var encodeMessages = true; var Base64 = { // private property _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode : function (input) { if (!encodeMessages) return input; var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode : function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } /* Simple AJAX Code-Kit (SACK) v1.6.1 */ /* �2005 Gregory Wild-Smith */ /* www.twilightuniverse.com */ /* Software licenced under a modified X11 licence, see documentation or authors website for more details */ function sack(file) { this.xmlhttp = null; this.errors = []; this.resetData = function() { this.method = "POST"; this.queryStringSeparator = "?"; this.argumentSeparator = "&"; this.URLString = ""; this.encodeURIString = true; this.execute = false; this.element = null; this.elementObj = null; this.requestFile = file; this.vars = new Object(); this.responseStatus = new Array(2); /** * Will hold any object to be restored after the ajax request is completed (it can be an object, an array) * It is used to store the current scope in form editor and rebuild it after the ajax request is executed */ this.argument = null; this.errors = []; }; this.resetFunctions = function() { this.onLoading = function() { Loading_Indicator.show(); }; this.onLoaded = function() { Loading_Indicator.hide(); Loading_Indicator.unblockUI(); }; this.onInteractive = function() { }; this.onCompletion = function() { }; this.onError = function() { }; this.onFail = function() { }; }; this.reset = function() { this.resetFunctions(); this.resetData(); }; this.createAJAX = function() { try { this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e1) { try { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { this.xmlhttp = null; } } if (!this.xmlhttp) { if (typeof XMLHttpRequest != "undefined") { this.xmlhttp = new XMLHttpRequest(); } else { this.failed = true; } } }; this.checkForErrors = function( divId ) { try { var el = eval(this.response); if (el.error == 1) { this.errors = el.errors; if (divId != null) { $("#"+divId+"_error_span").html(''); for(var i=0; i"); } } return true; } else { return false; } } catch (ex) { } return false; } this.setVar = function(name, value) { this.vars[name] = Array(value, false); }; this.encVar = function(name, value, returnvars) { if (true == returnvars) { return Array(encodeURIComponent(name), encodeURIComponent(value)); } else { this.vars[encodeURIComponent(name)] = Array( encodeURIComponent(value), true); } } this.processURLString = function(string, encode) { encoded = encodeURIComponent(this.argumentSeparator); regexp = new RegExp(this.argumentSeparator + "|" + encoded); varArray = string.split(regexp); for (i = 0; i < varArray.length; i++) { urlVars = varArray[i].split("="); if (true == encode) { this.encVar(urlVars[0], urlVars[1]); } else { this.setVar(urlVars[0], urlVars[1]); } } } this.createURLString = function(urlstring) { if (this.encodeURIString && this.URLString.length) { this.processURLString(this.URLString, true); } if (urlstring) { if (this.URLString.length) { this.URLString += this.argumentSeparator + urlstring; } else { this.URLString = urlstring; } } // prevents caching of URLString this.setVar("rndval", new Date().getTime()); urlstringtemp = new Array(); for (key in this.vars) { if (false == this.vars[key][1] && true == this.encodeURIString) { encoded = this.encVar(key, this.vars[key][0], true); delete this.vars[key]; this.vars[encoded[0]] = Array(encoded[1], true); key = encoded[0]; } urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0]; } if (urlstring) { this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator); } else { this.URLString += urlstringtemp.join(this.argumentSeparator); } } this.runResponse = function() { eval(this.response); } this.runAJAX = function(urlstring) { if (this.failed) { this.onFail(); } else { this.createURLString(urlstring); if (this.element) { this.elementObj = document.getElementById(this.element); } if (this.xmlhttp) { var self = this; if (this.method == "GET") { totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString; this.xmlhttp.open(this.method, totalurlstring, true); } else { this.xmlhttp.open(this.method, this.requestFile, true); try { this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") } catch (e) { } } this.xmlhttp.onreadystatechange = function() { switch (self.xmlhttp.readyState) { case 1: self.onLoading(); break; case 2: self.onLoaded(); break; case 3: self.onInteractive(); break; case 4: self.response = self.xmlhttp.responseText; self.responseXML = self.xmlhttp.responseXML; self.responseStatus[0] = self.xmlhttp.status; self.responseStatus[1] = self.xmlhttp.statusText; if (self.execute) { self.runResponse(); } if (self.elementObj) { elemNodeName = self.elementObj.nodeName; elemNodeName = elemNodeName.toLowerCase(); if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") { self.elementObj.value = self.response; } else { self.elementObj.innerHTML = self.response; } } if (self.responseStatus[0] == "200") { if (request.response == '{"alert":"session_expired"}') { Loading_Indicator.sessionExpired(); } else { self.onCompletion(request.response, self.argument || null); } } else { self.onError(); } /* * These lines were added by Alf Magne Kalleland * ref. info on the sack home page. It prevents * memory leakage in IE */ self.URLString = ""; delete self.xmlhttp['onreadystatechange']; self.xmlhttp = null; self.responseStatus = null; self.response = null; self.responseXML = null; break; } }; this.xmlhttp.send(this.URLString); } } }; this.reset(); this.createAJAX(); } function Service_Request() { } request = null; var request = { response : null, errors : [], checkForErrors : function( divId ) { try { var el = eval(this.response); if (el.error == 1) { this.errors = el.errors; if (divId != null) { $("#"+divId+"_error_span").html(''); for(var i=0; i"); } } return true; } else { return false; } } catch (ex) { } return false; } }; function checkForErrors(response, divId, showTime) { try { var el = eval(response); if (el.error == 1) { this.errors = el.errors; var msg = ''; for(var i=0; i"; } if (divId != null && (typeof el.usePageAlert === 'undefined ')) { $("#"+divId+"_error_span").html(''); $("#"+divId+"_error_div").css('display', 'block'); $("#"+divId+"_error_span").html(msg); } else { Loading_Indicator.showMessage(msg, showTime, 'error-message'); } return true; } else { return false; } } catch (ex) { } return false; } function clearErrors(divId) { if (typeof divId == 'undefined' || divId === null) { } else { $("#"+divId+"_error_div").css('display','none'); $("#"+divId+"_error_span").html(''); } } Service_Request.prototype.array2json = function(arr) { var parts = []; var is_list = (Object.prototype.toString.apply(arr) === '[object Array]'); for(var key in arr) { var value = arr[key]; if(typeof value == "object") { //Custom handling for arrays parts.push('"' + key + '":' + this.array2json(value)); /** if(is_list){ parts.push(this.array2json(value));} else { parts[key] = this.array2json(value); } **//* :RECURSION: */ } else { var str = ""; if(!is_list) str = '"' + key + '":'; //Custom handling for multiple data types /** if(typeof value == "number") str += value; //Numbers else if(value === false) str += 'false'; //The booleans else if(value === true) str += 'true'; else str += '"' + value + '"'; **/ str += '"' + Base64.encode(value+"") + '"'; //All other things // :TODO: Is there any more datatype we should be in the lookout for? (Functions?) parts.push(str); } } var json = parts.join(","); if(is_list) return '[' + json + ']';//Return numerical JSON return '{' + json + '}';//Return associative JSON } Service_Request.prototype.callMethod = function(service, method, params, handler, argument) { /** request = new sack(); request.requestFile = 'services.php'; request.setVar('service', service); // Specifying which file to get request.setVar('method', method); **/ var paramstr = '['; var value =""; var type =""; for ( var i = 0; i < params.length; i++) { type = ""; if (typeof params[i] == 'string') { if (params[i].indexOf('{"') == 0) { value = params[i]; } else { value = '"' + Base64.encode(params[i]) + '"'; } } else { if (typeof params[i] == 'object') { value = this.array2json(params[i]); type = "object"; } else { value = '"' + Base64.encode(params[i]+'') + '"'; } } paramstr += '{"value" : '+value+', "type" : "'+type+'"}'; if (i != params.length - 1) { paramstr += ',' } } paramstr += ']'; /** request.setVar('params', paramstr); request.setVar('sid', ''); request.setVar('encoded',(encodeMessages)?1:0); request.onCompletion = function(){ handler( request.response ); }; request.argument = argument || null; request.runAJAX(); return; **/ $.ajax({ url : "services.php?service=" + service + "&method=" + method + "&encoded=" + ((encodeMessages)?1:0) + "&argument=" + (argument || null), type: 'POST', data : { params : paramstr }, success: function(data){ if (data == '{"alert":"session_expired"}') { Loading_Indicator.sessionExpired(); } request.response = data; handler(data); } }); } var Loading_Indicator = function() { this.div = null; } Loading_Indicator.prototype.show = function() { $('body').css('cursor', 'progress'); return; if (this.div == null) { this.div = document.getElementById('indicator'); } this.div.style.display = "block"; } Loading_Indicator.prototype.hide = function() { $('body').css('cursor', 'auto'); return; this.div.style.display = "none"; } Loading_Indicator.prototype.showModalLoading = function(message, height, width) { var height = height || 150; var width = width || 350; if ($('.js-main-modal-loading').length == 0) { $('body').append(''); } $('.js-main-modal-loading .js-modal-message').html(message); $('.js-main-modal-loading').show(); } Loading_Indicator.prototype.hideModalLoading = function(message, height, width) { $('.js-main-modal-loading').hide(); } Loading_Indicator.prototype.blockUI = function(title, message, height, width) { var height = height || 150; var width = width || 350; this.alert(title, message, width, height); $("#jQueryAlertContainer").dialog('option', 'modal', true); $("#jQueryAlertContainer").dialog('option', 'buttons', {}); $("#jQueryAlertContainer").dialog('option', 'minHeight', 150); $("#jQueryAlertContainer").dialog('option', 'height', height); $("#jQueryAlertContainer").css('height', height); } Loading_Indicator.prototype.unblockUI = function() { $("#jQueryAlertContainer").dialog('close'); } Loading_Indicator.prototype.showMessage = function(message, time, cssClass) { var time = time || 6000; if(typeof cssClass != 'undefined'){ $("#jqueryMessageContainer").addClass(cssClass); } $("#jqueryMessageContainerText").html(message); $("#jqueryMessageContainer").show("fade"); setTimeout(' $("#jqueryMessageContainer").hide("fade");', time); } Loading_Indicator.prototype.closeMessage = function() { $("#jqueryMessageContainer").hide("fade"); } Loading_Indicator.prototype.confirm = function(message, type, handler, width ,height, handlerCancel) { if (document.getElementById('jQueryConfirmContainer')) { $('#jQueryConfirmContainer').remove(); } var height = height || 'auto'; var width = width || 'auto'; var handlerCancel = handlerCancel || function() { $(this).dialog('close'); }; var wrapdiv = (document.createElement('div')); wrapdiv.id = "jQueryConfirmContainer"; wrapdiv.title = "Confirm"; var wrapdiv = document.body.appendChild(wrapdiv); var image = "images/oxygen/32x32/places/user-trash.png"; switch (type) { case 'remove': image = "images/oxygen/32x32/places/user-trash.png"; break; case 'activate': image = "images/oxygen/32x32/actions/dialog-ok-apply.png"; break; case 'inactivate': image = "images/oxygen/32x32/actions/dialog-cancel.png"; break; default: image = "images/oxygen/32x32/categories/system-help.png"; break; } wrapdiv.innerHTML = "
"+message+"
"; $("#jQueryConfirmContainer").dialog( { bgiframe :true, modal :true, height :height, width :width, minHeight :150, position :'center', dialogClass : 'simple-ui-dialog confirm-dialog confirm-' + type, buttons : { "Ok" : handler, "Cancel" : handlerCancel } }); } Loading_Indicator.prototype.customConfirm = function(title, message, type, width ,height, buttons) { if (document.getElementById('jQueryConfirmContainer')) { $('#jQueryConfirmContainer').remove(); } var height = height || 'auto'; var width = width || 'auto'; var wrapdiv = (document.createElement('div')); wrapdiv.id = "jQueryConfirmContainer"; wrapdiv.title = title; var wrapdiv = document.body.appendChild(wrapdiv); var image = "images/oxygen/32x32/places/user-trash.png"; switch (type) { case 'remove': image = "images/oxygen/32x32/places/user-trash.png"; break; case 'activate': image = "images/oxygen/32x32/actions/dialog-ok-apply.png"; break; case 'inactivate': image = "images/oxygen/32x32/actions/dialog-cancel.png"; break; default: image = "images/oxygen/32x32/categories/system-help.png"; break; } wrapdiv.innerHTML = "
"+message+"
"; $("#jQueryConfirmContainer").dialog( { bgiframe :true, modal :true, height :height, width :width, minHeight :150, position :'center', buttons : buttons }); } Loading_Indicator.prototype.confirmLoading = function() { $("#jQueryConfirmContainer").html(""); } Loading_Indicator.prototype.confirmClose = function() { $("#jQueryConfirmContainer").dialog('close'); } Loading_Indicator.prototype.hideConfirmButtons = function() { $("#jQueryConfirmContainer").parent().find(".ui-dialog-buttonpane").css("visibility", "hidden"); } Loading_Indicator.prototype.showConfirmButtons = function() { $("#jQueryConfirmContainer").parent().find(".ui-dialog-buttonpane").css("visibility", "visible"); } Loading_Indicator.prototype.alert = function(title, message, width, height) { if (document.getElementById('jQueryAlertContainer')) { $('#jQueryAlertContainer').remove(); } var height = height || 'auto'; var width = width || 'auto'; var wrapdiv = (document.createElement('div')); wrapdiv.id = "jQueryAlertContainer"; wrapdiv.title = title || "Alert"; var containerP = (document.createElement('div')); containerP.className = "js-messages alert-message-container"; wrapdiv.appendChild(containerP); document.body.appendChild(wrapdiv); $("#jQueryAlertContainer").dialog( { bgiframe :true, modal :true, height :height, width :width, minHeight :200, minWidth: 500, position :'center', buttons : { "Ok" : function() { $(this).dialog('close'); } } }); $('#jQueryAlertContainer .js-messages').html(message); } Loading_Indicator.prototype.alertClose = function() { $("#jQueryAlertContainer").dialog('close'); } Loading_Indicator.prototype.openInNewTab = function(url) { var redirectWindow = window.open(url, '_blank'); redirectWindow.location; } Loading_Indicator.prototype.sessionExpired = function() { if (document.getElementById('session_expired')) { $('session_expired').remove(); } var height = height || 'auto'; var width = width || 'auto'; var wrapdiv = (document.createElement('div')); wrapdiv.id = "session_expired"; wrapdiv.title = "Warning"; var containerP = (document.createElement('p')); var iconSpan = (document.createElement('span')); iconSpan.className = "ui-icon ui-icon-alert"; $(iconSpan).css('float', "left"); $(iconSpan).css('pading', '5px'); $(iconSpan).css('margin', '0 7px 50px 0;'); containerP.appendChild(iconSpan); var textNode = document .createTextNode("Your session is expired. You need to login again."); containerP.appendChild(textNode); wrapdiv.appendChild(containerP); document.body.appendChild(wrapdiv); $("#session_expired").dialog( { bgiframe :true, modal :true, height :height, width :width, minHeight :150, position :'center', buttons : { Ok : function() { if (window.parent) { var href = window.parent.location.href; } else var href = window.location.href; setrawcookie('_redirect', href); window.open('index.php', '_self'); } } }); } Loading_Indicator = new Loading_Indicator(); function setrawcookie(name, value, expires, path, domain, secure) { // Send a cookie with no url encoding of the value // // version: 909.322 // discuss at: http://phpjs.org/functions/setrawcookie // + original by: Brett Zamir (http://brett-zamir.me) // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + derived from: setcookie // * example 1: setcookie('author_name', 'Kevin van Zonneveld'); // * returns 1: true if (expires instanceof Date) { expires = expires.toGMTString(); } else if (typeof (expires) == 'number') { expires = (new Date(+(new Date()) + expires * 1e3)).toGMTString(); } var r = [ name + "=" + value ], s = {}, i = ''; s = { expires :expires, path :path, domain :domain }; for (i in s) { s[i] && r.push(i + "=" + s[i]); } return secure && r.push("secure"), this.window.document.cookie = r .join(";"), true; } var shownAbout = false; function showAboutDialog() { if (!shownAbout) { $("#about_office").dialog({ bgiframe :false, modal :true, autoOpen: false, height :200, width :300, position :'center', show : 'blind' }); shownAbout = true; } $("#about_office").dialog('open'); } function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } function toggleEnable(buttonId, enable) { if (enable) { if ($("#" + buttonId).is('.ui-state-default')) { return; }; $("#" + buttonId).removeClass('ui-state-disabled'); $("#" + buttonId).addClass('ui-state-default'); } else { if ($("#" + buttonId).is('.ui-state-disabled')) { return; }; $("#" + buttonId).removeClass('ui-state-default'); $("#" + buttonId).addClass('ui-state-disabled'); } }; function currencyField( fieldRaw , fieldFormatted) { $(fieldFormatted).focus(function(){ $(this).hide(); $(fieldRaw).show().focus(); }); $( fieldRaw ).blur(function(){ var val = ''; if ($(this).val() != '') { val = parseFloat($(this).val()).toFixed(2); val = addCommas(val); } $(fieldFormatted).val( val ); $(this).hide(); $(fieldFormatted).show(); }); } function formatNumber(n, sep, decimals) { sep = sep || "."; // Default to period as decimal separator decimals = decimals || 2; // Default to 2 decimals return n.toLocaleString().split(sep)[0] + sep + n.toFixed(decimals).split(sep)[1]; }