var facebookLoaded = false;

function enterKey(evt) {
    // Firefox supports .which, MSIE .keyCode 
    var charCode = (window.event) ? evt.keyCode : evt.which
    if (charCode == 13) {
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$ContentPlaceHolder1$Blocklogin2$CustomButton1', '', true, 'BlockLogin', '', false, true));
        return false;
    }
}

function changeCss(cbClientId, elementMobile, mobile, elementEmail, email, checkEmail, checkSms) {
    var checked = document.getElementById(cbClientId).checked;
    var re = /^\+316\d{8}$/;
    var validMobile = re.test(mobile);
    var el1 = document.getElementById(elementMobile);
    if (checkSms == 'True' && checked && !validMobile) {
        el1.style.visibility = 'visible';
    }
    else { el1.style.visibility = 'hidden' }

    var reg = /\w+([-+.]\w+||[-+.])*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    var validEmail = reg.test(email);
    var el2 = document.getElementById(elementEmail);
    if (checkEmail == 'True' && checked && !validEmail) {
        el2.style.visibility = 'visible';
    }
    else { el2.style.visibility = 'hidden' }
}

function addWkColumn(tblId, wkStart, wkNext) {
    var tbl = document.getElementById(tblId);
    var tblBodyObj = tbl.tBodies[0];
    var run = false;
    for (var i = 0; i < tblBodyObj.rows.length; i++) {
        // Month Header
        if (i == 0) {
            // Add extra colspan column
            tblBodyObj.rows[i].cells[0].colSpan = 8;
        }
        // Week Header
        if (i == 1) {
            // Add week column headline
            var newCell = tblBodyObj.rows[i].insertCell(0);
            newCell.innerHTML = 'wk';
            newCell.style.fontWeight = 'bold';
            newCell.style.verticalAlign = 'bottom';
            newCell.style.backgroundColor = '#DEDEDE';
        }
        // Normal row
        if (i >= 2) {
            // Add the weeknumbers
            var newCell = tblBodyObj.rows[i].insertCell(0);
            newCell.innerHTML = wkStart;
            wkStart += 1;
            if (!run && wkStart != wkNext) {
                wkStart = wkNext;
            }
            run = true;
            newCell.style.backgroundColor = '#DEDEDE';
        }
    }
}

function TabNext(obj, event, len, next_field) {
    if (event == "down") {
        field_length = obj.value.length;
    }
    else if (event == "up") {
        if (obj.value.length != field_length) {
            field_length = obj.value.length;
            if (field_length == len) {
                var field = document.getElementById(next_field);
                if (field != null) { field.focus(); }
            }
        }
    }
}


// enable/disable validators and ajax callouts clientside
function EnableValidator(cbClientId, rfvFirstNameClientId, cvDateClientId, revEmailClientId, vceBehaviourID1, vceBehaviourID2, vceBehaviourID3) {
    var checked = document.getElementById(cbClientId).checked;
    ValidatorEnable(document.getElementById(rfvFirstNameClientId), checked);
    ValidatorEnable(document.getElementById(cvDateClientId), checked);
    ValidatorEnable(document.getElementById(revEmailClientId), checked);
    if (!checked) {
        var i;
        var arr = new Array(vceBehaviourID1, vceBehaviourID2, vceBehaviourID3)
        for (i in arr) {
            var validator = $find(arr[i]);
            if (validator != null) {
                validator.hide();
                if (validator._elementToValidate != null) { Sys.UI.DomElement.removeCssClass(validator._elementToValidate, validator._highlightCssClass); }
            }
        }
    }
}

//select all checkbox in the first column of the gridview(gridid)
//by the checked value of the given checkbox id (id)
function SelectAll(id, gridId) {
    var grid = document.getElementById(gridId);
    var cell;
    if (grid.rows.length > 0) {
        for (i = 1; i < grid.rows.length; i++) {
            cell = grid.rows[i].cells[0];
            for (j = 0; j < cell.childNodes.length; j++) {
                if (cell.childNodes[j].type == "checkbox") {
                    cell.childNodes[j].checked = document.getElementById(id).checked;
                }
            }
        }
    }
}




function disableCopyPaste() {
    // current pressed key
    var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
    if (event.ctrlKey && (pressedKey == "c" || pressedKey == "v")) {
        // disable key press porcessing
        alert('Doordat er vaan fouten gemaakt worden met het invullen van een e-mailadres is het kopieren/plakken niet toegestaan voor dit veld');
        event.returnValue = false;
    }
}


//check session timeout
var sTO = 0;
function startClock(iTimeOutAlert) {
    iTimeOutAlert = (iTimeOutAlert / 100) * 60;
    clearTimeout(sTO); dWatch = 0;
    dStarted = new Date();
    updateClock(iTimeOutAlert);
}
function updateClock(iTimeOutAlert) {
    dNow = new Date(); dWatch = dNow.getTime() - dStarted.getTime();
    dClock = Math.round(dWatch / 1000);
    if (dClock >= iTimeOutAlert) { alert("De sessie is verlopen.\nU gaat terug naar de startpagina..."); window.location.href = "Default.aspx"; }
    else sTO = setTimeout("updateClock(" + iTimeOutAlert + ");", 250);

}


function cd() {
    return confirm("Weet je zeker dat je dit wilt verwijderen?");
}

function doLogin(returnURL) {
    document.SecureLoginForm.returnurl.value = returnURL;
    document.SecureLoginForm.username.value = document.Form1.f_username.value;
    document.SecureLoginForm.password.value = document.Form1.f_password.value;
    document.SecureLoginForm.submit();
}

function openImage(url1) {
    var wnd = window.open(url1, '', 'width=600,height=800,top=' + (screen.height / 2 - 115) + ', left=' + (screen.width / 2 - 60) + ', scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no');
}

function openWindow(sUrl, sHeight, sWidth) {
    var load = window.open(sUrl, 'info', 'scrollbars=yes,menubar=no,height=' + sHeight + ',width=' + sWidth + ',resizable=yes,toolbar=no,location=no,status=no');
    load.focus()
}


function printWindow() {
    bV = parseInt(navigator.appVersion)
    if (bV >= 4) window.print()
}


