
/* 
  This function hides all of the overlays that
  may be currently displayed
*/
function hideSweepsOverlay() 
{
   clearForm('sweepsForm'); 
   clearForm('sweepsLoginForm');  
     
   jQuery("#overlayBackground").hide ();
   jQuery("#sweepsAlreadyRegisteredContainer").hide()
   jQuery("#sweepsAgeTooYoungContainer").hide()
   jQuery("#sweepsOfficialRulesMainContainer").hide();
   jQuery("#sweepsRegisterProfileMainContainer").hide ();
   jQuery("#sweepsRegisterProfileConfirmationContainer").hide ();
}

function displayOfficialRules(divName)
{
   // could have gotten here from sweepsAlreadyRegisteredContainer or sweepsAgeTooYoungContainer
   // so close those overlays
   jQuery("#sweepsAlreadyRegisteredContainer").fadeOut("slow");
   jQuery("#sweepsAgeTooYoungContainer").fadeOut("slow");
   
   var scroll = 0;
   
   document.getElementById("blushOfficialRules").scrollTop = scroll;
   
   trackOverlay (divName);      // tell web analytics that we're displaying this overlay
   
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      carouselMgr.autoStop();      // if we're autoscrolling the feature pane, kill the autoscroller
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
   }
   else
   {
      contentPanesLeft = 240;
   }
   
   overlayDisplayBackground (); // make background semi-opaque and only the overlay clickable

   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 172 left of the contentPanes
   var left = contentPanesLeft + 172;
   
   // set the top position 565 above the footer (545 for the register div height + 20 spacing)
   var top = footerTop - 565;
   
   // now position the overlay using the left and top variables
   jQuery("#"+divName).css('left',left);
   jQuery("#"+divName).css('top',top);

   jQuery("#"+divName).fadeIn("slow");
}

function displaySweepsOverlay()
{
  // if the user is already logged in the populate the form with their
  // profile data and hide the login div
  if ((carouselMgr == null) && (shopOptionsShown != ""))
    fadeShopOptions(250);
  if ((carouselMgr == null) && (viewportShown    != ""))
    fadeViewportNow(250);
  
  if (loggedIn)
  {
     jQuery("#sweepsLoginFormContent").hide ();
     jQuery("#sweepsLoginIntro").hide ();
     
     document.getElementById("sweepsFormContent").scrollTop = 0;
   
     jQuery("#sweepsStep1Intro").hide();
     jQuery("#sweepsLoggedInStep1Intro").show ();
     jQuery("#sweepsStep1").fadeIn("slow");
   
     jQuery("#sweepsStep2").hide ();
     jQuery("#sweepsStep2Intro").hide ();
     
     jQuery("#sweepsFormContent").css('height',420);
     
     jQuery("#profileContinueBtn").show();
     jQuery("#registerContinueBtn").hide();
     jQuery("#profileFinishBtn").show();
     jQuery("#registerFinishBtn").hide();
     
     sweepsProfile('sweepsRegisterProfileMainContainer','sweepsForm');
  }
  else
  {
     jQuery("#sweepsLoggedInStep1Intro").hide ();         
     jQuery("#sweepsLoginFormContent").show ();
     jQuery("#sweepsLoginIntro").show ();
     
     jQuery("#sweepsFormContent").css('height',470);
     
     jQuery("#profileContinueBtn").hide();
     jQuery("#registerContinueBtn").show();
     jQuery("#profileFinishBtn").hide();
     jQuery("#registerFinishBtn").show();
     
     sweepsRegister('sweepsRegisterProfileMainContainer','sweepsForm');
  }
}

/* 
  This function displays the sweeps overlay div.
*/
function sweepsRegister(divName, formName)
{
   var scroll = 0;
      
   jQuery("#sweepsStep1").fadeIn("slow");
   jQuery("#sweepsStep1Intro").fadeIn("slow");
   jQuery("#sweepsStep2Intro").hide();
   jQuery("#sweepsStep2").hide(); 
   
   document.getElementById("sweepsFormContent").scrollTop = scroll;
   
   var firstNameEmptyError = "";
   var lastNameEmptyError = "";
   var emailAddressEmptyError = "";
   var emailAddressInvalidError = "";
   var emailAddressUnconfirmedError = "";
   var emailAddressUnavailableError = "";
   var emailAddressConfirmEmptyError = "";
   var passwordEmptyError = "";
   var passwordInvalidError = "";
   var phoneNumberInvalidError = "";
   var genderEmptyError = "";
   var birthdayInvalidError = "";
   var addressLine1EmptyError = "";
   var cityEmptyError = "";
   var stateEmptyError = "";
   var zipCodeEmptyError = "";
   var zipCodeInvalidError = "";
 
   // the below code sets any errors that may have been displayed
   // before to null so they won't be displayed if the user re-opens the sweeps form
   jQuery ("#sweepsFirstNameEmpty").html(firstNameEmptyError);
   jQuery ("#sweepsLastNameEmpty").html(lastNameEmptyError);
   jQuery ("#sweepsEmailAddressEmpty").html(emailAddressEmptyError);
   jQuery ("#sweepsEmailAddressInvalid").html(emailAddressInvalidError);
   jQuery ("#sweepsEmailAddressUnconfirmed").html(emailAddressUnconfirmedError);
   jQuery ("#sweepsEmailAddressUnavailable").html(emailAddressUnavailableError);
   jQuery ("#sweepsEmailAddressConfirmEmpty").html(emailAddressConfirmEmptyError);
   jQuery ("#sweepsPasswordEmpty").html(passwordEmptyError);
   jQuery ("#sweepsPasswordInvalid").html(passwordInvalidError);
   jQuery ("#sweepsPhoneNumberInvalid").html(phoneNumberInvalidError);
   jQuery ("#sweepsGenderEmpty").html(genderEmptyError);
   jQuery ("#sweepsDateOfBirthInvalid").html(birthdayInvalidError);
   jQuery ("#sweepsAddress1Empty").html(addressLine1EmptyError);
   jQuery ("#sweepsCityEmpty").html(cityEmptyError);
   jQuery ("#sweepsStateEmpty").html(stateEmptyError);
   jQuery ("#sweepsZipCodeEmpty").html(zipCodeEmptyError);
   jQuery ("#sweepsZipCodeInvalid").html(zipCodeInvalidError);

   trackOverlay (divName);      // tell web analytics that we're displaying this overlay
   
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      carouselMgr.autoStop();      // if we're autoscrolling the feature pane, kill the autoscroller
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
   }
   else
   {
      contentPanesLeft = 240;
   }
   
   overlayDisplayBackground (); // make background semi-opaque and only the overlay clickable

   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 172 left of the contentPanes
   var left = contentPanesLeft + 172;
   
   // set the top position 565 above the footer (545 for the register div height + 20 spacing)
   var top = footerTop - 565;
   
   // now position the overlay using the left and top variables
   jQuery("#"+divName).css('left',left);
   jQuery("#"+divName).css('top',top);

   jQuery("#"+divName).fadeIn("slow");
}

/* 
  This function gets the data entered in step 1 of
  the register form and sends it to the back end to 
  be validated.  If errors are found then the errors 
  are retrieved and displayed on the page using Ajax.
*/
function validateSweepsConsumerData(formName)
{
   var currentForm = document.forms[formName];
   var firstNameValue = currentForm.elements["userFirstName"].value;
   var lastNameValue = currentForm.elements["userLastName"].value;
   var emailAddressValue = currentForm.elements["userEmailAddress"].value;
   var emailAddressConfirmValue = currentForm.elements["userEmailAddressConfirm"].value;
   var passwordValue = currentForm.elements["userPassword"].value;
   var phoneNumberValue = currentForm.elements["userPhoneNumber"].value;
   var genderValue = "";
   
   for (var i=0; i < document.forms[formName].userGender.length; i++)
   {
     if (document.forms[formName].userGender[i].checked)
     {
        genderValue = document.forms[formName].userGender[i].value;
     }
   }

   var monthValue = currentForm.elements["userDateOfBirthMM"].value;
   var dayValue = currentForm.elements["userDateOfBirthDD"].value;
   var yearValue = currentForm.elements["userDateOfBirthYYYY"].value;
   var addressLine1Value = currentForm.elements["userAddressLine1"].value;
   var addressLine2Value = currentForm.elements["userAddressLine2"].value;
   var addressLine3Value = currentForm.elements["userAddressLine3"].value;
   var cityValue = currentForm.elements["userCity"].value;
   var stateValue = currentForm.elements["userState"].value;
   var zipCodeValue = currentForm.elements["userZipCode"].value;
   
   jQuery.post("/registerConsumer.do", 
               {
                  firstName:  firstNameValue,
                  lastName:   lastNameValue,
                  emailAddress: emailAddressValue,
                  emailAddressConfirm: emailAddressConfirmValue,
                  password: passwordValue,
                  phoneNumber: phoneNumberValue,
                  gender: genderValue,
                  month:  monthValue,
                  day: dayValue,
                  year: yearValue,
                  addressLine1: addressLine1Value,
                  addressLine2: addressLine2Value,
                  addressLine3: addressLine3Value,
                  city:  cityValue,
                  state: stateValue,
                  zipCode: zipCodeValue,
                  sweepsId: "blush_sweeps"
               },
               function (errors)
               {
                   var firstNameEmptyError = "";
                   var lastNameEmptyError = "";
                   var emailAddressEmptyError = "";
                   var emailAddressInvalidError = "";
                   var emailAddressUnconfirmedError = "";
                   var emailAddressUnavailableError = "";
                   var emailAddressConfirmEmptyError = "";
                   var passwordEmptyError = "";
                   var passwordInvalidError = "";
                   var phoneNumberInvalidError = "";
                   var genderEmptyError = "";
                   var birthdayInvalidError = "";
                   var addressLine1EmptyError = "";
                   var cityEmptyError = "";
                   var stateEmptyError = "";
                   var zipCodeEmptyError = "";
                   var zipCodeInvalidError = "";
                 
                   jQuery ("#sweepsFirstNameEmpty").html(firstNameEmptyError);
                   jQuery ("#sweepsLastNameEmpty").html(lastNameEmptyError);
                   jQuery ("#sweepsEmailAddressEmpty").html(emailAddressEmptyError);
                   jQuery ("#sweepsEmailAddressInvalid").html(emailAddressInvalidError);
                   jQuery ("#sweepsEmailAddressUnconfirmed").html(emailAddressUnconfirmedError);
                   jQuery ("#sweepsEmailAddressUnavailable").html(emailAddressUnavailableError);
                   jQuery ("#sweepsEmailAddressConfirmEmpty").html(emailAddressConfirmEmptyError);
                   jQuery ("#sweepsPasswordEmpty").html(passwordEmptyError);
                   jQuery ("#sweepsPasswordInvalid").html(passwordInvalidError);
                   jQuery ("#sweepsPhoneNumberInvalid").html(phoneNumberInvalidError);
                   jQuery ("#sweepsGenderEmpty").html(genderEmptyError);
                   jQuery ("#sweepsDateOfBirthInvalid").html(birthdayInvalidError);
                   jQuery ("#sweepsAddress1Empty").html(addressLine1EmptyError);
                   jQuery ("#sweepsCityEmpty").html(cityEmptyError);
                   jQuery ("#sweepsStateEmpty").html(stateEmptyError);
                   jQuery ("#sweepsZipCodeEmpty").html(zipCodeEmptyError);
                   jQuery ("#sweepsZipCodeInvalid").html(zipCodeInvalidError);
                   
                   if (errors != null && errors != "")
                   {
                       var errorResult = errors.split("|");
                       var scroll = 0;
                       
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var tempPos = errorResult[i].indexOf('=');
                           if (tempPos > 0) 
                           {
                             var tempKey = errorResult[i].substring(0,tempPos);
                           }

                           if(tempKey == "firstNameEmpty" || tempKey == "lastNameEmpty" || tempKey == "emailAddressEmpty" || tempKey == "emailAddressInvalid" || tempKey == "emailAddressUnconfirmed" || tempKey == "emailAddressUnavailable" || tempKey == "emailAddressConfirmEmpty" || tempKey == "passwordEmpty" || tempKey == "passwordInvalid" || tempKey == "phoneNumberInvalid")
                           {
                              scroll = 0;
                              break;
                           }
                           else if(tempKey == "genderEmpty" || tempKey == "dateOfBirthInvalid" || tempKey == "addressLine1Empty" || tempKey == "cityEmpty" || tempKey == "stateEmpty" || tempKey == "zipCodeEmpty" || tempKey == "zipCodeInvalid")
                           {
                              scroll = 100;
                              break;
                           }
                       }
                                              
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var pos = errorResult[i].indexOf('=');
                           if (pos > 0) 
                           {
                             var key = errorResult[i].substring(0,pos);
                             var val = errorResult[i].substring(pos+1);
                           }
                                                      
                           if(key == "firstNameEmpty")
                           {
                              firstNameEmptyError = val;
                              jQuery ("#sweepsFirstNameEmpty").html(firstNameEmptyError);
                           }
                           else if(key == "lastNameEmpty")
                           {
                              lastNameEmptyError = val;
                              jQuery("#sweepsLastNameEmpty").html(lastNameEmptyError);
                           }
                           else if(key == "emailAddressEmpty")
                           {
                              emailAddressEmptyError = val;
                              jQuery("#sweepsEmailAddressInvalid").css('height',0);
                              jQuery("#sweepsEmailAddressInvalid").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',0);
                              jQuery("#sweepsEmailAddressUnconfirmed").hide();
                              jQuery("#sweepsEmailAddressUnavailable").css('height',0);
                              jQuery("#sweepsEmailAddressUnavailable").hide();
                              jQuery("#sweepsEmailAddressEmpty").css('height',15);
                              jQuery("#sweepsEmailAddressEmpty").show();
                              jQuery("#sweepsEmailAddressEmpty").html(emailAddressEmptyError);
                           }
                           else if(key == "emailAddressInvalid")
                           {
                              emailAddressInvalidError = val;
                              jQuery("#sweepsEmailAddressEmpty").css('height',0);
                              jQuery("#sweepsEmailAddressEmpty").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',0);
                              jQuery("#sweepsEmailAddressUnconfirmed").hide();
                              jQuery("#sweepsEmailAddressUnavailable").css('height',0);
                              jQuery("#sweepsEmailAddressUnavailable").hide();
                              jQuery("#sweepsEmailAddressInvalid").css('height',15);
                              jQuery("#sweepsEmailAddressInvalid").show();
                              jQuery("#sweepsEmailAddressInvalid").html(emailAddressInvalidError);
                           }
                           else if(key == "emailAddressUnconfirmed")
                           {
                              emailAddressUnconfirmedError = val;
                              jQuery("#sweepsEmailAddressEmpty").css('height',0);
                              jQuery("#sweepsEmailAddressEmpty").hide();
                              jQuery("#sweepsEmailAddressInvalid").css('height',0);
                              jQuery("#sweepsEmailAddressInvalid").hide();
                              jQuery("#sweepsEmailAddressUnavailable").css('height',0);
                              jQuery("#sweepsEmailAddressUnavailable").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',15);
                              jQuery("#sweepsEmailAddressUnconfirmed").show();
                              jQuery("#sweepsEmailAddressUnconfirmed").html(emailAddressUnconfirmedError);
                           }
                           else if(key == "emailAddressUnavailable")
                           {
                              emailAddressUnavailableError = val;
                              jQuery("#sweepsEmailAddressEmpty").css('height',0);
                              jQuery("#sweepsEmailAddressEmpty").hide();
                              jQuery("#sweepsEmailAddressInvalid").css('height',0);
                              jQuery("#sweepsEmailAddressInvalid").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',0);
                              jQuery("#sweepsEmailAddressUnconfirmed").hide();
                              jQuery("#sweepsEmailAddressUnavailable").css('height',15);
                              jQuery("#sweepsEmailAddressUnavailable").show();
                              jQuery("#sweepsEmailAddressUnavailable").html(emailAddressUnavailableError);
                           }
                           else if(key == "emailAddressConfirmEmpty")
                           {
                              emailAddressConfirmEmptyError = val;
                              jQuery("#sweepsEmailAddressConfirmEmpty").html(emailAddressConfirmEmptyError);
                           }
                           else if(key == "passwordEmpty")
                           {
                              passwordEmptyError = val;
                              jQuery("#sweepsPasswordInvalid").css('height',0);
                              jQuery("#sweepsPasswordInvalid").hide();
                              jQuery("#sweepsPasswordEmpty").css('height',15);
                              jQuery("#sweepsPasswordEmpty").show();
                              jQuery("#sweepsPasswordEmpty").html(passwordEmptyError);
                           }
                           else if(key == "passwordInvalid")
                           {
                              passwordInvalidError = val;
                              jQuery("#sweepsPasswordEmpty").css('height',0);
                              jQuery("#sweepsPasswordEmpty").hide();
                              jQuery("#sweepsPasswordInvalid").css('height',15);
                              jQuery("#sweepsPasswordInvalid").show();
                              jQuery("#sweepsPasswordInvalid").html(passwordInvalidError);
                           }
                           else if(key == "phoneNumberInvalid")
                           {
                              phoneNumberInvalidError = val;
                              jQuery("#sweepsPhoneNumberInvalid").html(phoneNumberInvalidError);
                           }
                           else if(key == "genderEmpty")
                           {
                             // genderEmptyError = val;
                              //jQuery("#sweepsGenderEmpty").html(genderEmptyError);
                           }
                           else if(key == "dateOfBirthInvalid")
                           {
                              birthdayInvalidError = val;
                              jQuery("#sweepsDateOfBirthInvalid").html(birthdayInvalidError);
                           }
                           else if(key == "addressLine1Empty")
                           {
                              addressLine1EmptyError = val;
                              jQuery("#sweepsAddress1Empty").html(addressLine1EmptyError);
                           }
                           else if(key == "cityEmpty")
                           {
                              cityEmptyError = val;
                              jQuery("#sweepsCityEmpty").html(cityEmptyError);
                           }
                           else if(key == "stateEmpty")
                           {
                              stateEmptyError = val;
                              jQuery("#sweepsStateEmpty").html(stateEmptyError);
                           }
                           else if(key == "zipCodeEmpty")
                           {
                              zipCodeEmptyError = val;
                              jQuery("#sweepsZipCodeInvalid").css('height',0);
                              jQuery("#sweepsZipCodeInvalid").hide();
                              jQuery("#sweepsZipCodeEmpty").css('height',15);
                              jQuery("#sweepsZipCodeEmpty").show();
                              jQuery("#sweepsZipCodeEmpty").html(zipCodeEmptyError);
                           }
                           else if(key == "zipCodeInvalid")
                           {
                              zipCodeInvalidError = val;
                              jQuery("#sweepsZipCodeEmpty").css('height',0);
                              jQuery("#sweepsZipCodeEmpty").hide();
                              jQuery("#sweepsZipCodeInvalid").css('height',15);
                              jQuery("#sweepsZipCodeInvalid").show();
                              jQuery("#sweepsZipCodeInvalid").html(zipCodeInvalidError);
                           }
                           else if(key == "ageMessage")
                           { 
                              sweepsTooYoung();
                           }
                       }
                       document.getElementById("sweepsFormContent").scrollTop = scroll;
                   }
                   else
                   {
                      sweepsRegisterStep2();
                   }
                }
              );
}

/* 
  The user data entered in step 1 of the registration
  form validated successfully so this function displays
  step 2 of the registration process
*/
function sweepsRegisterStep2()
{     
   var facial_foundationEmptyError = "";
   var mascaraEmptyError = "";
   var eye_shadowEmptyError = "";
   var lipstickEmptyError = "";
   var lip_glossEmptyError = "";
   var question2EmptyError = "";
   var question3EmptyError = "";
   var question4EmptyError = "";
   var question5EmptyError = "";
   var question6EmptyError = "";
   
   jQuery ("#sweepsFacial_foundationEmpty").html(facial_foundationEmptyError);
   jQuery ("#sweepsMascaraEmpty").html(mascaraEmptyError);
   jQuery ("#sweepsEye_shadowEmpty").html(eye_shadowEmptyError);
   jQuery ("#sweepsLipstickEmpty").html(lipstickEmptyError);
   jQuery ("#sweepsLip_glossEmpty").html(lip_glossEmptyError);
   jQuery ("#sweepsQuestion2Empty").html(question2EmptyError);
   jQuery ("#sweepsQuestion3Empty").html(question3EmptyError);
   jQuery ("#sweepsQuestion4Empty").html(question4EmptyError);
   jQuery ("#sweepsQuestion5Empty").html(question5EmptyError);
   jQuery ("#sweepsQuestion6Empty").html(question6EmptyError);
   
   jQuery("#sweepsLoginFormContent").hide ();
   jQuery("#sweepsLoginIntro").hide ();
                    
                    
   // adjust the height since we're not displaying the login fields
   jQuery("#sweepsFormContent").css('height',420);
   
   jQuery("#sweepsStep1").fadeOut("slow");
   jQuery("#sweepsStep1Intro").hide();
   document.getElementById("sweepsFormContent").scrollTop = 0;
   jQuery("#sweepsStep2Intro").show();
   jQuery("#sweepsStep2").fadeIn("slow"); 
}

/* 
  This function gets the data entered in the
  register form and sends it to the back end to 
  be validated.  If errors are found then the errors 
  are retrieved and displayed on the page using Ajax.
*/
function submitSweepsRegisterForm(formName)
{   
   var currentForm = document.forms[formName];
   
   var question1aValue = currentForm.elements["userQuestion1a"].value;
   var question1bValue = currentForm.elements["userQuestion1b"].value;
   var question1cValue = currentForm.elements["userQuestion1c"].value;
   var question1dValue = currentForm.elements["userQuestion1d"].value;
   var question1eValue = currentForm.elements["userQuestion1e"].value;
   var question2Value = currentForm.elements["userQuestion2"].value;
   var question3Value = currentForm.elements["userQuestion3"].value;
   var question4Value = currentForm.elements["userQuestion4"].value;
   var question5Value = currentForm.elements["userQuestion5"].value;
   var question6Value = currentForm.elements["userQuestion6"].value;
   var newsSamplesValue = "";
   var researchPanelValue = "";
   var offersFromOtherBrandsValue = "";
   
   if (document.forms[formName].userReceiveNewsAndSamples.checked)
   {
      newsSamplesValue = "on";
   }       
   
   if (document.forms[formName].userParticipateInResearchPanel.checked)
   {
      researchPanelValue = "on";
   }
      
   if (document.forms[formName].userReceiveOffersFromOtherBrands.checked)
   {
      offersFromOtherBrandsValue = "on";
   }
               
   jQuery.post("/registerConsumerSurvey.do",
               {
                  question1a: question1aValue,
                  question1b: question1bValue,
                  question1c: question1cValue,
                  question1d: question1dValue,
                  question1e: question1eValue,
                  question2: question2Value,
                  question3: question3Value,
                  question4: question4Value,
                  question5: question5Value,
                  question6: question6Value,
                  receiveNewsAndSamples: newsSamplesValue,
                  participateInResearchPanel: researchPanelValue,
                  receiveOffersFromOtherBrands: offersFromOtherBrandsValue,
                  sweepsId: "blush_sweeps"
               },
               function (errors)
               {
                   var facial_foundationEmptyError = "";
                   var mascaraEmptyError = "";
                   var eye_shadowEmptyError = "";
                   var lipstickEmptyError = "";
                   var lip_glossEmptyError = "";
                   var question2EmptyError = "";
                   var question3EmptyError = "";
                   var question4EmptyError = "";
                   var question5EmptyError = "";
                   var question6EmptyError = "";
   
                   jQuery ("#sweepsFacial_foundationEmpty").html(facial_foundationEmptyError);
                   jQuery ("#sweepsMascaraEmpty").html(mascaraEmptyError);
                   jQuery ("#sweepsEye_shadowEmpty").html(eye_shadowEmptyError);
                   jQuery ("#sweepsLipstickEmpty").html(lipstickEmptyError);
                   jQuery ("#sweepsLip_glossEmpty").html(lip_glossEmptyError);
                   jQuery ("#sweepsQuestion2Empty").html(question2EmptyError);
                   jQuery ("#sweepsQuestion3Empty").html(question3EmptyError);
                   jQuery ("#sweepsQuestion4Empty").html(question4EmptyError);
                   jQuery ("#sweepsQuestion5Empty").html(question5EmptyError);
                   jQuery ("#sweepsQuestion6Empty").html(question6EmptyError);

                   if (errors != null && errors != "")
                   {
                       var errorResult = errors.split("|");
                       var scroll = 0;
                       
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var tempPos = errorResult[i].indexOf('=');
                           if (tempPos > 0) 
                           {
                             var tempKey = errorResult[i].substring(0,tempPos);
                           }

                           if(tempKey == "facial_foundationEmpty" || tempKey == "mascaraEmpty" || tempKey == "eye_shadowEmpty" || tempKey == "lipstickEmpty")
                           {
                              scroll = 0;
                              break;
                           }
                           else if(tempKey == "lip_glossEmpty" || tempKey == "question2Empty" || tempKey == "question3Empty" || tempKey == "question4Empty" || tempKey == "question5Empty" || tempKey == "question6Empty")
                           {
                              scroll = 158;
                              break;
                           }
                       }
                       
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var pos = errorResult[i].indexOf('=');
                           if (pos > 0) 
                           {
                             var key = errorResult[i].substring(0,pos);
                             var val = errorResult[i].substring(pos+1);
                           }
                           
                           if(key == "facial_foundationEmpty")
                           {
                              facial_foundationEmptyError = val;
                              jQuery("#sweepsFacial_foundationEmpty").html(facial_foundationEmptyError);
                           }
                           else if(key == "mascaraEmpty")
                           {
                              mascaraEmptyError = val;
                              jQuery("#sweepsMascaraEmpty").html(mascaraEmptyError);
                           }
                           else if(key == "eye_shadowEmpty")
                           {
                              eye_shadowEmptyError = val;
                              jQuery("#sweepsEye_shadowEmpty").html(eye_shadowEmptyError);
                           }
                           else if(key == "lipstickEmpty")
                           {
                              lipstickEmptyError = val;
                              jQuery("#sweepsLipstickEmpty").html(lipstickEmptyError);
                           }
                           else if(key == "lip_glossEmpty")
                           {
                              lip_glossEmptyError = val;
                              jQuery("#sweepsLip_glossEmpty").html(lip_glossEmptyError);
                           }
                           else if(key == "question2Empty")
                           {
                              question2EmptyError = val;
                              jQuery("#sweepsQuestion2Empty").html(question2EmptyError);
                           }
                           else if(key == "question3Empty")
                           {
                              question3EmptyError = val;
                              jQuery("#sweepsQuestion3Empty").html(question3EmptyError);
                           }
                           else if(key == "question4Empty")
                           {
                              question4EmptyError = val;
                              jQuery("#sweepsQuestion4Empty").html(question4EmptyError);
                           }
                           else if(key == "question5Empty")
                           {
                              question5EmptyError = val;
                              jQuery("#sweepsQuestion5Empty").html(question5EmptyError);
                           }
                           else if(key == "question6Empty")
                           {
                              question6EmptyError = val;
                              jQuery("#sweepsQuestion6Empty").html(question6EmptyError);
                           }
                           else if(key == "alreadyEnteredMessage")
                           {
                              sweepsAlreadyEntered();
                           }
                       }
                       document.getElementById("sweepsFormContent").scrollTop = scroll;
                   }
                   else
                   {
                      sweepsRegisterConfirmation();
                   }
                }
              );
}

/* 
  The user successfully registered so display the 
  registration confirmation div.  
  
  The backend code automatically logs the user in
  if they registered successfully so this function also
  hides the logInDiv and signUp div and shows the myProfile
  div in the footer.
*/
function sweepsRegisterConfirmation()
{
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
      doCallout(carouselMgr.getNormalizedPaneName());
   }
   else
   {
      contentPanesLeft = 240;
   }
   
   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 172 left of the contentPanes
   var left = contentPanesLeft + 172;
   
   // set the top position 565 above the footer (545 for the registerConfirmation div height + 20 spacing)
   var top = footerTop - 565;
   
   // now position the overlay using the left and top variables
   jQuery("#sweepsRegisterProfileConfirmationContainer").css('left',left);
   jQuery("#sweepsRegisterProfileConfirmationContainer").css('top',top);
  
   jQuery("#sweepsRegisterProfileMainContainer").fadeOut("slow");
   jQuery("#sweepsRegisterProfileConfirmationContainer").fadeIn("slow");
  
   // the below code updates the footer divs to display the correct buttons
   jQuery("#logInDiv").hide  ();
   jQuery("#signUp").hide  ();
   jQuery("#myProfile").show  ();
   loggedIn = true;
   clearForm('sweepsForm');  
}

function sweepsProfile(divName, formName)
{  
   var profileForm = document.forms[formName];
   
   jQuery.post("/getProfile.do",
               function (values)
               {
                   var firstNameValue = "";
                   var lastNameValue = "";
                   var emailAddressValue = "";
                   var emailAddressConfirmValue = "";
                   var passwordValue = "";
                   var phoneNumberValue = "";
                   var genderValue = "";
                   var monthValue = "";
                   var dayValue = "";
                   var yearValue = "";
                   var addressLine1Value = "";
                   var addressLine2Value = "";
                   var addressLine3Value = "";
                   var cityValue = "";
                   var stateValue = "";
                   var zipCodeValue = "";
                   var question1aValue = "";
                   var question1bValue = "";
                   var question1cValue = "";
                   var question1dValue = "";
                   var question1eValue = "";
                   var question2Value = "";
                   var question3Value = "";
                   var question4Value = "";
                   var question5Value = "";
                   var question6Value = "";
                   var newsAndSamplesValue = "";
                   var participateValue = "";
                   var otherBrandsValue = "";
                   
                   if (values != null && values != "")
                   {
                       var valuesResult = values.split("|");
                                              
                       for(i = 0; i < valuesResult.length; i++)
                       {
                           var pos = valuesResult[i].indexOf('=');
                           if (pos > 0) 
                           {
                             var key = valuesResult[i].substring(0,pos);
                             var val = valuesResult[i].substring(pos+1);
                           }
                           
                           if(key == "firstName")
                           {
                              firstNameValue = val;
                              profileForm.elements["userFirstName"].value = firstNameValue;
                           }
                           else if(key == "lastName")
                           {
                              lastNameValue = val;
                              profileForm.elements["userLastName"].value = lastNameValue;
                           }
                           else if(key == "emailAddress")
                           {
                              emailAddressValue = val;
                              profileForm.elements["userEmailAddress"].value = emailAddressValue;
                           }
                           else if(key == "emailAddressConfirm")
                           {
                              emailAddressConfirmValue = val;
                              profileForm.elements["userEmailAddressConfirm"].value = emailAddressConfirmValue;
                           }
                           else if(key == "password")
                           {
                              passwordValue = val;
                              profileForm.elements["userPassword"].value = passwordValue;
                           }
                           else if(key == "phoneNumber")
                           {
                              phoneNumberValue = val;
                              if(phoneNumberValue == "null")
                              {
                                phoneNumberValue = "";
                              }
                              profileForm.elements["userPhoneNumber"].value = phoneNumberValue;
                           }
                           else if(key == "gender")
                           {
                              genderValue = val;
                              
                              profileForm.userGender[0].checked = false;
                              profileForm.userGender[1].checked = false;
                              
                              if(genderValue.toString() == "F")
                              {
                                 profileForm.userGender[0].checked = true;
                              }
                              else if(genderValue.toString() == "M")
                              {
                                 profileForm.userGender[1].checked = true;
                              }
                           }
                           else if(key == "month")
                           {
                              monthValue = val;
                              profileForm.elements["userDateOfBirthMM"].value = monthValue;
                           }
                           else if(key == "day")
                           {
                              dayValue = val;
                              profileForm.elements["userDateOfBirthDD"].value = dayValue;
                           }
                           else if(key == "year")
                           {
                              yearValue = val;
                              profileForm.elements["userDateOfBirthYYYY"].value = yearValue;
                           }
                           else if(key == "addressLine1")
                           {
                              addressLine1Value = val;
                              profileForm.elements["userAddressLine1"].value = addressLine1Value;
                           }
                           else if(key == "addressLine2")
                           {
                              addressLine2Value = val;
                              if(addressLine2Value == "null")
                              {
                                addressLine2Value = "";
                              }
                              profileForm.elements["userAddressLine2"].value = addressLine2Value;
                           }
                           else if(key == "addressLine3")
                           {
                              addressLine3Value = val;
                              if(addressLine3Value == "null")
                              {
                                addressLine3Value = "";
                              }
                              profileForm.elements["userAddressLine3"].value = addressLine3Value;
                           }
                           else if(key == "city")
                           {
                              cityValue = val;
                              profileForm.elements["userCity"].value = cityValue;
                           }
                           else if(key == "state")
                           {
                              stateValue = val;
                              profileForm.elements["userState"].value = stateValue;
                           }
                           else if(key == "zipCode")
                           {
                              zipCodeValue = val;
                              profileForm.elements["userZipCode"].value = zipCodeValue;
                           }
                           else if(key == "question1a")
                           {
                              question1aValue = val;
                              profileForm.elements["userQuestion1a"].value = question1aValue;
                           }
                           else if(key == "question1b")
                           {
                              question1bValue = val;
                              profileForm.elements["userQuestion1b"].value = question1bValue;
                           }
                           else if(key == "question1c")
                           {
                              question1cValue = val;
                              profileForm.elements["userQuestion1c"].value = question1cValue;
                           }
                           else if(key == "question1d")
                           {
                              question1dValue = val;
                              profileForm.elements["userQuestion1d"].value = question1dValue;
                           }
                           else if(key == "question1e")
                           {
                              question1eValue = val;
                              profileForm.elements["userQuestion1e"].value = question1eValue;
                           }
                           else if(key == "question2")
                           {
                              question2Value = val;
                              profileForm.elements["userQuestion2"].value = question2Value;
                           }
                           else if(key == "question3")
                           {
                              question3Value = val;
                              profileForm.elements["userQuestion3"].value = question3Value;
                           }
                           else if(key == "question4")
                           {
                              question4Value = val;
                              profileForm.elements["userQuestion4"].value = question4Value;
                           }
                           else if(key == "question5")
                           {
                              question5Value = val;
                              profileForm.elements["userQuestion5"].value = question5Value;
                           }
                           else if(key == "question6")
                           {
                              question6Value = val;
                              profileForm.elements["userQuestion6"].value = question6Value;
                           }
                           else if(key == "newAndSamples")
                           {
                              newsAndSamplesValue = val;
                              profileForm.userReceiveNewsAndSamples.checked = false;
                              if(newsAndSamplesValue == "on")
                              {
                                 profileForm.userReceiveNewsAndSamples.checked = true;
                              }
                              
                              profileForm.userReceiveNewsAndSamples.newsAndSamplesValue;
                           }
                           else if(key == "participate")
                           {
                              participateValue = val;
                              profileForm.userParticipateInResearchPanel.checked = false;
                              if(participateValue == "on")
                              {
                                 profileForm.userParticipateInResearchPanel.checked = true;
                              }
                              profileForm.userParticipateInResearchPanel.participateValue;
                           }
                           else if(key == "otherBrands")
                           {
                              otherBrandsValue = val;
                              profileForm.userReceiveOffersFromOtherBrands.checked = false;
                              if(otherBrandsValue == "on")
                              {
                                 profileForm.userReceiveOffersFromOtherBrands.checked = true;
                              }
                              profileForm.userReceiveOffersFromOtherBrands.otherBrandsValue;
                           }
                       }

                       trackOverlay (divName);      // tell web analytics that we're displaying this overlay
                       
                       var contentPanesLeft = null;
                       //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
                       if(carouselMgr != null)
                       {
                          carouselMgr.autoStop();      // if we're autoscrolling the feature pane, kill the autoscroller
                          // get the left position of the contentPanes
                          contentPanesLeft = parseInt($("contentPanes").style.left);
                       }
                       else
                       {
                          contentPanesLeft = 240;
                       }
                       
                       overlayDisplayBackground (); // make background semi-opaque and only the overlay clickable

                       // get the top position of the footer
                       var footerTop = parseInt($("footer").style.top);
   
                       // set the left position 172 left of the contentPanes
                       var left = contentPanesLeft + 172;
   
                       // set the top position 565 above the footer (545 for the profile div height + 20 spacing)
                       var top = footerTop - 565;
   
                       // now position the overlay using the left and top variables
                       jQuery("#"+divName).css('left',left);
                       jQuery("#"+divName).css('top',top);
                       
                       jQuery("#"+divName).fadeIn("slow");
                   }
                }
              );
}

/* 
  This function gets the data entered in step 1 of 
  the profile form and sends it to the back end to 
  be validated.  If errors are found then the errors 
  are retrieved and displayed on the page using Ajax.
  
  If no errors are found the the profileStep2 function
  is called.
*/
function validateSweepsConsumerProfileData(formName)
{  
   var currentForm = document.forms[formName];
   var firstNameValue = currentForm.elements["userFirstName"].value;
   var lastNameValue = currentForm.elements["userLastName"].value;
   var emailAddressValue = currentForm.elements["userEmailAddress"].value;
   var emailAddressConfirmValue = currentForm.elements["userEmailAddressConfirm"].value;
   var passwordValue = currentForm.elements["userPassword"].value;
   var phoneNumberValue = currentForm.elements["userPhoneNumber"].value;
   var genderValue = "";
   
   for (var i=0; i < currentForm.userGender.length; i++)
   {
     if (currentForm.userGender[i].checked)
     {
        genderValue = currentForm.userGender[i].value
     }
   }

   var monthValue = currentForm.elements["userDateOfBirthMM"].value;
   var dayValue = currentForm.elements["userDateOfBirthDD"].value;
   var yearValue = currentForm.elements["userDateOfBirthYYYY"].value;
   var addressLine1Value = currentForm.elements["userAddressLine1"].value;
   var addressLine2Value = currentForm.elements["userAddressLine2"].value;
   var addressLine3Value = currentForm.elements["userAddressLine3"].value;
   var cityValue = currentForm.elements["userCity"].value;
   var stateValue = currentForm.elements["userState"].value;
   var zipCodeValue = currentForm.elements["userZipCode"].value;
   
   jQuery.post("/validateConsumerProfile.do", 
               {
                  firstName:  firstNameValue,
                  lastName:   lastNameValue,
                  emailAddress: emailAddressValue,
                  emailAddressConfirm: emailAddressConfirmValue,
                  password: passwordValue,
                  phoneNumber: phoneNumberValue,
                  gender: genderValue,
                  month:  monthValue,
                  day: dayValue,
                  year: yearValue,
                  addressLine1: addressLine1Value,
                  addressLine2: addressLine2Value,
                  addressLine3: addressLine3Value,
                  city:  cityValue,
                  state: stateValue,
                  zipCode: zipCodeValue,
                  sweepsId: "blush_sweeps"
               },
               function (errors)
               {
                   var firstNameEmptyError = "";
                   var lastNameEmptyError = "";
                   var emailAddressEmptyError = "";
                   var emailAddressInvalidError = "";
                   var emailAddressUnconfirmedError = "";
                   var emailAddressUnavailableError = "";
                   var emailAddressConfirmEmptyError = "";
                   var passwordEmptyError = "";
                   var passwordInvalidError = "";
                   var phoneNumberInvalidError = "";
                   var genderEmptyError = "";
                   var birthdayInvalidError = "";
                   var addressLine1EmptyError = "";
                   var cityEmptyError = "";
                   var stateEmptyError = "";
                   var zipCodeEmptyError = "";
                   var zipCodeInvalidError = "";
                 
                   jQuery ("#sweepsFirstNameEmpty").html(firstNameEmptyError);
                   jQuery ("#sweepsLastNameEmpty").html(lastNameEmptyError);
                   jQuery ("#sweepsEmailAddressEmpty").html(emailAddressEmptyError);
                   jQuery ("#sweepsEmailAddressInvalid").html(emailAddressInvalidError);
                   jQuery ("#sweepsEmailAddressUnconfirmed").html(emailAddressUnconfirmedError);
                   jQuery ("#sweepsEmailAddressUnavailable").html(emailAddressUnavailableError);
                   jQuery ("#sweepsEmailAddressConfirmEmpty").html(emailAddressConfirmEmptyError);
                   jQuery ("#sweepsPasswordEmpty").html(passwordEmptyError);
                   jQuery ("#sweepsPasswordInvalid").html(passwordInvalidError);
                   jQuery ("#sweepsPhoneNumberInvalid").html(phoneNumberInvalidError);
                   jQuery ("#sweepsGenderEmpty").html(genderEmptyError);
                   jQuery ("#sweepsDateOfBirthInvalid").html(birthdayInvalidError);
                   jQuery ("#sweepsAddress1Empty").html(addressLine1EmptyError);
                   jQuery ("#sweepsCityEmpty").html(cityEmptyError);
                   jQuery ("#sweepsStateEmpty").html(stateEmptyError);
                   jQuery ("#sweepsZipCodeEmpty").html(zipCodeEmptyError);
                   jQuery ("#sweepsZipCodeInvalid").html(zipCodeInvalidError);
                   
                   if (errors != null && errors != "")
                   {
                       var errorResult = errors.split("|");
                       var scroll = 0;
                       
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var tempPos = errorResult[i].indexOf('=');
                           if (tempPos > 0) 
                           {
                             var tempKey = errorResult[i].substring(0,tempPos);
                           }

                           if(tempKey == "firstNameEmpty" || tempKey == "lastNameEmpty" || tempKey == "emailAddressEmpty" || tempKey == "emailAddressInvalid" || tempKey == "emailAddressUnconfirmed" || tempKey == "emailAddressUnavailable" || tempKey == "emailAddressConfirmEmpty" || tempKey == "passwordEmpty" || tempKey == "passwordInvalid" || tempKey == "phoneNumberInvalid")
                           {
                              scroll = 0;
                              break;
                           }
                           else if(tempKey == "genderEmpty" || tempKey == "dateOfBirthInvalid" || tempKey == "addressLine1Empty" || tempKey == "cityEmpty" || tempKey == "stateEmpty" || tempKey == "zipCodeEmpty" || tempKey == "zipCodeInvalid")
                           {
                              scroll = 100;
                              break;
                           }
                       }
                       
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var pos = errorResult[i].indexOf('=');
                           if (pos > 0) 
                           {
                             var key = errorResult[i].substring(0,pos);
                             var val = errorResult[i].substring(pos+1);
                           }
                           
                           if(key == "firstNameEmpty")
                           {
                              firstNameEmptyError = val;
                              jQuery ("#sweepsFirstNameEmpty").html(firstNameEmptyError);
                           }
                           else if(key == "lastNameEmpty")
                           {
                              lastNameEmptyError = val;
                              jQuery("#sweepsLastNameEmpty").html(lastNameEmptyError);
                           }
                           else if(key == "emailAddressEmpty")
                           {
                              emailAddressEmptyError = val;
                              jQuery("#sweepsEmailAddressInvalid").css('height',0);
                              jQuery("#sweepsEmailAddressInvalid").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',0);
                              jQuery("#sweepsEmailAddressUnconfirmed").hide();                              
                              jQuery("#sweepsEmailAddressUnavailable").css('height',0);
                              jQuery("#sweepsEmailAddressUnavailable").hide();
                              jQuery("#sweepsEmailAddressEmpty").css('height',15);
                              jQuery("#sweepsEmailAddressEmpty").show();
                              jQuery("#sweepsEmailAddressEmpty").html(emailAddressEmptyError);
                           }
                           else if(key == "emailAddressInvalid")
                           {
                              emailAddressInvalidError = val;
                              jQuery("#sweepsEmailAddressEmpty").css('height',0);
                              jQuery("#sweepsEmailAddressEmpty").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',0);
                              jQuery("#sweepsEmailAddressUnconfirmed").hide();        
                              jQuery("#sweepsEmailAddressUnavailable").css('height',0);
                              jQuery("#sweepsEmailAddressUnavailable").hide();
                              jQuery("#sweepsEmailAddressInvalid").css('height',15);
                              jQuery("#sweepsEmailAddressInvalid").show();
                              jQuery("#sweepsEmailAddressInvalid").html(emailAddressInvalidError);
                           }
                           else if(key == "emailAddressUnconfirmed")
                           {
                              emailAddressUnconfirmedError = val;
                              jQuery("#sweepsEmailAddressEmpty").css('height',0);
                              jQuery("#sweepsEmailAddressEmpty").hide();
                              jQuery("#sweepsEmailAddressInvalid").css('height',0);
                              jQuery("#sweepsEmailAddressInvalid").hide();
                              jQuery("#sweepsEmailAddressUnavailable").css('height',0);
                              jQuery("#sweepsEmailAddressUnavailable").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',15);
                              jQuery("#sweepsEmailAddressUnconfirmed").show();
                              jQuery("#sweepsEmailAddressUnconfirmed").html(emailAddressUnconfirmedError);
                           }
                           else if(key == "emailAddressUnavailable")
                           {
                              emailAddressUnavailableError = val;
                              jQuery("#sweepsEmailAddressEmpty").css('height',0);
                              jQuery("#sweepsEmailAddressEmpty").hide();
                              jQuery("#sweepsEmailAddressInvalid").css('height',0);
                              jQuery("#sweepsEmailAddressInvalid").hide();
                              jQuery("#sweepsEmailAddressUnconfirmed").css('height',0);
                              jQuery("#sweepsEmailAddressUnconfirmed").hide();
                              jQuery("#sweepsEmailAddressUnavailable").css('height',15);
                              jQuery("#sweepsEmailAddressUnavailable").show();
                              jQuery("#sweepsEmailAddressUnavailable").html(emailAddressUnavailableError);
                           }
                           else if(key == "emailAddressConfirmEmpty")
                           {
                              emailAddressConfirmEmptyError = val;
                              jQuery("#sweepsEmailAddressConfirmEmpty").html(emailAddressConfirmEmptyError);
                           }
                           else if(key == "passwordEmpty")
                           {
                              passwordEmptyError = val;
                              jQuery("#sweepsPasswordInvalid").css('height',0);
                              jQuery("#sweepsPasswordInvalid").hide();
                              jQuery("#sweepsPasswordEmpty").css('height',15);
                              jQuery("#sweepsPasswordEmpty").show();
                              jQuery("#sweepsPasswordEmpty").html(passwordEmptyError);
                           }
                           else if(key == "passwordInvalid")
                           {
                              passwordInvalidError = val;
                              jQuery("#sweepsPasswordEmpty").css('height',0);
                              jQuery("#sweepsPasswordEmpty").hide();
                              jQuery("#sweepsPasswordInvalid").css('height',15);
                              jQuery("#sweepsPasswordInvalid").show();
                              jQuery("#sweepsPasswordInvalid").html(passwordInvalidError);
                           }
                           else if(key == "phoneNumberInvalid")
                           {
                              phoneNumberInvalidError = val;
                              jQuery("#sweepsPhoneNumberInvalid").html(phoneNumberInvalidError);
                           }
                           else if(key == "genderEmpty")
                           {
                              //genderEmptyError = val;
                              //jQuery("#sweepsGenderEmpty").html(genderEmptyError);
                           }
                           else if(key == "dateOfBirthInvalid")
                           {
                              birthdayInvalidError = val;
                              jQuery("#sweepsDateOfBirthInvalid").html(birthdayInvalidError);
                           }
                           else if(key == "addressLine1Empty")
                           {
                              addressLine1EmptyError = val;
                              jQuery("#sweepsAddress1Empty").html(addressLine1EmptyError);
                           }
                           else if(key == "cityEmpty")
                           {
                              cityEmptyError = val;
                              jQuery("#sweepsCityEmpty").html(cityEmptyError);
                           }
                           else if(key == "stateEmpty")
                           {
                              stateEmptyError = val;
                              jQuery("#sweepsStateEmpty").html(stateEmptyError);
                           }
                           else if(key == "zipCodeEmpty")
                           {
                              zipCodeEmptyError = val;
                              jQuery("#sweepsZipCodeInvalid").css('height',0);
                              jQuery("#sweepsZipCodeInvalid").hide();
                              jQuery("#sweepsZipCodeEmpty").css('height',15);
                              jQuery("#sweepsZipCodeEmpty").show();
                              jQuery("#sweepsZipCodeEmpty").html(zipCodeEmptyError);
                           }
                           else if(key == "zipCodeInvalid")
                           {
                              zipCodeInvalidError = val;
                              jQuery("#sweepsZipCodeEmpty").css('height',0);
                              jQuery("#sweepsZipCodeEmpty").hide();
                              jQuery("#sweepsZipCodeInvalid").css('height',15);
                              jQuery("#sweepsZipCodeInvalid").show();
                              jQuery("#sweepsZipCodeInvalid").html(zipCodeInvalidError);
                           }
                           else if(key == "ageMessage")
                           { 
                              sweepsTooYoung();
                           }
                       }
                       document.getElementById("sweepsFormContent").scrollTop = scroll;
                   }
                   else
                   {
                      sweepsProfileStep2();
                   }
                }
              );
}

/* 
  This function displays step 2 in the profile form.
*/
function sweepsProfileStep2()
{     
   var facial_foundationEmptyError = "";
   var mascaraEmptyError = "";
   var eye_shadowEmptyError = "";
   var lipstickEmptyError = "";
   var lip_glossEmptyError = "";
   var question2EmptyError = "";
   var question3EmptyError = "";
   var question4EmptyError = "";
   var question5EmptyError = "";
   var question6EmptyError = "";
   
   jQuery ("#sweepsFacial_foundationEmpty").html(facial_foundationEmptyError);
   jQuery ("#sweepsMascaraEmpty").html(mascaraEmptyError);
   jQuery ("#sweepsEye_shadowEmpty").html(eye_shadowEmptyError);
   jQuery ("#sweepsLipstickEmpty").html(lipstickEmptyError);
   jQuery ("#sweepsLip_glossEmpty").html(lip_glossEmptyError);
   jQuery ("#sweepsQuestion2Empty").html(question2EmptyError);
   jQuery ("#sweepsQuestion3Empty").html(question3EmptyError);
   jQuery ("#sweepsQuestion4Empty").html(question4EmptyError);
   jQuery ("#sweepsQuestion5Empty").html(question5EmptyError);
   jQuery ("#sweepsQuestion6Empty").html(question6EmptyError);
   
   jQuery("#sweepsStep1").fadeOut("slow");
   jQuery("#sweepsStep1Intro").hide();
   jQuery("#sweepsLoggedInStep1Intro").hide();
   document.getElementById("sweepsFormContent").scrollTop = 0;
   jQuery("#sweepsStep2Intro").show();
   jQuery("#sweepsStep2").fadeIn("slow");
}

/* 
  This function gets the data entered in the
  profile form and sends it to the back end to 
  be validated.  If errors are found then the errors 
  are retrieved and displayed on the page using Ajax.
  
  If no errors are found the the data is updated in the
  database by the backend logic.  The profileConfirmation()
  function is then called.
*/
function submitSweepsProfileForm(formName)
{   
   var currentForm = document.forms[formName];
   
   var question1aValue = currentForm.elements["userQuestion1a"].value;
   var question1bValue = currentForm.elements["userQuestion1b"].value;
   var question1cValue = currentForm.elements["userQuestion1c"].value;
   var question1dValue = currentForm.elements["userQuestion1d"].value;
   var question1eValue = currentForm.elements["userQuestion1e"].value;
   var question2Value = currentForm.elements["userQuestion2"].value;
   var question3Value = currentForm.elements["userQuestion3"].value;
   var question4Value = currentForm.elements["userQuestion4"].value;
   var question5Value = currentForm.elements["userQuestion5"].value;
   var question6Value = currentForm.elements["userQuestion6"].value;
   
   var newsSamplesValue = "";
   if (currentForm.userReceiveNewsAndSamples.checked)
   {
      newsSamplesValue = currentForm.userReceiveNewsAndSamples.value
   }       

   var researchPanelValue = "";
   if (currentForm.userParticipateInResearchPanel.checked)
   {
      researchPanelValue = currentForm.userParticipateInResearchPanel.value
   }
   
   var otherBrandsValue = "";
   if (currentForm.userReceiveOffersFromOtherBrands.checked)
   {
      otherBrandsValue = currentForm.userReceiveOffersFromOtherBrands.value
   }
               
   jQuery.post("/updateConsumerSurveyProfile.do",
               {
                  question1a: question1aValue,
                  question1b: question1bValue,
                  question1c: question1cValue,
                  question1d: question1dValue,
                  question1e: question1eValue,
                  question2: question2Value,
                  question3: question3Value,
                  question4: question4Value,
                  question5: question5Value,
                  question6: question6Value,
                  receiveNewsAndSamples: newsSamplesValue,
                  participateInResearchPanel: researchPanelValue,
                  receiveOffersFromOtherBrands: otherBrandsValue,
                  sweepsId: "blush_sweeps"
               },
               function (errors)
               {
                   var facial_foundationEmptyError = "";
                   var mascaraEmptyError = "";
                   var eye_shadowEmptyError = "";
                   var lipstickEmptyError = "";
                   var lip_glossEmptyError = "";
                   var question2EmptyError = "";
                   var question3EmptyError = "";
                   var question4EmptyError = "";
                   var question5EmptyError = "";
                   var question6EmptyError = "";
                   
                   jQuery ("#sweepsFacial_foundationEmpty").html(facial_foundationEmptyError);
                   jQuery ("#sweepsMascaraEmpty").html(mascaraEmptyError);
                   jQuery ("#sweepsEye_shadowEmpty").html(eye_shadowEmptyError);
                   jQuery ("#sweepsLipstickEmpty").html(lipstickEmptyError);
                   jQuery ("#sweepsLip_glossEmpty").html(lip_glossEmptyError);
                   jQuery ("#sweepsQuestion2Empty").html(question2EmptyError);
                   jQuery ("#sweepsQuestion3Empty").html(question3EmptyError);
                   jQuery ("#sweepsQuestion4Empty").html(question4EmptyError);
                   jQuery ("#sweepsQuestion5Empty").html(question5EmptyError);
                   jQuery ("#sweepsQuestion6Empty").html(question6EmptyError);

                   if (errors != null && errors != "")
                   {
                       var errorResult = errors.split("|");
                       var scroll = 0;
                       
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var tempPos = errorResult[i].indexOf('=');
                           if (tempPos > 0) 
                           {
                             var tempKey = errorResult[i].substring(0,tempPos);
                           }

                           if(tempKey == "facial_foundationEmpty" || tempKey == "mascaraEmpty" || tempKey == "eye_shadowEmpty" || tempKey == "lipstickEmpty")
                           {
                              scroll = 0;
                              break;
                           }
                           else if(tempKey == "lip_glossEmpty" || tempKey == "question2Empty" || tempKey == "question3Empty" || tempKey == "question4Empty" || tempKey == "question5Empty" || tempKey == "question6Empty")
                           {
                              scroll = 158;
                              break;
                           }
                       }
                       
                       for(i = 0; i < errorResult.length; i++)
                       {
                           var pos = errorResult[i].indexOf('=');
                           if (pos > 0) 
                           {
                             var key = errorResult[i].substring(0,pos);
                             var val = errorResult[i].substring(pos+1);
                           }
                           
                           if(key == "facial_foundationEmpty")
                           {
                              facial_foundationEmptyError = val;
                              jQuery("#sweepsFacial_foundationEmpty").html(facial_foundationEmptyError);
                           }
                           else if(key == "mascaraEmpty")
                           {
                              mascaraEmptyError = val;
                              jQuery("#sweepsMascaraEmpty").html(mascaraEmptyError);
                           }
                           else if(key == "eye_shadowEmpty")
                           {
                              eye_shadowEmptyError = val;
                              jQuery("#sweepsEye_shadowEmpty").html(eye_shadowEmptyError);
                           }
                           else if(key == "lipstickEmpty")
                           {
                              lipstickEmptyError = val;
                              jQuery("#sweepsLipstickEmpty").html(lipstickEmptyError);
                           }
                           else if(key == "lip_glossEmpty")
                           {
                              lip_glossEmptyError = val;
                              jQuery("#sweepsLip_glossEmpty").html(lip_glossEmptyError);
                           }
                           else if(key == "question2Empty")
                           {
                              question2EmptyError = val;
                              jQuery("#sweepsQuestion2Empty").html(question2EmptyError);
                           }
                           else if(key == "question3Empty")
                           {
                              question3EmptyError = val;
                              jQuery("#sweepsQuestion3Empty").html(question3EmptyError);
                           }
                           else if(key == "question4Empty")
                           {
                              question4EmptyError = val;
                              jQuery("#sweepsQuestion4Empty").html(question4EmptyError);
                           }
                           else if(key == "question5Empty")
                           {
                              question5EmptyError = val;
                              jQuery("#sweepsQuestion5Empty").html(question5EmptyError);
                           }
                           else if(key == "question6Empty")
                           {
                              question6EmptyError = val;
                              jQuery("#sweepsQuestion6Empty").html(question6EmptyError);
                           }
                           else if(key == "alreadyEnteredMessage")
                           {
                              sweepsAlreadyEntered();
                           }
                       }
                       document.getElementById("sweepsFormContent").scrollTop = scroll;
                   }
                   else
                   {
                      sweepsProfileConfirmation();
                   }
                }
              );
}

/* 
  The user successfully updated their profile 
  so display the profile confirmation div
*/
function sweepsProfileConfirmation()
{
   loggedIn = true;
  
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
   }
   else
   {
      contentPanesLeft = 240;
   }

   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 172 left of the contentPanes
   var left = contentPanesLeft + 172;
   
   // set the top position 565 above the footer (545 for the myProfileConfirmation div height + 20 spacing)
   var top = footerTop - 565;
   
   // now position the overlay using the left and top variables
   jQuery("#sweepsRegisterProfileConfirmationContainer").css('left',left);
   jQuery("#sweepsRegisterProfileConfirmationContainer").css('top',top);
  
   jQuery("#sweepsRegisterProfileMainContainer").fadeOut("slow");
   jQuery("#sweepsRegisterProfileConfirmationContainer").fadeIn("slow");
}

/* 
  This function displays the login overlay div
*/
function sweepsLogin(divName, formName)
{
   // the user may have gotten here from the forgotPassword overlay so
   // go ahead and hide it if they did
   jQuery("#forgotPasswordMainContainer").fadeOut("slow");

   // gallery specific checks
   if ((carouselMgr == null) && (shopOptionsShown != ""))
     fadeShopOptions(250);
   if ((carouselMgr == null) && (viewportShown    != ""))
     fadeViewportNow(250);

   var loginForm = document.forms[formName];
   var emailAddressValue = "";
   var passwordValue = "";
   var rememberMeValue = "";
   
   jQuery.post("/getLogin.do",
               function (values)
               {                  
                   if (values != null && values != "")
                   {
                       var valuesResult = values.split("|");
                       for(i = 0; i < valuesResult.length; i++)
                       {
                           var pos = valuesResult[i].indexOf('=');
                           if (pos > 0) 
                           {
                             var key = valuesResult[i].substring(0,pos);
                             var val = valuesResult[i].substring(pos+1);
                           }
                           
                           if(key == "emailAddress")
                           {
                              emailAddressValue = val;
                              
                              if(emailAddressValue == "null")
                              {
                                 emailAddressValue = "";
                              }
                              loginForm.elements["loginEmailAddress"].value = emailAddressValue;
                           }
                           else if(key == "password")
                           {
                              passwordValue = val;
                              if(passwordValue == "null")
                              {
                                 passwordValue = "";
                              }
                              
                              loginForm.elements["loginPassword"].value = passwordValue;
                           }
                           else if(key == "rememberMe")
                           {
                              rememberMeValue = val;
                              if(rememberMeValue == "null")
                              {
                                 rememberMeValue = "";
                              }
                              
                              loginForm.rememberMe.checked = false;
                              if(rememberMeValue == "on")
                              {
                                 loginForm.rememberMe.checked = true;
                              }
                              loginForm.rememberMe.rememberMeValue;
                          
                           }
                       }

                       trackOverlay (divName);      // tell web analytics that we're displaying this overlay
                       
                       var contentPanesLeft = null;
                       //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
                       if(carouselMgr != null)
                       {
                          carouselMgr.autoStop();      // if we're autoscrolling the feature pane, kill the autoscroller
                          // get the left position of the contentPanes
                          contentPanesLeft = parseInt($("contentPanes").style.left);
                       }
                       else
                       {
                          contentPanesLeft = 240;
                       }
                       
                       overlayDisplayBackground (); // make background semi-opaque and only the overlay clickable

                       // get the top position of the footer
                       var footerTop = parseInt($("footer").style.top);
                          
                       // set the left position 172 left of the contentPanes
                       var left = contentPanesLeft + 172;
   
                       // set the top position 645 above the footer (545 for the login div height + 100 spacing)
                       var top = footerTop - 280;
                          
                       // now position the overlay using the left and top variables
                       jQuery("#"+divName).css('left',left);
                       jQuery("#"+divName).css('top',top);
                       
                       jQuery("#"+divName).fadeIn("slow");
                   }
                }
              );
   
   // the user may have gotten here from the forgot
   // password confirmation page so go ahead and hide it if they did
   jQuery("#forgotPasswordConfirmationContainer").fadeOut("slow");
   
   var emailAddressBlankError = "";
   var passwordBlankError = "";
   var loginFailedError = "";
   
   jQuery ("#errorEmailAddressBlank").html(emailAddressBlankError);
   jQuery ("#errorPasswordBlank").html(passwordBlankError);
   jQuery ("#errorLoginFailed").html(loginFailedError);
   
   var loginForm = document.forms[formName];
        
   trackOverlay (divName);      // tell web analytics that we're displaying this overlay
   
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      carouselMgr.autoStop();      // if we're autoscrolling the feature pane, kill the autoscroller
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
   }
   else
   {
      contentPanesLeft = 240;
   }
   
   overlayDisplayBackground (); // make background semi-opaque and only the overlay clickable

   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 164 left of the contentPanes
   var left = contentPanesLeft + 164;
   
   // set the top position 375 above the footer (255 for the login div height + 100 spacing)
   var top = footerTop - 375;
   
   // now position the overlay using the left and top variables
   jQuery("#"+divName).css('left',left);
   jQuery("#"+divName).css('top',top);

   jQuery("#"+divName).fadeIn("slow");
}

/* 
  This function gets the data entered in the
  login form and sends it to the back end to be 
  validated.  If errors are found then the errors 
  are retrieved and displayed on the page using Ajax.
  
  If no errors were found in the back end code then the Java code will
  log the user in and the log in overlay will automatically disappear.
*/
function submitSweepsLoginForm(formName)
{
   var currentForm = document.forms[formName];
   var loginEmailAddressValue = currentForm.elements["userLoginEmailAddress"].value;
   var loginPasswordValue = currentForm.elements["userLoginPassword"].value;
   var rememberMeValue = "";
       
   /*if (currentForm.rememberMe.checked)
   {
      rememberMeValue = currentForm.rememberMe.value
   } */
                          
   jQuery.post("/login.do", 
              {
                 loginEmailAddress:  loginEmailAddressValue,
                 loginPassword:   loginPasswordValue,
                 rememberMe: rememberMeValue
              },
              function (errors)
              {
                 var emailAddressBlankError = "";
                 var passwordBlankError = "";
                 var loginFailedError = "";
                       
                 jQuery ("#sweepsLoginEmailAddressBlank").html(emailAddressBlankError);
                 jQuery ("#sweepsLoginPasswordBlank").html(passwordBlankError);
                 jQuery ("#sweepsLoginFailed").html(loginFailedError);

                 if (errors != null && errors != "")
                 {
                     var errorResult = errors.split("|");
                     for(i = 0; i < errorResult.length; i++)
                     {
                        var pos = errorResult[i].indexOf('=');
                        if (pos > 0) 
                        {
                           var key = errorResult[i].substring(0,pos);
                           var val = errorResult[i].substring(pos+1);
                        }
                            
                        if(key == "errorEmailAddressBlank")
                        {
                           emailAddressBlankError = val;
                           jQuery ("#sweepsLoginEmailAddressBlank").html(emailAddressBlankError);
                        }
                        else if(key == "errorPasswordBlank")
                        {
                            passwordBlankError = val;
                            jQuery("#sweepsLoginPasswordBlank").html(passwordBlankError);
                        }
                        else if(key == "errorLoginFailed")
                        {
                            loginFailedError = val;
                            jQuery("#sweepsLoginFailed").html(loginFailedError);
                        }
                     }
                 }
                 else
                 {
                    jQuery("#logInDiv").hide  ();
                    jQuery("#signUp").hide  ();
                    jQuery("#myProfile").show  ();
                    loggedIn = true;

                    if(carouselMgr != null)
                    {
                       doCallout(carouselMgr.getNormalizedPaneName());
                    }
                    
                    jQuery("#sweepsLoginFormContent").hide ();
                    jQuery("#sweepsLoginIntro").hide ();
                    
                    jQuery("#sweepsStep1Intro").hide();
                    // adjust the height since we're not displaying the login fields
                    jQuery("#sweepsFormContent").css('height',420);
                    jQuery("#sweepsLoggedInStep1Intro").show ();                    
                    
                    jQuery("#profileContinueBtn").show();
                    jQuery("#registerContinueBtn").hide();
                    jQuery("#profileFinishBtn").show();
                    jQuery("#registerFinishBtn").hide();

                    sweepsProfile('sweepsRegisterProfileMainContainer','sweepsForm');
                 }
             }
        );
}

/* 
  This function displays the COPPA overlay if the user tried
  to register and they were too young
*/
function sweepsTooYoung()
{
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
   }
   else
   {
      contentPanesLeft = 240;
   }
   
   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 172 left of the contentPanes
   var left = contentPanesLeft + 172;
   
   // set the top position 565 above the footer (545 for the ageTooYoung div height + 20 spacing)
   var top = footerTop - 565;
   
   // now position the overlay using the left and top variables
   jQuery("#sweepsAgeTooYoungContainer").css('left',left);
   jQuery("#sweepsAgeTooYoungContainer").css('top',top);
   
   jQuery("#sweepsRegisterProfileMainContainer").fadeOut("slow");  
   jQuery("#sweepsAgeTooYoungContainer").fadeIn("slow");
   clearForm('sweepsForm'); 
}

function sweepsAlreadyEntered()
{
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
   }
   else
   {
      contentPanesLeft = 240;
   }
   
   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 172 left of the contentPanes
   var left = contentPanesLeft + 172;
   
   // set the top position 565 above the footer (545 for the ageTooYoung div height + 20 spacing)
   var top = footerTop - 565;
   
   // now position the overlay using the left and top variables
   jQuery("#sweepsAlreadyRegisteredContainer").css('left',left);
   jQuery("#sweepsAlreadyRegisteredContainer").css('top',top);
   
   jQuery("#sweepsRegisterProfileMainContainer").fadeOut("slow");  
   jQuery("#sweepsAlreadyRegisteredContainer").fadeIn("slow");
   clearForm('sweepsForm'); 
}