function CreateHipCookie()
{ // function creates cookie 'hip' in the form of hours_since_1_Jan_2004:ext_ip_address:int_ip_address

  // ALL times must be in GMT!
  var today = 'Wed Mar 10 03:08:08 GMT+0000 2010';
  // window.alert(today);
  var CookieText = 'hip=' + Math.floor((Date.parse(today) - Date.parse("Thu Jan 1 00:00:00 GMT+0000 2004"))/1000/60/60) + ':' + '38.107.191.118' + ':' + '(undefined)';

  // make it visible for the whole website
  CookieText = CookieText + "; path=/";

  // expiry time = 7 years
  var ExpiryDate = new Date();
  ExpiryDate.setTime(ExpiryDate.getTime() + 7*365*24*60*60*1000);
  CookieText = CookieText + "; expires=" + ExpiryDate.toGMTString();

  // check what we have
  // window.alert(CookieText);

  // set cookie
  document.cookie = CookieText;
}



function CreateInfoCookie()
{ // function creates cookie 'info' with some information about browser

  var currentdate = new Date();
  var CookieText = 'info=' + 
                   navigator.appName + '#' +
                   (navigator.javaEnabled()?'Java Enabled':'Java Disabled') + '#' +
                   screen.width + 'x' + screen.height + 'x' + 
                // if this is MSIE then use screen.colorDepth else use screen.pixelDepth
                   ((navigator.appName.substring(0,3) == 'Mic')?screen.colorDepth:screen.pixelDepth) + '#' + 
                   navigator.cpuClass              + '#' + 
                   navigator.systemLanguage        + '#' +
                   currentdate.getTimezoneOffset() + '#' +
                   document.referrer;

  // make it visible for the whole website
  CookieText = CookieText + "; path=/";

  // expiry time is not added, so it will exist for the current session only

  // check what we have
  // window.alert(CookieText);

  // set cookie
  document.cookie = CookieText;
}



function GetCookie(name)
{
  var cookieText=document.cookie;
  var cookieName=name + "=";
  var start=cookieText.indexOf(cookieName);

  if (start==-1) {return null;}

  var end=document.cookie.indexOf(";",start);
  if (end==-1) {end=cookieText.length;}

  return unescape(cookieText.substring(start+cookieName.length,end));
}



function DeleteCookie(name)
// Function deletes cookie with given name
{ if (GetCookie(name)) {document.cookie=name + "=; path=/; expires=0";}; }

function DeleteAllCookies()
// Function tries to delete all cookies
{ DeleteCookie("hip");
  DeleteCookie("info");
}



function CheckCookies()
// This function must be automatically called when an html document is loaded
// It is called at the end of this file
// Alternatively, you can use <body onLoad="CheckCookies();"> attribute,
// but this technique reqiures code to be amended in two places if you want to include tracking.js
{ // Two cookies are checked/created: hip and info

  // If hip cookie does not exist, delete all cookies, and create hip cookie
  // Note that old cookie hash will be deleted within the DeleteAllCookies() function
  if   ((GetCookie("hip")=="") || (GetCookie("hip")==null))
       {DeleteAllCookies(); // seems to be "brand new" client, so clean him from old rubbish :)
        CreateHipCookie();
        // if   ((GetCookie("hip")=="") || (GetCookie("hip")==null))
        //      {window.alert("unable to create hip cookie");}
        // else {window.alert("hip cookie has been created successfully");};
       }
  else { // window.alert("hip cookie already exists");
       };



  // If info cookie does not exist, create it
  if   ((GetCookie("info")=="") || (GetCookie("info")==null))
       {CreateInfoCookie();
       // if   ((GetCookie("info")=="") || (GetCookie("info")==null))
       //      {window.alert("unable to create info cookie");}
       // else {window.alert("info cookie has been created successfully");};
       };
  // else {window.alert("info cookie already exists"); };

}





// Finally, this is the entry point
// HTML page that links this file will automatically call the function below
// This function will be executed from the <HEADER> section of the HTML document

// Comment this call in tracking_mastercopy.js
   CheckCookies();

