//****************************************************************
// Function for Checking/ Validation of Company Registration Form
// Developer: Avanish Kumar
// Email: Kumar.Avanish@Gmail.com
//****************************************************************
function reg_Validator(theform)
{   
	if(theform.txtCompName.value=="")
		{	
		alert("Please Provide Company Name.");
		theform.txtCompName.focus();
		return (false);
		}//Company Name Validation


		if (theform.txtContPers.value=="")
		{
		alert("Please Provide Name of Contact Person.");
		theform.txtContPers.focus();
		return false;
		}//Contact Person Name Validation

		if (theform.txtPhone.value=="")
		{
		alert("Please Provide Contact Telephone No.");
		theform.txtPhone.focus();
		return false;
		}// Phone No Validation-1		

   
    var checkOK = "0123456789";
	var checkStr = theform.txtPhone.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.txtPhone.focus();
	return (false);
	}//Phone No Validation No-2 Final
 		

	if(theform.txtMobile.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.txtMobile.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.txtMobile.focus();
	return (false);
	}//Mobile No. Validation No-2 Final
	

	//EMAIL ID VALIDATION
	if(theform.txtEmail.value == "") 
	   {
	   alert("Please Provide Email ID for Better Communication.");
	   theform.txtEmail.focus();
	   return false;
	   }
   
	if (theform.txtEmail.value != "")
	{
	// Test if Valid Email Address, Must have @ and .
	var checkEmail = "@.";
	var checkStr = theform.txtEmail.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("Please Enter Valid Email ID.");
		theform.txtEmail.focus();
		return (false);
		}
// EMAIL VALIDATION FINISED

//Address
	if (theform.txtAddress.value=="")
    {
    alert("Please Provide Complete Address.Its Must to Get Listed.");
	theform.txtAddress.focus();
    return false;
    }

//City
	if (theform.txtCity.value=="")
    {
    alert("Please Provide City Name.Its Must to Get Listed.");
	theform.txtCity.focus();
    return false;
    }

//State
	if (theform.txtState.value=="")
    {
    alert("Please Provide State Name.");
	theform.txtState.focus();
    return false;
    }

//ZIPPostal
   if (isNaN(theform.txtZipPostal.value))
    {
	alert("Please Enter Only Numbers in Zip-Postal Code Field.");
	theform.txtZipPostal.focus();
	return false;
    }  
           	 
 //ZIP/ POSTAL
	if (theform.txtZipPostal.value=="")
    {
    alert("Please Provide ZIP/ Postal Code Name.");
	theform.txtZipPostal.focus();
    return false;
    }
	
//State
	if (theform.txtCountry.value=="")
    {
    alert("Please Provide Country Name.");
	theform.txtCountry.focus();
    return false;
    }

 
//Services - Check Box

with(window.document.frmRegCompany)
	{	totalChecked = 0; 
		totalElements = elements.length;
		
    	for(i = 0; i < totalElements; i++)
		{	
			if (elements[i].type == 'checkbox')
			{	if (elements[i].checked) 
				{	totalChecked++;
					break;
				}
			}
		}		

		if (totalChecked == 0)
		{	alert("Please Select At Least One Service Your Company Provides.");
	             return false;

		}
		
		}
	

//Services Brief
   if (theform.txtServices.value=="")
   {
	alert("Enter Provide Brief Services Details.");
	theform.txtServices.focus();
	return false;
   } 
   
//Network/ Branch List
   if (theform.txtNetwork.value=="")
   {
	alert("Enter Provide Network/ Branch Details.");
	theform.txtNetwork.focus();
	return false;
   }  
   
}// Function Ended
