// 50 States Sort Table - 8/8/2001 By Jim Shook

<!-- <hide>

var cc = 0; // column # to be sorted
var nc = 9; // last (max) column number
var  t = new Array(5);  // 2 dimensional array
  t[0] = new Array(50); // State Name
  t[1] = new Array(50); // Postal Abbriveation
  t[2] = new Array(50); // Capital City
  t[3] = new Array(50); // Largest City
  t[4] = new Array(50); // Date joined Union  
  t[5] = new Array(50); // Land area, sq mi   
  t[6] = new Array(50); // # of counties    
  t[7] = new Array(50); // Population  (Census Bureau Estimation 4/1/2000)
  t[8] = new Array(50); // Population  (Census Bureau Revised 4/1/1990)   
  t[9] = new Array(50); // Population  (Percent Increase or Decrease from 1990 to 2000)   
var kr = new Array(9);  // Color

t[0][01]="Alabama       "; t[1][01]="AL"; t[2][01]="Montgomery    "; t[3][01]="Birmingham    ";t[4][01]="1819 12/14"; t[5][01]=" 50,750"; t[6][01]=" 67"; t[7][01]=" 4,447,100"; t[8][01]=" 4,040,389"; t[9][01]=" 10.1";
t[0][02]="Alaska        "; t[1][02]="AK"; t[2][02]="Juneau        "; t[3][02]="Anchorage     ";t[4][02]="1959 01/03"; t[5][02]="570,374"; t[6][02]=" 16"; t[7][02]="   626,932"; t[8][02]="   550,043"; t[9][02]=" 14.0";
t[0][03]="Arizona       "; t[1][03]="AZ"; t[2][03]="Phoenix       "; t[3][03]="Phoenix       ";t[4][03]="1912 02/13"; t[5][03]="114,000"; t[6][03]=" 15"; t[7][03]=" 5,130,632"; t[8][03]=" 3,665,339"; t[9][03]=" 40.0";
t[0][04]="Arkansas      "; t[1][04]="AR"; t[2][04]="Little Rock   "; t[3][04]="Little Rock   ";t[4][04]="1836 06/15"; t[5][04]=" 52,075"; t[6][04]=" 75"; t[7][04]=" 2,673,400"; t[8][04]=" 2,350,624"; t[9][04]=" 13.7";
t[0][05]="California    "; t[1][05]="CA"; t[2][05]="Sacramento    "; t[3][05]="Los Angeles   ";t[4][05]="1850 09/09"; t[5][05]="155,973"; t[6][05]=" 58"; t[7][05]="33,871,648"; t[8][05]="29,811,427"; t[9][05]=" 13.6";
t[0][06]="Colorado      "; t[1][06]="CO"; t[2][06]="Denver        "; t[3][06]="Denver        ";t[4][06]="1876 08/01"; t[5][06]="103,730"; t[6][06]=" 63"; t[7][06]=" 4,301,261"; t[8][06]=" 3,294,473"; t[9][06]=" 30.6";
t[0][07]="Connecticut   "; t[1][07]="CT"; t[2][07]="Hartford      "; t[3][07]="Bridgeport    ";t[4][07]="1788 01/09"; t[5][07]="  4,845"; t[6][07]="  8"; t[7][07]=" 3,405,565"; t[8][07]=" 3,287,116"; t[9][07]="  3.6";
t[0][08]="Delaware      "; t[1][08]="DE"; t[2][08]="Dover         "; t[3][08]="Wilmington    ";t[4][08]="1787 12/07"; t[5][08]="  1,982"; t[6][08]="  3"; t[7][08]="   783,600"; t[8][08]="   666,168"; t[9][08]=" 17.6";
t[0][09]="Florida       "; t[1][09]="FL"; t[2][09]="Tallahassee   "; t[3][09]="Jacksonville  ";t[4][09]="1845 03/03"; t[5][09]=" 53,997"; t[6][09]=" 67"; t[7][09]="15,982,378"; t[8][09]="12,938,071"; t[9][09]=" 23.5";
t[0][10]="Georgia       "; t[1][10]="GA"; t[2][10]="Atlanta       "; t[3][10]="Atlanta       ";t[4][10]="1788 01/02"; t[5][10]=" 57,919"; t[6][10]="159"; t[7][10]=" 8,186,453"; t[8][10]=" 6,478,149"; t[9][10]=" 26.4";
t[0][11]="Hawaii        "; t[1][11]="HI"; t[2][11]="Honolulu      "; t[3][11]="Honolulu      ";t[4][11]="1959 08/21"; t[5][11]="  6,243"; t[6][11]="  5"; t[7][11]=" 1,211,537"; t[8][11]=" 1,108,229"; t[9][11]="  9.3";
t[0][12]="Idaho         "; t[1][12]="ID"; t[2][12]="Boise         "; t[3][12]="Boise         ";t[4][12]="1890 07/03"; t[5][12]=" 82,751"; t[6][12]=" 44"; t[7][12]=" 1,293,953"; t[8][12]=" 1,006,734"; t[9][12]=" 28.5";
t[0][13]="Illinois      "; t[1][13]="IL"; t[2][13]="Springfield   "; t[3][13]="Chicago       ";t[4][13]="1818 12/03"; t[5][13]=" 55,593"; t[6][13]="102"; t[7][13]="12,419,293"; t[8][13]="11,430,602"; t[9][13]="  8.6";
t[0][14]="Indiana       "; t[1][14]="IN"; t[2][14]="Indianapolis  "; t[3][14]="Indianapolis  ";t[4][14]="1816 12/11"; t[5][14]=" 35,870"; t[6][14]=" 92"; t[7][14]=" 6,080,485"; t[8][14]=" 5,544,156"; t[9][14]="  9.7";
t[0][15]="Iowa          "; t[1][15]="IA"; t[2][15]="Des Moines    "; t[3][15]="Des Moines    ";t[4][15]="1846 12/28"; t[5][15]=" 55,875"; t[6][15]=" 99"; t[7][15]=" 2,926,324"; t[8][15]=" 2,776,831"; t[9][15]="  5.4";
t[0][16]="Kansas        "; t[1][16]="KS"; t[2][16]="Topeka        "; t[3][16]="Wichita       ";t[4][16]="1861 01/29"; t[5][16]=" 81,823"; t[6][16]="105"; t[7][16]=" 2,688,418"; t[8][16]=" 2,477,588"; t[9][16]="  8.5";
t[0][17]="Kentucky      "; t[1][17]="KY"; t[2][17]="Frankfort     "; t[3][17]="Louisville    ";t[4][17]="1792 06/01"; t[5][17]=" 39,732"; t[6][17]="120"; t[7][17]=" 4,041,769"; t[8][17]=" 3,686,892"; t[9][17]="  9.6";
t[0][18]="Louisiana     "; t[1][18]="LA"; t[2][18]="Baton Rouge   "; t[3][18]="New Orleans   ";t[4][18]="1812 04/30"; t[5][18]=" 43,566"; t[6][18]=" 64"; t[7][18]=" 4,468,976"; t[8][18]=" 4,221,826"; t[9][18]="  5.9";
t[0][19]="Maine         "; t[1][19]="ME"; t[2][19]="Augusta       "; t[3][19]="Portland      ";t[4][19]="1820 03/15"; t[5][19]=" 30,865"; t[6][19]=" 39"; t[7][19]=" 1,274,923"; t[8][19]=" 1,227,928"; t[9][19]="  3.8";
t[0][20]="Maryland      "; t[1][20]="MD"; t[2][20]="Annapolis     "; t[3][20]="Baltimore     ";t[4][20]="1788 04/28"; t[5][20]="  9,775"; t[6][20]=" 23"; t[7][20]=" 5,296,486"; t[8][20]=" 4,780,753"; t[9][20]=" 10.8";
t[0][21]="Massachusetts "; t[1][21]="MA"; t[2][21]="Boston        "; t[3][21]="Boston        ";t[4][21]="1788 02/06"; t[5][21]="  7,838"; t[6][21]=" 14"; t[7][21]=" 6,349,097"; t[8][21]=" 6,016,425"; t[9][21]="  5.5";
t[0][22]="Michigan      "; t[1][22]="MI"; t[2][22]="Lansing       "; t[3][22]="Detroit       ";t[4][22]="1837 01/26"; t[5][22]=" 58,110"; t[6][22]=" 83"; t[7][22]=" 9,938,444"; t[8][22]=" 9,295,287"; t[9][22]="  6.9";
t[0][23]="Minnesota     "; t[1][23]="MN"; t[2][23]="St. Paul      "; t[3][23]="Minneapolis   ";t[4][23]="1858 05/11"; t[5][23]=" 79,617"; t[6][23]=" 87"; t[7][23]=" 4,919,479"; t[8][23]=" 4,375,665"; t[9][23]=" 12.4";
t[0][24]="Mississippi   "; t[1][24]="MS"; t[2][24]="Jackson       "; t[3][24]="Jackson       ";t[4][24]="1817 12/10"; t[5][24]=" 46,914"; t[6][24]=" 82"; t[7][24]=" 2,844,658"; t[8][24]=" 2,575,475"; t[9][24]=" 10.5";
t[0][25]="Missouri      "; t[1][25]="MO"; t[2][25]="Jefferson City"; t[3][25]="Kansas City   ";t[4][25]="1821 08/10"; t[5][25]=" 68,898"; t[6][25]="114"; t[7][25]=" 5,595,211"; t[8][25]=" 5,116,901"; t[9][25]="  9.3";
t[0][26]="Montana       "; t[1][26]="MT"; t[2][26]="Helena        "; t[3][26]="Billings      ";t[4][26]="1889 11/08"; t[5][26]="145,556"; t[6][26]=" 56"; t[7][26]="   902,195"; t[8][26]="   799,065"; t[9][26]=" 12.9";
t[0][27]="Nebraska      "; t[1][27]="NE"; t[2][27]="Lincoln       "; t[3][27]="Omaha         ";t[4][27]="1867 03/01"; t[5][27]=" 76,664"; t[6][27]=" 93"; t[7][27]=" 1,711,263"; t[8][27]=" 1,578,417"; t[9][27]="  8.4";
t[0][28]="Nevada        "; t[1][28]="NV"; t[2][28]="Carson City   "; t[3][28]="Las Vegas     ";t[4][28]="1864 10/31"; t[5][28]="109,806"; t[6][28]=" 16"; t[7][28]=" 1,998,257"; t[8][28]=" 1,201,675"; t[9][28]=" 66.3";
t[0][29]="New Hampshire "; t[1][29]="NH"; t[2][29]="Concord       "; t[3][29]="Manchester    ";t[4][29]="1788 06/21"; t[5][29]="  8,969"; t[6][29]=" 10"; t[7][29]=" 1,235,786"; t[8][29]=" 1,109,252"; t[9][29]=" 11.4";
t[0][30]="New Jersey    "; t[1][30]="NJ"; t[2][30]="Trenton       "; t[3][30]="Newark        ";t[4][30]="1787 12/18"; t[5][30]="  7,419"; t[6][30]=" 21"; t[7][30]=" 8,414,350"; t[8][30]=" 7,747,750"; t[9][30]="  8.6";
t[0][31]="New Mexico    "; t[1][31]="NM"; t[2][31]="Santa Fe      "; t[3][31]="Albuquerque   ";t[4][31]="1912 01/06"; t[5][31]="121,365"; t[6][31]=" 33"; t[7][31]=" 1,819,046"; t[8][31]=" 1,515,069"; t[9][31]=" 20.1";
t[0][32]="New York      "; t[1][32]="NY"; t[2][32]="Albany        "; t[3][32]="New York City ";t[4][32]="1788 07/26"; t[5][32]=" 47,224"; t[6][32]=" 62"; t[7][32]="18,976,457"; t[8][32]="17,990,778"; t[9][32]="  5.5";
t[0][33]="North Carolina"; t[1][33]="NC"; t[2][33]="Raleigh       "; t[3][33]="Charlotte     ";t[4][33]="1789 11/21"; t[5][33]=" 48,718"; t[6][33]="100"; t[7][33]=" 8,049,313"; t[8][33]=" 6,632,448"; t[9][33]=" 21.4";
t[0][34]="North Dakota  "; t[1][34]="ND"; t[2][34]="Bismark       "; t[3][34]="Fargo         ";t[4][34]="1889 11/02"; t[5][34]=" 68,994"; t[6][34]=" 53"; t[7][34]="   642,200"; t[8][34]="   638,800"; t[9][34]="  0.5";
t[0][35]="Ohio          "; t[1][35]="OH"; t[2][35]="Columbus      "; t[3][35]="Columbus      ";t[4][35]="1803 03/01"; t[5][35]=" 40,953"; t[6][35]=" 86"; t[7][35]="11,353,140"; t[8][35]="10,847,115"; t[9][35]="  4.7";
t[0][36]="Oklahoma      "; t[1][36]="OK"; t[2][36]="Oklahoma City "; t[3][36]="Oklahoma City ";t[4][36]="1907 11/16"; t[5][36]=" 68,679"; t[6][36]=" 77"; t[7][36]=" 3,450,654"; t[8][36]=" 3,145,576"; t[9][36]="  9.7";
t[0][37]="Oregon        "; t[1][37]="OR"; t[2][37]="Salem         "; t[3][37]="Portland      ";t[4][37]="1859 02/14"; t[5][37]=" 96,003"; t[6][37]=" 36"; t[7][37]=" 3,421,399"; t[8][37]=" 2,842,337"; t[9][37]=" 20.4";
t[0][38]="Pennsylvania  "; t[1][38]="PA"; t[2][38]="Harrisburg    "; t[3][38]="Philadelphia  ";t[4][38]="1787 12/12"; t[5][38]=" 44,820"; t[6][38]=" 67"; t[7][38]="12,281,054"; t[8][38]="11,882,842"; t[9][38]="  3.4";
t[0][39]="Rhode Island  "; t[1][39]="RI"; t[2][39]="Providence    "; t[3][39]="Providence    ";t[4][39]="1790 05/29"; t[5][39]="  1,045"; t[6][39]="  5"; t[7][39]=" 1,048,319"; t[8][39]=" 1,003,464"; t[9][39]="  4.5";
t[0][40]="South Carolina"; t[1][40]="SC"; t[2][40]="Columbia      "; t[3][40]="Columbia      ";t[4][40]="1788 05/23"; t[5][40]=" 30,111"; t[6][40]=" 46"; t[7][40]=" 4,012,012"; t[8][40]=" 3,486,310"; t[9][40]=" 15.1";
t[0][41]="South Dakota  "; t[1][41]="SD"; t[2][41]="Pierre        "; t[3][41]="Sioux Falls   ";t[4][41]="1889 11/02"; t[5][41]=" 75,898"; t[6][41]=" 67"; t[7][41]="   754,844"; t[8][41]="   696,004"; t[9][41]="  8.5";
t[0][42]="Tennessee     "; t[1][42]="TN"; t[2][42]="Nashville     "; t[3][42]="Memphis       ";t[4][42]="1796 06/01"; t[5][42]=" 41,220"; t[6][42]=" 95"; t[7][42]=" 5,689,283"; t[8][42]=" 4,877,203"; t[9][42]=" 16.7";
t[0][43]="Texas         "; t[1][43]="TX"; t[2][43]="Austin        "; t[3][43]="Houston       ";t[4][43]="1845 12/29"; t[5][43]="261,914"; t[6][43]="254"; t[7][43]="20,851,820"; t[8][43]="16,986,335"; t[9][43]=" 22.8";
t[0][44]="Utah          "; t[1][44]="UT"; t[2][44]="Salt Lake City"; t[3][44]="Salt Lake City";t[4][44]="1896 01/04"; t[5][44]=" 82,168"; t[6][44]=" 29"; t[7][44]=" 2,233,169"; t[8][44]=" 1,722,850"; t[9][44]=" 29.6";
t[0][45]="Vermont       "; t[1][45]="VT"; t[2][45]="Montpelier    "; t[3][45]="Burlington    ";t[4][45]="1791 03/04"; t[5][45]="  9,249"; t[6][45]=" 14"; t[7][45]="   608,827"; t[8][45]="   562,758"; t[9][45]="  8.2";
t[0][46]="Virginia      "; t[1][46]="VA"; t[2][46]="Richmond      "; t[3][46]="Virginia Beach";t[4][46]="1788 06/25"; t[5][46]=" 39,598"; t[6][46]=" 95"; t[7][46]=" 7,078,515"; t[8][46]=" 6,189,197"; t[9][46]=" 14.4";
t[0][47]="Washington    "; t[1][47]="WA"; t[2][47]="Olympia       "; t[3][47]="Seattle       ";t[4][47]="1889 11/11"; t[5][47]=" 66,582"; t[6][47]=" 39"; t[7][47]=" 5,894,121"; t[8][47]=" 4,866,669"; t[9][47]=" 21.1";
t[0][48]="West Virginia "; t[1][48]="WV"; t[2][48]="Charleston    "; t[3][48]="Charleston    ";t[4][48]="1863 06/20"; t[5][48]=" 24,087"; t[6][48]=" 55"; t[7][48]=" 1,808,344"; t[8][48]=" 1,793,477"; t[9][48]="  0.8";
t[0][49]="Wisconsin     "; t[1][49]="WI"; t[2][49]="Madison       "; t[3][49]="Milwaukee     ";t[4][49]="1848 05/29"; t[5][49]=" 54,314"; t[6][49]=" 72"; t[7][49]=" 5,363,675"; t[8][49]=" 4,891,954"; t[9][49]="  9.6";
t[0][50]="Wyoming       "; t[1][50]="WY"; t[2][50]="Cheyenne      "; t[3][50]="Cheyenne      ";t[4][50]="1890 07/10"; t[5][50]=" 97,105"; t[6][50]=" 23"; t[7][50]="   493,782"; t[8][50]="   453,589"; t[9][50]="  8.9";

// Remove commas and spaces from a string
function remcom(px) {
  var ix, cx, nx="";
  for (ix=0; ix<px.length; ix++) {
    cx=px.charAt(ix);
    if (cx!=" " && cx!=",") { nx=nx+cx; }
  }
  return nx;
}

// COMB SORT
function srtz(ad,c) {
// COMB SORT PHASE I
// ad = ascending(0) / descending(1) flag
//  c = column number to sort, 0 to 9
  var i, j, k, p1, p2, p;
  var i1 = 0;
  var temp=0;
  var n1 = 50; // Number of items to be sorted
  var gap = n1*.77;
  while (gap>1) {
    k=Math.floor(gap);
    for (i=1; i<=n1-k; i++) {
      i1=i+k; p1=t[c][i]; p2=t[c][i1];
      if (c>4) {
        p=remcom(p1); p1=parseFloat(p);
        p=remcom(p2); p2=parseFloat(p);
      }
      if ((ad==0 && p1>p2)||(ad==1 && p1<p2)) {
        for (j=0; j<=nc; j++) {
          temp = t[j][i];  t[j][i] = t[j][i1];  t[j][i1] = temp;
        }
      }
    }
    gap=gap*.77;
  }
// COMB SORT PHASE II
  i=1;
  while (i<n1) {
    while (i>0) {
      i1=i+1; p1=t[c][i]; p2=t[c][i1];
      if (c>4) {
        p=remcom(p1); p1=parseFloat(p);
        p=remcom(p2); p2=parseFloat(p);
      }
      if ((ad==0 && p1>p2)||(ad==1 && p1<p2)) {             
        for (j=0; j<=nc; j++) {
          temp = t[j][i];  t[j][i] = t[j][i1];  t[j][i1] = temp;
        }
        i=i-1;
      }
      else {
        break // break inner while loop
      }
    }
    i=i+1;
  }
}

function wrtz(c) {
  var i, j;
  for (i=0; i<=9; i++) { kr[i]="<td bgcolor=lightcyan>" }
  kr[c]="<td bgcolor=mintcream><b>";
  with (secWin.document) {
    write("<html><head><title>States Table</title></head>");
    write("<body bgcolor='white'>");
    write("Close this window (click on X) to re-sort.<table bgcolor='#aaaaff' border=5>");
    write("<th colspan=12><font size=+2><b>The 50-STATES of the United States");
    write("</b></font></th>");
    write("<tr align=right bgcolor='#ffffaa'>");
    write("<td>Rank</td>");
    write("<td>Name of State</td>");
    write("<td>Postal Code</td>");
    write("<td>Capital City</td>");
    write("<td>Largest City</td>");
    write("<td>Union Addmission Date</td>");
    write("<td>Land Area</td>");
    write("<td># of Coun -ties</td>");
    write("<td>Population 4/1/2000</td>");
    write("<td>Population 4/1/1990</td>");
    write("<td>% Inc /Dec</td>");
    write("<td>Rank</td></tr>");
    for (i=1; i<=50; i++) {
      write("<tr align=right><td bgcolor=lightskyblue>"+i+"</td>");
      for (j=0; j<10; j++) {
        write(kr[j]+t[j][i]+"</td>");
      }
      write("<td bgcolor=lightskyblue>"+i+"</td></tr>\n");
    }
    write("</table><br>Close this window (click on X) to re-sort.</body></html>");
  }
}

// main function call
function doit(ad,c) {
  srtz(ad,c);
  secWin = open("", "", "scrollbars", "width=900", "height=700");
  wrtz(c);
}   

// </hide> -->
