/**
* Preferred Stores
* Created By Jeff Gordillo
* March 4, 2009 
*/

var currSelectedDiv;

$(function($) {
	
    changeDesignated();
    showStoresReached();
});

function showStoresReached() {
    $("#btnMaxStoresReached").click(function() {
   
    var overlayObj = $("#div_RemoveStore");
    var posX = $(this).offset().left - 10;
    var posY = $(this).offset().top - 5;

    overlayObj.css({ top: posY, left: posX });
        overlayObj.show();
    });

    $('#div_RemoveStore .fright').click(function() {
    $('#div_RemoveStore').hide();
    });
}

function changeDesignated() {
    $(".radio").click(function() {
      if (!(currSelectedDiv)) { currSelectedDiv = $(".preferStore, .primary"); }

        var objDiv = $(this).parents("div:first");

        if (objDiv.hasClass("secondary")) {
            setPrimary(currSelectedDiv, false);
            setPrimary(objDiv, true);
        }
        else {
            setPrimary(currSelectedDiv, false);
            setPrimary(objDiv, true);
        }
    });
}

function setPrimary(thisObj, bPrimary) {
    if (bPrimary) {
        thisObj.removeClass('secondary');
        thisObj.addClass('primary');
        thisObj.find("span").html("Designated / Primary Preferred Store");
        currSelectedDiv = thisObj;
    }
    else {
        thisObj.removeClass('primary');
        thisObj.addClass('secondary');
        thisObj.find("span").html("Set as Primary Preferred Store");
    }

}