﻿function validateForm(oElement) {
	var valid = DDM.Validation;

	var formElements = new Array();
	formElements[0] = new valid.formElementsToValidate('mainMaster_cphMain_lvAnaymousView_lgnMain_UserName', "You must enter an email address");
	formElements[1] = new valid.formElementsToValidate('mainMaster_cphMain_lvAnaymousView_lgnMain_Password', "You must enter a User Name");

	var msg = valid.submitValidation(formElements);

	if (msg != "") {
		alert(msg);
		valid.setFocusFirstField();
		return false;
	} else {
		return true;
	}
}

function GetEmailAddress(e) {
	$('SendPassword').style.display = 'none';
	$('getEmail').style.display = 'block';
	//$(e).update("<b>Enter your email address:&nbsp;</b><input tabindex=\"0\" type=\"text\" id=\"txtEmailAddr\" name=\"txtEmailAddr\" onChange=\"return DDM.Validation.isEmailAddr(this);\" />&nbsp;<input type=\"button\" value=\"Send Password\" onclick=\"SendPassword($('txtEmailAddr'));\" />");
	$('txtEmailAddr').focus();
}

function SendPassword(e) {
	$('getEmailMsg').style.display = 'block';
	if ($('txtEmailAddr').value == '') {
		$('getEmailMsg').update("<span style=\"color:#ff0000\">You must enter a email address.</span>");
		$('getEmailMsg').style.display = 'block';
	} else {
		var emailAddr = e.value;
		$('getEmailMsg').update("<img src=\"images/spinner.gif\">");
		PageMethods.SendPassword(emailAddr, SendPassword_callback, onFaliure); // asynchronous call
	}
}

// This method will be called after the method has been executed
// and the result has been sent to the client.
function SendPassword_callback(response) {
	$('SendPassword').style.display = 'none';
	$('getEmail').style.display = 'none';
	$('getEmailMsg').innerHTML = "Your user name and password has been\nsent to your email address";
	$('getEmailMsg').style.display = 'block';
}

function onFaliure(error) {
	var exType = error.get_exceptionType();
	switch(exType) {
		case 'System.ApplicationException':
			alert(error.get_exceptionType() + '\n' + error.get_message());
			break;
		default:
			alert(error.get_message());
			break;
	}
	$('getEmail').style.display = 'none';
	$('getEmailMsg').innerHTML = "<span style=\"color:#ff0000;\">We were not able to send you your email with your password</span>";
	$('getEmailMsg').style.display = 'block';
	$('getEmail').style.display = 'block';
}


/*******************
add onLoad events
*******************/
Event.observe(window, 'load', function() {if (window.setFocus) window.setFocus();});

function setFocus() {
	//if ($('txtEmailAddr')) {
	//	$('txtEmailAddr').focus()
	//} else {
		if ($("mainMaster_cphMain_lvAnaymousView_lgnMain_UserName")) {
			$("mainMaster_cphMain_lvAnaymousView_lgnMain_UserName").focus();
		}
	//}
}

