
function VerifyCheckBox(checkBoxElement)
{
	if (checkBoxElement.checked)	checkBoxElement.value = 'true';
	else checkBoxElement.value = 'false';
}

function ValidateData(theForm)
{


	if (theForm.contactDate.value != "")
	{
		//alert("Test");
		return (false);
	}
	if (theForm.FirstName.value == "")
	{
		alert('Please, enter your first name.');
		theForm.FirstName.focus();
		return (false);
	}

	if (theForm.LastName.value == "")
	{
		alert('Please, enter your last name.');
		theForm.LastName.focus();
		return (false);
	}

	if (theForm.Phone.value == "")
	{
		alert('Please, enter your phone.');
		theForm.Phone.focus();
		return (false);
	}

	/*
	if (theForm.Email.value == "")
	{
		alert('Please, enter your email.');
		theForm.Email.focus();
		return (false);
	}
	*/

	if ((theForm.Email.value == "") || (theForm.Email.value == 'Email'))
	{
	alert('Please, enter your email.');
	theForm.Email.focus();
	return (false);
	}
	else
	{
	if(!ValidateEmail(theForm.Email.value))
	{
	alert("Please check the emails address");
	theForm.Email.focus();
	return false;
	}
	}
	
	if ((theForm.DateOfBirth.value != ""))
	{
		if(!ValidateDateOfBirth(theForm.DateOfBirth.value))
		{
			alert("Please check the date of birth");
			theForm.DateOfBirth.focus();
			return false;
		}
	}

	if ((theForm.ReplyByPhone.checked==false) && (theForm.ReplyByEmail.checked==false))
	{
		alert('Please, select how would you like us to reply.');
		theForm.ReplyByPhone.focus();
		return (false);
	}

	CheckValues(theForm);
	
	if (theForm.BlemishScar.checked)
	{		
		return (true);
	}
	if (theForm.Blepharoplasty.checked)
	{		
		return (true);
	}
	if (theForm.Botox.checked)
	{
		return (true);
	}
	if (theForm.Browlift.checked)
	{
		return (true);
	}
	if (theForm.CheekImplants.checked)
	{
		return (true);
	}
	if (theForm.CheekLift.checked)
	{
		return (true);
	}
	if (theForm.ChinImplant.checked)
	{
		return (true);
	}
	if (theForm.Dermabrasion.checked)
	{		
		return (true);
	}
	if (theForm.Facelift.checked)
	{
		return (true);
	}
	if (theForm.FacialLiposuction.checked)
	{
		return (true);
	}
	if (theForm.HairTransplantation.checked)
	{
		return (true);
	}
	if (theForm.LaserHairRemoval.checked)
	{
		return (true);
	}		
	if (theForm.LaserSkinResurfacing.checked)
	{
		return (true);
	}		
	if (theForm.LipAugmentation.checked)
	{
		return (true);
	}		
	if (theForm.NeckLiposuction.checked)
	{
		return (true);
	}		
	if (theForm.Otoplasty.checked)
	{
		return (true);
	}
	if (theForm.Rhinoplasty.checked)
	{
		return (true);
	}
	if (theForm.TatooRemoval.checked)
	{
		return (true);
	}
	if (theForm.Thermage.checked)
	{
		return (true);
	}
	if (theForm.WrinkleFillers.checked)
	{
		return (true);
	}
		

	alert('Please, select a procedure.');
	return (false);
}

function ValidateEmail(incoming) 
{
 var emailstring = incoming;
 var ampIndex = emailstring.indexOf("@");
 var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
 // find a dot in the portion of the string after the ampersand only
 var dotIndex = afterAmp.indexOf(".");
 // determine dot position in entire string (not just after amp portion)
 dotIndex = dotIndex + ampIndex + 1;
 // afterAmp will be portion of string from ampersand to dot
 afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
 // afterDot will be portion of string from dot to end of string
 var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
 var beforeAmp = emailstring.substring(0,(ampIndex));
 //var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
 // index of -1 means "not found"
 
 if ((emailstring.indexOf("@") != "-1") &&
	(emailstring.indexOf(".") != "-1") &&
  (emailstring.length > 5) &&
  (afterAmp.length > 0) &&
  (beforeAmp.length > 1) &&
  (afterDot.length > 1) //&&
  //(email_regex.test(emailstring))
  ) 
 {
  return true;
 } 
 else {
  return false;
 }
}

function CheckValues(theForm)
{
	if (theForm.BlemishScar.checked)
	{
		theForm.BlemishScar.value = 'true';
	}
	else
	{
		theForm.BlemishScar.value = 'false';
	}
	
	if (theForm.Blepharoplasty.checked)
	{		
		theForm.Blepharoplasty.value = 'true';
	}
	else
	{
		theForm.Blepharoplasty.value = 'false';
	}
	
	if (theForm.Botox.checked)
	{
		theForm.Botox.value = 'true';
	}
	else
	{
		theForm.Botox.value = 'false';
	}
	
	if (theForm.Browlift.checked)
	{
		theForm.Browlift.value = 'true';
	}
	else
	{
		theForm.Browlift.value = 'false';
	}	
	
	if (theForm.CheekImplants.checked)
	{
		theForm.CheekImplants.value = 'true';
	}
	else
	{
		theForm.CheekImplants.value = 'false';
	}
	
	if (theForm.CheekLift.checked)
	{
		theForm.CheekLift.value = 'true';
	}
	else
	{
		theForm.CheekLift.value = 'false';
	}
	
	if (theForm.ChinImplant.checked)
	{
		theForm.ChinImplant.value = 'true';
	}
	else
	{
		theForm.ChinImplant.value = 'false';
	}
	
	if (theForm.Dermabrasion.checked)
	{		
		theForm.Dermabrasion.value = 'true';
	}
	else
	{
		theForm.Dermabrasion.value = 'false';
	}
	
	if (theForm.Facelift.checked)
	{
		theForm.Facelift.value = 'true';
	}
	else
	{
		theForm.Facelift.value = 'true';
	}
	
	if (theForm.FacialLiposuction.checked)
	{
		theForm.FacialLiposuction.value = 'true';
	}
	else
	{
		theForm.FacialLiposuction.value = 'false';
	}
	
	if (theForm.HairTransplantation.checked)
	{
		theForm.HairTransplantation.value = 'true';
	}
	else
	{
		theForm.HairTransplantation.value = 'false';
	}
	
	if (theForm.LaserHairRemoval.checked)
	{
		theForm.LaserHairRemoval.value = 'true';
	}	
	else
	{
		theForm.LaserHairRemoval.value = 'false';
	}
		
	if (theForm.LaserSkinResurfacing.checked)
	{
		theForm.LaserSkinResurfacing.value = 'true';
	}
	else
	{
		theForm.LaserSkinResurfacing.value = 'false';
	}
		
	if (theForm.LipAugmentation.checked)
	{
		theForm.LipAugmentation.value = 'true';
	}
	else
	{
		theForm.LipAugmentation.value = 'false';
	}
	
	if (theForm.NeckLiposuction.checked)
	{
		theForm.NeckLiposuction.value = 'true';
	}
	else
	{
		theForm.NeckLiposuction.value = 'false';
	}	
	
	if (theForm.Otoplasty.checked)
	{
		theForm.Otoplasty.value = 'true';
	}
	else
	{
		theForm.Otoplasty.value = 'false';
	}
	
	if (theForm.Rhinoplasty.checked)
	{
		theForm.Rhinoplasty.value = 'true';
	}
	else
	{
		theForm.Rhinoplasty.value = 'false';
	}
	
	if (theForm.TatooRemoval.checked)
	{
		theForm.TatooRemoval.value = 'true';
	}
	else
	{
		theForm.TatooRemoval.value = 'false';
	}
	
	if (theForm.Thermage.checked)
	{
		theForm.Thermage.value = 'true';
	}
	else
	{
		theForm.Thermage.value = 'false';
	}
	
	if (theForm.WrinkleFillers.checked)
	{
		theForm.WrinkleFillers.value = 'true';
	}
	else
	{
		theForm.WrinkleFillers.value = 'false';
	}
}

function ValidateDateOfBirth(fld) 
{
 var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
 if ((fld.match(RegExPattern))) {
     var ar = fld.split("/"); 
     var a = ar[2];
     if(a.length==4) 
      return true;
     else
      return false; 
 } 
 else{
     return false;
 } 
}