// form validation for Clinical Professionals Getting Started form
function checkForm(form) {
// instantiate object
fv = new formValidator();
// set all title cell style to plain (non error color)
fv.resetTitles();

// perform checks
// check for empty qualified field
if (!fv.isChecked(form.qualified))
{
msg=fv.getError("qualified");
fv.raiseError(msg);
fv.changeTitleStyle('qualifiedtitle','titlecell_error','');
} 
// check for empty country field
if (fv.isEmpty(form.country.value))
{
msg=fv.getError("country");
fv.raiseError(msg);
fv.changeTitleStyle('countrytitle','titlecell_error','');
} 
// check for empty title field
if (fv.isEmpty(form.ctitle.value))
{
msg=fv.getError("title");
fv.raiseError(msg);
fv.changeTitleStyle('titletitle','titlecell_error','');
} 
// check for empty first name field
if (fv.isEmpty(form.firstname.value))
{
msg=fv.getError("firstname");
fv.raiseError(msg);
fv.changeTitleStyle('firsttitle','titlecell_error','');
} 
// check for empty last name field
if (fv.isEmpty(form.lastname.value))
{
msg=fv.getError("lastname");
fv.raiseError(msg);
fv.changeTitleStyle('lasttitle','titlecell_error','');
} 
// check for empty email address
if (fv.isEmpty(form.email.value))
{
msg=fv.getError("email");
fv.raiseError(msg);
fv.changeTitleStyle('emailtitle','titlecell_error','');
}
// check for valid email address format
if (!fv.isEmpty(form.email.value) && !fv.isEmailAddress(form.email.value))
{
msg=fv.getError("validemail");
fv.raiseError(msg);
fv.changeTitleStyle('emailtitle','titlecell_error','');
} 

if (form.veremail.value == "") {
      msg=fv.getError("retypeemail");
	  fv.raiseError(msg);
	  fv.changeTitleStyle('emailtitle','titlecell_error','');
}

if (form.email.value !=form.veremail.value) {
      msg=fv.getError("veremail");
	  fv.raiseError(msg);
	  fv.changeTitleStyle('veremailtitle','titlecell_error','');
}
// check for empty job field
if (fv.isEmpty(form.job.value))
{
msg=fv.getError("job");
fv.raiseError(msg);
fv.changeTitleStyle('jobtitle','titlecell_error','');
}
// check for empty license field
if (fv.isEmpty(form.credential.value))
{
msg=fv.getError("credential");
fv.raiseError(msg);
fv.changeTitleStyle('credentialtitle','titlecell_error','');
}
// check for empty yrs in practice field
if (fv.isEmpty(form.yrspractice.value))
{
msg=fv.getError("yrspractice");
fv.raiseError(msg);
fv.changeTitleStyle('yrspracticetitle','titlecell_error','');
}
if (!fv.isEmpty(form.yrspractice.value))
{
form.yrspractice.value=fv.strip_spaces(form.yrspractice.value); 
if (!isInteger(form.yrspractice.value))
{
msg=fv.getError("yrspracticedigits");
fv.raiseError(msg);
fv.changeTitleStyle('yrspracticetitle','titlecell_error','');
}
}

// check for empty company field
if (fv.isEmpty(form.organization.value))
{
msg=fv.getError("organizationBusiness");
fv.raiseError(msg);
fv.changeTitleStyle('organizationtitle','titlecell_error','');
} 

if (fv.isEmpty(form.org_type.value)) {
// 4 is Parent
msg=fv.getError("org_type");
fv.raiseError(msg);
fv.changeTitleStyle('org_typetitle','titlecell_error','');
}
// check for empty address field
if (fv.isEmpty(form.address1.value))
{
msg=fv.getError("address1");
fv.raiseError(msg);
fv.changeTitleStyle('addresstitle','titlecell_error','');
}
// check for empty city field
if (fv.isEmpty(form.city.value))
{
msg=fv.getError("city");
fv.raiseError(msg);
fv.changeTitleStyle('citytitle','titlecell_error','');
}
// check for empty state field
if (fv.isEmpty(form.state.value))
{
msg=fv.getError("state");
fv.raiseError(msg);
fv.changeTitleStyle('statetitle','titlecell_error','');
}
// check for empty zip field
if (fv.isEmpty(form.zip.value))
{
msg=fv.getError("zippostal");
fv.raiseError(msg);
fv.changeTitleStyle('ziptitle','titlecell_error','');
}

//Begin validating zip
// check for state or province
if (fv.isProvince(form.state.value))
{
   // check postal code
   if (!fv.isValidCanadianCode(form.zip.value)) {
      msg=fv.getError("validPostalcode");
      fv.raiseError(msg);
      fv.changeTitleStyle('ziptitle','titlecell_error','');
   } else {
      // check country
      if (!fv.isCanada(form.country.value)) {
      	  msg=fv.getError("validCAcountry");
          fv.raiseError(msg);
          fv.changeTitleStyle('countrytitle','titlecell_error','');
      }  
   }
} else if (form.state.value!="other") {
  // USA
  // check zip code
   if (!fv.isEmpty(form.zip.value) && !fv.isValidZip(form.zip.value)) {
      msg=fv.getError("validZipcode");
      fv.raiseError(msg);
      fv.changeTitleStyle('ziptitle','titlecell_error','');
   } else {
      // check country
      if (!fv.isEmpty(form.state.value) && !fv.isUSA(form.country.value)) {
          msg=fv.getError("validUScountry");
          fv.raiseError(msg);
          fv.changeTitleStyle('countrytitle','titlecell_error','');
      }    
   }

} else {
   if (form.country.value=="other") {
   //check that other is specified
   if (fv.isEmpty(form.countryother.value))
   {
      msg=fv.getError("specifycountry");  
      fv.raiseError(msg);
      fv.changeTitleStyle('countryotherfieldtitle','fieldcell_error','');
   }
   }
}
// Work phone
//validate area code 
if (fv.isEmpty(form.wphonearea.value))
{
msg=fv.getError("phonearea");
fv.raiseError(msg);
fv.changeTitleStyle('wphoneareatitle','titlecell_error','');
}
if (!fv.isEmpty(form.wphonearea.value))
{
   if (!fv.isPhoneCode(form.wphonearea.value)) {
      msg=fv.getError("phonearea");
	  fv.raiseError(msg);
	  fv.changeTitleStyle('wphoneareatitle','titlecell_error','');
	}  
}
//validate phone 
if (fv.isEmpty(form.wphone.value))
{
msg=fv.getError("phone");
fv.raiseError(msg);
fv.changeTitleStyle('wphonetitle','titlecell_error','');
}
if (!fv.isEmpty(form.wphone.value))
{
   if (!fv.isPhone(form.wphone.value)) {
      msg=fv.getError("phone");
	  fv.raiseError(msg);
	  fv.changeTitleStyle('wphonetitle','titlecell_error','');
	}  
}
//validate phone ext 
if (!fv.isEmpty(form.wphoneext.value))
{
   if (!fv.isPhoneCode(form.wphoneext.value)) {
      msg=fv.getError("phoneext");
	  fv.raiseError(msg);
	//  fv.changeTitleStyle('phoneexttitle','titlecell_error','');
	}  
}
// Home phone
//validate area code if it was entered
if (!fv.isEmpty(form.hphonearea.value))
{
   if (!fv.isPhoneCode(form.hphonearea.value)) {
      msg=fv.getError("phonearea");
	  fv.raiseError(msg);
	  fv.changeTitleStyle('hphoneareatitle','titlecell_error','');
	}  
}
//validate phone if it was entered
if (!fv.isEmpty(form.hphone.value))
{
   if (!fv.isPhone(form.hphone.value)) {
      msg=fv.getError("phone");
	  fv.raiseError(msg);
	  fv.changeTitleStyle('hphonetitle','titlecell_error','');
	}  
}


// check for empty preferred contact
if (!fv.isChecked(form.contact_method[0]) && !fv.isChecked(form.contact_method[1]))
{
msg=fv.getError("contact_method");
fv.raiseError(msg);
fv.changeTitleStyle('contact_methodtitle','titlecell_error','');
}
// check for empty source field
if (fv.isEmpty(form.source.value))
{
msg=fv.getError("source");
fv.raiseError(msg);
fv.changeTitleStyle('sourcetitle','titlecell_error','');
}
// all done
// if errors, display, else proceed
if (fv.numErrors() > 0)
{
fv.displayErrors();
return false;
}
else
{
return true;
}
}



