

var postState = '';
var postCountry = '';

// State table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var state = '\
1Color:www.poppyprint.com: - - - - - - - - - - - |\
1Color:www.poppyprint.com/cards-raised-1color.html:1 Color Raised Print|\
FullColor:www.poppyprint.com: - - - - - - - - - - - |\
FullColor:www.poppyprint.com/_animals-pets-fullcolor.html:Animals & Pets|\
FullColor:www.poppyprint.com/_beauty-health-fullcolor.html:Beauty & Health|\
FullColor:www.poppyprint.com/_businesseconomy-fullcolor.html:Business & Economy|\
FullColor:www.poppyprint.com/_computersecommerce-fullcolor.html:Computers & Internet|\
FullColor:www.poppyprint.com/_entertainment-fullcolor.html:Entertainment & Culture|\
FullColor:www.poppyprint.com/_fashion-clothing-fullcolor.html:Fashion & Clothing|\
FullColor:www.poppyprint.com/_food-drink-fullcolor.html:Food & Drink|\
FullColor:www.poppyprint.com/_government-fullcolor.html:Government & Military|\
FullColor:www.poppyprint.com/_miscellaneous-fullcolor.html:Miscellaneous & New|\
FullColor:www.poppyprint.com/_nature-fullcolor.html:Nature & Outdoors|\
FullColor:www.poppyprint.com/_people-fullcolor.html:People & Models|\
FullColor:www.poppyprint.com/_places-fullcolor.html:Places & Travel|\
FullColor:www.poppyprint.com/_simple-backgrounds-fullcolor.html:Simple Backgrounds|\
FullColor:www.poppyprint.com/_sports-wellness-fullcolor.html:Sports & Wellness|\
FullColor:www.poppyprint.com/_transportation-fullcolor.html:Transportation & Vehicles|\
FullColor:www.poppyprint.com/_all-designs-fullcolor.html:All Available Designs|\
Fullexpress:www.poppyprint.com: - - - - - - - - - - - |\
Fullexpress:www.poppyprint.com/_animals-pets-express.html:Animals & Pets|\
Fullexpress:www.poppyprint.com/_beauty-health-express.html:Beauty & Health|\
Fullexpress:www.poppyprint.com/_businesseconomy-express.html:Business & Economy|\
Fullexpress:www.poppyprint.com/_computersecommerce-express.html:Computers & Internet|\
Fullexpress:www.poppyprint.com/_entertainment-express.html:Entertainment & Culture|\
Fullexpress:www.poppyprint.com/_fashion-clothing-express.html:Fashion & Clothing|\
Fullexpress:www.poppyprint.com/_food-drink-express.html:Food & Drink|\
Fullexpress:www.poppyprint.com/_government-express.html:Government & Military|\
Fullexpress:www.poppyprint.com/_miscellaneous-express.html:Miscellaneous & New|\
Fullexpress:www.poppyprint.com/_nature-express.html:Nature & Outdoors|\
Fullexpress:www.poppyprint.com/_people-express.html:People & Models|\
Fullexpress:www.poppyprint.com/_places-express.html:Places & Travel|\
Fullexpress:www.poppyprint.com/_simple-backgrounds-express.html:Simple Backgrounds|\
Fullexpress:www.poppyprint.com/_sports-wellness-express.html:Sports & Wellness|\
Fullexpress:www.poppyprint.com/_transportation-express.html:Transportation & Vehicles|\
Fullexpress:www.poppyprint.com/_all-designs-express.html:All Available Designs|\
Fullmagnetic:www.poppyprint.com: - - - - - - - - - - - |\
Fullmagnetic:www.poppyprint.com/_animals-pets-magnetic.html:Animals & Pets|\
Fullmagnetic:www.poppyprint.com/_beauty-health-magnetic.html:Beauty & Health|\
Fullmagnetic:www.poppyprint.com/_businesseconomy-magnetic.html:Business & Economy|\
Fullmagnetic:www.poppyprint.com/_computersecommerce-magnetic.html:Computers & Internet|\
Fullmagnetic:www.poppyprint.com/_entertainment-magnetic.html:Entertainment & Culture|\
Fullmagnetic:www.poppyprint.com/_fashion-clothing-magnetic.html:Fashion & Clothing|\
Fullmagnetic:www.poppyprint.com/_food-drink-magnetic.html:Food & Drink|\
Fullmagnetic:www.poppyprint.com/_government-magnetic.html:Government & Military|\
Fullmagnetic:www.poppyprint.com/_miscellaneous-magnetic.html:Miscellaneous & New|\
Fullmagnetic:www.poppyprint.com/_nature-magnetic.html:Nature & Outdoors|\
Fullmagnetic:www.poppyprint.com/_people-magnetic.html:People & Models|\
Fullmagnetic:www.poppyprint.com/_places-magnetic.html:Places & Travel|\
Fullmagnetic:www.poppyprint.com/_simple-backgrounds-magnetic.html:Simple Backgrounds|\
Fullmagnetic:www.poppyprint.com/_sports-wellness-magnetic.html:Sports & Wellness|\
Fullmagnetic:www.poppyprint.com/_transportation-magnetic.html:Transportation & Vehicles|\
Fullmagnetic:www.poppyprint.com/_all-designs-magnetic.html:All Available Designs|\
2Magnetic:www.poppyprint.com: - - - - - - - - - - - |\
2Magnetic:www.poppyprint.com/cards-magnetic-2color.html:2 Color Magnetic Cards|\
Metal:www.poppyprint.com: - - - - - - - - - - - |\
Metal:www.poppyprint.com/_metal-business-cards.html:Metal Cards (Gold/Silver)|\
';

// Country data table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var country = '\
blacnk:  |\
1Color:1 Color Raised Print|\
blacnk:-------------------|\
FullColor:Glossy Full Color|\
Fullexpress:Express Full Color|\
blacnk:-------------------|\
2Magnetic:Magnetic (2 Color)|\
Fullmagnetic:Magnetic (Full Color)|\
blacnk:-------------------|\
Metal:Metal (Gold/Silver)\
';

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

// Populates the country selected with the counties from the country list
function populateCountry(defaultCountry) {
  if ( postCountry != '' ) {
    defaultCountry = postCountry;
  }
  var countryLineArray = country.split('|');  // Split into lines
  var selObj = document.getElementById('countrySelect');
  selObj.options[0] = new Option('Select card type..','');
  selObj.selectedIndex = 0;
  for (var loop = 0; loop < countryLineArray.length; loop++) {
    lineArray = countryLineArray[loop].split(':');
    countryCode  = TrimString(lineArray[0]);
    countryName  = TrimString(lineArray[1]);
    if ( countryCode != '' ) {
      selObj.options[loop + 1] = new Option(countryName, countryCode);
    }
    if ( defaultCountry == countryCode ) {
      selObj.selectedIndex = loop + 1;
    }
  }
}

function populateState() {
  var selObj = document.getElementById('stateSelect');
  var foundState = false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.options[i] = null;
    }
    selObj.options.length=null;
    selObj.options[0] = new Option('Select card theme..','');
    selObj.selectedIndex = 0;
  }
  // Populate the drop down with states from the selected country
  var stateLineArray = state.split("|");  // Split into lines
  var optionCntr = 1;
  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 (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
    // If it's a input element, change it to a select
      if ( selObj.type == 'text' ) {
        parentObj = document.getElementById('stateSelect').parentNode;
        parentObj.removeChild(selObj);
        var inputSel = document.createElement("SELECT");
        inputSel.setAttribute("name","state");
        inputSel.setAttribute("id","stateSelect");
        parentObj.appendChild(inputSel) ;
        selObj = document.getElementById('stateSelect');
        selObj.options[0] = new Option('Select State','');
        selObj.selectedIndex = 0;
      }
      if ( stateCode != '' ) {
        selObj.options[optionCntr] = new Option(stateName, stateCode);
      }
      // See if it's selected from a previous post
      if ( stateCode == postState && countryCode == postCountry ) {
        selObj.selectedIndex = optionCntr;
      }
      foundState = true;
      optionCntr++
    }
  }
  // If the country has no states, change the select to a text box
  if ( ! foundState ) {
return;
    parentObj = document.getElementById('stateSelect').parentNode;
    parentObj.removeChild(selObj);
  // Create the Input Field
    var inputEl = document.createElement("INPUT");
    inputEl.setAttribute("id", "stateSelect");
    inputEl.setAttribute("type", "text");
    inputEl.setAttribute("name", "state");
    inputEl.setAttribute("size", 20);
    inputEl.setAttribute("value", postState);
    parentObj.appendChild(inputEl) ;
  }
}

function initCountry(country) {
  populateCountry(country);
  populateState();
}






