﻿String.prototype.ltrim = function () { return this.replace(/^ */, ""); } 
String.prototype.rtrim = function () { return this.replace(/ *$/, ""); } 
String.prototype.trim  = function () { return this.ltrim().rtrim(); }

var currentZoekTekst = "";
var currentContactTekst = "";

function doZoekTekst()
{
    try
    {
        var newTekst = document.getElementById("ZoekPnl1_TextBox1").value.trim();
        if (newTekst != currentZoekTekst)
        {
            currentZoekTekst = newTekst;
            __doPostBack('ZoekPnl1$Button1', '');
        }
    }
    catch (err) { }
}

function doContactTekst()
{
    try
    {
        var newTekst = document.getElementById("ContactPnl1_TextBox1").value.trim();
        if (newTekst != currentContactTekst)
        {
            currentContactTekst = newTekst;
            __doPostBack('ContactPnl1$Button1', '');
        }
    }
    catch (err) { }
}

setInterval("doZoekTekst()", 500);
setInterval("doContactTekst()", 500);

function switchContactButton(turnOn)
{
    var divObj = document.getElementById("vhHoofdmenu1_omvatPnl_5");
    var gifObj = document.getElementById("vhHoofdmenu1_contactGif_theGifImg");
    var arrowObj = document.getElementById("vhHoofdmenu1_contactBullet");
    
    if (turnOn)
    {
        divObj.className = "menuOmvat3";
        gifObj.src = gifObj.src.replace("vhHoofdmenu2", "vhHoofdmenu3");
        arrowObj.src = "/images/veldhoen/bulletWhite.gif";
    }
    else
    {
        divObj.className = "menuOmvat";
        gifObj.src = gifObj.src.replace("vhHoofdmenu3", "vhHoofdmenu1");
        arrowObj.src = "/images/veldhoen/bulletBlack.gif";
    }
}

function rechterPnlZoek()
{
    switchContactButton(false);
    document.getElementById('zoekPnl').style.display = 'block';
    document.getElementById('contactPnl').style.display = 'none';
    startSlide('moveDiv', -384)
}

function rechterPnlContact()
{
    switchContactButton(true);
    document.getElementById('zoekPnl').style.display = 'none';
    document.getElementById('contactPnl').style.display = 'block';
    startSlide('moveDiv', -384)
}

function rechterPnlClose()
{
    switchContactButton(false);
    startSlide('moveDiv', 0);
}

function setBijschriftWidth(divEle, spanEle, maxWidth)
{
    var totalPadding = 10;
    
    var w1 = 175 - totalPadding;
    var w2 = 367 - totalPadding;
    var w3 = 559 - totalPadding;
    var w4 = 751 - totalPadding;
    
    var divObj = document.getElementById(divEle);
    var spanObj = document.getElementById(spanEle);
    var spanWidth = spanObj.offsetWidth + totalPadding;
    
    var setW;
    
    if (spanWidth <= w1) setW = w1;
    else if (spanWidth <= w2) setW = w2;
    else if (spanWidth <= w3) setW = w3;
    else setW = w4;

    divObj.style.width = Math.min(maxWidth, setW) + 'px';
}

var activeOmvatDiv = ''
var activeInnerDiv = '';

function toonFilmpje(omvatDiv, innerDiv, videoID)
{
    // Evt. actieve filmpjes sluiten
    try
    {
        document.getElementById(activeInnerDiv).innerHTML = '';
        document.getElementById(activeOmvatDiv).style.display = 'none';
    }
    catch (err) { }
    
    // Geklikte filmpje op actief zetten
    activeInnerDiv = innerDiv;
    activeOmvatDiv = omvatDiv;
    
    // Dingen doen
    var w = 367;
    var h = 300;
    
    var omvatObj = document.getElementById(omvatDiv);
    var innerObj = document.getElementById(innerDiv);
    
    var videoURL = "http://vimeo.com/moogaloop.swf?clip_id=" + videoID + "&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=eb1b23&amp;fullscreen=1&autoplay=1";
    var video = "";
    
    video += "<div style='position: absolute;'>";
    video += "<object width='" + w + "' height='" + h + "'>";
    video += "<param name='allowfullscreen' value='true' />";
    video += "<param name='allowscriptaccess' value='always' />";
    video += "<param name='scale' value='showAll' />";
    video += "<param name='wmode' value='transparent' />";
    video += "<param name='movie' value='" + videoURL + "' />";
    video += "<embed src='" + videoURL + "' type='application/x-shockwave-flash' wmode='transparent' allowfullscreen='true' allowscriptaccess='always' width='" + w + "' height='" + h + "'>";
    video += "</embed>";
    video += "</object>";
    video += "</div>";
    
    innerObj.innerHTML = video;
    omvatObj.style.display = 'block';
}

function sluitFilmpje(omvatDiv, innerDiv)
{
    activeOmvatDiv = ''
    activeInnerDiv = '';
    
    var omvatObj = document.getElementById(omvatDiv);
    var innerObj = document.getElementById(innerDiv);
    
    innerObj.innerHTML = '';
    omvatObj.style.display = 'none';
}

function toonFoto(omvatDiv)
{
    // Evt. actieve foto sluiten
    try
    {      
        document.getElementById(activeOmvatDiv).style.display = 'none';
        document.getElementById(activeInnerDiv).innerHTML = '';
    }
    catch (err) { }
    
    // Geklikte foto op actief zetten
    activeOmvatDiv = omvatDiv;
    activeInnerDiv = '';
    
    // Dingen doen   
    var omvatObj = document.getElementById(omvatDiv);   
    omvatObj.style.display = 'block';
}

function sluitFoto(omvatDiv)
{
    activeOmvatDiv = ''
    activeInnerDiv = '';
    
    var omvatObj = document.getElementById(omvatDiv);   
    omvatObj.style.display = 'none';
}

function disableEnter(field, event)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) return false;
}
