<!--
// If you have PHP you can set the post values like this
//var postState = '<?= $_POST["state"] ?>';
//var postCountry = '<?= $_POST["country"] ?>';


// 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 = '\
US:Alaska:Alaska|\
US:Alabama:Alabama|\
US:Arkansas:Arkansas|\
US:Arizona:Arizona|\
US:California:California|\
US:Colorado:Colorado|\
US:Connecticut:Connecticut|\
US:Delaware:Delaware|\
US:District of Columbia:District of Columbia|\
US:Florida:Florida|\
US:Georgia:Georgia|\
US:Hawai:Hawai|\
US:Illinois:Illinois|\
US:Iowa:Iowa|\
US:Idaho:Idaho|\
US:Indiana:Indiana|\
US:Kentucky:Kentucky|\
US:Kansas:Kansas|\
US:Louisiana:Louisiana|\
US:Massachusetts:Massachusetts|\
US:Maryland:Maryland|\
US:Maine:Maine|\
US:Michigan:Michigan|\
US:Minnesota:Minnesota|\
US:Missouri:Missouri|\
US:Mississippi:Mississippi|\
US:Montana:Montana|\
US:North Carolina:North Carolina|\
US:North Dakota:North Dakota|\
US:Nebraska:Nebraska|\
US:New Hampshire:New Hampshire|\
US:New Jersey:New Jersey|\
US:New Mexico:New Mexico|\
US:Nevada:Nevada|\
US:New York:New York|\
US:Ohio:Ohio|\
US:Oklahoma:Oklahoma|\
US:Oregon:Oregon|\
US:Pennsylvania:Pennsylvania|\
US:Rhode Island:Rhode Island|\
US:South Carolina:South Carolina|\
US:South Dakota:South Dakota|\
US:Tennessee:Tennessee|\
US:Texas:Texas|\
US:Utah:Utah|\
US:Virginia:Virginia|\
US:Vermont:Vermont|\
US:Washington:Washington|\
US:Wisconsin:Wisconsin|\
US:West Virginia:West Virginia|\
US:Wyoming:Wyoming|\
AU:Australian Antarctic Territory:Australian Antarctic Territory|\
AU:Australian Capital Territory:Australian Capital Territory|\
AU:Northern Territory:Northern Territory|\
AU:New South Wales:New South Wales|\
AU:Queensland:Queensland|\
AU:South Australia:South Australia|\
AU:Tasmania:Tasmania|\
AU:Victoria:Victoria|\
AU:Western Australia:Western Australia|\
UK:Avon:Avon|\
UK:Bedfordshire:Bedfordshire|\
UK:Berkshire:Berkshire|\
UK:Buckinghamshire:Buckinghamshire|\
UK:Cambridgeshire:Cambridgeshire|\
UK:Cheshire:Cheshire|\
UK:Cleveland:Cleveland|\
UK:Cornwall:Cornwall|\
UK:Cumbria:Cumbria|\
UK:Derbyshire:Derbyshire|\
UK:Devon:Devon|\
UK:Dorset:Dorset|\
UK:Durham:Durham|\
UK:Essex:Essex|\
UK:Gloucestershire:Gloucestershire|\
UK:Greater London:Greater London|\
UK:Greater Manchester:Greater Manchester|\
UK:Hampshire:Hampshire|\
UK:Hereford & Worcestershire:Hereford & Worcestershire|\
UK:Hertfordshire:Hertfordshire|\
UK:Humberside:Humberside|\
UK:Isle of Man:Isle of Man|\
UK:Isle of Wight:Isle of Wight|\
UK:Kent:Kent|\
UK:Lancashire:Lancashire|\
UK:Leicestershire:Leicestershire|\
UK:Lincolnshire:Lincolnshire|\
UK:Merseyside:Merseyside|\
UK:Norfolk:Norfolk|\
UK:Northamptonshire:Northamptonshire|\
UK:Northumberland:Northumberland|\
UK:Nottinghamshire:Nottinghamshire|\
UK:Oxfordshire:Oxfordshire|\
UK:Shropshire:Shropshire|\
UK:Somerset:Somerset|\
UK:Staffordshire:Staffordshire|\
UK:Suffolk:Suffolk|\
UK:Surrey:Surrey|\
UK:Sussex:Sussex|\
UK:Warwickshire:Warwickshire|\
UK:West Midlands:West Midlands|\
UK:Wiltshire:Wiltshire|\
UK:Yorkshire:Yorkshire|\
';

// 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.
//AU:Australia|\
var country = '\
UK:United Kingdom|\
US:United States\
';

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 Country','');

  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 State','');
    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 ) {
    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) ;
  }*/
     var coun = document.getElementById('countrySelect').value;

      if(coun=='AU'){
	   document.getElementById('ccode').value=61
   }
    else if(coun=='UK'){
	   document.getElementById('ccode').value=44
   }
    else if(coun=='US'){
	   document.getElementById('ccode').value=1
   }
   else{document.getElementById('ccode').value=''}
}

function initCountry(country) {
 populateCountry(country);
  populateState();
}
//-->

