﻿
/*
MERCHANT_SITE_URL - This needs to be replaced with the url of the site the code is going on with out the www for example .mysite.com

Please note that if you want to hide more than one thing on any page you will need to duplicat the div tags and JS function for each iteam you will also need to change the div tag id and the id in the JS function as this can only be used once on each page.

example of this code work is setup here:
Images showing: http://www.rufusb.com/Workstuff/layers-test.htm
Hidding images:	http://www.rufusb.com/Workstuff/layers-test.htm?adnetwork=af

<!-- insert this code at the top of the page, you should notes that this has to be above any thing your hidding and should be in the template file so it is on every page on your site -->

<script type="text/javascript">
*/

var searchString = window.location.search.substring(1);
var Parameters = new Object();
var nameValuePairs = searchString.split(/&/);
var nameValuePair;
var name;
var value;

for (var i = 0; i < nameValuePairs.length; i++) {
    nameValuePair = nameValuePairs[i].split(/=/);

    name = nameValuePair[0];
    value = nameValuePair[1];

    name = name.toLowerCase();

    if (name == "adnetwork") {
        if (typeof (value) != "undefined") {
            value = value.toLowerCase();
            pathname = '/';
            myDomain = GetMyDomain();
            //pathname.substring(0,pathname.lastIndexOf('/')) +'/';
            // set expiry date to 1 days from now.
            var days = 1
            var largeExpDate = new Date();
            largeExpDate.setTime(largeExpDate.getTime() + (1 * 24 * 3600 * 1000));
            SetCookie(name, value, largeExpDate, pathname, myDomain);
        }
    }
}

//////////////////functions////////////////////////////////////////////////
function GetMyDomain() {

    //return ".bensonsforbeds.co.uk";
    var _ta = (document.domain).split(".");
    if (_ta.length > 1 && (_ta[0] == "www" || _ta[0] == "WWW")) {

        var psd = "";
        for(var i=1; i<_ta.length; i++)
        {
            psd +=  "." + _ta[i];
        }
        //alert(psd);
        return psd;
    }
    else {
        //alert(document.domain);
        return document.domain
    }
    //alert(window.location.hostname);
    //return '.voxdev.com';
}

function SetCookie(name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
            break;
    }
    return null;
}

function showHideLayer(layerid, v) {
    var thelayer = document.getElementById(layerid);
    if (thelayer != null && typeof (thelayer) != "undefined")
        thelayer.style.visibility = v;
    //thelayer.display = "none";
}

function showHideDisplay(layerid, v) {
    var thelayer = document.getElementById(layerid);
    if (thelayer != null && typeof (thelayer) != "undefined")
        thelayer.style.display = v;
    //thelayer.display = "none";
}

//////////////////functions////////////////////////////////////////////////

/*

<!-- End code for top of page -->

<!-- DIV tags these need to go round what ever you are trying to hide from affiliate traffic -->

<div id="afhide1"> thing your trying to hide goes here </div>
<!-- End div tag -->

<!-- JS function this needs to be placed diretly after the closing div tag -->

<SCRIPT LANGUAGE=javascript>
<!--
if (GetCookie ("adnetwork") == "af"){  
showHideLayer('afhide1','hidden');  
}  
//-->
</SCRIPT>

<!-- End JS function -->

*/

