﻿// JavaScript

function MWM2POPUPWriteCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else {
        var expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function MWM2POPUPReadCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);

        if (c.indexOf(nameEQ) == 0) {
            return c.substring(nameEQ.length, c.length);
        }
    }

    return null;
}

function MWM2POPUPEraseCookie(name) {
    createCookie(name, "", -1);
}


function PopupCounter(link, showCount, title, body, bodybottom, closePauzePeriod, closeButton, imageUrl) {
    WriteCSS(closeButton);

    var showDaysAfterClose = 14;

    var i = MWM2POPUPReadCookie('MWM2POPUPCounter');

    if ((i > -1) || (i == null)) {
        if (i > showCount) {
            document.write('<div id="MWM2LayerBackground"></div><div class="MWM2POPUP" id="MWM2POPUP">');
            document.write('    <table border=0 cellpadding=5 cellspacing=3 width=340 align=center>');
            document.write('        <tr>');
            document.write('            <td class="MWM2POPUPTopbar" style="background-image:url(\'' + imageUrl + '\')"><div style="float:right;" class="MWM2POPUPCloseButton" onclick="document.getElementById(\'MWM2LayerBackground\').style.display=\'none\';document.getElementById(\'MWM2POPUP\').style.display=\'none\';MWM2POPUPWriteCookie(\'MWM2POPUPCounter\',-1,' + closePauzePeriod + ');"></div></td>');
            document.write('        </tr>');
            document.write('        <tr>');
            document.write('            <td class="MWM2POPUPBody"><table><tr><td class="MWM2POPUPRight">');
            document.write(body);
            document.write('                <br /><br /><div class="MWM2POPUPButtonsWrapper">');
            document.write('                    <input type=button name=Ja value="Ja, ik doe mee!" class="MWM2POPUPButtons MWM2POPUPButtonJA" onclick="MWM2PopupClickYes(\'' + link + '\')">');
            document.write('                    <input type=button name=Nee value="Nee, bedankt" class="MWM2POPUPButtons MWM2POPUPButtonNEE" onclick="MWM2POPUPWriteCookie(\'MWM2POPUPCounter\',-1,\'' + showDaysAfterClose + '\');window.location.reload();">');
            document.write('                </div></td></tr></table>');

            if (bodybottom != null) {
                document.write(bodybottom);
            }

            document.write('            </td>');
            document.write('        </tr>');
            document.write('    </table>');
            document.write('</div>');

            /* TODO: remove flicker! */
            window.setTimeout(function() {
                createBackdrop(document.getElementById('MWM2POPUP'), document.getElementById('MWM2LayerBackground'));
            }, 200);
        }


        i++;
        MWM2POPUPWriteCookie('MWM2POPUPCounter', i);
    }
}

//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//
//                                          CHANGEBLE PARTS BELOW
//
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

function createBackdrop(foreground, background) {
    background.style.width = foreground.clientWidth + 'px';
    background.style.height = foreground.clientHeight + 'px';
    background.style.top = foreground.offsetTop + 'px';
    background.style.left = foreground.offsetLeft + 'px';
}

function MWM2PopupClickYes(link) {
    MWM2POPUPWriteCookie('MWM2POPUPCounter', -1, '31');
    document.getElementById('MWM2POPUP').style.display = 'none';
    document.getElementById('MWM2LayerBackground').style.display = 'none';

    window.open(link, 'MWM2Onderzoekapplicatie', 'resizable=1,width=800,height=600');
}

function HunkemollerPopup(clicks) {
    PopupCounter('http://onderzoek.mwm2.nl/ga.asp?vp=23B34314-CFA0-4E57-971B-11B30467D4CD&alin=ja',
                 clicks - 1,
                 'klantenonderzoek',
                 'Wij zijn nieuwsgierig naar uw mening! Doe mee met onze online enquête, uw mening telt en draagt bij aan eventuele verbeteringen. Het zijn 20 vragen en kost hooguit 5 minuten.',
                 '',
                 1,
                 'http://onderzoek.mwm2.nl/third/hunkemoller/layer/kruis.gif',
                 'http://onderzoek.mwm2.nl/third/hunkemoller/layer/hunkemollerlogo.gif');
}

function WriteCSS(closeButton) {
    document.write("<style type=\"text/css\">");

    document.write("#MWM2LayerBackground");
    document.write("{");
    document.write("    display: block;");
    document.write("    background: black;");
    document.write("    position: absolute;");
    document.write("    opacity: 0.66;");
    document.write("    filter: alpha(opacity='66');");
    document.write("    border: solid 1px #907c5b;");
    document.write("}");

    document.write(".MWM2POPUPTopbar");
    document.write("{");
    document.write("    font-size:12pt;");
    document.write("    font-family:helvetica,arial,sans-serif;");
    document.write("    color:#eaeaea;");
    document.write("    font-weight:bold;");
    document.write("    background-position: 8px 7px;");
    document.write("    background-repeat: no-repeat;");
    document.write("}");

    document.write(".MWM2POPUPButtons");
    document.write("{");
    document.write("    font-size:10pt;");
    document.write("    width:120px;");
    document.write("    font-family:arial;");
    document.write("    margin-right:15px;");
    document.write("}");

    document.write(".MWM2POPUPBody");
    document.write("{");
    document.write("    font-size:10pt;");
    document.write("    font-family:helvetica,arial,sans-serif;");
    document.write("    color:white;");
    document.write("}");

    document.write("");

    document.write(".MWM2POPUPLeft");
    document.write("{");
    document.write("     vertical-align:top;");
    document.write("     padding-right:10px;");
    document.write("}");

    document.write(".MWM2POPUPRight");
    document.write("{");
    document.write("     padding-left:10px;");
    document.write("}");

    document.write(".MWM2POPUPButtonsWrapper");
    document.write("{");
    document.write("     text-align:center;");
    document.write("     padding-top:5px;");
    document.write("}");

    document.write(".MWM2POPUP");
    document.write("{");
    document.write("    width:344px;");
    document.write("    padding-top:2px;");
    document.write("    padding-bottom:2px;");
    document.write("    font-family:helvetica,arial,sans-serif;");
    document.write("    padding-left:2px;");
    document.write("    padding-right:2px;");
    document.write("    position: absolute;");
    document.write("    top: 70px;");
    document.write("    left: 50%;");
    document.write("    margin-left:-172px;");
    document.write("    z-index:9999;");
    document.write("}");

    document.write(".MWM2POPUPCloseButton");
    document.write("{");
    document.write("    margin-top:2px;");
    document.write("    width:15px;");
    document.write("    background-image:url(\'" + closeButton + "\');");
    document.write("    background-repeat:no-repeat;");
    document.write("    height:15px;");
    document.write("    cursor:pointer;");
    document.write("    font-family:helvetica,arial,sans-serif;");
    document.write("}");

    document.write("</style>");
}