Wed Dec 27 2017
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
_satellite.pushAsyncScript(function(event, target, $variables){
  
$(function(){


	// *****************************************************
	// ON-PAGE OFFER CONTROLS
	// *****************************************************

	// decide if you want to have bonus months included in monthly price division
	var we_want_to_change_monthly_divisor = true;

	function run_offer(offer_type){

		if(offer_type){
			init_on_page_offers();

			// add best value tab to preferred subscription
			add_best_value('24');

			// add offer to preferred subscription(s) - options include tutoring, bonus_months_low, bonus_months_high
			add_offer('12', offer_type);
			add_offer('24', offer_type);
		}
	}
	// run_offer('tutoring');


	var offer_for_page = {

		// tests
		// 'pumpkinpieafi': 'tutoring',
		// 'bluegloveafi': 'bonus_months_high',
		// 'em3payadi': 'bonus_months_low',
		

		// black friday
		'embf12saleadi': 'tutoring',
		'embf24saleadi': 'tutoring',
		'embf50saleadi': 'tutoring',
		'embf40saleadi': 'tutoring',
		'embf9pmsaleadi': 'tutoring',
		'embf7pmsaleadi': 'tutoring',
		'embf1299saleadi': 'tutoring',



		// cyber monday
		'cmtdealadi': 'tutoring',
		'cmt1299dealadi': 'tutoring',
		'cmtmonthdealadi': 'tutoring',
		'cmt6dealadi': 'tutoring',
		'cmt3dealadi': 'tutoring',
		'cmt1dealadi': 'tutoring',
		'cmt3pdealadi': 'tutoring',
		'emcms40dealadi': 'tutoring',
		'emcms50dealadi': 'tutoring',

		'cmsdealadi': 'bonus_months_high',
		'cmsmonthdealadi': 'bonus_months_high',
		'cms1299dealadi': 'bonus_months_high',
		'cmsmonth127dealadi': 'bonus_months_high',
		'cms6dealadi': 'bonus_months_high',
		'cms3dealadi': 'bonus_months_high',
		'cms1dealadi': 'bonus_months_high',
		'cms3pdealadi': 'bonus_months_high',
		'cms245dealadi': 'bonus_months_high',

		'cms246deal': 'bonus_months_low',
    'cmsdealbadi': 'bonus_months_low',
		'cms1299dealbadi': 'bonus_months_low',
		'cms246dealadi': 'bonus_months_low',
		'emcms246dealadi': 'bonus_months_low',
		'cms128dealadi': 'bonus_months_low',


		// cyber monday extended
    'cmetmonthdeal': 'tutoring',
		'cmetdealadi': 'tutoring',
		'cmet1299dealadi': 'tutoring',
		'cmet3dealadi': 'tutoring',
		'cmet3pdealadi': 'tutoring',
		'emcmes40dealadi': 'tutoring',
		'emcmes50dealadi': 'tutoring',
		'cmetmonthdealadi': 'tutoring',
		'cmet6dealadi': 'tutoring',
		'cmet1dealadi': 'tutoring',
		'emcmetdealadi': 'tutoring',
		'emcme9pmsaleadi': 'tutoring',
		'emcme7pmsaleadi': 'tutoring',

		'cmesmonthdealadi': 'bonus_months_high',
		'cmesmonth127dealadi': 'bonus_months_high',
		'cmes3dealadi': 'bonus_months_high',
		'cmess3pdealadi': 'bonus_months_high',
		'cmesdealadi': 'bonus_months_high',
		'cmes1299dealadi': 'bonus_months_high',
		'cmes6dealadi': 'bonus_months_high',
		'cmes1dealadi': 'bonus_months_high',
		'cmes3pdealadi': 'bonus_months_high',
		'cmes245dealadi': 'bonus_months_high',

		'cmes128dealadi': 'bonus_months_low',
    'cmes246dealadi': 'bonus_months_low',
		'cmes1299dealbadi': 'bonus_months_low',
		'emcmes246dealadi': 'bonus_months_low',
		'cmesdealbadi': 'bonus_months_low',
    
    // Flash sale dec
    'emholidayflash50adi': 'bonus_months_low',
    'emholidaysanta50adi': 'bonus_months_low',
    'emholidaytech2tsadi': 'tutoring',
    'emholidayflash6adi': 'bonus_months_low',
    
    'yellow7tsadi': 'tutoring',
    'emholidaysanta7tsadi' : 'tutoring',
    'holidaysanta7tsadi': 'tutoring',
    'sitewide': 'tutoring',
    'rmsitewide': 'tutoring',
    'sale': 'tutoring',
    'social': 'tutoring',

	};









	// *****************************************************
	// RUN OFFER IF AVAILABLE FOR CURRENT RSI
	// *****************************************************

	var rsi = RSI && RSI.rsi;

	if(/sitewide|rmsitewide|social|ppc\/sale/i.test(window.location.pathname)){
		rsi = RSI && RSI.header && RSI.header.mastheadImage.split('.')[0]; // use this variable instead of rsi name to avoid tripping up sitewide, rmsitewide, and ppc/sale
	}
	if(offer_for_page[rsi]){
		run_offer(offer_for_page[rsi]);
	}








	// *****************************************************
	// USE THIS TO RUN OFFERS ON A SCHEDULE - note this is NOT in use because the masthead match is better (see above)
	// *****************************************************
	/*function get_offer_from_schedule(){

		var schedule = [
			// test for now
			{ start:'Nov 16, 2017 00:00', end:'Nov 17, 2017 23:59', offer:'tutoring'},
			// Black Friday: no offers for sitewide, rmsitewide, ppc/sale
			// { start:'Nov 22, 2017 20:00', end:'Nov 26, 2017 11:59', offer:'tutoring'},
			// Cyber Monday
			{ start:'Nov 26, 2017 12:00', end:'Nov 27, 2017 23:59', offer:'bonus_months_low'},
			// Cyber Tuesday
			{ start:'Nov 28, 2017 09:30', end:'Nov 29, 2017 09:29', offer:'tutoring'},
			// Cyber Wednesday
			{ start:'Nov 29, 2017 09:30', end:'Nov 30, 2017 09:29', offer:'bonus_months_low'},
			// Cyber Thursday
			{ start:'Nov 30, 2017 09:30', end:'Dec 1, 2017 09:29', offer:'tutoring'},
			// Cyber Friday
			{ start:'Dec 1, 2017 09:30', end:'Dec 1, 2017 09:29', offer:'bonus_months_low'},
			// Cyber Saturday
			{ start:'Dec 2, 2017 09:30', end:'Dec 3, 2017 09:29', offer:'tutoring'},
			// Cyber Sunday
			{ start:'Dec 3, 2017 09:30', end:'Dec 4, 2017 10:00', offer:'bonus_months_low'}
		];

		var now = Date.now();
		for(var i=0; i<schedule.length; i++){
			if( Date.parse(schedule[i].start)<=now && now<=Date.parse(schedule[i].end) ){
				return schedule[i].offer;
			}
		}
		return null;
	}*/










	// *****************************************************
	// ON-PAGE OFFER
	// *****************************************************
	function add_offer(lvl, offer_type){
		
		var offers = {
			'tutoring': {
				'12': {
					promo_code: 'tutor_1special',
					message: 'Includes 1 free live tutoring session'
				},
				'24': {
					promo_code: 'tutor_2special',
					message: 'Includes 2 free live tutoring sessions'
				}
			},
			'bonus_months_low': {
				'12': {
					sku: '91213', // 12 + 1 month
					message: 'Plus 1 bonus month'
				},
				'24': {
					sku: '91211', // 24 + 3 month
					message: 'Plus 3 bonus months'
				}
			},
			'bonus_months_high': {
				'12': {
					sku: '90496', // 12 + 3 month
					message: 'Plus 3 bonus months'
				},
				'24': {
					sku: '90497', // 24 + 6 month
					message: 'Plus 6 bonus months'
				}
			}
		}


		var promo_code = offers[offer_type][lvl].promo_code;
		var sku = offers[offer_type][lvl].sku;
		var offer_message = offers[offer_type][lvl].message;



		// desktop elements
		var $product_content = $('.js_oct_2016_price[data-lvl='+lvl+']').closest('.oct_2016_product_square_content');
		var $product_header = $product_content.find('.oct_2016_product_square_header');

		// mobile elements
		var $mobile_product = $('.js_radio_lvl_mobile[data-lvl='+lvl+']').closest('.mobile_product_label');


		// update product header style on desktop
		var product_header_style = ''
			+'padding-bottom: 0px;'
			+'margin-bottom: 20px;'
			+'position: relative;'
			+'background-color: #3E3E40;'
			+'color: #fff;'
			;
		$product_header.attr('style', product_header_style);


		// show offer on desktop
		var offer_style = ''
			+'background-color: gold;'
			+'background-image: linear-gradient(45deg, #F2C534, #FEDE3B);'
			+'box-shadow: 0px 0px 3px 0px rgba(33,33,33,0.5);'
			+'font-family: gothammedium, gothambook, sans-serif;'
			+'color: #333;'
			+'line-height: 1;'
			+'padding: 10px;'
			+'position: relative;'
			+'top: 20px;'
			+'margin-bottom: -5px;'
			;
		$product_header.append('<div class="on_page_offer" style="'+offer_style+'">'+offer_message+'</div>');


		// show offer on mobile
		var offer_style_mobile = ''
			+'background-color: #01A13A;'
			+'font-family: gothammedium, gothambook, sans-serif;'
			+'color: #fff;'
			+'line-height: 1;'
			+'padding: 10px;'
			+'font-size: 14px;'
			+'text-transform: uppercase;'
			+'max-width: 370px;'
			+'margin: auto;'
			+'box-sizing: border-box;'
			+'border-bottom-left-radius: 5px;'
			+'border-bottom-right-radius: 5px;'
			+'box-shadow: 0px 5px 8px -3px rgba(33,33,33,0.5);'
			;
		var offer_html_mobile = '<div class="on_page_offer_mobile" style="'+offer_style_mobile+'">'+offer_message+'</div>';
		var $mobile_target_elem = _isPricingMonthly ? $mobile_product.next('.monthly_mobilebottom') : $mobile_product;
		$(offer_html_mobile).insertAfter($mobile_target_elem);

		$mobile_product.css({
			'border-radius': 'unset',
			'border-top-right-radius': '5px'
		});
		if(_isPricingMonthly){
			$mobile_product.next('.monthly_mobilebottom').css({
				'border-radius': 'unset',
				'box-shadow': '0px 0px 5px 0px rgba(33,33,33,0.4)'
			});
		}

		// fix mobile product style if best value tab is absent
		var is_best_value_absent = !$mobile_product.prev('.best_value_mobile_container').length;
		if(is_best_value_absent){
			$mobile_product.css({
				'border-top-left-radius': '5px'
			});
		}



		// add offer data to cart url
		$('.js_oct_2016_addtocart[data-lvl='+lvl+']').attr('href', function(){
			var url = this.href;
			return add_offer_to_url(url, promo_code, sku);
		});

		// make sure offer data stays in cart url whenever cart buttons update
		$(document).on('cart_update', function(){
			setTimeout(function(){
				$('.js_oct_2016_addtocart[data-lvl='+lvl+']').attr('href', function(){
					var url = this.href;
					return add_offer_to_url(url, promo_code, sku);
				});
			},0);
		});



		// monthly divisor updates for bonus month offers
		if( window._isPricingMonthly && we_want_to_change_monthly_divisor && /bonus_months/i.test(offer_type) ){

			// update relevant monthly prices on page load
			change_monthly_divisor(lvl, offer_type);

			// update relevant monthly prices on each price change
			$(document).on('price_update', function(){
				setTimeout(function(){
					change_monthly_divisor(lvl, offer_type);
				},0);
			});

			// add legal language if not already present
			if(!$('.divisor_legal_update').length){
				var message = 'The price per month displayed is the current promotional price divided by the selected subscription term, including bonus months.';
				$('<p class="divisor_legal_update">'+message+'</p>').insertBefore('.footer-links p:eq(3)');
				$('.footer-links p').css({'padding-bottom': '1em'});
				$('.footer-links p:last-of-type').css({'padding-top': '4em'});
			}

		}

	}








	// *****************************************************
	// UTILITIES
	// *****************************************************

	function add_offer_to_url(url, promo_code, sku){
		if(sku){
			url = url.replace(/\/sku\/\d+/i,'/sku/'+sku);
		}
		if(promo_code){
			var url_contains_promo = (new RegExp(promo_code, 'i')).test(url);
			if(!url_contains_promo){
				url = url.replace(/(pc=[^&]+)/i, '$1,'+promo_code);
			}
		}
		return url;
	}

	function init_on_page_offers(){
		window._isPricingMonthly = !!$('.monthly_mobilebottom').length;

		// remove previous best value callout on desktop and mobile
		$('.js_oct_2016_product .oct_2016_best_value, .labelcontain.topper').remove();

		// if monthly pricing layout is on, style mobile accordingly
		if(_isPricingMonthly){
			$('.mobile_product_label').css({
				'border-top-left-radius': '5px',
				'border-top-right-radius': '5px',
				'border-bottom-right-radius': 'unset',
				'border-bottom-left-radius': 'unset'
			});
		}
	}

	function change_monthly_divisor(lvl, offer_type){

		var divisor = {
			'bonus_months_low': {
				'12': 12+1,
				'24': 24+3
			},
			'bonus_months_high': {
				'12': 12+3,
				'24': 24+6
			}
		};

		var price_full = RSI({'lvl':lvl,'cat':'esp'})[0].price;
		var price_divided = (+price_full / divisor[offer_type][lvl]).toFixed(2).split('.');

		var price_int = price_divided[0];
		var price_decimal = price_divided[1];

		// update prices on desktop
		var price_html_desktop = price_int + '<div style="display: inline-block; font-size: 0.385em; vertical-align: top; text-align: left; margin-top: 0.3em; vertical-align: baseline; line-height: 1.2;"><p>.'+price_decimal+'</p><p>/Month</p></div>';
		$('.oct_2016_big_price_square.js_oct_2016_price[data-lvl='+lvl+']').html(price_html_desktop);

		// update prices on mobile
		$('.mobile_price.js_oct_2016_price[data-lvl='+lvl+']').html(price_int);
		$('.mobile_price.js_oct_2016_price[data-lvl='+lvl+'] + .productcents > p:first-of-type').html('.'+price_decimal);
	}









	// *****************************************************
	// BEST VALUE
	// *****************************************************
	function add_best_value(lvl){

		// desktop elements
		var $product_box = $('.js_oct_2016_price[data-lvl='+lvl+']').closest('.js_oct_2016_product');
		var $product_content = $('.js_oct_2016_price[data-lvl='+lvl+']').closest('.oct_2016_product_square_content');

		// mobile elements
		var $mobile_product = $('.js_radio_lvl_mobile[data-lvl='+lvl+']').closest('.mobile_product_label');

		// show best value on desktop
		var best_value_style_desktop = ''
			+'background-color: #00A139;'
			+'color: #fff;';
		var desktop_best_value_html = '<div class="oct_2016_best_value" style="'+best_value_style_desktop+'">Best Value</div>';
		$product_content.prepend(desktop_best_value_html);

		// show best value on mobile
		var best_value_style_mobile = ''
			+'line-height: 1;'
			+'display: inline-block;'
			+'padding: 7px 14px;'
			+'border-top-right-radius: 6px;'
			+'border-top-left-radius: 6px;'
			+'background-color: gold;'
			+'background-image: linear-gradient(45deg, #F2C534, #FEDE3B);'
			+'box-shadow: 0px 0px 3px 0px rgba(33,33,33,0.5);'
			+'font-size: 14px;'
			+'color: #333;'
			+'text-transform: uppercase;'
			+'font-family: gothambold, gothammedium, gothambook, sans-serif;'
			;

		var product_style_mobile = ''
			+'position: relative;'
			+'margin-top: 0px;'
			+'border-top-left-radius: 0px;'
			+'box-shadow: 0px 0px 5px 0px rgba(33,33,33,0.4);'
			;
		if(_isPricingMonthly){
			product_style_mobile += ''
				+'border-radius: unset;'
				+'border-top-right-radius: 5px;'
				;
		}

		var mobile_best_value_html = ''
			+'<div class="best_value_mobile_container" style="margin:10px auto 0px; max-width:370px; text-align:left;">'
				+'<div class="best_value_mobile" style="'+best_value_style_mobile+'">Best Value</div>'
			+'</div>';
		$(mobile_best_value_html).insertBefore($mobile_product);

		$mobile_product.attr('style', product_style_mobile);
	}





});
});