$(document).ready(function() {
    // DISABLE DRAG
    document.body.ondragstart = function() { return false; };
    document.body.onselectstart = function() { return false; };
    if (window.ie || window.opera) { document.body.setProperty("unselectable", "on"); }
    if (window.gecko) { document.body.setStyle("MozUserSelect", "none"); }
    if (window.webkit) { document.body.setStyle("KhtmlUserSelect", "none"); }
    
    // DISABLE RIGHT CLICK
    $(document).bind("contextmenu", function(e) {
        return false;
    });

    // ||| B // LOCATIONS EVENT HANDLER |||
    $("div.header-locations select").change(function() {
        var targetURL = $("div.header-locations select").val();
        window.location.href = targetURL;
    });

    // ||| B // EXIT MODAL |||
    $('a.external').click(function(e) {
        var location = $(this).attr('href');
        e.preventDefault();

        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        confirm(function() {
            //window.location.href = location;
            window.open(location);
        });
    });

});

function confirm(callback) {
    $("<div id=\"exit-modal\">\
            <a href=\"javascript:;\" class=\"close\"><img src=\"http://staging.scratchdev.com/www.cnbwax.com/_images/misc/icon_modal-close.png\" alt=\"Close Window\" class=\"close\"></a>\
		    <h1>Confirm</h1>\
		    <div class=\"hr\">&nbsp;</div>\
		    <p>You are leaving the CNB of Texas website.</p>\
		    <p><a href=\"javascript:;\" class=\"yes blue\">Continue</a>&nbsp;&nbsp;or&nbsp;&nbsp;<a href=\"javascript:;\" class=\"no red\">Cancel</a></p>\
	     </div>").modal({
            close: false,
            closeClass: "close",
            containerId: 'simplemodal-exit-container',

	         onShow: function(dialog) {
	             // if the user clicks "Continue"
	             dialog.data.find('.yes').click(function() {
	                 // call the callback
	                 if ($.isFunction(callback)) {
	                     callback.apply();
	                 }
	                 // close the dialog
	                 $.modal.close();
	             });
	             // if the user clicks "Cancel"
	             dialog.data.find('.no').click(function() {
	             // close the dialog
	             $.modal.close();
	            });
	         }
	     });
	 }