//This script copyright 2002 by Don Kent, eShopHost.net
//You may not use this script without prior permission
// YIBassLogOnExisting.js Issue 1, 07/06/02, D.Kent

function validate (Selection) {
// called on submit to validate form fields
	var i, name, FormError = 0, AddressPC, AssPW, AssPWi;
	for (i=0; i < document.forms[0].elements.length; i++) {
		name = document.forms[0].elements[i].name;
		if ((name == "NameFirst") || (name == "AddressPC") || ((name == "AssPW") && (Selection != "PasswordRemind"))) {
			if (document.forms[0].elements[i].value == "") {FormError = 1;}
		}
		if (name == "AddressPC") {AddressPC = document.forms[0].elements[i].value;}
		else if (name == "AssPW") {
			AssPW = document.forms[0].elements[i].value;
			AssPWi = i;
		};
	}
	if (FormError == 1) {
		if (Selection != "PasswordRemind") {
			alert ("You must fill in every box before you can log on!");
		}
		else {
			alert ("You still need to provide a valid First Name and Home Post Code before your password can be provided");
		};
		// No access to Form element in NOF, so the Submit button is just a button
	}
	else {
		// Ready to Submit
		// encrypt
		var PWarray = new Array (AssPW.length);
		var c = new Number;
		for (i = 0; i < AssPW.length; i++) {
			c = AssPW.charCodeAt(i) + AddressPC.charCodeAt(i%AddressPC.length);
			PWarray[i] = "" + c;
		}
		document.forms[0].elements[AssPWi].value = PWarray.join (",");
		// No access to Form element in NOF, so the Submit button is just a button - otherwise: return true;
		document.forms[0].elements["Submit"].value = Selection;
		var PleaseWaitElement = document.getElementById("PleaseWaitLYR");
		if (Selection != "PasswordRemind"){
			PleaseWaitElement.style.visibility = "visible";
		}
		document.forms[0].submit();
	}
}		