//*********************************************************************************
// Function for Checking/ Validation of Advertisement Form for the Member Companeis
// Developer: Avanish Kumar
// Email: Kumar.Avanish@Gmail.com
//*********************************************************************************
function advt_Validator(theform)
{   

	
	with(window.document.frmAdvtCompany)
	{	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 Advertisement Interest.");
			return false;
		}

		//return true;
	}
//Services Requirements Details 

//alert(theform.chkS[1].checked);
if(theform.txtDetails.value=="")
		{	
		alert("Please Provide Requirements Detail.");
		theform.txtDetails.focus();
		return (false);
		}
//Contact Info validations 
//========================

//Customer Name
		if (theform.txtName.value=="")
		{
		alert("Please Provide Name of Contact Person.");
		theform.txtName.focus();
		return false;
		}//Contact Person Name Validation

//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

// Phone Number
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
 		

//Mobile Phone Validation
	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
	

//Company Name
	if (theform.txtCompName.value=="")
    {
    alert("Please Enter Complete Company Name. Its Must.");
	theform.txtCompName.focus();
    return false;
    }

//Address Field
	if (theform.txtCompAddress.value=="")
    {
    alert("Please Provide Complete Company Address. Its Must");
	theform.txtCompAddress.focus();
    return false;
    }

//City Filed
	if (theform.txtCity.value=="")
    {
    alert("Please Provide City Name.");
	theform.txtCity.focus();
    return false;
    }
	
//State Filed
	if (theform.txtState.value=="")
    {
    alert("Please Provide State Name.");
	theform.txtState.focus();
    return false;
    }
	
//ZIP/ POSTAL CODE
	if (theform.txtPostCode.value=="")
    {
    alert("Please Provide ZIP/ Postal Code Name.");
	theform.txtPostCode.focus();
    return false;
    }

	if (isNaN(theform.txtPostCode.value))
    {
	alert("Please Enter Only Numbers in Zip-Postal Code Field.");
	theform.txtPostCode.focus();
	return false;
    }  
	
	
//Country Field Validation
	if (theform.txtCountry.value=="")
    {
    alert("Please Provide Country Name.");
	theform.txtCountry.focus();
    return false;
    }    
}// Function Ended
