var arrStates = new Array()
var locationString = new String(self.location)

function objState(name, code, country ) 
{
  this.name    = name.toUpperCase()
  this.code    = code
  this.country = country
}

function compareStates(a, b) 
{
  if (a.country < b.country) 
  { return -1 }
  if (a.country > b.country) 
  { return 1 }

  if (a.country == b.country) 
  {
    if (a.code < b.code) { return -1 }
    if (a.code > b.code) { return 1 }
  }
  return 0
}


function initStList() 
{
  arrStates[0]   = new objState('Alabama','AL','US')
  arrStates[1]   = new objState('Alaska','AK','US')
  arrStates[2]   = new objState('Arizona','AZ','US')
  arrStates[3]   = new objState('Arkansas','AR','US')
  arrStates[4]   = new objState('California','CA','US')
  arrStates[5]   = new objState('Colorado','CO','US')
  arrStates[6]   = new objState('Connecticut','CT','US')
  arrStates[7]   = new objState('Delaware','DE','US')
  arrStates[8]   = new objState('District of Columbia','DC','US')
  arrStates[9]   = new objState('Florida','FL','US')
  arrStates[10]  = new objState('Georgia','GA','US')
  arrStates[11]  = new objState('Guam','GU','US')
  arrStates[12]  = new objState('Hawaii','HI','US')
  arrStates[13]  = new objState('Idaho','ID','US')
  arrStates[14]  = new objState('Illinois','IL','US')
  arrStates[15]  = new objState('Indiana','IN','US')
  arrStates[16]  = new objState('Iowa','IA','US')
  arrStates[17]  = new objState('Kansas','KS','US')
  arrStates[18]  = new objState('Kentucky','KY','US')
  arrStates[19]  = new objState('Louisiana','LA','US')
  arrStates[20]  = new objState('Maine','ME','US')
  arrStates[21]  = new objState('Maryland','MD','US')
  arrStates[22]  = new objState('Massachusetts','MA','US')
  arrStates[23]  = new objState('Michigan','MI','US')
  arrStates[24]  = new objState('Minnesota','MN','US')
  arrStates[25]  = new objState('Mississippi','MS','US')
  arrStates[26]  = new objState('Missouri','MO','US')
  arrStates[27]  = new objState('Montana','MT','US')
  arrStates[28]  = new objState('Nebraska','NE','US')
  arrStates[29]  = new objState('Nevada','NV','US')
  arrStates[30]  = new objState('New Hampshire','NH','US')
  arrStates[31]  = new objState('New Jersey','NJ','US')
  arrStates[32]  = new objState('New Mexico','NM','US')
  arrStates[33]  = new objState('New York','NY','US')
  arrStates[34]  = new objState('North Carolina','NC','US')
  arrStates[35]  = new objState('North Dakota','ND','US')
  arrStates[36]  = new objState('N.Mariana Islands','MP','US')
  arrStates[37]  = new objState('Ohio','OH','US')
  arrStates[38]  = new objState('Oklahoma','OK','US')
  arrStates[39]  = new objState('Oregon','OR','US')
  arrStates[40]  = new objState('Pennsylvania','PA','US')
  arrStates[41]  = new objState('Puerto Rico','PR','US')
  arrStates[42]  = new objState('Rhode Island','RI','US')
  arrStates[43]  = new objState('South Carolina','SC','US')
  arrStates[44]  = new objState('South Dakota','SD','US')
  arrStates[45]  = new objState('Tennessee','TN','US')
  arrStates[46]  = new objState('Texas','TX','US')
  arrStates[47]  = new objState('Utah','UT','US')
  arrStates[48]  = new objState('Vermont','VT','US')
  arrStates[49]  = new objState('Virgin Islands','VI','US')
  arrStates[50]  = new objState('Virginia','VA','US')
  arrStates[51]  = new objState('Washington','WA','US')
  arrStates[52]  = new objState('West Virginia ','WV','US')
  arrStates[53]  = new objState('Wisconsin','WI','US')
  arrStates[54]  = new objState('Wyoming','WY','US')
  arrStates[55]  = new objState('Alberta','AB','CA')
  arrStates[56]  = new objState('British Columbia','BC','CA')
  arrStates[57]  = new objState('Manitoba','MB','CA')
  arrStates[58]  = new objState('New Brunswick','NB','CA')
  arrStates[59]  = new objState('Newfoundland','NF','CA')
  arrStates[60]  = new objState('Nova Scotia','NS','CA')
  arrStates[61]  = new objState('Northwest Territories','NT','CA')
  arrStates[62]  = new objState('Ontario','ON','CA')
  arrStates[63]  = new objState('Prince Edward Island','PE','CA')
  arrStates[64]  = new objState('Quebec','QC','CA')
  arrStates[65]  = new objState('Saskatchewan','SK','CA')
  arrStates[66]  = new objState('Yukon','YT','CA')
  arrStates[67]  = new objState('Nunavut','NU','CA')  
  arrStates[68]  = new objState('Labrador','LB','CA')  
  /*
  arrStates[67]  = new objState('Aguascalientes','AG','MX')
  arrStates[68]  = new objState('Baja California','BN','MX')
  arrStates[69]  = new objState('Baja California Sur','BS','MX')
  arrStates[70]  = new objState('Campeche','CA','MX')
  arrStates[71]  = new objState('Chihuahua','CH','MX')
  arrStates[72]  = new objState('Chiapas','CI','MX')
  arrStates[73]  = new objState('Colima','CL','MX')
  arrStates[74]  = new objState('Coahuila de Zaragoza','CO','MX')
  arrStates[75]  = new objState('Distrito Federal','DF','MX')
  arrStates[76]  = new objState('Durango','DU','MX')
  arrStates[77]  = new objState('Guanajuato','GA','MX')
  arrStates[78]  = new objState('Guerrero','GE','MX')
  arrStates[79]  = new objState('Hidalgo','HI','MX')
  arrStates[80]  = new objState('Jalisco','JA','MX')
  arrStates[81]  = new objState('Mexico','ME','MX')
  arrStates[82]  = new objState('Michoacan de Ocampo','MI','MX')
  arrStates[83]  = new objState('Morelos','MO','MX')
  arrStates[84]  = new objState('Nayarit','NA','MX')
  arrStates[85]  = new objState('Nuevo Leon','NL','MX')
  arrStates[86]  = new objState('Oaxaca','OA','MX')
  arrStates[87]  = new objState('Puebla','PE','MX')
  arrStates[88]  = new objState('Queretaro de Arteaga','QE','MX')
  arrStates[89]  = new objState('Quintana Roo','QI','MX')
  arrStates[90]  = new objState('Sinaloa','SI','MX')
  arrStates[91]  = new objState('San Luis Potosi','SL','MX')
  arrStates[92]  = new objState('Sonora','SO','MX')
  arrStates[93]  = new objState('Tabasco','TB','MX')
  arrStates[94]  = new objState('Tlaxcala','TL','MX')
  arrStates[95]  = new objState('Tamaulipas','TM','MX')
  arrStates[96]  = new objState('Veracruz-Llave','VE','MX')
  arrStates[97]  = new objState('Yucatan','YU','MX')
  arrStates[98]  = new objState('Zacatecas','ZA','MX')
  */

//  arrStates.sort(compareStates)
}

initStList()

function updateStateList(country,stSelect,item) 
{ 
  if (typeof(strFormDisplayed) != "undefined") 
  { 
    ShowHideStateList(country)
    if(strFormDisplayed == "AltDisplay")
    {  return;  } 
  }
  item = document.getElementById(item);
  if (country != "OT") 
  {
    var idx    = 1
    var idxSet = 0
    item.options.length = 0
    if (country == 'CA') 
      {  item.options[0] = new Option("(Select Province)","");  }
    else 
      {  item.options[0] = new Option("(Select State)","") }
  
    for (var x = 0; x < arrStates.length; x++) 
    {
      if (arrStates[x].country == country) 
      {
        item.options[idx] = new Option(arrStates[x].name,arrStates[x].code)  
        if (stSelect == arrStates[x].code) { idxSet = idx }
        idx++
      }
    }
    item.options[idxSet].selected = true
  }
}

function buildStateList(seq, formName, lstStName, CountrySelect, stSelect) 
{
  if (CountrySelect == '') 
     { CountrySelect = 'US' }
     
  if (seq == null) 
     { seq = '' }

  document.write("<SELECT NAME=\"" + lstStName + "\" SIZE=\"1\" CLASS=\"frm\" ID=\"" + lstStName + seq + "\">")

  if (CountrySelect == 'CA')
       {  document.write("<OPTION VALUE=''>(Select Province)</OPTION>")  }     
  else
       {  document.write("<OPTION VALUE=''>(Select State)</OPTION>")  }

  for (var z = 0; z < arrStates.length; z++) 
  {
     if (arrStates[z].country == CountrySelect) 
        {
           if((locationString.indexOf('truckpack') > 0) && (seq == 0))
           {
              if (arrStates[z].code == stSelect) 
              { document.write("<OPTION SELECTED VALUE='"+arrStates[z].code+"'>"+arrStates[z].name+"</OPTION>")  }
           } 
           else
           { 
              if (arrStates[z].code == stSelect) 
                 { document.write("<OPTION SELECTED VALUE='"+arrStates[z].code+"'>"+arrStates[z].name+"</OPTION>")  }
              else 
                 { document.write("<OPTION VALUE='"+arrStates[z].code+"'>"+arrStates[z].name+"</OPTION>")  }
           }    
        }
   }
  document.write("</SELECT>")
}

function buildRadioCountryList(seq,formName,lstCtyName,lstStName,CountrySelect,blnReqZip,blnShortForm,txtCustName,blnShowMexico)
{
  var lastCty = ''
  var strSub  = ''

  if (seq == null) 
     { seq = ''  }
  else
     { strSub = '['+seq+']' }
       
  if (CountrySelect == "US")
     {  var checkUS = "CHECKED"  }
  else if (CountrySelect == "CA")
     {  var checkCA = "CHECKED"  }
  else if (CountrySelect == "MX")
     {  var checkMX = "CHECKED"  }
  else if (CountrySelect == "OT")
     {  var checkOT = "CHECKED"  }
  else
     {  var checkUS = "CHECKED"  }
 
  document.write("<table ALIGN='LEFT' BORDER='0' CELLPADDING='0' CELLSPACING='0' ><tr>")

  document.write("<td ALIGN='LEFT' VALIGN='MIDDLE' NOWRAP><input type='radio' value='US' ONCLICK=\"updateStateList('US',null,document." + formName + "." + lstStName + strSub + ");updateCheckBox('US','"+formName+"','"+seq+"');ZipPostalText('US','"+formName+"','"+seq+"','"+blnReqZip+"','"+blnShortForm+"','"+txtCustName+"');\" NAME=\"" + lstCtyName + seq + "\" CLASS=\"frm\" "+checkUS+"></td>")
  document.write("<td ALIGN='LEFT' VALIGN='MIDDLE' NOWRAP><font CLASS='formTxt'>United States&nbsp;&nbsp;</font></td>")

  document.write("<td ALIGN='LEFT' VALIGN='MIDDLE'><input type='radio' value='CA' ONCLICK=\"updateStateList('CA',null,document." + formName + "." + lstStName + strSub + ");updateCheckBox('CA','"+formName+"','"+seq+"');ZipPostalText('CA','"+formName+"','"+seq+"','"+blnReqZip+"','"+blnShortForm+"','"+txtCustName+"');\" NAME=\"" + lstCtyName + seq + "\" CLASS=\"frm\" "+checkCA+"></td>")
  document.write("<td ALIGN='LEFT' VALIGN='MIDDLE' NOWRAP><font CLASS='formTxt'>Canada&nbsp;&nbsp;</font></td>")

  if (blnShowMexico != "False")
  {
    document.write("<td ALIGN='LEFT' VALIGN='MIDDLE'><input type='radio' value='MX' ONCLICK=\"updateStateList('MX',null,document." + formName + "." + lstStName + strSub + ");updateCheckBox('MX','"+formName+"','"+seq+"');ZipPostalText('MX','"+formName+"','"+seq+"','"+blnReqZip+"','"+blnShortForm+"','"+txtCustName+"');\" NAME=\"" + lstCtyName + seq + "\" CLASS=\"frm\" "+checkMX+"></td>")
    document.write("<td ALIGN='LEFT' VALIGN='MIDDLE' NOWRAP><font CLASS='formTxt'>Mexico&nbsp;&nbsp;</font></td>")
  }

  if (typeof blnShowRadCountryOT != "undefined")
  {
    document.write("<td ALIGN='LEFT' VALIGN='MIDDLE'><input type='radio' value='OT' ONCLICK=\"updateStateList('OT',null,document." + formName + "." + lstStName + strSub + ");updateCheckBox('OT','"+formName+"','"+seq+"');ZipPostalText('OT','"+formName+"','"+seq+"','"+blnReqZip+"','"+blnShortForm+"','"+txtCustName+"');\" NAME=\"" + lstCtyName + seq + "\" CLASS=\"frm\" "+checkOT+"></td>")
    document.write("<td ALIGN='LEFT' VALIGN='MIDDLE' NOWRAP><font CLASS='formTxt'>Other</font></td>")
  }
  document.write("</tr></table>")
}

function ShowHideStateList(country)
{
  if (ie5 || ns6)
  {
    if (country == "OT")
    { 
      document.getElementById("OrigDisplay").className = "hidden"
      document.getElementById("AltDisplay").className = "visible"
    }
    else
    {
     document.getElementById("AltDisplay").className = "hidden"
     document.getElementById("OrigDisplay").className = "visible"
    }
  }
  else if (ie4)
  {
    if (country == "OT")
    { 
      document.all.OrigDisplay.className = "hidden"
      document.all.AltDisplay.className = "visible"
    }
    else
    {
     document.all.AltDisplay.className = "hidden"
     document.all.OrigDisplay.className = "visible"
    }
  }
  else if (ns4)
  {
    if (country == "OT")
    {  
      document.passForm.blnShowAltDisplay.value = "True" 
      document.passForm.submit()
    }
    else
    {
      if(strFormDisplayed == "AltDisplay")
      { 
        document.passForm.blnShowAltDisplay.value = "False" 
        document.passForm.submit() 
      }
    }
  }
}  