/**
 * @file: demo.js
 * @use: on any page with an HB login form.
 * @installation: include using a script tag in the markup anywhere AFTER
 *           THE LOGIN FORM, and DO NOT CHANGE ANYTHING.
 */

var urltocheck = self.location.href;

if ( GetCookie("demo").length > 1 ){
	DeleteCookie("demo");
}

document.forms["Login"].setAttribute("autocomplete", "off");
document.forms['Login'].userNumber.value = "";
document.forms['Login'].password.value = "";

if(urltocheck.indexOf("demo")>0){
	goDemo();
}

//Functions are below.

function goDemo(){
	document.cookie = "cookie_check%3dvalid%3b%20path%3d/index.html";
	document.cookie = "demo%3dSTART%3b%20path%3d/index.html";
	document.forms['Login'].userNumber.value = "999999999";
	document.forms['Login'].password.value = "1234";
	openDemoWin();
	dofocus();
}

function GetCookie(name){
	var cValue = '';
	if(document.cookie.length > 0){
		var cName = name +"=";
		var cBegin = document.cookie.indexOf(cName);
		var cEnd = 0;
		if( cBegin > -1 ){
			cBegin += cName.length;
			cEnd = document.cookie.indexOf(";", cBegin);
			if(cEnd < cBegin){
				cEnd = document.cookie.length;
			}
			cValue = document.cookie.substring(cBegin, cEnd);
			cValue = unescape(cValue);
		}
	}
	return(cValue);
}
function DeleteCookie(name){
	expireDate = new Date;
	expireDate.setDate( (expireDate.getDate() - 1) );
	document.cookie = name +"=Deleted;expires=" + expireDate.toGMTString();
}

function dofocus(){
	document.cookie = "cookie_check=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/";
	document.cookie = "current%3dsignon%3b%20path%3d/onlineserv/HB/index.html";
	document.cookie = "LogTime=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/onlineserv/HB/";
	document.cookie = "dihb30=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/onlineserv/HB/";
	document.cookie = "direc30=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/onlineserv/HB/";
	inSubmit = 0;
}
function openDemoWin(){
	demoWin=window.open("../onlineserv/HB/dimlDisplayerfa96.html?DIML_FILE=DemoLayout.diml&amp;DIML_PATH=../HB3.library/standard/layout/&amp;pageType=Signon&amp;language=english&amp;DEFAULT_HTTP_CHAR_SET=charset=ISO-8859-1","demo", "resizable,scrollbars,toolbar,height=400,width=700");
	if(demoWin)demoWin.focus();
	document.cookie = "demo%3dDISPLAY%3b%20path%3d/index.html";
}

//NEW CODE TO ENSURE PASSWORD AND USERNAME HAVE LENGTHS

var pwLength = document.forms['Login'].elements['password'].maxLength;
var userLength = document.forms['Login'].elements['userNumber'].maxLength;
if((!pwLength)||(pwLength<=0)||(pwLength>32))
			{alert("No maxlength is set for the password field\nor it is set incorrectly.\nThis MUST be set.");}
if((!userLength)||(userLength!=32)||(userLength>32))
			{alert("Maxlength should be set for userName, and it should be 32.\nPlease set the maxlenght attribute appropriately.");}
//end of file
