﻿function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function validateZoek(frm) {
    if (trim(frm.zoek.value) == "") {
        window.alert("Vul a.u.b. een zoekterm in");
        return false;
    }
    else {
        return true;
    }
}

function openImage(url,alt,w,h)
{
	var nam = url.substring(url.lastIndexOf("/")+1,url.length-4);
	var cfg = "width="+w+",height="+h+",resizable=no";
	var htm = "<html>";
	htm += "<title>" + nam + "</title>"
	htm += "<body style='margin:0;'>";
	htm += "<img src='" + url +"' alt='" + alt + "'>";
	htm += "</body>";
	htm += "</html>";
	var win = window.open("",nam,cfg);
	win.document.write(htm);
}

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;
}


		function hideAllTeasers()
		{
			var x = document.getElementsByClassName("teaser_item"), i=x.length
			while(i--)
			{
				x[i].style.display = 'none';
			}
		}
		
		function showTeaser(elItem,el)
		{
			var x = document.getElementById(elItem)
			x.style.display = 'block';
			
			var y = document.getElementsByClassName(el)
			var z = document.getElementsByClassName("teaser_item_titels"), i = z.length
			while(i--)
			{
				var n = z[i].parentNode.className
				if (n=='last') z[i].parentNode.className = 'last';
				else z[i].parentNode.className = '';
			}
			y[0].parentNode.className = 'active';
			
		}


sfHover = function() {
    if(document.getElementById("submenu"))
    {
	    var sfEls = document.getElementById("submenu").getElementsByTagName("li");
	    for (var i=0; i<sfEls.length; i++) {
		    sfEls[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		    }
	    }
	}
}


function hideInputs()
{
 var x = document.getElementsByTagName("input")
 if (x)
 {
    var i = x.length
    while (i--)
    {
        x[i].style.visibility = 'hidden';
    }
 }
}

function showInputs()
{
 var x = document.getElementsByTagName("input")
 if (x)
 {
    var i = x.length
    while (i--)
    {
        x[i].style.visibility = 'visible';
    }
 }
}

function sfHoverSubmenu() {

    var li = document.getElementsByClassName("jshover"), i = li.length
    while (i--)
    {
        li[i].onmouseover = function ha(){hideInputs();}
        li[i].onmouseout = function ha(){showInputs();}
    }
    
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function OpenPics(url, iwidth, iheight)
{
	window.open(url,"afbeelding","width="+iwidth+",height="+iheight+",left=125,top=100");
}

window.addEvent('domready', function () 
{
	sfHoverSubmenu();
});


function CheckRegExMatch(strRegEx, strValue)
{
    var objRegEx = new RegExp(strRegEx);
    return objRegEx.test(strValue);
}

function CheckValidInput(strValue)
{
    return CheckRegExMatch(/[^(\/\*)|(\*\/)|(@@)|(--)|(<)|(>)]/, strValue);
}

function CheckValidInteger(strValue)
{
    if ( CheckValidInput(strValue) )
        return CheckRegExMatch(/^([0-9])+$/, strValue);
    else
        return false;    
}

function CheckValidDecimal(strValue)
{
    if ( CheckValidInput(strValue) )
        return CheckRegExMatch(/^([0-9])+(([.,])*([0-9])+)*$/, strValue);
    else
        return false;    
}

function CheckValidName(strValue)
{
    if ( CheckValidInput(strValue) )
        return CheckRegExMatch(/^(\D)*$/, strValue);
    else
        return false;
}

function CheckValidEmail(strValue)
{
    if ( CheckValidInput(strValue) )
        return CheckRegExMatch(/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/, strValue);
    else
        return false;
}

function CheckValidUrl(strValue)
{
    if ( CheckValidInput(strValue) )
        return CheckRegExMatch(/(http(s)?|ftp(s)?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/, strValue);
    else
        return false;
}