//--JTHMY98------------------------
//  java script file: jhjscrpt.js
//  last update: Jan.9,2000
//--------------------------------
function newcookie(i){
 var sd=GetCookie("jhelmigd");
 var se=GetCookie("jhelmige");
 if(se==null){
  if(sd==null)sd="N000000";
  if(sd.length <7)sd=sd+"000000";
  var l=sd.length;
  var cdy=0;
  var i;
  for(i=1;i<l-5;i=i+6){
    if(sd.substring(i,i+6) != "000000")cdy++; 
  }
  var st="D000"+cdy;
  l=st.length;
  se=sd.substring(0,1)+sd.substring(0,1)+"YYN000"+st.substring(l-3,l)+sd.substring(1,7)
  WriteCookie("jhelmige",se);
  EraseCookie("jhelmigd");
 }
 else {
  if(sd != null)EraseCookie("jhelmigd");
 }
 EraseCookie("jhelmifcd");
 EraseCookie("jhelmigcp");
 return 0;
}
//------------------------------------------------
function trackpage(idx,ibit){
// idx is the index inside the cookie, range 0 - x
// ibit is the bit, valid values: 1,2,4
//------------------------------------------------
// updated: June17,2000:Y2K problem
//------------------------------------------------
 newcookie(0);
 var jhc="jhelmigu";
 var strTrack=GetCookie(jhc);
 if(strTrack == null)strTrack="00";  // empty cookie
 var strNew=UpdateUsage(strTrack,idx,ibit);
 WriteCookie(jhc,strNew);
 var nPages=CountPages(strNew);
 //
 // track the last date
 //
 jhc="jhelmige"
 strTrack=GetCookie(jhc);
 if(strTrack == null)strTrack="NNYYN000000000000";
 
 // y2k fix to patch up bad cookies
 if(strTrack.length == 19){
    if(strTrack.substring(11,15)=="2000"){
      var strFix=strTrack.substring(0,8) + "00130" + strTrack.substring(15,19);
      strTrack=strFix;
    }
 }

 var lstdy=parseInt( strTrack.substring(11,17),10);
 tdy= new Date();
 var iYear=tdy.getYear();

 // make it work with year 2000+
 if(iYear>=2000)iYear=iYear-1970;

 var iMonth=tdy.getMonth()+1;
 var iDay=tdy.getDate();
 var iDate=iYear*10000 + iMonth*100 + iDay;
 // day count
 var cntd=parseInt( strTrack.substring(8,11),10);
 if( iDate != lstdy)cntd++;
 // build new cookie
 var st="P000"+nPages;
 var l=st.length;
 var snew=strTrack.substring(0,5)+st.substring(l-3,l);
 st="D000"+cntd;
 l=st.length;
 snew=snew+st.substring(l-3,l)+iDate;
 WriteCookie(jhc,snew);
 return snew;
}
//-----------
function CountPages(strPages){
 var ilen=strPages.length;
 var i;
 var ibit;
 var nPages=0;
 for(i=0;i<ilen;i++){
  ibit=parseInt(strPages.substring(i,i+1));
  if( (ibit & 1) != 0)nPages++;
  if( (ibit & 2) != 0)nPages++;
  if( (ibit & 4) != 0)nPages++; 
 }
 return nPages;
}
// write cookie back with 1 year valid
//---------------------------------
function WriteCookie(jhcookie,strCookie){
 SetCookie(jhcookie,strCookie,365);
}
function EraseCookie(jhcookie){
 SetCookie(jhcookie,"dummy",-1);
}
function SetCookie(jhcookie,strCookie,idays){
 expires = new Date();
 expires.setTime(expires.getTime() + 24 * 3600 *1000*idays);
 var strNew=jhcookie + "=" + strCookie +";expires="+expires.toGMTString();
 // document.writeln("Setting:" + strNew);
 document.cookie=strNew;
}
//-----------------------
// update the usage cookie
//-----------------------
function UpdateUsage(oldUsage,idx,ibit){
 var oldAdd=oldUsage;
 var iLen=oldAdd.length;
 // extend string, if required
 while(idx >= iLen)
 {
  oldAdd=oldAdd+"0";
  iLen=oldAdd.length;
 }
 // separate sections of old usage string
 var strBefore="";
 if(idx>0)
 {
  strBefore=oldAdd.substring(0,idx);
 }
 var strOn=oldAdd.substring(idx,idx+1);
 var strAfter="";
 if(idx +1 < iLen)
 {
  strAfter=oldAdd.substring(idx+1,iLen);
 }
 // map in the bit (1,2,4) to indicate usage of page
 var inum= parseInt(strOn,8);
 inum = inum | ibit;
 var result= strBefore + inum + strAfter;
 // document.writeln("New:"+result+":<br>");
 return result;
}
//---------------
// reading cookie
//---------------
function GetCookie(cname){
 var lookfor = cname + "=";
 //-- dif between Netscape and Microsoft Java engines
 // var idxcookie=document.cookie.indexOf(lookfor,0);
 //----- naviagtor returns -1 on "Not Found"
 //----- MS IE returns  ???
 var ilenall = document.cookie.length;
 var ilencode= lookfor.length;
 var i=0;
 var idxcookie = -1;
 while (i < ilenall-ilencode){
  // document.writeln("i="+i+":"+document.cookie.substring(i,i+ilencode)+":<br>");
  if(document.cookie.substring(i,i+ilencode) == lookfor){
   idxcookie=i;
   break;
  }
  i++;
 }
 //- end work-around ---
 if (idxcookie < 0){
  // document.writeln("Cookie:" + cname + " Not Found!<br>");
  return null;
 }
 // document.writeln("cookie at " + idxcookie);
 var idxstart=idxcookie+lookfor.length;
 //-- different behavior ---------
 var idxlast=-1;
 for(i=idxstart;i<ilenall;i++){
  if(document.cookie.substring(i,i+1)==";"){
    idxlast=i;
    break;
  }
 }
 //-- end work-around ---------
 if(idxlast < 0){
   idxlast=document.cookie.length;
 }
 result=document.cookie.substring(idxstart,idxlast);
 return result;
}
//-- play sound ----
function plays(cy,sfile){
 if(cy.substring(2,3)=="N"){
  document.write('<p><embed src="'+sfile);
  document.write('" hidden="true" align="baseline" border="0"');
  document.write(' width="10" height="10" autostart="TRUE"></p>');
 }
 return 0;
}
//---- show animation
function showani(iw,ih,nani,nstat,ntext)
{
 var ndisp=nani;
 if(cy.substring(3,4)=="Y")ndisp=nstat;
 if(ndisp==null){
  if(ntext != null){
   document.write(ntext);
  }  
 }
 else {
  document.write('<img src="' + ndisp + '"');
  if(iw > 0)document.write(' width="' + iw + '"');
   if(ih > 0)document.write(' height="' + ih +'"');
   document.write('>');
  }
  return 1;  
}
//--- end of utilities -----
//
var cy=trackpage(ip1,ip2);
if (nsnd != null){
   plays(cy,nsnd);
}
// download page

if(ip1==29 && ip2==4){
  if( cy.substring(0,1)=="Y"){
    document.write('Download Location:<br>');
    document.write('<a href="http://168.144.47.190/ftp/dwnldzpn.htm">Site: WoWN</a><br>');
  }
  else {
     document.write("Sorry !");
  }
}


//------ end of the js-file

