﻿function BetaValidateLogin(userNameId,passwordId,errorId,btnId,imgId)
{
	var username = $(userNameId).val(); var password = $(passwordId).val(); var regExpression = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/; var errorMsgSelector = errorId; var regex = new RegExp(regExpression);
	if (username.length == 0)
	{ $(errorMsgSelector).html("* Please enter an email address."); $(userNameId).focus(); return false; }						
	if (password.length == 0)
	{ $(errorMsgSelector).html("* Please enter a password."); $(passwordId).focus(); return false; }						
	if (!regex.test(username))
	{ $(errorMsgSelector).html("* Incorrect email address format."); $(userNameId).focus(); return false; }

	$(btnId).hide();
	$(imgId).show();
	return true;
}

function BetaSignIn(userNameId,passwordId,errorId,btnId,imgId,successFunc,errorFunc)
{
	$(errorId).html('');
	var isValid = BetaValidateLogin(userNameId,passwordId,errorId,btnId,imgId);
	if (isValid)
	{
		var username = $(userNameId).val(); 
		var password = $(passwordId).val();
		DG_Web.Services.SiteAjaxService.Login(username, password, false, 0, window.location.toString(), successFunc, errorFunc);
	}
}

function ValidateEmailCapture(emailId,errorId)
{
	var email = $(emailId).val(); var regExpression = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/; var errorMsgSelector = errorId; var regex = new RegExp(regExpression);

	$(errorMsgSelector).html('');
	if (email.length == 0)
	{ $(errorMsgSelector).html("* Please enter an email address."); $(emailId).focus(); return false; }
	if (!regex.test(email))
	{ $(errorMsgSelector).html("* Incorrect email address format."); $(emailId).focus(); return false; }
	
	return true;
}

function SubmitEmail(emailId,errorId,successFunc,errorFunc)
{
	if (ValidateEmailCapture(emailId,errorId))
	{
		var email = $(emailId).val();
		if (email.length > 0)
		{
			DG_Web.Services.SiteAjaxService.SubmitBetaEmail(email, successFunc, errorFunc);
		}
	}
}
