﻿function FilterNumeric(dots)
{
    //debugger;
    var ch = String.fromCharCode(event.keyCode);
    if (event.keyCode < 32)
    {
        return;
    }

    if ((event.keyCode <= 57) && (event.keyCode >= 48))
    {
        if (!event.shiftKey)
        {
            return;
        }
    }
    if (dots != false)
    {
        if ((ch == ',') || (ch == '.'))
        {
            event.keyCode = 44; // ',', Pagina's instellen op nl-NL
            return;
        }
    }
    event.returnValue = false;
}

function popup(callback, dest, w, h, name)
{
    //debugger;
    var term = "?callback=" + callback;

    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    if (winl < 0) winl = 0;
    if (wint < 0) wint = 0;

    var page = dest + term;
    windowprops = "height=" + h + ",width=" + w + ",top=" + wint + ",left=" + winl + ",location=no,"
		+ "scrollbars=yes,menubars=no,toolbars=no,resizable=no,status=yes";

    win2 = window.open(page, name, windowprops);
    if (win2.opener == null)
    {
        win2.opener = self;
    }
}

function popopen(callback, dest, w, h, name)
{
    //debugger;
    var term = "?callback=" + callback;

    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    if (winl < 0) winl = 0;
    if (wint < 0) wint = 0;

    var page = dest + term;
    windowprops = "height=" + h + ",width=" + w + ",top=" + wint + ",left=" + winl + ",location=no,"
		+ "scrollbars=yes,menubars=no,toolbars=no,resizable=yes,status=yes";

    win2 = window.open(page, name, windowprops);
    if (win2.opener == null)
        win2.opener = self;
}

var delay = 20; // Aantal seconden om te wachten
function SessionStart()
{

    var exp = new Date();
    exp.setSeconds(exp.getSeconds() + delay);

    // Cookie zetten die na x minuten expired
    setCookie("sesstart", "yes", exp);

    // Is even voor te debuggen, elke 2 seconden even checken tot de cookie weg is
    //setTimeout(CheckDelay, 2000)
}

function CheckDelay()
{
    var ck = getCookie("sesstart"); // als ie er nog is ben ik pas net op de site
    var ret = (ck == null);
    //	if (ck != null) {
    //		setTimeout(CheckDelay, 2000);
    //	}
    //	else {
    //		alert("Time!");
    //	}
    return ret;
}

function setCookie(name, value, expires, path, domain, secure)
{
    var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie(name)
{
    var results = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');

    if (results)
        return (unescape(results[2]));
    else
        return null;
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
function Toggle(div, hidden, shown)
{
    var sibling;
    if (div.nextSibling.nodeType == 3)
    {
        sibling = div.nextSibling.nextSibling; // Moz. Opera
    }
    else
    {
        sibling = div.nextSibling; // IE
    }

    if (sibling.style.display != "none")
    {
        sibling.style.display = "none";
        div.innerHTML = hidden;
    }
    else
    {
        sibling.style.display = "inline";
        div.innerHTML = shown;
    }
}

function ScrollToTop(elem)
{
    var pos = $("#" + elem).position();
    $(window).scrollTop(pos.top);
}
function loadjscssfile(filename, filetype)
{
    if (filetype == "js")
    {
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css")
    {
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

function WaterMark(id, txt, evt)
{
    var c = $('#' + id);
    var t = c.val();
    if (c.attr('type') == 'password')
    {
        if (t.length == 0 && evt.type == "blur")
        {
            c.addClass('watermarked_psw');
        }

        if (t == '' && evt.type == "focus")
        {
            c.removeClass('watermarked_psw');
        }
    }
    else
    {
        if (t.length == 0 && evt.type == "blur")
        {
            c.val(txt);
        }

        if (t == txt && evt.type == "focus")
        {
            c.val('');
        }
    }
}

function MyShowModal(id, closer, mask)
{
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $(mask).css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect		
    $(mask).fadeIn(1000);
    $(mask).fadeTo("slow", 0.6);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top', winH / 2 - $(id).height() / 2);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    //transition effect
    $(id).fadeIn(2000);

    //if close button is clicked
    var cl = $(mask);
    $(closer).click(function (e)
    {
        //Cancel the link behavior
        e.preventDefault();

        $(mask).hide();
        $(id).hide();
    });

    //if mask is clicked
    $(mask).click(function ()
    {
        $(this).hide();
        $(id).hide();
    });
}

function SendAjax(urlMethod, jsonData, returnFunction, async)
{
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        async: async,
        url: urlMethod,
        data: jsonData,
        dataType: "json",
        success: function (msg)
        {
            // Do something interesting here.
            if (msg != null)
            {
                returnFunction(msg);
            }
        },
        error: function (xhr, status, error)
        {
            // Boil the ASP.NET AJAX error down to JSON.
            var err = eval("(" + xhr.responseText + ")");
            // Display the specific error raised by the server
            alert(err.Message);
        }
    });
} 

