// Checks whether all questions have been answered/answered correctly.
// Also checks for screen resolution.
function register() {
	var message = "";
	var strIndex = document.regform.marketing.selectedIndex;
	if (strIndex > -1) {
		var str = document.regform.marketing.options[strIndex].value;
	}

	with (document.regform) {
		// If marketing question is answered.
		if (strIndex != -1 && strIndex != 0) {
			// Detect screen resolution. If it's incorrect give the user the chance to continue.
			if (screen.height > 480 && screen.width > 640) {
			//if (screen.height < 480 && screen.width < 640) {  // for testing
				var url = "/cgi-bin/ib/301_register.pl?marketing=" + str + "&browser=close";
				openIBRegWin(url,"ib");
				//location = "/cgi-bin/ib/301_register.pl?marketing=" + str + "&browser=close";
			} else {
				var msg = "The ideal screen resolution for National Internet Banking is 800 x 600." +
							"We have detected that you are running at a lower resolution than the " +
							"recommended setting. Using a lower screen resolution will require you " +
							"to scroll the screen to access the Internet Banking functions. " +
							"If you wish, you can change your screen resolution to optimise your " +
							"view of Internet Banking.\n\n" +
							"Do you wish to continue Internet Banking?";

				if (confirm(msg)) {
					var url = "/cgi-bin/ib/301_register.pl?marketing=" + str + "&browser=close";
					openIBRegWin(url,"ib");
					//location = "/cgi-bin/ib/301_register.pl?marketing=" + str + "&browser=close";
				} else {
					var url = "/cgi-bin/ib/301_register.pl?browser=close&marketing=" + str;
					openIBRegWin(url,"ib");
					//location = "/cgi-bin/ib/301_register.pl?browser=close&marketing=" + str;
				}
			}
		} else {
			alert("Please tell us where you heard about Internet Banking before clicking the \"Continue\" button.");
		}
	}
}

function startReg() {
	if (document.browserOptOut.cookieSet.checked) {
		setCookie("ibBrowser", "yes");
	}
			
	// Open register page.
	location = "/cgi-bin/ib/301_register.pl?browser=correct";
}

function openIBRegWin(url,winName) {
	// Open window to screen extents
	var wOpen;
	var sOptions;

	sOptions = 'directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,hotkeys=true';
	sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
	sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
	sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

	wOpen = window.open( '', winName, sOptions );
	wOpen.location = url;
	wOpen.focus();
	wOpen.moveTo( 0, 0 );
	if (document.layers) {
		wOpen.resizeTo( screen.availWidth - window.outerWidth, screen.availHeight  - window.outerHeight );
	} else {
		wOpen.resizeTo( screen.availWidth, screen.availHeight );
	}
}
