var mdivPopup = '';
var menuActief = 0;
var MenubehoudItem=0;
var lastOpened;

var browser = navigator.appName + ' ' + navigator.appVersion.substring(22,25);

function setBg(p_strBgImage,p_strBgColor)
{
    ImageBG = new Image(); 
    ImageBG.src = "/image/bg2.jpg";
    heavyImage = new Image(); 
    heavyImage.onLoad = ShowBg(p_strBgImage,p_strBgColor);
    heavyImage.src = p_strBgImage;
}

function ShowBg(p_strBgImage,p_strBgColor)
{
    document.getElementById('centerContainer').style.backgroundColor=p_strBgColor;
    document.getElementById('centerContainer').style.backgroundImage="URL("+p_strBgImage+")";
}

function getHeight()
{
    document.getElementById('shadowRight').style.height=document.getElementById('centerContainer').offsetHeight+'px';
}

function showHide(info)
{
    var elm = document.getElementById(info);
    if(elm.style.display == 'none')
    {
        if (lastOpened) lastOpened.style.display='none'; 
        lastOpened = elm; 
    }
    elm.style.display = (elm.style.display=='none'?'block':'none');
}

var mdivPopup = '';

function showInfoPopup(anchorElement, p_strText, p_strGotoUrl) {
	try {
		PopupHTML = '<div style="background-color: window; color: windowtext;" onmouseover="this.style.cursor=\'pointer\'" onclick="window.location.href=\''+p_strGotoUrl+'\'">' + p_strText + '</div>';
		showPopup_(anchorElement, PopupHTML);
	}
	catch (x) {}
}

function showPopup_(anchorElement, innerHTML) {
	try {
		// Remove any existing popups
		if (mdivPopup != null)
			forceHidePopup();
		// Create the popup 
		mdivPopup = document.createElement('div');
		mdivPopup.style.position = 'absolute';
		mdivPopup.style.zIndex = 999999
		mdivPopup.style.backgroundColor = 'infobackground';
		mdivPopup.style.color = '#000066';
		mdivPopup.style.borderStyle = 'solid';
		mdivPopup.style.borderWidth = '1px';
		mdivPopup.style.borderColor = '#1845a2';
		mdivPopup.style.fontSize = '8pt';
		mdivPopup.style.width = '220px';
		mdivPopup.onmouseout = hidePopup;
		mdivPopup.className = 'infoPopUp';
		
		// Insert the content of the popup
				
		// Position the popup
		mdivPopup.style.top = (getAbsoluteTop(anchorElement) + 9) + 'px';				
		mdivPopup.style.left = (getAbsoluteLeft(anchorElement) + 9) + 'px';

		mdivPopup.innerHTML = innerHTML;
		
		// Show the popup
		document.body.appendChild(mdivPopup);
	}
	catch (x) {} 
}

function hidePopup() {
	try {
		if (mdivPopup != null) {
			forceHidePopup();
		}
	}
	catch (x) {}
}

function forceHidePopup() {
	try {
		if (mdivPopup != null) {
			document.body.removeChild(mdivPopup);
			mdivPopup = null;
		}
	}
	catch (x) {}
}


function getAbsoluteLeft(element) {
	try {
		var intLeft = 0;
		var objParent = element;
		
		do {
			intLeft += objParent.offsetLeft;
			objParent = objParent.offsetParent;
		}
		while (objParent != null);
		
		return intLeft; 
	}
	catch (x) {}
}

function getAbsoluteTop(element) {
	try {
		var intTop = 0;
		var objParent = element;

		do {
			intTop += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
		while (objParent != null);
		
		return intTop; 
	}
	catch (x) {}
}

function getAbsoluteBottom(element) {
	try {
		var intBottom = 0;
		var objParent = element;

		do {
			intBottom += objParent.offsetBottom;
			objParent = objParent.offsetParent;
		}
		while (objParent != null);
		
		return intBottom; 
	}
	catch (x) {}
}

function Berekenleeftijd(p_strDatum)
{
now = new Date();

setdate = new Date(p_strDatum);
day = (now -setdate) /1000 /60 / 60/ 24 / 356 ;
day = Math.round(day);
document.write(""+day+"");
}

function ToonMenu(p_strAnchorRechts,p_strAnchorLeft,p_strMenuId,p_strMenuCounter)
{
var widthItem=0;
var objmenuSubItem = document.getElementById('menuSubItem'+p_strMenuCounter)

menuActief=1;
//alert(p_strAnchorRechts.id+','+p_strAnchorLeft.id+','+p_strMenuId+','+p_strMenuCounter +','+objmenuSubItem.id);
    if (objmenuSubItem != null){
        if(objmenuSubItem.style.display == "block")
        {
            MenuReset(p_strMenuId);
        }
        else
        {
        MenuReset(p_strMenuId);
        showVraagPopup(p_strAnchorLeft,p_strAnchorRechts)
        objmenuSubItem.style.display = "block";
        if(p_strMenuCounter==0)
            widthItem=-1;
        else if(p_strMenuCounter==1)
            widthItem=16;
        else if(p_strMenuCounter==2)
            widthItem=16;
        else if(p_strMenuCounter==3)
            widthItem=276;
        else if(p_strMenuCounter==4)
            widthItem=91;
        objmenuSubItem.style.left = widthItem+"px";
        if(p_strMenuCounter==0)
            document.getElementById('MenuTabLinks'+p_strMenuCounter).style.backgroundImage = "url(/image/tab_midden_lijn.gif)";
        else
            document.getElementById('MenuTabLinks'+p_strMenuCounter).style.backgroundImage = "url(/image/tab_links_lijn.gif)";
         document.getElementById('MenuTab'+p_strMenuCounter).style.backgroundImage = "url(/image/tab_midden_lijn.gif)";
         document.getElementById('MenuTabRechts'+p_strMenuCounter).style.backgroundImage = "url(/image/tab_rechts_lijn.gif)";
        }
    }
}

function ToonVraag(p_strVraag,p_strAantal)
{
    if(document.getElementById('AntwoordBlok'+p_strVraag).style.display!='block')
    {
        ResetVraag(p_strVraag,p_strAantal)
        document.getElementById('AntwoordBlok'+p_strVraag).style.display='block';
        document.getElementById('faqPijlDown'+p_strVraag).style.display='block';
        document.getElementById('faqPijl'+p_strVraag).style.display='none';
    }
    else
        ResetVraag(p_strVraag,p_strAantal)
}

function ResetVraag(p_strVraag,p_strAantal)
{
    for (i=1;i<=p_strAantal;i++)
    {
        document.getElementById('faqPijl'+p_strVraag).style.display='block';
        document.getElementById('faqPijlDown'+p_strVraag).style.display='none';
        document.getElementById('AntwoordBlok'+i).style.display='none';
        document.getElementById('faqVraag'+i).style.color='#000066';
    }
}


function behoudItem()
{
    if(MenubehoudItem==0)
        MenubehoudItem =1;
    else
        MenubehoudItem=0;
}

function closeMenu(p_strAantal)
{
    if(menuActief==1 && MenubehoudItem!=1)
    {
        MenuReset(p_strAantal+1);
        menuActief =0;
    }
    MenubehoudItem=0;  
}

function MenuReset(p_strMenuCounter)
{
    // Remove any existing popups

   if (mdivPopup != '')
                  forceHidePopup();

    for(i=0;i<p_strMenuCounter;i++)
    {
        document.getElementById('menuSubItem'+i).style.display = "none";
        if(i==0)
            document.getElementById('MenuTabLinks'+i).style.backgroundImage = "url(/image/tab_midden.gif)";
        else
            document.getElementById('MenuTabLinks'+i).style.backgroundImage = "url(/image/tab_links.gif)";
     document.getElementById('MenuTab'+i).style.backgroundImage = "url(/image/tab_midden.gif)";
     document.getElementById('MenuTabRechts'+i).style.backgroundImage = "url(/image/tab_rechts.gif)";
    }
}


function showVraagPopup(p_strAnchorLinks,p_strAnchorRechts) {
      try {
            PopupHTML = '<div style="background-color: window; color: windowtext;" onmouseover="this.style.cursor=\'pointer\'" ></div>';
            showPopup(p_strAnchorLinks,p_strAnchorRechts,PopupHTML);
      }
      catch (x) {} 
}

function showPopup(p_strAnchorLink,p_strAnchorRechts,PopupHTML) {
      try {
            mdivPopup = document.createElement('div');
            mdivPopup.style.position = 'absolute';
            mdivPopup.style.zIndex = 999999
            mdivPopup.style.backgroundColor = '#fff';
            mdivPopup.style.height = '1px';
            // Position the popup
            mdivPopup.style.top = (getAbsoluteTop(p_strAnchorLink)+40) + 'px';                   
            mdivPopup.style.left = (getAbsoluteLeft(p_strAnchorLink)) + 'px';
            mdivPopup.style.width = (getAbsoluteLeft(p_strAnchorRechts) - getAbsoluteLeft(p_strAnchorLink) +25) + 'px';
            mdivPopup.innerHTML = PopupHTML;
            // Show the popup
            document.body.appendChild(mdivPopup);
      }
      catch (x) {} 
}

function getAbsoluteLeft(element) {
      try {
            var intLeft = 0;
            var objParent = element;
            do {
                  intLeft += objParent.offsetLeft;
                  objParent = objParent.offsetParent;
            }
            while (objParent != null);
            return intLeft; 
      }
      catch (x) {} 
}

function getAbsoluteTop(element) {
      try {
            var intTop = 0;
            var objParent = element;
            do {
                  intTop += objParent.offsetTop;
                  objParent = objParent.offsetParent;
            }
            while (objParent != null);
            return intTop; 
      }
      catch (x) {} 
}

function forceHidePopup() {
      try {
            if (mdivPopup != '') {
                  document.body.removeChild(mdivPopup);
                  mdivPopup = '';
            }
      }
      catch (x)  {}
}

function getAge(dateString,dateType) {
    var now = new Date();
    var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());

    var yearNow = now.getFullYear();
    var monthNow = now.getMonth();
    var dateNow = now.getDate();

   var dob = new Date(dateString.substring(6,10),
   dateString.substring(3,5)-1,
   dateString.substring(0,2));
      

    var yearDob = dob.getFullYear();
    var monthDob = dob.getMonth();
    var dateDob = dob.getDate();
    yearAge = yearNow - yearDob;

    if (monthNow >= monthDob)
        var monthAge = monthNow - monthDob;
    else {
        yearAge--;
        var monthAge = 12 + monthNow -monthDob;
    }

    if (dateNow >= dateDob)
        var dateAge = dateNow - dateDob;
    else {
        monthAge--;
        var dateAge = 31 + dateNow - dateDob;

        if (monthAge > 0) {
            monthAge = 11;
            yearAge--; 
        }
    }
    document.write(yearAge+' jaar');

}

function getDagen(dateString)
{
    var nu = new Date();
    var dob = new Date(dateString.substring(6,10),dateString.substring(3,5)-1,dateString.substring(0,2));
    var yearDob = dob.getFullYear();
    var monthDob = dob.getMonth();
    var dateDob = dob.getDate();

    if (nu.getMonth() == monthDob && nu.getDate() > dateDob){
        dob.setFullYear(nu.getFullYear()+1);
    }
    else{
        dob.setFullYear(nu.getFullYear());
        }

    var verschil = new Date();
    verschil.setTime(parseInt(nu.getTime()-dob.getTime()));
    dagengehad = Math.round(verschil.getTime()/1000/60/60/24);
    document.write(dagengehad +' dagen');

}

//fading voor deelgemeente / raadsleden banners

var FadeDurationMS=1000;
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}

function FadeInImage(foregroundID,newImage,backgroundID,tekstID,newText)
{
  var foreground=document.getElementById(foregroundID);
  if (foreground.timer) window.clearTimeout(foreground.timer);
  
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    var tekst=document.getElementById(tekstID);
    if (background)
    {
      if (background.src && browser!='Microsoft Internet Explorer 6.0')
      {
        foreground.src = background.src;
        SetOpacity(foreground,100);
      }
      background.src = newImage;
      background.style.backgroundImage = 'url(' + newImage + ')';
      background.style.backgroundRepeat = 'no-repeat';
      var startMS = (new Date()).getTime();
      foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)",10);
      if(tekst)
      {
        tekst.innerHTML=newText;
      }
    }
  } else {
    foreground.src = newImage;
    tekst.innerHTML=newText;
  }
}
var slideCache = new Array();
function RunSlideShow(pictureID,backgroundID,imageFiles,displaySecs,tekstFiles,tekstID)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  var tekstSeparator = tekstFiles.indexOf(";");
  var nextTekst = tekstFiles.substring(0,tekstSeparator);
  if(nextTekst != "")
  {
  FadeInImage(pictureID,nextImage,backgroundID,tekstID,nextTekst);
  }
  var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
  var futureTekst= tekstFiles.substring(tekstSeparator+1,tekstFiles.length)+ ';' + nextTekst;
  if(nextTekst != null)
  {
  setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+futureImages+"','"+displaySecs+"','"+futureTekst+"','"+tekstID+"')",displaySecs*1000);
  }
  // Cache the next image to improve performance.
  
  imageSeparator = futureImages.indexOf(";");
  tekstSeparator = futureTekst.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  nextTekst =futureTekst.substring(0,tekstSeparator);
  if (slideCache[nextImage] == null)
  {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}

function CheckForm() {
    if(document.getElementById('search').value.length < 3) {
        alert('Voer minimaal 3 tekens in');
        return false;
    }else if(document.getElementById('search').value == 'zoek op trefwoord in deze site') {
        alert('Voer een trefwoord in');
        return false;
    } else {
     return true;
    }
}

function CheckFormVideo() {
    if(document.getElementById('searchVideo').value.length < 3) {
        alert('Voer minimaal 3 tekens in');
        return false;
    }else if(document.getElementById('searchVideo').value == 'vul hier uw zoekterm in') {
        alert('Voer een zoekterm in');
        return false;
    } else {
     return true;
    }
}

function CheckFormFoto() {
    if(document.getElementById('searchFoto').value.length < 3) {
        alert('Voer minimaal 3 tekens in');
        return false;
    }else if(document.getElementById('searchFoto').value == 'vul hier uw zoekterm in') {
        alert('Voer een zoekterm in');
        return false;
    } else {
     return true;
    }
}

function ShowFormAfspraak()
{
 if(document.getElementById('FormAfspraakMaken').style.display!='block')
 {
        document.getElementById('FormTerugbellen').style.display='none';
        document.getElementById('FormAfspraakMaken').style.display='block';
        }
    else
        document.getElementById('FormAfspraakMaken').style.display='none';
}

function ShowForm()
{

    if(document.getElementById('FormTerugbellen').style.display!='block')
    {
        document.getElementById('FormAfspraakMaken').style.display='none';
        document.getElementById('FormTerugbellen').style.display='block';
        }
    else
        document.getElementById('FormTerugbellen').style.display='none';
}

function FormAfspraakOpen()
{
    document.getElementById('FormAfspraakMaken').style.display='block';
}

function closeformAfspraak()
{
    document.getElementById('FormAfspraakMaken').style.display='none';
}

function FormTerugbellenOpen()
{
    document.getElementById('FormTerugbellen').style.display='block';
}

function closeform()
{
    document.getElementById('FormTerugbellen').style.display='none';
}

function checkUploadForm()
{
    document.UploadFormulier.submit();
}

function CheckFormPDF()
{
    if(document.getElementById('searchPDF').value=='' || document.getElementById('searchPDF').value=='vul hier uw zoekterm in')
    { 
            alert("U dient wel een zoekterm in te vullen."); 
            document.getElementById('searchPDF').focus(); 
            return false; 
    } 
    if(document.getElementById('Datum_text').value=='')
    { 
            alert("U dient wel een startdatum te selecteren waarop u wilt zoeken."); 
            document.getElementById('Datum_text').focus(); 
            return false; 
    } 
    if(document.getElementById('Datum_tot').value=='')
    { 
            alert("U dient wel een einddatum te selecteren waarop u wilt zoeken."); 
            document.getElementById('Datum_tot').focus(); 
            return false; 
    } 
    
    document.UploadFormulier.submit();
}

function checkTerugbellenForm()
{
    if(document.getElementById('naam').value=='')
    { 
            alert("U dient wel een naam in te vullen."); 
            document.getElementById('naam').focus(); 
            return false; 
    } 
    if(document.getElementById('telefoonnummer').value=='')
    { 
            alert("U dient wel een telefoonnummer in te vullen."); 
            document.getElementById('telefoonnummer').focus(); 
            return false; 
    } 
    document.forms['TerugbelFormulier'].submit();
}

function checkAfspraakForm()
{
    if(document.getElementById('naamafspraak').value=='')
    { 
            alert("U dient wel een naam in te vullen."); 
            document.getElementById('naamafspraak').focus(); 
            return false; 
    } 
    if(document.getElementById('contactafspraak').value=='')
    { 
            alert("U dient wel in te vullen hoe wij contact met u op kunnen nemen."); 
            document.getElementById('contactafspraak').focus(); 
            return false; 
    } 
    document.forms['FormulierAfspraakMaken'].submit();
}

function checkUploadGegevensForm()
{
    if(document.getElementById('naam').value=='')
    { 
            alert("U dient wel een naam in te vullen."); 
            document.getElementById('naam').focus(); 
            return false; 
    } 
    if(document.getElementById('email').value=='' )
    {
        window.alert('E-mail adres is verplicht.');
        document.getElementById('email').focus();
        return false;
    }
    else
    {
	   var pattern1 = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
        if(!pattern1.test(document.getElementById('email').value))
        { 
            alert("Het door u ingevulde emailadres is niet correct"); 
            document.getElementById('email').focus(); 
            return false; 
        } 
    }
    document.UploadGegevensFormulier.submit();
}

