﻿$(document).ready(function() {
    
    $("a[href*=View_Document.aspx],a[href*=View_Image.aspx]").each(function() {
        var ar = $(this).attr("href").toLowerCase().split("iddocument=");
        var id = ar[1];
        //call google traker api only if _gaq object exist in the page
        if (typeof (_gaq) == "object") {
            $(this).bind('click', function() {
                $.ajax({
                    dataType: 'text',
                    type: "POST",
                    url: "/GetDownloadDocumentName.ashx",
                    data: "IdDocument=" + id,
                    success: function(msg) {
                        //call google traker api
                        try {
                            _gaq.push(['_trackPageview', '/downloads/' + msg]);
                        }
                        catch (err) {
                        }
                    },
                    error: function(req) {
                        //alert('si è verificato un errore');
                    }
                });
            });
        }
    })
})
