
document.getElementsbyClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

/*function toggle(obj) {
	var el = document.getElementById(obj);
	
	
	if ( el.style.display != 'block' ) {
		el.style.display = 'block';
	}
	else {
		el.style.display = 'none';
	}
}*/

function hide(obj) {
	var el = document.getElementById(obj);
	if (validate(obj)) 
	{
		el.style.display = 'none';
		return (true);
	}
	else return (false);
}

/*
function valshow(obj) {
	if (obj=='acknowledge') fillname();

	sections = document.getElementsbyClassName('oneatatime');
	
	for (i=0, j=sections.length; i<j; i++)
		{
			if (sections[i].id != obj) 
				{
					if (!hide(sections[i].id)) return (false);
					//if (sections[i].style.display != 'none') if (!hide(sections[i].id)) return (false);
					//sections[i].style.display = 'none';				
				}
		}

	var el = document.getElementById(obj);
	el.style.display = 'block';
	
	return (true);
}
*/

function show(obj) {
	if (obj=='acknowledge') fillname();

	sections = document.getElementsbyClassName('oneatatime');
	
	for (i=0, j=sections.length; i<j; i++)
		{
			if (sections[i].id != obj) 
				{
					sections[i].style.display = 'none';				
				}
		}

	var el = document.getElementById(obj);
	el.style.display = 'block';
	
	return (true);
}

function fillname() {
	var el = document.getElementById('patientname');

	el.innerHTML = document.newform.patient_first_name.value + " " + document.newform.patient_middle_initial.value + " " + document.newform.patient_last_name.value;
}

function fillbill() {
	document.newform.billing_first_name.value = document.newform.patient_first_name.value;
	document.newform.billing_middle_initial.value = document.newform.patient_middle_initial.value;
	document.newform.billing_last_name.value = document.newform.patient_last_name.value;
	document.newform.billing_ssn1.value = document.newform.patient_ssn1.value;
	document.newform.billing_ssn2.value = document.newform.patient_ssn2.value;
	document.newform.billing_ssn3.value = document.newform.patient_ssn3.value;
	document.newform.billing_dob1.value = document.newform.patient_dob1.value;
	document.newform.billing_dob2.value = document.newform.patient_dob2.value;
	document.newform.billing_dob3.value = document.newform.patient_dob3.value;
	document.newform.billing_address.value = document.newform.patient_address.value;
	document.newform.billing_city.value = document.newform.patient_city.value;
	document.newform.billing_state.value = document.newform.patient_state.value;
	document.newform.billing_zip.value = document.newform.patient_zip.value;
	document.newform.billing_home_phone.value = document.newform.patient_home_phone.value;
	document.newform.billing_employer_phone.value = document.newform.patient_employer_phone.value;
	document.newform.billing_employer.value = document.newform.patient_employer.value;
	document.newform.billing_employer_address.value = document.newform.patient_employer_address.value;
	document.newform.billing_employer_city.value = document.newform.patient_employer_city.value;
	document.newform.billing_employer_state.value = document.newform.patient_employer_state.value;
	document.newform.billing_employer_zip.value = document.newform.patient_employer_zip.value; 	
}

function fillinsure1() {
	document.newform.insuree_first_name.value = document.newform.patient_first_name.value;
	document.newform.insuree_middle_initial.value = document.newform.patient_middle_initial.value;
	document.newform.insuree_last_name.value = document.newform.patient_last_name.value;
	document.newform.insuree_ssn1.value = document.newform.patient_ssn1.value;
	document.newform.insuree_ssn2.value = document.newform.patient_ssn2.value;
	document.newform.insuree_ssn3.value = document.newform.patient_ssn3.value;
	document.newform.insuree_dob1.value = document.newform.patient_dob1.value;
	document.newform.insuree_dob2.value = document.newform.patient_dob2.value;
	document.newform.insuree_dob3.value = document.newform.patient_dob3.value;
}

function fillinsure2() {
	document.newform.secondary_insuree_first_name.value = document.newform.patient_first_name.value;
	document.newform.secondary_insuree_middle_initial.value = document.newform.patient_middle_initial.value;
	document.newform.secondary_insuree_last_name.value = document.newform.patient_last_name.value;
	document.newform.secondary_insuree_ssn1.value = document.newform.patient_ssn1.value;
	document.newform.secondary_insuree_ssn2.value = document.newform.patient_ssn2.value;
	document.newform.secondary_insuree_ssn3.value = document.newform.patient_ssn3.value;
	document.newform.secondary_insuree_dob1.value = document.newform.patient_dob1.value;
	document.newform.secondary_insuree_dob2.value = document.newform.patient_dob2.value;
	document.newform.secondary_insuree_dob3.value = document.newform.patient_dob3.value;
}

function sign1(){
	if (document.newform.form_signature.value == "") document.newform.form_signature.value = document.newform.patient_first_name.value + " " + document.newform.patient_middle_initial.value + " " + document.newform.patient_last_name.value;
}

function validate(section){
	
switch (section)
{

case 'patient':
{	
	if (document.newform.patient_first_name.value == "")
  	{	alert("Please enter a value for the \"Patient's First Name\" field.");
		show(section);
		document.newform.patient_first_name.focus();
		return (false);
	}
  	if (document.newform.patient_last_name.value == "")
  	{	alert("Please enter a value for the \"Patient's Last Name\" field.");
		show(section);
		document.newform.patient_last_name.focus();
		return (false);
  	}
  	if (document.newform.patient_address.value == "")
  	{	alert("Please enter a value for the \"Patient's Address\" field.");
		show(section);
		document.newform.patient_address.focus();
		return (false);
  	}
  	if (document.newform.patient_city.value == "")
  	{	alert("Please enter a value for the \"Patient's City\" field.");
		show(section);
		document.newform.patient_city.focus();
		return (false);
  	}
	if (document.newform.patient_state.value == "")
  	{	alert("Please enter a value for the \"Patient's State\" field.");
		show(section);
		document.newform.patient_state.focus();
		return (false);
  	}
	if (document.newform.patient_zip.value == "")
  	{	alert("Please enter a value for the \"Patient's Zipcode\" field.");
		show(section);
		document.newform.patient_zip.focus();
		return (false);
  	}
	if (document.newform.patient_home_phone.value == "")
  	{	alert("Please enter a value for the \"Patient's Home Phone\" field.");
		show(section);
		document.newform.patient_home_phone.focus();
		return (false);
  	}
	if ((document.newform.patient_email.value==null)||(document.newform.patient_email.value==""))
	{	alert("Please Enter the \"Patient's Email");
		show(section);
		document.newform.patient_email.focus();
		return (false);
	}
  	if ((document.newform.patient_dob1.value == "") || (document.newform.patient_dob2.value == "") || (document.newform.patient_dob3.value == ""))
  	{	alert("Please enter a value for the \"Patient's Date of Birth\" field.");
		show(section);
		document.newform.patient_dob1.focus();
		return (false);
  	}
  	if ((document.newform.patient_ssn1.value == "") || (document.newform.patient_ssn2.value == "") || (document.newform.patient_ssn3.value == ""))
  	{	alert("Please enter a value for the \"Patient's SSN#\" field.");
		show(section);
		document.newform.patient_ssn1.focus();
		return (false);
  	}
  	if (document.newform.patient_sex.value == "")
  	{	alert("Please specify the \"Patient's Sex\".");
		show(section);
		document.newform.patient_sex.focus();
		return (false);
  	}
  	if (document.newform.patient_marital_status.value == "")
  	{	alert("Please specify the \"Patient's Marital Status\".");
		show(section);
		document.newform.patient_marital_status.focus();
		return (false);
  	}
  	if (document.newform.patient_emergency_contact.value == "")
  	{	alert("Please enter a value for the \"Patient's Emergency Contact\" field.");
		show(section);
		document.newform.patient_emergency_contact.focus();
		return (false);
  	}
  	if (document.newform.how_heard.value == "Please Select")
  	{	alert("Please let us know how you heard about our office.");
		show(section);
		document.newform.how_heard.focus();
		return (false);
  	}
	break;
}

case 'billing':
{
	if (document.newform.billing_first_name.value == "")
  	{	alert("Please enter a value for the \"Billing First Name\" field.");
    	show(section);
		document.newform.billing_first_name.focus();
		return (false);
  	}
  	if (document.newform.billing_last_name.value == "")
  	{	alert("Please enter a value for the \"Billing Last Name\" field.");
    	show(section);
		document.newform.billing_last_name.focus();
		return (false);
  	}
  	if ((document.newform.billing_ssn1.value == "") || (document.newform.billing_ssn2.value == "") || (document.newform.billing_ssn3.value == ""))
  	{	alert("Please enter a value for the \"Billing SSN#\" field.");
    	show(section);
		document.newform.billing_ssn1.focus();
		return (false);
  	}
  	if ((document.newform.billing_dob1.value == "") || (document.newform.billing_dob2.value == "") || (document.newform.billing_dob3.value == ""))
  	{	alert("Please enter a value for the \"Billing Date of Birth\" field.");
    	show(section);
		document.newform.billing_dob1.focus();
		return (false);
  	}
    if (document.newform.billing_address.value == "")
  	{	alert("Please enter a value for the \"Billing Address\" field.");
    	show(section);
		document.newform.billing_address.focus();
		return (false);
  	}
  	if (document.newform.billing_city.value == "")
  	{	alert("Please enter a value for the \"Billing City\" field.");
    	show(section);
		document.newform.billing_city.focus();
		return (false);
  	}
  	if (document.newform.billing_state.value == "")
  	{	alert("Please enter a value for the \"Billing State\" field.");
    	show(section);
		document.newform.billing_state.focus();
		return (false);
  	}
  	if (document.newform.billing_zip.value =="")
  	{	alert("Please enter a 5-digit value for the \"Billing Zip Code\" field.");
    	show(section);
		document.newform.billing_zip.focus();
		return (false);
  	}
  	if (document.newform.billing_home_phone.value == "")
  	{	alert("Please enter a value for the \"Billing Home Phone\" field.");
    	show(section);
		document.newform.billing_home_phone.focus();
		return (false);
  	}	
	break;
}

case 'signature':
{ 
	if (document.newform.form_signature.value == "")
  	{	alert("Please sign this form to continue.");
		show(section);
		document.newform.form_signature.focus();
		return (false);
  	}
	if (!document.newform.form_acknowledgement.checked)
  	{	alert("Please sign this form and accept the terms & conditions by checking the \"I accept\" box to continue.");
		show(section);
		document.newform.form_acknowledgement.focus();
		return (false);
  	}
	break;
}

case 'acknowledge':
{
	if (!document.newform.privacy_acknowledgement.checked)
  	{	alert("Please confirm that you received the privacy agreement by checking the box to continue.");
		show(section);
		document.newform.privacy_acknowledgement.focus();
		return (false);
  	}
	break;
}

} //end switch
complete(section);
return (true);
}//end function
		
function complete(section)
{
	var sectid=section+"_incomplete";
	el = document.getElementById(sectid);
	el.style.display = 'none';

	var sectid=section+"_complete";
	el = document.getElementById(sectid);
	el.style.display = 'inline';
	
	
}

function checkall()
{
	sections = document.getElementsbyClassName('oneatatime');

	for (i=0, j=sections.length; i<j; i++)
	{
	if (!validate(sections[i].id)) return (false);
	}

	return (true);
}
