<!--
/* **********************************************************************************************************
Module Name  : registration.js
Date Written : 08/11/2002
Company      : CRKInteractive
Copyright    : (c) 2002, 2003 CRKInteractive All Rights Reserved
Purpose      : To provide a set of functions that handle client side registration logic for CBC event 
               registrations
Revisions    :
************************************************************************************************************/
/* **********************************************************************************************************
Constants
************************************************************************************************************/

/* **********************************************************************************************************
Variables
************************************************************************************************************/

/* **********************************************************************************************************
Startup Code
************************************************************************************************************/

/* **********************************************************************************************************
Functions
************************************************************************************************************/
/* ----------------------------------------------------------------------------------------------------------
Routine Name : CopyRegistrationInfoToCcBillingInfo
Date Written : 08/11/2002
Author       : Peter R Lynch (plynch@crkinteractive.com)
Purpose      : To copy registration info to cc billing info
Parameters   : [IN] objForm - registration form object
Returns      : None
Revisions    :
-----------------------------------------------------------------------------------------------------------*/
function CopyRegistrationInfoToCcBillingInfo(objForm)
{ objForm.ccFirstName.value = objForm.firstName.value;
  objForm.ccLastName.value = objForm.lastName.value;
  objForm.ccStreet1.value = objForm.street1.value;
  objForm.ccStreet2.value = objForm.street2.value;
  objForm.ccCity.value = objForm.city.value;
  objForm.ccStateID.selectedIndex = objForm.stateID.selectedIndex;
  objForm.ccStateOther.value = objForm.stateOther.value;
  objForm.ccZipCode.value = objForm.zipCode.value;
  objForm.ccCountryID.selectedIndex = objForm.countryID.selectedIndex;
}
/* ----------------------------------------------------------------------------------------------------------
Routine Name : ComputeAmount
Date Written : 08/11/2002
Author       : Peter R Lynch (plynch@crkinteractive.com)
Purpose      : To compute credit card amount depending on the selections made during registration and set
               the ccAmount field value
Parameters   : [IN] objForm - registration form object
Returns      : None
Revisions    :
-----------------------------------------------------------------------------------------------------------*/
function ComputeAmount(objForm)
{ var intI, curCcAmount;
  curCcAmount = 0;
  for(intI = 0; intI < objForm.elements.length; intI++)
  { var objElement = objForm.elements[intI];
    if(objElement.name == "tuitionID")
    { if(objElement.checked)
      { if(objElement.rate)
        { curCcAmount += parseFloat(objElement.rate);
        }
        else
        { curCcAmount += parseFloat(eval("objForm.tuitionRate" + objElement.value + ".value"));
        }
      }
    }
  }
  objForm.ccAmount.value = curCcAmount;
}

/* ----------------------------------------------------------------------------------------------------------
Routine Name : SetRate
Date Written : 08/11/2002
Author       : Peter R Lynch (plynch@crkinteractive.com)
Purpose      : To provide a rate attribute work around for NS browsers
Parameters   : [IN] objElement - element to create the custom attribute on
             : [IN] curRate - value to set the attribute to
Returns      : None
Revisions    :
-----------------------------------------------------------------------------------------------------------*/
function SetRate(objElement, strTuitionType, curTuitionRate)
{ objElement.tuitionType = strTuitionType;
  objElement.tuitionRate = curTuitionRate;
  eval("objElement.form.tuitionType" + objElement.value + ".value = '" + strTuitionType + "'");
  eval("objElement.form.tuitionRate" + objElement.value + ".value = " + curTuitionRate);
}

/* ----------------------------------------------------------------------------------------------------------
Routine Name : TrimWhiteSpaceSTR
Date Written : 08/11/2002
Author       : Peter R Lynch (plynch@crkinteractive.com)
Purpose      : To trim leading and trailing whitespaces off a string
Parameters   : [IN] strSource - source string
Returns      : trimmed string
Revisions    :
-----------------------------------------------------------------------------------------------------------*/
function TrimWhiteSpaceSTR(strSource)
{ var strTrimmed = strSource;
  strTrimmed = strTrimmed.replace(/^\s+/, "");
  strTrimmed = strTrimmed.replace(/\s+$/, "");
  return strTrimmed;
}

/* ----------------------------------------------------------------------------------------------------------
Routine Name : ValidatePreregistrationBLN
Date Written : 08/11/2002
Author       : Peter R Lynch (plynch@crkinteractive.com)
Purpose      : To validate preregistration form fields for all required infomation
Parameters   : [IN] objForm - preregistration form object
Returns      : True if form is validated, False if not validated
Revisions    :
-----------------------------------------------------------------------------------------------------------*/
function ValidatePreregistrationBLN(objForm)
{ var intI, strPaymentMethod, strErrorMessage = "";
  //Run through all fields and trim white spaces
  var blnPhoneTypeSelected = false;
  for(intI = 0; intI < objForm.elements.length; intI++)
  { var objElement = objForm.elements[intI];
    if(objElement.name == "phoneNumberType")
    { if(objElement.checked) { blnPhoneTypeSelected = true; }
    }
    //Trim up all text boxes
    if(objElement.type == "text" || objElement.type == "textarea")
    { objElement.value = TrimWhiteSpaceSTR(objElement.value);
    }
  }

  //Verify all required personal information
  if(objForm.firstName.value == "") { strErrorMessage += "First Name is required.\n"; }
  if(objForm.lastName.value == "") { strErrorMessage += "Last Name is required.\n"; }
  if(objForm.degree.value == "") { strErrorMessage += "Degree is required.\n"; }

  //Verify all required contact information
  if(objForm.street1.value == "") { strErrorMessage += "Street address is required.\n"; }
  if(objForm.city.value == "") { strErrorMessage += "City is required.\n"; }
  if(objForm.stateID.value == "") { strErrorMessage += "State is required.\n"; }
  if(objForm.zipCode.value == "") { strErrorMessage += "Zip/Postal Code is required.\n"; }
  if(objForm.countryID.value == "") { strErrorMessage += "Country is required.\n"; }
  if(objForm.phoneNumber.value == "") { strErrorMessage += "Business or Home Phone number is required.\n"; }
  if(!blnPhoneTypeSelected) { strErrorMessage += "A phone number type (Business/Home) must be selected.\n"; }
  if(objForm.faxNumber.value == "" && objForm.emailAddress.value == "") { strErrorMessage += "Fax number or Email address is required.\n"; }

  //Check to see if there were any errors then alert the submitter and return false
  if(strErrorMessage != "")
  { strErrorMessage = "The following must be corrected before your pre-registration can be submitted on-line:\n\n" + strErrorMessage;
    alert(strErrorMessage);
    return false;
  }
  else
  { return true;
  }
}

/* ----------------------------------------------------------------------------------------------------------
Routine Name : ValidateRegistrationBLN
Date Written : 08/11/2002
Author       : Peter R Lynch (plynch@crkinteractive.com)
Purpose      : To validate registration form fields for all required infomation
Parameters   : [IN] objForm - registration form object
Returns      : True if form is validated, False if not validated
Revisions    :
-----------------------------------------------------------------------------------------------------------*/
function ValidateRegistrationBLN(objForm)
{ var intI, strPaymentMethod, strErrorMessage = "";
  //Run through all fields and look at specific radio button fields
  var blnRoomTypeIdSelected = blnBedTypeIdSelected = blnSmokingSelected = blnTuitionIdSelected = blnPaymentMethodSelected = blnPhoneTypeSelected = false;
  for(intI = 0; intI < objForm.elements.length; intI++)
  { var objElement = objForm.elements[intI];
    if(objElement.name == "roomTypeID")
    { if(objElement.checked) { blnRoomTypeIdSelected = true; }
    }
    if(objElement.name == "bedTypeID")
    { if(objElement.checked) { blnBedTypeIdSelected = true; }
    }
    if(objElement.name == "smokingRoom")
    { if(objElement.checked) { blnSmokingSelected = true; }
    }
    if(objElement.name == "phoneNumberType")
    { if(objElement.checked) { blnPhoneTypeSelected = true; }
    }
    if(objElement.name == "tuitionID")
    { if(objElement.type == "radio" && objElement.checked) { blnTuitionIdSelected = true; }
    }
    if(objElement.name == "paymentMethod")
    { if(objElement.checked)
      { blnPaymentMethodSelected = true;
        if(objElement.value == "Tuition Check")
        { strErrorMessage += "NOTE: Payment by check cannot be submitted on-line. Either reselect to pay by Credit Card or print out this registration form and send it along with your check made payable to CBC, Inc.\n\n";
        }
        strPaymentMethod = objElement.value;
      }
    }
    //Trim up all text boxes
    if(objElement.type == "text" || objElement.type == "textarea")
    { objElement.value = TrimWhiteSpaceSTR(objElement.value);
    }
  }

  //Verify all required personal information
  if(objForm.firstName.value == "") { strErrorMessage += "First Name is required.\n"; }
  if(objForm.lastName.value == "") { strErrorMessage += "Last Name is required.\n"; }
  if(objForm.degree.value == "") { strErrorMessage += "Degree is required.\n"; }

  //Verify all required contact information
  if(objForm.street1.value == "") { strErrorMessage += "Street address is required.\n"; }
  if(objForm.city.value == "") { strErrorMessage += "City is required.\n"; }
  if(objForm.stateID[objForm.stateID.selectedIndex].value == "") { strErrorMessage += "State is required.\n"; }
  if(objForm.zipCode.value == "") { strErrorMessage += "Zip/Postal Code is required.\n"; }
  if(objForm.countryID[objForm.countryID.selectedIndex].value == "") { strErrorMessage += "Country is required.\n"; }
  if(objForm.phoneNumber.value == "") { strErrorMessage += "Business or Home Phone number is required.\n"; }
  if(!blnPhoneTypeSelected) { strErrorMessage += "A phone number type (Business/Home) must be selected.\n"; }
  if(objForm.faxNumber.value == "" && objForm.emailAddress.value == "") { strErrorMessage += "Fax number or Email address is required.\n"; }

  //Verify all required room information
  if(objForm.RoomRequested)
  { if(objForm.RoomRequested.checked)
    { if(objForm.checkInDate[objForm.checkInDate.selectedIndex].value == "") { strErrorMessage += "Room Check-In Date is required.\n"; }
      if(objForm.checkOutDate[objForm.checkOutDate.selectedIndex].value == "") { strErrorMessage += "Room Check-Out Date is required.\n"; }
      if(!blnRoomTypeIdSelected) { strErrorMessage += "Type of Room is required.\n"; }
      if(!blnBedTypeIdSelected)  { strErrorMessage += "Type of Bed is required.\n"; }
      if(!blnSmokingSelected)    { strErrorMessage += "Smoking preference is required.\n"; }
    }
  }

  //Verify all required tuition information
  if(!blnTuitionIdSelected) { strErrorMessage += "Tuition Rate is required.\n"; }
  
  //Verify all required payment information
  if(!blnPaymentMethodSelected)
  { strErrorMessage += "Payment Method is required.\n";
  }
  else
  { if(strPaymentMethod != "Tuition Check")
    { if(objForm.typeID[objForm.typeID.selectedIndex].value == "") { strErrorMessage += "Card is required.\n"; }
      if(objForm.cardOwnerTypeID[objForm.cardOwnerTypeID.selectedIndex].value == "") { strErrorMessage += "Card Type is required.\n"; }
      if(objForm.ccNumber.value == "") { strErrorMessage += "Credit Card # is required.\n"; }
      if(objForm.ccCVV2.value == "") { strErrorMessage += "Card Security Code is required.\n"; }
      if(objForm.ccMonth[objForm.ccMonth.selectedIndex].value == "") { strErrorMessage += "Credit Card Expiration Month is required.\n"; }
      if(objForm.ccYear[objForm.ccYear.selectedIndex].value == "") { strErrorMessage += "Credit Card Expiration Year is required.\n"; }
      if(objForm.ccFirstName.value == "") { strErrorMessage += "Credit Card Billing First Name is required.\n"; }
      if(objForm.ccLastName.value == "") { strErrorMessage += "Credit Card Billing Last Name is required.\n"; }
      if(objForm.ccStreet1.value == "") { strErrorMessage += "Credit Card Billing Street Address is required.\n"; }
      if(objForm.ccCity.value == "") { strErrorMessage += "Credit Card Billing City is required.\n"; }
      if(objForm.ccStateID[objForm.ccStateID.selectedIndex].value == "") { strErrorMessage += "Credit Card Billing State is required.\n"; }
      if(objForm.ccZipCode.value == "") { strErrorMessage += "Credit Card Billing Zip/Postal Code is required.\n"; }
      if(objForm.ccCountryID[objForm.ccCountryID.selectedIndex].value == "") { strErrorMessage += "Credit Card Billing Country is required.\n"; }
    }
  }
  
  //Check to see if there were any errors then alert the submitter and return false
  if(strErrorMessage != "")
  { strErrorMessage = "The following must be corrected before your registration can be submitted on-line:\n\n" + strErrorMessage;
    alert(strErrorMessage);
    return false;
  }
  else
  { return true;
  }
}

var mblnRegistrationApiLoaded = true; //Flag variable to determine if this js file has been fully loaded
// -->
