﻿
function AddHours(myDate, hours) {
    return new Date(myDate.getTime() + hours * 60 * 60 * 1000);
}


$(function () {


    var pageCounter = 0;
    pageCounter = $.cookie('TePapaPageCounter');

    if (pageCounter == null) {
        pageCounter = 1;
        $.cookie('TePapaPageCounter', pageCounter + '', { path: '/', expires: AddHours(new Date(), 1) });
    }
    else {
        pageCounter = parseInt(pageCounter);

        if (pageCounter > 0) {
            pageCounter = pageCounter + 1;

            if (pageCounter < 4)
                $.cookie('TePapaPageCounter', pageCounter + '', { path: '/', expires: AddHours(new Date(), 1) });

            if (pageCounter == 3) {
                $('#outercontainer').append('<br style="clear:both;" />');

                //popup
                $.fx.speeds._default = 1000;
                var $dialog = $('<div id="pop">stuff</div>')
		    .html('<p>Help us improve our website by answering a short survey and be in to win a $200 voucher!</p>')
		    .dialog({
		        autoOpen: false,
		        title: 'Online Survey',
		        hide: 'drop',
		        modal: true,
		        width: 550,
		        buttons: {
		            "Remind me later": function () {
		                $(this).dialog('close');
		            },
		            "No I'm not interested": function () {
		                $.cookie('TePapaPageCounter', '-2', { path: '/', expires: AddHours(new Date(), 24 * 365) });
		                $(this).dialog('close');
		            },
		            "Complete the online survey": function () {
		                $.cookie('TePapaPageCounter', '-1', { path: '/', expires: AddHours(new Date(), 24 * 365) });
		                //window.location = 'http://www.surveymonkey.com/s/CQQ9598';
						window.open('http://www.surveymonkey.com/s/CQQ9598');		                
		                $(this).dialog('close');
		            }
		        }
		    });

                $dialog.dialog('open');
                
				window.scrollTo(0,0);                

                //remove line above buttons
                $('.ui-dialog-buttonpane').css('border-width', '0 0 0');
            }
        }

    }


});

