function xcPopUp(el) {
 	$(el).unbind('click').click(function(e){
			// Remove any previous instances of the layer
		$('#tempWrap, #tempContent').remove();
			// This is the layer wrap
		var templayer = '<div id="tempWrap" class="layerWrap"></div>' + '<div id="tempContent" class="layerContent">' + '<p class="layerBody"></p>' + '</div>';
			$('body').append(templayer);
			// Load in the dynamic page for the popup
			$('#tempContent p.layerBody').load('MyGoferAffiliate', null, function(){
				// Set the wrapper height
			$('.layerWrap').css('height',  $('.layerContent').height() + 10);
				// Show the layer
			$('#tempWrap').show().css({
				top: e.pageY,
				left: e.pageX - 310
			});
			$('#tempContent').show().css({
				top: e.pageY + 5,
				left: e.pageX - 305
			});
				$('a.closeWin').click(function(){
				$('#tempWrap, #tempContent').remove();
				});
			});
		});
}

$(function() {
//dashboard preffered stores			
$("#dashboard .pod #preferred_stores_content .preferred_stores_box:last-child").addClass('last');
//dashboard gofer affiliation popup
	xcPopUp('#goferCheck');

/*affiliations*/
$("#affiliations .affiliation_box:nth-child(5)").addClass('clearleft');
 
/*opens and closes the motto*/
    $("div.mottotext").click(function(){
	$("#motto div.expanded").slideToggle("fast");
	}); /*expands the left nav*/
    $("div.menu_universal_profile div > h3 span.openclose").click(function(){
                    $(this.parentNode).toggleClass("open");
                    $(this.parentNode.parentNode).children("ul:eq(0)").slideToggle("fast");
                    $(this.parentNode.parentNode).children("span.displayAll").toggle();
		if ($(this.parentNode.parentNode).children("ul:eq(0)").children().length <= 10) {
			$(this.parentNode.parentNode).children("span.displayAll").hide();
		}
                    return false;
 	 });			 
 
/* open orders table removes the last right white border from the header row*/
 $("table.order_center_table td:last-child").css("border-right", "0"); 
	$("table.order_center_table th:last-child").css("border-right", "0"); /* open orders table removes the last row bottom border*/

	/* calendar styles*/
 $("table#month td:first-child").css("border-left", "#ffffff"); 
	$("a.printPage").click(function() {
		window.print();
	});
 
/*styles the previous and next tabs*/

$("#tabs_wrapper ul.profile_tabs li:first-child").css("border-left", "0");

	//account info
	$('a.changePass').toggle(function() {
		$(this).addClass('open');
		$('#standardButtons').hide();
		$('.section.password').show();
	}, function() {
		$(this).removeClass('open');
		$('#standardButtons').show();
		$('.section.password').hide();
    });
	
	//Preferred Sotres Selection for the P.S. page in Profile...
	$('div.preferStore input[type="radio"]').click(function(){
		var gp = $(this).parent().parent();  //grandparent

		if($('span.Designated').text()=="Set Designated Store as Primary Preferred Store"){	
			gp.parent().find('span').text('Select as My Primary Preferred Store');
			$('span.Designated').text('Designated/Primary Preferred Store');			
			gp.parent().find('div.preferStore').removeClass('primary').addClass('secondary');
			gp.removeClass('secondary').addClass('primary');
		}
		if($(this).parent().find('span').text()=="Select as My Primary Preferred Store"){
			gp.parent().find('div.preferStore').removeClass('primary').addClass('secondary');

			gp.removeClass('secondary').addClass('primary');
			gp.parent().find('span').text('Select as My Primary Preferred Store');
				$(this).parent().find('span').text('Primary Preferred Store');					
				$('span.Designated').text('Set Designated Store as Primary Preferred Store');
		}
	});

	$('a.modStores').click(function(e){
		var offset = $(this).offset(),
			newE = {
				pageX: offset.left - 50,
				pageY: offset.top - 75
			},
			settings = {
				filename: dynamicPopupPath2,
				contentname: '#delStorePop',
				jsonFlag: false,
				dynamicContent: true,
				windowWidth: '220px',
				windowHeight: 'auto'
			};
			
		dynpop.ini(newE, settings);
	});
});

function removeStore(removedStoreUnitnumber,isPrimary){
	$("#removedStoreUnitNumber").val(removedStoreUnitnumber);
	$("#isPrimaryStore").val(isPrimary);
	$("#key").val('DELETE');
	
	$("#PreferredStoresForm").submit();
}
		
function changePrimaryStore(newPrimaryStoreId) {
	$.ajax({
		url: 'PreferredStoresCmd',
		data: 'key=UPDATE&newPrimaryStoreId=' + newPrimaryStoreId,
		success: function(res) {
			//nothing
		        }
	});
}

function savePickupInfo(){	
	var pickUpAddressId = $("#autoRefill").val(),
		address_Id = pickUpAddressId,
		location = "", deskDeliveryId,
		deliveryType = "DeliveryPickup";

	if(pickUpAddressId !="noSelection"){
	    if(pickUpAddressId=="Desk Delivery"){
			deskDeliveryId = $("#deskDeliveryId").val();
		    address_Id = deskDeliveryId;
			location = $("#deskLocation").val();
			if (trim(location) == '') {
				$("#expressResult").html("Desk location field is empty.Please enter a valid value for desk location.");
		    	return false;
		    }
		    deliveryType = "DeskDelivery";
	    }
	    if(pickUpAddressId=="Home Delivery"){
			address_Id = $("#homeAddressId").val();
	    	deliveryType = "HomeDelivery";
	    }
	 }
	 else{
		address_Id = pickUpAddressId;
	 	deliveryType = pickUpAddressId;
	 }
	
	$.ajax({
		url: 'MyInfoUpdate',
		data: "storeId=10152&catalogId=10108&preferred=Y&URL=LogonStatusView&address_Id=" + address_Id + "&deliveryType=" + deliveryType + "&location=" + location,
		success: function(res) {
			$("#expressResult").html(trim(res));

			if ($("#successEC").val() == "true") {
				$("#expressResult").html("Express checkout settings have been saved.");
}
			else {
				$("#expressResult").html("Error occured while saving express checkout settings.");
	}
	return true;
}
	});

	return false;
}

function trackClickAction(obj, linkType) {
    if(omnitureEnabled == true){
    var s=s_gi(omAcct);
    s.linkTrackVars='prop12';
    s.prop12=linkType;
    s.tl(obj, 'o', linkType);
}
}
function trackClickAction(obj, prop12, linkType) { 
if(omnitureEnabled == true){
var s=s_gi(omAcct);
s.linkTrackVars='prop12,prop10,channel,prop1,prop2,prop3,prop27,prop28'; 
s.prop12=prop12; 
s.tl(obj, 'o', linkType); 
}
}

