﻿
$(document).ready(function() {

    $("a#aMainAd").click(function(e) {
        try {
            pageTracker._trackEvent('AdClick', 'MainAd');
        } catch (err) { }
    });

    $("a.ShareLink_Twitter").click(function(e) {
        OpenTwitterWindow(this);
        try {
            pageTracker._trackEvent('SocialShare', 'Twitter');
        } catch (err) { }
        e.preventDefault();
    });

    $("a.ShareLink_Facebook").click(function(e) {
        try {
            pageTracker._trackEvent('SocialShare', 'Facebook');
        } catch (err) { }
    });

    $("a.ShareLink_Email").click(function(e) {
        try {
            pageTracker._trackEvent('SocialShare', 'Email');
        } catch (err) { }
    });

});

function OpenTwitterWindow(obj) {
    
    url = $(obj).attr('share_url');
    message = $(obj).attr('message');

    // opening a blank window prior to the ajax call prevents popup blockers from shutting us down.
    myWindow = window.open('/U/loading.htm','twitter','width=820,height=620,menubar=no,toolbar=no,location=no,status=no',true);

    Web.Service1.GetTwitterLink(message, url,
            function(d) {
                lnk = d;
                myWindow.location.replace(lnk);
            },
            function() {
                lnk = 'http://twitter.com/home?status=I just scheduled my classes with UniversityTools.com!';
                myWindow.location.replace(lnk);
            }
        );
}

function ToggleSection(sectionID) {
    $("#AddButton_" + sectionID).attr('src', '/U/Images/loading-circleball.gif');

    Web.Service1.ToggleSection(sectionID, function(d) {
        if (d == "Added") {
            $("#AddButton_" + sectionID).attr('src', '/U/Images/Buttons/small-remove.png');
            try {
                pageTracker._trackEvent('SiteAction', 'SectionAdd');
            } catch (err) { }
        } else {
            $("#AddButton_" + sectionID).attr('src', '/U/Images/Buttons/small-add.png');
            try {
                pageTracker._trackEvent('SiteAction', 'SectionRemoved');
            } catch (err) { }
        }

    }, function() {
        $("#AddButton_" + sectionID).attr('src', '/U/Images/Buttons/small-add.png');
        alert('You must be logged in to use this feature -- it\'s free!');
    });
}
