var myVideoPlayerWindow;
var loggedIn = false

function checkSSL(inLoggedIn){
  
  loggedIn = inLoggedIn;
  
  var securePage = false;
  
  var myLocation = new String("" + document.location);
  
  if(myLocation.indexOf("accountlogin") > -1){
    securePage = true;
  }
  else if(myLocation.indexOf("myaccount") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("accountbalance") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("mysavedwalks") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("internetconnection") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("emailaddress") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("password") > -1){
    securePage = true;
  }
  else if(myLocation.indexOf("mailinglist") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("customerservice") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("suggestionbox") > -1){
    //securePage = true;
  }
  else if(myLocation.indexOf("openanaccount2") > -1){
    securePage = true;
  }
  else if(myLocation.indexOf("openanaccount3") > -1){
    securePage = true;
  }
  else if(myLocation.indexOf("openanaccount4") > -1){
    securePage = true;
  }
  else if(myLocation.indexOf("editopenanaccount2") > -1){
    securePage = true;
  }
  else if(myLocation.indexOf("editopenanaccount3") > -1){
    securePage = true;
  }
  else if(myLocation.indexOf("replenishmyaccount") > -1){
    securePage = true;
  }// end if/else
  
  if(securePage){
    //if(String("" + document.location).indexOf("player") < 0){
      enforceSSL();
    //}
    //else{
    //  unenforceSSL();
    //}// end if/else
  }
  else{
    //if(String("" + document.location).indexOf("openanaccount") < 0 && String("" + document.location).indexOf("accountlogin") < 0){
      unenforceSSL();
    //}
    //else{
    //  enforceSSL();
    //}// end if
  }// end if/else
  
}// end checkSSL
 
function SubmitPurchasePass1(){

  var myArguments = SubmitPurchasePass1.arguments;
  
  var PassType = myArguments[0];
  var inMode = "initialsave";
  if(myArguments.length > 1){
    inMode = myArguments[1];
  }// end if
  
  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=SubmitCreateAccount1&PassType=" + PassType + "&Mode=" + inMode);

}// end SubmitCreateAccount1

function SubmitCreateAccount2(){

  var myArguments = SubmitCreateAccount2.arguments;
  var inMode = "initialsave";
  
  if(myArguments.length > 0){
    inMode = myArguments[0];
  }// end if

  tempDisableAllElements();
  
  var formIsValid = false;
  
  ge("tfCardNumber").value = condense(gev("tfCardNumber"));
  
  if(!ge("cbTermsOfUse").checked){
    alert("You must agree to the Terms of Use before proceeding.");
  }
  else if(tfIsBlank("tfFirstName")){
    alert("Please enter your first name.");
  }
  else if(tfIsBlank("tfLastName")){
    alert("Please enter your last name.");
  }
  else if(tfIsBlank("tfAddressLine1")){
    alert("Please enter your address.");
  }
  else if(tfIsBlank("tfCity")){
    alert("Please enter your city.");
  }
  else if(tfIsBlank("tfStateProvince")){
    alert("Please enter your state.");
  }
  else if(tfIsBlank("tfZipPostalCode")){
    alert("Please enter your postal code.");
  }
  else if(tfIsBlank("tfCountry")){
    alert("Please enter your country.");
  }
  else if(tfIsBlank("tfNameOnCard")){
    alert("Please enter the name on your credit card.");
  }
  else if(tfIsBlank("tfCardNumber")){
    alert("Please enter your credit card number.");
  }
  else if(!isValidCreditCardNumberFormat(gev("tfCardNumber"), gev("selectCreditCard"))){
    alert("Please enter a valid credit card number.");
  }
  else if(!isValidInteger(gev("tfSecurityCode"), "", "", 3, 3)){
    alert("Please enter a valid security code.");
  }
  else if(tfIsBlank("tfExpiresMonth") || tfIsBlank("tfExpiresYear")){
    alert("Please enter your credit card expiration date.");
  }
  else if(!isValidInteger(gev("tfExpiresMonth"), "", "", 2, 2) 
       || !isValidInteger(gev("tfExpiresYear"), "", "", 4, 4)
       || !isValidCreditCardExpiresDate(gev("tfExpiresMonth"), gev("tfExpiresYear"))){
    alert("Please enter a valid credit card expiration date.");
  }
  else{
    formIsValid = true;
  }// end if/else
  
  if(formIsValid){
  
    var tString = "services/pwservices.php?function=SubmitCreateAccount2";
    
    tString += "&FirstName="     + gev("tfFirstName");
    tString += "&LastName="      + gev("tfLastName");
    tString += "&Addr1="         + gev("tfAddressLine1");
    tString += "&Addr2="         + gev("tfAddressLine2");
    tString += "&City="          + gev("tfCity");
    tString += "&StateProv="     + gev("tfStateProvince");
    tString += "&ZipPostalCode=" + gev("tfZipPostalCode");
    tString += "&Country="       + gev("tfCountry");
    tString += "&CreditCard="    + gev("selectCreditCard");
    tString += "&NameOnCard="    + gev("tfNameOnCard");
    tString += "&CardNumber="    + gev("tfCardNumber");
    tString += "&SecurityCode="  + gev("tfSecurityCode");
    tString += "&ExpiresMonth="  + gev("tfExpiresMonth");
    tString += "&ExpiresYear="   + gev("tfExpiresYear");
    tString += "&Mode="          + inMode;
    
    getReturnCode(tString, "_blank");
  }
  else{
    reEnableAllElements();
  }// end if form is valid

}// end SubmitCreateAccount2

function SubmitCreateAccount3(){

  var myArguments = SubmitCreateAccount3.arguments;
  var inMode = "initialsave";
  
  if(myArguments.length > 0){
    inMode = myArguments[0];
  }// end if

  tempDisableAllElements();
  
  var formIsValid = false;
  
  if(tfIsBlank("tfEmailAddress")){
    alert("Please enter your email address.");
  }
  else if(gev("tfEmailAddress").length < 6 
      || gev("tfEmailAddress").indexOf('@') < 2 
      || gev("tfEmailAddress").indexOf('@') >  gev("tfEmailAddress").length-3
      || getOccurenceCount(gev("tfEmailAddress"), "@") > 1
      || gev("tfEmailAddress").indexOf('.') == gev("tfEmailAddress").length-1
      || gev("tfEmailAddress").indexOf('.') < 1
      || gev("tfEmailAddress").indexOf(' ') > -1){
    alert("Please enter a valid email address.");
  }
  else if(gev("tfPassword1").length < 6){
    alert("Please enter a password at least six characters in length.");
  }
  else if(gev("tfPassword1") != gev("tfPassword2")){
    alert("Passwords do not match.  Please re-enter your password.");
  }
  else{
    formIsValid = true;
  }// end if/else

  if(formIsValid){
  
    var myChar = "N";
    
    if(ge("cbMailList").checked){
      myChar = "Y";
    }// end if

    var tString = "services/pwservices.php?function=SubmitCreateAccount3";
    
    tString += "&Email="     + gev("tfEmailAddress");
    tString += "&Password="  + gev("tfPassword1");
    tString += "&MailList="  + myChar;
    tString += "&Mode="      + inMode;
    
    getReturnCode(tString);
  
  }
  else{
    reEnableAllElements();
  }// end if form is valid

}// SubmitCreateAccount3

function SubmitCreateAccount3g(){

  var myArguments = SubmitCreateAccount3g.arguments;
  var inMode = "initialsave";
  
  if(myArguments.length > 0){
    inMode = myArguments[0];
  }// end if

  tempDisableAllElements();
  
  var formIsValid = false;
  
  if(tfIsBlank("tfEmailAddress")){
    alert("Please enter your email address.");
  }
  else if(tfIsBlank("tfEmailAddress2")){
    alert("Please enter the recipient's email address.");
  }
  else if(gev("tfEmailAddress").length < 6 
      || gev("tfEmailAddress").indexOf('@') < 2 
      || gev("tfEmailAddress").indexOf('@') >  gev("tfEmailAddress").length-3
      || getOccurenceCount(gev("tfEmailAddress"), "@") > 1
      || gev("tfEmailAddress").indexOf('.') == gev("tfEmailAddress").length-1
      || gev("tfEmailAddress").indexOf('.') < 1
      || gev("tfEmailAddress").indexOf(' ') > -1){
    alert("Please enter a valid email address.");
  }
  else if(gev("tfEmailAddress2").length < 6 
      || gev("tfEmailAddress2").indexOf('@') < 2 
      || gev("tfEmailAddress2").indexOf('@') >  gev("tfEmailAddress2").length-3
      || getOccurenceCount(gev("tfEmailAddress2"), "@") > 1
      || gev("tfEmailAddress2").indexOf('.') == gev("tfEmailAddress2").length-1
      || gev("tfEmailAddress2").indexOf('.') < 1
      || gev("tfEmailAddress2").indexOf(' ') > -1) {
    alert("Please enter a valid email address for the recipient.");
  }
  else{
    formIsValid = true; 
  }// end if/else

  if(formIsValid){
    
    var myChar = "N";

    var tString = "services/pwservices.php?function=SubmitCreateAccount3";
    
    tString += "&Email="     + gev("tfEmailAddress");
    tString += "&Email2="    + gev("tfEmailAddress2");
    tString += "&Mode="      + inMode;
    
    getReturnCode(tString);
  
  }
  else{
    reEnableAllElements();
  }// end if form is valid

}// SubmitCreateAccount3g

function SubmitCreateAccount4(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=SubmitCreateAccount4"); 
  
}// end SubmitCreateAccount4

function displayExistingInfoOpenAccount2(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayExistingInfoOpenAccount2");
  
}// end displayExistingInfoOpenAccount2

function displayExistingInfoOpenAccount3(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayExistingInfoOpenAccount3");
  
}// end displayExistingInfoOpenAccount2

function displayExistingInfoOpenAccount3g(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayExistingInfoOpenAccount3g");
  
}// end displayExistingInfoOpenAccount2

function displayExistingInfoRenewPass2(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayExistingInfoRenewPass2");
  
}// end displayExistingInfoOpenAccount2

function displayExistingInfoRenewPass2Edit(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayExistingInfoRenewPass2&Mode=edit");
  
}// end displayExistingInfoOpenAccount2


function DisplayRenewPassConfirmInfo(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayRenewPassConfirmInfo");
  
}// end DisplayReplenishAccountConfirmInfo

function SubmitRenewPass1(){

  var myArguments = SubmitRenewPass1.arguments;
  
  var inPassType = myArguments[0];
  var inMode = "initialsave";
  
/*  if(myArguments.length > 3){
    inMode = myArguments[3];
  }// end if*/

  tempDisableAllElements();
  getReturnCode("services/pwservices.php?function=SubmitRenewPass1&PassType=" + inPassType + "&Mode=" + myArguments[1]);
  
}// end SubmitRenewPass1

function SubmitRenewPass2(){

  var myArguments = SubmitRenewPass2.arguments;
  var inMode = "initialsave";
  
  if(myArguments.length > 0){
    inMode = myArguments[0];
  }// end if

  tempDisableAllElements();
  
  var formIsValid = false;
  
  ge("tfCardNumber").value = condense(gev("tfCardNumber"));
  
  if(tfIsBlank("tfFirstName")){
    alert("Please enter your first name.");
  }
  else if(tfIsBlank("tfLastName")){
    alert("Please enter your last name.");
  }
  else if(tfIsBlank("tfAddressLine1")){
    alert("Please enter your address.");
  }
  else if(tfIsBlank("tfCity")){
    alert("Please enter your city.");
  }
  else if(tfIsBlank("tfStateProvince")){
    alert("Please enter your state.");
  }
  else if(tfIsBlank("tfZipPostalCode")){
    alert("Please enter your postal code.");
  }
  else if(tfIsBlank("tfCountry")){
    alert("Please enter your country.");
  }
  else if(tfIsBlank("tfNameOnCard")){
    alert("Please enter the name on your credit card.");
  }
  else if(tfIsBlank("tfCardNumber")){
    alert("Please enter your credit card number.");
  }
  else if(!isValidCreditCardNumberFormat(gev("tfCardNumber"), gev("selectCreditCard"))){
    alert("Please enter a valid credit card number.");
  }
  else if(!isValidInteger(gev("tfSecurityCode"), "", "", 3, 3)){
    alert("Please enter a valid security code.");
  }
  else if(tfIsBlank("tfExpiresMonth") || tfIsBlank("tfExpiresYear")){
    alert("Please enter your credit card expiration date.");
  }
  else if(!isValidInteger(gev("tfExpiresMonth"), "", "", 2, 2) 
       || !isValidInteger(gev("tfExpiresYear"), "", "", 4, 4)
       || !isValidCreditCardExpiresDate(gev("tfExpiresMonth"), gev("tfExpiresYear"))){
    alert("Please enter a valid credit card expiration date.");
  }
  else{
    formIsValid = true;
  }// end if/else
  
  if(formIsValid){
  
    var tString = "services/pwservices.php?function=SubmitRenewPass2";
  
    tString += "&FirstName="     + gev("tfFirstName");
    tString += "&LastName="      + gev("tfLastName");
    tString += "&Addr1="         + gev("tfAddressLine1");
    tString += "&Addr2="         + gev("tfAddressLine2");
    tString += "&City="          + gev("tfCity");
    tString += "&StateProv="     + gev("tfStateProvince");
    tString += "&ZipPostalCode=" + gev("tfZipPostalCode");
    tString += "&Country="       + gev("tfCountry");
    tString += "&CreditCard="    + gev("selectCreditCard");
    tString += "&NameOnCard="    + gev("tfNameOnCard");
    tString += "&CardNumber="    + gev("tfCardNumber");
    tString += "&SecurityCode="  + gev("tfSecurityCode");
    tString += "&ExpiresMonth="  + gev("tfExpiresMonth");
    tString += "&ExpiresYear="   + gev("tfExpiresYear");
    tString += "&Mode="          + inMode;
  
    getReturnCode(tString);
    
  }
  else{
    reEnableAllElements();
  }// end if form is valid

}// end SubmitCreateAccount2

function SubmitRenewPass3(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=SubmitRenewPass3");
  
}// end SubmitCreateAccount1

function LogIn(){

  var destinationString = "";
  var myQSO = new QueryStringObject();
  
  try{  
    if(myQSO.destination != null && myQSO.destination != "" && myQSO.destination != "undefined"){
      destinationString = "&destination=" + myQSO.destination;
    }// end if
  }catch(e){}

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=LogIn&Email=" + gev('tfEmail') + "&Password=" + gev('tfPassword') + destinationString, "_blank");
  
}// end LogIn

function CheckLogin(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=CheckLogin");
  
}// end LogIn

function LogOut(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=LogOut");
  
}// end LogIn

function GetWalkName() {
	getReturnCode("services/pwservices.php?function=GetWalkName");
}

function DisplayCurrentUserEmailAddress(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayCurrentUserEmailAddress");
  
}// end DisplayCurrentUserEmailAddress

function UpdateCurrentUserEmailAddress(){

  if(tfIsBlank("tfEmailAddress")){
    alert("Please enter your email address.");
  }
  else if(gev("tfEmailAddress").length < 6 
      || gev("tfEmailAddress").indexOf('@') < 2 
      || gev("tfEmailAddress").indexOf('@') >  gev("tfEmailAddress").length-3
      || getOccurenceCount(gev("tfEmailAddress"), "@") > 1
      || gev("tfEmailAddress").indexOf('.') == gev("tfEmailAddress").length-1
      || gev("tfEmailAddress").indexOf('.') < 1
      || gev("tfEmailAddress").indexOf(' ') > -1){
    alert("Please enter a valid email address.");
  }
  else{
    tempDisableAllElements();
    getReturnCode("services/pwservices.php?function=UpdateCurrentUserEmailAddress&email=" + gev("tfEmailAddress"));
  }// end if/else
  
}// end UpdateCurrentUserEmailAddress

function UpdateCurrentUserPassword(){

  tempDisableAllElements();
  
  if(gev("tfPassword") != gev("tfPasswordConfirm")){
    alert("Passwords do not match.  Please re-enter your new password.");
    reEnableAllElements();
  }
  else if(gev("tfPassword") == ""){
    alert("Password cannot be blank.  Please re-enter your new password.");
    reEnableAllElements();
  }
  else{
    getReturnCode("services/pwservices.php?function=UpdateCurrentUserPassword&password=" + gev("tfPassword"));
  }// end if/else
  
  ge("tfPassword").value = ge("tfPasswordConfirm").value = "";
  
}// end UpdateCurrentUserPassword

function DisplayCurrentUserMailingList(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayCurrentUserMailingList");
  
}// end DisplayCurrentUserMailingList

function UpdateCurrentUserMailingList(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=UpdateCurrentUserMailingList&mailinglist=" + gev("selectMailingList"));
  
}// end UpdateCurrentUserMailingList

function UpdateCurrentUserMySavedWalks(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=UpdateCurrentUserMySavedWalks");
  
}// end UpdateCurrentUserMySavedWalks

function LoadOnlinePrograms(){
  
  getReturnCode("services/pwservices.php?function=LoadOnlinePrograms");
  
}// end LoadOnlinePrograms

function ShowMyWalk(){
  
  getReturnCode("services/pwservices.php?function=ShowMyWalk");
  
}// end LoadOnlinePrograms

      function saveWalk(){

        

        if(gev('walkName') != ""){

          SaveMyWalk(gev("walkName"), true);

        }

        else{

          alert("You must enter a name in order to save your walk");
        
        }// end if/else

        

      }// end saveWalk
	  
	        function renameWalk(){

        

        if(gev('walkName') != ""){

          RenameSavedWalk(gev("walkName"), true);

        }

        else{

          alert("You must enter a name in order to rename your walk");

        }// end if/else

        

      }// end renameWalk

function SaveMyWalk(inString, inIsDialog){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=SaveMyWalk&walkName=" + inString);
  
}// end LoadOnlinePrograms

function EditMyWalk(inIndex, inAction){

  getReturnCode("services/pwservices.php?function=EditMyWalk&index=" + inIndex + "&action=" + inAction);
  
}// end EditMyWalk

function AddToMyWalk(inProgID){
  
  getReturnCode("services/pwservices.php?function=AddToMyWalk&walkItem=" + inProgID);
  
}// end LoadOnlinePrograms

function LoadEditSavedWalk(inWalkID){

  getReturnCode("services/pwservices.php?function=LoadEditSavedWalk&walkID=" + inWalkID);

}// end LoadEditSavedWalk

function DisplayAccountConfirmInfo(){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=DisplayAccountConfirmInfo");
  
}// end DisplayAccountConfirmInfo

function PrintSessionData(){
    
  window.open("services/pwservices.php?function=PrintSessionData", "_blank");

}// end PrintSessionData

function LoadOnlineProgramsForEdit(){
  
  getReturnCode("services/pwservices.php?function=LoadOnlineProgramsForEdit");
  
}// end LoadOnlineProgramsForEdit

function AddToSavedWalk(inProgID){
  
  getReturnCode("services/pwservices.php?function=AddToSavedWalk&walkItem=" + inProgID);
  
}// end AddToSavedWalk

function EditSavedWalk(inIndex, inAction){

  getReturnCode("services/pwservices.php?function=EditSavedWalk&index=" + inIndex + "&action=" + inAction);

}// end EditMyWalk

function RenameSavedWalk(inString, inIsDialog){

  tempDisableAllElements();
  
  getReturnCode("services/pwservices.php?function=RenameSavedWalk&walkName=" + inString + "&isDialog=" + inIsDialog);
  
}// end RenameSavedWalk

function ViewMyWalk(inWalkID){
    
  ViewSavedWalk(-1);

}// end View My Walk


function ViewSampleProgram(inConSpeed){

  if(myVideoPlayerWindow){myVideoPlayerWindow.close(); }

  var myWidth   = 800; // original 713 without borders
  var myHeight  = 580; // original 530 without borders
  
  var myLeft    = (screen.availWidth-myWidth)/2;
  var myTop     = (screen.availHeight-myHeight)/2;
  
  if(screen.availHeight < 700){
    myHeight = 542;
    myWidth = 790;
    myLeft = 0;
    myTop = 0;
  }// end if

  //myVideoPlayerWindow = window.open("player.shtml?mode=singleprogram&progid=Sample-001", "pw_player", "width=" + myWidth + ",height=" + myHeight + ",left=" + myLeft + ",top=" + myTop);
//  window.location = "sampleplayer.shtml?conspeed=" + inConSpeed, "pw_player", "width=" + myWidth + ",height=" + myHeight + ",left=" + myLeft + ",top=" + myTop);
  
  myVideoPlayerWindow.focus();
  
}// end ViewSampleProgram

function ViewProgram2(inProgID) {
   window.location = "peacefulwalksplayer.php?progid=" + inProgID;
}

function ViewProgram(inProgID){
  gscPD("CheckSessionAndViewProgram", "&progid=" + inProgID);
}// end CheckSessionAndViewProgram

function ViewProgramForEdit2(inProgID) {
   window.location = "peacefulwalksplayer2.php?progid=" + inProgID;
}

function ViewProgramForEdit(inProgID){
  gscPD("CheckSessionAndViewProgramForEdit", "&progid=" + inProgID);
}// end CheckSessionAndViewProgramForEdit


function ViewSavedWalk2(inWalkID) {
   window.location = "peacefulwalksplayer.php?walkid=" + inWalkID;
}// end ViewSavedWalk


function ViewSavedWalk(inWalkID){
  gscPD("CheckSessionAndViewSavedWalk", "&walkid=" + inWalkID);
}// end CheckSessionAndViewProgram
      
      
function UpdateDownloadCount(){
  gsc("UpdateDownloadCount");
}// end UpdateDownloadCount


//Generic Service Call
function gsc(){

  var myArguments = gsc.arguments;
  var myString;
  var preDisable = false;
  
  if(myArguments.length > 0){
    
    myString = "services/pwservices.php?function=" + myArguments[0];
    
    if(myArguments.length > 1){
    
      myString += myArguments[1];
      
      if(myArguments.length > 2 && (String("" + myArguments[2]) == "true" || myArguments[2] == "1")){
        tempDisableAllElements();
      }// end if
      
    }// end if
    
  }// end if
  
  getReturnCode(myString);
  
}// end GenericServiceCall


//Generic Service Call with preDisable
function gscPD(){

  var myArguments = gscPD.arguments;
  
  if(myArguments.length > 0){
  
    if(myArguments.length < 2){
      gsc(myArguments[0]);
    }
    else{
      gsc(myArguments[0], myArguments[1], "true");
    }// end if/else

  }// end if
  
}// end GenericServiceCall

// For free trial programs, check for valid e-mail and then send link
function SendFreeLinks() {
    
    // var myArguments = SendFreeLinks.arguments;
    
    tempDisableAllElements();
    
    var formIsValid = false;
    
    if (tfIsBlank("EmailAddress1")) {
        alert("Please enter an e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (tfIsBlank("EmailAddress2")) {
        alert("Please enter a confirmation e-mail address.");
        ge("EmailAddress2").focus();
    }
    else if (gev("EmailAddress1").length < 6) {
        alert("The e-mail address is too short.  Please enter a valid e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (gev("EmailAddress1").indexOf('@') < 2) {  
        alert("The e-mail username is too short.  Please enter a valid e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (gev("EmailAddress1").indexOf('@') > (gev("EmailAddress1").length - 3)) {  
        alert("The e-mail domain is too short.  Please enter a valid e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (getOccurenceCount(gev("EmailAddress1"), "@") > 1) {  
        alert("There should only be one '@' in the address.  Please enter a valid e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (gev("EmailAddress1").indexOf('.') == gev("EmailAddress1").length - 1) {  
        alert("The address should not end in a period.  Please enter a valid e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (gev("EmailAddress1").indexOf('.') < 1) {  
        alert("The address should not begin with a period.  Please enter a valid e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (gev("EmailAddress1").indexOf(' ') > -1) {  
        alert("The address should not contain spaces.  Please enter a valid e-mail address.");
        ge("EmailAddress1").focus();
    }
    else if (gev("EmailAddress1") != gev("EmailAddress2")) {
        alert("E-mail addresses must match!");
        ge("EmailAddress1").focus();
    }
    else {
        formIsValid = true;
    }
        
    if (formIsValid) {
        getReturnCode("services/pwservices.php?function=SendFreeLinks&email=" + gev("EmailAddress1"));
    }
    else {
        reEnableAllElements();
    }
}

// Unset the free program session variables
function StartFreeProgs() {
    getReturnCode("services/pwservices.php?function=StartFreeProgs");
}
