// JavaScript Document
//  Javascripts - Scripts on the productArea - sign in page
// GF 

// Check the Email and password when the user is signing in
function initSignIn() {

	if(document.getElementById) {
		
		//Function to validate registration input - Moved from old AMC javascript.asp file
		function SignInFormCheck(){
			var varFrmSignIn		= document.getElementById('signinForm');
			
			var intValidEmail = varFrmSignIn.txtContactUser.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.us)|(\.biz)|(\.coop)||(\..{2,2}))$)\b/gi);
			if(!intValidEmail){
				window.alert("Please enter a valid email address.");
				//varFrmSignIn.txtContactUser.focus();
				return false;
			}
			
			// not sure if this was enforced so I am not going to enforce it
			//if(varFrmSignIn.txtPassword.value.length < passwordMinLength || varFrmSignIn.txtPassword.value.length > passwordMaxLength ){
			//	window.alert('Please confirm that your password is between '+passwordMinLength+' and '+passwordMaxLength +' characters.');
			//	return false;
			//}
			
			if(varFrmSignIn.txtContactPassword.value.length < 1 || varFrmSignIn.txtContactPassword.value.length > 20 ){
				window.alert('Please confirm that your password is valid.');
				//varFrmSignIn.txtContactPassword.focus();						
				return false;
			}						
			varFrmSignIn.submit();
		}
		
		document.getElementById('signinSubmitBtn').onclick	= SignInFormCheck;	
					
	}

}

// Function to show and hide the forgot password form
function showPasswordForm() {
	var forgotPassDiv = document.getElementById('forgotPasswordDiv');
	
	if (forgotPassDiv.style.display == 'none') {
		forgotPassDiv.style.display = 'block';
	} else {
		forgotPassDiv.style.display = 'none';
	}
	
	var forgotPasswordForm = document.getElementById('forgotPasswordForm');
	//forgotPasswordForm.txtContactUser.focus();
	
}

//Function to validate the email address when requesting password help
function ForgotPasswordCheck(){
	
	var varFrmForgotPassword = document.getElementById('forgotPasswordForm');
	
	var intValidEmail = varFrmForgotPassword.txtContactUser_ForgotPassword.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.us)|(\.biz)|(\.coop)||(\..{2,2}))$)\b/gi);
	if(!intValidEmail){
		window.alert("Please enter a valid email address.");
		//varFrmForgotPassword.txtContactUser_ForgotPassword.focus();
		return false;
	}									
	varFrmForgotPassword.submit();
}


// Initialize the forgot password events
function initForgotPassword() {

	if(document.getElementById) {
		
		document.getElementById('closePassDiv').onclick				= showPasswordForm;
		document.getElementById('forgotPassLink').onclick			= showPasswordForm;
		document.getElementById('forgotPasswordSubmitBtn').onclick	= ForgotPasswordCheck;	
		
	}
}

// Load the functions that require initialization
function initializePage() {
	initSignIn();
	initForgotPassword();
}

// Initialize the events on the page
window.onload = initializePage;



