var MAX_DUMP_DEPTH = 10;

// window.onerror = errorHandler; --> Tijdelijk uitgeschakeld
var lastError = {};
lastError.msg = "";
lastError.url = "";
lastError.lno = 0;

var erroralertmsg = Language.JSUtils_UnexpectedError_Line1;
erroralertmsg += "\n"+Language.JSUtils_UnexpectedError_Line2;
erroralertmsg += "\n\n"+Language.JSUtils_UnexpectedError_Line3;

function errorHandler(msg, url, lno) {
    var pl = new SOAPClientParameters();
    pl.add("message", msg);
    pl.add("linenumber", lno);
    pl.add("url", url);
    try {
        if (msg.indexOf("LogJSError", 0) > -1) {
            document.body.style.cursor = "";
            alert(erroralertmsg);
        }
        else {
            lastError.msg = msg;
            lastError.url = url;
            lastError.lno = lno;
            SOAPClient.invoke(hsWebsrvServer + "HsLogging.asmx", "LogJSError", pl, true, LogJSErrorResp);
        }
    }
    catch (err) {
        alert(erroralertmsg);
    }

    return true;
}

function LogJSErrorResp(r) {
    window.onerror = errorHandler;
    alert(erroralertmsg);
}

function dumpObj(obj, name, indent, depth) {
    if (depth > MAX_DUMP_DEPTH) {
        return indent + name + ": <Maximum Depth Reached>\n";
    }
    if (typeof obj == "object") {
        var child = null;
        var output = indent + name + "\n";

        indent += "\t";

        for (var item in obj) {
            try {
                child = obj[item];
            }
            catch (e) {
                child = "<Unable to Evaluate>";
            }
            if (typeof child == "object") {
                output += dumpObj(child, item, indent, depth + 1);
            }
            else {
                output += indent + item + ": " + child + "\n";
            }
        }
        return output;
    }
    else {
        return obj;
    }
}

var errorFields = new Array();

function IsIE() {
    return navigator.appName == 'Microsoft Internet Explorer';
}

function setSelectFromValue(sel, val) {
    if (typeof (sel) != "object") {
        sel = document.getElementById(sel);
    }
    if (sel) {
        sel.value = val;
        if (sel.getAttribute("hshasinput") == "true" && sel.options.length > 0) {
            //old selectbox
            if (sel.selectedIndex == -1) sel.selectedIndex = 0;

            var o = document.getElementById(sel.id + "_input");
            if (o) {
                o.value = sel.options[sel.selectedIndex].text;
                o.hsSelectedValue = val;
            }
        }
        else if ($(sel.parentNode).hasClass("selector")) 
        {
            //new selectbox which uses jquery plugin uniform
            UpdateJQueryUniformSelect(sel);
        }
        UpdateLinkedFieldsForSelect(sel);
    }
}

function ApplyJQueryUniformSelect(selectBox) {
    //jquery plugin "http://uniformjs.com" 
    //initialise selectbox custom ui
    if (selectBox.parentNode != null)
    {
        if ($(selectBox.parentNode).hasClass("selector"))
        {
		    //bug? https://github.com/pixelmatrix/uniform/issues/142	
		    return; 
		}
	}
	
	$(selectBox).uniform();
}

function UpdateJQueryUniformSelect(selectBox) {
    //jquery plugin "http://uniformjs.com" 
    //update of the selectbox is needed if the selectedvalue of the selectbox changes programatically
    $.uniform.update('#' + selectBox.id);
}

function UpdateLinkedFieldsForSelect(sel) {
    var touchedFields = new Array(); // object for managing multiple linkeddiv with options

    for (var i = 0; i < sel.options.length; i++) {
        var linkedIds = sel.options[i].getAttribute("hsshowdiv");
        if (linkedIds) {
            linkedIds = linkedIds.split("|");
            var linkedId;
            for (var j = 0; j < linkedIds.length; j++) {
                linkedId = linkedIds[j];
                if (linkedId && !touchedFields[linkedId]) {
                    if (i == sel.selectedIndex) showField(linkedId);
                    else hideField(linkedId);
                    touchedFields[linkedId] = (i == sel.selectedIndex);
                }
            }
        }
    }
}

function setCheckboxFromValue(cbx, val) {
    if (typeof (cbx) != "object") {
        cbx = document.getElementById(cbx);
    }
    val == cbx.value ? cbx.checked = true : cbx.checked = false;

    // eventueel een gekoppelde div mee laten schakelen
    if (cbx) {
        var linkedIds = cbx.getAttribute("hshidediv");
        if (linkedIds) {
            linkedIds = linkedIds.split("|");
            var linkedId;
            for (var j = 0; j < linkedIds.length; j++) {
                linkedId = linkedIds[j];
                if (cbx.checked) hideField(linkedId);
                else showField(linkedId);
            }
        }

        linkedIds = cbx.getAttribute("hsshowdiv");
        if (linkedIds) {
            linkedIds = linkedIds.split("|");
            var linkedId;
            for (var j = 0; j < linkedIds.length; j++) {
                linkedId = linkedIds[j];
                if (cbx.checked) showField(linkedId);
                else hideField(linkedId);
            }
        }
    }
}

function setTextFromValue(txt, val, valElse) {
    if (typeof (txt) != "object") {
        txt = document.getElementById(txt);
    }

    if (val || !valElse) // !valElse : 20070116
    {
        txt.value = val ? val : "";
    }
    else if (valElse) txt.value = valElse;
}

function getValueFromText(txt) {
    if (typeof (txt) != "object") {
        txt = document.getElementById(txt);
    }
    return txt.value;
}

function setRadioFromValue(radioName, val) {
    var rg = document.getElementsByName(radioName);
    if (rg) {
        for (var i = 0; i < rg.length; i++) {
            if (rg[i].value == val) {
                rg[i].checked = true;
            }
        }
        UpdateLinkedFieldsForRadioGroup(radioName);
    }
}

function UpdateLinkedFieldsForRadioGroup(name) {
    var touchedFields = new Array(); // object for managing multiple linkeddiv with options

    var y = document.getElementsByName(name);
    var field;
    for (var i = 0; i < y.length; i++) {
        field = y[i];
        if (field && field.type && field.type == "radio" && field.getAttribute("hsshowdiv")) {
            var linkedIds = field.getAttribute("hsshowdiv").split("|");
            var linkedId;
            for (var j = 0; j < linkedIds.length; j++) {
                linkedId = linkedIds[j];
                if (linkedId && !touchedFields[linkedId]) {
                    if (field.checked) showField(linkedId);
                    else hideField(linkedId);
                    touchedFields[linkedId] = field.checked;
                }
            }
        }
    }
}

function getValueFromRadio(radioName) {
    var rg = document.getElementsByName(radioName);
    if (rg) {
        for (var i = 0; i < rg.length; i++) {
            if (rg[i].checked) {
                return rg[i].value;
            }
        }
    }
    return "";
}

var EmptyHtmlContents = ["<p></p>", "<p>&nbsp;</p>", "<p> </p>", "<p/>", "<p />"];
function IsEmptyHtml(value) {
    if (!value) {
        return true;
    }

    value = value.toLowerCase();

    for (var i = EmptyHtmlContents.length - 1; i >= 0; i--) {
        if (EmptyHtmlContents[i] == value) {
            return true;
        }
    }

    return false;
}

function getValueFromHtmlEditor(id) {
    var ed = tinymce.get(id);
    if (!ed) {
        return "";
    }

    var result = ed.getContent({ format: 'html' });
    if (IsEmptyHtml(result)) {
        return "";
    }

    return result;
}

function setHtmlEditorFromValue(id, value) {
    var ed = tinymce.get(id);
    if (ed) {
        ed.setContent(value);
    }
}

function setInnerHtml(oID, txt) {
    var o = document.getElementById(oID);
    if (o) {
        o.innerHTML = txt;
    }
}

function setInnerHtmlJaNee(oID, val) {
    if (val == 1) {
        setInnerHtml(oID, "Ja");
    } else {
        setInnerHtml(oID, "Nee");
    }
}

function getValueFromSelect(sel) {
    if (typeof (sel) != "object") {
        sel = document.getElementById(sel);
    }
    if (sel) {
        var i = sel.selectedIndex;
        if (i > -1) {
            return sel.options[i].value
        }
        else {
            return "";
        }
    }
}

function getValueFromCheckbox(cbx) {
    if (typeof (cbx) != "object") {
        cbx = document.getElementById(cbx);
    }
    var b = false;

    if (cbx) cbx.checked ? b = cbx.value : b = false;

    return b
}

function getTxtFromSelect(sel) {
    if (typeof (sel) != "object") {
        sel = document.getElementById(sel);
    }
    if (sel) {
        var i = sel.selectedIndex;
        if (i > -1) {
            return sel.options[i].text
        }
        else {
            return "";
        }
    }
}

function setSelectDisabled(sel, disable) {
    if (typeof (sel) != "object") {
        sel = document.getElementById(sel);
    }
    if (sel) {
        sel.disabled = disable;

        if (sel.getAttribute("hshasinput") == "true") {
            var o = document.getElementById(sel.id + "_input");
            if (o) o.disabled = disable;

            var o = document.getElementById(sel.id + "_img");
            if (o) o.disabled = disable;
        }
        else if ($(sel.parentNode).hasClass("selector"))
        {
            //new selectbox which uses jquery plugin uniform
            if (disable)
            {
                $(sel.parentNode).addClass("disabled");
            }
            else
            {
                $(sel.parentNode).removeClass("disabled");
            }
        }
    }
}

function removeOptionsFromSelect(sel) {
    if (typeof (sel) != "object") {
        sel = document.getElementById(sel);
    }
    if (sel) {
        while (sel.length > 0) {
            sel.remove(0);
        }

        if (sel.getAttribute("hshasinput") == "true") {
            var o = document.getElementById(sel.id + "_input");
            if (o) o.value = "";
        }
    }
}


function addOptionToSelect(sel, txt, val, showDiv) {
    if (typeof (sel) != "object") {
        sel = document.getElementById(sel);
    }
    if (sel) {
        var o = document.createElement("OPTION");
        sel.options.add(o);
        o.innerHTML = txt;
        o.value = val;
        if (showDiv) o.setAttribute("hsshowdiv", showDiv);
    }
}

function changeClassAddStr(oID, str) {
    var o = document.getElementById(oID);
    if (o) {
        if (o.className != '' && o.className.substr(o.className.length - str.length) != str) {
            s = o.className + str;
            o.className = s;
        }
    }
}

function changeClassDelStr(oID, str) {
    var o = document.getElementById(oID);
    if (o) {
        if (o.className != '' && o.className.substr(o.className.length - str.length) == str) {
            s = o.className.substr(0, o.className.length - str.length);
            o.className = s;
        }
    }
}

function showFieldError(oID, str, oExtraID) {
    var o = document.getElementById(oID);
    if (o) {
        o.style.display = "block";
        if (str) o.innerHTML = str;

        var index = -1;
        for (var i = 0; index == -1 && i < errorFields.length; i++) if (errorFields[i] == oID) index = i;
        if (index == -1) {
            errorFields.push(oID);
        }
    }
}

function hideField(oID) {
    var o = document.getElementById(oID);
    if (o) {
        o.style.display = "none";
    }
}

function showField(oID) {
    var o = document.getElementById(oID);
    if (o) {
        o.style.display = "block";
    }
}

function showFieldEx(oID) {
    var o = document.getElementById(oID);
    if (o) {
        o.style.display = "";
    }
}

function toggleField(oID) {
    if (fieldIsVisible(oID)) hideField(oID);
    else showField(oID);
}

function toggleFieldEx(oID) {
    if (fieldIsVisible(oID)) hideField(oID);
    else showFieldEx(oID);
}

function fieldIsVisible(oID) {
    var o = document.getElementById(oID);
    if (o) {
        return ((o.style.display == "block") || (o.style.display == ""))
    }
    return false;
}

function changeDisplayField(oID) {
    var o = document.getElementById(oID);
    if (o) {
        if (o.style.display == "none") {
            o.style.display = "block";
        }
        else {
            o.style.display = "none";
        }
    }
}

function ToggleMultiUitklap(prefix, activeId) {
    var i = 0;
    var o;
    var wasopen = false;
    while (null != (o = document.getElementById(prefix + (++i)))) {
        if (i == activeId) wasopen = o.style.display != 'none';
        o.style.display = 'none';
    }

    if (!wasopen) document.getElementById(prefix + activeId).style.display = 'block';
}

function ToggleMultiUitklapAndActivateTab(prefix, tabprefix, activeId, activeClass, unactiveClass) {
    var i = 0;
    var o;
    while (null != (o = document.getElementById(prefix + (++i)))) {
        o.style.display = 'none';
    }
    document.getElementById(prefix + activeId).style.display = 'block';

    var o, i = 0;
    while (null != (o = document.getElementById(tabprefix + (++i)))) {
        o.className = i == activeId ? activeClass : unactiveClass;
    }
}

function hideFieldError(oID) // voor backward compatibility
{
    hideField(oID);

    var index = -1;
    for (var i = 0; index == -1 && i < errorFields.length; i++) if (errorFields[i] == oID) index = i;
    if (index != -1) {
        errorFields.splice(index, 1);
    }
}

function hideAllFieldErrors() {
    for (var i = 0; i < errorFields.length; i++) {
        hideField(errorFields[i]);
    }
    errorFields.length = 0;
}

function enterToTab(field) {
    //	alert(window.event.keyCode);
    //	if(event.keyCode==13){
    //		window.event.keyCode=9;
    //event.returnValue = ;
    //	}	
    //== 45 || (event.keyCode > 47 &amp;&amp; event.keyCode < 58))) event.returnValue = false; else DateFormat(this,this.value,event,false,'3');
}

function setFocus(field) {
    if (typeof (field) != "object") {
        var fieldname = field;

        field = document.getElementById(field);

        if (!field || fieldname != field.id) // igv radio's
        {
            var fields = document.getElementsByName(fieldname);
            for (var i = 0; i < fields.length; i++) {
                if (fields[i].checked) {
                    field = fields[i];
                    break;
                }
            }
        }
    }

    if (field) {
        if (field.tagName.toLowerCase() == "select" && field.getAttribute("hshasinput") == "true") {
            field = document.getElementById(field.id + "_input");
        }

        if (field.type != "hidden") {
            field.focus();
        }
    }
}

function fmtMoney(n, c, d, t) { //v1.1
    n = Math.round(n * 100) * 0.01; // uitgaande van 2 decimalen, anders Math.pow(10, c) gebruiken

    var m = (c = Math.abs(c) + 2 ? c : 2, d = d || ",", t = t || ".",
        /(\d+)(?:(\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0;
    return (x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(\d{3})(?=\d)/g,
        "$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : "");
}

function disableField(oID) {
    var o = document.getElementById(oID);
    if (o) {
        o.disabled = true;
    }
}

function getIntValue(id) {
    var o = document.getElementById(id);
    if (o) {
        var i = o.value;

        i = i.replace(/\./, "");

        i = parseInt(i);

        if (isNaN(i)) {
            i = 0;
        }
        return i;
    }
}

function getFloatValue(id) {
    var o = document.getElementById(id);
    if (o) {
        var i = o.value;

        i = i.replace(/\./, "");
        i = i.replace(/\,/, ".");

        i = parseFloat(i);

        if (isNaN(i)) {
            i = 0;
        }
        return i;
    }
}

function composeName(voornaam, tussenv, achternaam) {
    var s = voornaam;
    if (tussenv) {
        if (s) s = s + " ";
        s = s + tussenv;
    }
    if (achternaam) {
        if (s) s = s + " ";
        s = s + achternaam;
    }
    return s;
}

function indexOf(ar, s) {
    for (var i = 0; i < ar.length; i++) {
        if (ar[i] == s) {
            return i;
        }
    }
    return -1;
}

function changeDisplayOfDivWithClassName(className, disp) {
    var e = document.getElementsByTagName("div");
    for (var i = 0; i < e.length; i++) {
        if (e[i].className == className) {
            e[i].style.display = disp;
            return;
        }
    }
}


function GetDots(value) {
    if (value == 0) {
        return "";
    }

    var orig = parseFloat(value);
    var t = value / 1000000;
    var i = Math.floor(t);
    var r = "";

    if (i > 0) {
        r += i.toString();
        r += ".";
        value -= i * 1000000;
    }
    t = value / 1000;
    i = Math.floor(t);
    if (i > 0) {
        if (i < 100 && orig >= 1000000) {
            r += "0";
            if (i < 10) r += "0";
        }
        r += i.toString();
        r += ".";
        value -= i * 1000;
    }
    else if (orig > 1000) r += "000.";
    if (value > 0) {
        i = Math.round(value);
        if (i < 100 && orig >= 1000) {
            r += "0";
            if (i < 10) r += "0";
        }

        r += i.toString();
        value -= i;
    }
    else if (orig > 0) r += "000";

    i = Math.round(value * 100);
    if (i > 0) {
        r += ",";
        if (i < 10) r += "0";
        r += i.toString();
    }

    return r;
}

function getTopPos(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;

    return curtop;
}
function getLeftPos(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;

    return curleft;
}

function InitAdvSelectOnNormalWebsite() {
    var y = document.getElementsByTagName('select');
    for (var i = 0; i < y.length; i++) 
    {
        hsInitAdvSelect(y[i].id);
    }
}

var zIndexForSelectContainerDiv = 1;

function setBlurfalse(id) {
    var oSel = document.getElementById(id);
    if (oSel) {
        oSel.blurring = false;
        oSel.isOpen = false;
    }
}

function hsInitAdvSelect(id) {
    var oSel = document.getElementById(id);
    if (!oSel || oSel.initialized) 
    {
        return;
    }

    if (oSel.getAttribute("hshasinput") == "true")
    {
        var oInput = document.getElementById(id + "_input");
        var oDiv = document.getElementById(id + "_div");
        var oImg = document.getElementById(id + "_img");

        oDiv.style.position = "absolute";
        oDiv.style.display = "none";
        oDiv.style.zIndex = 100;
        oInput.style.cursor = "default";
        oSel.isOpen = false;
        oSel.blurring = false;
        oSel.initialized = true;

        if (oDiv.getAttribute("hshtmlpositioned") == "true")
        {
            oDiv.style.left = oInput.offsetLeft + "px";
            oDiv.style.top = oInput.offsetHeight + "px";
        }

        if (oSel.selectedIndex != -1)
        {
            oInput.value = oSel.options[oSel.selectedIndex].text;
            oInput.hsSelectedValue = oSel.options[oSel.selectedIndex].value;
        }
        else
        {
            if (oSel.options[0])
            {
                oInput.value = oSel.options[0].text;
                oInput.hsSelectedValue = oSel.options[0].value;
            }
        }

        oInput.onfocus = function ()
        {
            oInput.blur();
            if (oSel.isOpen == false)
            {
                oSel.isOpen = true;
                hsShowAdvSelect(oSel.id);
            }
            else
            {
                oSel.isOpen = false;
                hsCancelAdvSelect(oSel.id);
            }
        }
        oSel.onblur = function ()
        {
            hsHideAdvSelect(oSel.id);
            oSel.blurring = true;
            setTimeout("setBlurfalse('" + oSel.id + "')", 100);
        }
        oSel.oldOnChange = oSel.onchange;
        /*
        oSel.onclick = function() {
        hsClickAdvSelect(oSel.id);
        if (oSel.oldOnChange) oSel.oldOnChange();
        }/**/
        oSel.onscroll = function (event)
        {
            if (!event) event = window.event;
            this.dontMouseUp = true;
            var this_ = this;
            clearTimeout(this.timeOut);
            this.timeOut = setTimeout(function ()
            {
                this_.dontMouseUp = false;
            }
        , 200);
        }
        oSel.onmouseup = function (event)
        {
            if (!event) event = window.event;
            if (!this.dontMouseUp)
            {
                setTimeout(function () { hsClickAdvSelect(oSel.id); if (oSel.oldOnChange) oSel.oldOnChange(); }, 50);
            }
            this.dontMouseUp = false;
            clearTimeout(this.timeOut);
        }
        oSel.onchange = null;
        oSel.onfocus = function () { if (!document.all) { try { document.activeElement = this; } catch (ex) { /*ignore*/ } } }
        oSel.onkeypress = function (event)
        {
            if (!event) event = window.event;

            if (event.keyCode == 13) // Return
            {
                hsClickAdvSelect(oSel.id);
                if (oSel.oldOnChange) oSel.oldOnChange();
            }
            else if (event.keyCode == 27) // Escape
            {
                hsCancelAdvSelect(oSel.id);
                if (oSel.oldOnChange) oSel.oldOnChange();
            }
        }
        oImg.onmousedown = function ()
        {
            var s = oImg.src;
            oImg.src = s.replace(/bg.gif/g, "bg_mo.gif");
        }
        oImg.onmouseup = function ()
        {
            var s = oImg.src;
            oImg.src = s.replace(/bg_mo.gif/g, "bg.gif");
        }
        oImg.onclick = function ()
        {
            if (!oSel.isOpen && !oSel.blurring)
            {
                oSel.isOpen = true;
                hsShowAdvSelect(oSel.id);
            }
            else
            {
                oSel.blurring = false;
                oSel.isOpen = false;
                hsCancelAdvSelect(oSel.id);
            }
        } 
    }
    else
    {
        //apply custom selectbox visualisation
        ApplyJQueryUniformSelect(oSel);
    }
}

function hsHideAdvSelect(id) {
    if (document.activeElement && (document.activeElement.id != id) && ((document.activeElement.id + "_img") != id) && ((document.activeElement.id + "_input") != id)) {
        hideField(id + "_div");
    }
}

function hsShowAdvSelect(id) {
    var oInput = document.getElementById(id + "_input");
    var oDiv = document.getElementById(id + "_div");
    var oSel = document.getElementById(id);

    if (oDiv.getAttribute("hshtmlpositioned") != "true") {
        oDiv.style.left = getLeftPos(oInput) + "px";
        oDiv.style.top = (getTopPos(oInput) + oInput.offsetHeight) + "px";
    }
    else {
        oDiv.style.left = oInput.offsetLeft + "px";
        oDiv.style.top = oInput.offsetHeight + "px";
        oDiv.parentNode.style.zIndex = ++zIndexForSelectContainerDiv;
    }
    //oDiv.style.left = getLeftPos(oInput)+"px";
    //oDiv.style.top = (getTopPos(oInput)+oInput.offsetHeight)+"px";

    var i = oSel.options.length;
    if (i > 10) i = 10;
    if (i == 1) i = 2;
    oSel.size = i;

    showField(id + "_div");
    /*
    for(i=0;i<oSel.options.length;i++)
    {
    if(oSel.options[i].text==oInput.value)oSel.selectedIndex=i;
    }
    /**/
    oSel.value = oInput.hsSelectedValue;
    oSel.focus();
}

function hsClickAdvSelect(id) {
    var o = document.getElementById(id);
    var i = document.getElementById(id + "_input");
    if (o) {
        var idx = o.selectedIndex;
        if (idx != -1 && o.options[idx]) {
            i.value = o.options[idx].text;
            i.hsSelectedValue = o.options[idx].value;
        }
    }
    hideField(id + "_div");
}

function hsCancelAdvSelect(id) {
    hideField(id + "_div");

    var o = document.getElementById(id);
    var i = document.getElementById(id + "_input");
    for (var j = 0; j < o.options.length; j++) {
        if (o.options[j].text == i.value) {
            o.selectedIndex = j;
            break;
        }
    }
}

function IsAdvancedSelect(o) {
    if (typeof (o) == "string") {
        o = document.getElementById(o);
    }

    if (o && o.tagName.toLowerCase() == "select" && o.getAttribute("hshasinput") == "true") {
        return true;
    }

    return false;
}

function changeDisplayMultiField(fields) {
    var x = fields.split("|");
    for (var i = 0; i < x.length; i++) {
        changeDisplayField(x[i]);
    }
}

function InitHintsOnWebsite() {
    var y = document.getElementsByTagName('a');
    for (var i = 0; i < y.length; i++) {
        if (y[i].getAttribute("hshinttext")) {
            y[i].onmouseover = function (event) { showhint(this.getAttribute("hshinttext"), this, event, ''); }
        }
    }
}

function GetQuerystringValue(name) {
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var tmpURL = window.location.href;
    var results = regex.exec(tmpURL);
    if (results == null) return "";
    else return results[1];
}

function getWeekNum() {
    // returns weeknumber for current date
    // checkdatum: 31-12-2031
    var today = new Date();
    return DateToWeekNum(today.getFullYear(), today.getMonth(), today.getDate());
}

// original YMD2YWD script from http://www.merlyn.demon.co.uk/weekcalc.htm#JS
function DateToWeekNum(y, m, d) {
    var ms1d = 864e5, ms7d = 7 * ms1d;
    var DC3 = Date.UTC(y, m, d + 3) / ms1d; // an Absolute Day Number
    var DoW = 1 + (DC3 + 7777777) % 7;
    var AWN = Math.floor(DC3 / 7); // an Absolute Week Number
    var Wyr = new Date(AWN * ms7d).getUTCFullYear();
    return [AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1];
}

function trimLeftRightSpaces(value) {
    value = value.replace(/^\s+/, '');
    value = value.replace(/\s+$/, '');
    return value;
}
function trimLeftSpaces(value) {
    value = value.replace(/^\s+/, '');
    return value;
}
function trimRightSpaces(value) {
    value = value.replace(/\s+$/, '');
    return value;
}

function GetDateAsString(date) {
    return zeroPad(date.getDate(), 2) + "-" + zeroPad((date.getMonth() + 1), 2) + "-" + zeroPad(date.getFullYear(), 4);
}
function GetDateAsStringInformation(date) {
    var dat = new Date();
    return zeroPad(date.getDate(), 2) + "-" + zeroPad((date.getMonth() + 1), 2) + "-" + zeroPad(date.getFullYear(), 4) + "<br/>om " + zeroPad(date.getHours(), 2) + ":" + zeroPad(date.getMinutes(), 2) + " uur";
}
function GetDateFromString(str) {
    if (!str) {
        return "";
    }
    var arr = str.split("-");
    var date = new Date();
    date.setFullYear(arr[2], 0, 1);
    date.setMonth(arr[1] - 1);
    date.setDate(arr[0]);
    return date;
}
function zeroPad(num, count) {
    var numZeropad = num + '';
    while (numZeropad.length < count) {

        numZeropad = "0" + numZeropad;
    }
    return numZeropad;
}

function IsTablet() {
    var ua = navigator.userAgent;

    if (ua.match(/iPad/i) ||
        ua.match(/Android/i)) {
        return true;
    }

    return false;
}

String.Format = function (msg)
{
    var args = arguments;
    msg = msg.replace(/\{[0-9]+\}/g, function (m)
    {
        var i = parseInt(m.substr(1, m.length - 2));
        return args[i + 1];
    });

    return msg;
}
