///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// JavaScript code to handle surveys.  Routines include
//
// rpop - Pops up the survey teaser if certain cookie
//       and random rate criteria are met.
//
// getRandom - Generates a random number between 1 and
//       a max number (popup rate).
//
// isCookie - Returns true if the specified cookie name
//       is present, false if it is not.
//
// getCookie - Returns the value for the specified
//       cookie name (null if it doesn't exist).
//
// setCookie - Sets the specified cookie with the
//       specified value.
//
// openSurvey - Pops up the survey in a new window.
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////


///////////////////////////////////////////////////////
// SET TO ZERO WHEN GOING TO PRODUCTION!!!
///////////////////////////////////////////////////////
var TESTING = 0;
///////////////////////////////////////////////////////


///////////////////////////////////////////////////////
// Popup window definitions
//
var PopupWidth   = 380;
var PopupHeight  = 500;
var PopupLeft    = 150;
var PopupTop     = 20;
var PopupScroll  = "no";

// Close popup window after X milliseconds
//   60 = 1 minute
//  120 = 2 minutes
var PopupTimeout = 120 * 1000;



///////////////////////////////////////////////////////
// Name of the cookie used to show the user has seen
// the survey teaser.  If you wish to show a new
// survey to people who have seen a previous survey,
// simply change this cookie name to something new.
//
// Record old cookie names here so we don't have
// conflicts.
//
// PAST COOKIE NAMES:
//   SiteSurvey2002
//
var SurveyCookie = "SiteSurvey2002";

///////////////////////////////////////////////////////
// Popup IDs for the eight sections - regular ID is
// for unregistered users and ID+1 is for registered
// users.
//
var hp_id    = 0;
var fac_id   = 2;
var meo_id   = 4;
var chs_id   = 6;
var ced_id   = 8;
var youth_id = 10;
var abp_id   = 12;
var prom_id  = 14;
var doo_id   = 16;
var doolo_id = 18;
var pe_id    = 20;
var deb_id   = 22;
var hol03_id = 24;
var fac2_id  = 26;
var aoc_id   = 28;

///////////////////////////////////////////////////////
// Popup rates for the eight sections - popup rate for
// a section is the array index of the section ID.
//
//  UnRegID, RegID,
//
var rates = new Array( 500,    5,
                        45,    1,
                        45,    2,
                        33,    1,
                         3,    1,
                        20,    2,
                         2,    2,
                        25,    2,
                        30,   30,
                        30,   30,
                        30,   30,
                       100,    2,
                       180,    2,
                         3,    3,
                        18,    2);

///////////////////////////////////////////////////////
// RECORD CHANGES IN THE POPUP RATES HERE:
// 2002-05-21: Initial rates set
//             90,2,50,2,45,2,10,2,10,2,2,2,2,2,25,2
// 2002-06-17: Change request from Michael Carlon
//             1000,2,1000,2,45,2,100,2,10,2,2,25,2,25,2
// 2002-12-06: Added two new ids, doo_id and doolo_id
//             as requested by Michael Carlon
// 2003-01-02: Changed hp rate from 1000 to 10000 as
//             requested by Michael Carlon
// 2003-01-03: Changed doo and doolo rates from 2 to
//             1000 a srequested by Michael Carlon
// 2003-11-03: Changed home page rate to 100 for registered.
//             Added priceless edge (pe_id) survey.
// 2003-03-27: Added debit promotion (deb_id).
// 2003-04-09: Modified the rates as follows:
//             - home page   from (10000, 100) to (1000, 10)
//             - fac         from (1000, 2)    to (150, 2)
//             - abp         from (25, 2)      to (8, 2)
//             - DOO         from (1000, 1000) to (50, 50)
//             - DOO with LO from (1000, 1000) to (50, 50)
// 2003-05-02: Modified the rates as follows:
//             - fac         from (150, 2)     to (10, 2)
//             - abp         from (8, 2)       to (3, 2)
// 2003-05-02: Add summer 2003 promo (sum03_id) with rates (63:2)
// 2003-09-19: Modify fac rates from (10, 2) to (120, 2)
// 2003-09-24: Added fac2_id with rates (120,2) for
//             new custom fac survey. Launches 09-30.
// 2003-10-02: Adjusted fac2_id rate from (120, 2) to (30, 2)
//             per Sharon's request. Launches 10-03.
// 2003-10-07: Adjusted fac2_id rate from (30, 2) to (10, 10)
//             per Sharon's request. Launches 10-08.
// 2003-10-10: Adjusted youth_id survey from (2, 2) to (20, 2)
//             and altered URLs from 220261studentA/B to
//             220261youth for both. Launches 10-14.
// 2003-10-15: Adjusted fac2_id rate from (10, 10) to (3, 3)
//             per Sharon's request. Launches 10-16.
// 2003-10-21: Altered youth_id survey URLs per BO request.
//             Launches 10-22.
// 2003-10-24: Replaced summer 03 with holiday 03 survey
// 2003-12-02: Modified the rates as follows:
//             - fac         from (120, 2)    to (90, 2)
//             - abp         from (3, 2)      to (2, 2)
//             - doo_id      from (50, 50)    to (30, 30)
//             - doolo_id    from (50, 50)    to (30, 30)
// 2003-12-24: Added survey id and links for About Our Cards
//             Rates are (18,2). Launches 1/1/04
// 2004-01-28: Updated links for Priceless Experience promotion.   
// 2004-01-29: Updated links for Priceless Experience promotion
//             (Uses a new ratio and shares only one link)
// 2004-02-23: Updated rates (approved for impl. on 3/3/04):
//             - hp_id  from (1000, 10) to (500, 5)
//             - fac_id from (90, 2)    to (45, 1)
//             - chs_id from (100, 2)   to (33, 1)
//             - ced_id from (10, 2)    to (3, 1)
//             - pe_id  from (90, 90)   to (30, 30) 
//
///////////////////////////////////////////////////////


///////////////////////////////////////////////////////
// Survey URLs for the eight sections
//
//  UnRegURL,
//    RegURL,
//
var urls = new Array(
   'www.acrobat-results.com/220261homeA',
      'www.acrobat-results.com/220261homeB',
   'www.acrobat-results.com/220261findA',
      'www.acrobat-results.com/220261findB',
   'www.acrobat-results.com/220261meoA',
      'www.acrobat-results.com/220261meoB',
   'www.acrobat-results.com/220261servicesA',
      'www.acrobat-results.com/220261servicesB',
   'www.acrobat-results.com/220261educA',
      'www.acrobat-results.com/220261educB',
   'www.acrobat-results.com/220261studentA',
      'www.acrobat-results.com/220261studentB',
   'www.acrobat-results.com/220261newA',
      'www.acrobat-results.com/220261newB',
   'www.acrobat-results.com/220261promoA',
      'www.acrobat-results.com/220261promoB',
   'www.acrobat-results.com/220261meoB',
      'www.acrobat-results.com/220261meoB',
   'www.acrobat-results.com/220261meoA',
      'www.acrobat-results.com/220261meoA',
   'www.acrobat-results.com/220261expA',
      'www.acrobat-results.com/220261expA',
   'www.acrobat-results.com/220261debitA',
      'www.acrobat-results.com/220261debitB',
   'www.acrobat-results.com/220261catA',
      'www.acrobat-results.com/220261catB',
   'www.acrobat-results.com/231010',
      'www.acrobat-results.com/231010',
   'www.acrobat-results.com/220261aocA',
      'www.acrobat-results.com/220261aocB'
);


///////////////////////////////////////////////////////
// Determine if the user is "registered".
//
var RegUser = 0;
var MCVal = getCookie("mc_visitor_id");
if (MCVal.indexOf("R") == 0)
   RegUser = 1;




///////////////////////////////////////////////////////
// Generate random nubmer between 1 and frequency
//
function getRandom(rate) {
   return Math.floor(Math.random() * rate + 1);
}


///////////////////////////////////////////////////////
// Determine if the specified cookie is set.  If it is
// the user has already seen the survey.
//
function isCookie(name) {
   if (getCookie(name))
      return true;
   else
      return false;
}


///////////////////////////////////////////////////////
// Return the value of the for the provided cookie
// name.
//
function getCookie(cookie_name) {
   var dc     = document.cookie;
   var cname  = cookie_name + "=";
   var clen   = dc.length;
   var cbegin = 0;

   while (cbegin < clen) {
      var vbegin = cbegin + cname.length;

      if (dc.substring(cbegin, vbegin) == cname) {
         var vend = dc.indexOf (";", vbegin);
         if (vend == -1) vend = clen;

         return unescape(dc.substring(vbegin, vend));
      }

      cbegin = dc.indexOf(" ", cbegin) + 1;

      if (cbegin== 0) break;
   }

   return "";
}


///////////////////////////////////////////////////////
// Set the cookie to show that the user has seen the
// survey.
//
function setCookie(name, value) {
   // the cookie will  expire after 1 year
   var date    = new Date();
       date    = new Date(date.getTime() + 1000*60*60*24*365);
 
   document.cookie = name + '=' + escape(value) + ';expires=' + date.toGMTString() + ';path=/';

   return true;
}


///////////////////////////////////////////////////////
// Popup the survey teaser.
//
function rpop(id) {
   var prate = getRandom(rates[id+RegUser]);

   if (((prate == 1) && (!isCookie(SurveyCookie)) || TESTING)) {
      setCookie(SurveyCookie, 1);
      window.open('/cgi-bin/site_survey.cgi?survey='+id+'&rate='+rates[id+RegUser]+'&mcreg='+RegUser, 'SurveyPopup', 'width='+PopupWidth+',height='+PopupHeight+',scrollbars='+PopupScroll+',left='+PopupLeft+',top='+PopupTop+',menubar=no,location=no,status=no,toolbar=no,resizable=no');
   }

   return true;
}

// custom find a card survey popup wrapper
function survey_popup(pWidth, pHeight, pScroll, pResize, pName, pURL) {
   // first, popup the survey
   // rpop(fac2_id); -- removed 10/31/03
   // then, popup the regular bank window (popup function will focus the window)
   popup(pWidth,pHeight,pScroll,pResize,pName,pURL);
}

///////////////////////////////////////////////////////
// Popup the survey.
//
function openSurvey(id) {
   window.open("/cgi-bin/indirect/Survey"+id+"_"+RegUser+"_"+rates[id+RegUser]+"/"+urls[id+RegUser], 'Survey', 'width=590,height=430,scrollbars=yes');
}
