// JavaScript Document
function MM_openBrWindow(theURL,winName,features) { //v2.0
	//alert(features)
	features += ",scrollbars=yes,resizable=yes";
 	var w = window.open(theURL,winName,features);
 	w.focus();
}

function foldOut(obj){	
	document.getElementById(obj).style.display = (document.getElementById(obj).style.display=='none')?'block' :'none';
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}



// Random banner functions
//create random number
function createRandomNumber(arrImages) {
	// return a number between 0 and length of array - 1.
	var randomNumber= Math.floor(Math.random()*arrImages.length);
	return randomNumber;
}


// renders the banner src
function showRandomBanners () {

	//create random number
	var banner1, banner2, bannerLink1, bannerLink2

	//if banner 1 exist
	if (banner1 = document.getElementById('randomBanner1')) {
           
		//get id to place banner and place banner
                               	var randomNumber = createRandomNumber(arrRandomImagesPositionA);
		banner1.src = arrRandomImagesPositionA[randomNumber][0];
		banner1.alt = arrRandomImagesPositionA[randomNumber][2];

		//if the link for banner 1 exists
		if (bannerLink1 = document.getElementById('randomBannerLink1')) {
			bannerLink1.href = arrRandomImagesPositionA[randomNumber][1];
			bannerLink1.target = arrRandomImagesPositionA[randomNumber][3];
		}
	}


	//if banner 2 exists
	if (banner2 = document.getElementById('randomBanner2')) {

		//create second random number
		var randomNumber2 = createRandomNumber(arrRandomImagesPositionB);

		//if the images we selected are the same, then get another number (image)
                                if (document.getElementById('randomBanner1')) {
		if (arrRandomImagesPositionA[randomNumber][0] == arrRandomImagesPositionB[randomNumber2][0]) {
			randomNumber2 == 0 ? randomNumber2 = arrRandomImagesPositionB.length - 1 : randomNumber2 = randomNumber2 - 1;
		}
                                }

		banner2.src = arrRandomImagesPositionB[randomNumber2][0];
		banner2.alt = arrRandomImagesPositionB[randomNumber2][2];

		//if the link for banner 2 exists
		if (bannerLink2 = document.getElementById('randomBannerLink2')) {
			bannerLink2.href = arrRandomImagesPositionB[randomNumber2][1];
			bannerLink2.target = arrRandomImagesPositionB[randomNumber2][3];
		}
	}

	if (document.getElementById("banners")) {
		document.getElementById("banners").style.visibility = "visible";
	}
}

function printWindow() {
	window.open(location.href.substr(0, location.href.length - location.search.length - location.hash.length) + '?media=print' + (location.search ? '&' + location.search.substr(1):''),'print','scrollbars=yes,toolbar=no,location=no, resizable=yes, width=800, height=600'); return false;
}

function checkCookie() {
	var cookieName = "firstVisit";
	var intCurrentCount = parseInt(readCookie(cookieName));
	if (isNaN(intCurrentCount)) {
		intCurrentCount = 1;
	}
	else {
		intCurrentCount++;
	}
	
	if (intCurrentCount <= 3 && (readCookie('selectedBranche') == null || readCookie('selectedBranche') == "") && (readCookie('selectedRegion') == null || readCookie('selectedRegion') == "" )) {
		createCookie(cookieName,intCurrentCount,3650);
		if (document.cookie != "") {
			MM_showHideLayers('popmijnkvk','','show');
		}
	}
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function checkLayer() {
	var regioform;
	
	if (regioform = document.forms["regioform"]) {
		var postcode = regioform.postcode;
		var branche = regioform.branche;
		

		if (branche.selectedIndex < 1 && postcode.value == "plaatsnaam of postcode") {
			alert("U dient een plaatsnaam/postcode of branchesector te kiezen");
		} else {
			regioform.submit();
		}
	}
	return false;
}

// Global variable: is false on first time we run the script. Gets set to yes when clearInputFields runs succesfully
var clearInputRan = false

//Expects comma seperated list of IDs of input fields to clear
function clearInputFields(fieldIDs) 
{
	var arrIDs;
	
	arrIDs = fieldIDs.split(",");

	if (!clearInputRan) {
		for (x=0; x<arrIDs.length; x++) {
			document.getElementById(arrIDs[x]).value = "";
		}
	clearInputRan = true
	}
}

function GetCookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

function handleLocalLinks (elmt) {
	var localAnchor = getLocalAnchor(elmt.href);
	var currentUrl = stripLocalAnchor (location.href);
	if (localAnchor != '') {
		location.href = currentUrl + '#' + localAnchor;
	} else {
		location.href = currentUrl;
	}
}

function getLocalAnchor(strUrl) {
	var re = /^.*#(.+)$/;
	if (re.test(strUrl)) {
		return strUrl.replace (re, '$1');
	} else {
		return '';
	}
}

function stripLocalAnchor(strUrl) {
	var re = /^(.*)#.+$/;
	if (re.test(strUrl)) {
		return strUrl.replace (re, '$1');
	} else {
		return strUrl;
	}
}



function MM_timelinePlay(tmLnName, intAnimatie, myID) { //v1.2
  //Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Macromedia, Inc. All rights reserved.
  //11-2006 intAnimatie 0 = leftcolumn search-no animation,  1 = middlecolumn (homepage) animation

 if (intAnimatie == 1) {

 var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,propNum,theObj,firstTime=false, countLine = 0;

  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  tmLn = document.MM_Time[tmLnName];
  if (myID == null) { myID = ++tmLn.ID; firstTime=true;}//if new call, incr ID
  if (myID == tmLn.ID) { //if Im newest
    setTimeout('MM_timelinePlay("'+tmLnName+'",'+intAnimatie+','+myID+')',tmLn.delay);
    fNew = ++tmLn.curFrame;
    for (i=0; i<tmLn.length; i++) {
      sprite = tmLn[i];
      if (sprite.charAt(0) == 's') {
        if (sprite.obj) {
          numKeyFr = sprite.keyFrames.length; firstKeyFr = sprite.keyFrames[0];
          if (fNew >= firstKeyFr && fNew <= sprite.keyFrames[numKeyFr-1]) {//in range
            keyFrm=1;
            for (j=0; j<sprite.values.length; j++) {
              props = sprite.values[j]; 
              if (numKeyFr != props.length) {
                if (props.prop2 == null) sprite.obj[props.prop] = props[fNew-firstKeyFr];
                else        sprite.obj[props.prop2][props.prop] = props[fNew-firstKeyFr];
              } else {
                while (keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]) keyFrm++;
                if (firstTime || fNew==sprite.keyFrames[keyFrm-1]) {
                  if (props.prop2 == null) sprite.obj[props.prop] = props[keyFrm-1];
                  else        sprite.obj[props.prop2][props.prop] = props[keyFrm-1];
        } } } } }
      } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
      if (fNew > tmLn.lastFrame){
	  //EXTRA CODE to detect end of animation and Submitform 
	  countLine++;
		  if(countLine == document.MM_Time[0].length){
		   submitForm();
			}
		//=======================
	  	tmLn.ID = 0;
		}
  	 } 	
  }
 } else {
   submitForm();
 }
}

function submitForm(){
	//alert("submit");
	document.forms["srchkvk"].submit();
}

function MM_initTimelines() { //v4.0
    //MM_initTimelines() Copyright 1997 Macromedia, Inc. All rights reserved.

    var ns = navigator.appName == "Netscape";
    var ns4 = (ns && parseInt(navigator.appVersion) == 4);
    var ns5 = (ns && parseInt(navigator.appVersion) > 4);
    var macIE5 = (navigator.platform ? (navigator.platform == "MacPPC") : false) && (navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4);
    document.MM_Time = new Array(1);
    document.MM_Time[0] = new Array(3);
    document.MM_Time["Timeline1"] = document.MM_Time[0];
    document.MM_Time[0].MM_Name = "Timeline1";
    document.MM_Time[0].fps = 25;
    document.MM_Time[0][0] = new String("sprite");
    document.MM_Time[0][0].slot = 1;
    if (ns4)
        document.MM_Time[0][0].obj = document["main"] ? document["main"].document["searchkvk"] : document["searchkvk"];
    else if (ns5)
        document.MM_Time[0][0].obj = document.getElementById("searchkvk");
    else
        document.MM_Time[0][0].obj = document.all ? document.all["searchkvk"] : null;
    document.MM_Time[0][0].keyFrames = new Array(1, 7);
    document.MM_Time[0][0].values = new Array(2);
    if (ns5 || macIE5)
        document.MM_Time[0][0].values[0] = new Array("0px", "0px", "0px", "0px", "0px", "0px", "0px");
    else
        document.MM_Time[0][0].values[0] = new Array(0,0,0,0,0,0,0);
    document.MM_Time[0][0].values[0].prop = "left";
    if (ns5 || macIE5)
        document.MM_Time[0][0].values[1] = new Array("0px", "8px", "16px", "24px", "32px", "40px", "48px");
    else
        document.MM_Time[0][0].values[1] = new Array(0,8,16,24,32,40,48);
    document.MM_Time[0][0].values[1].prop = "top";
    if (!ns4) {
        document.MM_Time[0][0].values[0].prop2 = "style";
        document.MM_Time[0][0].values[1].prop2 = "style";
    }
    document.MM_Time[0][1] = new String("sprite");
    document.MM_Time[0][1].slot = 2;
    if (ns4)
        document.MM_Time[0][1].obj = document["main"] ? document["main"].document["banners"] : document["banners"];
    else if (ns5)
        document.MM_Time[0][1].obj = document.getElementById("banners");
    else
        document.MM_Time[0][1].obj = document.all ? document.all["banners"] : null;
    document.MM_Time[0][1].keyFrames = new Array(1, 15);
    document.MM_Time[0][1].values = new Array(2);
    if (ns5 || macIE5)
        document.MM_Time[0][1].values[0] = new Array("0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px", "0px");
    else
        document.MM_Time[0][1].values[0] = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
    document.MM_Time[0][1].values[0].prop = "left";
    if (ns5 || macIE5)
        document.MM_Time[0][1].values[1] = new Array("0px", "8px", "17px", "25px", "34px", "42px", "51px", "59px", "67px", "76px", "84px", "93px", "101px", "110px", "118px");
    else
        document.MM_Time[0][1].values[1] = new Array(0,8,17,25,34,42,51,59,67,76,84,93,101,110,118);
    document.MM_Time[0][1].values[1].prop = "top";
    if (!ns4) {
        document.MM_Time[0][1].values[0].prop2 = "style";
        document.MM_Time[0][1].values[1].prop2 = "style";
    }
    document.MM_Time[0][2] = new String("sprite");
    document.MM_Time[0][2].slot = 1;
    if (ns4)
        document.MM_Time[0][2].obj = document["main"] ? document["main"].document["searchkvk"] : document["searchkvk"];
    else if (ns5)
        document.MM_Time[0][2].obj = document.getElementById("searchkvk");
    else
        document.MM_Time[0][2].obj = document.all ? document.all["searchkvk"] : null;
    document.MM_Time[0][2].keyFrames = new Array(8, 22);
    document.MM_Time[0][2].values = new Array(2);
    if (ns5 || macIE5)
        document.MM_Time[0][2].values[0] = new Array("0px", "-15px", "-29px", "-44px", "-59px", "-74px", "-88px", "-103px", "-118px", "-132px", "-147px", "-162px", "-177px", "-191px", "-206px");
    else
        document.MM_Time[0][2].values[0] = new Array(0,-15,-29,-44,-59,-74,-88,-103,-118,-132,-147,-162,-177,-191,-206);
    document.MM_Time[0][2].values[0].prop = "left";
    if (ns5 || macIE5)
        document.MM_Time[0][2].values[1] = new Array("48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px", "48px");
    else
        document.MM_Time[0][2].values[1] = new Array(48,48,48,48,48,48,48,48,48,48,48,48,48,48,48);
    document.MM_Time[0][2].values[1].prop = "top";
    if (!ns4) {
        document.MM_Time[0][2].values[0].prop2 = "style";
        document.MM_Time[0][2].values[1].prop2 = "style";
    }
    document.MM_Time[0].lastFrame = 22;
    for (i=0; i<document.MM_Time.length; i++) {
        document.MM_Time[i].ID = null;
        document.MM_Time[i].curFrame = 0;
        document.MM_Time[i].delay = 1000/document.MM_Time[i].fps;
    }
}

// This function creates popups from productlinks in the content. 
//If this function is not executed then the productlinks will open in the current window.
// created by Albert to 
function FixLinks()
{
	//var iframe = document.getElementById("iframe");
	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
  	{ //alert(links[i].href);
		if (links[i].href != null)
		{
			if (links[i].href.indexOf("productdetails.asp") > -1)
				links[i].target = "_blanc";
		}
	}
}

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent(window, 'load', FixLinks);

function MWM2POPUPWriteCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function MWM2POPUPReadCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
	    
		if (c.indexOf(nameEQ) == 0)
		{
		    return c.substring(nameEQ.length,c.length);
		}
	}
	
	return null;
}

function MWM2POPUPEraseCookie(name)
{
    createCookie(name, "", -1);
}


function PopupCounter(link, showCount, title, body, bodybottom, closePauzePeriod,closeButton,imageUrl)
{
    WriteCSS(closeButton);

    var i = parseInt('0' + MWM2POPUPReadCookie('MWM2POPUPCounter'));    
    
    if((i > - 1) || (i == null))
    {
        if(i > showCount)
        {          
            document.write('<div class="MWM2POPUP" id="MWM2POPUP">');
            document.write('    <table border=0 cellpadding=5 cellspacing=3 width=320 align=center>');
            document.write('        <tr>');
            document.write('            <td class="MWM2POPUPTopbar"><div class="MWM2POPUPTopbar" style="float:left;">' + title + '</div><div style="float:right;" class="MWM2POPUPCloseButton" onclick="document.getElementById(\'MWM2POPUP\').style.display=\'none\';MWM2POPUPWriteCookie(\'MWM2POPUPCounter\',-1,' + closePauzePeriod + ');"></div></td>');
            document.write('        </tr>');
            document.write('        <tr>');
            document.write('			<td class="MWM2POPUPBody"><table><tr><td>');
            if (imageUrl != '') {
				document.write('            <img src="' + imageUrl + '"></td><td>');
            }
            document.write(body);
            document.write('                <center>');
            document.write('                    <input type=button name=Ja value="Yes" class="MWM2POPUPButtons MWM2POPUPButtonJA" onclick="MWM2PopupClickYes(\'' + link + '\')">');
            document.write('                    <input type=button name=Nee value="No" class="MWM2POPUPButtons MWM2POPUPButtonNEE" onclick="MWM2POPUPWriteCookie(\'MWM2POPUPCounter\',-1,\'2000\');window.location.reload();">');
            document.write('                </center></td></tr></table>');
            
            if(bodybottom != null)
            {
                document.write(bodybottom);
            }
            
            document.write('            </td>');
            document.write('        </tr>');
            document.write('    </table>');
            document.write('</div>');
        }


        i++;
        MWM2POPUPWriteCookie('MWM2POPUPCounter',i);
    }
}

//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//
//                                          CHANGEBLE PARTS BELOW
//
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

function MWM2PopupClickYes(link)
{
    MWM2POPUPWriteCookie('MWM2POPUPCounter',-1,'31');
    document.getElementById('MWM2POPUP').style.display='none';

    window.open(link,'MWM2Onderzoekapplicatie','resizable=1,width=800,height=600,scrollbars=yes,status=yes');
}

function KVKPopup(closeButton, image)
{
    PopupCounter('http://onderzoek.mwm2.nl/ga.asp?vp=6B54C04A-56B7-40BD-9618-E474CA1355D2', 1,'Website survey KvK.nl/English','KvK.nl wants to know more about het visitors and has put together a short survey. The survey will take about 5 minutes. <br><br>With your answers, this website can be improved and modified to your wishes.<br><br>Do you want to participate? <br><br>','',1,closeButton, image);
}

function WriteCSS(closeButton)
{
    document.write("<style>");

    document.write(".MWM2POPUPTopbar");
    document.write("{");
    document.write("    font-size:12pt;");
    document.write("    font-family:arial;");
    document.write("    color:RGB(16, 65, 115);");
    document.write("    font-weight:bold;");
    document.write("}");

    document.write(".MWM2POPUPButtons");
    document.write("{");
    document.write("    font-size:12px;");
    document.write("    width:45px;");
    document.write("    font-family:arial;");
    document.write("    margin-right:15px;");
    document.write("}");

    document.write(".MWM2POPUPBody");
    document.write("{");
    document.write("     background-color:RGB(222, 231, 247);");
    document.write("     font-size:12px;");
    document.write("    font-family:arial;");
    document.write("     color:RGB(16, 65, 115);");
    document.write("}");

    document.write(".MWM2POPUP");
    document.write("{");
    document.write("    width:324px;");
    document.write("    background-color:RGB(156, 207, 255);");
    document.write("    padding-top:2px;");
    document.write("    padding-bottom:2px;");
    document.write("    font-family:arial;");
    document.write("    padding-left:2px;");
    document.write("    padding-right:2px;");
    document.write("    position: absolute;");
    document.write("    top: 250px;");
    document.write("    left: 350px;");
    document.write("    z-index:9999;");
    document.write("}");

    document.write(".MWM2POPUPCloseButton");
    document.write("{");
    document.write("    margin-top:2px;");
    document.write("    width:15px;");
    document.write("    background-image:url(" +  closeButton +");");
    document.write("    height:15px;");
    document.write("    cursor:pointer;");
    document.write("    font-family:arial;");
    document.write("}");

    document.write("</style>");
}



