// Concatenate a phone number from its Area Code-Prefix-Number fields
//   frm - the form
//   phonetype - valid values are 'home', 'work', and 'fax'
function ConcatenatePhoneNumber(frm, phonetype) {
  // alert ("In ConcatenatePhoneNumber()");
  if (phonetype == 'home') {
    // Concatenate the home phone - address.phone1 column in WC
    frm.phone1.value = frm.homeAreaCode.value + frm.homePhonePrefix.value + frm.homePhone.value;
    // alert ("home phone = " + frm.phone1.value);
  } else if (phonetype == 'work') {
    // Concatenate the work phone - address.phone2 column in WC
    frm.phone2.value = frm.workAreaCode.value + frm.workPhonePrefix.value + frm.workPhone.value;
    // alert ("work phone = " + frm.phone2.value);
  } else if (phonetype == 'fax') {
    // Concatenate the fax phone - address.fax column in WC
    frm.fax.value = frm.faxAreaCode.value + frm.faxPhonePrefix.value + frm.faxPhone.value;
    // alert ("fax phone = " + frm.fax.value);
  }
}

// Split a phone number into its Area Code-Prefix-Number fields
//   frm - the form
//   phonetype - valid values are 'home', 'work', and 'fax'
function SplitPhoneNumber(frm, phonetype, phonevalue) {
   //alert ("In SplitPhoneNumber()"+phonevalue);
  if (phonevalue.length == 10) {
   
    var PhoneAreaCode = phonevalue.substring(0, 3);
    var PhonePrefix   = phonevalue.substring(3, 6);
    var PhoneNumber   = phonevalue.substring(6, 10);
    
    if (phonetype == 'home') {
    
      // Split the home phone - address.phone1 column in WC
      //alert ("home area code = " + frm.homeAreaCode.value);
      frm.homeAreaCode.value = PhoneAreaCode;
       
      frm.homePhonePrefix.value = PhonePrefix;
      // alert ("home prefix = " + frm.homePhonePrefix.value);
      frm.homePhone.value = PhoneNumber;
      // alert ("home number = " + frm.homePhone.value);
    } else if (phonetype == 'work') {
      // Split the work phone - address.phone2 column in WC
      frm.workAreaCode.value = PhoneAreaCode;
      // alert ("work area code = " + frm.workAreaCode.value);
      frm.workPhonePrefix.value = PhonePrefix;
      // alert ("work prefix = " + frm.workPhonePrefix.value);
      frm.workPhone.value = PhoneNumber;
      // alert ("work number = " + frm.workPhone.value);
    } else if (phonetype == 'fax') {
      // Split the fax phone - address.fax1 column in WC
      frm.faxAreaCode.value = PhoneAreaCode;
      // alert ("fax area code = " + frm.faxAreaCode.value);
      frm.faxPhonePrefix.value = PhonePrefix;
      // alert ("fax prefix = " + frm.faxPhonePrefix.value);
      frm.faxPhone.value = PhoneNumber;
      // alert ("fax number = " + frm.faxPhone.value);
    } else if (phonetype == 'mobile') {
      // Split the fax phone - address.fax1 column in WC
      frm.mobileAreaCode.value = PhoneAreaCode;
      // alert ("fax area code = " + frm.faxAreaCode.value);
      frm.mobilePhonePrefix.value = PhonePrefix;
      // alert ("fax prefix = " + frm.faxPhonePrefix.value);
      frm.mobilePhone.value = PhoneNumber;
      // alert ("fax number = " + frm.faxPhone.value);
    }
  } // else undefined rules for parsing phone number
}

// Set the value of the state dropdown with the value - initialize to the first option if not found
function setStateOption(frm, statevalue) {
  // alert ("Checking state");
  if (statevalue) {
    // alert ("state set = " + frm.state.value);
    if (!setFormIndexbyValue(frm.state, statevalue)) {
      // alert ("setting the state to the first in the list");
      frm.state.selectedIndex = 0;
      frm.state.options[0].selected = true;
    }
  }
}

// Set the value of the country dropdown with the value - initialize to the first option if not found
function setCountryOption(frm, countryvalue) {
  // alert ("Checking country");
  if (countryvalue) {
    // Use the value for country passed to the page, if invalid, reset
    // alert ("country set = " + frm.country.value);
    if (!setFormIndexbyValue(frm.country, countryvalue)) {
      // We could not verify the country value...ignore the state and reset
      // alert ("setting the country to the first in the list");
      frm.country.selectedIndex = 0;
      frm.country.options[0].selected = true;
    }
  }
}

// Set the value of the store dropdown with the value - initialize to the first option if not found
function setStoreOption(frm, storevalue) {
  // alert ("Checking store");
  if (storevalue) {
    // Use the value for store passed to the page, if invalid, reset
    // alert ("store set = " + frm.demographicField6.value);
    if (!setFormIndexbyValue(frm.demographicField6, storevalue)) {
      // We could not verify the store value
      // alert ("setting the store to the first in the list");
      frm.demographicField6.selectedIndex = 0;
      frm.demographicField6.options[0].selected = true;
    }
  }
}

// Set the value of the challenge question dropdown with the value - initialize to the first option if not found
function setChallengeQuestionOption(frm, questionvalue) {
  // alert ("Checking question");
  if (questionvalue) {
    // Use the value for question passed to the page, if invalid, reset
    // alert ("question set = " + frm.challengeQuestion.value);
    if (!setFormIndexbyValue(frm.challengeQuestion, questionvalue)) {
      // We could not verify the question value
      // alert ("setting the question to the first in the list");
      frm.challengeQuestion.selectedIndex = 0;
      frm.challengeQuestion.options[0].selected = true;
    }
  }
}

// Set the value of the eemail format dropdown with the value - initialize to the first option if not found
function setEmailFormatOption(frm, emailformatvalue) {
  // alert ("Checking email format");
  if (emailformatvalue) {
    // Use the value for email format passed to the page, if invalid, reset
    // alert ("email format set = " + frm.emailFormat.value);
    if (!setFormIndexbyValue(frm.emailFormat, emailformatvalue)) {
      // We could not verify the email format value
      // alert ("setting the email format to the first in the list");
      frm.emailFormat.selectedIndex = 0;
      frm.emailFormat.options[0].selected = true;
    }
  }
}


