
var expDate=new Date();
expDate.setTime(expDate.getTime() + 1000*3600*24*356); //1 year

//In order for .js files to be parsable by webserver, add .js to the following variable in cofig file as so:
//AddHandler server-parsed .shtml .js
var remoteAddr='38.107.191.98';
var remoteHost='(none)';
var httpHost='www.sats.net';

function getCookieByName(name) {
  var props=document.cookie.split("; "); // split cookie into properties
  for(var i=0; i<props.length; i++) {
    var name_value=props[i].split("=");  // split each property into name/value pair
    if(name_value.length == 2 && name_value[0] == name && name_value[1].indexOf("!--") == -1)
      return unescape(name_value[1]);
  }
  return null;
}


function setCookie(name, value) {
  if(value != null && value !="") 
    document.cookie=name+"="+escape(value)+"; path=/; expires="+expDate.toGMTString();   
}



function getNewPCID() {
  var today=new Date();
  var pcid="pc."+remoteAddr+"."+today.getTime();//to ensure different ids for users with the same ip
  return pcid;
}


function printPCInfoString() {
  var pcid=getCookieByName("pcid") || getNewPCID();
  setCookie("pcid",pcid); //refresh expiration date if the cookie already exists or set new cookie if it doesn't

  var pcInfoStr="pcid="+pcid; //record pcid
  pcInfoStr=pcInfoStr+"&ip="+remoteAddr; //record ip address

  //if(remoteHost != null && remoteHost != "\(none\)") { //record hostname
  //  pcInfoStr=pcInfoStr+"&hostname="+remoteHost;
  //}
 
  if(document.referrer != null && document.referrer != "") {
    var ourAddress="http://"+httpHost.toLowerCase();
    var index=document.referrer.toLowerCase().indexOf(ourAddress);  // user was previously on this site
    //alert(ourAddress+" "+index);
    if(index == -1) //if user didn't come from our website, record referrer
      pcInfoStr=pcInfoStr+"&referrer="+document.referrer;
  }

  //alert(pcInfoStr);
  document.write(pcInfoStr);
}
