﻿function DownloadSW()
{
    if(document.getElementById("terms").checked == true)
    {
        window.open("/similarweb/download/similarwebie.exe","popDown","width=1,height=1,top=0,left=0");
        document.location.href="/similarweb/download-IE.aspx";
        try{_gaq.push(['_trackPageview','/downloadsw/ie']);}catch(e){}
    }
    else
    {
        alert("Please agree to our Privacy Policy in order to download the SimilarWeb Extension Tool");
        return false;
    }
}    

function OnFFDownload()
{
  if(document.getElementById("terms").checked == true)
    {
        document.getElementById('download_overlay').style.display='block'; 
        document.getElementById('download_msg').style.display='block'; 
        HighlightStep();
        
       try{_gaq.push(['_trackPageview','/downloadsw/ff']);}catch(e){}
    }
    else
    {
        alert("Please agree to our Privacy Policy in order to download the SimilarWeb Extension Tool");
        return false;
    }
}

function OnCHDownload()
{
  if(document.getElementById("terms").checked == true)
    {
      try{_gaq.push(['_trackPageview','/downloadsw/ch']);}catch(e){}
    }
    else
    {
        alert("Please agree to our Privacy Policy in order to download the SimilarWeb Extension Tool");
        return false;
    }
}

function OnSFDownload()
{
  if(document.getElementById("terms").checked == true)
    {
      try{_gaq.push(['_trackPageview','/downloadsw/sf']);}catch(e){}
    }
    else
    {
        alert("Please agree to our Privacy Policy in order to download the SimilarWeb Extension Tool");
        return false;
    }
}

function OnOpDownload()
{
  if(document.getElementById("terms").checked == true)
    {
      try{_gaq.push(['_trackPageview','/downloadsw/op']);}catch(e){}
    }
    else
    {
        alert("Please agree to our Privacy Policy in order to download the SimilarWeb Extension Tool");
        return false;
    }
}

function CloseDownloadMsg()
{
    document.getElementById('download_overlay').style.display='none'; 
    document.getElementById('download_msg').style.display='none'; 
    return false;
}

var nextStep = 'step1';

function HighlightStep()
{
    if (nextStep != '')
    {
        document.getElementById(nextStep).style.color='white';
        
        if (nextStep == 'step1')
        {
            document.getElementById('step3').style.color=''; 
            nextStep = 'step2';
        }
        else if (nextStep == 'step2')
        {
            document.getElementById('step1').style.color=''; 
            nextStep = 'step3';
        }
        else
        {
            document.getElementById('step2').style.color='';
            nextStep = 'step1';
        }
        
        setTimeout("HighlightStep()", 2000);
    }
}

function getParam(paramName){
    try {
        // get the current URL
        var url = window.location.toString();
        //get the parameters
        url.match(/\?(.+)$/);
        var params = RegExp.$1;
        // split up the query string and store in an
        // associative array
        var params = params.split("&");
        var queryStringList = {};
        
        for (var i = 0; i < params.length; i++) {
            var tmp = params[i].split("=");
            queryStringList[tmp[0]] = tmp[1];
        }
        
        // print all querystring in key value pairs
        for (var i in queryStringList) {
            if (i == paramName) {
                return queryStringList[i];
            }
        }
    } 
    catch (e) {
    }
    
    return "";
}



function trackSimilarWeb(linkElement)
{
    var param = getParam("ref");
    
    if(param != "")
    {
        document.getElementById(linkElement).href = document.getElementById(linkElement).href + "_"  + param;
        return;
    }
    
    param = getParam("subid");
    
    if(param != "")
    {
        document.getElementById(linkElement).href = document.getElementById(linkElement).href + "_"  + param;
        return;
    }
}
