﻿$(document).ready(function(){
    // AdWords.
    if (StatisticsGetParameterByName("gclid") != "")
    {
        StatisticsLogClick("adwords");
        return;
    }    
    
    // Yahoo.
    if (StatisticsGetParameterByName("OVKEY") != "")
    {
        StatisticsLogClick("yahoo");
        return;
    }
});

function StatisticsLogClick(agency)
{
    var hostName = window.location.hostname.toLowerCase();
    var url = "http://statistics.volpet.com/Log.ashx?function=logclick&agency=" + agency + "&hostname=" + hostName; 
    StatisticsIssueGetRequest(url);
}

function StatisticsIssueGetRequest(url)
{
    $.get(StatisticsGetProxyPage() + "?proxy_url=" + encodeURIComponent(url));    
}

function StatisticsGetProxyPage(hostName)
{
    var hostName = window.location.hostname.toLowerCase();
    if(hostName.indexOf("www.volpet.") != -1)
    {
        return "/proxy.php"; 
    }
    return "/proxy.ashx";
}

function StatisticsGetParameterByName( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
    return "";
    else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}
