var http; var divname; var alertOptions = {}; //---------------------------------------------------------------------- // Service wide javascript //---------------------------------------------------------------------- $(document).ready(function() { // if the sidebar is empty.. hide it. hide_empty_sidebar(); // Show the help slider if(typeof $.fn.tabSlideOut == 'function'){ $('#help-div').tabSlideOut({ tabHandle: '.handle', //class of the element that will become your tab pathToTabImage: '/i/tpl/tabs/help_tab.png', //path to the image for the tab //Optionally can be set using css imageHeight: '194px', //height of tab image //Optionally can be set using css imageWidth: '62px', //width of tab image //Optionally can be set using css tabLocation: 'left', //side of screen where tab lives, top, right, bottom, or left speed: 300, //speed of animation action: 'click', //options: 'click' or 'hover', action to trigger animation topPos: '210px', //position from the top/ use if tabLocation is left or right leftPos: '20px', //position from left/ use if tabLocation is bottom or top fixedPosition: false //options: true makes it stick(fixed position) on scroll }); } if(typeof $.fn.livequery == 'function'){ // activate help links livequery // will automatically update links, even if they // are added using ajax $("a.tippable:not(.cluetip)").livequery(function() { $(this).cluetip({ width: $(this).attr("cstyle") == "wide" ? 800 : 400, sticky: true, positionBy: 'bottomTop', closePosition: 'title', activation: 'click', arrows: true }); }); // format all numeric fields $(document).find("input.numeric:not(.inited)").livequery(function() { $(this).numeric({ allow:"." }).bind("blur", function() { $(this).formatCurrency({ showZero: false }); }) }); // format all percent fields $(document).find("input.percent:not(.inited)").livequery(function() { $(this).numeric({ allow:"." }).bind("blur", function() { $(this).formatCurrency({ symbol: '', showZero: false }); }) }); // format all integer fields $(document).find("input.integer:not(.inited)").livequery(function() { $(this).numeric(); }); // force all the numeric fields to format their values $(document).find("input.numeric:not(.inited),input.integer:not(.inited),input.percent:not(.inited)").each(function() { $(this).addClass("inited"); $(this).blur(); }); } if(typeof $.fn.autocomplete == 'function'){ $("#tagsearch").autocomplete("/tagquery", { width: 320, max: 100, highlight: false, scroll: true, scrollHeight: 240, cacheLength: 10, multiple: false, extraParams : { refs: 1, zero: 1 }, formatItem: function(data, i, n, value) { return value.split(",")[0]; }, formatResult: function(data, value) { return value.split(",")[0]; } }); } // make sure the body is at least 500 pixels high var cpage = $("body"); if (cpage.height() < 500) { cpage.css("height", "500px"); cpage.css("overflow", "visible"); } // run afterReady if it exists if (typeof(afterReady) != "undefined"){ if (typeof(afterReady) == "function") { afterReady(); } } // and we're out }); //---------------------------------------------------------------------- function sprintf () { var i = 0, a, f = arguments[i++], o = [], m, p, c, x; while (f) { if (m = /^[^\x25]+/.exec(f)) o.push(m[0]); else if (m = /^\x25{2}/.exec(f)) o.push('%'); else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) { if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments."); if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) throw("Expecting number but found " + typeof(a)); switch (m[7]) { case 'b': a = a.toString(2); break; case 'c': a = String.fromCharCode(a); break; case 'd': a = parseInt(a); break; case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break; case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break; case 'o': a = a.toString(8); break; case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break; case 'u': a = Math.abs(a); break; case 'x': a = a.toString(16); break; case 'X': a = a.toString(16).toUpperCase(); break; } a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a); c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' '; x = m[5] - String(a).length; p = m[5] ? str_repeat(c, x) : ''; o.push(m[4] ? a + p : p + a); } else throw ("Huh ?!"); f = f.substring(m[0].length); } return o.join(''); } //---------------------------------------------------------------------- function hide_empty_sidebar(){ var obj = $('#cside'); if (obj && obj.html()) { if (obj.html().replace(/^\s+|\s+$/g,"") == ''){ obj.css("display", "none"); obj.width($('#pagetitle').width()); } } } //---------------------------------------------------------------------- function extwrite(message) { document.write(message); } //---------------------------------------------------------------------- function createRequestObject() { var req = false; if (window.XMLHttpRequest) { // native XMLHttpRequest object try { req = new XMLHttpRequest(); } catch (e) { req = false; } } else if (window.ActiveXObject) { // IE/Windows ActiveX version try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } } } return req; } //---------------------------------------------------------------------- function replaceDiv_response() { if (http.readyState == 4){ var response = http.responseText; $(divname).innerHTML = response; } } //---------------------------------------------------------------------- function replaceDiv(name, url) { divname = name; http = createRequestObject(); http.onreadystatechange = replaceDiv_response; http.open('GET', url); http.send(null); return false; } //---------------------------------------------------------------------- function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); } //---------------------------------------------------------------------- function ltrim(stringToTrim) { return stringToTrim.replace(/^\s+/,""); } //---------------------------------------------------------------------- function rtrim(stringToTrim) { return stringToTrim.replace(/\s+$/,""); } //---------------------------------------------------------------------- function replace(value, from, to) { return value.replace(from,to); } //---------------------------------------------------------------------- function numeric_cleanup( value ) { return replace(value, /[^0-9\.]/, ''); } //---------------------------------------------------------------------- // open a passive notification //---------------------------------------------------------------------- function growl( settings ) { var options = { closer: false, check: 1000, life: 3000, theme: '', content: "No message provided" } // if passed a string, make options object if (typeof(settings) == "string") { options.content = settings; } else { // copy their settings into options for( var i in settings ) { options[i] = settings[i]; } } $.jGrowl( options.content, { header: (options.title) ? options.title : '', closer: false, check: 1000, life: 3000, theme: options.theme } ); } //---------------------------------------------------------------------- // open a passive notification // { // save: true | false, // close: true | false, // onSave: function // onClose: function // content: any content to show in the box // timeout: # of ms to stay open before closing automatically // focusAfter: selector to pass focus to after close (requires timeout) // // Note: if close and save buttons are hidden, footer hides // automatically unless footer is TRUE // //---------------------------------------------------------------------- function alertBox( settings ) { alertOptions = { confirm: false, overlay: true, // show the curtain? opacity: 0.5, save: false, // hide save button close: true, // hide close button footer: false, // hide footer klass: '', // layout class that defines th size onConfirm: null, // after-confirm event onSave: null, // after-save event onClose: null, // after-close event beforeReveal: null, // before-open event timeout: 3000, // timeout timer in milliseconds content: '' // content to show } // if passed a string, make options object if (typeof(settings) == "string") { alertOptions.content = settings; } else { // copy their settings into options for( var i in settings ) { alertOptions[i] = settings[i]; } } // ensure mutual exclusivity and save has // precedence over confirm if (alertOptions.save == true) { alertOptions.confirm = false; } // map our options into facebox $.extend($.facebox.settings, alertOptions); // handle reveal event $(document).bind('reveal.facebox', function() { // before show if (alertOptions.beforeReveal) { alertOptions.beforeReveal($("#facebox .content")); } // hide save? $("#facebox .save").css({ display: (alertOptions.save) ? 'block' : 'none', visibility: (alertOptions.save) ? 'visible' : 'hidden' }); // setup onsave event if (alertOptions.onSave) { $(document).unbind("save.facebox"); $(document).bind('save.facebox', function() { if (alertOptions.onSave) { alertOptions.onSave($("#facebox")); } }); } // hide or show confirm $("#facebox .confirm").css({ display: (alertOptions.confirm) ? 'block' : 'none', visibility: (alertOptions.confirm) ? 'visible' : 'hidden' }); $(document).bind('confirm.facebox', function() { // remove the timer $(document).stopTime("alertTimeout"); // optionally callback if (alertOptions.onConfirm) { alertOptions.onConfirm($("#facebox")); } }); // hide close? $("#facebox .close").css({ display: (alertOptions.close) ? 'block' : 'none', visibility: (alertOptions.close) ? 'visible' : 'hidden' }); $(document).bind('close.facebox', function() { // remove the timer $(document).stopTime("alertTimeout"); // optionally callback if (alertOptions.onClose) { alertOptions.onClose($("#facebox")); } }); // hide footer if ((typeof(alertOptions.footer) == "undefined" || alertOptions.footer == false) && (alertOptions.save == true || alertOptions.close == true)) { alertOptions.footer = true; } $("#facebox .footer").css({ display: (alertOptions.footer) ? 'block' : 'none', visibility: (alertOptions.footer) ? 'visible' : 'hidden' }); // if timeout is specified if (alertOptions.timeout !== false && alertOptions.timeout != null) { $(document).oneTime(parseInt(alertOptions.timeout), "alertTimeout", function() { // remove the timer $(document).stopTime("alertTimeout"); // close the box $.facebox.close(); // focus if asked to $(alertOptions.focusAfter).focus(); }); } }); if (alertOptions.klass != "") { $.facebox(alertOptions.content, alertOptions.klass); } else { $.facebox(alertOptions.content); } } //---------------------------------------------------------------------- function searchTags( value ) { var newValue = replace(value, /"/g, '"'); newValue = replace(newValue, /'/g, '&squot;'); VS_Ajax_Search.do_search({ keywords: newValue }, { "content_type": "json", 'onFinish' : function(response) { // clear the body if (response.status == "OK") { window.location = response.redirect_to; } else { alertBox({ content: response.message, save: false, timeout: null }); } }}); } //---------------------------------------------------------------------- function showLoader( parent, bshow ) { if ($("div#loader").length == 0) { alertBox("No loader control on this page."); return false; } if (bshow == true) { $(parent).prepend($("div#loader").clone()); $(parent).find("div#loader").removeClass("hidden"); $(parent).find("div#loader #image").each(function() { var width = $(parent).find("div#loader:first").width(); var height = $(parent).find("div#loader:first").height(); //var iwidth = $(this).find("div#loader #image").width(); //var iheight = $(this).find("div#loader #image").height(); $(this).css({ left: (width / 4) + "px", top: (height / 4) + "px" }); $(this).attr("width", Math.round(width / 2)); $(this).attr("height", Math.round(height / 2)); }); } else { $(parent).find("div#loader").remove(); } return false; } //---------------------------------------------------------------------- function myencode( val ) { var xx = val.replace(/\"/g, '\\\"'); var xx = xx.replace(/(.)[\n\r]+/g, "$1
"); return xx; } //---------------------------------------------------------------------- function delay_keycheck( delay, target, container, callback ) { var name = target; if (!name) { alertBox({ timeout: null, content: 'Fatal Error : A call to delay_keycheck was made on an input with no id!' }); } else { name = name + "_delay_keycheck"; $(document).stopTime(name); $(document).oneTime(delay, name, function() { showLoader(container, true); if (callback) { callback(target, container); } }); } } //---------------------------------------------------------------------- function gotoURL( url ) { window.location.href = url; return false; }