// *****some functions****

//set cookie and call function callphp()
function setCookie(page) {
today = new Date();
expiry = new Date(today.getTime() + 30*60*1000);   // cookie expires after 30 min (no re-logging within this time)
document.cookie='pages='+page+'; expires='+expiry.toGMTString()+'; path=/'; 
cook='yes';
callphp(); 
}



//send variables to PHP script
function callphp() {
statstring = 'url='+url+'&ref='+ref+'&agent='+agent+'&screenwidth='+screenwidth+'&cookie='+cook;
document.write('<img border="0" height="1" width="1" src="/scripts/stats.php?'+statstring+'">');
}



//  ****main script****

//initialize some variables
 var url='-'; 
 var ref='-'; 
 var agent='-'; 
 var screenwidth=0;
 var page='';
 var urlpath=new Array('',''); 
 var cook='no';

 //get environment variables
 if (document.URL) { url=decodeURI(document.URL); url=escape(url); }
 if (document.referrer) { ref = decodeURI(document.referrer); ref=escape(ref); }
 if (navigator.userAgent) { agent = decodeURI(navigator.userAgent); agent=escape(agent); }
 if (screen.width) { screenwidth = screen.width; }



//get cookies and check if page has been reloaded; if not call function setCookie() and add page-url to list
 if (navigator.cookieEnabled) {
    urlpath=url.split(window.location.host) ; 
    page=urlpath[1]; 
    if ( urlpath[1].indexOf('%23')!=-1 ) {urlpath=urlpath[1].split('%23'); page=urlpath[0]; }          // %23=#
    if (page=='' || page=='/') { page='/index.html'; }
    if (document.cookie) {
      if ( document.cookie.indexOf('pages=') !=-1 ) {
         cookiestring=document.cookie.split('pages=');
         match=cookiestring[1].indexOf(page);
         if (match==-1) { page=cookiestring[1]+', '+page;   setCookie(page); }
      } 
      else { setCookie(page); }
    }
    else { setCookie(page); } 
 }
 else { callphp(); }


