////////////////////////////////////////////////////////////////
// D-Date JavaScript functionality
// (C) 2004-2005 New House Internet Services
// info@newhouse.nl
////////////////////////////////////////////////////////////////

var IMGROOTURL="/media/img/";

var browsername;
var browserversion;
if(navigator.appName == "Microsoft Internet Explorer")
{
  if(navigator.userAgent.indexOf(" Opera ") >= 0)
  {
    browsername="OPERA";
  }
  else
  {
    browsername="IE";
  }
}
else if(navigator.appName == "Netscape")
{
  browsername="MOZILLA";
}
/*
alert(navigator.appName);
alert(navigator.appCodeName);
alert(navigator.appMinorVersion);
alert(navigator.appVersion);
alert(navigator.userAgent);
*/
// alert(browsername);


/* Toggle open/close of submenu
   id: id of the clicked item
   Corresponding submenu has id+"_sub"
   Returns false if action was succesful, otherwise returns true;
*/
function mT(id)
{
  if(!compatibleBrowser()) return true;
  var itemel=document.getElementById(id);
  var submenuel=document.getElementById(id+"_sub");
  var isopen=submenuel.style.visibility != "hidden";
  mHideShowSubmenu(id,!isopen);
  return false;
}

/* mouseEnter op menuitem */
function mE(id)
{
  if(!compatibleBrowser()) return true;
  var el=document.getElementById(id);
  var currentclass=el.className;
  if(stringEndsWith(currentclass,"_mouseover")==null)
  {
    el.className=currentclass+"_mouseover";
  }
  return false;
}

/* mouseOut op menuitem */
function mO(id)
{
  if(!compatibleBrowser()) return true;
  var el=document.getElementById(id);
  var currentclass=el.className;
  var prefix=stringEndsWith(currentclass,"_mouseover");
  if(prefix != null)
  {
    el.className=prefix;
  }
  return false;
}

function compatibleBrowser()
{
  if(  document
    && document.body
    && document.getElementById
    && document.body.style
    && document.body.className
    && document.nodeName
  )
  {
    return true;
  }
  else
  {
    return false;
  }
}

function mHideShowSubmenu(id,show)
{
  var submenuel=document.getElementById(id+"_sub");
  submenuel.style.visibility=show? "visible":"hidden";
  submenuel.style.display=show? "block":"none";

  var ballel=document.getElementById(id+"_ball");
  var ballclass=show? "mm0_ballsubopen":"mm0_ballsub";
  var currentclass=ballel.className;
  if(stringEndsWith(currentclass,"sel")!=null)
  {
    ballclass += "sel";
  }
  ballel.className=ballclass;
}

function stringEndsWith(str,end)
{
  var prefix=null;
  if( (str.length >= end.length) && (str.substr(str.length-end.length) == end) )
  {
    prefix=str.substr(0,str.length-end.length);
  }
  return prefix;
}

function adCfrmDel()
{
  return confirm("Echt verwijderen?");
}

function cfrmSure()
{
  return confirm("Weet u dit zeker?");
}


var _onloadscripts=Array();

function addOnLoad(cmd)
{
  _onloadscripts[_onloadscripts.length]=cmd;
}

function bodyOnLoad()
{
  for(var i=0; i < _onloadscripts.length; i++)
  {
    eval(_onloadscripts[i]);
  }
}

function changeElementClasses(fromclass, toclass)
{
  if(document.all)
  {
     for(var i=0; i < document.all.length; i++)
     {
       if(document.all[i].className && (document.all[i].className == fromclass))
       {
         document.all[i].className=toclass;
       }
     }
  }
}

function hoeterecht1Changed(focus)
{
  if(document.getElementById)
  {
    var listbox=document.getElementById("hoeterecht1");
    var subvalues=new Array();
    var subtexts=new Array();
    var hassublist=false;
    var hassubtext=false;
    if(listbox.selectedIndex > 0)
    {
      var catparams=hoeterecht[listbox.selectedIndex-1];
      var catsubvalues=catparams[2];
      if( ((typeof catsubvalues)=="object") && (catsubvalues.constructor == Array))
      {
        hassublist=true;
        subvalues[0]="";
        subtexts[0]="";
        for(var i=0; i < catsubvalues.length; i++)
        {
          var subvalue=catsubvalues[i];
          var a=subvalue.split("|");
          if(a[0] == "*")
          {
            subtexts[subtexts.length]=a[1];
            subvalues[subvalues.length]="-";
            subtexts[0]=a[2]+":";
            document.getElementById("hoeterecht3caption").innerHTML=a[2]+": ";
          }
          else
          {
            subvalues[subvalues.length]=a[0];
            subtexts[subtexts.length]=a[1];
          }
        }
      }
      else if(catsubvalues != "")
      {
        hassubtext=true;
        document.getElementById("hoeterecht3caption").innerHTML=catsubvalues+": ";
      }
      else
      {
      }
    }
    fillListBox(document.getElementById("hoeterecht2"),subvalues,subtexts);
    if(hassublist)
    {
      document.getElementById("hoeterecht2").selectedIndex=0;
      hoeterecht2Changed(false);
    }
    showHideTR(document.getElementById("tr_hoeterecht2"),hassublist);
    showHideTR(document.getElementById("tr_hoeterecht3"),hassubtext);
    document.getElementById("hoeterecht3").value="";
    if(focus)
    {
      if(hassubtext) document.getElementById("hoeterecht3").focus();
      if(hassublist) document.getElementById("hoeterecht2").focus();
    }
  }
}

function hoeterecht2Changed(focus)
{
  if(document.getElementById)
  {
    var listbox=document.getElementById("hoeterecht2");
    var hastext=( (listbox.selectedIndex > 0) && ( listbox.options[listbox.selectedIndex].value == "-") );
    showHideTR(document.getElementById("tr_hoeterecht3"),hastext);
    document.getElementById("hoeterecht3").value="";
    if(hastext && focus)
    {
      document.getElementById("hoeterecht3").focus();
    }
  }
}

function hoeterechtInit()
{
//  debugger;
  if(document.getElementById)
  {
    document.getElementById("hoeterecht1").selectedIndex=hoeterecht_init[0];
    hoeterecht1Changed(false);
    if(document.getElementById("hoeterecht2").options.length > 0)
    {
      document.getElementById("hoeterecht2").selectedIndex=hoeterecht_init[1];
      hoeterecht2Changed(false);
    }
    document.getElementById("hoeterecht3").value=hoeterecht_init[2];
  }
}

function showHideTR(mytr,show)
{
  if(browsername == "IE")
  {
    mytr.style.display=show? "block":"none";
    mytr.style.visibility=show? "visible":"hidden";
    showHideListboxChildren(mytr,show);
  }
  else
  {
    mytr.style.visibility=show? "visible":"hidden";
    if(browsername == "MOZILLA")
    {
      mytr.style.position=show? "relative":"absolute";
    }
  }
}

function showHideListboxChildren(el,show)
{
  if(el.children)
  {
    for(var i=0; i< el.children.length; i++)
    {
      var child=el.children[i];
      if( ((typeof child)=="object")
        && (child.type)
        && (child.type == "select-one")
      )
      {
        child.style.visibility=show? "visible":"hidden";
      }
      else
      {
        showHideListboxChildren(child,show);
      }
    }
  }
}

function showHideTD(mytd,show)
{
  if( (browsername == "IE") || (browsername == "MOZILLA") )
  {
    mytd.style.display=show? "block":"none";
  }
  else
  {
//    mytd.style.display=show? "block":"none";
    mytd.style.visibility=show? "visible":"hidden";
  }
}

function fillListBox(listbox,values,names)
{
  var i;
  for(i=0;i<values.length;i++)
  {
    listbox.options[i]=new Option(names[i],values[i],false,false);
  }
  for(i=listbox.options.length-1;i>=values.length;i--)
  {
    listbox.options[i]=null;
  }
}

function showHideInUitwonend()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_kind_inwonend");
    if(row)
    {
      if(document.getElementById("select_kinderen"))
      {
        var kinderen=getListboxValue("select_kinderen");
        var show=(kinderen > 0);
        showHideTR(row,show);
      }
    }
  }
}

function showHideRekening()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_rekening");
    if(row)
    {
      if(document.getElementById("select_membertype"))
      {
        var membertype=getListboxValue("select_membertype");
        var show=(membertype != "BEPERKT");
        showHideTR(row,show);
      }
    }
  }
}

function showHideZoekInUitwonend()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_zoek_kind_inwonend");
    var kinderen=getListboxValue("select_zoekkinderen");
    if(row)
    {
      var show=(kinderen != "0");
      showHideTR(row,show);
      // Bug in IE6: de slider van w_zoek_kind_inwonend wordt willekeurig op de pagina
      // neergezet als we de omliggende TR verbergen. Daarom de slider ook expliciet
      // verbergen/tonen
      var slider=document.getElementById("id_w_zoek_kind_inwonend_wb");
      if(slider)
      {
        slider.style.visibility=show? "visible":"hidden";
      }
    }
  }
}

function showHideZoekAfstandPostcode()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_zoek_afstand_postcode");
    var zoekafstand=getListboxValue("select_zoek_afstand");
    if(row)
    {
      showHideTR(row,(zoekafstand != ""));
    }
  }
}

function canDoCheckboxSummary()
{
  if(document.getElementById)
  {
    if(browsername != "OPERA")
    {
      return true;
    }
  }
  return false;
}

function initSummary(cbox_id,idprefix)
{
  if(canDoCheckboxSummary())
  {
    var cbox=document.getElementById(cbox_id);
    mChk(cbox,idprefix);
  }
}

function mChk(cbox,idprefix)
{
  if(canDoCheckboxSummary())
  {
    var isradio=false;
    var frm=cbox.form;
    var fieldname=cbox.name;
    if(frm.elements && frm.elements[fieldname])
    {
      var summary="";
      var firstcheckbox=null;
      var els=frm.elements[fieldname];
      for(var i=0;i < els.length; i++)
      {
        var el=els[i];
        if(el && el.type)
        {
          if( (el.type == "checkbox") || (el.type == "radio") )
          {
            isradio=(el.type == "radio");
            if(el.name == fieldname)
            {
              if(!isradio)
              {
                if(firstcheckbox == null)
                {
                  firstcheckbox=el;
                  if(cbox.checked && (cbox != firstcheckbox))
                  {
                    firstcheckbox.checked=false;
                  }
                }
                else
                {
                  if(firstcheckbox.checked)
                  {
                    el.checked=false;
                  }
                }
              }
              if(el.checked)
              {
                if(summary != "")
                {
                  summary += " / ";
                }
                summary += el.title;
              }
            }
          }
        }
      }
      if(summary == "")
      {
        if(!isradio)
        {
          if(firstcheckbox)
          {
            firstcheckbox.checked=true;
            summary += firstcheckbox.title;
          }
        }
      }
      var summarya=document.getElementById(idprefix+"_a");
      summarya.innerHTML=summary;
    }
    if(isradio)
    {
      mColl(idprefix);
    }
  }
}

var _expanded=null;

function mExp(idprefix)
{
  if(_expanded)
  {
    mColl(_expanded);
  }
  mExpColl(idprefix,true);
  _expanded=idprefix;
}

function mColl(idprefix)
{
  mExpColl(idprefix,false);
  if(idprefix == _expanded)
  {
    _expanded=null;
  }
}

function mExpColl(idprefix,expand)
{
  var td_sum=document.getElementById(idprefix+"_sum");
  var td_chk=document.getElementById(idprefix+"_chk");
  var td_col=document.getElementById(idprefix+"_col");
  showHideTD(td_sum,!expand);
  showHideTD(td_chk,expand);
  showHideTD(td_col,expand);
}

function zoekRelatieCheckClick(cbox)
{
  var frm=cbox.form;
  var fieldname=cbox.name;
  var lboxfieldname=replacePrefix(fieldname,"db_zoek_relatie_","db_zoek_geslacht_");
  if(frm.elements)
  {
    var lbox=frm.elements[lboxfieldname];
    if(cbox.checked)
    {
      if(lbox.selectedIndex <= 0)
      {
        var lboxfields=Array("db_zoek_geslacht_re","db_zoek_geslacht_hu","db_zoek_geslacht_vr");
        for(var i=0; i < lboxfields.length; i++)
        {
          var field=frm.elements[lboxfields[i]];
          if(field.selectedIndex > 0)
          {
            lbox.selectedIndex=field.selectedIndex;
            break;
          }
        }
      }
    }
    else
    {
      lbox.selectedIndex=0;
    }
  }
}

function zoekRelatieGeslachtChange(lbox)
{
  var frm=lbox.form;
  if(frm.elements)
  {
    var fieldname=lbox.name;
    var cboxfieldname=replacePrefix(fieldname,"db_zoek_geslacht_","db_zoek_relatie_");
    if(cboxfieldname != null)
    {
      var cbox=frm.elements[cboxfieldname];
      if(cbox != null)
      {
        cbox.checked=(lbox.selectedIndex > 0);
      }
    }
    var correspondinglistboxname="";
    if(fieldname == "db_zoek_geslacht_re")
    {
      correspondinglistboxname="db_zoek_geslacht_hu";
    }
    else if(fieldname == "db_zoek_geslacht_hu")
    {
      correspondinglistboxname="db_zoek_geslacht_re";
    }
    if(correspondinglistboxname != "")
    {
      var correspondinglistbox=frm.elements[correspondinglistboxname];
      if(correspondinglistbox != null)
      {
        if( (lbox.selectedIndex > 0) && (correspondinglistbox.selectedIndex > 0) )
        {
          if(correspondinglistbox.selectedIndex != lbox.selectedIndex)
          {
            correspondinglistbox.selectedIndex = lbox.selectedIndex;
          }
        }
      }
    }
  }
}

function replacePrefix(str,oldprefix,newprefix)
{
  if(str.substr(0,oldprefix.length) == oldprefix)
  {
    return newprefix+str.substr(oldprefix.length,str.length-oldprefix.length);
  }
  return null;
}

function focusFirstField(formid)
{
  focusFirstField2(formid,false);
}

function focusFirstEmptyField(formid)
{
  focusFirstField2(formid,true);
}

function focusFirstField2(formid,onlyempty)
{
  if(document.getElementById)
  {
    var frm=document.getElementById(formid);
    if(frm && frm.elements)
    {
      for(var i=0; i < frm.elements.length; i++)
      {
        var el=frm.elements[i];
        var canfocus=false;
        if(el.focus)
        {
          if(el.type)
          {
            if( (el.type != "hidden") && (el.type != "submit") && (el.type != "reset") )
            {
              if( onlyempty && ((el.type == "text") || (el.type == "password")))
              {
                canfocus=(el.value == "")
              }
              else
              {
                canfocus=true;
              }
            }
          }
          else if(el.options)
          {
            canfocus=true;
          }
        }
        if(canfocus)
        {
          try
          {
            el.focus();
            if(el.type && (el.type == "text"))
            {
              el.select();
            }
          }
          catch(e)
          {
          }
          break;
        }
      }
    }
  }
}

function showHideTDSWithClassName(classname,show)
{
  var els=document.getElementsByTagName("td");
  for(var i=0; i < els.length; i++)
  {
    var el=els[i];
    if(el.className == classname)
    {
      showHideTD(els[i],show);
    }
  }
}

function showHideSpansWithClassName(classname,show)
{
  var els=document.getElementsByTagName("span");
  for(var i=0; i < els.length; i++)
  {
    var el=els[i];
    if(el.className == classname)
    {
//      el.style.visibility=show? "visible":"hidden";
      el.style.display=show? "inline":"none";
    }
  }
}

function showHideGeavanceerdOld()
{
  if(!compatibleBrowser()) return true;
  var v=getListboxValue("zoek_mode");
  var show=(v == "A");
  showHideTDSWithClassName("wf",show);
  showHideTDSWithClassName("wfhead",show);
}

function getListboxValue(id)
{
  var lb=document.getElementById(id);
  if(lb.type == "radio")
  {
    return getRadioValue(id);
  }
  else
  {
    if(lb.selectedIndex < 0) return null;
    return lb.options[lb.selectedIndex].value;
  }
}

function showHideGeavanceerd()
{
  if(!compatibleBrowser()) return true;
  var v=getListboxValue("zoek_minscore");
  var show=(v != "100");
  showHideSpansWithClassName("wf",show);
}

function cbSumStart(colid,firstid)
{
  if(canDoCheckboxSummary())
  {
    document.write("<table class=\"multitable\"><tr><td id=\""+colid+"_sum\" class=\"multitable\">"
            +"<a id=\""+colid+"_a\" href=\"#\" onmousedown=\"mExp('"+colid+"');\" onClick=\"mExp('"+colid+"');\"></a>"
            +" <a href=\"#\" onmousedown=\"mExp('"+colid+"');\" onClick=\"mExp('"+colid+"');\"><img src=\""+IMGROOTURL+"mainlayout/expand.gif\" border=0 align=\"absmiddle\"></a>"
            +"</td><td id=\""+colid+"_chk\" style=\"display:none;\" class=\"multitable\">");
    addOnLoad("initSummary('"+firstid+"','"+colid+"');");
  }
}
function cbSumEnd(colid)
{
  if(canDoCheckboxSummary())
  {
    document.write("</td><td id=\""+colid+"_col\" style=\"display:none\" class=\"multitable\">"
                  +" <a href=\"#\" onmousedown=\"mColl('"+colid+"');\" onClick=\"mColl('"+colid+"');\"><img src=\""+IMGROOTURL+"mainlayout/collapse.gif\" border=0 align=\"absmiddle\"></a></td></tr></table>");
  }
}

function pager(lb,urlprefix)
{
  var value=lb.options[lb.selectedIndex].value;
  var url=urlprefix+value;
  document.location.href=url;
}

function setImage(id,src)
{
  var image=document.getElementById(id);
  image.src=src;
}

function setStyleVisibility(cssselector,visible)
{
  for(var s=0; s < document.styleSheets.length; s++)
  {
    var stylesheet=document.styleSheets[s];
    for(var r=0; r < stylesheet.rules.length; r++)
    {
      var therule=stylesheet.rules.item(r);
      if(therule.selectorText == cssselector)
      {
        var newdisplay=visible? "block":"none";
        if(therule.style.display != newdisplay)
        {
          therule.style.display = newdisplay;
          break;
        }
      }
    }
  }
}

function showHideEmailServiceScore()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_emailservice_minscore");
    if(row)
    {
      showHideTR(row,getListboxValue("select_emailservice") == "1");
    }
  }
}

function toggleCollapse(id)
{
  var el=document.getElementById(id);
  if(el)
  {
    if(el.style.display == "none")
    {
      // open:
      el.style.display="block";
      window.location.href="#_end";
      setImage(id+"_i",IMGROOTURL+"tridown.gif");
    }
    else
    {
      el.style.display="none";
      setImage(id+"_i",IMGROOTURL+"triright.gif");
    }
  }
}

function toggleCollapseButton(id)
{
  var abtn=document.getElementById(id+"_btn");
  var adiv=document.getElementById(id+"_div");
  if(abtn && adiv)
  {
    if(adiv.style.display == "none")
    {
      // open:
      adiv.style.display="block";
      abtn.style.display="none";
    }
    else
    {
      adiv.style.display="none";
      abtn.style.display="inline";
    }
  }
}

function makeCollapse(id,caption,divclass)
{
  var collapsejs="toggleCollapse('"+id+"');";
  var atag="<a href=\"#"+id+"_1\" onclick=\""+collapsejs+"\">";
  var o="";
  o += "<a name=\""+id+"_1\"></a>";
  o += atag+"<img src=\""+IMGROOTURL+"triright.gif\" id=\""+id+"_i\"></a>&nbsp;";
  o += atag+caption+"</a>";
  o += "<div id=\""+id+"\"";
  if(divclass != "")
  {
    o += " class=\""+divclass+"\"";
  }
  o += " style=\"display: none\">";
  document.write(o);
  document.write("<div style=\"display: none\">");
}

function makeCollapseButton(id,caption,divclass)
{
  var collapsejs="toggleCollapseButton('"+id+"');";
  var btn="<input id=\""+id+"_btn\" class=\"button\" type=\"button\" onclick=\""+collapsejs+"\" value=\""+caption+"\">";
  var o="";
  o += btn+"<br>";
  o += "<div id=\""+id+"_div\"";
  if(divclass != "")
  {
    o += " class=\""+divclass+"\"";
  }
  o += " style=\"display: none\">";
  document.write(o);
  document.write("<div style=\"display: none\">");
}

function openPopup(url)
{
  var hwnd=window.open(url,"ddate_popup","directories=no,location=no,menubar=no,resizable=yes,scrollbars=1,status=yes,titlebar=yes,toolbar=yes,height=500,width=500");
  if(hwnd)
  {
    hwnd.focus();
    return false;
  }
  else
  {
    return true;
  }
}

function openFotoPopup(url)
{
  var hwnd=window.open(url,"ddate_fotoopup","directories=no,location=no,menubar=no,resizable=yes,scrollbars=1,status=yes,titlebar=yes,toolbar=yes,height=480,width=300");
  if(hwnd)
  {
    hwnd.focus();
    return false;
  }
  else
  {
    return true;
  }
}

function showLogin()
{
  if(document.getElementById)
  {
    var loginblock=document.getElementById("loginblock");
    var loginblockcollapsed=document.getElementById("loginblockcollapse");
    if(loginblock && loginblockcollapsed)
    {
      loginblockcollapsed.style.visibility='hidden';
      loginblock.style.visibility='visible';
    }
  }
}

function closeWindow()
{
  window.close();
  return false;
}

function toggleLoginCollapse()
{
  var loginsubblock=document.getElementById("loginextrablock");
  if(loginsubblock)
  {
    var isvisible=loginsubblock.style.visibility == "visible";
    loginsubblock.style.visibility=isvisible? "hidden":"visible";
    var img=isvisible? "collapse_blue.gif":"expand_blue.gif";
    setImage("logincollapseimg",IMGROOTURL+"mainlayout/"+img);
  }
}

function inputCheckEmpty(el,focused,emptystring)
{
  var v=trimString(el.value);
  if(focused)
  {
    if(v == emptystring)
    {
      el.value="";
      el.style.color='rgb(0,0,128)';
    }
  }
  else
  {
    if( (v == "") || (v == emptystring) )
    {
      el.style.color='rgb(100,100,100)';
      el.value=emptystring;
    }
  }

}

function trimString(s)
{
  s=s.replace(/^\s+/,"");
  s=s.replace(/\s+$/,"");
  return s;
}

function commentChange(listbox,taname)
{
  var index=listbox.selectedIndex;
  if(index < 1) return;
  var value=listbox.options[index].value;
  var now=new Date();
  var printdate=now.getDate()+"/"+(1+now.getMonth())+"/"+now.getFullYear()+" "+now.getHours()+":"+(now.getMinutes()<10? "0":"")+now.getMinutes();
  var id=username;
  var ta=listbox.form.elements[taname];
//  ta.value += "\n"+"("+printdate+" "+id+") "+value;
  ta.value = "("+printdate+" "+id+") "+value+"\n"+ta.value;
  listbox.selectedIndex=0;
  ta.focus();
  rng=ta.createTextRange();
  rng.collapse(false);
  rng.select();
}

function wbStart(firstradio_id)
{
  if(geschiktVoorTrackbar())
  {
    var weightbar_id=firstradio_id+"_wb";
    var weightbarimage_id=firstradio_id+"_wbi";
    document.write("<div class=\"wb\" id=\""+weightbar_id+"\" onmousedown=\"wbMousedown(event,'"+firstradio_id+"')\"><img class=\"wbi\" id=\""+weightbarimage_id+"\" src=\""+IMGROOTURL+"weightbar_button.gif\" onmousedown=\"wbiMousedown(event,'"+firstradio_id+"')\" onmousemove=\"wbiMousemove(event,'"+firstradio_id+"')\" onmouseup=\"wbiMouseup(event,'"+firstradio_id+"')\"></div><span class=\"hidden\">");
    addOnLoad("initWb('"+firstradio_id+"');");
  }
}

function wbEnd()
{
  if(geschiktVoorTrackbar())
  {
    document.write("</span>");
  }
}

function initWb(firstradio_id)
{
  var value=getRadioValue(firstradio_id);
  var weightbarimage_id=firstradio_id+"_wbi";
  var weightbarimg=document.getElementById(weightbarimage_id);
  if(weightbarimg)
  {
    weightbarimg.style.left=wbNum2Pos(value)+"px";
    //weightbarimg.style.paddingLeft=wbNum2Pos(value)+"px";
    weightbarimg.style.display="inline";
    var src=IMGROOTURL+"weightbar_button";
    if(value == 2)
    {
      src += "red";
    }
    src += ".gif";
    weightbarimg.src=src;
  }
}

function getRadioValue(radioid)
{
  return getSetRadioValue(radioid,false,0);
}

function setRadioValue(radioid,value)
{
  return getSetRadioValue(radioid,true,value);
}

function getSetRadioValue(radioid,write,newvalue)
{
  var firstradio=document.getElementById(radioid);
  var value=null;
  if(firstradio)
  {
    var radios=firstradio.form.elements[firstradio.name];
    for(var i=0; i < radios.length; i++)
    {
      var r=radios[i];
      if(write)
      {
        if(r.value == newvalue)
        {
          r.checked=true;
          break;
        }
      }
      else
      {
        if(r.checked)
        {
          value=r.value;
          break;
        }
      }
    }
  }
  return value;
}

function wbNum2Pos(num)
{
  return 6+21*(num-(-2));
  //return 21*(num-(-2));
}

function wbPos2Num(pos)
{
  var num=((pos-6.0)/21.0)-2.0;
  num=Math.floor(num+0.5);
  if(num < -2) num=-2;
  if(num > 2) num=2;
  return num;
}

var _wbidragging=null;
var _dragoffset=0;
function wbiMousedown(event,firstradio_id)
{
  _wbidragging=firstradio_id;
  var xcoord=event.clientX;
  var value=getRadioValue(firstradio_id);
  _dragoffset=xcoord-wbNum2Pos(value);
  event.returnValue = false;
  event.cancelBubble = true;
}

function wbMousedown(event,firstradio_id)
{
  var xcoord=event.offsetX;
  if(xcoord == null)
  {
    xcoord=event.layerX;
  }
  if(xcoord != null)
  {
    var newvalue=wbPos2Num(xcoord);
    var currentvalue=getRadioValue(firstradio_id);
    if(newvalue != currentvalue)
    {
      setRadioValue(firstradio_id,newvalue+"");
      initWb(firstradio_id);
    }
  }
  event.returnValue = false;
  event.cancelBubble = true;
}

function wbiMousemove(event,firstradio_id)
{
  if(_wbidragging==firstradio_id)
  {
    var xcoord=event.clientX;
    var pos=xcoord-_dragoffset;
    var newvalue=wbPos2Num(pos);
    var currentvalue=getRadioValue(firstradio_id);
    if(newvalue != currentvalue)
    {
      setRadioValue(firstradio_id,newvalue+"");
      initWb(firstradio_id);
    }
    event.returnValue = false;
    event.cancelBubble = true;
  }
}

function wbiMouseup(event,firstradio_id)
{
  _wbidragging=null;
}

function geschiktVoorTrackbar()
{
//  if(navigator.userAgent.indexOf("Gecko/20041107") >= 0) return false;
  if(navigator)
  {
    if(navigator.appName == "Microsoft Internet Explorer")
    {
      if(navigator.appVersion.indexOf("MSIE 5.0; Macintosh;") >= 0)
      {
        return false;
      }
    }
  }
  return true;
}

function dboeketGekozen()
{
  var dboeketid=getListboxValue("id_dboeket_boeket");
  var p=dboeketid.indexOf("|");
  var prijs=null;
  var totaalbedrag=null;
  var kosten=8.50;
  if(p >= 0)
  {
    prijs=dboeketid.substring(p+1)-0.00;
    totaalbedrag=prijs+kosten;
  }
  document.getElementById("id_dboeket_prijs").innerHTML=formatEuro(prijs);
  document.getElementById("id_dboeket_kosten").innerHTML=formatEuro(kosten);
  document.getElementById("id_dboeket_totaalbedrag").innerHTML="<b>"+formatEuro(totaalbedrag)+"</b>";
}

function formatEuro(bedrag)
{
  if(bedrag == null) return "";
  bedrag=Math.floor(bedrag*100.0);
  var heel=Math.floor(bedrag/100);
  var rest=bedrag % 100;

  var out="EUR ";
  out += heel+",";
  if(rest == 0)
  {
    out += ",--";
  }
  else
  {
    if(rest < 10)
    {
      out += "0"+rest;
    }
    else
    {
      out += rest;
    }
  }
  return out;
}

function boeketSubmit(frm)
{

/*
  var datumindex=frm.elements["db_dboeket_datum"].selectedIndex;
  var eerstgegarandeerd=frm.elements["eerstgegarandeerd"].value;
  if(datumindex < eerstgegarandeerd)
  {
    return confirm('U heeft de datum gewijzigd in een vroegere termijn dan gegarandeerd kan worden. D-Date doet haar best dit voor u te regelen doch kan de aflevering op dit tijdstip niet garanderen.');
  }
*/
  var btn=frm.elements["submit"];
  if(btn.disabled != null)
  {
    btn.disabled=true;
  }
  btn.style.color="rgb(128,128,128)";
  return true;
}

function showHidePoll1_9()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_poll1_10");
    var value=getListboxValue("select_poll1_9");
    if(row)
    {
      showHideTR(row,(value == "anders"));
    }
  }
}

function showHidePoll1_14_15_16()
{
  if(document.getElementById)
  {
    var row1=document.getElementById("tr_poll1_14");
    var row2=document.getElementById("tr_poll1_15");
    var row3=document.getElementById("tr_poll1_16");
    var value=getListboxValue("select_poll1_13");
    if(row1 && row2 && row3)
    {
      showHideTR(row1,(value == "J"));
      showHideTR(row2,(value == "J"));
      showHideTR(row3,(value == "J"));
    }
  }
}


function showHidePoll2_16()
{
  if(document.getElementById)
  {
    var row1=document.getElementById("tr_poll2_17");
    var value=getListboxValue("select_poll2_16");
    if(row1)
    {
      showHideTR(row1,(value == "niet"));
    }
  }
}

function phs(title,body)
{
  return overlib(body,CAPTION,title,WIDTH,200,FIXX,90);
}

function phh()
{
  return nd();
}

function showHidePoll3_2()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_poll3_3");
    var value=getListboxValue("select_poll3_2");
    if(row)
    {
      showHideTR(row,(value == "N"));
    }
  }
}

function showHidePoll3_5()
{
  if(document.getElementById)
  {
    var row=document.getElementById("tr_poll3_6");
    var value=getListboxValue("select_poll3_5");
    if(row)
    {
      showHideTR(row,(value == "anders"));
    }
  }
}

function showHidePoll3_10()
{
  if(document.getElementById)
  {
    var row1=document.getElementById("tr_poll3_11");
    var row2=document.getElementById("tr_poll3_12");
    var row3=document.getElementById("tr_poll3_13");
    var row4=document.getElementById("tr_poll3_14");
    var value=getListboxValue("select_poll3_10");
    if(row1 && row2 && row3 && row4)
    {
      showHideTR(row1,(value == "J"));
      showHideTR(row2,(value == "J"));
      showHideTR(row3,(value == "J"));
      showHideTR(row4,(value == "J"));
    }
  }
}

var _foto_pop_up=false;
function fotoover(object)
{
    if(!_foto_pop_up) {
        // First display block, then scale image. Else Safari doesnt get it and gives image size = 0.
        div = object.getElementsByTagName('div')[0];
        div.style.visibility = "hidden";
        div.style.display = "block";
        img = object.getElementsByTagName('img')[0];
        object.style.outline = "none";
        object.focus()
        maxW = 400;
        maxH = 300;
        maxF = maxW/maxH
        w=img.width;
        h=img.height;
        f = w/h;
        if(w > maxW && maxF < f) {
            img.width=maxW;
            img.height=maxW / f;
        }
        if(h > maxH && maxF >= f){
            img.width=maxH * f;
            img.height=maxH;
        }
        div.style.visibility = "visible";
        result_table = document.getElementById('sr');
        images = result_table.getElementsByTagName('img');
        for (var i=0; i < images.length; i++) {
            if(images[i].className!="result_picture_popup_image") {
                images[i].style.visibility = "hidden";
            }
        }
        _foto_pop_up=true;
    }
}

function fotoout(object)
{
    if(_foto_pop_up) {    
        div = object.getElementsByTagName('div')[0];
        div.style.display = "none";
        result_table = document.getElementById('sr');
        images = result_table.getElementsByTagName('img');
        for (var i=0; i < images.length; i++) {
            images[i].style.visibility = "visible";
        }
        _foto_pop_up=false;
    }
}

function showHidePoll4()
{
/*
  if(document.getElementById)
  {
    var heeftrelatie=getListboxValue("select_poll4_3");
    var heeftrelatiegehad=getListboxValue("select_poll4_31");
    var i;
    for(i=4; i <= 29; i++)
    {
      var row=document.getElementById("tr_poll4_"+i);
      showHideTR(row,(heeftrelatie == "J"));
    }
    for(i=30; i <= 31; i++)
    {
      var row=document.getElementById("tr_poll4_"+i);
      showHideTR(row,(heeftrelatie == "N"));
    }
    for(i=32; i <= 49; i++)
    {
      var row=document.getElementById("tr_poll4_"+i);
      showHideTR(row,(heeftrelatie == "N") && (heeftrelatiegehad == "J"));
    }
  }
*/
}

function setAVAkkoordTxt()
{
  if(document.getElementById)
  {
    var value=getListboxValue("select_membertype");
    var span_avbeperkt=document.getElementById("avbeperkt");
    var span_avonbeperkt=document.getElementById("avonbeperkt");
    if(value == "BEPERKT")
    {
      span_avbeperkt.style.display="inline";
      span_avonbeperkt.style.display="none";
    }
    else
    {
      span_avbeperkt.style.display="none";
      span_avonbeperkt.style.display="inline";
    }
  }
}

function setRandomBorderImage()
{
  // Set up the image files to be used.
  var theImages = new Array() // do not change this
  // To add more image files, continue with the
  // pattern below, adding to the array.

  theImages[0] = 'geel1.jpg';
  theImages[1] = 'geel2.jpg';
  theImages[2] = 'geel3.jpg';
  theImages[3] = 'geel4.jpg';
  theImages[4] = 'geel5.jpg';
  theImages[5] = 'geel6.jpg';
  theImages[6] = 'grijs1.jpg';
  theImages[7] = 'grijs2.jpg';
  theImages[8] = 'grijs3.jpg';
  theImages[9] = 'grijs4.jpg';
  theImages[10] = 'grijs5.jpg';
  theImages[11] = 'grijs6.jpg';
  theImages[12] = 'rood1.jpg';
  theImages[13] = 'rood2.jpg';
  theImages[14] = 'rood3.jpg';
  theImages[15] = 'rood4.jpg';
  theImages[16] = 'rood5.jpg';
  theImages[17] = 'rood6.jpg';

  // do not edit anything below this line

  var j = 0;
  var p = theImages.length;
  var preBuffer = new Array();
  for (i = 0; i < p; i++){
//     preBuffer[i] = new Image();
//     preBuffer[i].src = theImages[i];
  }   
  var whichImage = Math.round(Math.random()*(p-1));
  if (whichImage < 6)
  {
    document.getElementById('fixed6').style.backgroundImage='url("/ddatev3/images/zijkant/'+theImages[whichImage]+'")';
  } else {
    if (whichImage < 12)
    {
      document.getElementById('fixed5').style.backgroundImage='url("/ddatev3/images/zijkant/'+theImages[whichImage]+'")';
    } else {
      document.getElementById('fixed7').style.backgroundImage='url("/ddatev3/images/zijkant/'+theImages[whichImage]+'")';
    }
  }
}

function capsLock(e)
{
    kc = e.keyCode?e.keyCode:e.which;
    sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
    if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
	{
        document.getElementById('divCapsLock').style.visibility = 'visible';
	} else {		
        document.getElementById('divCapsLock').style.visibility = 'hidden';
	}
} 

var cookiesEnabled = false;

function getCookie(cookieName)
{
  var cookieFoundAt;
  var cookieValue;

  // find start position in cookie string
  cookieFoundAt = document.cookie.indexOf(cookieName + "=");
    if (cookieFoundAt < 0)
     {
        cookieValue = "";
     }
  else
     {
        // move to actual start of cookies data
        cookieFoundAt = document.cookie.indexOf("=",cookieFoundAt);
        cookieFoundAt++;
                // find end position of cookies data
        cookieEnd = document.cookie.indexOf(";", cookieFoundAt);
        if (cookieEnd == -1)
           {
            cookieEnd = document.cookie.length - 1;
           }
        cookieValue =document.cookie.substring(cookieFoundAt,cookieEnd  );
     }
  return cookieValue;
}

	function setMaaktNietUIt(myCheckBox) {
		var registrerenForm = myCheckBox.form;
//document.getElementById(formname); 
	 	var inputTags = registrerenForm.getElementsByTagName("input"); 
		var inputName = myCheckBox.name;
		var tagsLength = inputTags.length;
		if (myCheckBox.value == 'maakt niet uit') {
			//zet alle andere uit
			for (var i=0; i < tagsLength; i++) {
        		if (inputTags[i].name == inputName) {
					if (inputTags[i].value != 'maakt niet uit') {
						inputTags[i].checked = false;
					}
         		}
    		} 
		} else {
			//zet 'maakt niet uit' uit
			for (var i=0; i < tagsLength; i++) {
        		if (inputTags[i].name == inputName) {
	        		if (inputTags[i].value == 'maakt niet uit') {
						inputTags[i].checked = false;
					}
         		}
    		} 
		}
	}
	
