

// Main struct

Main.sid = null;
Main.cardApp = null;

function Main() {
}

Main.validateUser = function(username,password) {
  var valid = false;
  new Ajax.Request('cgi-bin/validateUser.pl', {
      method: 'post',
      asynchronous: true,
      parameters: {
          username: username,
          password: password,
      },
      onSuccess: function(transport){
        var t = Smartbox.parse(transport.responseXML.documentElement);
        if(t instanceof SmartboxException) {
          alert(t.toString());
        } else {
          //<<<< TBD: sessionId.  For now, validates returns name of cardApp 
          //Main.sid = t.toString();
          Main.cardApp = t.toString();
          Main.advance(Main.cardApp);
        }
      },
      onFailure: function(transport){
      },
      onException: function(req, e){
      }
  });
}

Main.test = function(username,password) {
  alert("Username:" + username + " password:" + password);
}

function sleep(millis) {
  var now = new Date();
  var end = now.getTime() + millis;
  while( now.getTime() < end) {
    now = new Date();
  }
}



Main.advance = function(swfFile) {
  // Javascript madness!
  var counter = 16;
  var timer = setInterval(
    function() {
      var opacity = Math.pow(0.5,16-counter);
      $('logo1').setOpacity(opacity);
      $('p1').setOpacity(opacity);
      counter--;
      if(counter<0) {
        clearInterval(timer);
        setTimeout(Main.loadSwf,0);
      }
    },
    30
  );
}

Main.loadSwf = function() {
  // swf filename expected in Main.cardApp
  $('card').update('');

  var embedText = AC_FL_RunContent(
    "src", "swf/" + Main.cardApp,
    "width", "1024", //"940",
    "height", "480", //"448",
    "align", "left", //"middle",
    "id", "Id of App",
    "quality", "high",
    "bgcolor", "#423834", //"#f0f0f0",
    "name", "Name of App",
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer"
  );

  $('card').update(embedText);
}

