//*************All function of JavaScript for Registration Form************

// Function for Login Validatio

// Function for removing first and last spaces
function Trim(str)
{
    while (str.substring(0,1) == ' ') // check for white spaces from beginning
    {
        str = str.substring(1, str.length);
    }
	
    while (str.substring(str.length-1, str.length) == ' ') // check white space from end
    {
        str = str.substring(0,str.length-1);
    }
    return str;
}

// Function for All Validation on Form Submit
function userUpdateValidation()						//user Registration form validation
{
// Check for user_name field
	
	
	
// Check for E-mail
	var checkEmail=Trim(document.userRegistration.email.value);
	document.userRegistration.email.value=checkEmail;
	
	if (document.userRegistration.email.value == "")
	{
		alert("Please enter a value for the \"Email\" field.");
		document.userRegistration.email.focus();
		return(false);
	}

	// test if valid email address, must have @ and .

	var checkEmail = "@.";
	var checkStr = document.userRegistration.email.value;
	var EmailValid = false;0000000000
	var EmailAt = false;
	var EmailPeriod = false;

	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);

				for (j = 0;  j < checkEmail.length;  j++)

				{

					if (ch == checkEmail.charAt(j) && ch == "@")

						EmailAt = true;

					if (ch == checkEmail.charAt(j) && ch == ".")

						EmailPeriod = true;

		  			if (EmailAt && EmailPeriod)

				break;

      	  		if (j == checkEmail.length)

				break;

			}



				// if both the @ and . were in the string

				if (EmailAt && EmailPeriod)

				{

					EmailValid = true

					break;

				}

		}

			

			if (!EmailValid)

				{

					alert("Invalid email ID ! Please enter your valid email ID.");

					document.userRegistration.email.focus();

					return(false);

				}

if (document.userRegistration.state_id.value == "")

		{

			alert("Please select your state.");

			document.userRegistration.state_id.focus();

			return(false);

		}
		
		
// Check for Addreess field

	var checkAddr=Trim(document.userRegistration.address1.value);
	document.userRegistration.address1.value=checkAddr;
	
	if(document.userRegistration.address1.value	==	""	&& document.userRegistration.address2.value	==	"")
	{
		alert("Please provide your address");
		document.userRegistration.address1.focus();
		return false;
	}
	
// Check for Mobile
	if(document.userRegistration.mobile.value	== "")
	{
		alert("Please provide your mobile number");
		document.userRegistration.mobile.focus();
		return false;
	}
	
	var y = document.userRegistration.mobile.value;       
	if(isNaN(y)||y.indexOf(" ")!=-1)
    {
    	alert("Enter Mobile no in numeric value");
		document.userRegistration.mobile.value="";
		document.userRegistration.mobile.focus();
        return false;
    }
    if (y.length>10 || y.length <= 9)
    {
        alert("Enter Mobile no in 10 digits.");
		document.userRegistration.mobile.focus();
        return false;
    }
    
	
// Check for STD code
	

	return true;
}// JavaScript Document
