//
// Send the request to the server...
// (This is essentially a fake InternetSecure reponse)
//
function enableDemoCourse(server,courseID,userName,userMail){
  var w = 400; var h = 200;
  var l = (screen.width) ? (screen.width-w)/2 : 0;
  var t = (screen.height) ? (screen.height-h)/2 : 0;
  var settings = "height="+h+",width="+w+",top="+t+",left="+l+",status=no,scrollbars=no,resizable=no";

  // Parse out string from Double Colon Product String
  var courseDCPS = courseID.split("::");
  var courseName = courseDCPS[3];

  var win = window.open("","regSWIFT",settings);
  win.document.open();
  win.document.write('<HTML>');
  win.document.write('<HEAD>');
  win.document.write('<TITLE>SWIFT Course Registration</TITLE>');
  win.document.write('<LINK TYPE="text/css" REL="stylesheet" HREF="resources/portal.css">');
  win.document.write('</HEAD>');
  win.document.write('<BODY CLASS="login" onLoad="document.regSWIFT.submit();">');

  win.document.write('<FORM NAME="regSWIFT" METHOD="POST" ACTION="http://'+ server +'/e-commerce">');
  win.document.write('<INPUT TYPE="HIDDEN" NAME="request" VALUE="0">');
  win.document.write('<INPUT TYPE="HIDDEN" NAME="xxxName" VALUE="'+ userName +'">');
  win.document.write('<INPUT TYPE="HIDDEN" NAME="xxxEmail" VALUE="'+ userMail +'">');
  win.document.write('<INPUT TYPE="HIDDEN" NAME="DoubleColonProducts" VALUE="'+ courseID +'">');
  win.document.write('<INPUT TYPE="HIDDEN" NAME="receiptnumber" VALUE="-1">');
  win.document.write('</FORM>');

  win.document.write('<TABLE WIDTH="100%" HEIGHT="100%"><TR><TD VALIGN="MIDDLE" ALIGN="CENTER">');
  win.document.write('<P CLASS="login">Processing your registration request for:</P>');
  win.document.write('<H3 CLASS="login">'+ courseName +'</H3>');
  win.document.write('<P CLASS="login">...Please Wait...</P>');
  win.document.write('</TD></TR></TABLE>');
  win.document.write('</BODY>');
  win.document.write('</HTML>');
  win.document.close();
}

//
// Function for "Try" course
//
function formPreview()
{
  var regForm = document.register;

  // Gather our values
  var server   = regForm.server.value;
  var courseID = regForm.course.value;
  var userName = regForm.uname.value;
  var userMail = regForm.email.value;

  // Do our field checks...
  if((userMail=="")||(userMail.indexOf("@")==-1)||(userMail.indexOf(".")==-1)){alert("Please enter a valid EMAIL address.");regForm.email.select();return;}
  if((userName=="")){alert("Please enter your NAME.");regForm.uname.select();return;}

  // Go ahead and directly tell SWIFT to seat the
  // user in the course and send out the emails...
  enableDemoCourse(server,courseID,userName,userMail);
  regForm.submit();
}

//
// Function for "Buy" course
//
function formPurchase()
{
  var regForm = document.register;

  // Gather our values
  var userName = regForm.uname.value;
  var userMail = regForm.email.value;

  // Do our field checks...
  if((userMail=="")||(userMail.indexOf("@")==-1)||(userMail.indexOf(".")==-1)){alert("Please enter a valid EMAIL address.");regForm.email.select();return;}
  if((userName=="")){alert("Please enter your NAME.");regForm.uname.select();return;}

  // Pass info on to InternetSecure fields...
  regForm.xxxName.value  = userName;
  regForm.xxxEmail.value = userMail;

  // Go ahead and head off to InternetSecure,
  // which in turn tells SWIFT to seat the user
  // in the course and send out the emails...
  regForm.submit();
}

function formReset()
{
  var regForm = document.register;

  regForm.reset();
  regForm.email.focus();
}