
	/////// form validation
function Form1_Validator(theForm)
{

var alertsay = "";
		// check to see if the login field is blank
	if ((theForm.loginid.value == " ") || (theForm.loginid.value ==""))
		{
		alert("You must enter LoginID.");
		theForm.loginid.focus();
		return (false);
		}

	if (theForm.loginid.value.length < 5)
		{
		alert("Please enter at least 5 characters in the LoginID field.");
		theForm.loginid.focus();
		return (false);
		}
	// this can be altered for any "checkOK" string you desire
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		var checkStr = theForm.loginid.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 letter and numeric characters in the LoginID field.");
				theForm.loginid.focus();
				return (false);
		}

		// check to see if the First name field is blank
	if ((theForm.fname.value == "") || (theForm.fname.value == " "))
		{
		alert("You must enter  First Name.");
		theForm.fname.focus();
		return (false);
		}
		// check to see if the Last namme field is blank
	if ((theForm.lname.value == "") || (theForm.lname.value == " "))
		{
		alert("You must enter  Last Name.");
		theForm.lname.focus();
		return (false);
		}

	// check if email field is blank
	if ((theForm.email.value == "") || (theForm.email.value == " "))
	{
	alert("You must enter an EmailID .");
	theForm.email.focus();
	return (false);
	}

		// 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("Your  EmailID   is invalid" );
	theForm.email.focus();
	return (false);
	}
	
		// check to see if the Address field is blank
	if ((theForm.address.value == "") || (theForm.address.value == " "))
		{
		alert("You must enter an Address.");
		theForm.address.focus();
		return (false);
		}

		// check to see if the City field is blank
	if ((theForm.city.value == "") || (theForm.city.value == " "))
		{
		alert("You must enter City.");
		theForm.city.focus();
		return (false);
		}

// check to see if the State field is blank
	if ((theForm.state.value == "") || (theForm.state.value == " "))
		{
		alert("You must enter State.");
		theForm.state.focus();
		return (false);
		}


//check if other country field is blank
	if (theForm.resident[1].checked)
		
		{
			if (theForm.country.value =="Enter state or foreign country.")
				{
					alert("Your are not California resident. Please enter valid Country.");
						theForm.country.focus();
						return (false);
				}
			else if (theForm.country.value =="")
				{
					alert("Your are not California resident. Please enter valid Country.");
					theForm.country.focus();
					return (false);
				}
		}
	// check if Zipcode field is blank
	if ((theForm.zipcode.value == "") || (theForm.zipcode.value == " "))
		{
		alert("Please enter  Zip Code.");
		theForm.zipcode.focus();
		return (false);
		}
	


	// check if Telephone field is blank
	if ((theForm.telephone.value == "") || (theForm.telephone.value == " "))
		{
		alert("Please enter  Telephone Number.");
		theForm.telephone.focus();
		return (false);
		}

		// only allow numbers to be entered in Telephone
	var checkOK = "0123456789-";
	var checkStr = theForm.telephone.value;
	var allValid = true;
	var allNum = "";
	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 (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
	alert("Please enter only digit characters in the Telephone field.");
	theForm.telephone.focus();
	return (false);
	}

	// only allow numbers to be entered in Telephone
	var checkOK = "0123456789-";
	var checkStr = theForm.zipcode.value;
	var allValid = true;
	var allNum = "";
	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 (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
	alert("Please enter only digit characters in the Zip Code field.");
	theForm.zipcode.focus();
	return (false);
	}

		// check if the first drop down is selected, if so, invalid selection
	
				
	//check if BirthDay field is blank
	if (theForm.age[1].checked)
		
		{
			if (theForm.birthdate.value =="MM/DD/YYYY")
				{
					alert("Your are not 18 years old. Please enter  Birth Date.");
						theForm.birthdate.focus();
						return (false);
				}
			else if (theForm.country.value =="")
				{
					alert("Your are not 18 years old. Please enter  Birth Date.");
					theForm.birthdate.focus();
					return (false);
				}
				//Check for date format
				var err=0
					a=theForm.birthdate.value
					if (a.length != 10) err=1
					b = a.substring(0, 2)// month
					c = a.substring(2, 3)// '/'
					d = a.substring(3, 5)// day
					e = a.substring(5, 6)// '/'
					f = a.substring(6, 10)// year

					//basic error checking
					if (b<1 || b>12) err = 1
					if (c != '/') err = 1
					if (d<1 || d>31) err = 1
					if (e != '/') err = 1
					if (f<0 || f>9999) err = 1
					
					//advanced error checking

					// months with 30 days
					if (b==4 || b==6 || b==9 || b==11){
						if (d==31) err=1
					}

					// february, leap year
					if (b==2){
						// feb
						var g=parseInt(f/4)
						if (isNaN(g)) {
							err=1
						}

						if (d>29) err=1
						if (d==29 && ((f/4)!=parseInt(f/4))) err=1
					}

					if (err==1)
					{
						alert("Please enter proper date format");
						theForm.birthdate.focus();
						return (false);
					}
					//-----------validation for age >18 years--------
					var now      = new Date();
					var birthd1  = Form1.birthdate.value
					var birthd   = new Date(birthd1);
					var toGo     =  now.getTime()-birthd.getTime();
					var days     = Math.floor(toGo / (1000 * 60 * 60 * 24 * 365));
					if (days >18)
					{
						alert("You are above 18 Years.  Please enter a valid Birthdate.")
						theForm.birthdate.focus();
						return (false);
					
					}
					if (birthd > now)
					{
						alert("Please enter a valid Birthdate.")
						theForm.birthdate.focus();
						return (false);
					}	

		}		
		
		
			
	/*	//check if other country field is blank
	if (theForm.campaigns[0].checked)
		
		{
			if (theForm.newspaper.value =="Please enter newspapers name")
				{
						alert("Please enter newspaper name");
						theForm.newspaper.focus();
						return (false);
				}
			else if ((theForm.newspaper.value =="") || (theForm.newspaper.value ==" "))
				{
					alert("Please enter newspaper name");
					theForm.newspaper.focus();
					return (false);
				}
		}		

*/

/*		// check if Telephone field is blank
	if ((theForm.newspaper.value == "") || (theForm.newspaper.value == " "))
		{
		alert("Please enter  \"letter writing campaigns\".");
		theForm.newspaper.focus();
		return (false);
		}*/

}



//set disable to anable text box for birthdate
	function birthday()
	{
	  Form1.birthdate.disabled=true;
	  Form1.birthdate.value ="Not Applicable"	
	}
	function birthday1()
	{
	  Form1.birthdate.disabled=false;
	 Form1.birthdate.value = "MM/DD/YYYY"	
	 Form1.birthdate.focus();
	}
	//set disable to anable text box for other country
	
	function othercountry()
	{
	  Form1.country.disabled=false;
	  Form1.country.value ="Please enter state and country."
	  Form1.country.focus();
	}

	function othercountry1()
	
	{
		Form1.country.disabled = true;
		Form1.country.value ="Not Applicable"
	}

function camp()
	{
	  Form1.newspaper.disabled=false;
	  Form1.newspaper.value ="Please enter newspaper name.";
	}

	function camp1()
	
	{
		Form1.newspaper.disabled = true;
		Form1.newspaper.value ="Not Applicable";
	}
	
//-----------checkMe function-------------
	function checkMe()
	{
		if (Form1.resident[1].checked)
		{
				Form1.country.disabled=false;
		}
		
		if (Form1.age[1].checked)
		{
				Form1.birthdate.disabled=false;
		}

/*		if(Form1.campaigns[0].checked)
		{
			Form1.newspaper.disabled = false;
		}*/

		if(Form1.condition[0].checked)
		{
			Form1.Submit1.disabled = false;
		}

	}
		
	// check Terms and conditions ..........................

	function checkTermsCondtions2()
	
	{
		    Form1.Submit1.disabled = false;
	}

	function checkTermsCondtions1()
	
	{
//		'alert("Please read and agree with CPEC's principles and mission.");
		    Form1.Submit1.disabled = false;
	}


	// To check for Characters and Intergers in fields ................

	function sand1()
	{
		// only allow numbers to be entered in Telephone
		var checkOK = "0123456789-";
		var checkStr = Form1.zipcode.value;
		var allValid = true;
		var allNum = "";
		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 (ch != ",")
		allNum += ch;
		}
		if (!allValid)
		{
		alert("Enter numbers and dashes only in the Zip Code field.");
		Form1.zipcode.focus();
		return (false);
		}
	}


	function firstName()
	{
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var checkStr = Form1.fname.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 characters in the First Name field.");
				Form1.fname.focus();
				return (false);
		}
	}

function lastName()
	{
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var checkStr = Form1.lname.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 characters in the Last Name field.");
				Form1.lname.focus();
				return (false);
		}
	}

	function formCity()
	{
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
		var checkStr = Form1.city.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 characters in the City field.");
				Form1.city.focus();
				return (false);
		}
	}

	function formState()
	{
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
		var checkStr = Form1.state.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 characters in the State field.");
				Form1.state.focus();
				return (false);
		}
	}

	function tel()
	{
		// only allow numbers to be entered in Telephone
		var checkOK = "0123456789-";
		var checkStr = Form1.telephone.value;
		var allValid = true;
		var allNum = "";
		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 (ch != ",")
		allNum += ch;
		}
		if (!allValid)
		{
		alert("Enter numbers and dashes only in the Telephone Number field.");
		Form1.telephone.focus();
		return (false);
		}
	}

function pjob()
	{
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
		var checkStr = Form1.job_title.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 characters in the Profession/Job field.");
				Form1.job_title.focus();
				return (false);
		}
	}

function other_state()
	{
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
		var checkStr = Form1.country.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 characters in the Other State/Country field.");
				Form1.country.focus();
				return (false);
		}
		if(Form1.country.value == "")
		{
			alert("Please enter only characters in the Other State/Country field.");
			Form1.country.focus();
		}
	}


