<!--//
function menuCheck(theField){ 
	n = theField.selectedIndex;
	if (theField.selectedIndex == 0){
   		return false;   
  	}
	else{
		return true;
	}
}

function isNumber(theField)
{
   for(var i = 0; i < theField.value.length; i++)
   {
       var ch = theField.value.substring(i, i+1);
    if ((ch < "0" || "9" < ch) && (ch != "-") &&(ch != " "))
    {  
       return false;
    }
   }
   return true;
}


function phoneCheck(theField, theLabel){
	j = theField.value.length;
	k = 0;
	for(var i = 0; i < j; i++){
		var ch = theField.value.substring(i, i+1);
		if ((ch < "0" || "9" < ch) && (ch != "-") &&(ch != " ")){
			alert('Your '+ theLabel +' should contain numerals only.');
			theField.focus();
			theField.select();
			i = j;
			k = 1;
			return false;
		}
	}
	if(k == 0){
		return true;
	} else {
		return false;
	}
}

function radiocheck(theField){
	typecheck = "no";
	o = 0;
	while(theField[o]){
		if(theField[o].checked){
			typecheck = "yes";
		}
		o++;
	}
	if(typecheck == "no"){
		return false;
	} else {
		return true;
	}
}

function checkYear(year) {
 
//Leap year checker

	var temp_year

	temp_year = parseFloat(year);

	return (((temp_year % 4 == 0) && (temp_year % 100 != 0)) || (temp_year % 400 == 0)) ? 1 : 0;

}
function date_check(month, date, year, text) { 

	var max_days;

	var temp_date;

	if (month == "January" || month == "1") { 

		max_days = 31;
	
	} else if (month == "February" || month == "2") { 

		if (checkYear(year)) { 

			max_days = 29;

		} else { 

			max_days = 28;

		}

	} else if (month == "March" || month == "3") { 

		max_days = 31;

	} else if (month == "April" || month == "4") { 
	
		max_days = 30;

	} else if (month == "May" || month == "5") { 

		max_days = 31;

	} else if (month == "June" || month == "6") { 

		max_days = 30;

	} else if (month == "July" || month == "7") { 

		max_days = 31;

	} else if (month == "August" || month =="8") { 

		max_days = 31;

	} else if (month == "September" || month == "9") { 

		max_days = 30;

	} else if (month == "October" || month == "10") { 

		max_days = 31;

	} else if (month == "November" || month == "11") { 

		max_days = 30;

	} else if (month == "December" || month == "12") { 

		max_days = 31;

	}

	temp_date = parseInt(date);


	if (temp_date > max_days) { 

		alert(text);

		return false;

	} else { 

		return true;

	} 
}

function isFieldBlank(theField){
	if(theField.value.length == 0){		
		return true;		
	}else	{		
		return false;
	}	
}

function Year(theField){
	if(theField.value.length == 4){		
		return true;		
	}else	{		
		return false;
	}	
}


function verify_form(form){
	
		if(isFieldBlank(form.first_name)){
			alert('Please enter your first name');
			form.first_name.focus();
		} else if(isFieldBlank(form.last_name)){
			alert('Please enter your last name');
			form.last_name.focus();
		} else if (!menuCheck(form.month)){
   			alert("Please select your birth month");
   			form.month.focus();
		} else if (!menuCheck(form.date)){
   			alert("Please select your birth date");
   			form.date.focus();
		} else if (isFieldBlank(form.year)){
   			alert("Please enter your birth year");
   			form.year.focus();
		} else if((form.year.value < 1890) || (form.year.value > 2079)){
			alert('Please enter a valid birth year');
			form.year.focus();
		} else if(!isNumber(form.year)){
			alert('Your birth year should contain numerals only');
			form.year.select();
			form.year.focus();
		} else if (!date_check(form.month.value, form.date.value, form.year.value, 'This birthday does not exist')) {
			form.date.focus();
			return;

		} else if(!radiocheck(form.sex)){
			alert('Please select your gender');
		//} else if(isFieldBlank(form.ssn)){
		//	alert('Please enter your social security number');
		//	form.ssn.focus();
		//} else if(!isNumber(form.ssn)){
		//	alert('Your social security number should contain numerals only');
		//	form.ssn.select();
		//	form.ssn.focus();
		} else if(isFieldBlank(form.p_home_phone)){
			alert('Please enter your phone number');
			form.p_home_phone.focus();
		}else if(!phoneCheck(form.p_home_phone,'telephone number')){
			return;
		} else if(isFieldBlank(form.doc_f_name)){
			alert('Please enter the first name of your referring physician');
			form.doc_f_name.focus();
		} else if(isFieldBlank(form.doc_l_name)){
			alert('Please enter the last name of your referring physician');
			form.doc_l_name.focus();

		//} else if(!radiocheck(form.past_patient)){
		//	alert('Please select if you have been an Epic patient before');
			
			
		} else if ((form.month1.options[form.month1.selectedIndex].value == "MONTH" || form.date1.options[form.date1.selectedIndex].value == "DATE" || form.year1.options[form.year1.selectedIndex].value == "YEAR") && (form.month1.options[form.month1.selectedIndex].value != "MONTH" || form.date1.options[form.date1.selectedIndex].value != "DATE" || form.year1.options[form.year1.selectedIndex].value != "YEAR")) { 
			alert("Please complete or reset your appointment date");
			form.date1.focus();

		} else if(isFieldBlank(form.rp_name)){
			alert("Please enter the responsible party's name");
			form.rp_name.focus();
		} else if(isFieldBlank(form.rp_address)){
			alert("Please enter the responsible party's address");
			form.rp_address.focus();
		} else if(isFieldBlank(form.rp_city)){
			alert("Please enter the responsible party's city");
			form.rp_city.focus();
		} else if(isFieldBlank(form.rp_state)){
			alert("Please enter the responsible party's state");
			form.rp_state.focus();
		} else if(isFieldBlank(form.rp_zip)){
			alert("Please enter the responsible party's zipcode");
			form.rp_zip.focus();
		} else if(!isNumber(form.rp_zip)){
			alert('The zipcode should contain numerals only');
			form.rp_zip.select();
			form.rp_zip.focus();
		} else if(isFieldBlank(form.rp_ssn)){
			alert("Please enter the responsible party's social security number");
			form.rp_ssn.focus();
		} else if(!isNumber(form.rp_ssn)){
			alert('The SSN should contain numerals only');
			form.rp_ssn.select();
			form.rp_ssn.focus();
		} else if(!radiocheck(form.work_related)){
			alert('Please select if your visit is the result of a work related injury');
		} else if(!radiocheck(form.auto_related)){
			alert('Please select if your visit is the result of an automobile injury');
		//} else if(!radiocheck(form.c_insur_bill)){
		//	alert('Please select if there is another insurance company you would like us to bill');
		} else if(isFieldBlank(form.a_insur)){
			alert("Please enter the name of your insurance company");
			form.a_insur.focus();
		} else if(isFieldBlank(form.a_name_insur)){
			alert("Please enter the name of insured");
			form.a_name_insur.focus();
		} else if(isFieldBlank(form.a_relation)){
			alert("Please enter relationship to ensured");
			form.a_relation.focus();
		} else if(isFieldBlank(form.a_policy)){
			alert("Please enter the policy number");
			form.a_policy.focus();
		} else if(isFieldBlank(form.a_group_numb)){
			alert("Please enter the group number");
			form.a_group_numb.focus();
		} else if (form.month1.options[form.month1.selectedIndex].value != "MONTH" && form.date1.options[form.date1.selectedIndex].value != "DATE" && form.year1.options[form.year1.selectedIndex].value != "YEAR") { 
			if (!date_check(form.month1.value, form.date1.value, form.year1.value, 'This appointment date does not exist')) {
				form.date1.focus();
				return;
			} else { 
				form.submit();
			}
		} else {
			form.submit();
		}

}


// -->