var errors = new Array();
var i = 0;
	
function regValidation()
{
	errors.length = 0;
	i = 0;
	var FName  = document.getElementById('txtFName');
	var LName  = document.getElementById('txtLName');
	var Email  = document.getElementById('txtEmail');
	var User   = document.getElementById('txtUserName');
	var pass   = document.getElementById('txtPass');
	var cpass  = document.getElementById('txtCPass');
	var sQues  = document.getElementById('securityQuestion');
	var sAns   = document.getElementById('txtAns');
	
	isEmpty(FName, "First Name can not be empty");
	isEmpty(LName, "Last Name can not be empty");
	isEmpty(User, "User name can not be empty");
	passLen(pass, "Password length can not be less than ",8);
	emailValidator(Email,"Please Enter a valid Email Address");
	isEmpty(sQues, "Please choose a security question");
	isEmpty(sAns, "Answer of security question can not be empty");
	checkEqual(pass,cpass,"Confirm password does not match Password");
	
	return errors; 
}

function checkEqual(elem,elem1, helperMsg)
{
	tmp  = trim(elem.value);
	tmp1 = trim(elem1.value);
	if(tmp != tmp1)
	{
		errors[i] = helperMsg;
		i++; 
	}

}

function isEmpty(elem, helperMsg)
{
	tmp = trim(elem.value);
	if(tmp.length == 0)
	{
		errors[i] = helperMsg;
		i++; 
	}

}

function passLen(elem, helperMsg,len)
{
	tmp = trim(elem.value);
	if(tmp.length < len)
	{
		errors[i] = helperMsg + len + " charachters";
		i++; 
	}

}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){

	}else{
		errors[i] = helperMsg;
		i++; 
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}


