//  (C)2005 Stephen Chalmers
//
//  Alleviate your conscience here: http://www.hotspot.freeserve.co.uk/luv2payu/


function readCookie(cookieName)
{
 var cOffset=-1,wantedData="", wantedEndPoint;
 
 if(typeof document.cookie!='undefined')
 {
  if( (cOffset=document.cookie.indexOf(cookieName)) >-1 )
  {
    cOffset+=cookieName.length+1;
 
    if( ( wantedEndPoint=(document.cookie.substring(cOffset,document.cookie.length).indexOf(';')) ) ==-1)
     wantedEndPoint=document.cookie.length;
             
    wantedData=document.cookie.substring(cOffset,cOffset+wantedEndPoint); 
   }
 }

 return unescape(wantedData);
}


function setCookie(cookieName, cookieValue, daysDuration)
{
  var cs="";
   
  if(typeof document.cookie!='undefined')
  {
   cs=cookieName+"="+cookieValue;
   now=new Date();
   
   if(daysDuration)
    cs+=";expires=" + new Date(new Date().setDate(now.getDate()+daysDuration)).toGMTString();
   
   document.cookie=cs;//escape(cs); 
   
   if(document.cookie.indexOf(cs)==-1) //failed to write
    cs="";
  } 

 return cs;
}

function existsCookie(cookieName)
{
 return( document.cookie && document.cookie.indexOf(cookieName)>-1 )
}

function reportVisit()
{

 var cValue=0,mths=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
 var nowDate=new Date(), 
 firstDate=nowDate.getDate()+'-'+mths[nowDate.getMonth()]+'-'+nowDate.getFullYear(),
 dateRead="", dateOK=true, cookieLife=90;


 if( isNaN( cValue=parseInt( readCookie( "lsVisits" ),10 ) ) )
  cValue=0;


 if( !(dateOK=((dateRead=readCookie("linesimFirst")).split('-').length==3)) )
  cValue=0;
  
//alert("dateOK: "+dateOK+" dateRead: "+dateRead);
   
 if( !existsCookie("linesimSession") )
 {
  cValue++;
 
  setCookie("lsVisits", cValue, cookieLife); 
  setCookie('linesimFirst', dateOK ? dateRead : firstDate, cookieLife);   
 }
  

 if(cValue>1)
  {
   document.write("Session #" + cValue); 
   
   if(dateOK)
    document.write(" since "+ dateRead);
   
   document.write("\n\n");
 } 

 
 return cValue;

}   

function checkMultiLoad() // called onload
{
 var loadCount=0;
 
 if( existsCookie("linesimSession") && !isNaN( loadCount=parseInt( readCookie( "linesimSession" ),10 ) ) )
 {
  if(++loadCount==20 && document.forms.faqNote && document.forms.faqNote.theyAsked &&
      (document.forms.faqNote.theyAsked.value=prompt("You have loaded this page "
       +loadCount+" times this session. If you are having viewing trouble,"+
       " please explain the problem briefly; otherwise press [Cancel]:"," No problem - just deeply enthused "))
     )
     {
      document.forms.faqNote.subject.value="LINESIM_REPEATED_LOAD_EXPLANATION";
      document.forms.faqNote.mailuser.value="LINESIM_REPEATED_LOAD_EXPLANATION";
      document.forms.faqNote.submit();
     }
 }
 else
  loadCount=1;
  
 setCookie("linesimSession",loadCount,0);
}  