// advanced functions for improving Venda's site
// programation by Venda
// for detailed usage, see the file usage.txt in the same folder
// for any comments, help, don't hesitate to contact me
// adnev@podvodnik.cz


ns4=(navigator.appName=='Netscape')
ie4=(navigator.appName=='Microsoft Internet Explorer')
op4=(typeof(window.opera)!='undefined')

wel="Welcome to this section."
mpg="Return to zdarmanet.net."
zout="Back to a smaller zoom factor."
zmes="Click to zoom. To close the window that will open, just click on it or move the mouse out of it."
zwel="You can try to click on areas that you would zoom in."
xmes="To close that window, just click on it or move the mouse out of it."
cmes="Click to see a third party comment."
ctr="Click to read."
bta="Back to the article list."

//
//
//
// general functions
//
//
//


baseHref="http://zdarma.minet.net:8080/"

function start(mes) {
  baseHref=initBaseHref('8080','venda')
  if (typeof zmes=='undefined')
    location.href=location.href
  initKeyCapture()
  initMenu()
  initTv()
  if (typeof mes!='undefined')
    wel=mes
  setTimeout('sts()','200')
}

function initBaseHref(id1,id2) {
  var baseHref=location.href
  var i=baseHref.length
  if (baseHref.indexOf(id1)!='-1')
    i=baseHref.indexOf(id1)+id1.length+1
  if (baseHref.indexOf(id2)!='-1')
    i=baseHref.indexOf(id2)+id2.length+1
  baseHref=baseHref.substring(0,i)
  return baseHref
}

function sts(mes) {
  if (typeof mes=='undefined')
    mes=wel
  var com='window.status="'+mes+'"'
  setTimeout(com,'10')
}

//
//
//
// functions for capturing keyboard commands
//
//
//

//
// data
//

//syntax1: keyword;txt;[wavfile];[hor size];[ver size];
// [] = can be omitted (don't omit the ; separator)
// txt must be different from $ otherwise:
//syntax2: keyword;$;link;
// syntaxes can be alternated

ds  =  "hello;please no such naiv words;;;;merde;please no french insults;;;;prdel;please no czech insults;;;;hovno;please no czech insults;;;;malak;please no greeek insults;;;;katzo;please no italian insults;;;;gamisi;please no greek insults;;;;shit;please no english insults;;;;fuck;please no english insults;;;;scheisse;please no german insults;;;;poulos;greek lifestyle;;;;venda;author of this site - initial member of zdarma;;150;;filippos;too much professional guy - initial member of zdarma;;150;135;socrate;specialist in cutting & pasting sleeping time - initial member of zdarma;;180;135;jeanbaptiste;a sort of people colector - member of zdarma;;160;105;christophe;specialist in sequential activity - member of zdarma;;182;;celine;a breton girl - member of zdarma;;130;;edouard;cool monster - member of zdarma;;120;;julia;special agent - member of zdarma;;120;;nadina;dommage woman - member of zdarma                                   ;domaze;130;;elina;decibel woman - member of zdarma;;120;;rolland;permission man - the boss;;120;;constantin;member of zdarma;;;;dorothee;member of zdarma;;;;maria;diplomatic member of zdarma;;110;;arzu;pagowoman - member of zdarma;;130;;mehtab;fan of brookly funk essentials - member of zdarma;;150;130;julie;metaphysical member of zdarma;;;;olivia;eternal dancer - memeber of zdarma;;130;;faride;specialist in greek and american girls - member of zdarma;;150;120;aurelie;member of zdarma;;;;zdarma;very good concept;;;;boost;1 boost = unity of succes;;;;concept;what our activity produces;;;;ermanno;italian memeber of zdarma;;;;dadafkas;lissen to the sound of inspiration;dadafkas;120;;activity;------ boosting ------;;;;success;see: dadafkas;;;;inspiration;what i do not have any more;;120;;bourrage;french word for direct cd;;;;viking;$;browser/lefevre_yard/viking.htm;moderntalking;initiators of modern smiling;;;;europe;$;browser/europe.htm;lille;$;browser/lille.htm;prague;$;browser/prague/prague.htm;lefevre;$;browser/lefevre_main.htm;beach;$;browser/beach/beach_en$fr$cz;paris;$;browser/paris/paris.htm;greece;$;browser/greece.htm;athens;$;browser/athens/athens.htm;lemans;$;browser/lemans.htm;geneva;$;browser/geneva/geneva.htm;czech;$;browser/czech.htm;pec;$;browser/pec/pec.htm;machac;$;browser/machac/machac_97.htm;universe;$;browser/universe.htm;earth;$;browser/earth.htm;mykonos;$;browser/mykonos/mykonos.htm;neamakri;$;browser/nea_makri/nea_makri.htm;jumps;$;browser/jumps/jumps.htm;czech;$;browser/czech.htm;home;$;main.htm;download;$;download/index.htm;mirror;$;mirror/mirror.htm;links;$;links/links.htm;games;$;games/index.htm;attik;$;browser/attik.htm;finland;$;browser/finland.htm;france;$;browser/france.htm;helsinki;$;browser/helsinki/helsinki.htm;predium;$;browser/predium/predium.htm;joroinen;$;browser/joroinen/joroinen.htm;articles;$;articles/index.htm;paper;$;articles/paper/paper_fr$en;sst;$;articles/sst/sst.htm;wien;$;browser/wien/bac_96.htm;c314;$;browser/c_3_14/c_3_14.htm;s32;$;browser/s_3_2/s_3_2.htm;familly;$;browser/lefevre_yard/familly.htm;plaquettes;$;plaquettes/plaquettes.htm;"

function readData() {
  var i=ds.indexOf(';')
  var theData=ds.substring(0,i)
  ds=ds.substring(i+1,ds.length)
  return theData
}

function dd(wh,txt,wav,hor,ver) {
  this.wh=wh
  this.txt=txt
  this.dur=eval(txt.length+'*100+300')
  if (wav!='')
    wav+='.wav'
  this.wav=wav
  if (hor=='')
    hor='100'
  this.hor=hor
  if (ver=='')
    ver='100'
  this.ver=ver
}

function ld(wh,adr) {
  this.wh=wh
  this.adr=adr
  this.txt='$'
  return this
}

function makeList() {
  var n=0
  while (ds.length>0) {
    n++
    wh=readData()
    txt=readData()
    if (txt=='$') {
      adr=readData()
      this[n]=new ld(wh,adr)
    }
    else {
      wav=readData()
      hor=readData()
      ver=readData()
      this[n]=new dd(wh,txt,wav,hor,ver)
    }
  }
  this.length=n
  return this
}

dtlst=new makeList()

//
// action
//

function initKeyCapture() {
  if (ns4)
    document.captureEvents(Event.KEYPRESS)
  document.onkeypress=addKey
  pressed=''
}

function addKey(e) {
  if (ns4)
    c=String.fromCharCode(e.which)
  if (ie4)
    c=String.fromCharCode(window.event.keyCode)
  pressed+=c.toLowerCase(c)
  for(i = 1; i <= dtlst.length; i++)
    if (pressed.indexOf(dtlst[i].wh)!=-1) {
      if (dtlst[i].txt=='$') {
        var where=baseHref+dtlst[i].adr
alert(where)
        if (where.indexOf('$')!='-1')
          goTo(where)
        else
          location.href=where
      }
      else
        openDef(dtlst[i].dur,dtlst[i].txt,dtlst[i].wav,dtlst[i].hor,dtlst[i].ver)
      pressed=''
      i=dtlst.length+1
    }
  if (pressed.indexOf('testall')!=-1) {
    pressed=''
    testAll('1')
  }
  if (pressed.indexOf('cookie')!=-1) {
    pressed=''
    alert(document.cookie)
  }
}

function openDef(dur,txt,wav,hor,ver) {
  opt='height='+ver+',width='+hor
  yy=open('','',opt)
  ifie=(ie4)?'STYLE="margin:8" ':''
  txt='<HTML><HEAD><TITLE> ...........................................................................</TITLE></HEAD><BODY '+ifie+'BGCOLOR=000000 TEXT=FFFF00 STYLE="font-size:18px;text-align:center;font-family:tahoma" ONLOAD="setTimeout(\'self.close()\',\''+dur+'\')"><B>'+txt
  if (wav!='')
    txt+='<EMBED SRC="'+baseHref+wav+'" AUTOSTART=true MASTERSOUND HIDDEN>'
  txt+='</BODY></HTML>'
  yy.document.write(txt)
  yy.document.close()
}

function testAll(i) {
  if (i<=dtlst.length)
    if (dtlst[i].txt!='$') {
      openDef(dtlst[i].dur,dtlst[i].txt,dtlst[i].wav,dtlst[i].hor,dtlst[i].ver)
      i++
      var toDo='testAll('+i+')'
      setTimeout(toDo,dtlst[i-1].dur+100)
    }
    else {
      i++
      testAll(i)
    }
}

//
//
//
// functions for displaying submenus
//
//
//

function initMenu() {
  if (ns4) if (typeof document.menu!='undefined') {
    document.captureEvents(Event.MOUSEDOWN)
    document.onmousedown=locateMouse
    menS=document.menu
    men=menS.document
  }
  if (ie4) if (typeof document.all.menu!='undefined') {
    document.onmousedown=locateMouse
    men=document.all.menu
    menS=men.style
  }
  clickedX=0
  clickedY=0
  displaying=false
}

function locateMouse(e) {
  if (ns4) {
    clickedX=e.pageX
    clickedY=e.pageY
  }
  if (ie4) {
    clickedX=event.clientX+document.body.scrollLeft
    clickedY=event.clientY+document.body.scrollTop
  }
}

function dispMenu(ds,wid) {
  if (displaying) {
    var toDo="dispMenu('"+ds+"','"+wid+"')"
    setTimeout(toDo,'100')
  }
  else {
    displaying=true
    hideMenu()
    menS.left=clickedX+5
    menS.top=clickedY+10
    ds+='Cancel;javascript:hideMenu();'
    var toDo="nextItem('"+ds+"','"+wid+"')"
    setTimeout(toDo,'80')
  }
}

function nextItem(ds,wid) {
  var i=ds.indexOf(';')
  itm=ds.substring(0,i)
  ds=ds.substring(i+1,ds.length)
  i=ds.indexOf(';')
  link=ds.substring(0,i)
  ds=ds.substring(i+1,ds.length)
  if (link.indexOf('$')!='-1')
    link="javascript:goTo('"+link+"')"
  txt='<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=1  BGCOLOR=93D2D2><TR><TD WIDTH='+wid+'><A HREF="'+link+'" ONMOUSEOVER="sts(\'Wanna '+itm+'\')"  ONMOUSEOUT="sts(\'Press Cancel to hide the menu.\')" STYLE="color:000000;font-size:13px;text-decoration:none">'+itm+'</A></TD></TR></TABLE>'
  var menTop=menS.top
  if (ie4)
    menTop=menTop.substring(0,menTop.indexOf('px'))
  menTop=menTop-22
  if (menTop<0)
    menTop=0
  menS.top=menTop
  if (ns4)
    men.write(txt)
  else
    men.innerHTML+=txt
  menS.visibility=(ns4)? 'show':'visible'
  var toDo="nextItem('"+ds+"','"+wid+"')"
  if (ds.length>0)
    setTimeout(toDo,'80')
  if (ds.length==0) {
    setTimeout("sts('Make your choice')","50")
    displaying=false
  }
}

function hideMenu() {
  if (ns4)
    men.close()
  else
    men.innerHTML=''
  menS.visibility=(ns4)?'hide':'hidden'
  setTimeout('sts(wel)','25')
}

//
//
//
// functions to zoom a picture or to display a comment
//
//
//

function srcExt(link) {
  var i=link.lastIndexOf('.')
  var j=link.lastIndexOf('/')
  if (i>j)
    var ext=link.substring(i+1,link.length)
  else
    var ext=''
  if (ext=='')
    link=link+'.jpg'
  return link
}


function zoom(what,hor,ver) {
  hor=eval(hor+"+18")
  ver=eval(ver+"+18")
  adr=srcExt(what)
  opt="height=" + ver + ",width=" + hor
  closeMe()
  xx=open("","xx",opt)
  ifie=(navigator.appName=="Netscape")? '':' STYLE="margin:9"'
  xx.document.write('<HTML><TITLE>Zoom</TITLE></HEAD><BODY ONBLUR="self.focus()" ONLOAD="self.focus()" BGCOLOR=000000 LINK=000000'+ifie+'><A HREF="Javascript:generator.closeMe()" ONMOUSEOUT="generator.closeMe()"><IMG SRC="' + adr + '" BORDER=0></A></BODY></HTML>')
  xx.generator=self
  xx.document.close()
  sts(xmes)
}

function comment(sx,sy,dur,txt,chrset) {
  dur=eval(dur+'*1000')
  if (chrset=='')
    chrset='ISO-8859-1'
  coded="height="+sy+",width="+sx+",scrollbars=no,resizable"
  closeMe()
  xx=open("","",coded)
  xx.document.clear()
  xx.document.write("<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-2\"><TITLE>Comment</TITLE></HEAD><BODY BGCOLOR=A5D6A3 ONLOAD=\"setTimeout('generator.closeMe();','"+dur+"');self.focus()\" ONBLUR=\"self.focus()\">"+txt+"<P><CENTER><FORM><FONT SIZE=0><INPUT TYPE=button VALUE=\" Ok \" ONCLICK=\"generator.closeMe()\"></FONT></FORM></BODY></HTML>");
  xx.document.close()
  xx.generator=self
  sts(wel)
}

function closeMe() {
  if (typeof xx!='undefined') if (typeof xx.document != 'undefined')
    xx.close()
  sts(wel)
}

//
//
//
// functions to put tvsets
//
//
//

//
// data
//

function makeArray(size) {
  this.length=size
  for(i=1;i<= size;i++)
    this[i]=null
  return this
}

function makeIm(imName,width,height) {
  this.name=imName
  this.w=width
  this.h=height
  var pre=new Image(1,1)
  this.file=pre
  return this
}

function makeTv(tvName,imList) {
  this.name=tvName
  this.i=1
  this.im=imList
  this.t=0
  return this
}

//
// action
//


function initTv() {
  if (typeof tv!='undefined' && typeof tvTimer=='undefined') {
    for(s = 1; s<= tv.length; s++)
      doDispNextIm(s)
    tvTimer=setInterval('nextIms()','100')
  }
}

function nextIms() {
  for(s = 1; s<= tv.length; s++)
    nextIm(s)
}


function nextIm(s) {
  if (tv[s].t!=0)
    tv[s].t=tv[s].t-1
  else
    if (imReady(s))
  doDispNextIm(s)
}

function imReady(s) {
  return tv[s].im[tv[s].i].file.complete
}

function doDispNextIm(s) {
  document[tv[s].name].src=tv[s].im[tv[s].i].file.src
  tv[s].i=tv[s].i+1
  if (tv[s].i>tv[s].im.length)
    tv[s].i=1
  if (tv[s].im[tv[s].i].file.src!=tv[s].im[tv[s].i].name+'.jpg')
    tv[s].im[tv[s].i].file.src=tv[s].im[tv[s].i].name+'.jpg'
  tv[s].t=25
}

function zoomTv(tvName) {
  for(i = 1; i<=tv.length; i++)
    if(tv[i].name==tvName)
      tvNumber=i
  j=tv[tvNumber].i-1
  if(j==0)
    j=tv[tvNumber].im.length
  imToZoom=tv[tvNumber].im[j]
  zoom(imToZoom.name+'_z',imToZoom.w,imToZoom.h)
  sts(xmes)
}

//
//
//
// functions for activating buttons
//
//
//

function reduceButtonSrc(button) {
  var imSrc=document[button].src
  this.pre=imSrc.substring(0,imSrc.length-4)
  if (this.pre.substring(this.pre.length-2,this.pre.length-1)=='_')
    this.pre=this.pre.substring(0,this.pre.length-2)
  this.ext=imSrc.substring(imSrc.length-4,imSrc.length)
  return this
}

function oB(button) {
  var imSrc=new reduceButtonSrc(button)
  document[button].src=imSrc.pre+'_o'+imSrc.ext
}

function fB(button) {
  var imSrc=new reduceButtonSrc(button)
  document[button].src=imSrc.pre+imSrc.ext
}

//
//
//
// functions for managing languages
//
//
//


// see content of language_changer.htm
// syntax of general cookie: en$fr$lan3$lan4$

function goTo(link) {
  i=link.lastIndexOf('_')
  var linkPre=link.substring('0',i+1)
  var avalaibleLan=link.substring(i+1,link.length)
  location.href=linkPre+bestLanguage(avalaibleLan)+'.htm'
}

function setBestLanguage(lan) {
  open(baseHref+'language_changer.htm#'+lan,'lan','height=100,width=10')
}

function bestLanguage(avalaible) {
  var result=avalaible.substring(0,avalaible.indexOf('$'))
  var prefOrder=document.cookie
  if (prefOrder.indexOf(';')!='-1')       prefOrder=prefOrder.substring(prefOrder.lastIndexOf(';')+2,prefOrder.length)
  while (prefOrder!='') {
    var sepIndex=prefOrder.indexOf('$')
    if (sepIndex!='-1') {
      var lan=prefOrder.substring(-1,sepIndex)
      prefOrder=prefOrder.substring(sepIndex+1,prefOrder.length)
    }
    else {
      var lan='noCookieSet'
      prefOrder=''
    }
    if (avalaible.indexOf(lan)!='-1') {
      result=lan
      prefOrder=''
    }
  }
  return result
}

