function validate() {
//require first name
if (document.main_form.FirstName.value == '') {
	window.alert('Please enter your first name.');
	document.main_form.FirstName.focus();
	return false; 
}
//required last name
if (document.main_form.LastName.value == '') {
	window.alert('Please enter your last name.');
	document.main_form.LastName.focus();
	return false; 
}
if  ((document.main_form.Home_Phone.value == '') &&
(document.main_form.Work_Phone.value == '')){
	window.alert('Please enter either a Home or Business Telephone.');
	document.main_form.Home_Phone.focus();
	return false; 
}
//require email
if (document.main_form.Email.value == '') {
	window.alert('Please enter your email address.');
	document.main_form.Email.focus();
	return false; 
}		
 if (document.main_form.PreferredMail[0].checked == false) 
 {
	 if (document.main_form.PreferredMail[1].checked == false)
		{
		window.alert
		('Please tell us which Address you prefer for mail delivery.');
		document.main_form.PreferredMail[0].focus();
		return false;
		}
 }
if (document.main_form.PreferredMail[0].checked == true) {
	if (document.main_form.HomeAddress1.value == '' ||
		document.main_form.HomeCity.value == '' ||
		document.main_form.HomeState_Province.selectedIndex == 0 ||
		document.main_form.HomeZip.value == '') {
			window.alert
			('Please provide your Home Address, City, State and Zip Code.');
			document.main_form.HomeAddress1.focus();
			return false;
	} 
}
if (document.main_form.PreferredMail[1].checked == true) {
	if (document.main_form.Company.value == '' ||
		document.main_form.BusAddress1.value == '' ||
		document.main_form.BusCity.value == '' ||
		document.main_form.BusState_Province.selectedIndex == 0 ||
		document.main_form.BusZip.value == '') {
			window.alert
			('Please provide your Employer, Business Address, City, State and Zip Code.');
			document.main_form.BusAddress1.focus();
			return false;
	} 
}
if (!_CF_checkzip(document.main_form.HomeZip.value)) {
	window.alert('Please enter a valid Home Zip/Postal code.');
	document.main_form.HomeZip.focus();
	return false; 
}
if (!_CF_checkzip(document.main_form.BusZip.value)) {
	window.alert('Please enter a valid Business Zip/Postal code.');
	document.main_form.BusZip.focus();
	return false; 
}
var OrgTypeValue = document.main_form.Organization.value;
if  (OrgTypeValue == 0)  {
	window.alert('Please select an Organization type.');
	document.main_form.Organization.focus();
	return false; 
}
var PositionValue = document.main_form.Position.value;
if  (PositionValue == 0)  {
	window.alert('Please select a Position Level.');
	document.main_form.Position.focus();
	return false; 
}	
var FunctionValue = document.main_form.Function.value;
if  (FunctionValue == 0)  {
	window.alert('Please select a Function.');
	document.main_form.Function.focus();
	return false; 
}
if  (isDate(document.main_form.StartedHealthCare)==false)  {
	window.alert('Please enter a valid Date Started in Healthcare.');
	document.main_form.StartedHealthCare.focus();
	return false; 
}
if  (isDate(document.main_form.DOB)==false)  {
	window.alert('Please enter a valid Date of Birth.');
	document.main_form.DOB.focus();
	return false; 
}
if (document.main_form.siteusername.value == '') {
	window.alert('Please enter your website user name.');
	document.main_form.siteusername.focus();
	return false; 
}
if (document.main_form.sitepassword.value == '') {
	window.alert('Please enter your website password.');
	document.main_form.sitepassword.focus();
	return false; 
}
if (document.main_form.sitepasswordconfirm.value == '') {
	window.alert('Please enter confirm your website password.');
	document.main_form.sitepasswordconfirm.focus();
	return false; 
}
if (document.main_form.AgreementSignature.value == '') {
	window.alert('Please enter your Name in the Signature box.');
	document.main_form.AgreementSignature.focus();
	return false; 
}
			
}	



function selectOther() { 
	document.main_form.Prefix[4].checked = true;
}

function verifyDropDown(val) {
if (val == 0) {
	return false;}
else {
	return true;}
}



function isEmail(theEmail)
	{
	var s = theEmail.value;
	var ok = 1;
	
	//Check to make sure it is more than 6 characters in length
	if ((s.length < 7)){
		ok = 0;
	}

	//Check to make sure it is has an @ character and there is at least one character before it
	var at = s.indexOf('@');
	if (at <= 0)
		{ ok = 0; }
	
	//Check to make sure it is has only one @ character
	if (at != s.lastIndexOf('@')){
		ok = 0;
	}

	//Check to make sure there is at least one full stop after the @ character and the number of characters from the full stop to the end is between 2-5 characters in length
	if ((s.lastIndexOf('.') < (at+1)) || (s.lastIndexOf('.') > (s.length-3)) || (s.lastIndexOf('.') < (s.length-6))){
		ok = 0;
	}

	//Check to make sure there are no funny characters
	if ((s.indexOf(',') != -1) || 
		(s.indexOf(' ') != -1) || 
		(s.indexOf(';') != -1) || 
		(s.indexOf(':') != -1) || 
		(s.indexOf('?') != -1) || 
		(s.indexOf('/') != -1) || 
		(s.indexOf('"') != -1) || 
		(s.indexOf('\\') != -1) || 
		(s.indexOf("'") != -1) || 
		(s.indexOf('[') != -1) || 
		(s.indexOf(']') != -1)){
		ok = 0;
	}
	
	if (s.length == 0){
		ok = 1;
	}
	
	if (ok == 1){
		return true;}
	else
		{
		window.alert('Please provide a valid email address.');
		document.main_form.Email.focus();
		return false;
		}
}

function _CF_checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0){
        return true;
    }
    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format);
    //Was it a decimal?
    if (check_char < 1){
	return _CF_checknumber(object_value);
	}
    else{
	return false;
    }
 }



function _CF_numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value){
		return false;
	}
    }

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value){
		return false;
	}
    }
	
    //All tests passed, so...
    return true;
}



function _CF_checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0){
        return true;
    }
    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0));
    //Was it a decimal?
	if (check_char == 1){
	    decimal = true;
	}
	else if (check_char < 1){
		return false;
        }
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i));
		if (check_char < 0){
			return false;
		}
		else if (check_char == 1)
		{
			if (decimal){		// Second decimal.
				return false;
			}
			else{
				decimal = true;
			}
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	{
				trailing_blank = true;
			}
        // ignore leading blanks

		}
	        else if (trailing_blank){
			return false;
		}
		else{
			digits = true;
		}
	}	
    //All tests passed, so...
    return true;
    }



function _CF_checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0){
        return true;
    }

    if (!_CF_checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (_CF_numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }



function _CF_checkphone(object_value)
    {
    if (object_value.length == 0){
        return true;
    }
    if (object_value.length != 12){
        return false;
    }
	// check if first 3 characters represent a valid area code
    if (!_CF_checknumber(object_value.substring(0,3))){
		return false;
    }
    else{
	if (!_CF_numberrange((eval(object_value.substring(0,3))), 100, 1000)){
		return false;
	}
    }
	// check if area code/exchange separator is either a'-' or ' '
	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " "){
        return false;
        }

	// check if  characters 5 - 7 represent a valid exchange
    if (!_CF_checknumber(object_value.substring(4,7))){
		return false;
    }else{
	if (!_CF_numberrange((eval(object_value.substring(4,7))), 100, 1000)){
		return false;
	}
    }
	
	// check if exchange/number separator is either a'-' or ' '
	if (object_value.charAt(7) != "-" && object_value.charAt(7) != " "){
        return false;
	}
	// make sure last for digits are a valid integer
	if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+"){
        return false;
	}else
	{
		return (_CF_checkinteger(object_value.substring(8,12)));
	}
    }



function _CF_checkzip(object_value)
    {
    if (object_value.length == 0){
        return true;
    }
		
    if (object_value.length != 5 && object_value.length != 10){
        return false;
    }
	// make sure first 5 digits are a valid integer
	if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+"){
        return false;
        }
	if (!_CF_checkinteger(object_value.substring(0,5))){
		return false;
        }
	if (object_value.length == 5){
		return true;
	}
	// make sure

	// check if separator is either a'-' or ' '
	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " "){
        return false;
	}
	// check if last 4 digits are a valid integer
	if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+"){
        return false;
	}
	return (_CF_checkinteger(object_value.substring(6,10)));
    }
	
	
	
	
	
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2010;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))){
        return false;
        }
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1){
        	returnString += c;
        }
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
   } 
   return this;
}

function isDate(dtStr){
	var passedstrDt = dtStr.value;
	
	if (dtStr.name == 'StartedHealthCare' && dtStr.value == '')
		{
		return false;
		}
	if (dtStr.name == 'DOB' && dtStr.value == '')
		{
		return false;
		}
	
	var daysInMonth = DaysArray(12);
	var pos1 = passedstrDt.indexOf(dtCh);
	var pos2=passedstrDt.indexOf(dtCh,pos1+1);
	var strMonth=passedstrDt.substring(0,pos1);
	var strDay=passedstrDt.substring(pos1+1,pos2);
	var strYear=passedstrDt.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1){
		strDay=strDay.substring(1);
	}
	if (strMonth.charAt(0)=="0" && strMonth.length>1){
		strMonth=strMonth.substring(1);
	}
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1){
			strYr=strYr.substring(1);
		}
	}
	month=parseInt(strMonth, 10);
	day=parseInt(strDay, 10);
	year=parseInt(strYr, 10);
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		dtStr.focus();
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		dtStr.focus();
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		dtStr.focus();
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		dtStr.focus();
		return false;
	}
	if (passedstrDt.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(passedstrDt, dtCh))==false){
		alert("Please enter a valid date");
		dtStr.focus();
		return false;
	}
return true;
}

