/**********************************************************************************
  **** Login scripts                                                           ****
  **** Copyright 2002-2004, Hershey Systems, Inc.                              ****
  **** Author: Daniel Q. Yu                                                    ****
  **** Filename: login.js Version: 1.1                                         ****
  *********************************************************************************/

if(self != top) {
	top.location = self.location;
}

function sendUserPassword(passwordEntered) {
	if(singularityAuth == "CHAPS") {
		var hashed = hex_md5(passwordEntered);
		document.login.temporarypassword.value = "";
		document.login.DCAppSesPasswordV1_0.value = hashed;
	} else if(singularityAuth == "LDAP") {
		document.login.DCAppSesPasswordV1_0.value = passwordEntered;
	} else {
		document.login.DCAppSesPasswordV1_0.value = passwordEntered;
	}
	document.login.submit();
}

function sendHashPassword(passwordToHash) {
	var hashed = hex_md5(passwordToHash);
	document.login.temporarypassword.value = "";
	document.login.DCAppSesPasswordV1_0.value = hashed;
	document.login.submit();
}
  	

function initHandlers () {
	addhandlers(window);
	addhandlers(document);
	addhandlers(document.login);
}

function removeHandlers(){
	removeHandler(window);
	removeHandler(document);
	removeHandler(document.login);
}

function mainHandler(e) {
	var whichField;
	var Key;
	if (isNetscape) {
		Key = e.which;
	}

	if ( isMSIE ) {
		e = window.event;
		Key = e.keyCode;
		e.cancelBubble = true;
	}

	if (Key == 13){
		doSearch();
	}
}

function emptyHandler(e) {

}

function addhandlers(o) {
	if(isNetscape) {
		window.captureEvents(Event.KEYPRESS);
	}
	//o.onkeypress = mainHandler;
}

function removeHandler(o) {
	if (isNetscape) {
		window.releaseEvents(Event.KEYPRESS);
	}
	//o.onkeypress = emptyHandler;
}

function doSearch() {
	sendUserPassword(document.login.temporarypassword.value);
}


function buildLoginForm(message) {
	document.write("	<table border='0' cellpadding='0' align='center' valign='top' cellspacing='0' height='300' width='400'>");
	document.write("		<tr align='center' valign='top'><td>");
	document.write("			<table><tr><td align='center' valign='top'>");
	document.write("				<table border='1' cellpadding='0' align='left' valign='top' cellspacing='0' height='270' width='400'>");
	document.write("					<tr width='100%' height='100%' valign='top' align='left'><td>");
	document.write("						<table valign='top' border='0' cellpadding='0' cellspacing='0' class='dc_TitleBackGround' width='100%'>");
	document.write("							<tr valign='top' width='100%'>");
	document.write("								<td width='150' height='50'> <img border='0' src='./graphics/logos/steplogo.jpg' width='150' height='50'></td>");
	document.write("								<td valign='top'  align='right' height='50' background='./graphics/stepline.jpg'>&nbsp;</td>");
	document.write("							</tr>");
	document.write("							<tr height='20'>");
	document.write("								&nbsp;");
	document.write("							</tr>");
	document.write("						</table>");
	document.write("						<!-- Content Frame Location Bar -->");
	document.write("						<table border='0' cellpadding='0' cellspacing='0' class='dc_TitleBackGround' width='100%'><tr>");
	document.write("							<td width='15'>&nbsp; </td>");
	document.write("							<td width='370'>");
	document.write("								<!-- User Action Statement -->");
	document.write("								<table  border='0' cellpadding='0' cellspacing='0' class='dc_TitleBackGround' width='100%'>");
	document.write("									<tr align='left'>");
	document.write("										<td align='left' class='pageHeaderText' valign='top' width='89%'>");
	document.write("											<label><h6>" + message + "</h6></label>");
	document.write("										</td>");
	document.write("									</tr>");
	document.write("								</table>");
	document.write("								<!-- End User Action Statement -->");
	document.write("							</td>");
	document.write("						</tr></table>");
	document.write("						<!-- End Content Frame Location Bar -->");
	document.write("						<!-- Tab Bar -->");
	document.write("						<center><table width='95% height='100%' border='0' cellpadding='0' cellspacing='0'>");
	document.write("							<tr><td>");
	document.write("								<table  border='0' cellpadding='0' cellspacing='0' width='100%'>");
	document.write("									<tr background='graphics/tabbg.gif'>");
	document.write("										<td align='left' background='./graphics/tabbg.gif' height='17' width='100%'>&nbsp;</td>");
	document.write("									</tr>");
	document.write("								</table>");
	document.write("						<!-- End Tab Bar -->");
	document.write("						<!-- Content ToolBar -->");
	document.write("						<table  border='0' cellpadding='0' cellspacing='0' class='dc_ContentToolbarBackground' width='100%'>");
	document.write("							<tr valign='center'>");
	document.write("								<td class='dc_ContentToolbarText' width='100%'>&nbsp; </td>");
	document.write("							  </tr>");
	document.write("						</table>");
	document.write("						<!-- End Content ToolBar -->");
	document.write("						<!-- Content Line Separator -->");
	document.write("						<table  border='0' cellpadding='0' cellspacing='0' height='100%' width='100%'>");
	document.write("							<tr align='left' valign='top'>");
	document.write("								<td class='dc_SepLeft' width='1%'>&nbsp; </td>");
	document.write("								<td class='dc_SepMiddle' width='98%'>&nbsp; </td>");
	document.write("								<td class='dc_SepRight' width='1%'>&nbsp; </td>");
	document.write("							</tr>");
	document.write("						</table>");
	document.write("						<!-- End Content Line Separator -->");
	document.write("						<table border='0' cellpadding='0' cellpading='0' cellspacing='0' class='formtable' height='100%'>");
	document.write("							<tr>");
	document.write("								<td height='20' colspan='3'>");
	document.write("									<img height='20' src='./graphics/notrequired.gif' width='1'>");
	document.write("								</td>");
	document.write("							</tr>");
	document.write("							<!-- Form Body Table Row -->");
	document.write("							<tr>");
	document.write("								<!-- Form Body Field -->");
	document.write("								<td class='dc_formLeftSpace' valign='top' width='15'> <img height='10' src='./graphics/required.gif' width='15'>&nbsp;</td>");
	document.write("								<td class='dc_formControlLabel' false><label for='DCAppSesUserNameV1_0'>User Id:&nbsp; </label> </td>");
	document.write("								<td class='dc_controlBackGround' true valign='top'>");
	document.write("									<table border='0' cellpadding='0' cellspacing='0'>");
	document.write("										<tr nowrap='true'>");
	document.write("											<td class='dc_controlBackGround' nowrap='true'>");
	document.write("												<input class='dc_control' name='DCAppSesUserNameV1_0' required='true' maxlength='50' style='width:200px;' width='200px' size='50' tabindex='1'>");

	document.write("											</td>");
	document.write("											<td class='dc_controlBackGround' nowrap='true'>");
	document.write("												<span class='invalidMessageLogin' id='DCAppSesUserNameV1_0.span'></span>");

	document.write("											</td>");
	document.write("										</tr>");
	document.write("									</table>");
	document.write("								</td>");
	document.write("								<!-- End Form Body Field -->");
	document.write("							</tr>");
	document.write("							<tr>");
	document.write("								<!-- Form Body Field -->");
	document.write("								<td class='dc_formLeftSpace' valign='top' width='15'> <img height='10' src='./graphics/required.gif' width='15'>&nbsp;</td>");
	document.write("								<td class='dc_formControlLabel' false> <label for='temporarypassword'>Password:&nbsp; </label> </td>");
	document.write("								<td class='dc_controlBackGround' true valign='top'>");
	document.write("									<table border='0' cellpadding='0' cellspacing='0'>");
	document.write("										<tr nowrap='true'>");
	document.write("											<td class='dc_controlBackGround' nowrap='true'>");
	document.write("												<input class='dc_control' required='true' name='temporarypassword' type='password' maxlength='30' style='width:200px;' width='200px' size='30' tabindex='2'>");
	
	document.write("											</td>");
	document.write("											<td class='dc_controlBackGround' nowrap='true'>");
	document.write("												<span class='invalidMessageLogin' id='temporarypassword.span'></span>");

	document.write("											</td>");
	document.write("										</tr>");
	document.write("									</table>");
	document.write("								</td>");
	document.write("								<!-- End Form Body Field -->");
	document.write("							</tr>");
	document.write("							<!-- End Form Body Table Row -->");
	document.write("						</table>");
	document.write("						<table border='0' cellpadding='0' cellspacing='0'>");
	document.write("							<tr>");
	document.write("								<td class='dc_controlBackGround'>");
	document.write("									<input class='dc_control' name='DCAppSesIntDomainV1_0' maxlength='20' style='width:200px;' width='200px' tabindex='3' type='hidden' value='Default'>");
	document.write("								</td>");
	document.write("								<td class='dc_controlBackGround'>");
	document.write("									<input class='dc_control' name='DCAppSesPasswordV1_0' maxlength='20' style='width:200px;' width='200px' tabindex='3' type='hidden' value=''>");
	document.write("								</td>");
	document.write("							</tr>");
	document.write("						</table>");
	document.write("						<!-- The Submit Button -->");
	document.write("						<div align='right'>");
	document.write("							<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111'>");
	document.write("								<tr>");
	document.write("									<td class='dc_controlBackGround' style='text-align: right'>");
	document.write("										<a name='submit_button' href='javascript:sendUserPassword(document.login.temporarypassword.value)' target='_top' onblur='initHandlers();' onfocus='removeHandlers();'>");
	document.write("										<img border='0' src='graphics/login.jpg'></a>");
	document.write("									</td>");
	document.write("								</tr>");
	document.write("							</table>");
	document.write("						</div>");
	document.write("						<!-- End The Submit Button -->");
	document.write("					<!-- End Form Body Table -->");
	document.write("					</td>");
	document.write("					</tr>");
	document.write("				</table>");
	document.write("			</center>");
	document.write("			</td>");
	document.write("			</tr>");
	document.write("			</table>");
	document.write("		</td>");
	document.write("		<td>");
	document.write("		<table border='1' cellpadding='0' align='left' valign='top' cellspacing='0' width='100' height='270'>");
	document.write("			<tr valign='top' align='right'>");
	document.write("						  <td valign='top' align='center'>");
	document.write("							<p align='left'><img src='graphics/intro.jpg' width='95' height='260'></p>");
	document.write("						  </td>");
	document.write("						</tr>");
	document.write("					  </table>");
	document.write("					</td>");
	document.write("				</tr>");
	document.write("			</table>");
	document.write("		</td>");
	document.write("	  </tr>");
	document.write("	  <tr bgcolor='#666666'>");
	document.write("		<td width='100%' align='left' colspan='2'>");
	document.write("		  <table>");
	document.write("				<tr>");
	document.write("					<td width='297' align='left'>");
	document.write("						<font color='#000000'>");
	document.write("							<b>");
	document.write("								<font face='Tahoma' size='1'>");
	document.write("									Copyright &copy; 2002-2004 Hershey Systems, Inc.");
	document.write("								</font>");
	document.write("							</b>");
	document.write("						</font>");
	document.write("					</td>");
	document.write("					<td width='203' align='right'>");
	document.write("						<div align='right'>");
	document.write("							<font color='#FFFFFF'>");
	document.write("								<i>");
	document.write("									<font face='Tahoma' size='1'>");
	document.write("										<b>");
	document.write("											CHAPs Based Authentication");
	document.write("										</b>");
	document.write("									</font>");
	document.write("								</i>");
	document.write("							</font>");
	document.write("						</div>");
	document.write("					</td>");
	document.write("				</tr>");
	document.write("			</table>");
	document.write("		</td>");
	document.write("		</tr>");
	document.write("		<tr width='100%' align='right'>");
	document.write("			<td width='100%' align='right'>");
	document.write("				<table border='0' cellspacing='0' cellpadding='0' width='100%' height='150'>");
	document.write("					<tr>");
	document.write("         				<td width='100%' valign='top'><table height='100%' width='100%'><tr valign='top' width='100%'><td>Version: " + singularityVersion + "</td></tr><tr height='100%'><td/></tr></table></td>");
	document.write("						<td width='235' height='75'> <a href='/jre/jre-1_5_0_06-windows-i586-p.exe'><img width='225' height='75' src='graphics/install_jre.jpg' border='0'></a></td>");
	document.write("					</tr>");
	document.write("					<tr>");
	document.write("          				<td width='100%'>&nbsp;</td>");
	document.write("						<td width='235' height='75'> <a href='/acrobat/AdbeRdr60_enu_full.exe'><img width='225' height='75' src='graphics/install_acrobat.jpg' border='0'></a>");
	document.write("						</td>");
	document.write("					</tr>");
	document.write("					<tr><td colspan='2'></td></tr>");
	document.write("				</table>");
	document.write("			</td>");
	document.write("		</tr>");
	document.write("	</table>");
}
