/** * Code to run when the DOM is finished loading * Uses .ready from jQuery instead of document.onload * jQuery must be loaded before this file. */ $(document).ready(init); //global variables to track loaded objects/files etc GLOBAL_GRID_EXTENSIONS_LOADED = false; function init() { //works in IE only - look at removing window.defaultStatus = "Software Developed by Database Communications"; $("a").bind("mouseover",function() { window.status = "Software Developed by Database Communications"; }); if ($.browser.msie == true) { try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { //do nothing } } try{ //initaliase all calendars linked to fields with class="field-datepicker" initCalendars(); // Init the singleton. Any tag-based quick tips will start working. Ext.QuickTips.init(); // Apply a set of config properties to the singleton Ext.apply(Ext.QuickTips.getQuickTip(), { maxWidth: 300, minWidth: 50, showDelay: 0, trackMouse: true, dismissDelay: 0, hideDelay: 100 }); } catch(e) { //do nothing } } function initFlash() { //fix for latest IE versions to automatically activate Flash objects theObjects = document.getElementsByTagName("object"); for (var i = 0; i < theObjects.length; i++) { theObjects[i].outerHTML = theObjects[i].outerHTML; } } /** * Set focus on the first form element * in the specified form */ function setFormFocus($formId) { var bFound = false; // for each element in each form for(i=0; i < document.forms[$formId].length; i++) { // if it's not a hidden element if (document.forms[$formId][i].type != "hidden") { // and it's not disabled if (document.forms[$formId][i].disabled != true) { //and its empty if (document.forms[$formId][i].value == "") { // set the focus to it document.forms[$formId][i].focus(); bFound = true; } } } // if found in this element, stop looking if (bFound == true) break; } } /** * generates a random string * often used to force cache refresh in a URL */ function randomTime() { var now = new Date(); var serial = now.valueOf(); return serial; } /** * These functions are responsible for internal windows * * @param {Object} objWindow */ function openWindow(objWindow) { eval("openWin_"+objWindow+"()"); } function closeWindow(objWindow) { eval("win_"+objWindow+".hide()"); } /** * Check Browser * Values = msie, gecko, opera, safari?? */ function checkBrowser($browser) { // convert all characters to lowercase to simplify testing var agt=navigator.userAgent.toLowerCase(); if(agt.indexOf($browser) != -1) return true; else return false; } /** * Get inner window size * works across all browsers */ function getWindowSize($dimension) { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } if($dimension == "width") return myWidth; else return myHeight; } function reloadMain($url) { if($url != undefined) { top.document.getElementById('iframeMain').src = $url; } else { top.document.getElementById('iframeMain').src = top.document.getElementById('iframeMain').src; } } function reloadWindow($id, $url) { if($url != undefined) { top.getWindow($id).location = $url; } else { top.getWindow($id).location = top.getWindow($id).location; } } function reloadNav($url) { if($url != undefined) { top.iframeNav.document.getElementById('iframeTree').src = $url; } else { top.document.getElementById('iframeNav').src = top.document.getElementById('iframeNav').src; } } function reloadNavTree($url, $title) { if($url != undefined) { top.iframeNav.document.getElementById('iframeTree').src = $url; } else { top.iframeNav.document.getElementById('iframeTree').src = top.iframeNav.document.getElementById('iframeTree').src; } if($title != undefined) { top.iframeNav.document.getElementById('iframeTreeTitle').className = 'nav-header'; top.iframeNav.document.getElementById('iframeTreeTitle').innerHTML = $title; } } function showMessage($id, $message) { $('#'+$id).html('' + $message + ""); $('#'+$id).fadeOut(2500, function(){ $('#'+$id).html(" ").show() }); } /** * Trims whitespace from string */ function Trim (pStr) { var s = pStr.replace(/^\s*/, ''); s = s.replace(/\s*$/, ''); return s; } /** * Will create a new window with the content rendered * Great for debugging messages */ function debugWindow(content) { top.consoleRef=window.open('','myconsole','width=350,height=250,menubar=0,toolbar=1,status=0,scrollbars=1,resizable=1') top.consoleRef.document.writeln(content) top.consoleRef.document.close() } /** * Will get the form values from the specified form and return as * serialised object. This is a wrapper for the xajax.getFormValues() * so can only be used on Xajax pages. */ function getFormValues($formName, $form2, $form3, $form4, $form5, $form6) { $formdata1 = xajax.getFormValues($formName); if($form2 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata2 = xajax.getFormValues($form2); $formdata2 = $formdata2.replace("",""); $formdata1 = $formdata1 + $formdata2; } if($form3 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata3 = xajax.getFormValues($form3); $formdata3 = $formdata3.replace("",""); $formdata1 = $formdata1 + $formdata3; } if($form4 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata4 = xajax.getFormValues($form4); $formdata4 = $formdata4.replace("",""); $formdata1 = $formdata1 + $formdata4; } if($form5 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata5 = xajax.getFormValues($form5); $formdata5 = $formdata5.replace("",""); $formdata1 = $formdata1 + $formdata5; } if($form6 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata6 = xajax.getFormValues($form6); $formdata6 = $formdata6.replace("",""); $formdata1 = $formdata1 + $formdata6; } return $formdata1; } /** * A string replace function */ function str_replace($needle, $replacement, $haystack) { var $string = new String($haystack); $newstr = $string.replace($needle,$replacement); return $newstr; } function str_contains($needle, $haystack) { var pos=$haystack.indexOf($needle); if (pos>=0) { return pos } else { return false; } } // Returns true if the passed value is found in the // array. Returns false if it is not. function in_array($needle, $haystack) { var i; for (i=0; i < $haystack.length; i++) { // Matches identical (===), not just similar (==). if ($haystack[i] === $needle) { return true; } } return false; } function is_array(obj) { if (obj.constructor.toString().indexOf("Array") == -1) { return false; } else { return true; } } function is_object(obj) { if(obj instanceof Array) { return false; } else { return (obj !== null) && (typeof( obj ) == 'object'); } } function showMessageBox($message, $buttons, $function, $title, $modal, $width) { if($buttons == undefined) $buttons = Ext.Msg.OK; if($title == undefined) $title = 'Notice'; if($function == undefined) $function = false; if($modal == undefined) $modal = true; if($buttons == 'OK') { $buttons = Ext.Msg.OK; } else if($buttons == 'OKCANCEL') { $buttons = Ext.Msg.OKCANCEL; } else if($buttons == 'YESNO') { $buttons = Ext.Msg.YESNO; } //strip bad spaces $message = $message.replace(/\%20/g, " "); if($width == undefined) { Ext.Msg.show({ title: $title, msg: $message, buttons: $buttons, fn: $function, modal: $modal }); } else { Ext.Msg.show({ title: $title, msg: $message, buttons: $buttons, fn: $function, modal: $modal, width: $width }); } } /** * Prepare Xajax for any custom requests */ var xajaxRequestUri="/xajax/"; var xajaxDebug=false; var xajaxStatusMessages=false; var xajaxWaitCursor=true; var xajaxDefinedGet=0; var xajaxDefinedPost=1; var xajaxLoaded=false; // is dirty form functions var isDirty = 0; var custom_windowName = ''; function initDirtyCheck(formName,windowName) { if(Ext.isGecko) { $('input').bind('keyup', setDirty); $('textarea').bind('keyup', setDirty); } else { $('input').bind('change', setDirty); $('textarea').bind('change', setDirty); } $('select').bind('change', setDirty); if(top.windows[windowName]) { document.custom_windowName = windowName; } else { var window_type = windowName; document.custom_windowName = window_type.replace(/[0-9]/g,""); } } function checkIsDirty($window_name) { if( isDirty == 1 ) { top.windows[document.custom_windowName].show(); if(Ext.isIE6) { var $ICON_TYPE = 'gif'; } else { var $ICON_TYPE = 'png'; } showMessageBox("
You have not saved your changes. Are you sure you want to close this window?
","YESNO",customProcessDlg,'Warning!',true,280); return false; } else { return true; } } function customProcessDlg(option) { if( option=="yes" ) { isDirty = 0; top.destroyWindow(document.custom_windowName); } } function setDirty() { isDirty = 1; } function clearDirty() { isDirty = 0; } function format_currency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); } function format_number(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 transformDropdown($combo, $width, $list_width, $function, forceSelection) { if(forceSelection==undefined) { forceSelection=true; } var $dropdown = new Ext.form.ComboBox({ typeAhead: true, typeAheadDelay: 1000, triggerAction: 'all', transform: $combo, width: $width, forceSelection: forceSelection, listWidth: $list_width, id: 'ext-'+$combo }); $dropdown.on('select', $function); return $dropdown; } function setStrLength(string, maxlength) { if (string.length <= maxlength) { return string; } string = (string.substr(0, maxlength))+" ..." return string; } function reloadLoader($url) { if($url != undefined) { top.document.getElementById('iframeLoader').src = $url; } else { top.document.getElementById('iframeLoader').src = top.document.getElementById('iframeLoader').src; } } function printObject(obj) { var str = ""; for(prop in obj) { str+=prop + " value = "+ obj[prop]+"\n"; } alert(str); } function urlencode($string) { return encodeURIComponent($string); } function getFrame($name) { var $length = window.frames.length; for (var i=0; i < $length; i++) { if($.browser.msie) { $iframe = window.frames(i); } else { $iframe = frames[i]; } if($iframe.name == $name) { return $iframe; } } return false; } function reloadFrame($frame, $url) { $("iframe[name='"+$frame+"']").attr('src', $url); } var $searchfield_timeout; function createSearchField($field_id, $fn, $icon, $default_text) { var $field = $('#'+$field_id); $field.bind('keypress', function(event) { if(event.which == 13) { eval($fn); } }); $field.bind('keyup', function(event) { try { clearTimeout( $searchfield_timeout ); } catch(e) {} $searchfield_timeout = setTimeout('searchFieldLookup("'+$field_id+'",'+$fn+','+event.which+');',500); }); if($icon != undefined) { if(Ext.isIE) { var $icon_padding_top = 3; var $field_padding_left = 19; } else { var $icon_padding_top = 2; var $field_padding_left = 18; } var $div = '
'; $field.before($div); $field.addClass('field-input'); $field.css('padding-left', $field_padding_left); $field.css('padding-top', '2px'); $('#'+$field_id+'_icon').bind('click', function() { $('#'+$field_id).val(''); eval($fn); $('#'+$field_id).focus(); }); } if($default_text != undefined) { $field.css('color', '#CCC'); $field.val($default_text); $field.bind('focus', function() { $(this).css('color', '#000'); if($(this).val() == $default_text) { $(this).val(''); } }); } } function searchFieldLookup($field_id, $fn, $key) { var $str = ''; try { clearTimeout( $searchfield_timeout ); } catch(e) {} str = $('#'+$field_id).val(); try { if( $string.length > 2 || $key == 8 ) { eval($fn); } } catch(e) {} } function validateUrl($url) { if ((($url.indexOf("http://")==0) || ($url.indexOf("https://")==0) || ($url.indexOf("ftp://")==0) || ($url.indexOf("mailto:")==0)) && ($url.length>8)) { return true; } else { return false; } } function ajaxSaveGridPreference($grid_name, $type, $columnNumber, $changedValue) { var args = new Array(); args[0] = "Ajax_Preferences"; args[1] = $grid_name, args[2] = $type; args[3] = $columnNumber; args[4] = $changedValue; xajax.call("ajaxSaveGridPreferences", args, 1); } function ucfirst($words, $strip_extra) { if($strip_extra != false) { $words = str_replace('-', ' ', $words); $words = str_replace('_', ' ', $words); } // Split the string into words if string contains multiple words. var x = $words.split(/\s+/g); for (var i = 0; i < x.length; i++) { var parts = x[i].match(/(\w)(\w*)/); x[i] = parts[1].toUpperCase() + parts[2].toLowerCase(); } // Rejoin the string and return. return x.join(' '); } function buildToolbar($container) { var $tbar = []; Ext.get($container).select('>li').each( function() { var html = this.dom.innerHTML; //check for separator if(html == "") { var currentItem = '-'; $tbar.push(currentItem); } else { //normal menu link var link = this.child('a', true); var link_html = link.innerHTML //check for icon try{ var image = this.child('img:first', true); var icon = image.src; if(link_html == "") { var classname = 'x-btn-icon'; } else { var classname = 'x-btn-text-icon'; } } catch(e) { var icon = ""; var classname = 'x-btn-text' } if(link.className == 'disabled') { $disabled = true; } else { $disabled = false; } if(link.className == 'hidden') { $hidden = true; } else { $hidden = false; } var currentItem = { text: link.innerHTML, cls: classname, icon: icon, id: link.id, tooltip: link.title, handler: evalHandler(link.href), menu: eval(link.target), disabled: $disabled, hidden: $hidden }; $tbar.push(currentItem); } }); return $tbar; } function addslashes($string) { $string = $string.replace(/\\/g,'\\\\'); $string = $string.replace(/\'/g,'\\\''); $string = $string.replace(/\0/g,'\\0'); //$string = $string.replace(/\"/g,'\\\"'); return $string; }