// Messages
var message=new Array();
message[0]="&#145;See how that works?&#146";
message[1]="The Dash";
message[2]="&#145;Maybe it's not about the destination&#133;&#146;";
message[3]="&#145;&#133;maybe, just maybe, it's all about the journey.&#146";
message[4]="2112";
message[5]="&#145;Don't harbor the belief system that was given to you&#133;&#146";
message[6]="&#145;&#133;venture out to find your own.&#146";
message[7]="The Cave";
message[8]="&#145;Sometimes the light can be so bright that it is too painful to see.&#146";
message[9]="Arrow in the Logo";
message[10]="&#145;Bleed Green&#146";
var mssgnum=Math.floor(Math.random()*message.length);
    
function initiate() {
mssg.innerHTML=message[mssgnum];
}

function msgTerm() {
	 alert("Grades will be posted on or before Wednesday, December 19.");
}

function startUp() {
   document.forms['fantasy'].mask.focus();
}

function process() {
   var maskIn = document.forms['fantasy'].mask.value;
   var maskOut = new Array;
   var consonant = new Array("b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","z");
   var vowel = new Array("a","e","i","o","u","y");
   var oldMask = "";
   var newMask = "";
   var firstChar = "";

   if (maskIn.length > 14) {
      alert("A mask may be a maximum of 14 characters including spaces. Please try again.");
      document.forms['fantasy'].mask.select();
      document.forms['fantasy'].mask.focus();
      return;
   }

   for (var x = 0; x < 20; ++x) {
      for (var y = 0; y < maskIn.length; ++y) {
         oldMask = maskIn.charAt(y);
         if (oldMask == "c")
            newMask += consonant[Math.floor(Math.random() * consonant.length)];
         else if (oldMask == "v")
            newMask += vowel[Math.floor(Math.random() * vowel.length)];
         else
            newMask += oldMask;
      }
      newMask = newMask.toLowerCase();
      newMask2 = newMask.split("");
      newMask2[0] = newMask2[0].toUpperCase();
      for (var z = 0; z < newMask2.length; ++z) {
         if (newMask2[z] == " ")
            newMask2[z+1] = newMask2[z+1].toUpperCase();
      }
      maskOut[x] = newMask2.join("");
      newMask = "";
   }

   maskOut.sort();
   
   if (document.getElementsByTagName) {
      var tds = document.getElementsByTagName("td");
      for (var i=0; i < tds.length; ++i) {
         if (tds[i].id == "a1") {
            for (var j = 0; j < 4; ++j) {
               tds[i].innerHTML = maskOut[j];
               ++i;
            }
         }
         if (tds[i].id == "b1") {
            for (var j = 4; j < 8; ++j) {
               tds[i].innerHTML = maskOut[j];
               ++i;
            }
         }
         if (tds[i].id == "c1") {
            for (var j = 8; j < 12; ++j) {
               tds[i].innerHTML = maskOut[j];
               ++i;
            }
         }
         if (tds[i].id == "d1") {
            for (var j = 12; j < 16; ++j) {
               tds[i].innerHTML = maskOut[j];
               ++i;
            }
         }
         if (tds[i].id == "e1") {
            for (var j = 16; j < 20; ++j) {
               tds[i].innerHTML = maskOut[j];
               ++i;
            }
         }
      }
   }
   else
      alert("Fantasy Names will not run on this browser. \n\nFantasy Names is functional with DOM2 compatible browsers such as \nInternet Explorer 5.5+, Netscape Navigator 6.0+, and Mozilla 1.0+.");
   document.forms['fantasy'].mask.select();
   document.forms['fantasy'].mask.focus();
}


var http_request = false;

function makeRequest(url) 
{

   http_request = false;

   if (window.XMLHttpRequest) // Mozilla, Safari, Chrome...
   { 
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) 
         http_request.overrideMimeType('text/xml');
   } 
   else if (window.ActiveXObject) // IE
   { 
      try 
      {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } 
      catch (e) 
      {
         try 
         {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } 
         catch (e) {}
      }
   }

   if (!http_request) 
   {
      alert('Cannot create an XMLHTTP instance');
      return false;
   }

   http_request.onreadystatechange = displayGrades;
   http_request.open('GET', url, true);
   http_request.send(null);

}

function displayGrades() 
{

   if (http_request.readyState == 4) 
   {
      if (http_request.status == 200) 
      {
         var xmlDoc = http_request.responseXML;
         var x = xmlDoc.getElementsByTagName("id");
         var out = "<table class='gradetable'><colgroup><col width='20' /><col width='60' /><col width='60' /></colgroup><tr><th>ID</th><th>Final</th><th>Grade</th></tr>";
         var rowcol1 = "<tr><td>";
         var rowcol2 = "</td><td>";
         var rowcol3 = "</td></tr>";
         for (var i = 0; i < x.length; ++i) 
         {
            out += rowcol1 + xmlDoc.getElementsByTagName("id")[i].childNodes[0].nodeValue +
                   rowcol2 + xmlDoc.getElementsByTagName("finalScore")[i].childNodes[0].nodeValue +
                   rowcol2 + xmlDoc.getElementsByTagName("letterGrade")[i].childNodes[0].nodeValue +
                   rowcol3;
         }
         out += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
         document.getElementById('grades').innerHTML = out;
      } 
      else
         alert('There was a problem with the request.');
   }

}


