if ( window.name == kMainFrameName && window.parent !== window )
{
	window.parent.location = window.location.href;
}

function writeDialog()
{
	if ( showSmallDialog ) 
	{
		writeSmallDialog()
	}
	else
	{
		writeNormalDialog();
	}
}

function writeNormalDialog()
{	
	document.write(
		'<table align="center" border="0" width="100%" cellspacing="0" cellpadding="0" height="100%">' +
			'<tr height="15%">' +
				'<td valign ="middle"></td>' +
			'</tr>' +
			'<tr height="70%">' +
				'<td>' +
					'<table align="center" width="510" border ="0" cellspacing="0" cellpadding="0">' +
						'<tr>' +
							'<td>' +
								'<img src ="login-images/' + logoImage +'" width="518" height="118" alt="' + htmlString(logoAltText)  + '">' +
							'</td>' +
						'</tr>' +			
						'<tr>' +
							'<td background="login-images/logo-background-image.gif">' +
								'<table align="center" width="518" height="267" border="0" cellspacing="0" cellpadding="0">' +
									'<tr>' +
										'<td><img src="login-images/pixel.gif" height="1" width="1">&nbsp;</td>' +
									'</tr>' +	
									'<tr>' +
										'<td><img src="login-images/pixel.gif" height="1" width="1">&nbsp;</td>' +
									'</tr>' +	
									'<tr>' +
										'<td>');
	
	writeInnerPanel();
	
	document.write(
										'</td>' +
									'</tr>' +
									'<tr>' +
										'<td align="center" class="worksite-login-msg" id="msg-window">&nbsp;</td>' +								
									'</tr>' +
									'<tr>' +
										'<td><img src="login-images/pixel.gif" height="1" width="1">&nbsp;</td>' +								
									'</tr>' +										
								'</table>' +
							'</td>' +
						'</tr>' +											
						'<tr>' +
							'<td bgcolor="617D8E"><img src="login-images/pixel.gif" width="5" height="4" alt="" border="0"></td>' +
						'</tr>' +	
						'<tr>' +
							'<td align="right" bgcolor="617D8E">');
							
	writeValidateBrowser();							
							
	document.write(
							'</td>' +
						'</tr>' +			
					'</table>' +
				'</td>' +	
			'</tr>' +			
			'<tr height="15%">' +
				'<td valign="middle"></td>' +
			'</tr>' +				
		'</table>');
}

function writeValidateBrowser()
{
	document.write(
		'<table border="0" cellspacing="0" cellpadding="0">' +
			'<tr>' +
				'<td valign="top">' +
					'<a style="cursor:hand; text-decoration:none;" href="bc/index.aspx">' +
						'<img src="login-images/validate-check.gif" width="16" height="16" alt="' + htmlString(getLocStrByLID(828, 'Validate Browser')) + '" border="0">&nbsp;' +
					'</a>' +
				'</td>' +
				'<td valign="top" style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;font-weight:bold;font-size:7pt;">' +
					getAnchorStr(828, 'Validate Browser', 'bc/index.aspx', '', '', '', 'cursor:hand; text-decoration:underline; color:#FFFFFF;', '', '', '') +
				'</td>' +
			'</tr>' +
		'</table>');

}
function writeSmallDialog()
{
	document.write(	
		'<table height="100%" bgcolor="BBC7CE" width="100%" border="0" align="center">' +
			'<tr>' +
				'<td valign="middle" align="center">' +
					'<font color="Black">' + htmlString(getLocStrByLID(37, 'Your session has expired. You must log in again.')) + '</font>' +
					'<br><br>');
	
	writeInnerPanel();
	
	document.write(
				'</td>' +
			'</tr>' +
		'</table>');
}

function writeInnerPanel()
{
	if ( isCompatible  ) 
	{ 
		writeLoginTable()
	}
	else
	{
		writeIncompatible()
	}
	
	if ( browserWarning ) 
	{
		writeBrowserWarning()
	}
}

function writeLoginTable()
{
	document.write(
		'<table align="center" border="0" cellspacing="0" cellpadding="0">' +
			'<iframe name="trusted-login-frame" width="0" height="0" src="login-images/pixel.gif"></iframe>' +
			//fix for 36774:  IE 55 crashes when session expires and redirected to login --> per IB, IE55 having
			//problems submitting to iframe
			'<form action="scripts/login.aspx" method="post" id="fm" name="fm"' +  (g_browser.isIE55 ? '' : ' target="trusted-login-frame"') + '>' +
				'<input type="hidden" name="timeZone" value="">' +
				'<input type="hidden" name="ReturnUrl" id="ReturnUrl" value="' + htmlString(returnUrl) + '">' +
			'<tr>' +							
				'<td colspan="2" background="login-images/loginBox-top-left-corner.gif"><img src="login-images/pixel.gif" width="15" height="15" alt="" border="0"></td>' +
				'<td bgcolor ="E8ECEE" valign="top"><img src="login-images/loginBox-top-piece.gif" width="260" height="3" alt="" border="0"></td>' +
				'<td colspan="2" background="login-images/loginBox-top-right-corner.gif"><img src="login-images/pixel.gif" width="15" height="15" alt="" border="0"></td>' +							
			'</tr>' +
			'<tr>' +
				'<td background="login-images/loginBox-left-piece.gif"><img src="login-images/pixel.gif" width="3" height="1" alt="" border="0"></td>' +
				'<td bgcolor ="E8ECEE"><img src="login-images/pixel.gif" width="12" height="1" alt="" border="0"></td>' +
				'<td>');

	writeLoginForm();

	document.write(
				'</td>' +
				'<td bgcolor ="E8ECEE"><img src="login-images/pixel.gif" width="12" height="1" alt="" border="0"></td>' +													
				'<td background="login-images/loginBox-right-piece.gif"><img src="login-images/pixel.gif" width="3" height="1" alt="" border="0"></td>' +
			'</tr>' +
			'<tr>' +
				'<td colspan="2" background="login-images/loginBox-bot-left-corner.gif"><img src="login-images/pixel.gif" width="15" height="15" alt="" border="0"></td>' +										
				'<td valign="bottom" bgcolor ="E8ECEE"><img src="login-images/loginBox-bot-piece.gif" width="260" height="6" alt="" border="0"></td>' +
				'<td colspan="2" background="login-images/loginBox-bot-right-corner.gif"><img src="login-images/pixel.gif" width="15" height="15" alt="" border="0"></td>' +
			'</tr>' +
			'</form>' +
		'</table>');								
}

function writeLoginForm()
{
	document.write('<table bgcolor ="E8ECEE" align="center" border="0" cellspacing="0" cellpadding="0" width="260">');
	
	if ( trustedLoginEnabled ) 
	{ 
		writeTrustedLogin();
	
		if(  showSmallDialog ) 
		{
			writeUsernamePassword();
		}
		else
		{
			writeSeparator();
			writeUsernamePassword();
			writeSeparator();
		}
	}
	else
	{
		writeUsernamePassword();
	}
	
	writeLoginButton();
	
	document.write('</table>');
}

function writeTrustedLogin()
{
	document.write(
		'<tr>' +			
			'<td align="right" valign="top"><input type="checkbox" name="trustedLoginCheck" id="trustedLoginCheck" onClick="disable()" onkeyup="onKey(event)">&nbsp;</td>' +
			'<td align="left" class="worksite-login-text" valign="middle" nowrap>' + getString('334', '', 'Trusted Login', 'trustedLoginCheck') + '&nbsp;</td>' +
			'<td>&nbsp;</td>' +
		'</tr>' +
		'<tr>' +
			'<td colspan="3"><img src="login-images/pixel.gif" width="1" height="5" alt="" border="0"></td>' +
		'</tr>');
}

function writeUsernamePassword()
{
	document.write(
		'<tr valign="middle">' +
			'<td width="50">&nbsp;</td>' +
			'<td align="left"><span class="worksite-login-text" id="userID-label">' + getString(497, '', 'User Name', 'userID') + '</span></td>' +
			'<td width="50">&nbsp;</td>' +
		'</tr>' +
		'<tr>' +
			'<td width="50">&nbsp;</td>' +
			'<td align="center" style="font-weight:normal;">' +
				'<input id="userID" name="userID" maxlength="64" type="text" value="' + htmlString(defaultUsername) + '" size="20" onfocus="this.select()" onkeyup="onKey(event)" style="width:100%">' +
			'</td>' +
			'<td width="50">&nbsp;</td>' +
		'</tr>' +
		'<tr>' +
			'<td colspan="3"><img src="login-images/pixel.gif" alt="" width="1" height="10" border="0"></td>' +
		'</tr>' +
		'<tr>' + 
			'<td width="50">&nbsp;</td>' +
			'<td align="left"><span class="worksite-login-text" id="password-label">' + getString(320, '', 'Password', 'password') + '</span></td>' +
			'<td width="50">&nbsp;</td>' +
		'</tr>' +
		'<tr>' +
			'<td width="50">&nbsp;</td>' +
			'<td align="center" style="font-weight:normal;">' +
				'<input id="password" name="password" maxlength="32" type="password" size="20" onfocus="this.select()" onkeyup="onKey(event)" style="width:100%">' +
			'</td>' +
			'<td width="50">&nbsp;</td>' +
		'</tr>' +
		'<tr>' +
			'<td colspan="3"><img src="login-images/pixel.gif" alt="" width="1" height="10" alt="" border="0"></td>' +
		'</tr>');
}

function writeLoginButton()
{
	document.write(
		'<tr>' +
			'<td colspan ="2">' +																																	
				'<table align="right" border="0" cellspacing="0" cellpadding="0">' +
					'<tr>' +
						'<td onclick="doSubmit()"><img src="login-images/login-left.gif" width="6" height="20" alt="" border="0" style="cursor:hand;"></td>' +																																																														
						'<td background="login-images/login-mid.gif">' +
							'<input type="button" onclick="doSubmit()" value="' + htmlString(getLocStrByLID(317, 'Login')) + '" style="cursor:hand;background-color:FFFFFF;border:0;font-family:Verdana, Arial;font-weight:bold;font-size:8pt;color:#000000">' +
						'</td>' +																				
						'<td onclick="doSubmit()"><img src="login-images/login-right.gif" width="17" height="20" alt="" border="0" style="cursor:hand;"></td>' +
					'</tr>' +
				'</table>' +																			
			'</td>' +
			'<td width="50">&nbsp;</td>' +
		'</tr>');
}

function writeSeparator()
{
	document.write(
		'<tr>' +
			'<td><img src="login-images/pixel.gif" width="1" height="2" border="0" alt=""></td>' +
			'<td bgColor="#999999"><img src="login-images/pixel.gif" width="1" height="2" border="0"></td>' +
			'<td><img src="login-images/pixel.gif" width="1" height="2" border="0" alt=""></td>' +
		'</tr>' +
		'<tr>' +
			'<td colspan="3"><img src="login-images/pixel.gif" width="1" height="5" alt="" border="0"></td>' +
		'</tr>');
}

function writeIncompatible()
{
	document.write(
		'<table width="100%" border="0" cellspacing="0" cellpadding="0">' +	
		'<tr>' +
			'<td align="center">' +
				'<table width="100%" border="0" cellspacing="5" cellpadding="3">' +	
					'<tr>' +
						'<td>' +
							'<h3>' + htmlString(getLocalizedMessage(1028, product)) + '</h3>' +
							'<h4>' + htmlString(getLocalizedMessage(1024, product)) + '</h4>' +
						'</td>' +
					'</tr>' +
				'</table>' +
		'</tr>' +
		'<tr>' +								
			'<td align="center">' +
				'<table>' +
					'<tr>' +
						'<td valign="top">' +
							'<ul>' +
								'<li>' + 
									'<a href="http://www.microsoft.com/windows/ie">' + 
										htmlString(getLocStrByLID(1025, 'Internet Explorer 5.5 and above')) + 
									'</a>' + 
								'</li>' +
							'</ul>' +
						'</td>' +
					'</tr>' +
				'</table>' +
			'</td>' +
		'</tr>' +
	'</table>');
}

function writeBrowserWarning()
{
	document.write(
		'<table width="100%" border="0" cellspacing="0" cellpadding="0">' +
			'<tr>' +
				'<td align="center">' +
					'<table width="90%" align="center">' +
						'<tr>' +
							'<td colspan="2">' +
								'<font color="Red">' + getLocStrByLID(185, 'Caution') + ':  </font>' +
								htmlString(getLocStrByLID(188, 'If you do not have SP1, at minimum, for ' +
													'Internet Explorer 5.x installed, some of the features may not work properly. ' +
													'Therefore, it is recommended that you install the latest service pack for Internet Explorer 5.x.')) +
							'</td>' +
						'</tr>' +
						'<tr>' +
							'<td colspan="2">' +
								'<a href="http://www.microsoft.com/windows/ie/downloads">' +
									htmlString(getLocStrByLID(189, 'Click here for the latest service pack.')) + 
								'</a>' +
							'</td>' +
						'</tr>' +
					'</table>' +
				'</td>' +
			'</tr>' +
		'</table>');
}

function testLoginFrame(reset)
{
	var loginFrame = window.frames["trusted-login-frame"]; 
	if ( ! reset && loginFrame && loginFrame.document.readyState == 'complete' )
	{
		var html = loginFrame.document.body.innerHTML;
		var msg = html.indexOf("Error:") == 0 ? html.substr("Error:".length, html.length) : ""
		showWait(loginFrame.document.getElementById("login") != null, htmlString(msg))
	}
	else
	{
		window.setTimeout('testLoginFrame()', 100, 'JavaScript')
	}
}

function showWait(show, msg)
{
	document.body.style.cursor = show ? 'wait' :'auto'
	
	var obj = document.getElementById("msg-window")
	if ( obj )
	{
		if ( show )
		{
			obj.innerHTML = htmlString(getLocStrByLID(448, 'Logging in (please wait)...'));
		} 
		else
		{
			obj.innerHTML = '<span class="worksite-error-msg">' + (msg ? msg : '&nbsp;') + '</span>';
		}
	}
}		

function doValidation() 
{
	if ( browserProblem() ) 
	{
		window.location = "bc/browserinformation.aspx";
		return false;
	}	
	return true				
}

function doSubmit()
{	
	var fm = document.forms["fm"];	
	var isTrustedLogin = fm.trustedLoginCheck && fm.trustedLoginCheck.checked;
	
	if((isTrustedLogin || (fm.userID.value && fm.password.value)) && doValidation())
	{	    
	    var trustedLoginCookie = TrustedLoginCookie();		
	    if ( fm.trustedLoginCheck && fm.trustedLoginCheck.checked ) 
	    {		
		    trustedLoginCookie.setState(trustedLoginCookie.getState() | TrustedLoginStates().Login);
	    }			
	    else
	    {
		    trustedLoginCookie.setState(TrustedLoginStates().None);
	    }

	    testLoginFrame(true)			
	    showWait(true);
	    fm.submit();						    
	}
}	

function browserProblem() 
{
	//test cookie creation capability
	deleteCookie("checkCookies");
	setCookie("checkCookies", "true");
	var cookieEnabled = getCookie("checkCookies");			
	if (cookieEnabled == "" || cookieEnabled == null) 
	{				
		return true;
	}
			
	//test for compatible browsers
	var clientBrowser  = new yrBrowser();
	if (!clientBrowser.isCompatible) 
	{
		return true;
	}
			
	//test for Java
	var isJavaEnabled = navigator.javaEnabled();
	if (!isJavaEnabled) 
	{
		return true;
	}

	return false;				
}
// We should be fine with JVM version 4.79.2435 and higher		

function autoTrustedLogin() 
{	
	var trustedLoginStates = TrustedLoginStates();
	var trustedLoginCookie = TrustedLoginCookie();
	var state = trustedLoginCookie.getState();
	trustedLoginCookie.setState(state & ~trustedLoginStates.Logout);
	
	var fm = document.forms["fm"];
	if ( (state & (trustedLoginStates.Auto | trustedLoginStates.Login))
		|| trustedLoginAuto	) 
	{
		var checkBox = fm.trustedLoginCheck
		if ( checkBox ) 
		{
			checkBox.checked = true
		}
		disable()
		
		if ( ((state & trustedLoginStates.Auto) || trustedLoginAuto) && ! (state & trustedLoginStates.Logout) )
		{
			doSubmit()
		}
	}
}

function disable()
{
	var fm = document.forms["fm"]
	var disabled = fm.trustedLoginCheck ? fm.trustedLoginCheck.checked : false;
	var className = "worksite-login-text" + (disabled ? "-disabled" : "")
	
	fm.userID.disabled = disabled
	fm.password.disabled = disabled

	document.getElementById("userID-label").className = className
	document.getElementById("password-label").className = className
}

function onKey(e)
{	
	if ( e && e.keyCode == keyCodes.ENTER )
	{
		doSubmit();
	}
}

function setFocus()
{
	var fm = document.forms["fm"];
	if ( fm )
	{
		if ( fm.userID 
			&& ! fm.userID.disabled
			&& ! defaultUsername ) 
		{
			fm.userID.focus();
		} 
		else if ( fm.password 
			&& ! fm.password.disabled )
		{
			fm.password.focus();
		}
	}
}