/* Script to remove ClickBank hoplink from URL and put it in a cookie
/* Author: Ned Storm
/* Version: 1
/* 6th October 2009
/* http://aweconsulting.co.uk
/*
/* this script should be included in the head section of a web page as follows:
<script type="text/javascript" language="JavaScript" src="hotlink.js"></script>
/*
/* The hop value is stored in qsVals.hop
/*
/* Code to add to a web form:
<script type="text/javascript" language="JavaScript">
document.write('<input type="hidden" name="hop" value="' + qsVals.hop + '"/>');
</script>
/*
/* Licence: Creative Commons Attribution-Share Alike 3.0
/* http://creativecommons.org/licenses/by-sa/3.0/us/
*/
// Change this value to your hoplink
var defaultHop = "YOURHOP";
var qsVals = new Array();
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsVals[key] = val;
}
}
// check for hop value
if (qsVals.hop != null) {
// Set cookie to remember the hop value
if (document.cookie.search(/hop=/) < 0) { // No cookie yet
var theDate = new Date();
var oneYearLater = new Date( theDate.getTime() + 31536000000 );
var expiryDate = oneYearLater.toGMTString();
document.cookie = 'hop=' + qsVals.hop + ';expires='+ expiryDate;
}
// If the cookie was successfully set, redirect the page to remove the hoplink from the url
var url = "" + window.location;
if (document.cookie.search(/hop=/) >= 0) top.location.href = url.split("?")[0];
} else qsVals.hop = defaultHop;
// Look for cookie
if (document.cookie.search(/hop=/) >= 0) {
var cookies = "" + document.cookie;
var hop = cookies.match(/hop=([a-z0-9]+);?/i);
if (hop != null) qsVals.hop = hop[1];
}