function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

/*
If a referrer cookie exists, don't do anything, otherwise
auto-load the current promo page.

This is to appease affiliates who disagree with our practice of
running strange things like 'promotions' and 'sales'!
*/

function redirnocookie(URL) {
	if (document.cookie.indexOf("referred")>-1) {
		return true;
	} else { 
		eval("window.location=URL;");
	};
}


/*
If a referrer cookie exists and they're a premium affiliate,
send them to the proper place
*/

if (document.cookie.indexOf("promo")>-1) {
	var whodoneit = getCookie("promo");
	if ( (whodoneit == "WHS") || (whodoneit == "WHC") || (whodoneit == "TOP10BWH") || (whodoneit == "WHS2") || (whodoneit == "WHC2") || (whodoneit == "TOP10BWH2") ) {
		eval("window.location='promo.html';");
	} else {
	};
}

/*
If a referrer cookie exists, forward them on, otherwise
don't do anything.
*/

function redircookie(URL) {
	if (document.cookie.indexOf("referred")>-1) {
		eval("window.location=URL;");
	} else { 
		return true;
		};
}

/*
If they don't have a referrer cookie, set one based on
the DOM value of document.referrer, then load URL.
This 'referrer' cookie is separate from our 'referred' cookie.
*/

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
";path=/;domain=dreamhost.com"+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function redirnoreferrercookie(URL) {
	if (document.cookie.indexOf("referrer")>-1) {
		return true;
	} else {
		setCookie("cookietest","ok",1); /* just one day! */
		if (document.cookie.indexOf("cookietest")>-1) {
			setCookie("referrer",document.referrer,1); /* just one day! */
			eval("window.location=URL;");
		} else {
		  return true;
		}
	};
}
