stateArray = new Array();
stateArray['AK'] = 'Alaska';
stateArray['AL'] = 'Alabama';
stateArray['AR'] = 'Arkansas';
stateArray['AZ'] = 'Arizona';
stateArray['CA'] = 'California';
stateArray['CO'] = 'Colorado';
stateArray['CT'] = 'Connecticut';
stateArray['DC'] = 'District of Columbia';
stateArray['DE'] = 'Delaware';
stateArray['FL'] = 'Florida';
stateArray['GA'] = 'Georgia';
stateArray['HI'] = 'Hawaii';
stateArray['ID'] = 'Idaho';
stateArray['IL'] = 'Illinois';
stateArray['IN'] = 'Indiana';
stateArray['IA'] = 'Iowa';
stateArray['KS'] = 'Kansas';
stateArray['KY'] = 'Kentucky';
stateArray['LA'] = 'Louisiana';
stateArray['ME'] = 'Maine';
stateArray['MD'] = 'Maryland';
stateArray['MA'] = 'Massachusetts';
stateArray['MI'] = 'Michigan';
stateArray['MN'] = 'Minnesota';
stateArray['MS'] = 'Mississippi';
stateArray['MO'] = 'Missouri';
stateArray['MT'] = 'Montana';
stateArray['NE'] = 'Nebraska';
stateArray['NV'] = 'Nevada';
stateArray['NH'] = 'New Hampshire';
stateArray['NJ'] = 'New Jersey';
stateArray['NM'] = 'New Mexico';
stateArray['NY'] = 'New York';
stateArray['NC'] = 'North Carolina';
stateArray['ND'] = 'North Dakota';
stateArray['OH'] = 'Ohio';
stateArray['OK'] = 'Oklahoma';
stateArray['OR'] = 'Oregon';
stateArray['PA'] = 'Pennsylvania';
stateArray['RI'] = 'Rhode Island';
stateArray['SC'] = 'South Carolina';
stateArray['SD'] = 'South Dakota';
stateArray['TN'] = 'Tennessee';
stateArray['TX'] = 'Texas';
stateArray['UT'] = 'Utah';
stateArray['VT'] = 'Vermont';
stateArray['VA'] = 'Virginia';
stateArray['WA'] = 'Washington';
stateArray['WV'] = 'West Virginia';
stateArray['WI'] = 'Wisconsin';
stateArray['WY'] = 'Wyoming';

intlShipOpts = new Array();
intlShipOpts['PI'] = "Priority International - $20";
intlShipOpts['EMS'] = "EMS (Express Postal) - $30";
intlShipOpts['FE'] = "FedEx International - $30";

//Clear page if no payment is needed
function nopayment (){
  document.getElementById("payment").innerHTML = " There is currently no outstanding balance on your account.";
}

function countryChange (countryfldid,curStateAbbr) {
  sttype = countryfldid.replace(/country$/,"");
stillbidding = document.getElementById("stillbid").value;
if (sttype == "shipping" && stillbidding == '1') { return; }
  statetd = document.getElementById(sttype+"state").parentNode;
  shippingsel = document.getElementById("shippingselect");
  switch (document.getElementById(sttype+"country").value) {
    case "US":
      if (document.getElementById(sttype+"state").className != "statesel") {
        statetd.removeChild(document.getElementById(sttype+"state")); 
        statesel = document.createElement("select"); statesel.name = sttype + "state"; statesel.id = statesel.name; statesel.className = "statesel";
        statesel.style.width="225px";
        opt = document.createElement("option"); opt.value = ''; opt.innerHTML = "";
        statesel.appendChild(opt);
        
        for (abbr in stateArray) {
          if ( abbr.length > 2 ) { continue; }
          opt = document.createElement("option"); opt.value = abbr; opt.innerHTML = stateArray[abbr];
          if (curStateAbbr && abbr == curStateAbbr) { opt.selected = "selected"; statesel.value=opt.value; }
//          opt.setAttribute("onchange","changeShipping();");
          statesel.appendChild(opt);
        }
        statesel.setAttribute("onChange","changeShipping();"); 
	statetd.appendChild(statesel);
        if (!statesel.value) { document.getElementById(sttype+"state").getElementsByTagName("option")[0].selected="selected"; }
      }
      if (sttype == "shipping") {
        while (shippingsel.hasChildNodes()) { shippingsel.removeChild(shippingsel.childNodes[0]); }
        shipopt = document.createElement("option"); shipopt.value = "DO"; shipopt.innerHTML = "Domestic Shipping - $5";
        shippingsel.appendChild(shipopt);
      }
      break;
      

    default:
      if (document.getElementById(sttype+"state").className != "stateinp") {
        statetd.removeChild(document.getElementById(sttype+"state")); 
        stateinp = document.createElement("input"); stateinp.name = sttype + "state"; stateinp.id = stateinp.name; stateinp.className = "stateinp";
        stateinp.style.width="225px"; statetd.appendChild(stateinp);
      }
      if (sttype == "shipping") {
        while (shippingsel.hasChildNodes()) { shippingsel.removeChild(shippingsel.childNodes[0]); }
        for (thisopt in intlShipOpts) {
          if ( thisopt.length > 2 && thisopt != "EMS") { continue; }
          shipopt = document.createElement("option"); shipopt.value = thisopt; shipopt.innerHTML = intlShipOpts[thisopt];
          shippingsel.appendChild(shipopt);
        }
      }
      break;
  }

}


 
function changeShipping(){
stillbidding = document.getElementById("stillbid").value;
  var selectBox = document.getElementById("shippingstate");

  var shippingType = document.getElementById("shippingselect").value;
	if (shippingType == "DO") {
         shippingCost = parseFloat(5).toFixed(2);
	} else if (shippingType == "PI") {
         shippingCost = parseFloat(20).toFixed(2);
	} else if (shippingType == "EMS"){
         shippingCost = parseFloat(30).toFixed(2);
	} else if (shippingType == "FE"){
	 shippingCost = parseFloat(30).toFixed(2);
        }

  amtid = (document.getElementById("amount")) ? "amount" : "amt";
  commaitemCost = document.getElementById(amtid).innerHTML;
  if (!commaitemCost) {   commaitemCost = document.getElementById("amt").innerHTML;}
  //Environmental fixes
  //Removes commas from Cost so it can be displayed
  itemCost = commaitemCost.replace(/,/gi, '');
  //end fixes

if (stillbidding == '1') { shippingCost = 0.00 ; }
else { document.getElementById("shippingcost").innerHTML = shippingCost;}
  tax = parseFloat(itemCost) * 0.06;
  totalCost = (parseFloat(shippingCost) + parseFloat(itemCost) + (parseFloat(itemCost) * 0.06)); //MI Sales tax included
  if (totalCost <0 ) { totalCost = 0; } 
  totalCost = totalCost.toFixed(2);
   
  if (selectBox.value && selectBox.value == "MI") { //MI Sales tax include
    document.getElementById("total").innerHTML = totalCost + " (MI tax included)";
  } else { //If MI is not selected then normal charge aka no sales tax
    totalCost = (parseFloat(shippingCost) + parseFloat(itemCost));
    if (totalCost <0 ) { totalCost = 0; } 
    totalCost = totalCost.toFixed(2);
    document.getElementById("total").innerHTML = totalCost;
  }

}

function countryChange2 (countryfldid,curStateAbbr) {
  sttype = countryfldid.replace(/country$/,"");
  statetd = document.getElementById(sttype+"state").parentNode;
  switch (document.getElementById(sttype+"country").value) {
    case "US":
      if (document.getElementById(sttype+"state").className != "statesel") {
        statetd.removeChild(document.getElementById(sttype+"state")); 
        statesel = document.createElement("select"); statesel.name = "state"; statesel.id = sttype + "state"; statesel.className = "statesel forms";
        statesel.style.width="225px";
        opt = document.createElement("option"); opt.value = ''; opt.innerHTML = "";
        statesel.appendChild(opt);
        
        for (abbr in stateArray) {
          if ( abbr.length > 2 ) { continue; }
          opt = document.createElement("option"); opt.value = abbr; opt.innerHTML = stateArray[abbr];
          if (curStateAbbr && abbr == curStateAbbr) { opt.selected = "selected"; statesel.value=opt.value; }
          statesel.appendChild(opt);
          if (abbr == 'WY') { break; }
        }
	statetd.appendChild(statesel);
        if (!statesel.value) { document.getElementById(sttype+"state").getElementsByTagName("option")[0].selected="selected"; }
      }

      break;
      

    default:
      if (document.getElementById(sttype+"state").className != "stateinp") {
        statetd.removeChild(document.getElementById(sttype+"state")); 
        stateinp = document.createElement("input"); stateinp.name = "state"; stateinp.id = sttype + "state"; stateinp.className = "stateinp forms";
        stateinp.size='40'; stateinp.maxlength='255'; statetd.appendChild(stateinp);
      }
      break;
  }

}