var WS_site = 56;

// YOU SHOULD NOT CHANGE ANYTHING BELOW HERE
////////////////////////////////////////////////////////////////

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

var WS_rand = Math.random();

var WS_ref = escape(document.referrer);
var WS_visid = getCookie("visid");
var WS_nvisid;
if(!WS_visid){
	// not set yet, so set
	//if(WS_nvisid > 0){
		// create an instance of the Date object
		var WS_inayear = new Date();
		// fix the bug in Navigator 2.0, Macintosh
		fixDate(WS_inayear);
		// cookie expires in one year (actually, 365 days)
		// 365 days in a year
		// 24 hours in a day
		// 60 minutes in an hour
		// 60 seconds in a minute
		// 1000 milliseconds in a second
		WS_nvisid = WS_inayear.getTime() + "_" + WS_rand; // time and rand
		WS_inayear.setTime(WS_inayear.getTime() + 30 * 24 * 60 * 60 * 1000); // only 30 days
		
		setCookie("visid", WS_nvisid, WS_inayear, "/");
		WS_visid = WS_nvisid;
	//}
}
var qstr = "&s=" + WS_site + "&ref=" + WS_ref + "&visid=" + WS_visid + "&charset=" + document.charset;
// ecomm variables
var orderid;
var total; 
var shipping = 0.0;
function arielSetShipping(x){
	shipping = x;
}
function arielSetTotal(x){
	total = x;
}
function arielSetOrderId(x){
	orderid = "" + x;
}
function ecommstats_setAction(x){
    qstr += "&action=" + x;
}
//document.write(qstr);
function statImage(){
	if(total){ // ecomm set
		qstr += "&total=" + total + "&shipping=" + shipping + "&orderid=" + orderid;
	}
	if(document.location.href.substring(0,5) == "https"){
		document.write("<a href=\"http://www.ecommstats.com/\"><img src=\"https://ariel1.spaceprogram.com/webstats/statimg.jsp?r=" + Math.random() + qstr + "\" border=\"0\" alt=\"Ecommstats\"></a>");
	}
	else document.write("<a href=\"http://www.ecommstats.com/\"><img src=\"http://ariel1.spaceprogram.com/webstats/statimg.jsp?r=" + Math.random() + qstr + "\" border=\"0\" alt=\"Ecommstats\"></a>");
}
