// JavaScript Dropdowns //


///////////////////////////////////////////////
// stateSelect											//
// Fills a select field with the US States 	//
///////////////////////////////////////////////

var stateArray = '\
US:AK:Alaska|\
US:AL:Alabama|\
US:AR:Arkansas|\
US:AS:American Samoa|\
US:AZ:Arizona|\
US:CA:California|\
US:CO:Colorado|\
US:CT:Connecticut|\
US:DC:D.C.|\
US:DE:Delaware|\
US:FL:Florida|\
US:FM:Micronesia|\
US:GA:Georgia|\
US:GU:Guam|\
US:HI:Hawaii|\
US:IA:Iowa|\
US:ID:Idaho|\
US:IL:Illinois|\
US:IN:Indiana|\
US:KS:Kansas|\
US:KY:Kentucky|\
US:LA:Louisiana|\
US:MA:Massachusetts|\
US:MD:Maryland|\
US:ME:Maine|\
US:MH:Marshall Islands|\
US:MI:Michigan|\
US:MN:Minnesota|\
US:MO:Missouri|\
US:MP:Marianas|\
US:MS:Mississippi|\
US:MT:Montana|\
US:NC:North Carolina|\
US:ND:North Dakota|\
US:NE:Nebraska|\
US:NH:New Hampshire|\
US:NJ:New Jersey|\
US:NM:New Mexico|\
US:NV:Nevada|\
US:NY:New York|\
US:OH:Ohio|\
US:OK:Oklahoma|\
US:OR:Oregon|\
US:PA:Pennsylvania|\
US:PR:Puerto Rico|\
US:PW:Palau|\
US:RI:Rhode Island|\
US:SC:South Carolina|\
US:SD:South Dakota|\
US:TN:Tennessee|\
US:TX:Texas|\
US:UT:Utah|\
US:VA:Virginia|\
US:VI:Virgin Islands|\
US:VT:Vermont|\
US:WA:Washington|\
US:WI:Wisconsin|\
US:WV:West Virginia|\
US:WY:Wyoming|\
US:AA:Military Americas|\
US:AE:Military Europe/ME/Canada|\
US:AP:Military Pacific|\
';

var stateUnused ='\
';

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

function populateState() {
  var stateSel = document.getElementById('stateSelect');
  stateSel.options[0] = new Option('Select State','');
  
  // Populate the drop down with states from the selected country
  var stateLineArray = stateArray.split("|");  // Split into lines
  var optionCounter = 1;
  var countryCode, stateCode, stateName;
  for (var loop = 0; loop < stateLineArray.length; loop++) {
		lineArray = stateLineArray[loop].split(":");
		countryCode  = TrimString(lineArray[0]);
		stateCode    = TrimString(lineArray[1]);
		stateName    = TrimString(lineArray[2]);
      if ( stateCode != '' ) {
        stateSel.options[optionCounter] = new Option(stateName, stateCode);
		}
		//Set the default selected state to Hawaii
		if (stateCode == 'HI') {
			stateSel.selectedIndex = optionCounter;
		}
      optionCounter++;
  }
}