//GETELEMENTBYCLASSNAME CUSTOM FUNCTION
document.getElementsByClassName = function (needle)
{
    var s, i, r = [], l = 0, e;
    var re = new RegExp('(^|\\s)' + needle + '(\\s|$)');

    if (navigator.userAgent.indexOf('Opera') > -1)
    {
        s = [document.documentElement || document.body], i = 0;

        do
        {
            e = s[i];

            while (e)
            {
                if (e.nodeType == 1)
                {
                    if (e.className && re.test(e.className)) r[l++] = e;

                    s[i++] = e.firstChild;
                }

                e = e.nextSibling;
            }
        }
        while (i--);
    }
    else
    {
        s = document.getElementsByTagName('*'), i = s.length;

        while (i--)
        {
            e = s[i];
            if (e.className && re.test(e.className)) r[l++] = e;
        }
    }

    return r;
}

//MENU
function hidealllayers(){
  var oLayers = document.getElementsByClassName("su");
  for (var i = 0; i < oLayers.length; i++) {
      document.getElementById(oLayers[i].id).style.visibility = 'hidden';
  }
}

function showHide(divID) {
  hidealllayers();
  
  var hidden = document.layers ? 'hide' : 'hidden';
  var visible = document.layers ? 'show' : 'visible';
  
  var divStyle = (document.layers) ? document.layers[divID] : document.all ? document.all[divID].style : document.getElementById(divID).style;
  divStyle.visibility = (divStyle.visibility.toLowerCase() == visible) ? hidden : visible;
}

//VALIDATION
function validateField(fld, fldName, min) {
  //check on given minimal length
  if (fld.value.length < min) {
    alert("Het veld \"" + fldName + "\" dient te zijn ingevuld.");
    fld.focus();
    return false;
  }
	
  return true;
}

//EMAILADDRESS FIELD VALIDATION
function validateEmailaddressField(fld, fldName) {
  //check on given minimal length
	if (fld.value.indexOf('@')<=0 || fld.value.indexOf('@')==fld.value.length-1 ) {
    alert("Je hebt geen geldig emailadres ingevuld in veld \"" + fldName + "\".");
    fld.focus();
    return false;
  }
	
  return true;
}

//OTHER FUNCITONS
function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr) was found in the string str.  (If the character is not found, -1 is returned.)
Requires use of:
	Mid function
	Len function
*/
{
	return strSearch.indexOf(charSearchFor);
}

//DEZE VALIDATION WORDT NIET GEBRUIKT
function validateFieldSANDER(fld, fldName, min, max, regxp) {
  //check on given minimal length
  if (fld.value.length < min) {
    alert("Het veld \"" + fldName + "\" dient tenminste " + min + " karakter(s) te bevatten.");
    fld.focus();
    return false;
  }
	
	//check on given maximal length
  if (fld.value.length > max) {
    alert("Het veld \"" + fldName + "\" kan maximaal " + max + " karakter(s) bevatten.");
    fld.focus();
    return false;
  }
  
  //check on given regular expression
  if (min > 0) {
		if (regxp != '') {
			reg = new RegExp(regxp);
			if (!reg.test(fld.value)) {
				alert('Er is een ongeldig waarde ingevuld in het veld ' + fldName + '.');
				fld.focus();
				return false;
			}
		}
	}
		
  return true;
}

//function to move a div layer
function moveLayerTo(layerId, dleft, dtop) {
	layerId.style.top = dleft + 'px';
	layerId.style.left = dtop + 'px';

	return true;
}

//function to open a new window
function popUp(URL, title, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height);");
}


//function to check if an ISBN (10 or 13) is correct
function checkISBN(x) {
  var ISBNVal = x;
  var s = '';
  var io = false;
  
  for (var j = 0; j < ISBNVal.length; j++) {
    var c = ISBNVal.charAt(j);
    if ((c != ' ' && ! isNaN(c)) || c == 'x' || c == 'X') {
      s = s + c;
    }
  }
  
  ISBNVal = s;
  
  if (s.length < 10) {
    for (var j = 0; j < (11 - s.length); j++) {
      s = '0' + s;
    }
  }
  
  if ((s == '0000000000') || (s == '0000000000000')) {
  	io = false;
  }
  else if (s.length == 10) {
  	var checkdigit = String(s).substring(s.length, s.length - 1);
  	checkdigit = checkdigit.toLowerCase();
  	
  	var checkcount = (10 * s.substring(0,1)) + (9 * s.substring(1,2)) + (8 * s.substring(2,3)) + (7 * s.substring(3,4)) + (6 * s.substring(4,5)) + (5 * s.substring(5,6)) + (4 * s.substring(6,7)) + (3 * s.substring(7,8)) + (2 * s.substring(8,9));

 		if ((checkcount % 11) == 0) {
 		  var calculatedcheckdigit = 0;
 		}
 		else {
 			var calculatedcheckdigit = (11 - (checkcount % 11));
 		}

		if (calculatedcheckdigit == 10) {calculatedcheckdigit = 'x';}

		if (calculatedcheckdigit == checkdigit) {
		  io = true;
		}
		else {
			io = false;
		}
  }
  else if (s.length == 13) {
  	var checkdigit = String(s).substring(s.length, s.length - 1);
  	
  	var checkcount = (1 * s.substring(0,1)) + (3 * s.substring(1,2)) + (1 * s.substring(2,3)) + (3 * s.substring(3,4)) + (1 * s.substring(4,5)) + (3 * s.substring(5,6)) + (1 * s.substring(6,7)) + (3 * s.substring(7,8)) + (1 * s.substring(8,9)) + (3 * s.substring(9,10)) + (1 * s.substring(10,11)) + (3 * s.substring(11,12));

		if ((checkcount % 10) == 0) {
			var calculatedcheckdigit = 0;
		}
		else {
			var calculatedcheckdigit = (10 - (checkcount % 10));
		}

		if (calculatedcheckdigit == checkdigit) {
		  io = true;
		}
		else {
			io = false;
		}
  }
  else {
    io = false;
  }
 
  return io;
}