/*#region Error Handler */ // Record client side errors in the database's ErrorLog table. // If displayErrorPage is set to true, either the timeout or standard error page will be displayed. function recordClientError(errorMessage, occurredIn, comments, displayErrorPage) { var showErrorPage = true; if (typeof displayErrorPage !== 'undefined') { showErrorPage = displayErrorPage; } try { $.ajax({ url: '/Error/RecordClientError', type: 'post', dataType: 'json', cache: false, data: { errorMessage: errorMessage, occurredIn: occurredIn, comments: comments } }); } catch (ex) { } try { if (showErrorPage) { if (errorMessage.indexOf('timeout') > -1) { $.ajax({ url: '/Error/ShowErrorTimeoutPage', type: 'get', dataType: 'html', cache: false, success: function (response, status, XMLHttpRequest) { $('section.ui-content-Override').html(response); $('section.ui-content-Override').trigger('create'); } }); } else { $.ajax({ url: '/Error/ShowErrorPage', type: 'get', dataType: 'html', cache: false, success: function (response, status, XMLHttpRequest) { $('section.ui-content-Override').html(response); $('section.ui-content-Override').trigger('create'); } }); } } } catch (ex) { } } /*#endregion */ /*#region Session Storage */ // The following functions use session storage if the browser supports it or a cookie // DEPENDENCIES: jquery; jquery.cookie.js; json2.js; // Stores a key value pair. function SetSessionData(key, value) { if (('sessionStorage' in window) && window.sessionStorage !== null) { sessionStorage[key] = value; } else { $.cookie(key, value, { path: '/' }); } } // Retrieves a value. function GetSessionData(key) { if (('sessionStorage' in window) && window.sessionStorage !== null) { return sessionStorage[key]; } else { return $.cookie(key); } } // Removes the specified item. function RemoveSessionData(key) { if (('sessionStorage' in window) && window.sessionStorage !== null) { sessionStorage.removeItem(key); } else { return $.cookie(key, null); } } // Converts the object to JSON then stores it. function SetSessionObject(key, value) { var stringValue = JSON.stringify(value); if (('sessionStorage' in window) && window.sessionStorage !== null) { sessionStorage[key] = stringValue; } else { $.cookie(key, stringValue, { path: '/' }); } } // Gets a stored object converted to string and converts it back into an object. function GetSessionObject(key) { if (('sessionStorage' in window) && window.sessionStorage !== null) { return JSON.parse(sessionStorage.getItem(key)); } else { return JSON.parse($.cookie(key)); } } // Clears all stored data from local storage if the browser supports it or deletes all cookies. // WARNING: Use with caution, will destroy forms authentication cookies as well. function ClearSessionData() { if (('sessionStorage' in window) && window.sessionStorage !== null) { sessionStorage.clear(); } else { if ((document.cookie !== null) && (document.cookie !== "")) { var cookies = document.cookie.split('; '); for (var i = cookies.length; i > 0; i--) { var parts = cookies[i - 1].split('='); $.cookie(parts[0], null); } } } } /*#endregion */ /*#region Persistent Storage */ // The following functions use local storage if the browser supports it or a cookie. // WARNING: Use this only for persistent storage!! Use session methods above for all others! // DEPENDENCIES: jquery; jquery.cookie.js; json2.js; // Stores a key value pair. function SetPersistentData(key, value) { if (('localStorage' in window) && window.localStorage !== null) { localStorage[key] = value; } else { $.cookie(key, value, { expires: 30, path: '/' }); } } // Retrieves a value. function GetPersistentData(key) { if (('localStorage' in window) && window.localStorage !== null) { return localStorage[key]; } else { return $.cookie(key); } } // Removes the specified item. function RemovePersistentData(key) { if (('localStorage' in window) && window.localStorage !== null) { localStorage.removeItem(key); } else { return $.cookie(key, null); } } // Converts the object to JSON then stores it. function SetPersistentObject(key, value) { var stringValue = JSON.stringify(value); if (('localStorage' in window) && window.localStorage !== null) { localStorage[key] = stringValue; } else { $.cookie(key, stringValue, { expires: 30, path: '/' }); } } // Gets a stored object converted to string and converts it back into an object. function GetPersistentObject(key) { if (('localStorage' in window) && window.localStorage !== null) { return JSON.parse(localStorage.getItem(key)); } else { return JSON.parse($.cookie(key)); } } // Clears all stored data from local storage if the browser supports it or deletes all cookies. // WARNING: Use with caution, will destroy forms authentication cookies as well along with session cookies. function ClearPersistentData() { if (('localStorage' in window) && window.localStorage !== null) { localStorage.clear(); } else { if ((document.cookie !== null) && (document.cookie !== "")) { var cookies = document.cookie.split('; '); for (var i = cookies.length; i > 0; i--) { var parts = cookies[i - 1].split('='); $.cookie(parts[0], null); } } } } /*#endregion */ /*#region Cookie Storage */ // The following functions use session cookie storage only for transmittal between client and server. // DEPENDENCIES: jquery; jquery.cookie.js; json2.js; // Stores a key value pair. function SetCookie(key, value) { $.cookie(key, value, { path: '/' }); } // Retrieves a value. function GetCookie(key) { return $.cookie(key); } // Removes the specified item. function RemoveCookie(key) { return $.cookie(key, null); } // Converts the object to JSON then stores it. function SetCookieObject(key, value) { var stringValue = JSON.stringify(value); $.cookie(key, stringValue, { path: '/' }); } // Gets a stored object converted to string and converts it back into an object. function GetCookieObject(key) { return JSON.parse($.cookie(key)); } // Clears all stored data from local storage if the browser supports it or deletes all cookies. // WARNING: Use with caution, will destroy forms authentication cookies as well. function ClearCookies() { if ((document.cookie !== null) && (document.cookie !== "")) { var cookies = document.cookie.split('; '); for (var i = cookies.length; i > 0; i--) { var parts = cookies[i - 1].split('='); $.cookie(parts[0], null); } } } /*#endregion */ /*#region Common Functions */ // Returns the current formatted date. function GetDate() { var date = new Date(); var day = date.getDate(); var mon = date.getMonth() + 1; // Months are 0 based. var yr = date.getFullYear(); var curDate = mon + '/' + day + '/' + yr; return curDate; } // Returns the current formatted time. function GetTime() { var date = new Date(); var hour = date.getHours(); var min = date.getMinutes(); var ampm = 'AM'; if (hour >= 12) { ampm = 'PM'; } if (hour > 12) { hour = hour - 12; } var curTime = hour + ':' + min + ' ' + ampm; return curTime; } //Formats to currency with two decimal places function FormatCurrency(amount) { var i = parseFloat(amount); if (isNaN(i)) { i = 0.00; } var minus = ''; if (i < 0) { minus = '-'; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if (s.indexOf('.') < 0) { s += '.00'; } if (s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s; return s; } /*#endregion */ /// /// /// /*#region Global Variables, Constants, & Initializers */ // Global jQuery Ajax setup. $.ajaxSetup({ timeout: 20000 }); $.watermark.options.useNative = false; // Set this or some browsers will not work properly. $(function () { //Highlight the active menu link HighlightActiveMenuItem(); //add click event to privacy policy link to open in a new window $('#PrivacyPolicyLink').click(function () { window.open('/Company/PrivacyPolicy', 'PrivacyPolicy', 'height=600px,width=1000px,scrollbars=yes'); }); }); //highlights the links for the navigation function HighlightActiveMenuItem() { //remove the active-menu class from the navigation $('#nav').find('.active-menu').removeClass('active-menu'); var url = location.pathname if (url.substring(url.length - 1) == '/') { url = url.substring(0, url.length - 1)//remove any trailing backslashes } var page = url.split('/')[url.split('/').length - 1];//get the last segment of the url if (page == '') {//add the active-menu class for highlighting the current page $('#nav').find('a:first').addClass('active-menu'); } else { $('#nav a[href$=' + page + ']').addClass('active-menu'); $('.nav a[href$=' + page + ']').addClass('active'); } //highlight the customer portal link when in the customer portal if (url.indexOf('CustomerPortal') > 0) { $('#nav a[href$="CustomerPortal"]').addClass('active-menu'); //check to see if we need to highlight the summary page navigation link if (page == 'CustomerPortal' || page == 'Home') { $('#CustomerPortalNav ul.nav li:first a').addClass('active'); } } } //show an alert for browsers that are not supported function HandleUnsupportedBrowserAlert(isUnsupportedBrowser) { var showAlert = isUnsupportedBrowser; //show alert is true if (showAlert == 'true' || showAlert == true) { $('#UnsupportedBrowserContainer').show('slow'); $('.supported-browser').hide(); } else { $('#UnsupportedBrowserContainer').hide(); } }; //show a loading spinner for table data function ShowDataLoading() { $('.table-data-loading').show(); }; //show a loading spinner for table data function HideDataLoading() { $('.table-data-loading').hide(); }; var imgCache = []; //Finally, preload the images. Note I’m doing both large and small images here but you’ll be able to cut it down to just the images: // Preload all menu images. function PreloadImages() { // Just need to do this once. if (imgCache.length > 0) { return false; } imgCache = []; for (var i = 0; i < imgs.length; i++) { var cacheImage = document.createElement('img'); cacheImage.src = imgs[i].src; imgCache.push(cacheImage); } }; //show a modal dialog for loading with a spinner function ShowLoadingDialog(message) { //assign empty value to message if it is undefined if (IsUndefined(message)) { message = ''; } //insert the message into the modal loading dialog $('#ModalLoadingDialogMessage').html(message); //show the modal loading dialog $('#ModalLoadingDialog').modal('show'); }; //hide a modal dialog for loading with a spinner function HideLoadingDialog() { $('#ModalLoadingDialog').modal('hide'); }; //return true if the aurgument is undefined function IsUndefined(variable) { var isUndefined = false; if (typeof (variable) == 'undefined') { isUndefined = true; } return isUndefined; }; function FormatCurrency(amount) { var i = parseFloat(amount); if (isNaN(i)) { i = 0.00; } var minus = ''; if (i < 0) { minus = '-'; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if (s.indexOf('.') < 0) { s += '.00'; } if (s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s; return s; }; /*#endregion */ function PostJson(url, postData, timeout) { var self = this; self.returnData = ''; var postJson = $.ajax({ url: url, type: 'POST', dataType: 'json', data: postData, contentType: 'application/json; charset=utf-8', timeout: timeout || 10000 }); return postJson; }