var value;
var mtstyle = ""
var code;
var mtaction="subscribe"; // "subscribe", "subscribeResponse", "confirm", "confirmResponse"
var mtmessage=""; // e.g. This email address is already subscribed.
var mtemail = "";
var mtsite = 39;
var mtmessages = new Array();

mtmessages[0] = "Thanks for subscribing to our newsletter!  A confirmation E-mail has been sent to you.  You must click on the link in the E-mail in order to join our list.";
mtmessages[1] = "The provided E-mail address is already subscribed.";
mtmessages[2] = "The provided E-mail address was invalid.";
mtmessages[3] = "You're E-mail address has been confirmed.";
mtmessages[4] = "You must enter a valid E-mail address.";

function printCSS()
{
  document.writeln(mtstyle);
}

// BEGIN GENERATED CODE
//

// Override mtaction, mtmessage, mtemail if necessary.


function printForm()
{
  document.writeln("<form name=\"mtmlist\" action=\"http://joinemaillist.musictoday.com/www/processEmailRequest.asp\" method=\"post\"> ");
  //printResponse();
  document.writeln("E-mail: <input type=\"text\" name=\"mtemail\" ",
                   "value=\"", mtemail, "\">");
  document.writeln("<input type=\"hidden\" name=\"mtaction\" value=\"",
                   mtaction, "\">");
  document.writeln("<input type=\"hidden\" name=\"mtsite\" value=\"",
                   mtsite, "\">");
  document.writeln("<input type=\"submit\" name=\"submitButton\" value=\"Join\">"); 
  document.writeln("</form>");
}

function printResponse()
{
  var status;

  if(value == 1 || value == 2 || value  == 4)
  {
    status = 'error';
  }
  else
  {
    status = 'confirm';
  }
  
  if(mtmessage)
  {
    document.writeln('<div id="form_' + status + '">' + mtmessage + '</div><br />');
  }
}

function processVars()
{
  var query = window.location.search.substring(1);
  var pairs = query.split("&");

  for (var i=0;i<pairs.length;i++)
  {
    var pos = pairs[i].indexOf('=');
    if (pos >= 0)
    {
      var argname = pairs[i].substring(0,pos);
      value = pairs[i].substring(pos+1);

      if (argname == "mtaction")
      {
        mtaction = value;
      }
      else if (argname == "mtemail")
      {
        mtemail = value;
      }
      else if (argname == "mtsite")
      {

        mtsite = value;
      }
      else if (argname == "mtmessage")
      {
        value = parseInt(value);

        var validId = true;
        validId = validId && !isNaN(value);
        validId = validId && (mtmessages[value] != null);

        if (validId)
        {
          mtmessage = mtmessages[value];
          code = value;
        }
      }
    }
  }
}

function printMTList()
{
  processVars();
  printCSS();
  printResponse();

  if (mtaction == "confirm")
  {
    document.writeln("Please click the button to confirm your subscription");
    document.writeln("<form name=\"mtmlist\" action=\"http://joinemaillist.musictoday.com/www/processEmailRequest.asp\" method=\"post\"> ");
    document.writeln("<input type=\"hidden\" name=\"mtaction\" value=\"",
                   mtaction, "\">");
    document.writeln("<input type=\"hidden\" name=\"mtsite\" value=\"",
                   mtsite, "\">");
    document.writeln("<input type=\"hidden\" name=\"mtemail\" value=\"",
                   mtemail, "\">");

    document.writeln("<input type=\"submit\" name=\"submitButton\" value=\"confirm\">");
    document.writeln("</form>");

  }
  else
  {
    if(code == 1 || code == 2 || code == 4 || !code)
    {
      printForm();
    }
  }

}

printMTList();
