function WinOpen(url,x,y){
    var options = "toolbar=no,scrollbars=yes,resizable=yes,width=" + x + ",height=" + y;
    msgWindow=window.open(url,"WinOpen",options);
}

function WinOpenPlus(url,w,h,name){
    var options = "toolbar=no,scrollbars=yes,resizable=yes,width=" + w + ",height=" + h;
    msgWindow=window.open(url,name,options);
    msgWindow.focus();
}

// for Cash Back Terms & Conditions popup
function popDetails(cbmerch)
{
    window.open('/cashback/cb_details.php?cbmerch=' + cbmerch,'cb_details','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=516,height=250,left=490,top=362');
}

function getCookieValue(name)
{
    var crumbs = document.cookie.split(";");
    var value = '';
    for (var i=0; i<crumbs.length; i++) {
        crumbs[i] = crumbs[i].trim();
        if (crumbs[i].substr(0, crumbs[i].indexOf("=")) == name) {
            value = crumbs[i].substr(crumbs[i].indexOf("=") + 1);
            break;
        }
    }

    return value;
}

function lockoutTime(uniqueId, duration)
{
    var id = 'lockout_' + uniqueId;

    if (!window._lockouts)
        window._lockouts = {};

    if (window._lockouts[id])
        return true;

    window._lockouts[id] = true;

    setTimeout(
        function() {
            window._lockouts[id] = false;
        }, duration
    );

    return false;
}

// for unique url logging
(function()
{
    var value = '';
    var key = '#article=';
    var hash = document.location.hash;

    if(key == hash.substring(0, key.length))
    {
        value = hash.substring(key.length)
        $.get('/query/track_unique_url.php', {id:value, referer:document.referrer});
    }
})();

function fbLogin(refpage, nextpage)
{
    FB.login(
        function(response) {
            if (response.authResponse)
            {
                $.getJSON("/facebook/fb_login.php", { uid : response.authResponse.userID, access_token : response.authResponse.accessToken },
                    function(response){
                        if (response.facebook_login == 'success')
                        {
                            if (response.fatwallet_login == 'success')
                                next = refpage;
                            else
                                next = nextpage;
                            document.location = next;
                        }
                        else if (response.facebook_login == 'real_email_required')
                        {
                            alert('Sorry, you must provide your real email address for security reasons.');
                        }
                        else
                        {
                            alert('Failure logging into Facebook, please try again.');
                        }
                    });
            }
            else
            {
                alert('You must login with your Facebook account and agree to the permission request to use this feature.');
            }
        },
        { scope: 'email' }
    );
}

