$(document).ready(function(){
	$("#modallogin_popup input").keypress(function (e) { e.stopPropagation() ; });
	$('.lpChatTextLinkText').find('span').css('font-size','11px');
});
function storePortlandCookie(){
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime()+ 60* 24 * 3600000);
	document.cookie="location=portland"+";expires="+expire.toGMTString();
}
function storeZipCodeInCookie(zipcode){
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*30);
	var url = '{$base_url}'.split("/");
	document.cookie = "zipCode" +"="+ zipcode + ";domain="+url[2]+";path=/;expires="+expire.toGMTString();
}
function storeLastCategory(selectedCategory, domain){
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*30);
	var url = domain.split("/");
	document.cookie = "LastCategory" +"="+ selectedCategory + ";domain="+url[2]+";path=/;expires="+expire.toGMTString();
}

var preventReloadAfterLogin = false;
var temporaryCartProductsCount = 0;
var temporaryCartSamplesCount = 0;	
var isLoggedIn = false ;
var isAddToWishListItems = false;
var isModalLoginWithCallback = false;
var selectedFormAction = '';
var registerCallbackFunction = '';

function checkLogin(callBack, isAddToWishlist, preventReload) {

    registerCallbackFunction = callBack;
    if (isAddToWishlist == true) {
        selectedFormAction = 'configWishList';
    } else {
        selectedFormAction = 'configCart';
    }
    if (preventReload == true) {
        preventReloadAfterLogin = preventReload;
    }
    //get temporary cart counts
    var data = {};
    $.ajax({
        url: ultraHome + "getCartWishlistCounts",
        type: 'POST',
        async: false,
        data: data,
        success: function(data) {
            data = eval('(' + data + ')');
            temporaryCartProductsCount = data.cart.productsCount;
            temporaryCartSamplesCount = data.cart.samplesCount;
            isLoggedIn = data.isLoggedIn;
        }
    });

    if (isLoggedIn) {
        eval(callBack);
        temporaryCartProductsCount = 0;
        temporaryCartSamplesCount = 0;

    } else {
	
        dojo.byId('loginCallbackFunction').value = callBack;
        $('#continueAsGuest').css("display", "none");
        $('#returnToPreviousPage').css("display", "none");
        if (isAddToWishlist != true) {
            isModalLoginWithCallback = true;
            $('#continueAsGuest').css("display", "block");
            $('#continueAsGuest').attr('href', 'javascript:hideOverlay();' + callBack);
        } else {
            isAddToWishListItems = true;
            isModalLoginWithCallback = false;
            $('#returnToPreviousPage').css("display", "block");
            $('#returnToPreviousPage').attr('href', 'javascript:hideOverlay();');
        }
        showModalLoginDialog();
    }
}