﻿//options for all popups used by window.open
var popup_options = 'scrollbars=0, status=0, location=0, resizable=1, ';
var field_popup_options = 'scrollbars=1, status=0, location=0, resizable=1, ';

function popup_contribution(id, full_post_back)
//Pop up to view edit or delete a current contribution
//id - id of contribution to open in a new window
//full_post_back - 1 causes parents update panel to update => used by the Repository.aspx
//                 0 causes the entire page to reload.
//                 This is used to remove deleted entries in real time.
{
    full_post_back = typeof (full_post_back) != 'undefined' ? full_post_back : 0;
    window.open('/Intranet/ModifyViewContribution.aspx?id=' + id + '&fpb=' + full_post_back, '_blank', popup_options+'width=350px, height=450px');
}

function popup_contribution_event(start_date, end_date) {
    window.open('/Intranet/ModifyViewContribution.aspx?insert_type=1&fpb=1&date1=' + start_date + '&date2=' + end_date, '_blank', popup_options + 'width=350px, height=450px');
}

function popup_new_contribution(type_id)
//Pop up for creation of new contribution
//id - id of contribution to open in a new window
{
    window.open('/Intranet/ModifyViewContribution.aspx?insert_type=' + type_id + '&fpb=1', '_blank', popup_options + 'width=350px, height=450px');
}


function popup_field_financial_report(city, financial_or_field, city_gsip_showcase)
//city - string name of city
//financial_or_field - string; either 'financial' for financial reporting or 'field for field reporting
{
    window.open('CityReport_' + financial_or_field + '.aspx?'+city_gsip_showcase+'=' + city, financial_or_field + '_popup_window', field_popup_options + 'width=500px, height=475px').focus();
}

/*
function popup_field_financial_report(city, financial_or_field)
//city - string name of city
//financial_or_field - string; either 'financial' for financial reporting or 'field for field reporting
{

    popup_field_financial_report(city, financial_or_field, 'city');
}*/


function popup_field_entry() {
    window.open('/Intranet/TigerTeamFieldReporting.aspx', 'narrativePopUp', field_popup_options + 'width=610px, height=400px').focus();
}

function popup_financial_entry() {
    window.open('/Intranet/TigerTeamFinancialReporting.aspx', 'financialPopUp', field_popup_options + 'width=675px, height=400px').focus();
}


function ProtectEmailLinks() {

    //HTML anchors with 'username' and 'domain' attributes will have their functionality provided by javascript to
    //conceal email address from spam or other malicious code bots.

    $('a[username][domain]').click(
function(e) {
    e.preventDefault();
    window.location = 'mailto:' + $(this).attr('username') + '@' + $(this).attr('domain');
});



    $('a[username][domain]').hover(function() {
        window.status = 'mailto:' + $(this).attr('username') + '@' + $(this).attr('domain');
    },
function() {
    window.status = '';
});

}

function alternate_view_create_rollover() {
    $('.alternate_view').click(function() { document.location = $(this).attr('href'); });
    $('.alternate_view').hover(function() {
        $(this).children('.aleternate_view_cap_right').addClass('aleternate_view_cap_right_alt');
        $(this).children('.aleternate_view_cap_left').addClass('aleternate_view_cap_left_alt');
        $(this).children(".alternate_view_link").addClass('alternate_view_link_alt');
    }, function() {
        $(this).children('.aleternate_view_cap_right').removeClass('aleternate_view_cap_right_alt');
        $(this).children('.aleternate_view_cap_left').removeClass('aleternate_view_cap_left_alt');
        $(this).children(".alternate_view_link").removeClass('alternate_view_link_alt');
     });

}


$(document).ready(function() {
    ProtectEmailLinks();
    alternate_view_create_rollover();
});



var login_original_height;
//Show Rules of Use for Intranet from login box
function show_use_rules() {

    $("#loginbox").stop(true);
    $("#login_primary_functionality").stop(true);
    $("#login_green_bar").stop(true);

    login_original_height = $("#login_primary_functionality").height();
    $("#login_primary_functionality").animate({
        opacity: 0
    }, 1500,
            function() {

                $("#loginbox").animate({
                    width: "300px",
                    left: "694px",
                    height: "300px"
                }, 1500);
                $("#login_green_bar").animate({
                    left: "208px"
                }, 1500, function() {
                    $("#login_primary_functionality").css('display', 'none');

                    $("#login_rules").fadeIn(2000);
                });

            });

}
//Hide Rules of Use for Intranet from login box.
function hide_use_rules() {

    $("#loginbox").stop(true);
    $("#login_primary_functionality").stop(true);
    $("#login_green_bar").stop(true);

    $("#login_rules").fadeOut(2000,
            function() {
                $("#login_primary_functionality").css('display', 'block');

                $("#loginbox").animate({
                    width: "194px",
                    left: "800px",
                    height: login_original_height + 'px'
                }, 1500);

                $("#login_green_bar").animate({
                    left: "102px"
                }, 1500,
                function() {
                    $("#loginbox").css('height', 'auto');
                    $("#login_primary_functionality").animate({ opacity: 1 }, 1500);
                });
            });
        }



        //Hide Rules of Use for Intranet from login box.
        function get_time_offset() {
            var d = new Date();
            
                $.ajax({
                    async: false,
                    type: "POST",
                    url: "/Home.aspx/registerTimeOffset",
                    data: "{'offset':'" + (-d.getTimezoneOffset() / 60) + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                      // alert('REGISTERED');
                    },
                    error: function(msg) {
                        alert('Time offset error.');
                    }
                });
                return true;
       }