var arrDivElements;
var myTimer;

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function setDivGebied(strClassName, block){
    //var arrElements = getElementsByClassName(document, "div" , strClassName);
    if (arrDivElements)
        arrElements = arrDivElements;
    else{
        arrElements = document.getElementsByTagName("div");
        arrDivElements = arrElements;
        }
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oElement.className == strClassName)
          oElement.style.display = block ? 'block':'none';
    }    
}

function idDisplay(strId, block)
{
  var x=document.getElementById(strId);
  if (x)
     x.style.display = block ? 'block':'none';
}

function idDisplaySwitch(strId)
{
  var x=document.getElementById(strId);
  if (x){
  
     x.style.display = x.style.display == 'none' ? 'block':'none';
     }
}

function setClass(strId, cls)
{
  var x=document.getElementById(strId);
  if (x)
     x.className = cls;
}

function setBackground(strId, bck)
{
  var x=document.getElementById(strId);
  if (x)
     x.style.background=bck;
}

function openDisplay(strId)
{
    window.open(strId,"info_menu",'left=20,top=20,width=1100,height=750,toolbar=0,resizable=1,directories=0,status=0,menubar=0,scrollbars=1');
}


function setTabMenu(active, all){

	var y, tabs = "";

  	tabs = all.split(";");
    if (tabs.length > 0){
		for (y = 0; y < tabs.length; y++){
			setClass(tabs[y] +'_li', active == tabs[y] ? 'current':"");
			setClass(tabs[y] +'_a',  active == tabs[y] ? 'current':"");
			idDisplay('tab_' + tabs[y],  active == tabs[y] ? true:false);
		}
	}    
}


function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";


    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}


function emailcheckBasis(str) {
	var str, veld
	var ok = true;
	if (str != ""){
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   ok  = false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   ok  = false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   ok  = false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   ok  = false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   ok  = false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   ok  = false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		   ok  = false;
		 }
	}
	 return ok;					
	}



function emailcheck(veld) {
	var str, veld
	var ok = true;
	if (veld != null){
		ok = emailcheckBasis(veld.value);
		if (!ok){
			alert("Onjuist e-mailadres "+ veld.value);
			veld.focus();
		}
	}
	 return ok;					
	}

var reInteger = /^\d+$/


function checkBSNBasis (mtBSN){
        var chksum = 0.0;
        stripCharsInBag(mtBSN, " .");
        var lengte = mtBSN.length;
        if (mtBSN == "000000000"){
             return false;
        }
        if (lengte == 0)
        	return (true);
        if (lengte != 9){
                return (false);
        	}
        if (!reInteger.test(mtBSN)){
                return (false);
                }
      for (i = 0; i < 8; i++) {
        var c = mtBSN.charAt(i);
        if (c >= '0' && c<= '9')
          chksum += ( (9 - i) * (c - '0'));
        else
          chksum = -10000;
      }
      var berchksum = parseInt(chksum / 11);
      berchksum *= 11;
      if (chksum - berchksum != mtBSN.charAt(8) - '0'){
               return (false);
      }

        return (true);
}


function checkRelatienummer (mtRelnr){
        var chksum = 0.0;
        stripCharsInBag(mtRelnr, " .");
        var lengte = mtRelnr.length;
        if (mtRelnr == "00000000"){
             return false;
        }
        if (lengte == 0)
        	return (true);
        if (lengte > 8){
                return (false);
        	}
        if (!reInteger.test(mtRelnr)){
                return (false);
                }

        return (true);
}


function messageLengthCheck(veld, max){
	var veld;
	var ok = true;
	if (veld != null){
		ok = messageLengthCheckBasis(veld.value, max);
		if (!ok){
			veld.focus();
			}
		}
		return ok;
}

function messageLengthCheckBasis(str, max)
{
	//remove the whitespaces for and after the string
	var str = str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	
	//regular expression: to catch if the box is not filled
	var regex1 = new RegExp ("^Maximaal " + max + " woorden");
	//regular expression: amount of words is less or equal then the max value

	if(regex1.test(str))
	{
		alert("U dient uw vraag nog in te vullen.");
		return false;
	}

	words = str.replace(/^\s+/,'');
	words = words.replace(/\s+$/,'');
	words = words.split(/\s/);

	if (words.length > max)
	{
		alert("Uw vraag of opmerking kan maximaal " + max + " woorden bevatten");
		return false;
	}	

	return true;
}
