//****************************
//* Login JavaScript Library *
//****************************
function ValidateForm(){
	var form=document.frmLogin;
	trimForm(form);
	if (isEmpty(form.txtUsername.value)){
		alert("Please enter a username.");
		form.txtUsername.select();
		form.txtUsername.focus();
		return false;
		}
	if (isEmpty(form.txtPassword.value)){
		alert("Please enter a password.");
		form.txtPassword.select();
		form.txtPassword.focus();
		return false;
	}
	return true;
}

function RequestPassword(){
	var form=document.frmLogin;
	trimForm(form);
	if(isEmpty(form.txtUsername.value)){
		alert("Please enter your registered email and then\nclick the FORGOT PASSWORD link.");
		form.txtUsername.focus();return;
	}
	else{
		location="login.asp?action=password&email="+form.txtUsername.value;
	}
}

function ValidateContact(form){
	var e;
	trimForm(form);
	e=form.txtFrom;
	if (isEmpty(e.value)||!isEmail(e.value)){
		alert("Please enter a valid email address.");
		e.select();e.focus();
		return false;
	}
	return true;
}

function ValidateInquiry(form){
	var e;
	trimForm(form);
	e=form.txtFName;
	if(isEmpty(e.value)){
		alert("Please enter contact first name.");
		e.select();e.focus();return false;
	}
	e=form.txtLName;
	if(isEmpty(e.value)){
		alert("Please enter contact last name.");
		e.select();e.focus();return false;
	}	
	e=form.txtEmail;
	if (isEmpty(e.value)||!isEmail(e.value)){
		alert("Please enter a valid email address.");
		e.select();e.focus();
		return false;
	}
	e=form.txtPhone;
	e.value=convPhone(e.value);
	if(isEmpty(e.value)){
		alert("Please enter contact phone number.");
		e.select();e.focus();return false;
	}	
	return true;
}

function ValidatePassword(form){
	var password=form.txtPassword;
	var confirm=form.txtConfirm;
	trimForm(form);
	//validate password using account policy
	var s=password.value
	if(isEmpty(s)||s.search(/\s/)!=-1){
		alert("Password can not be empty or contain spaces. Please enter a valid password.");
		password.select();password.focus();return false;
	}
	if(s.length<parseInt(form.hdnPwdLength.value)){
		alert("Password does not meet the minimum length requirement. Please enter a valid password.");
		password.select();password.focus();return false;
	}
	var iMatch=0;
	var vMatch=s.match(/[A-Z]/g);
	if(vMatch){iMatch=vMatch.length;}else{iMatch=0;}
	if(iMatch<parseInt(form.hdnPwdUpper.value)){
		alert("Password does not meet the minimum uppercase requirement. Please enter a valid password.");
		password.select();password.focus();return false;
	}
	vMatch=s.match(/[a-z]/g);
	if(vMatch){iMatch=vMatch.length;}else{iMatch=0;}
	if(iMatch<parseInt(form.hdnPwdLower.value)){
		alert("Password does not meet the minimum lowercase requirement. Please enter a valid password.");
		password.select();password.focus();return false;
	}
	vMatch=s.match(/[0-9]/g);
	if(vMatch){iMatch=vMatch.length;}else{iMatch=0;}
	if(iMatch<parseInt(form.hdnPwdNum.value)){
		alert("Password does not meet the minimum numeric requirement. Please enter a valid password.");
		password.select();password.focus();return false;
	}
	vMatch=s.match(/[`~!@#\$%\^&\*\|\?\\\/\{\}\[\]\(\)\+\-\=_:\;\"\',.\<\>]/g);
	if(vMatch){iMatch=vMatch.length;}else{iMatch=0;}
	if(iMatch<parseInt(form.hdnPwdChar.value)){
		alert("Password does not meet the minimum special character requirement. Please enter a valid password.");
		password.select();password.focus();return false;
	}
	if(confirm.value!=password.value){
		alert("Please re-enter your password for consistency.");
		confirm.select();confirm.focus();return false;
	}
	return true;
}

function UpdatePassword(form){
	if(ValidatePassword(form)){
		form.action="../account/account.asp?form=password&action=update";
		form.submit();
	}
}

