// JavaScript Document

function add_user_validation()
{
	/**************************Username validation***********************************************************/
		id=isWhitespace(document.form_registeration.user_name.value);
		if(id==true) 
		{
			alert("Enter username!");
			document.form_registeration.user_name.focus();
			return false;
		}
		else
		{
			var space=document.form_registeration.user_name.value.indexOf(" ");
			if(space!=-1)
			{
				alert("User Name should not Contain Spaces .Only letters and numbers are allowed ");
				document.form_registeration.user_name.focus();
				return false;
			}
		}
		if(isAlphaNumeric(document.form_registeration.user_name.value)==false) 
		{
			alert("Enter user Name in characters or numerics only!");
			document.form_registeration.user_name.focus();
			return false;
		}
		if(document.getElementById("user_name").value.length<3)
		{
			alert("User Name should have more than 3 characters in it!");
			document.getElementById("user_name").focus();
			return false;
		}
		if(document.getElementById("user_name").value.length>15)
		{
			alert("User Name cannot have more than 15 characters in it!");
			document.getElementById("user_name").focus();
			return false;
		}
		name		=	document.form_registeration.user_name.value;
		lower_id	= 	name.toLowerCase();
		if(lower_id.indexOf('nuswag')!=-1)
		{
			alert("User Name Should not contain word Nuswag");
			document.getElementById("user_name").focus();
			return false;
		}
	
	/************************* Password validation************************************************************/
		id=isWhitespace(document.form_registeration.user_password.value);			
		if(id==true) 
		{
			alert("Enter password!");
			document.form_registeration.user_password.focus();
			return false;
		}
		if(isAlphaNumeric(document.form_registeration.user_password.value)==false) 
		{
			alert("Enter password in characters or numerics only!");
			document.form_registeration.user_password.focus();
			return false;
		}
		if(document.form_registeration.user_password.value.length<6) 
		{
			alert("Password must be atleast 6 characters!");
			document.form_registeration.user_password.focus();
			return false;
		}
		if(document.form_registeration.user_password.value.length>12) 
		{
			alert("Password must be atmost 12 characters!");
			document.form_registeration.user_password.focus();
			return false;
		}

	/************************* Retype Password validation*****************************************************/
		id=isWhitespace(document.form_registeration.re_user_password.value);
		
		if(id==true) 
		{
			alert("Please retype password!");
			document.form_registeration.re_user_password.focus();
			return false;
		}
		if(isAlphaNumeric(document.form_registeration.re_user_password.value)==false) 
		{
			alert("Enter retype password in characters or numerics only!");
			document.form_registeration.re_user_password.focus();
			return false;
		}
		if(document.form_registeration.re_user_password.value.length<6) 
		{
			alert("Retyped password must be atleast 6 characters!");
			document.form_registeration.re_user_password.focus();
			return false;
		}
		if(document.form_registeration.re_user_password.value.length>12) 
		{
			alert("Retyped password must be atmost 12 characters!");
			document.form_registeration.re_user_password.focus();
			return false;
		}
	/************************* Comparng Password *************************************************************/
		if(document.form_registeration.user_password.value!=document.form_registeration.re_user_password.value) 
		{
			alert("Passwords Do Not Match, Retype Password!");
			document.form_registeration.re_user_password.focus();
			return false;
		}	
	
	/************************* Email validation***************************************************************/
		id=isWhitespace(document.form_registeration.user_email.value);
		if(id==true) 
		{
			alert("Please enter email address!");
			document.form_registeration.user_email.focus();
			return false;
		}	

		if((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form_registeration.user_email.value))==false) 
		{
			alert("Please enter valid email address!");
			document.form_registeration.user_email.focus();
			return false;
		}	
	/************************* Retype Email validation*******************************************************/
		if((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form_registeration.re_user_email.value))==false) 
		{
			alert("Please retype valid email address");
			document.form_registeration.re_user_email.focus();
			return false;
		}	
	/************************* Comparing Email****************************************************************/
		if(document.form_registeration.user_email.value!=document.form_registeration.re_user_email.value) 
		{

			alert("E-mails Do Not Match, Retype E-mail!");
			document.form_registeration.re_user_email.focus();
			return false;
		}
		
	//************************* Check User Acceptance of Terms And Condiotions**************************************/
		if(document.getElementById("check_agreement").checked==false) 
		{

			alert("You need to accept Terms And Conditions before becoming A User Of This Site...");
			document.getElementById("check_agreement").focus();
			return false;
		}
return true;
}