// 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 userContactValidation()						//user Registration form validation
{
// Check for Contact Name field
	var checkUser=Trim(document.userContactfrm.contactname.value);
	document.userContactfrm.contactname.value=checkUser;
	
	if(document.userContactfrm.contactname.value	== "")
	{
		alert("Contact name must not be blank.");
		document.userContactfrm.contactname.focus();		
		return	false;
	}
	
// Check for Business Name field
	var checkbname=Trim(document.userContactfrm.businessname.value);
	document.userContactfrm.businessname.value=checkbname;
	
	if(document.userContactfrm.businessname.value	== "")
	{
		alert("Business name must not be blank.");
		document.userContactfrm.businessname.focus();		
		return	false;
	}
	
// Check for Business Address field
	var checkUser=Trim(document.userContactfrm.businessaddress.value);
	document.userContactfrm.businessaddress.value=checkUser;
	
	if(document.userContactfrm.businessaddress.value	== "")
	{
		alert("Address must not be blank.");
		document.userContactfrm.businessaddress.focus();		
		return	false;
	}

// Check for Telephone
	if(document.userContactfrm.telephone.value	== "")
	{
		alert("Please provide your telephone number.");
		document.userContactfrm.telephone.focus();
		return false;
	}
	
	/*var x = document.userContactfrm.telephone.value;
	if(isNaN(x)||x.indexOf("")!=-1)
    {
    	alert("Enter phone number in numeric value.");
		document.userContactfrm.telephone.value="";
		document.userContactfrm.telephone.focus();
        return false;
    }*/

// Check for Mobile
	if(document.userContactfrm.mobile.value	== "")
	{
		alert("Please provide your mobile number.");
		document.userContactfrm.mobile.focus();
		return false;
	}
	
	/*var y = document.userContactfrm.mobile.value;       
	if(isNaN(y)||y.indexOf("")!=-1)
    {
    	alert("Enter mobile number in numeric value.");
		document.userContactfrm.mobile.value="";
		document.userContactfrm.mobile.focus();
        return false;
    }
*/

// Check for E-mail field
	var checkUser=Trim(document.userContactfrm.email.value);
	document.userContactfrm.email.value=checkUser;
	
	if(document.userContactfrm.email.value	== "")
	{
		alert("E-mail must not be blank.");
		document.userContactfrm.email.focus();		
		return	false;
	}
	
	// test if valid email address, must have @ and .
	var checkEmail = "@.";
	var checkStr = document.userContactfrm.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.userContactfrm.email.focus();
		return(false);
	}
	
// Check for Wesite Address
	var checkUser=Trim(document.userContactfrm.websiteaddress.value);
	document.userContactfrm.websiteaddress.value=checkUser;
	
	return true;
}