//****************************************************************
// Company Registration Form Validation : JavaScript Validation
//****************************************************************
function RegisterValidator(theform)
{   
// Company Name
		if(theform.company_name.value=="")
		{	
		alert("Please Provide Your Company Name.");
		theform.company_name.focus();
		return (false);
		}//Company Name Validation

// Contact Person
		if (theform.contact_person.value=="")
		{
		alert("Please Provide Name of Contact Person.");
		theform.contact_person.focus();
		return false;
		}
// Designation
		if (theform.designation.value=="")
		{
		alert("Please Provide Your Designation in The Company.");
		theform.designation.focus();
		return false;
		}

// Company Address
		if (theform.address.value=="")
		{
		alert("Please Provide Your Company Address.");
		theform.address.focus();
		return false;
		}
		
// City Name
		if (theform.city.value=="")
		{
		alert("Please Provide City Name In Which Your Company Is.");
		theform.city.focus();
		return false;
		}
		
// PIN Code
		if (theform.pin.value=="")
		{
		alert("Please Provide Pin Code.");
		theform.pin.focus();
		return false;
		}
// PIN-Numeric
   var checkOK = "0123456789";
	var checkStr = theform.pin.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
	if (!allValid)
	{
	alert("PLease Enter Only Numbers For Pin Code.");
	theform.pin.focus();
	return (false);
	}

//State Validation
	if (theform.state.value=="")
    {
    alert("Please Provide In Which State Your Comapny Is.");
	theform.state.focus();
    return false;
    }

// Phone No
		if (theform.phone.value=="")
		{
		alert("Please Provide Contact Telephone No.");
		theform.phone.focus();
		return false;
		}// Phone No Validation-1		

   
    var checkOK = "0123456789";
	var checkStr = theform.phone.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}

	if (!allValid)
	{
	alert("PLease Enter Only Numbers In Phone No. Field.");
	theform.phone.focus();
	return (false);
	}
 		
//Mobile Number
	if(theform.mobile.value == "") 
	   {
	   alert("Please Provide Mobile No for Quick Contacts.");
	   theform.txtMobile.focus();
	   return false;
	   }	   

	//Mobile No Field Only Numbers Validation
	var checkOK = "0123456789";
	var checkStr = theform.mobile.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
	if (!allValid)
	{
	alert("Please Enter Only Numbers In Mobile No. Field.");
	theform.mobile.focus();
	return (false);
	}
	
//EMAIL ID VALIDATION
	if(theform.email.value == "") 
	   {
	   alert("Please Provide Your Email ID. Prefer Company Email ID.");
	   theform.email.focus();
	   return false;
	   }
   
if (theform.email.value != "")
	{
	// Test if Valid Email Address, Must have @ and .
	var checkEmail = "@.";
	var checkStr = theform.email.value;
	var EmailValid = false;
	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 Valid Email ID.");
		theform.email.focus();
		return (false);
		}

	
//Web Site URL
	if (theform.website.value=="")
    {
    alert("Please Provide WebSite URL. If No WebSite Enter 'NA'.");
	theform.website.focus();
    return false;
    }

 
//Brief Details About Company
   if (theform.description.value=="")
   {
	alert("Enter Provide Brief Details About Company.");
	theform.description.focus();
	return false;
   } 
   
//Network/ Branch List
   if (theform.branches.value=="")
   {
	alert("Enter Provide Network/ Branch Details.");
	theform.branches.focus();
	return false;
   }   
}