function in_array (needle, haystack, argStrict) {    
    var key = '', strict = !! argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    } 
    return false;
}

function getDomain(url) {
    var asd = url.match(/:\/\/(.[^/]+)/);
    if(asd && asd.length > 0)
        return asd[1];         
    else
        return '';
}

function setUpAutomaticFileTracking(types)
{   
    if (typeof _gaq != 'undefined') {
        $('a').filter(function(index) {
            if($(this).attr('href') === undefined )
            {
                //alert('undefined href file');
                return false;
            }
            
            var ext = $(this).attr('href').substr(-3);
            $(this).data('ext', ext);
            var dom = this.hostname;
            
            if(dom && dom!=window.location.hostname)
            {                
                return false;
            }
            
            return in_array(ext, types);
        }).click(function(){
            var ext = $(this).data('ext');
            var name = $(this).attr('href').substr(0, ($(this).attr('href').length-4));            
            //alert('TRACKING file link: '+'/'+ext+'/'+name);
            //pageTracker._trackPageview('/'+ext+'/'+name);
            try {_gaq.push(['_trackEvent', 'Downloads', $(this).attr('href')]);}
            catch(e){alert(e.message);}
            //return false;
        }).data('file_dl', 1);
    }       
   
    return true;
}

function setUpAutomaticMailToTracking()
{
    if (typeof _gaq != 'undefined') {        
        $('a[href^=mailto:]').click(function(){
            //alert('TRACKING mailto link: '+$(this).attr('href'));
            try { _gaq.push(['_trackEvent', 'Mailto Links', $(this).attr('href')]); }
            catch(e){alert(e.message);}
            //return false;
        });
    }
    
    return true;
}

function setUpAutomaticSiteTracking()
{
    if (typeof _gaq != 'undefined') {
        
        var domain = window.location.hostname;        
        
        $('a').each(function(){
            if($(this).attr('href') !== undefined )
            {
                if($(this).data('file_dl')!=1)
                {
                    var dom = this.hostname;
                    if( ($(this).attr('href').indexOf('http://')!==-1 || $(this).attr('href').indexOf('https://')!==-1) &&
                       domain != dom )
                    {
                        $(this).click(function(){
                            //alert('TRACKING outbound link: '+dom);
                            try { _gaq.push(['_trackEvent', 'Outbound Links', dom, $(this).attr('href')]); }
                            catch(e){alert(e.message);}
                            //return false;
                        });
                    }               
                }
            }
            else
            {
                //alert('undefined href site');
            }
        });    
    }
    
    return true;
}

