var srcurl;
$(document).ready(function()
{
    $("a.extern").click(function()
    {
        srcurl = $(this).attr('href');
        //mywindow = window.open('/Home/Redirect', '_blank');

        if (srcurl.indexOf("www.intmedpress.com/osteoporosis-online") != -1)
        {
            $(".btn_forward").attr('href', '');

            $.ajax({
                url: '/Account/GetUserIdToken',
                type: 'GET',
                dataType: 'json',
                success: function(data)
                {
                    $("#userId").val(data.userId);
                    $("#token").val(data.token);
                    $(".btn_forward").attr('href', 'javascript:SubmitIMPForm()');
                }
            });
        }
        else
        {
            $(".btn_forward").attr('href', srcurl);
            $(".btn_forward").attr('target', "_blank");
        }


        $.fn.colorbox({ opacity: 0.50, inline: true, href: "#DvRedirect", scrolling: false, close: false });
        return false;
    });

    /* colorbox */
    $(".signIn").colorbox({ innerWidth: 400, innerHeight: 240, iframe: true, opacity: 0.50, scrolling: false });
    $(".NavSignIn").colorbox({ innerWidth: 400, innerHeight: 240, iframe: true, opacity: 0.50, scrolling: false });    
    $(".forgottenPassword").colorbox({ innerWidth: 400, innerHeight: 240, iframe: true, opacity: 0.50, scrolling: false });

    

});


function SubmitIMPForm()
{
    document.frmOsteoporosisOnline.submit();
}

$(document).ready(function()
{
    $("a.extern2").click(function()
    {
        srcurl = $(this).attr('href');
        //mywindow = window.open('/Home/Redirect', '_blank');
        

        $(".btn_forward").attr('href', srcurl);

        $.fn.colorbox({ opacity: 0.50, inline: true, href: "#DvRedirectAlt", scrolling: false, close: false });
        return false;
    });

    /* colorbox */
    $(".signIn").colorbox({ innerWidth: 400, innerHeight: 220, iframe: true, opacity: 0.50, scrolling: false });
    $(".forgottenPassword").colorbox({ innerWidth: 400, innerHeight: 225, iframe: true, opacity: 0.50, scrolling: false });

});

$(document).ready(function() {

    $('form.rating').click(function() {
        var f = $(this);
        var action = f.attr("action");
        var serializedForm = f.serialize();
        $.post(action, serializedForm,
            function() {
            });
        return false;
    });

});

function CloseColorBox() {
    $.fn.colorbox.close();
}


function valRegistrationForm() {

    var toReturn = true;

    if ($("#Pwd").val() != "") {
        $("#Password").val(hex_md5($("#Pwd").val()));
    }
    else {
        $("#Password").val("");
    }


    if ($("#ConfPassword").val() != "") {
        $("#Password2").val(hex_md5($("#ConfPassword").val()));
    }
    else {
        $("#Password2").val("");
    }
    
    $("#pwdCount").val($("#Pwd").val().length);
        

    $("#Pwd").val("");
    $("#ConfPassword").val("");

    return toReturn;
}

function OpenWindow(url) {
    window.open(url, 'BAPopUp', 'width=800,height=600,scrollbars=yes,resizable=yes');
}

//following scroll function from http://css-tricks.com/snippets/jquery/smooth-scrolling/
$(function()
{
    $('a[href*=#]').click(function()
    {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
        && location.hostname == this.hostname)
        {
            var $target = $(this.hash);

            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');

            if ($target.length)
            {

                var targetOffset = $target.offset().top;

                $('html,body').animate({ scrollTop: targetOffset }, 1000);

                return false;
            }
        }
    });
});
