var CPA={customizeWidget:function(title,bonus,url,instructions){html='<div class="infotext">You are now leaving myYearbook.com to customize the <b>'+title+'</b> widget.</div>';if(instructions){html+='<h3>To get the L$'+bonus+' bonus, you\'ll have to:</h3>';html+='<ol>';for(i=0;i<instructions.length;i++){html+='<li>'+instructions[i]+'</li>'}html+='</ol>'}html+='<button id="cpaGoBtn" data-url="'+url+'">OK, Let\'s Go &gt;&gt;</button>';html+='<div class="subtext">If you change your mind and don\'t want to grab this widget, just close the window and you\'ll be back on myYearbook.com.';$('<div id="CPA_content" />').appendTo('body').dragonDrop({type:'window',title:'Customize Widget',content:html,enableMinMax:false,width:300,left:430,top:175,callbackClose:function(e){$('#cpaPromo').removeClass('cpaLoading')}});$('#CPA_content #cpaGoBtn').unbind('click').bind('click',function(){window.open($(this).attr('data-url'));CPA.RefreshOffer('cpaNext');$('#CPA_content').slayDragon()})},RefreshOffer:function(dir){$('#cpaPromo').addClass('cpaLoading');var idx=$('#cpaActions').attr('data-offer-index');var dir=2*(dir!='cpaPrev')-1;var page='unknown';if(window.location.pathname=='/apps/owned/browse'||window.location.pathname=='/apps/owned/browse/'){page='Owned'}else if(window.location.pathname=='/apps/home/'||window.location.pathname=='/apps/home'){page='HALCPA'}if(typeof window.BASE_URL=='undefined'){window.BASE_URL='/apps/'}$.ajax({url:SITE_URL+'apps/cpa/ajax?callback=?',dataType:'jsonp',type:'get',data:{"index":idx,"dir":dir,page:page},success:function(data){$('#cpaPromo').removeClass('cpaLoading').html(data.markup);CPA.Init()}})},Init:function(){$('#cpaNext,#cpaPrev').unbind('click').bind('click',function(){CPA.RefreshOffer($(this).attr('id'))});$('a.cpaWidgetComet').unbind('click').bind('click',function(e){e.preventDefault();e.stopPropagation();var url=$(this).attr('data-widget-url');$('#cpaPromo').addClass('cpaLoading');$.ajax({url:url,type:'GET',dataType:'script',cache:true,success:function(){if("cpaResult"in window){if(window.cpaResult.added){alert("The widget has been added to your profile!");location.href=SITE_URL+'?mysession=cmVnaXN0cmF0aW9uX3Byb2ZpbGU='}CPA.RefreshOffer('cpaNext')}}})});function cpaFeedbackPopup(){CPA.Feedback.create()};$('#howDoesItWorkLink').click(function(){$('#yourLunchMoneyDiv').hide();$('#lmGet').show();return false});$('#howDoesItWorkX').click(function(){$('#lmGet').hide();$('#yourLunchMoneyDiv').show();return false});$('#cpaPromo .instructionPopupLink a').click(function(){if($('#cpaPromo #cpaInstructionPopup').is(':visible')){$('#cpaPromo #cpaInstructionPopup').hide();$(this).html('Info').get(0).blur()}else{$('#cpaPromo #cpaInstructionPopup').show();$(this).html('Close').get(0).blur()}return false})}};CPA.Feedback={create:function(){if($('#myPopup').length<1){$('<div id="myPopup" />').appendTo('body').dragonDrop({type:'window',title:'Missing L$?',content:CPA.Feedback.getContents(),enableMinMax:false,width:300,left:430,curtain:true})}return false},remove:function(){$('.CPAFeedback_content').parents('.dragon').slayDragon();return false},getContents:function(){var html='<div class="CPAFeedback_content">Loading...</div>';if(typeof window.BASE_URL=='undefined'){window.BASE_URL='/apps/'}$.ajax({url:window.BASE_URL+'cpa/ajax/feedback',dataType:'json',type:'get',success:function(data){$('.CPAFeedback_content').html(data.markup);$('#cpaFeedbackSubmit').bind('click',CPA.Feedback.submit)}});return $(html)},submit:function(e){var data={offer:$('#cpaFeedbackOffer').val(),feedback:$('#cpaFeedbackInput textarea').val()};if(data.offer!='vipPayPal-paypal'&&data.offer!='vipPayPal-credit'&&data.offer!='vipZong'){data.offer=parseInt(data.offer)}if($('#cpaFeedbackOffer option').size()>0&&isNaN(data.offer)&&data.offer!='vipPayPal-paypal'&&data.offer!='vipPayPal-credit'&&data.offer!='vipZong'){alert('You didn\'t select the offer that you\'re missing Lunch Money from!  Please select an offer first.');return false}$(this).attr('disabled','disabled').text(' Sending . . . ');if(typeof window.BASE_URL=='undefined'){window.BASE_URL='/apps/'}$.ajax({url:window.BASE_URL+'cpa/ajax/feedback',dataType:'json',type:'post',data:data,success:function(data){$('.CPAFeedback_content').html('<div id="cpaNoOffers">Thank you for your report.  You will receive a message to your myYearbook Inbox when your complaint has been handled.<div style="text-align:center;"><button id="cpaMissingPopClose"> Close </button></div></div>');$('#cpaMissingPopClose').click(CPA.Feedback.remove)}});return false}};$(document).ready(CPA.Init);