/*-----------------------------------------------------------------------
Created by: Neeraj Kumar
Created date: 23-Nov-06
File description: Add Member Form
Special instructions-notes:Java script Validation
Tables used:None
Stored procedures:None
Triggers used:None
-----------------------------------------------------------------------*/

function Validate(theForm)
{
	
	
	var errMesg = "";
	var displayMesg = "";
	
	var loginName = theForm.userid.value = theForm.userid.value.toLowerCase();

	//Validate the login name
	if ( !isCharsInBag( loginName, "abcdefghijklmnopqrstuvwxyz0123456789.-_" ))
	{
		errMesg += "Login name has invalid characters.\n" ;
	}
	else if ( loginName.length < 3 )
	{
		errMesg += "Login name must be 3 or more characters.\n" ;
	}
	else
	{
		var count;
		for (count=0; count < loginName.length; count++)
		{
			if (loginName.charAt(count) == "_")
			{
				if (loginName.charAt(count+1) == "_")
				{
					errMesg += "Login name may not contain more than one consecutive underscore.\n";
				}
			}
		}
	}


	//Check for password
	if ( theForm.password.value.length < 6 || theForm.password.value.length > 12)
		{
		errMesg += "Password must be 6-12 characters.\n";
		}	

if (theForm.retypepassword)
	{	
	if ( theForm.password.value != theForm.retypepassword.value )
		{
		errMesg += "Your Password do not match. Please retype and try again.\n" ;
		}
}
	
	
	
 	var Q = ""; // this block determines lifespan of Q
	{
	
	if (isWhitespace(theForm.fname.value))
		{
			Q += "  First Name\n";
			theForm.fname.focus();
		}
else if(!isCharsInBag(theForm.fname.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' "))
		{
		errMesg += "First Name contains Invalid Characters\n";
		}
	if (isWhitespace(theForm.lname.value))
		{
			Q += "  Last Name\n";
		}
else if(!isCharsInBag(theForm.lname.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' "))
		{
		errMesg += "Last Name contains Invalid Characters\n";
		}

	if (isWhitespace(theForm.emailadd.value))
		{
			Q += "  E-mail Address\n";
		}	
		
		else if(echeck(theForm.emailadd.value))
			{
			   errMesg += "Invalid Email ID\n";
			}	
		else if(!isCharsInBag( theForm.emailadd.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
			{
				errMesg += "Email ID contains Invalid Characters\n";
			}




/*

if (isWhitespace(theForm.tel.value))
		{
			Q += "  Telephone\n";
		}			
	else if(!isCharsInBag(theForm.tel.value, "0123456789- "))
		{
		errMesg += "Telephone Number contains Invalid Characters\n";
		}

    
	
	if (isWhitespace(theForm.fax.value))
		{
			Q += "  Fax\n";
		}

	else if(theForm.fax.value!="" && !isCharsInBag(theForm.fax.value, "0123456789- "))
		{
		errMesg += "Fax contains Invalid Characters\n";
		}
		

    if (isWhitespace(theForm.company.value))
		{
			Q += "  Company\n";
	}
	*/
	if (isWhitespace(theForm.userid.value))
		{
			Q += "  User Id\n";
		}	



	if (isWhitespace(theForm.password.value))
		{
			Q += "  Password\n";
		}	
	if (isWhitespace(theForm.retypepassword.value))
		{
			Q += "  Retype Password\n";
		}	
	
	if (theForm.confirmpwd)
	{	
	if (isWhitespace(theForm.confirmpwd.value))
		{
			Q += "  Retype Password\n";
		}	
	
}
		

	if (theForm.address.value=="")
		{
			Q += "  Address\n";
		}		
		
	if(theForm.address.value!="" && theForm.address.value.length>500)
		{
			errMesg += "Address should not be greater than 500 characters\n";
		}
    	
				
	
   if (isWhitespace(theForm.city.value))
		{
			Q += "  City\n";
		}
	if (isWhitespace(theForm.zipcode.value))
		{
			Q += "  Zip Code\n";
		}	
if (theForm.state.value=="")
		{
			Q += "  State\n";
		}
	
		
		
		

if (theForm.chkterm)
{		
	if (theForm.chkterm.checked==false)	
		{
			Q += "  Terms and Conditions\n";
		}
}
			
	if ( Q.length > 0 )
		{
		displayMesg = "Please provide Valid values for\n" + Q ;
		}	
	}
 
	
	if (errMesg == "" && displayMesg == "")
	{
		return true;
	}
	else
	{
		if(displayMesg!="")
			{
				alert(displayMesg);
				return false;			
			}
			else
			{
				alert(errMesg);
				return false;
			}	
	}
}

