// // NHLS Javascript // Based on Mootools library framework // $Id$ // var NHLSCore = new Class( { Implements: [Options,Events], options: { base_url: "", current_tab: "", display_mode: "", action_dispatch: "", ajaxResponse: "", ajaxResponseXML: "", fixedActionDispatch: "", moduleObject: "", displayMode: "min", subDisplayMode: "list", suppressDisplay: "false" }, /** * Initialize the core, sets the options * @param Set of options defined in the header */ initialize: function( options ) { this.setOptions( options ); }, /** * Initializes the Helper() system for writing * help text bubbles next to input items */ initHelperSys: function() { // // Called from the module class, only as needed var openForHelpers = $$('div.helperText'); if( openForHelpers && openForHelpers.length > 0 ) { var languageObj = new Language(); openForHelpers.each( function(el) { // // Need to inject the helper image if( Browser.Engine.trident && Browser.Engine.version == 4 ) { var helperElement = new Element( 'img', { 'src': 'resources/images/forms/help.gif', 'class' : 'helperImage', 'title' : languageObj.getString(el.id) }); } else { var helperElement = new Element( 'img', { 'src': 'resources/images/forms/help.png', 'class' : 'helperImage', 'title' : languageObj.getString(el.id) }); } // // Inject at the end of the DIV helperElement.inject(el); //delete helperElement; }); var helperImages = $$('img.helperImage'); if( helperImages && helperImages.length > 0 ) { var myTips; if( Browser.Engine.trident ) { myTips = new Tips(helperImages, { className: 'helperImageText', offsets: {'x':-9, 'y':-52}, onShow: function(tip) { tip.setStyle('opacity','0.9') } }); } else { myTips = new Tips(helperImages, { className: 'helperImageText', offsets: {'x':-8, 'y':-42}, onShow: function(tip) { tip.setStyle('opacity','0.9') } }); } } } }, /** * Initializes the Module object * @param The object to extend * @deprecated */ initModule: function( modObject ) { this.options.moduleObject = modObject; $extend( this, this.options.moduleObject ); }, /** * Dynamically includes Javascript and init's the modules * Works in Firefox, but has cache issues with IE * @deprecated */ dispatch: function() { // // Get the action var fullURI = window.location.href; var actionURI = ( fullURI.substring( ( fullURI.indexOf( this.options.base_url ) + this.options.base_url.length ), fullURI.length ) ); this.options.action_dispatch = actionURI.split(".")[0]; delete fullURI; delete actionURI; // // Empty? if( !this.options.action_dispatch ) { this.options.action_dispatch = 'publicWelcome'; } // // Inject into head $(document).getElement("head").appendChild( new Element( 'script', { 'src': 'resources/javascripts/modules/'+this.options.action_dispatch+'.js', 'type': 'text/javascript', 'language': 'javascript' }), 'top' ); // // Capitalize the first letter to match the INIT call /* this.options.fixedActionDispatch = ( ( "this.init" ) + ( this.options.action_dispatch.charAt(0).toUpperCase() ) + ( this.options.action_dispatch.slice(1) ) ); // // Call the INIT // Don't want to do it like this, // but IE has another problem as usual if( eval( "typeof "+this.options.fixedActionDispatch+" =='function'" ) ) { eval(this.options.fixedActionDispatch+"()"); }*/ }, /** * Tries to center an HTML element using window coords * @param The element ID of the container that needs to be centered */ centerElement: function( el ) { // // Get the HV pos var elCoords = $(el).getCoordinates(); var elLeft = ( ( window.getWidth() - elCoords['width'] ) /5 ); var elTop = ( ( window.getHeight() /4 ) - elCoords['height'] ); // // Set the values $(el).setStyle( 'left', elLeft ).setStyle( 'top', elTop ); }, /** * Switches the upper level tab menu to the correct tab * based on the String in this.options.current_tab */ switchCurrentTab: function() { // // Figure out which tab is active // if( this.options.current_tab != '' ) { // // Set the class to blank, reset tab class to normal // if( $('tabHome') ) { $('tabHome').setProperty('class', ""); $('tabDivHome').setProperty('class', "navLeftCorner"); } if( $('tabActive') ) { $('tabActive').setProperty('class', ""); $('tabDivActive').setProperty('class', "navLeftCorner"); } if( $('tabLocator') ) { $('tabLocator').setProperty('class', ""); $('tabDivLocator').setProperty('class', "navLeftCorner"); } if( $('tabHouse') ) { $('tabHouse').setProperty('class', ""); $('tabDivHouse').setProperty('class', "navLeftCorner"); } if( $('tabReport') ) { $('tabReport').setProperty('class', ""); $('tabDivReport').setProperty('class', "navLeftCorner"); } // // Not always present if( $('tabReferral') ) { $('tabReferral').setProperty('class', ""); $('tabDivReferral').setProperty('class', "navLeftCorner"); } if( $('tabAdmin') ) { $('tabAdmin').setProperty('class', ""); $('tabDivAdmin').setProperty('class', "navLeftCorner"); } // //DCM tabs if( $('tabDCMHome') ) { $('tabDCMHome').setProperty('class', ""); $('tabDivDCMHome').setProperty('class', "navLeftCorner"); } if( $('tabDCMManage') ) { $('tabDCMManage').setProperty('class', ""); $('tabDivDCMManage').setProperty('class', "navLeftCorner"); } if( $('tabDCMPropList') ) { $('tabDCMPropList').setProperty('class', ""); $('tabDivDCMPropList').setProperty('class', "navLeftCorner"); } if( $('tabDCMDownload') ) { $('tabDCMDownload').setProperty('class', ""); $('tabDivDCMDownload').setProperty('class', "navLeftCorner"); } if( $('tabDCMReport') ) { $('tabDCMReport').setProperty('class', ""); $('tabDivDCMReport').setProperty('class', "navLeftCorner"); } if( $('tabDCMUser') ) { $('tabDCMUser').setProperty('class', ""); $('tabDivDCMUser').setProperty('class', "navLeftCorner"); } if( $('tabDCMEmail') ) { $('tabDCMEmail').setProperty('class', ""); $('tabDivDCMEmail').setProperty('class', "navLeftCorner"); } if( $('tabDCMScheduler') ) { $('tabDCMScheduler').setProperty('class', ""); $('tabDivDCMScheduler').setProperty('class', "navLeftCorner"); } switch (this.options.current_tab) { case 'doInit': default: $('tabHome').setProperty('class', 'current'); $('tabDivHome').setProperty('class', "navLeftCornerCurrent"); break; case 'doActive': $('tabActive').setProperty('class', 'current'); $('tabDivActive').setProperty('class', "navLeftCornerCurrent"); break; case 'doLocator': $('tabLocator').setProperty('class', 'current'); $('tabDivLocator').setProperty('class', "navLeftCornerCurrent"); break; case 'doHouse': $('tabHouse').setProperty('class', 'current'); $('tabDivHouse').setProperty('class', "navLeftCornerCurrent"); break; case 'doReport': $('tabReport').setProperty('class', 'current'); $('tabDivReport').setProperty('class', "navLeftCornerCurrent"); break; case 'doReferral': $('tabReferral').setProperty('class', 'current'); $('tabDivReferral').setProperty('class', "navLeftCornerCurrent"); break; case 'doAdmin': // // We may be on the login page if( $('tabAdmin') ) { $('tabAdmin').setProperty('class', 'current'); $('tabDivAdmin').setProperty('class', "navLeftCornerCurrent"); } break; // //DCM tabs case 'doDCMHome': if( $('tabDCMHome') ) { $('tabDCMHome').setProperty('class', 'current'); $('tabDivDCMHome').setProperty('class', "navLeftCornerCurrent"); } break; case 'doDCMManage': if( $('tabDCMManage' ) ) { $('tabDCMManage').setProperty('class', 'current'); $('tabDivDCMManage').setProperty('class', "navLeftCornerCurrent"); } break; case 'doDCMPropList': $('tabDCMPropList').setProperty('class', 'current'); $('tabDivDCMPropList').setProperty('class', "navLeftCornerCurrent"); break; case 'doDCMDownload': $('tabDCMDownload').setProperty('class', 'current'); $('tabDivDCMDownload').setProperty('class', "navLeftCornerCurrent"); break; case 'doDCMReport': $('tabDCMReport').setProperty('class', 'current'); $('tabDivDCMReport').setProperty('class', "navLeftCornerCurrent"); break; case 'doDCMUser': $('tabDCMUser').setProperty('class', 'current'); $('tabDivDCMUser').setProperty('class', "navLeftCornerCurrent"); break; case 'doDCMEmail': $('tabDCMEmail').setProperty('class', 'current'); $('tabDivDCMEmail').setProperty('class', "navLeftCornerCurrent"); break; case 'doDCMScheduler': $('tabDCMScheduler').setProperty('class', 'current'); $('tabDivDCMScheduler').setProperty('class', "navLeftCornerCurrent"); break; } } }, /** * Function is called in header if IE, to fix a lag issue */ removeLoadingOverlay: function() { if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', 'none' ); } }, /** * Sends the resource locator form * @TODO Needs to be moved into a module * @param Name of the form to be sent * @param The Struts command variable * @param An array of Element ID's that are required for the form to be submitted */ sendForm: function( form, cmd, required ) { var submit = true; if( form == 'resourceForm' ) { if( $('tmp').checked ) { // // Searching by county var fields = new Array('state2','county','radius1','radius2'); } else { // // Searching by address var fields = new Array('state','address','city','zip','radius1','radius2'); } } else { fields = required; } if( $type( fields ) == 'array' ) { fields.each( function( field ) { if( $(field).value == '' || $(field).value == '#' ) { submit = false; } }); } if( submit ) { $( form ).cmd.value = cmd; $( form ).submit(); } else { alert( 'Please fill out all required elements.' ); } }, /** * Helper function to open an inline frame * @param Iframe ID * @param The URL to be opened in the Iframe */ openIframe: function( iId, url ) { $( iId ).src = url; }, /** * Helper function that opens an outside URL with a warning message * @param The URL that needs to be accessed */ openUrl: function( url ) { if( url != null ) { if(confirm("You have requested a document that is external to HUD's World Wide Website. HUD cannot attest to the accuracy of information provided by linked sites. Linking to a website does not constitute an endorsement by HUD, or any of its employees, of the sponsors of the site or the products presented on the site.")){ window.open(url); } } }, /** * Function takes two arrays and toggles each element in the array * to its opposite display state ( show becomes hidden, hidden becomes show ) * @param Array of Element ID's that need to be turned "on" * @param Array of Element ID's that need to be turned "off" */ toggleDisplay: function( divOn, divOff ) { if( $type( divOn ) != "array" || $type( divOff ) != "array" ) { return null; } divOn.each( function(el) { $( el ).setStyle( "display", "block" ); }); divOff.each( function(el2) { if ($(el2)) { $( el2 ).setStyle( "display", "none" ); } }); }, /** * Similar to toggleDisplay, but takes a single Div and flips it's display state * Works best with elements defined with a + - icon * @param Element ID to be manipulated * @see toggleDisplay() */ toggleDiv: function( divId ) { if ($(divId).style.display == "block" || $(divId).style.display =="" ) { $(divId).style.display = "none"; if( $(divId+"-icon") ) { $(divId+"-icon").src = "resources/images/bullet_toggle_plus.png"; } // // IE problem if( ( Browser.Engine.trident && Browser.Engine.version == 4 ) && divId.test("assist-search") ) { $('selectedCountiesList').setStyle("display", ""); } } else { $(divId).style.display = "block"; if( $(divId+"-icon") ) { $(divId+"-icon").src = "resources/images/bullet_toggle_minus.png"; } // // IE problem if( ( Browser.Engine.trident && Browser.Engine.version == 4 ) && divId.test("assist-search") ) { $('selectedCountiesList').setStyle("display", "none"); } } }, /** * Main AJAX function. Executes AJAX action, populates container and flips * the AJAX loading dialog on and off automatically * @param The URL to be accessed via AJAX * @param Element ID of the container to be updated by the * Ajax return * @param If using a Comments style template Div, this will flip the * wrapper "on" and give it a drag handle * @param If using a custom AJAX loading string, give the element ID of the * custom loader here * @see AjaxCallBack() */ AjaxRequest: function( actionUrl, updateContainer, showWrapper, customLoader ) { // // Build the full URL if( actionUrl.test("http") ) { var xml_request = actionUrl; } else { var xml_request = this.options.base_url + actionUrl; } // // Pop the loading screen if( $(customLoader) ) { $( customLoader ).setStyle( 'display', '' ); } else if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', '' ); this.centerElement('ajax-loader'); } var Ajax = new Request( { url: xml_request, method: 'get', headers: { 'If-Modified-Since': 'Sat, 1 Jan 2000 00:00:00 GMT' }, update: $( updateContainer ), onSuccess: function( responseText, responseXML ) { if( $(customLoader) ) { $( customLoader ).setStyle( 'display','none'); } else if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', 'none' ); } // // Update the inner html if( $(updateContainer) && ( NHLS.options.suppressDisplay == "false" ) ) { $(updateContainer).set('html', responseText ).setStyle('display',''); } else { NHLS.options.ajaxResponse = responseText; NHLS.options.ajaxResponseXML = responseXML; } // // Reset? if( NHLS.options.suppressDisplay == "true" ) { NHLS.options.suppressDisplay = "false"; } if( $(showWrapper) ) { $( showWrapper ).setStyle( 'display', 'block' ); $( showWrapper ).makeDraggable( { handle: $( showWrapper+'-handle' ) } ); } } }).send(); }, /** * Function usually used as a debug for Ajax calls. * If the AJAX request is not empty, it will throw an alert * @param The URL to be accessed by the call * @param The Element ID of the HTML container that should be updated * @see AjaxRequest() */ AjaxCallBack: function( actionUrl, updateContainer) { // // Build the full URL if( actionUrl.test("http") ) { var xml_request = actionUrl; } else { var xml_request = this.options.base_url + actionUrl; } if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', '' ); this.centerElement('ajax-loader'); } var Ajax = new Request( { url: xml_request, method: 'get', headers: { 'If-Modified-Since': 'Sat, 1 Jan 2000 00:00:00 GMT' }, update: $( updateContainer ), onSuccess: function( responseText, responseXML ) { if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', 'none' ); } if(responseText!=''){ alert(responseText); } } }).send(); }, /** * This function should be called right before an Ajax call * that you DONT want to update anything on the screen. * This also supresses the AJAX loading box */ silentUi: function() { this.options.suppressDisplay = "true"; }, /** * This checks and accepts every RFC valid email address * @param The email address that needs checking * @return True if email is valid, false if it isn't */ checkValidEmail: function(email) { if( !email ) { return false; } if( email.toLowerCase().test("^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$") ) { return true; } else if( email.toLowerCase().test("^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$") ) { return true; } else { return false; } } });