

do__onLoad = new Array()
do__pageLoaded = false

do__textSizes = new Array( '0.8em', '0.9em', '1.0em', '1.1em', '1.2em', '1.3em', '1.4em', '1.5em', '1.6em', '1.7em'  )
do__textSizeNormal = 2
do__textSize = do__textSizeNormal
do__textSizeCookieName = 'sizeOfText'


dojo.addOnLoad( do_onLoadRun )
dojo.addOnLoad( do_highlightHash )
dojo.addOnLoad( do_parse )

do_setFocusUnlessHash( 'headerLogin' ) 

function do_write( s )
{
	document.write( s )
}

function openWindow( url, windowName, width, height, options )
{
	if ( url.length > 0 )
	{
		windowName = windowName || '_blank'
		width = width || 625
		height = height || 475
		
		if ( ! options )
		{
			options = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=0,left=0'
		}
		
		options = options + ',width=' + width + ',height=' + height
		
		var win = window.open( url, windowName, options )
		
		if ( win )
		{
			if ( win.focus )
			{
				win.focus()
			}
		}
		else
		{
			alert( 'Could not open window.\n\nPlease ensure all popup-blockers are disabled for this site.' )
		}
	}
	
	return false
}

function do_setHref( href )
{
	self.location.href = href
}

function do_onLoadRun()
{
	var i
	
	do__pageLoaded = true
	
	for ( i = 0; i < do__onLoad.length; i++ )
	{
		eval( do__onLoad[ i ] )
	}
}

function do_onLoadAdd( str )
{
	do__onLoad[ do__onLoad.length ] = str
}



function do_setPageWidth( width )
{
	if ( ! width )
	{
		var viewport = dijit.getViewport()
		
		if ( viewport.w < 1024 ) width = 766
		else width = 984
	}
	
	dojo.style( 'page', 'width', String( width ) )
}

function do_setupPage()
{
	do_dynamicStylesWrite()
}

function do_dynamicStylesWrite()
{
	try
	{
		var size = dojo.cookie( do__textSizeCookieName )
		
		if ( size != null )
		{
			size = parseInt( size )
			
			if ( size != null && size != NaN && size >= 0 && size < do__textSizes.length )
			{
				document.write( '<style>.page { font-size: ' + do__textSizes[size] + '; }</style>' )
				
				do__textSize = size
			}
		}
	}
	catch( e )
	{
	}
}

function do_adjustTextSize( adjustment )
{
	var size = do__textSize

	if ( adjustment == -1 ) 
		size = size - 1
	else if ( adjustment == 0 ) 
		size = do__textSizeNormal
	else if ( adjustment == 1 ) 
		size = size + 1
	else if ( adjustment == 2 ) 
		size = parseInt( dojo.cookie( do__textSizeCookieName ) )
	
	if ( size != null && size >= 0 && size < do__textSizes.length )
	{
		do__textSize = size
		dojo.style( 'page', 'fontSize', do__textSizes[do__textSize] )
		do_adjustTextSizeLink()
		
		dojo.cookie( do__textSizeCookieName, new String( do__textSize ), { expires: 5, path: '/' } )
	}
	
	return false
}

function do_adjustTextSizeLink()
{
	var smallerTextSize = dojo.byId( 'smallerTextSize' )
	var normalTextSize = dojo.byId( 'normalTextSize' )
	var largerTextSize = dojo.byId( 'largerTextSize' )
	
	if ( smallerTextSize && normalTextSize && largerTextSize )
	{
		dojo.style( 'smallerTextSize', 'color', '' );
		dojo.style( 'normalTextSize', 'color', '' );
		dojo.style( 'largerTextSize', 'color', '' );
		
		if ( do__textSize == 0 )
		{
			dojo.style( 'smallerTextSize', 'color', '#CDCDCD' );
		}
		else if ( do__textSize == do__textSizeNormal )
		{
			dojo.style( 'normalTextSize', 'color', '#CDCDCD' );
		}
		else if ( do__textSize == 9 )
		{
			dojo.style( 'largerTextSize', 'color', '#CDCDCD' );
		}
	}
}

function do_setFocus( idOrForm, field )
{
	field = field || ''

	if ( do__pageLoaded )
	{
		if ( field && field.length > 0 )
		{
			if ( eval( 'document.' + idOrForm ) && eval( 'document.' + idOrForm + '.' + field ) )
			{
				var focus = eval( 'document.' + idOrForm + '.' + field )
				
				if ( focus && focus.focus )
				{
					focus.focus()
				}
			}
		}
		else
		{
			dijit.focus( dojo.byId( idOrForm ) )
		}
	}
	else
	{
		do_onLoadAdd( 'do_setFocus("' + idOrForm + '","' + field + '")' )
	}
}

function do_setFocusUnlessHash( idOrForm, field )
{
	if ( eval( 'self.location.hash' ) )
	{
		
	}
	else
	{
		do_setFocus( idOrForm, field )
	}
}
				
function do_parse()
{
	dojo.query( ".delayedDisplay", document ).forEach( delayedDisplay )
	dojo.query( ".delayedHide", document ).forEach( delayedHide )
	dojo.query( ".delayedWipeIn", document ).forEach( delayedWipeIn )
}

function delayedDisplay( node )
{
	dojo.removeClass( node, "delayedDisplay" )
}

function delayedHide( node )
{
	if ( dojo.hasClass( node, "delayedHide" ) )
	{
		dojo.addClass( node, "hidden" )
	}
}

function delayedWipeIn( node )
{
	if ( dojo.hasClass( node, "delayedWipeIn" ) )
	{
		
		dojo.style( node, 'display', 'none' )
		dojo.style( node, 'visibility', 'hidden' )
		
		
		dojo.removeClass( node, "delayedWipeIn" )
		
		dojo.fx.wipeIn( { node: node, duration: 250 } ).play()
	}
}



function do_submitSearch( queryDefault )
{
	if ( do_checkSearchSubmit( queryDefault ) )
	{
		document.searchForm.submit()
	}
	
	return false
}

function do_checkSearchSubmit( queryDefault )
{
	var query = document.searchForm.query.value
	var retVal = true
	
	if ( query == '' || query == queryDefault )
	{
		retVal = false
		alert( 'Please type a query into the search box.' )
	}
	
	return retVal
}



function highlight( id, duration )
{
	if ( eval( 'dojo.byId( id )' ) )
	{
		if ( ! duration ) duration = 5000
		
		dojox.fx.highlight( { node: id, color: '#FFFFB4', duration: duration } ).play()
	}
	
	return true
}

function do_highlightHash()
{
	var hash = self.location.hash
	
	if ( eval( 'hash' ) )
	{
		highlight( hash.replace( /#/, '' ) )
	}
}

function do_notImplemented()
{
	alert( 'Sorry, this feature is not yet implemented.' )
	
	return false
}

function do_scrollToTop()
{
	if ( eval( 'self.scrollTo' ) )
	{
		self.scrollTo( 0, 0 )
	}
	else
	{
		self.location.replace( '#top' )
	}
}



var checkboxes = new Array()

function checkboxesInfo()
{
	this.checkboxes = new Array()
	this.formName = ''
	this.actionFieldName = ''
	this.valuesFieldName = ''
	
	return this
}

function checkboxesPrepare( controlName, formName, actionFieldName, valuesFieldName )
{
	var checkboxInfo = checkboxInfoGet( controlName )
	
	checkboxInfo.formName = formName
	checkboxInfo.actionFieldName = actionFieldName
	checkboxInfo.valuesFieldName = valuesFieldName
}

function checkboxesCheckedCount( controlName )
{
	var i
	var check = dojo.byId( controlName ).checked
	var checkboxArray = checkboxArrayGet( controlName )
	var checkedCount = 0
	
	for ( i = 0; i < checkboxArray.length; i++ )
	{
		if ( dojo.byId( checkboxArray[ i ] ).checked )
		{
			checkedCount++
		}
	}
	
	return checkedCount
}

function checkboxesToggle( controlName )
{
	var i
	var check = dojo.byId( controlName ).checked
	var checkboxArray = checkboxArrayGet( controlName )
	
	for ( i = 0; i < checkboxArray.length; i++ )
	{
		dojo.byId( checkboxArray[ i ] ).checked = check
	}
}

function checkboxesValidateChecked( controlName )
{
	var ok = false
	
	if ( checkboxesCheckedCount( controlName ) < 1 )
	{
		alert( 'Please select at least one item.' )
	}
	else
	{
		ok = true
	}
	
	return ok
}

function checkboxAdd( controlName, name )
{
	var checkboxArray = checkboxArrayGet( controlName )
	
	checkboxArray[ checkboxArray.length ] = name
}

function checkboxArrayGet( controlName )
{
	return checkboxInfoGet( controlName ).checkboxes
}

function checkboxInfoGet( controlName )
{
	var checkboxInfo = checkboxes[ controlName ]
	
	if ( eval( 'checkboxInfo' ) )
	{
		
	}
	else
	{
		
		
		checkboxes[ controlName ] = new checkboxesInfo()
		
		checkboxInfo = checkboxes[ controlName ]
	}
	
	return checkboxInfo
}

function checkboxToggle( controlName )
{
	var anyChecked = false
	var checkboxArray = checkboxArrayGet( controlName )
	
	for ( i = 0; i < checkboxArray.length; i++ )
	{
		if ( dojo.byId( checkboxArray[ i ] ).checked )
		{
			anyChecked = true
			break
		}
	}
	
	dojo.byId( controlName ).checked = anyChecked
}

function checkboxSubmitAction( controlName, actionFieldValue, confirmText )
{
	if ( checkboxesValidateChecked( controlName ) )
	{
		var bPerformAction = true
		
		if ( eval( 'confirmText' ) )
		{
			bPerformAction = confirm( confirmText )
		}
		
		if ( bPerformAction )
		{
			var checkboxInfo = checkboxes[ controlName ]
			
			eval( 'document.' + checkboxInfo.formName + '.' + checkboxInfo.actionFieldName + '.value = actionFieldValue' )
			eval( 'document.' + checkboxInfo.formName + '.' + checkboxInfo.valuesFieldName + '.value = checkboxGetValuesString( "' + controlName + '" )' )
			
			eval( 'document.' + checkboxInfo.formName + '.submit()' )
		}
	}
}

function checkboxGetValuesString( controlName )
{
	var checkboxArray = checkboxArrayGet( controlName )
	var valuesString = ''
	
	for ( i = 0; i < checkboxArray.length; i++ )
	{
		if ( dojo.byId( checkboxArray[ i ] ).checked )
		{
			if ( valuesString.length > 0 ) valuesString += ','
			
			valuesString += dojo.byId( checkboxArray[ i ] ).value
		}
	}
	
	return valuesString
}



function do_dialogShowContent( title, content )
{
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		if ( title != null ) dialog.titleNode.innerHTML = title
		dialog.setContent( content )
		dialog.show()
	}
	
	return false
}

function do_dialogShowHref( title, href )
{
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		if ( title != null ) dialog.titleNode.innerHTML = title
		dialog.setHref( href )
		dialog.show()
	}
	
	return false
}

function do_dialogHide()
{
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		dialog.hide()
	}
	
	return false
}

function do_dialogFormSubmit( form )
{
	try
	{
		var kw = { mimetype: "text/plain",
					formNode: form,
					load: do_dialogFormSubmitResponse,
					error: do_dialogFormSubmitError
				}
		
		dojo.io.bind( kw )
	}
	catch ( e )
	{
		do_dialogFormSubmitError( 'Error submitting form.', e )
	}
	
	return false
}

function do_dialogFormSubmitResponse( t, txt, e )
{
	
	
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		do_dialogShowContent( null, txt )
	}
}

function do_dialogFormSubmitError( t, e )
{
	
	
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		var preamble = 'Fatal error for this request: <br><br>'
		
		if ( t )
			t += '<br><br>'
		else
			t = ''
		
		do_dialogShowContent( null, preamble + t + e.message )
	}
}

function do_loginShow( requestedResource, followRR )
{
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		do_dialogShowContent( 'Log In', do_loginHtml( requestedResource, followRR ) )
		
		
		setTimeout( "do_setFocus( 'loginFormDialog', 'LogonID' )", 100 )
	}
	else
	{
		
		self.location.href = '/public/pages/site/logon.html?requestedResource=' + encodeURIComponent( requestedResource )
	}
	
	return false
}

function do_loginHtml( requestedResource, followRR )
{
	requestedResource = requestedResource || ''
	
	var s = ''
	
	s += '<div class="loginDialog">'
		
	s += '	<form name="loginFormDialog" action="/public/pages/site/logon.html" method="POST">'
	s += '		<input type="hidden" name="requestedResource" value="' + requestedResource + '">'
	s += '		<input type="hidden" name="followRR" value="' + ( followRR ? '1' : '0' ) + '">'
	s += '		<input type="hidden" name="FormSubmit" value="1">'
	
	s += '		<table>'
	s += '			<tr>'
	s += '				<td>'
	
	s += '					<fieldset>'
	s += '						<legend>Login</legend>'
	s += '						<table class="formTable" cellspacing="0">'
	s += '							<tr>'
	s += '								<td>Username</td>'
	s += '								<td><input class="medium-2" type="text" name="LogonID"></td>'
	s += '							</tr>'
	s += '							<tr>'
	s += '								<td>Password</td>'
	s += '								<td><input class="medium-2" type="password" name="LogonPswd"></td>'
	s += '							</tr>'
	
	if ( ! followRR )
	{
		s += '							<tr>'
		s += '								<td>Start In</td>'
		s += '								<td>'
		s += '									<select name="StartIn">'

		s += '										<option value="HOME">Home</option>'

		s += '										<option value="ACCOUNTS_ALL_OVERVIEW">Accounts - Overview</option>'

		s += '									</select>'
		s += '								</td>'
		s += '							</tr>'
	}
	
	s += '						</table>'
	s += '					</fieldset>'
	
	s += '					<div class="formButtonArea">'
	s += '						<input type="submit" value="Login">'
	s += '						<input onclick="return do_dialogHide()" type="button" value="Cancel">'
	s += '					</div>'
	
	s += '					<div class="formButtonArea" style="font-size: 80%;">'
	s += '						Need your <a href="/public/pages/site/getUsername.html">Username</a> or <a href="/public/pages/site/resetPassword.html">Password</a>?'
	s += '						<br><br>'
	s += '						<a href="/public/pages/site/register.html">Need to register</a>?'
	s += '					</div>'
	
	s += '				</td>'
	s += '			</tr>'
	s += '		</table>'
	
	s += '	</form>'
	
	s += '</div>'
	
	return s
}

function ov6_loginShow( requestedResource, followRR )
{
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		do_dialogShowContent( 'Log On', ov6_loginHtml( requestedResource, followRR ) )
		
		
		setTimeout( "do_setFocus( 'loginFormDialog', 'LogonID' )", 100 )
	}
	else
	{
		
		self.location.href = '/ov6/public/pages/site/logon.html?requestedResource=' + encodeURIComponent( requestedResource )
	}
	
	return false
}

function ov6_loginHtml( requestedResource, followRR )
{
	requestedResource = requestedResource || ''
	
	var s = ''
	
	s += '<div class="loginDialog">'
		
	s += '	<form name="loginFormDialog" action="/ov6/public/pages/site/logon.html" method="POST">'
	s += '		<input type="hidden" name="requestedResource" value="' + requestedResource + '">'
	s += '		<input type="hidden" name="followRR" value="' + ( followRR ? '1' : '0' ) + '">'
	s += '		<input type="hidden" name="FormSubmit" value="1">'
	
	s += '		<table>'
	s += '			<tr>'
	s += '				<td>'
	
	s += '					<fieldset>'
	s += '						<table class="formTable" cellspacing="0">'
	s += '							<tr>'
	s += '								<td>Logon ID</td>'
	s += '								<td><input class="medium-2" type="text" name="LogonID"></td>'
	s += '							</tr>'
	s += '							<tr>'
	s += '								<td>Password</td>'
	s += '								<td><input class="medium-2" type="password" name="LogonPswd"></td>'
	s += '							</tr>'
	
	s += '						</table>'
	s += '					</fieldset>'
	
	s += '					<div class="formButtonArea">'
	s += '						<input type="submit" value="Log On">'
	s += '						<input onclick="return do_dialogHide()" type="button" value="Cancel">'
	s += '					</div>'
	
	s += '					<div class="formButtonArea" style="font-size: 80%;">'
	s += '						Need your <a href="/ov6/public/pages/site/getUsername.html">Logon ID</a> or <a href="/ov6/public/pages/site/resetPassword.html">Password</a>?'
	s += '					</div>'
	
	s += '				</td>'
	s += '			</tr>'
	s += '		</table>'
	
	s += '	</form>'
	
	s += '</div>'
	
	return s
}

function do_logoutShow()
{
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		do_dialogShowContent( 'Logout', do_logoutHtml() )
		
		
		setTimeout( "do_setFocus( 'logoutForm', 'logoutButton' )", 100 )
	}
	
	return false
}

function do_logoutHtml()
{
	var s = ''
	
	s += '<div class="logoutDialog">'
	s += '	<table>'
	s += '		<tr>'
	s += '			<td align="center">'
	s += '				Do you really want to log out?<br>'
	s += '				<div class="formButtonArea">'
	s += '					<form name="logoutForm" action="/public/pages/site/logout.html" method="POST">'
	s += '						<input type="submit" name="logoutButton" value="Logout">'
	s += '						<input onclick="return do_dialogHide()" type="button" value="Cancel">'
	s += '					</form>'
	s += '				</div>'
	s += '			</td>'
	s += '		</tr>'
	s += '	</table>'
	s += '</div>'
	
	return s
}

function ov6_logoutShow()
{
	var dialog = dijit.byId( 'pageDialog' )
	
	if ( dialog )
	{
		do_dialogShowContent( 'Logout', ov6_logoutHtml() )
		
		
		setTimeout( "do_setFocus( 'logoutForm', 'logoutButton' )", 100 )
	}
	
	return false
}

function ov6_logoutHtml()
{
	var s = ''
	
	s += '<div class="logoutDialog">'
	s += '	<table>'
	s += '		<tr>'
	s += '			<td align="center">'
	s += '				Do you really want to log out?<br>'
	s += '				<div class="formButtonArea">'
	s += '					<form name="logoutForm" action="/ov6/public/pages/site/logout.html" method="POST">'
	s += '						<input type="submit" name="logoutButton" value="Log Out">'
	s += '						<input onclick="return do_dialogHide()" type="button" value="Cancel">'
	s += '					</form>'
	s += '				</div>'
	s += '			</td>'
	s += '		</tr>'
	s += '	</table>'
	s += '</div>'
	
	return s
}

function hitslink( pageTracker, altPageName )
{
	pageTracker = pageTracker || ''
	altPageName = altPageName || ''
	
	var pageName = altPageName 
	
	if ( pageName.length == 0 )
	{
		pageName = location.pathname
	}
	
	if ( pageName == null || pageName.length < 1 || pageName == '/' )
	{
		pageName = 'Default Page'
	}
	
	if ( pageTracker.length > 0 )
	{
		pageName = pageName + ' : ' + pageTracker
	}
	
	document.write( '<script type="text/javascript" id="wa_u"></script>' )
	
	wa_account="Securities"; wa_location=102;
	wa_pageName=pageName;
	document.cookie='__support_check=1';wa_hp='http';
	wa_rf=document.referrer;wa_sr=window.location.search;
	wa_tz=new Date();if(location.href.substr(0,6).toLowerCase()=='https:')
	wa_hp='https';wa_data='&an='+escape(navigator.appName)+ 
	'&sr='+escape(wa_sr)+'&ck='+document.cookie.length+
	'&rf='+escape(wa_rf)+'&sl='+escape(navigator.systemLanguage)+
	'&av='+escape(navigator.appVersion)+'&l='+escape(navigator.language)+
	'&pf='+escape(navigator.platform)+'&pg='+escape(wa_pageName);
	wa_data=wa_data+'&cd='+
	screen.colorDepth+'&rs='+escape(screen.width+ ' x '+screen.height)+
	'&tz='+wa_tz.getTimezoneOffset()+'&je='+ navigator.javaEnabled();
	wa_img=new Image();wa_img.src=wa_hp+'://counter.hitslink.com/statistics.asp'+
	'?v=1&s='+wa_location+'&acct='+wa_account+wa_data+'&tks='+wa_tz.getTime();
	document.getElementById('wa_u').src=wa_hp+'://counter.hitslink.com/track.js';
}
