/***********************************************************/
var cartID;

function initializepage() {
//Look for CartID in cookie first
var cookies=document.cookie;
cartID = getcartid("cartid", cookies, ";");
//If cookies aren't enabled, first determine if customer is coming from an external site.  If so, a new
//CartID must be generated for them.  If they are changing pages within site, simply get the
//CartID from the URL
if (cartID==null) {
if ((document.referrer.substring (0, 26).toLowerCase() !== "http://apollofunctions.com") || 
(document.referrer.substring (0, 27).toLowerCase() !== "https://apollofunctions.com")  || 
(document.referrer.substring (0, 30).toLowerCase() !== "http://www.apollofunctions.com")  || 
(document.referrer.substring (0, 31).toLowerCase() !== "https://www.apollofunctions.com")) {
cartID=randomnum();
}
else {
var URLcartid = new String(document.URL);
cartID=getcartid("cartid", URLcartid, "&");
}
}
//Append CartID to all links on the current page, regardless of whether cookies are enabled or not
setlinks(cartID);
}

function randomnum() {
var TodaysDate=new Date();
var rn = Math.floor(16000*Math.random()+1)+"-"+TodaysDate.getHours()+TodaysDate.getMinutes()+TodaysDate.getSeconds();
return rn;
}

function setlinks(v) {
for (var i = 0; i < document.links.length; i++) {
if (((document.links[i].href.indexOf("://dev6.hbngroup.org") !== -1) || (document.links[i].href.indexOf("://www.apollofunctions.com") !== -1) || (document.links[i].href.indexOf("://apollofunctions.com")) !== -1) && (document.links[i].href.indexOf("#top") == -1))
{
//Use the search property of the link object to append the CartID
document.links[i].href += "&CartID=" + v
}
}
}

function getcartid(name, inputstring, trunc) {
//Simply parses out CartID from either the cookie or URL passed to function
inputstring = inputstring + trunc;
inputstring = inputstring.toLowerCase();
var start=inputstring.indexOf(name + "=");
if (start>-1) {
start=inputstring.indexOf("=", start)+1
}
var end = inputstring.indexOf(trunc, start);
if (start==-1 || end==-1) {
value=null
}
else {
var value=unescape(inputstring.substring(start,end))
}
return value;
}
/***********************************************************/
