﻿    function ShowBuckaroo() {
        if (!document.forms['frm']) { 
            return;
        }

        self.name = 'payopener';

        var buckaroo_frame = document.getElementById('buckaroo');
        var buckaroo_form = document.getElementById('buckaroo_form');
        if (buckaroo_frame) {
            buckaroo_frame.className = 'show';          
            document.forms['frm'].submit();
            
            if (buckaroo_form) {
                buckaroo_form.className = 'hide';
            }
        }
    }

    function ChangeCSS(el) {
        var top_el = el.parentNode.parentNode.parentNode;
        if (top_el.tagName != 'UL') { return; }

        if (top_el) { var all_links = top_el.getElementsByTagName('A'); }
        var i = all_links.length;
        while (i--) { all_links[i].className = ''; }
        el.className = 'selected';
        
        document.getElementById('ctl00_ccMenu_txtSearch').focus();
    }

	//Called when the user clicks on the ASC sort button
	function ChangeSort(strSort, strSortUI) {
		document.frmOverzicht.Sort.value = strSort;
		document.frmOverzicht.SortUI.value = strSortUI;
		document.frmOverzicht.submit();
	}

	//Called when the user clicks on the DESC sort button
	function ChangeSortDesc(strSort, strSortUI) {
		document.frmOverzicht.Sort.value = strSort + ' DESC';
		document.frmOverzicht.SortUI.value = strSortUI;
		document.frmOverzicht.submit();
	}

	function IsValidDate(strDate){
	var strDate;
	var strDateArray;
	var strDay = "";
	var strMonth = "";
	var strYear = "";
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-","/",".");
	var intElementNr;
	var err = 0;

		if (strDate.length < 1)
			return true;

		for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
			if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
				strDateArray = strDate.split(strSeparatorArray[intElementNr]);
				if (strDateArray.length != 3) {
					err = 1;
					return false;
				}
				else {
					strDay = strDateArray[0];
					strMonth = strDateArray[1];
					strYear = strDateArray[2];
				}
				booFound = true;
			}
		}

		if (booFound == false) {
			return false
			/*if (strDate.length>5) {
				strDay = strDate.substr(0, 2);
				strMonth = strDate.substr(2, 2);
				strYear = strDate.substr(4);
		   }*/
		}

		if (strYear.length == 2)
			strYear = '20' + strYear;

		intday = parseInt(strDay, 10);
		if (isNaN(intday)) {
			err = 2;
			return false;
		}

		intMonth = parseInt(strMonth, 10);

		intYear = parseInt(strYear, 10);

		if (intYear < 1900 || intYear > 3000) {
			err = 4;
			return false;
		}

		if (intMonth>12 || intMonth<1) {
			err = 5;
			return false;
		}

		if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
			err = 6;
			return false;
		}

		if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
			err = 7;
			return false;
		}

		if (intMonth == 2) {
			if (intday < 1) {
				err = 8;
				return false;
			}
			if (LeapYear(intYear) == true) {
				if (intday > 29) {
					err = 9;
					return false;
				}
			}
			else {
				if (intday > 28) {
					err = 10;
					return false;
				}
			}
		}
	return true;
	}

	function LeapYear(intYear) {
		if (intYear % 100 == 0) {
			if (intYear % 400 == 0) { return true; }
		}
		else {
			if ((intYear % 4) == 0) { return true; }
		}
		return false;
	}

	function formatAsMoney(mnt) {
	    mnt -= 0;
	    mnt = (Math.round(mnt*100))/100;
	    return (mnt == Math.floor(mnt)) ? mnt + '.00'
	              : ( (mnt*10 == Math.floor(mnt*10)) ?
	                       mnt + '0' : mnt);
	}

	function CheckDate(source) {

		var strDate="";
		var intLen=0;
		var currentdate=new Date();

		strDate = source.value;
		intLen = source.value.length;

		if (intLen != 0) {
			if (intLen <= 5)
				strDate += "-" + currentdate.getYear()
			if (strDate.indexOf("-", 3) != -1 && strDate.substring(strDate.indexOf("-", 3) + 1).length == 2) {
				if (strDate.substring(strDate.indexOf("-", 3) + 1) < 30)
					strDate = strDate.substring(0, intLen - 2) + "20" + strDate.substring(strDate.indexOf("-", 3) + 1);
				else	
					strDate = strDate.substring(0, intLen - 2) + "19" + strDate.substring(strDate.indexOf("-", 3) + 1);
			}
		}

		source.value = strDate;
	}

	//Remove leading blanks from our string.
	function LTrim(str) {
	   var whitespace = new String(" \t\n\r");

	   var s = new String(str);

	   if (whitespace.indexOf(s.charAt(0)) != -1) {
	      // We have a string with leading blank(s)...

	      var j=0, i = s.length;

	      // Iterate from the far left of string until we
	      // don't have any more whitespace...
	      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
	         j++;

	      // Get the substring from the first non-whitespace
	      // character to the end of the string...
	      s = s.substring(j, i);
	   }
	   return s;
	}

	//Remove trailing blanks from our string.
	function RTrim(str)	{
	   // We don't want to trip JUST spaces, but also tabs,
	   // line feeds, etc.  Add anything else you want to
	   // "trim" here in Whitespace
	   var whitespace = new String(" \t\n\r");

	   var s = new String(str);

	   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	      // We have a string with trailing blank(s)...

	      var i = s.length - 1;       // Get length of string

	      // Iterate from the far right of string until we
	      // don't have any more whitespace...
	      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
	         i--;


	      // Get the substring from the front of the string to
	      // where the last non-whitespace character is...
	      s = s.substring(0, i+1);
	   }

	   return s;
	}

	//Remove trailing and leading blanks from our string.
	function Trim(str) {
	   return RTrim(LTrim(str));
	}

	//Use this function to show a popup with additional information
	function OpenPopupInfo(lngPopupID) {
		window.open('/popupinfo.asp?info=' + lngPopupID, 'test', 'toolbar=no,height=250,width=250,directories=no,status=no,scrollbars=no,resizable=no,menubar=no');
	}

	function IsValidEmail (emailStr) {

		if (emailStr == "")
			return true;

		/* The following pattern is used to check if the entered e-mail address
		   fits the user@domain format.  It also is used to separate the username
		   from the domain. */
		var emailPat=/^(.+)@(.+)$/

		/* The following string represents the pattern for matching all special
		   characters.  We don't want to allow special characters in the address.
		   These characters include ( ) < > @ , ; : \ " . [ ]    */
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

		/* The following string represents the range of characters allowed in a
		   username or domainname.  It really states which chars aren't allowed. */
		var validChars="\[^\\s" + specialChars + "\]"

		/* The following pattern applies if the "user" is a quoted string (in
		   which case, there are no rules about which characters are allowed
		   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		   is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")"

		/* The following pattern applies for domains that are IP addresses,
		   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		   e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

		/* The following string represents an atom (basically a series of
		   non-special characters.) */
		var atom=validChars + '+'

		/* The following string represents one word in the typical username.
		   For example, in john.doe@somewhere.com, john and doe are words.
		   Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")"

		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

		/* The following pattern describes the structure of a normal symbolic
		   domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


		/* Finally, let's start trying to figure out if the supplied address is
		   valid. */

		/* Begin with the coarse pattern to simply break up user@domain into
		   different pieces that are easy to analyze. */
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
		  /* Too many/few @'s or something; basically, this address doesn't
			 even fit the general mould of a valid e-mail address. */
			return false
		}
		var user=matchArray[1]
		var domain=matchArray[2]

		// See if "user" is valid
		if (user.match(userPat)==null) {
			// user is not valid
			return false
		}

		/* if the e-mail address is at an IP address (as opposed to a symbolic
		   host name) make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			// this is an IP address
			  for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					return false
				}
			}
			return true
		}

		// Domain is symbolic name
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			return false
		}

		/* domain name seems valid, but now make sure that it ends in a
		   three-letter word (like com, edu, gov) or a two-letter word,
		   representing country (uk, nl), and that there's a hostname preceding
		   the domain or country. */

		/* Now we need to break up the domain to get a count of how many atoms
		   it consists of. */
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 ||
			domArr[domArr.length-1].length>4) {
		   // the address must end in a two letter or three letter word.
		   return false
		}

		// Make sure there's a host name preceding the domain.
		if (len<2) {
		   var errStr="This address is missing a hostname!"
		   return false
		}

		// If we've gotten this far, everything's valid!
		return true;
	}

	function checkPrice(price)
	{
		var pattern

		pattern = /^([0-9].+),([0-9]{2})$|\d[0-9]$|^([0-9].+).([0-9]{2})$|^([0-9])$/

		var matchArray=price.match(pattern)
		if (matchArray==null)
		{
			var matchArray=price.match(pattern)
			if (matchArray==null)
				return false;
		}
		else
			return true;

	}

	function checkPercentage(percentage)
	{
		var pattern

		pattern = /^([0-9]+),([0-9]+)$|^([0-9]+)$/

		var matchArray=percentage.match(pattern)
		if (matchArray==null)
		{
			var matchArray=percentage.match(pattern)
			if (matchArray==null)
				return false;
		}
		else
			return true;

	}

	function checkDecimal(decValue)
	{
		var pattern = /^[0-9]+[,|.][0-9]+$|^[0-9]+$/

		var matchArray=decValue.match(pattern)
		if (matchArray==null)
		{
			var matchArray=decValue.match(pattern)
			if (matchArray==null)
				return false;
		}
		else
			return true;

	}

	function IsNumeric(strValue)
	{
		var intGetal
		var blnGetal
		blnGetal = true
		if(strValue != "" )
		{
			for(i = 0; i < strValue.length; i++)
			{
				intGetal = parseInt(strValue.charAt(i), 10)
				if(intGetal >= 0 && intGetal <= 9)
				{
				}
				else
				{
					alert("U moet een getal invoeren om het maximaal aantal cursisten aan te geven.");
					return false;
				}
			}
		}
		return true;
	}
    function getWindowSize(strHeightWidth) {
      var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
      if (strHeightWidth=='H'){return myHeight}else{return myWidth}
    }
    function setHeight(){

    //onLoad="setHeight();" onResize="setHeight();"
      var intHeight = getWindowSize('H');
      var scrollHeight = document.documentElement.scrollHeight ;
      if (scrollHeight > intHeight){
        intHeight = scrollHeight;
      }
      if(intHeight > 84){document.getElementById('contentcontainer').style.height=intHeight-84+'px'}
    
    }

    function setSearchFilter(me) {
        var hidFilter = document.getElementById('hidSearchFilter');
        if (hidFilter) {
            hidFilter.value = me.id.replace('filter_', '');
        }
        var ulSearchFilter = document.getElementById('search_filter');
        if (ulSearchFilter) {
            var ulSearchChilds = ulSearchFilter.getElementsByTagName('LI');
            if (ulSearchChilds.length > 0) {
                var i = ulSearchChilds.length;
                while (i--) {
                    ulSearchChilds[i].className = '';
                }
            }
        }
        me.parentNode.className = 'selected';
    }