<!--

function HighLightMenuOn(menuid,num) {
	document.images["menu" + menuid + "_" + num].src = eval("menu" + menuid + "on[num]");
}
function HighLightMenuOff(menuid,num) {
	document.images["menu" + menuid + "_" + num].src = eval("menu" + menuid + "[num]");
}

function submitRegister() {
	if (document.register.firstname.value==""){
		alert ("Please enter first name.");
		return false;
	} else if (document.register.lastname.value==""){
		alert ("Please enter last name.");
		return false;
/*	} else if (document.register.login.value==""){
		alert ("Please enter user name.");
		return false;*/
	} else if (document.register.state.value=="" && (document.register.country.value=="CANADA" || document.register.country.value=="USA")){
		alert("Please choose a state.");
		return false;
	} else {
		document.register.submit();
	}
}


function resetRegister() {
	document.register.reset();
}

	function checkNumber(val){
		re = /[^0-9,]/;
		var m=val.match(re);
		if (m){
			return false;
		}

		return true;
	}

	function checkInteger(val){
		re = /[^0-9]/;
		var m=val.match(re);
		if (m){
			return false;
		}

		return true;
	}

	function checkName(val){
		re=/[^a-zA-Z\-']/
		var m=val.match(re);
		if (m){
			return false;
		}

		return true;
	}

	function checkDate(val) {
		re = /^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}$/;
		var m=val.match(re);
		var arr;
		var b=true;
		arr=val.split("/",3);
		b=arr[0]<13 && arr[1]<32 && ((arr[2]>1900 && arr[2]<2079));
//alert(arr[0]+","+arr[1]+","+arr[2]);
		if (m && b)
			return true;

		return false;

	}

//http://www.faqts.com/knowledge_base/view.phtml/aid/1553
function makeDaysOfMonth(){
  var i = 0;
  this[i++] = 0; // dummy
  this[i++] = 31;
  this[i++] = 29;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 30;
  this[i  ] = 31;
  this.length = i;
}

//http://www.faqts.com/knowledge_base/view.phtml/aid/1553
function calcAge(dd, mm, yy){
  var t, mon, day, year, DD, MM, YY, age;
  var MTB = new makeDaysOfMonth();
  YY   = eval(yy);	// year of birth (4 digits)
  MM   = eval(mm) + 0;	// month of birth (1-12)
  DD   = eval(dd);	// date of birth (1-31)
  if (MTB[MM] < DD || DD < 1) return -1;
  t    = new Date();	// get current date
  year = t.getFullYear();	// get year of current
  mon  = t.getMonth() + 1;	// get month of current
  day  = t.getDate();	// get date of current
  if (MM == 2 && DD == 29){	// check leap year
    if (!(((YY % 4 == 0) && (YY % 100 != 0)) || (YY % 400 == 0))){
      alert("The year " +YY+ " ends at 28th of "+MM+" month\nPlease check the date.");
      return -1;
    }
  }
  age = year - YY;
  if ((MM > mon) || (MM == mon && day < DD)) age --;

  return age;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.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=eval(strMonth)
	day=eval(strDay)
	year=eval(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

	function checkAnti(val){
		re = /^[0-9]{2}\w+$/;
		var m=val.match(re);

		if (m){
			return true;
		}
		return false;
	}

	function checkDonor() {	
		if (document.DonorRequest.__01ConsentResponse[1].checked == true){
			alert("Please read and agree to the Primary Consent to Participate as a Donor by selecting Yes at the top of the page.");
			return;
		}
		if ( document.DonorRequest.ma_insured[0].checked == false && document.DonorRequest.ma_insured[1].checked == false ){
			alert("Please answer the question following #15: Are you medically insured...");
			return;
		}
		if (document.DonorRequest.__02First_name.value == ""){
			alert("Please enter your first name.");
			document.DonorRequest.__02First_name.focus();
			return;
		}
		if (document.DonorRequest.__03Last_name.value == ""){
			alert("Please enter your last name.");
			document.DonorRequest.__03Last_name.focus();
			return;
		}
		if (document.DonorRequest.__05Date_of_birth.value=="" || !isDate(document.DonorRequest.__05Date_of_birth.value )){
			alert("Please make sure that the date (DOB) is in the correct format. mm/dd/yyyy.");
			document.DonorRequest.__05Date_of_birth.focus();
			return;
		}		
		arr=document.DonorRequest.__05Date_of_birth.value.split("/",3);
		age = calcAge(arr[1], arr[0], arr[2])
		if (age>=61){
			alert("The Caitlin Raymond International Registry can only register donors under the age of 61.  The date of birth you have entered indicates that you are 61 years of age or older and thus we cannot register you as a donor.  For further information please contact us at 1-800-726-2824.");
			document.DonorRequest.__05Date_of_birth.focus();
			return;
		}
		if (age<16){
			alert("The Caitlin Raymond International Registry can only register donors over the age of 16.  The date of birth you have entered indicates that you are under 16 years of age and thus we cannot register you as a donor.  For further information please contact us at 1-800-726-2824.");
			document.DonorRequest.__05Date_of_birth.focus();
			return;
		}
		if (age>=16 && age<18){
			alert("The date of birth you have entered indicates that you are between the ages of 16 and 18.  Although we allow testing on donors between 16 and 18 your registration will not become active until your 18th birthday.  For further information please contact us at 1-800-726-2824.");
		}
		if (document.DonorRequest.sex.value==""){
			alert("Please select a Sex.");
			document.DonorRequest.sex.focus();
			return;
		}		
//		if (document.DonorRequest.__07Race.value==""){
//			alert("Please enter a Race.");
//			document.DonorRequest.__07Race.focus();
//			return;
//		}
		if (document.DonorRequest.__10Address.value==""){
			alert("Please enter an Address.");
			document.DonorRequest.__10Address.focus();
			return;
		}
		if (document.DonorRequest.__11City.value==""){
			alert("Please enter a City.");
			document.DonorRequest.__11City.focus();
			return;
		}			
		if (document.DonorRequest.__12State.value==""){
			alert("Please enter a State.");
			document.DonorRequest.__12State.focus();
			return;
		}
		if (document.DonorRequest.__13Zip.value==""){
			alert("Please enter a Zipcode.");
			document.DonorRequest.__13Zip.focus();
			return;
		}
		if (document.DonorRequest.__14Email.value==""){
			alert("Please enter an Email Address.");
			document.DonorRequest.__14Email.focus();
			return;
		}
		if (document.DonorRequest.__15Telephone_Home.value=="" && document.DonorRequest.__16Telephone_Work.value=="" && document.DonorRequest.__17Telephone_Mobile.value==""){
			alert("Please enter a Telephone Number where you can be reach in any of the available telephone number fields.");
			document.DonorRequest.__15Telephone_Home.focus();
			return;
		}
		if (document.DonorRequest.tf_1[1].checked==false && document.DonorRequest.tf_1[0].checked==false){
			alert("Please enter an answer for question 1.");
			return;
		}
		if (document.DonorRequest.tf_2[1].checked==false && document.DonorRequest.tf_2[0].checked==false){
			alert("Please enter an answer for question 2.");
			return;
		}
		if (document.DonorRequest.tf_3[1].checked==false && document.DonorRequest.tf_3[0].checked==false){
			alert("Please enter an answer for question 3.");
			return;
		}
		if (document.DonorRequest.tf_3[0].checked==true  && document.DonorRequest.__23Number_of_Pregnancies.value==""){
			alert("You have indicated that you have been pregnant.  Please enter the number of pregnancies.");
			return;
		}
		if (document.DonorRequest.tf_3[0].checked==true  && document.DonorRequest.__24Number_of_Live_Births.value==""){
			alert("You have indicated that you have been pregnant.  Please enter the number of live births.");
			return;
		}
		if (document.DonorRequest.tf_4[1].checked==false && document.DonorRequest.tf_4[0].checked==false){
			alert("Please enter an answer for question 4.");
			return;
		}
		if (document.DonorRequest.tf_5[1].checked==false && document.DonorRequest.tf_5[0].checked==false){
			alert("Please enter an answer for question 5.");
			return;
		}
		if (document.DonorRequest.tf_6[1].checked==false && document.DonorRequest.tf_6[0].checked==false){
			alert("Please enter an answer for question 6.");
			return;
		}
		if (document.DonorRequest.tf_7[1].checked==false && document.DonorRequest.tf_7[0].checked==false){
			alert("Please enter an answer for question 7.");
			return;
		}
		if (document.DonorRequest.tf_8[1].checked==false && document.DonorRequest.tf_8[0].checked==false){
			alert("Please enter an answer for question 8.");
			return;
		}
		if (document.DonorRequest.tf_9[1].checked==false && document.DonorRequest.tf_9[0].checked==false){
			alert("Please enter an answer for question 9.");
			return;
		}
		if (document.DonorRequest.tf_10[1].checked==false && document.DonorRequest.tf_10[0].checked==false){
			alert("Please enter an answer for question 10.");
			return;
		}
		if (document.DonorRequest.tf_11[1].checked==false && document.DonorRequest.tf_11[0].checked==false){
			alert("Please enter an answer for question 11.");
			return;
		}
		if (document.DonorRequest.tf_12[1].checked==false && document.DonorRequest.tf_12[0].checked==false){
			alert("Please enter an answer for question 12.");
			return;
		}
		if (document.DonorRequest.tf_13[1].checked==false && document.DonorRequest.tf_13[0].checked==false){
			alert("Please enter an answer for question 13.");
			return;
		}
		if (document.DonorRequest.tf_14[1].checked==false && document.DonorRequest.tf_14[0].checked==false){
			alert("Please enter an answer for question 14.");
			return;
		}
		if (document.DonorRequest.tf_15[1].checked==false && document.DonorRequest.tf_15[0].checked==false){
			alert("Please enter an answer for question 15.");
			return;
		}


		if (document.DonorRequest.__41Friends_name.value==""){
			alert("Please enter a Relative's Name.");
			document.DonorRequest.__41Friends_name.focus();
			return;
		}
		if (document.DonorRequest.__42Friends_relationship.value==""){
			alert("Please enter your relative's Relationship to you.");
			document.DonorRequest.__42Friends_relationship.focus();
			return;
		}
		if (document.DonorRequest.__47Friends_phone.value == "" ) {
			//no phone number
			if (document.DonorRequest.__43Friends_address.value == "" ) {
				//no address
				alert("Please enter a telephone number or an address with city and state or zipcode for you relative.");
				document.DonorRequest.__43Friends_address.focus();
				return;
			} else if (document.DonorRequest.__46Friends_Zip.value == "" && !(document.DonorRequest.__44Friends_City.value != "" && document.DonorRequest.__45Friend_State.value != "") ) {
				//address - no city and state or zip
					alert("Please enter a telephone number or an address with city and state or zipcode for you relative.");
					document.DonorRequest.__43Friends_address.focus();
					return;
				
			}

		}
		document.DonorRequest.submit();
	}


	function checkDonorInsuranceOrPayment(){
		if (document.DonorInsuranceOrPayment.type.value == "MAInsured") {
			//__49Insurance_Company
			if (document.DonorInsuranceOrPayment.__49Insurance_Company.value == "") {
				alert("Please enter the insurance company name.");
				document.DonorInsuranceOrPayment.__49Insurance_Company.focus();
				return;
			}
			//__51IDNum
			if (document.DonorInsuranceOrPayment.__51IDNum.value == "") {
				alert("Please enter the insurance id number.");
				document.DonorInsuranceOrPayment.__51IDNum.focus();
				return;
			}
			//__54Name_of_Insured
			if (document.DonorInsuranceOrPayment.__54Name_of_Insured.value == "") {
				alert("Please enter the name of the subscriber.");
				document.DonorInsuranceOrPayment.__54Name_of_Insured.focus();
				return;
			}
			//__57Insureds_Employer
			if (document.DonorInsuranceOrPayment.__57Insureds_Employer.value == "") {
				alert("Please enter subscriber's employer.");
				document.DonorInsuranceOrPayment.__57Insureds_Employer.focus();
				return;
			}
			//__58InsuredState
			if (document.DonorInsuranceOrPayment.__58InsuredState.value == "") {
				alert("Please enter the state in which the subscriber is employed.");
				document.DonorInsuranceOrPayment.__58InsuredState.focus();
				return;
			}
		}
		
		if (document.DonorInsuranceOrPayment.type.value == "MANotInsured") {
		//check nothing in this case.
		}
		
		if (document.DonorInsuranceOrPayment.type.value == "Payment") {
			//only check the fields below if they wish to pay by credit card
			if (document.DonorInsuranceOrPayment.__61Payment_type[0].checked == false && document.DonorInsuranceOrPayment.__61Payment_type[1].checked == false && document.DonorInsuranceOrPayment.__61Payment_type[2].checked == false) {
				alert("Please select a payment type.");
				return;			
			}
			if (document.DonorInsuranceOrPayment.__61Payment_type[1].checked == true) {
				if (document.DonorInsuranceOrPayment.__62Credit_Card_Type.value == "" || document.DonorInsuranceOrPayment.__62Credit_Card_Type.value == "Click to Choose") {
					alert("Please select a credit card type.");
					document.DonorInsuranceOrPayment.__62Credit_Card_Type.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.__63Card_Holder.value == "" ) {
					alert("Please enter the credit card holder as it appears on the card.");
					document.DonorInsuranceOrPayment.__63Card_Holder.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.__64Card_Number.value == "" ) {
					alert("Please enter the credit card number.");
					document.DonorInsuranceOrPayment.__64Card_Number.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.__65Expiration_Date.value == "" ) {
					alert("Please enter the credit card expiration date.");
					document.DonorInsuranceOrPayment.__65Expiration_Date.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.__66Card_Verification_Number.value == "" ) {
					alert("Please enter the credit card verification number date.");
					document.DonorInsuranceOrPayment.__66Card_Verification_Number.focus();
					return;
				}
			
			
			
			}
		
		}
		document.DonorInsuranceOrPayment.submit();	
	}








// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}








	function check_consentform_2c(){
		value = getCheckedValue(document.DonorInsuranceOrPayment.payment_type);

		if ( value == "" )
			{
				alert("Please select a Donation Option.");
				return false;
			}

		if (value == "credit_card") {
			//only check the fields below if they wish to pay by credit card

				if (document.DonorInsuranceOrPayment.credit_card_type.value == "" || 
							document.DonorInsuranceOrPayment.credit_card_type.value == "Click to Choose") 
				{
					alert("Please select a credit card type.");
					document.DonorInsuranceOrPayment.credit_card_type.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.card_holder.value == "" ) {
					alert("Please enter the credit card holder as it appears on the card.");
					document.DonorInsuranceOrPayment.card_holder.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.card_number.value == "" ) {
					alert("Please enter the credit card number.");
					document.DonorInsuranceOrPayment.card_number.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.card_expiration.value == "" ) {
					alert("Please enter the credit card expiration date.");
					document.DonorInsuranceOrPayment.card_expiration.focus();
					return;
				}
				if (document.DonorInsuranceOrPayment.card_verification_number.value == "" ) {
					alert("Please enter the credit card verification number.");
					document.DonorInsuranceOrPayment.card_verification_number.focus();
					return;
				}
			
					
		}
		document.DonorInsuranceOrPayment.submit();	
	}





	function check_consentform_2a() {
		if (document.DonorInsuranceOrPayment.certify.checked == false)
		{
			alert("Please select the check box if you agree to the information provided.");
			document.DonorInsuranceOrPayment.certify.focus();
			return;
		}
		if (document.DonorInsuranceOrPayment.insurance_company.value == "") {
			alert("Please enter the insurance company name.");
			document.DonorInsuranceOrPayment.insurance_company.focus();
			return;
		}
		if (document.DonorInsuranceOrPayment.id_number.value == "") {
			alert("Please enter the insurance id number.");
			document.DonorInsuranceOrPayment.id_number.focus();
			return;
		}
		if (document.DonorInsuranceOrPayment.name_of_insured.value == "") {
			alert("Please enter the name of the subscriber.");
			document.DonorInsuranceOrPayment.name_of_insured.focus();
			return;
		}
		if (document.DonorInsuranceOrPayment.subscriber_employer.value == "") {
			alert("Please enter subscriber's employer.");
			document.DonorInsuranceOrPayment.subscriber_employer.focus();
			return;
		}
		//__58InsuredState
		if (document.DonorInsuranceOrPayment.insured_state.value == "") {
			alert("Please enter the state in which the subscriber is employed.");
			document.DonorInsuranceOrPayment.insured_state.focus();
			return;
		}
		
		document.DonorInsuranceOrPayment.submit();	
	}









	function checkRequest(){
		var i,j;
		if (document.request.t_FrstName.value=="" || !checkName(document.request.t_FrstName.value )){
			alert("You did not enter the first name field in the proper format. Please make sure that you enter only letters.");
			document.request.t_FrstName.focus();
			return;
		}

		if (document.request.t_LastName.value=="" || !checkName(document.request.t_LastName.value )){
			alert("You did not enter the last name field in the proper format. Please make sure that you enter only letters.");
			document.request.t_LastName.focus();
			return;
		}

		/*for (i=1;i<8;i++)
			for (j=1;j<3;j++)
			{
				obj=document.all("a_"+i+""+j);
				if (obj.value!="" && !checkAnti(obj.value))
				{
					alert("Please enter the proper format for antigens. They should begin with two number-digits and end with a combination of numbers and letters.");
					obj.focus();
					return;
				}
			}*/


		if (document.request.t_SearchType.value==""){
			alert("Please choose a search type.");
			document.request.t_SearchType.focus();
			return;
		}

		if (document.request.t_State.value=="" && (document.request.t_Country.value=="CANADA" || document.request.t_Country.value=="USA")){
			alert("Please choose a state.");
			document.request.t_State.focus();
			return;
		}

		if (document.request.t_Country.value==""){
			alert("Please select a Country.");
			document.request.t_Country.focus();
			return;
		}

		if (document.request.t_Weight.value=="" || !checkInteger(document.request.t_Weight.value) || document.request.t_Weight.value <= 0){
			alert("Please make sure that the weight is a non-decimal number. Also, this field will not accept a weight less than 0 kilograms.");
			document.request.t_Weight.focus();
			return;
		}

		if (document.request.t_DOB.value=="" || !checkDate(document.request.t_DOB.value )){
			alert("Please make sure that the date (DOB) is in correct format. mm/dd/yyyy.");
			document.request.t_DOB.focus();
			return;
		}
		if (document.request.t_DXDate.value == "" || !checkDate(document.request.t_DXDate.value)){
			alert("Please make sure that the date (Date of diagnosis) is in correct format. mm/dd/yyyy.");
			document.request.t_DXDate.focus();
			return;
		}
		if (document.request.t_DX.value == ""){
			alert("Please select a Diagnosis.");
			document.request.t_DX.focus();
			return;
		}
		if (document.request.a_11.value == ""){
			alert("Please enter the patients A antigens.");
			document.request.a11.focus();
			return;
		}
		if (document.request.a_21.value == ""){
			alert("Please enter the patients B antigens.");
			document.request.a21.focus();
			return;
		}
		if (document.request.a_41.value == ""){
			alert("Please enter the patients DR/DRB1 antigens.");
			document.request.a41.focus();
			return;
		}	
		if (document.request.t_Sex.value==""){
			alert("Please select a Gender.");
			document.request.t_Sex.focus();
			return;
		}
		if (document.request.PhysLast.value==""){
			alert("Please enter the name of the Attending Physician.");
			document.request.PhysLast.focus();
			return;
		}
		if (document.request.PhysicianAddress.value==""){
			alert("Please enter the address of the Attending Physician.");
			document.request.PhysicianAddress.focus();
			return;
		}
		if (document.request.PhysicianTelephone.value==""){
			alert("Please enter the telephone number of the Attending Physician.");
			document.request.PhysicianTelephone.focus();
			return;
		}


		if (document.request.PhysicianEMail.value==""){
			alert("Please enter the email address of the Attending Physician.");
			document.request.PhysicianEMail.focus();
			return;
		}
		
		document.request.submit();
	}

function submitLogin() {
	document.login.submit();
}
function submitPatientinfo() {
	document.patientinfo.submit();
}
function submitPatientCancel() {
	document.cancelsearch.submit();
}
function submitForgot() {
	document.forgot.submit();
}

function submitChangePass() {
	document.changepass.submit();
}

function showP(urlString,w_width,w_height,scrollB){
	center_x = Math.round((window.screen.width - w_width) / 2);
	center_y = Math.round((window.screen.height - w_height) / 2);
	window.open(urlString,"_blank","width=" + w_width + ",height=" + w_height + ",top=" + center_y + ",left=" + center_x + ",menubar=no,resizable=no,status=no,titlebar=no,toolbar=no,scrollbars=" + scrollB);
}

function confirmDelete()
{
	var selection = confirm ("Are you sure you want to delete your record?");
	if (selection)
		return true;
	else
		return false;
}
//-->

