var bodyHeightSubtract = 0;
var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isLoaded = 0;
var isNetscape = (navigator.appName == "Netscape");
var last_active_element = "";
var last_element = new Array(); //content in usp table
last_element[0] = "";
var prevHeight = 0;
var prevWidth = 0;
var usp_text0 = new Array(); //default text in usp table
usp_text0[0] = "";
// when testing bodyHeight function:
function afterLoad() {
//records isLoaded and does onResize()
isLoaded = 1;
onLoadFunctions();
onResize();
}
function bodyHeight(subtract) {
// do at changing size also on load (through onResizeFunctions)
// expecting a div with id "body0" setting at height minus "subtract":
// or a "leftpart" (only IE); with Netscape 15 more
    bodyHeightSubtract = subtract;
    var height = 0;
    var dh = document.body.clientHeight;
    if (subtract > 0 && dh > subtract) {
    var height = dh - subtract;
    if (isNetscape)
        height += 15;
    }
    else
    var d = null;
    if (isNetscape)
        var d = document.getElementById("leftpart");
    if (d == null)
         d = document.getElementById("body0");
    if (d == null) {
    alert("no such id: leftpart or body0");
    return;
    }
    d.style.height = height;
    d = document.getElementById("body0");
}
function bodyHeightTest(subtract) {
// do at changing size also on load (through onResizeFunctions)
// expecting a div with id "body0" setting at height minus "subtract":
// or a "leftpart" (only IE); with Netscape 15 more
    var height = 0;
    var dh = document.body.clientHeight;
    var t = prompt("subtract is nu: " + bodyHeightSubtract + ", geef nieuwe:", subtract);
    var substract = parseInt(t);
    if (substract <= 0)
         return;
    bodyHeight(subtract);
    }
function changeSize(frameName, Width, Height, minWPadding, minHPadding, scale) {
// do at changing size also on load
// expecting a div with id "frameName":
var dw = parseInt(document.body.clientWidth*scale);
var d = document.getElementById(frameName);
if (d == undefined) {
    alert("no such id: frame");
    return;
}
var p = String(minWPadding);
var q = String(minHPadding);
if (Width > 0 && dw > Width)
   var p = String(Math.max(minWPadding, parseInt((dw-Width)/2)));
var dh = document.body.clientHeight;
if (Height > 0 && dh > Height)
   var q= String(Math.max(minHPadding, parseInt((dh-Height)/2)));
//style_node.appendChild(document.createTextNode(
var selector = "#" + frameName;
var declaration = "padding: " + q + " " + p;
setCssStyleScreenOnly(selector, declaration);
}
function copyArrayToElement(fromArray, toElement) {
    //first empty element
    while (toElement.hasChildNodes()) {
        toElement.removeChild(toElement.lastChild);
    }
    for (var i = 0; i<fromArray.length; i++)
        if (fromArray[i] != "")
               toElement.appendChild(fromArray[i]);
}
function copyElementToArray(fromElement, toArray) {
    var kids = fromElement.childNodes;
    var numkids = kids.length;
    for (var i = 0; i<toArray.length; i++)
        toArray[i] = "";
    for (var i=0; i<numkids; i++) {
        var clone = kids[i].cloneNode(true);
    //alert("i:"+i+ " clone:"+clone);
        toArray[i] = clone;
        }
}
function doNetscapeCss(prefix, fileName) {
    if (isNetscape) {
        var t = '<link rel="stylesheet" href="'+prefix+fileName+'" type="text/css" title="'+fileName+'">';
  // alert("t:" + t);
        w(t);
    }
}
function doReload() {
    //reloads if height or width changed more than 10 pixels
var dw = document.body.clientWidth;
var dh = document.body.clientHeight;
var deltax = Math.abs(prevWidth-dw);
var deltay = Math.abs(prevHeight-dh);
if (deltax < 10 && deltay < 50)
    return;
document.location.href = document.location.href;
}
function flashtest(filename) {
    var dw = document.body.clientWidth;
    var dh = document.body.clientHeight-230;
w('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550");height="400" id="'+filename+'" align="middle">');
w('<param name="allowScriptAccess" value="sameDomain" />');
w('<param name="movie" value="'+filename+'.swf" />');
w('<param name="quality" value="high" />');
w('<param name="bgcolor" value="#000000" />');
w('<embed src="'+filename+'.swf" quality="high" bgcolor="#ffffff" width="'+dw+'" height="'+dh+'" name="'+filename+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
w('</object>');
}
function getSize(w) {
  var myWidth = 0, myHeight = 0;
  if( typeof( w.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = w.innerWidth;
    myHeight = w.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return Array(myWidth, myHeight);
}
function hello() {
    var win = window._content.top;
    var doc = win.document;
    var Frames = win.frames;
    var t = "";
    alert("hello");
    if (Frames.length > 0) {
        alert("frames:" + Frames.length);
        t = 'Frames:'
        for (var f in Frames)
            t += "\n"+f.document.name;
        alert(t);
    }
    else {
        t = "location:"+win.location+"\ndocument:"+doc.title;
        alert(t);
    }
}
function hideMore(id) {
    //at start of page, hide the Lees verder part
var d = document.getElementById(id);
if (d === null) {
    alert("no such id: "+id);
    return;
}
d.style.display = "none";
}
function indexmenu(Pic, Width, Height, Cl, Link, Text, Additional, Scale) {
    var L = Pic.length;
    var mw = 0;
    var paddingFactor = 0.98;
    for (var i=0; i<L; i++) {
        mw = Math.max(mw, Width[i]);
    }
    //width times Scale, that accounts for leftMenuWidth times
    //paddingFactor (above) which accounts for padding.
    var dw = document.body.clientWidth*Scale*paddingFactor;
    var nCol = Math.min(parseInt(dw/(mw+10)), L);
    e = '<table class="picmenu" border="0" cellpadding="0" cellspacing="0" width="100%">';
    document.write(e);
    document.write('<tr><td height="10"><td></tr><tr>');
    var al = "center";
    var im = '';
    var li = '';
    var validCol = 0; // in case of empty columns
    for (var i=0; i<L; i++) {
        if (validCol%nCol == 0 && validCol > 0) {
            document.write('</tr><tr><td height="10"><td></tr><tr>');
        }
        if (Pic[i] != "") {
             im = '<img src="'+Pic[i]+'" width="' + Width[i]+
                      '" height="'+Height[i]+'" alt="' + Text[i] +
                     '">';
        }
        else {
// geen entry als geen plaatje
// im = Text[i];
            continue;
        }
        validCol++;
        if (Link[i] != "" && im != "") {
            li = '<a href="'+ Link[i] + '">' + im + '</a>';
        }
        else {
            li = im;
        }
        var textLink = '<a href="'+ Link[i] + '">' + Text[i] + "</a>";
      // if (Pic[i] == "" && Additional[i] != "")
      // li = li + "<br>"+Additional[i];
      // hier ook de link als text:
        li = li + "<br>" + textLink;
        document.write('<td class="' + Cl[i] + '" align="' +
                        'center' + '">' + li + '</td>');
    }
    document.write('</tr><tr><td height="10"><td></tr></table>');
}
function indexmenucount(Pic, Width, Height, Cl, Link, Text, Additional, Count, Scale) {
    var L = Pic.length;
    var mw = 0;
    var paddingFactor = 0.98;
    for (var i=0; i<L; i++) {
        mw = Math.max(mw, Width[i]);
    }
    //width times Scale, that accounts for leftMenuWidth times
    //paddingFactor (above) which accounts for padding.
    var dw = document.body.clientWidth*Scale*paddingFactor;
    var nCol = Math.min(parseInt(dw/(mw+10)), L);
    e = '<table class="picmenu" border="0" cellpadding="0" cellspacing="0" width="100%">';
    document.write(e);
    document.write('<tr><td height="10"><td></tr><tr>');
    var al = "center";
    var im = '';
    var li = '';
    for (var i=0; i<L; i++) {
        if (i%nCol == 0 && i > 0) {
        document.write('</tr><tr><td height="10"><td></tr><tr>');
        }
        if (Pic[i] != "") {
             im = '<img src="'+Pic[i]+'" width="' + Width[i]+
                      '" height="'+Height[i]+'" alt="' + Text[i] +
                     '">';
        }
        else {
            im = Text[i];
        }
        if (Link[i] != "") {
            li = '<a href="'+ Link[i] + '">' + im + '</a>';
        }
        else {
            li = im;
        }
        if (Pic[i] == "" && Additional[i] != "")
            li = li + "<br>"+Additional[i];
        if (Count[i] > 1)
            li = li + '&nbsp;('+Count[i]+')';
        document.write('<td class="' + Cl[i] + '" align="' +
                        'center' + '">' + li + '</td>');
    }
    document.write('</tr><tr><td height="10"><td></tr></table>');
}
function m(a, b, s, t) {
var mm;mm='<a href="';mm=mm+'mailto';mm+=":"+b;mm+="@"+a;
if(s){mm+="?subj";mm+="ect="+s};mm+='">';
if(t)mm=mm+t;else mm=mm+b+"@"+a;mm+="</a>";w(mm);
}
function onResize() {
    //acts if height or width changed more than 10 pixels
    if (!isLoaded) return;
    var dw = document.body.clientWidth;
    var dh = document.body.clientHeight;
    var deltax = Math.abs(prevWidth-dw);
    var deltay = Math.abs(prevHeight-dh);
    if (deltax < 10 && deltay < 50)
    return;
    prevHeight=dh;
    prevWidth=dw;
    onResizeFunctions();
}
function onResizeReload() {
    //reloads if height or width changed more than 10 pixels
    if (!isLoaded) return;
    var dw = document.body.clientWidth;
    var dh = document.body.clientHeight;
    var deltax = Math.abs(prevWidth-dw);
    var deltay = Math.abs(prevHeight-dh);
    if (deltax < 25 && deltay < 50)
    return;
    document.location.href = document.location.href;
}
function photopage(Text, Pic, Width, Height, AltText, Scale, SplitAt) {
    var L = Pic.length;
    var mw = 0;
    var padding = 20;
    for (var i=0; i<L; i++) {
        mw = Math.max(mw, Width[i]);
    }
    //width times Scale, that accounts for leftMenuWidth times
    //paddingFactor (above) which accounts for padding.
    var available = document.body.clientWidth*Scale - 2*padding;
    var dw = available*(1.0-SplitAt);
    var wide = 0;
    var leftandright = 0;
    if (dw > mw) wide = 1;
    else {
        if (available > mw)
            leftandright = (available - mw)/2;
    }
// comment = 'wide; ' + wide + ' available: '+available + ' mw: '+ mw + ' leftandright:' + leftandright;
// document.write('<p>'+comment+'</p>');
    document.write('<table class="inbody" border="0" cellpadding="0" cellspacing="0" width="100%">');
    for (var i=0; i<L; i++) {
        document.write('<tr><td height=10></td></tr>')
        if (wide == 0) {
            // onder elkaar!!
            if (Text[i] != "") {
                document.write('<tr><td height=10></td></tr>');
                document.write('<tr>');
                if (leftandright > 0)
                     document.write('<td width="'+leftandright+'"></td>');
                document.write('<td class="ibtop" align="left">' + Text[i]+ '</td></tr>');
                if (leftandright > 0)
                     document.write('<td width="'+leftandright+'"></td>');
                document.write('<tr><td height=10></td></tr>')
            }
            if (Pic[i] != "") {
                document.write('<tr>');
                 if (leftandright > 0)
                     document.write('<td width="'+leftandright+'"></td>');
                document.write('<td class="ibpbottom" align="left">');
                document.write('<img src="'+Pic[i]+'" width="' + Width[i]+
                      '" height="'+Height[i]+'" alt="' + AltText[i]+
                     '">');
                document.write('</td>');
                 if (leftandright > 0)
                     document.write('<td width="'+leftandright+'"></td>');
                 document.write('</tr>');
            }
        }
        else {
            // naast elkaar!!
            // altijd (eventueel lege) tekst:
            // eventueel test:' dw:' + dw + ' mw: ' + mw + ' wide: ' + wide +
            document.write('<tr><td class="ibleft" width="50%">' + Text[i]+'</td>');
            if (Pic[i] != "") {
                 document.write('<td class="ibpright" align="left">');
                 document.write('<img src="'+Pic[i]+'" width="' + Width[i]+
                      '" height="'+Height[i]+'" alt="' + AltText[i]+
                     '">');
                 document.write('</td></tr>');
            }
            else {
                document.write('<td></td></tr>');
            }
        }
    }
    document.write('<tr><td height=10></td></tr>')
    document.write('</table>');
}
function picmenu(Pic, Width, Height, Cl, Link, Text, Scale) {
    var L = Pic.length;
    var mw = 0;
    var paddingFactor = 0.85;
    for (var i=0; i<L; i++) {
        mw = Math.max(mw, Width[i]);
    }
    //width times Scale, that accounts for leftMenuWidth times
    //paddingFactor (above) which accounts for padding.
    var dw = document.body.clientWidth*Scale*paddingFactor;
    var nCol = Math.min(parseInt(dw/(mw+10)), L);
    e = '<table class="picmenu" border="0" cellpadding="0" cellspacing="0" width="100%">';
    document.write(e);
    document.write('<tr><td height="10"><td></tr><tr>');
    var al = "center";
    var im = '';
    var li = '';
    for (var i=0; i<L; i++) {
        if (i%nCol == 0 && i > 0) {
        document.write('</tr><tr><td height="10"><td></tr><tr>');
        }
        if (Pic[i] != "") {
             im = '<img src="'+Pic[i]+'" width="' + Width[i]+
                      '" height="'+Height[i]+'" alt="' + Text[i]+
                     '">';
        }
        else {
            im = Text[i];
        }
        if (Link[i] != "") {
            li = '<a href="'+ Link[i] + '">' + im + '</a>';
        }
        else {
            li = im;
        }
        // if want texts:
        li = li + '<br>' + Text[i];
        document.write('<td class="' + Cl[i] + '" align="' +
                        'center' + '">' + li + '</td>');
    }
    document.write('</tr><tr><td height="10"><td></tr></table>');
}
function prelima(Name, Width, Height) {
    var L = Name.length;
    for (var i=0; i<L; i++) {
        (new Image(Width[i], Height[i])).src = Name[i];
    }
}
function resizeprint(doResize, language) {
//sizes to convenient format for printing
alert ('doResize: '+doResize);
if (doResize != 1) {
    window.print();
    return;
}
alert('href:'+window.location.href);
var w = window.open(window.location.href, 'Sample', 'width=800,height=600');
w.print();
alert('close againsize:');
w.close();
}
function setCssStyleScreenOnly(selector, declaration) {
// set style for element screen only. declaration WITHOUT braces!!
// example: see changeSize.
if (!isIE) { // firefox:
    var style_node = document.createElement("style");
    style_node.setAttribute("type", "text/css");
    style_node.setAttribute("media", "screen");
    var text = selector + "{" + declaration + "}";
    style_node.appendChild(document.createTextNode(text));
    // append the style node:
    document.getElementsByTagName("head")[0].appendChild(style_node);
}
else { //IE
   if (declaration.indexOf("url(../") >= 0){
    declaration = declaration.replace(/..\//g, "");
   }
   if (document.styleSheets && document.styleSheets.length > 0) {
         var last_style_node = document.styleSheets[document.styleSheets.length - 1];
         if (typeof(last_style_node.addRule) == "object") last_style_node.addRule(selector, declaration);
        }
}
}
function setbackgroundimage(baseoffile, minh, maxh, steph) {
    var b = document.body;
       var dh = b.clientHeight;
       for (h=minh; h <maxh; h += steph) {
       if (dh <= h) {
               var name = baseoffile + h + ".jpg";
                     var bgim = "url(" + '"' + name + '"' + ")";
             // alert ("height: " + dh + " name: " + name + " bgim: " + bgim);
                    b.style.backgroundImage =bgim;
                    return;
            }
        }
           var name = baseoffile + maxh + ".jpg";
             var bgim = "url(" + '"' + name + '"' + ")";
     // alert ("else, height: " + dh + " name: " + name + " bgim: " + bgim);
        b.style.backgroundImage=bgim;
}
function showMore(id) {
    //show Lees verder part hide id+"link"
var d = document.getElementById(id);
if (d === null) {
    alert("no such id: "+id);
    return;
}
d.style.display = "inline";
d = document.getElementById(id+"link");
if (d === null) {
    return;
}
d.style.display = "none";
}
function sidebarindent(n){
var dh = document.body.clientHeight;
var h = parseInt(n*dh/40);
var d = document.getElementById("sidebarindent");
if (d == undefined) {
    alert("no such id: sidebarindent");
    return;
}
d.style.padding = h;
}
function tdhide(idnum) {
//do a (closing) hide by leaving a table usp cell, for tableusp and tableusp2
var tfield = document.getElementById(idnum+'t');
tfield.className = "tduspsb";
var e=document.getElementById(idnum+'h');
var f=document.getElementById('tduspe');
copyArrayToElement(usp_text0, f);
}
function tdshow(idnum) {
//do show in usp table (from tableusp and tableusp2)
if (last_active_element)
    tdhide(last_active_element);
last_active_element = idnum;
var tfield = document.getElementById(idnum+'t');
tfield.className = "tduspsa";
var e=document.getElementById(idnum+'h');
var f=document.getElementById('tduspe');
var toChild = f.lastChild;
// first time copy contents to array:
if (usp_text0.length == 1 && usp_text0[0] == "" && f.hasChildNodes())
    copyElementToArray(f, usp_text0);
//copy contents to last_array:
copyElementToArray(e, last_element);
//put element in e cell:
copyArrayToElement(last_element, f);
}
function tdshowextra(activebutton) {
//do show last content in extra cell
var efield = document.getElementById('tduspe');
//put element in e cell:
copyArrayToElement(last_element, efield);
//alert("extra"+efield);
if (last_active_element != "") {
    var tfield = document.getElementById(last_active_element+'t');
    tfield.className = "tduspsa";
    }
}
function validateForm(f) {
    var aanaf = "";
    for (var i=0; i < f.length; i++) {
        var e = f.elements[i];
        if (e.type == "radio" && e.checked){
            var aanaf = e.value;
    }
    }
    if (!aanaf) {
        alert("Kies Aanmelden of Afmelden s.v.p.");
        return false;
    }
    aanaf = aanaf.toLowerCase();
  var text = "Er wordt nu (op uw computer) een e-mail gemaakt met uw gegevens.\n\nNadat u deze e-mail hebt verzonden verwerken wij uw aan/afmelding.";
        if (aanaf == "aanmelden")
     var text = "Er wordt nu (op uw computer) een e-mail gemaakt met uw gegevens.\n\nNadat u deze e-mail hebt verzonden hebt u zich aangemeld en ontvangt u onze nieuwsbrieven.";
    if (aanaf == "afmelden")
       var text = "Er wordt nu (op uw computer) een e-mail gemaakt met uw gegevens.\n\nNadat u deze e-mail hebt verzonden schrappen wij u van onze mailinglijst. U kunt zich later altijd weer aanmelden.";
   text = text + "\n\nVriendelijke groet, Jochem en Anna, Bezoekerscentrum De Breek."
   alert(text);
   return true;
}
function w(t) {
    // helper function
    document.write(t);
}
