function initPage() {
	// focus
	var email = document.getElementById("emailID");
	email.focus();
}

function validateCallback(answer) {
	if (!answer) {
		alert("Could not continue because the server was not available.");
		return;
	}
	if (answer.success) {
		// use answer.text here to get text data, or
		// use answer.xml here to get a XMLDocument
		// (only if your server sent XML back)
		var response = swEval(answer.text);
		if (response.failedI18nKey) {
			alert(response.failedI18nKey);
			return;
		}
		//alert("response:" + response.toSource());
		alert("Your password has been emailed to:" +
			response.keyValueM.email);
		var emailID = document.getElementById("emailID").value;
		window.location = "/sw2/index.html?userID=" + encodeURIComponent(emailID);
	}
	else {
		alert("The server seems to be unavailable and your session has expired.");
	}
}

function validateCaptcha() {
	try {
		//alert("validateCaptcha()");
		var emailID = document.getElementById("emailID").value;
		if (!emailID || emailID.length === 0) {
			alert("Missing emailID");
			return;
		}
		var re = /[^0-9]/;
		if (re.test(emailID)) {
			if (emailID.indexOf("@") < 1) {
				alert("Missing '@' symbol in your email.\n \nUse the email you signed up with\nor your ScheduleWorld ID (number).");
				return;
			}
		}
		var captchaGuess = document.getElementById("captchaGuess").value;
		if (!captchaGuess || captchaGuess.length === 0) {
			alert("Missing captcha value.");
			return;
		}
	
		var encUser = encodeURIComponent(emailID);
		var validateCaptcha = {};
		validateCaptcha.captchaGuess = captchaGuess;
		var xml = Sarissa.xmlize(validateCaptcha, "validateCaptcha");
	
		var url = "/sw2/commandV3";
		var rpc = new DlRPC( {
			url			: url,
			callback	: validateCallback,
			args		: { user: encUser },
			data		: xml } );
		rpc.call();
	} catch(ex) {
		alert("Failed validateCaptcha():" + ex);
	}
}

