//====================================================================================================
//	File Name		:	register.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Client side validation in JavaScript.
//	Creation Date	:	25-April-2006
//====================================================================================================

//====================================================================================================
//	Function Name	:	Add_Form_Submit()
//	Purpose			:	This function will check inputted field by user are valid or not.
//	Return			:	none
//----------------------------------------------------------------------------------------------------
function Add_Form_Submit(frm)
{
	with(frm)
    {
		if(!IsEmpty(login_name, 'Please, enter the Login Name.'))
		{
			return false;
		}
		
		if(login_name.value.length < 3 || login_name.value.length > 12)
		{
			alert("Login Name should be minimum 3 and maximum 12 Characters");
			login_name.focus();
			return false;
		}

		if(!IsValidString(login_name, 'Please Enter, valid Login Name.'))
		{
			return false;
		}

		if(!IsEmpty(password, 'Please, enter the Password.'))
		{
			return false;
		}
		
		if(password.value.length < 6 || password.value.length > 12)
		{
			alert("Password should be minimum 6 and maximum 12 Characters");
			password.focus();
			return false;
		}

		if(!IsEmpty(conpassword, 'Please confirm your password.'))
		{
			return false;
		}
		if(password.value != conpassword.value)
		{
			alert("Password and confirm password should be same");
			conpassword.focus();
			return false;
		}		

		if(!IsEmpty(security_answer, 'Please, enter the Security Answer.'))
		{
			return false;
		}
		
		if(!IsEmpty(first_name, 'Please, enter the First Name.'))
		{
			return false;
		}
		if(!IsEmpty(last_name, 'Please, enter the Last Name.'))
		{
			return false;
		}
		if(!IsEmpty(address, 'Please, enter the Street Address.'))
		{
			return false;
		}
		if(!IsEmpty(city, 'Please, enter the Suburb.'))
		{
			return false;
		}
		
		if(!IsEmpty(zip, 'Please, enter the Post Code.'))
		{
			return false;
		}	
		if(!IsZip(zip, 'Post code should be 4 digits only.'))
		{
			return false;
		}	
		if(!IsEmpty(phone, 'Please, enter the Phone.'))
		{
			return false;
		}
		if(!IsEmpty(email_name, 'Please Enter Email.'))
		{
			return false;    
		}
		if(!IsEmail(email_name, 'Please Enter Valid Email.'))
		{
			return false;
		}
		if(!IsEmpty(security_code, 'Please Enter Security Code.'))
		{
			return false;    
		}
		/*if(!allDigits(client_weight.value))
		{
			alert('Please, enter valid Weight.');
			return false;
		}*/
		return true;
    }
}
//====================================================================================================
//	Function Name	:	Edit_Form_Submit()
//	Purpose			:	This function will check inputted field by user are valid or not.
//	Return			:	none
//----------------------------------------------------------------------------------------------------
function Edit_Form_Submit()

{
	
	with(document.frmRegister)
    {
    	
		if(!IsEmpty(first_name, 'Please, enter the First Name.'))
		{
			return false;
		}
		
		if(!IsEmpty(last_name, 'Please, enter the Last Name.'))
		{
			return false;
		}
		
		if(!IsEmpty(address, 'Please, enter the Address.'))
		{
			return false;
		}
		if(!IsEmpty(city, 'Please, enter the City.'))
		{
			return false;
		}
		if(!IsEmpty(zip, 'Please, enter the Post Code.'))
		{
			return false;
		}	
		if(!IsZip(zip, 'Post code should be 4 digits only.'))
		{
			return false;
		}	
		if(!IsEmpty(phone, 'Please, enter the Phone.'))
		{
			return false;
		}
		if(!IsEmpty(email_name, 'Please Enter Email.'))
		{
			return false;    
		}
		if(!IsEmail(email_name, 'Please Enter Valid Email.'))
		{
			return false;
		}		
		return true;
    }
}
//====================================================================================================
//	Function Name	:	Add_Click()
//	Purpose			:	This function will executed when user submits a form. It checks validity of 
//						every field in the form.
//	Parameters		:	frm  - form name
//	Return			:	true or false
//----------------------------------------------------------------------------------------------------
function Add_Click()
{
	with(document.frmRegister)
	{
		Action.value = "Add";
		submit();
	}
}
//====================================================================================================
//	Function Name	:	Edit_Click()
//	Purpose			:	This function will executed when user submits a form. It checks validity of 
//						every field in the form.
//	Parameters		:	frm  - form name
//	Return			:	true or false
//	Author			:	Nitin Rana
//----------------------------------------------------------------------------------------------------
function Edit_Click(User_Auth_Id)
{
	with(document.frmRegister)
	{
		Action.value = "Update";
		user_auth_id.value = User_Auth_Id;		
		submit();
	}
}