var favoriteListCommand = '/user/add_item_to_wishlist.cmd';
var registrationLayerCommand = new Array(8);
registrationLayerCommand[0] = '/includes/login_include_layer.jsp';
registrationLayerCommand[1] = '/user/registration_login_layer.cmd';
registrationLayerCommand[2] = '/checkout/add_items_uc.cmd';
registrationLayerCommand[3] = '/checkout/delete_item_in_list.cmd';
var currentContext = '';
var secureContext = 'https://www.hannaford.com';
var registrationLayerContainerId = "#widget-registration";
var registrationLayerCloseButClass = ".widget-close-but";
var hideTimeOuts= new Array();
var regLoadingHTML = '
';
var regSimpleHTML = '';
var postRegister = '/login';
function submitRegistrationLayer(container) {
var form = $(container);
var userName = ($("input[name=userName]", form).val());
var password = ($("input[name=password]", form).val());
var dest = ($("input[name=dest]", form).val());
dest = jQuery.trim(dest);
// if we have an empty dest passed in then let's set it to an empty string.
// the empty string says just reload.
if (dest == 'undefined') {
dest = '';
}
var params = "userName=" + userName + "&password=" + password;
//params = params + "&dest=" + dest;
var postURL = registrationLayerCommand[1];
$(registrationLayerContainerId + " #errorUserName").hide();
$(registrationLayerContainerId + " #errorPassword").hide();
$(registrationLayerContainerId + " #errorGeneral").hide();
$(registrationLayerContainerId + " #errorUserLocked").hide();
//console.log(postURL);
$.ajax({
type: "POST",
url: postURL,
data: params,
dataType: "json",
timeout: 15000,
complete: function() {
//hideRegLoading();
//location.reload(true);
},
success: function(data) {
//hideRegLoading();
//$(registrationLayerContainerId).append(data);
//$(registrationLayerContainerId).show();
//if (refreshPage != undefined && refreshPage) {
// setTimeout( function() { location.reload(true); }, refreshDelayTime != undefined? refreshDelayTime : 0);
if (data.usernameError.length > 0) {
$(registrationLayerContainerId + " #errorUserName").html(data.usernameError);
$(registrationLayerContainerId + " #errorUserName").show();
$(registrationLayerContainerId + " #errorGeneral").show();
}
if (data.passwordError.length > 0) {
$(registrationLayerContainerId + " #errorPassword").html(data.passwordError);
$(registrationLayerContainerId + " #errorPassword").show();
$(registrationLayerContainerId + " #errorGeneral").show();
}
if (data.userLockedError.length > 0) {
$(registrationLayerContainerId + " #errorUserLocked").html(data.userLockedError);
$(registrationLayerContainerId + " #errorUserLocked").show();
}
if (data.merge == 'true') {
hideRegLoading();
if (dest != null && dest != '') {
if (dest.indexOf("addToFavorites") > 0) {
var uriCurrent = new Uri(window.location);
var uriFavorite = new Uri(dest);
uriFavorite.replaceQueryParam("dest", encodeURIComponent(uriCurrent.toString()));
var uriMerge = uriCurrent.clone().setProtocol("https");
uriMerge.replaceQueryParam("merge", true);
if (data.keepLoggedIn != '') {
uriMerge.replaceQueryParam("keepLoggedIn", data.keepLoggedIn);
}
uriMerge.replaceQueryParam("dest", encodeURIComponent(uriFavorite.toString()));
utils.url.redirect(uriMerge.toString());
} else {
window.location.replace(dest);
}
} else {
window.location.reload();
}
}
// if the user is successfully logged in then go to the destination if it was set.
// else reload the page.
else if (data.success == 'true') {
hideRegLoading();
var params = dest.substring(dest.indexOf("?") + 1, dest.length);
if (dest != null && dest != '') {
//bganesan 01/14/10 - The dest variable may contain the command call to add items to favorites and the parameters.
//If the call is made from the search results or thumbnails or event details page (identified by addToFavorites variable), perform
//an ajax call to add the item to Favorites and display the confirmation message. Also the page should be reloaded since the user just signed in from the
//registration layer and will need to be shown as logged in, in the header.
if (dest.indexOf("addToFavorites") > 0) {
addToFavorites(params, 'true');
}
else {
window.location.replace(dest);
}
} else {
window.location.reload();
}
}
},
error: function() {
//hideRegLoading();
//return false;
}
});
}
function displayRegistrationLayer() {
// No destination on registration default will be to just reload it on submitRegistrationLayer
// Pass in an empty dest variable so that it doesn't get set.
var params = "dest=";
showRegistrationLayer('show',params, false, 0);
}
// using this when a user clicks register
function jumpToRegistrationPage(dest) {
var location = 'https://www.hannaford.com/user/login.jsp?dest=';
window.location = location + encodeURIComponent(dest);
}
function displayRegistrationLayer(dest) { // Has close button & background overlay
// set the destination param
var params = "dest=" + encodeURIComponent(dest);
showRegistrationLayer('closeshow',params, false, 0);
}
function displayRegistrationLayerNoClose(dest) { // No close button, no background overlay
// set the destination param
var params = "dest=" + encodeURIComponent(dest);
showRegistrationLayer('show',params, false, 0);
}
//bganesan 01/15/10 - Create a new function, to load the original page the user was on, when trying to add the item to favorites
//so that the location is loaded and the product is added to favorites.
function displayRegistrationLayer(dest,location) {
// set the destination param and the location.
var params = "dest=" + encodeURIComponent(dest) + "&location=" + encodeURIComponent(location);
showRegistrationLayer('closeshow',params, false, 0);
}
function displayRegistrationLayerThenReload() {
showRegistrationLayer('closeshow',params, true, 0);
}
/* Function(s) to Show the Registration Layer */
function showRegistrationLayer(action,params,refreshPage,refreshDelayTime) {
if( (action == "show") || (action == "showFromQuickview") || (action == "closeshow") ){
showRegistrationLayerLoading(regLoadingHTML); requestURL = registrationLayerCommand[0];
// Resize widget container which is shared by other layers
var $loginContainer = $('#widget-registration');
$loginContainer.css('width','490px').center().css('top','160px');
} else if(action == "addProduct")
{ showRegistrationLayerLoading(regSimpleHTML); requestURL = registrationLayerCommand[1];}
else if(action == "addEnsemble")
{ showRegistrationLayerLoading(regSimpleHTML); requestURL = registrationLayerCommand[2];}
else if(action == "remove")
{ showRegistrationLayerLoading(regLoadingHTML); requestURL = registrationLayerCommand[3];}
else if(action == "addVariety")
{ showRegistrationLayerLoading(regSimpleHTML); requestURL = registrationLayerCommand[1];}
else
{ alert("missing action"); }
requestURL = requestURL;
params = "ts=" + timestamp() + "&action=" + action + "&" + params;
$.ajax({
type: "POST",
url: requestURL,
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
hideRegLoading();
$(registrationLayerContainerId).append(data);
$(registrationLayerContainerId).show();
if (refreshPage != undefined && refreshPage) {
setTimeout( function() { location.reload(true); }, refreshDelayTime != undefined? refreshDelayTime : 0);
}
return true;
},
complete: function() {
if (action == 'closeshow') {
$('.colorBoxClose').show(); // was .widget-close-but, widget and colorbox layers share same html
if(!$('#cboxOverlay').length){
$('body').append('');
} else {
$('#cboxOverlay').show();
}
setTimeout(function(){
$(document).one("layerUtil_closed", function(){
hideReg();
});
/*
$('.colorBoxClose, #cboxOverlay').click(function() {
hideReg();
$('#cboxOverlay').hide();
});
*/
},10);
}
var labelTimer;
if (labelTimer != null){
clearTimeout(labelTimer);
labelTimer = null;
}
labelTimer = setTimeout(function(){
setFormLabels();
},500);
},
error: function() {
hideRegLoading();
return false;
}
});
};
function showRegistrationLayerLoading(htmlToShow) {
$(registrationLayerContainerId).remove();
//load, position, show new cart
$("body").append(htmlToShow);
positionRegistrationLayer();
$(registrationLayerContainerId).show();
};
function hideRegLoading() {
$(registrationLayerContainerId + " *").remove();
$(registrationLayerContainerId).html("");
};
//Center the positionRegistrationLayer
function positionRegistrationLayer() {
$(registrationLayerContainerId).center();
};
//Edit this function if need to do something special on basket close.
function hideReg() {
$(registrationLayerContainerId).hide();
$(registrationLayerContainerId).remove();
};