$(function(){
	$('#preferred_stores .primary_radio').each(function(){
		$(this).click(function(){
			// Reset all of the primary selectors
			$('#preferred_stores .store_selector label').each(function(){
				$(this).html('Make Primary').removeClass('primary');
			});
			$(this).next().html('Primary Store').addClass('primary');
		});
	});
});

function adddefaultstore(StoreUnitnumber,storeId){
	$.ajax({
		url: 'PreferredStoresCmd',
		data: "storeUnitNumber=" + StoreUnitnumber + "&key=INSERT",
		success: function (res) {
			$("#modcontent").html(trim(res));
        }
	});
}

function addStore(storeId, userId) {
	$.ajax({
		url: 'StoreLocatorView1',
		data: 'storeId=' + storeId,
		success: function(res) {
			showScreen(trim(res));
        }
	});
}

	 function showScreen(data){
	if ($('#loginCurtain').length === 0) {
			// Create the curtain
			$('<div id="loginCurtain"></div>').appendTo('body').css({
				'position': 'absolute', 
				'zIndex': '2000',
				'top': '0', 
				'left': '0',
				'backgroundColor': '#000000',
				'opacity': '0.5',
				'display': 'none'
			});
			// Create the layer container
			$('<div id="loginLayer"></div>').appendTo('body').css({
				'position': 'absolute',
				'zIndex': '2001',
				'top': '0', 
				'left': '0',
				'display': 'none'
			});
			// Add the file content to the '#loginLayer'
			// $(data).appendTo('#loginLayer');
			 $('#loginLayer').append(data);
			// Close window button
			$('.closeWin').click(function(){
			$('#loginLayer, #loginCurtain').remove();
			});
			// Curtain click
		$('#loginCurtain')
			.click(function() {
				$('#loginLayer, #loginCurtain').remove();
			})
			.css({
				height: $(document).height(),
				width: $(document).width()
			})
			.show().bgiframe();
			
			$('#loginLayer').center().show();
		}
}

$.fn.center = function(){
    this.css("position", "absolute");
	var top = ($(window).height() - this.height()) / 2 + $(window).scrollTop();
	var left = ($(window).width() - this.width()) / 2 + $(window).scrollLeft();
	top = (top < 0) ? 0 : top;
	left = (left < 0) ? 0 : left;
    this.css("top", top + "px");
    this.css("left", left + "px");
    return this;
};
