﻿$(document).ready(function () {
    $('a').filter(function () {
        if ($(this).hasClass('fbPost')) {
            return true;
        }


        return this.hostname && this.hostname !== location.hostname;
    })
    .click(function () {
        if (!$(this).hasClass('fbPost')) {
	        var stringSplit = this.hostname.split(".");
	        var mcdHost = stringSplit[stringSplit.length - 2].toLowerCase();

	        if ((mcdHost != "plcontent") && (mcdHost != "mcdonalds") && (mcdHost != "iwonatmcd") && ($(this).attr('class') != "rmd_link")) {
	            showColorbox("300", "external-popup");
	            $('#leave').attr('href', $(this).attr('href'));
	            return false;
	        }
	    }
	    else {
	        showColorbox("300", "facebook-popup");
	        $('#leave').css('cursor', 'pointer');
	        return false;
	    }
	});
});


function external(e) {
    var targetUrl = $(this).attr("href");
    $("#confirmExitDialog").dialog({
        buttons: {
            "Confirm": function () { window.open(targetUrl, 'external', ''); $(this).dialog("close"); },
            "Cancel": function () { $(this).dialog("close"); }
        }});
    $("#confirmExitDialog").dialog("open");

    e.preventDefault();
    return false;
}

$(function () {
    $('.external').live('click', external);
//    $("#confirmExitDialog").dialog({
//        autoOpen: false,
//        modal: true
//    });
});

$(function () {
    //Dialog for "Where can I get more codes?"
    $("#bonusTrackerInfoDialog").dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            "Close": function () { $(this).dialog("close"); }
        }
    });
    $('#bonusTrackerInfoLink').click(function (e) {
        $("#bonusTrackerInfoDialog").dialog("open");
        e.preventDefault();
        return false;
    });
});

