var gDropDowns = new Array(); function InArray( MyString, MyArray ) { var VarInArray = false; for( i = 0; i < MyArray.length; i++ ) { if( MyArray[i] == MyString ) { return true; } } return false; } // if localeCompare() is not defined (Safari <3), or does not work properly (Safari 3+), define a stand-in if( String.prototype.localeCompare == null || String.prototype.localeCompare('Argentina','Venezuela') >= 0 ) { String.prototype.localeCompare = function( sOther ) { a = Normalize( this ); b = Normalize( sOther ); if( a < b ) return -1; else if ( a > b ) return 1; else return 0; } } function Normalize(str) { var nstr = str; nstr = nstr.replace(/[√Ä√†√Å√°√É√£√Ñ√§√Ö√•√Ü√¶]/,'a'); nstr = nstr.replace(/[√á√ß]/,'c'); nstr = nstr.replace(/[√ê√∞]/,'d'); nstr = nstr.replace(/[√à√(R)√â√(c)√ä√TM√ã√´]/,'e'); nstr = nstr.replace(/[√å√¨√ç√≠√é√Æ√è√Ø]/,'i'); nstr = nstr.replace(/[√í√≤√ì√≥√î√¥√ñ√∂¬å¬ú√ò√∏]/,'o'); nstr = nstr.replace(/[√ô√π√ö√∫√õ√ª√ú√º]/,'u'); nstr = nstr.replace(/[√ù√Ω¬ü√ø]/,'y'); nstr = nstr.replace(/√ü/,'s'); return nstr; } function LocaleSort(a,b) { return a.localeCompare(b); } function AddEvent( obj, type, fn ) { // IE if( obj.attachEvent ) { obj['e'+type+fn] = fn; obj[type+fn] = function(){obj['e'+type+fn]( window.event );} return obj.attachEvent( 'on'+type, obj[type+fn] ); } // W3C DOM else { return obj.addEventListener( type, fn, false ); } } function RemoveEvent( obj, type, fn ) { // IE if( obj.detachEvent ) { var Result = obj.detachEvent( 'on'+type, obj[type+fn] ); obj[type+fn] = null; return Result; } // W3C DOM else { return obj.removeEventListener( type, fn, false ); } } function DropDownMouseOut( Identifier ) { // start the time, if there is an auto hide duration if( gDropDowns[Identifier].AutoHideDuration > 0 ) { return DropDownHandler( Identifier, gDropDowns[Identifier].AutoHideDuration, false ); } return false; } function SetDropDown( Identifier, IsHovering ) { return DropDownHandler( Identifier, gDropDowns[Identifier].AutoHideDuration, IsHovering ); } function ToggleDropDown( Identifier ) { return DropDownHandler( Identifier, 0, ( gDropDowns[ Identifier ] == null || !gDropDowns[ Identifier ].Hovering ) ); } function GoToDropDown(e,Identifier) { if( !e ){ e = window.event; } if( e ) { var KeyCode = ( e.keyCode ? e.keyCode : e.which ); var PressedKey = String.fromCharCode( KeyCode ); if( document.getElementById( Identifier + '-' + PressedKey ) ) { document.getElementById(Identifier + '-' + PressedKey).scrollIntoView(); } } } function DropDownHandler( Identifier, TimeOutDuration, IsHovering ) { if( gDropDowns[ Identifier ] == null ) { gDropDowns[ Identifier ] = { Hovering:false, TimeoutID:null }; } // if we are changing state if( gDropDowns[ Identifier ].Hovering != IsHovering ) { var Element = document.getElementById( Identifier + '-List' ); if( IsHovering ) { // hide all other active drop downs for( DropDownIdentifier in gDropDowns ) { if( DropDownIdentifier != Identifier ) { var DropDownElement = document.getElementById( DropDownIdentifier + '-List' ); if( DropDownElement ) { if( DropDownElement.style.display != 'none' ) { document.onkeypress = null; DropDownElement.style.display = 'none'; } if( gDropDowns[DropDownIdentifier].TimeoutID != null ) { clearTimeout( gDropDowns[ DropDownIdentifier ].TimeoutID ); gDropDowns[DropDownIdentifier].TimeoutID = null; } gDropDowns[DropDownIdentifier].Hovering = false; } } } Element.style.display = 'block'; if( gDropDowns[ Identifier ].TimeoutID != null ) { clearTimeout( gDropDowns[ Identifier ].TimeoutID ); gDropDowns[ Identifier ].TimeoutID = null; } AddEvent( document, 'keydown', gDropDowns[ Identifier ].KeyHandler ); } else if( TimeOutDuration > 0 ) { gDropDowns[ Identifier ].TimeoutID = setTimeout('HideDropDown("' + Identifier + '")', TimeOutDuration ); } else { RemoveEvent( document, 'keydown', gDropDowns[ Identifier ].KeyHandler ); Element.style.display = 'none'; if( gDropDowns[ Identifier ].TimeoutID != null ) { clearTimeout( gDropDowns[ Identifier ].TimeoutID ); gDropDowns[ Identifier ].TimeoutID = null; } } gDropDowns[ Identifier ].Hovering = IsHovering; } } function HideDropDown( Identifier ) { if( !gDropDowns[ Identifier ].Hovering ) { var Element = document.getElementById( Identifier + '-List' ); document.onkeypress = null; Element.style.display = 'none'; } gDropDowns[ Identifier ].TimeoutID = null; } function DropDownIsActive( Identifier ) { return ( gDropDowns[ Identifier ] != null && gDropDowns[ Identifier ].TimeoutID != null ); } /* * Create a
that contains all of the necessary elements and functionality * for a drop-down menu. * * Identifier - desired form element id/name * * Title - initial/default value * * Values - array of objects that define the list values and optional href URLs * * ChainedDropDowns - array of drop-down Identifiers to "chain" to this drop-down * so that when a value is selected for this drop-down, the chained drop-downs * are reset to their default value and their lists are filtered based on the * selected value of this drop-down (through related object property values) * * AutoHideDuration - delay before hiding drop-down after mouseout (0=never) * * IsSubmittable- displays the submit button * */ function CreateDropDown( Identifier, Title, Values, FormName, ChainedDropDowns, AutoHideDuration, IsSubmittable ) { var UniqueValues = new Array(); for( var index = 0; index < Values.length; index++) { if( !InArray( Values[index][Identifier], UniqueValues ) ) { UniqueValues.push( Values[index][Identifier] ); } } gDropDowns[ Identifier ] = { Identifier:Identifier, Title:Title, Values:Values, FormName:FormName, ChainedDropDowns:ChainedDropDowns, AutoHideDuration:( AutoHideDuration == null ? 0 : AutoHideDuration ), IsSubmittable:IsSubmittable, TimeoutID:null, KeyHandler:new Function( "e", "if(!e){e=window.event;} GoToDropDown(e,'" + Identifier + "')" ), Hovering:false }; document.writeln(''); document.writeln(''); BuildDropDownList( Identifier ); } /* * TextValue = null - build default lists */ function BuildDropDownLists( Identifier, TextValue ) { if( TextValue == null ) { BuildDropDownList( Identifier ); } var ChainedDropDowns = gDropDowns[ Identifier ].ChainedDropDowns; if( ChainedDropDowns != null ) { // rebuild chained drop-down lists for( var ChainIndex = 0; ChainIndex < ChainedDropDowns.length; ChainIndex++ ) { var ChainedIdentifier = ChainedDropDowns[ChainIndex]; BuildDropDownList( ChainedIdentifier, Identifier, TextValue ); } } } function BuildDropDownList( Identifier, MatchIdentifier, MatchValue ) { var Values = gDropDowns[ Identifier ].Values; var UniqueValues = new Array(); for( var ValuesIndex = 0; ValuesIndex < Values.length; ValuesIndex++) { if( MatchIdentifier == null || MatchValue == null || Values[ValuesIndex][MatchIdentifier] == MatchValue ) { if( Values[ValuesIndex][Identifier] != '' && !InArray( Values[ValuesIndex][Identifier], UniqueValues ) ) { UniqueValues.push( Values[ValuesIndex][Identifier] ); } } } UniqueValues.sort(LocaleSort); var ListHTML = ''; var ListDiv = document.getElementById( Identifier + '-List' ); if( UniqueValues.length > 8 ) { ListDiv.style.height = '160px'; } else { ListDiv.style.height = 'auto'; } ListDiv.innerHTML = ListHTML; var Element; Element = document.getElementById( Identifier ); Element.value = ''; Element = document.getElementById( Identifier + '-Value' ); Element.innerHTML = gDropDowns[ Identifier ].Title; } function SelectOption( Identifier, TextValue ) { var Element; Element = document.getElementById( Identifier ); Element.value = TextValue; Element = document.getElementById( Identifier + '-Value' ); Element.innerHTML = TextValue; if(gDropDowns[Identifier].IsSubmittable) { if(document.getElementById(gDropDowns[Identifier].FormName)) { var Children = document.getElementById(gDropDowns[Identifier].FormName).childNodes; var FoundSubmit = false; for( var i = 0; i < Children.length; i++ ) { if( Children[i].id == "Submit" ) { Children[i].style.display='block'; FoundSubmit = true; break; } } if(FoundSubmit == false) { document.getElementById(gDropDowns[Identifier].FormName).submit(); } } } else { if(document.getElementById(gDropDowns[Identifier].FormName)) { var Children = document.getElementById(gDropDowns[Identifier].FormName).childNodes; var FoundSubmit = false; for( var i = 0; i < Children.length; i++ ) { if( Children[i].id == "Submit" ) { Children[i].style.display='none'; FoundSubmit = false; break; } } if( FoundSubmit == false && document.getElementById('Submit') ) { document.getElementById('Submit').style.display='none'; } } } DropDownHandler( Identifier, 0, false ); var FoundLink = false; var Values = gDropDowns[ Identifier ].Values; for( var ValuesIndex = 0; ValuesIndex < Values.length; ValuesIndex++) { if( Values[ValuesIndex][Identifier] == TextValue ) { if( Values[ValuesIndex]['href'] != null && gDropDowns[ Identifier ].ChainedDropDowns == null) { location.href = Values[ValuesIndex]['href']; FoundLink = true; } break; } } if( !FoundLink ) { BuildDropDownLists( Identifier, TextValue ); if( ValuesIndex < Values.length && gDropDowns[Identifier].FormName != null && gDropDowns[Identifier].FormName != '' && Values[ValuesIndex][Identifier+'Link'] != null) { document.getElementById(gDropDowns[Identifier].FormName).action = Values[ValuesIndex][Identifier+'Link']; if(Values[ValuesIndex]['Target'] == 1) { document.getElementById(gDropDowns[Identifier].FormName).target = "_blank"; } else { document.getElementById(gDropDowns[Identifier].FormName).target = "_self"; } if(Values[ValuesIndex][Identifier+'Link']=='http://www.boydeninterim.co.uk/ukinterim/'){ document.getElementById(gDropDowns[Identifier].FormName).target = "_blank"; } if(gDropDowns[Identifier].IsSubmittable && !document.getElementById('Submit')) { document.getElementById(gDropDowns[Identifier].FormName).submit(); } } } }