function zoomMobile(factor) {
    document.body.style.zoom = frameWidth() / factor;
    //alert(frameWidth() + '  ' + document.body.style.zoom);
    //document.Fm.TxAre.value = factor;
}

function getOffsetX(pCtl, e) {
    var isIE = false;
    if (navigator.appName == "Microsoft Internet Explorer") {
        isIE = true;
    }

    //alert(document.getElementById(pCtl).offsetLeft);
    if (isIE) {
        OffsetX = window.event.offsetX;
    } else {
        OffsetX = e.pageX - document.getElementById(pCtl).offsetLeft;
    }

    return OffsetX;
}

function getOffsetY(pCtl, e) {
    var isIE = false;
    if (navigator.appName == "Microsoft Internet Explorer") {
        isIE = true;
    }

    if (isIE) {
        OffsetY = window.event.offsetY;
    } else {
        OffsetY = e.pageY - document.getElementById(pCtl).offsetTop;
    }
    return OffsetY;
}

//function frameHeight() {
//    var winH = 460;
//    if (document.body && document.body.offsetWidth) {
//        winH = document.body.offsetHeight;
//    }
//    if (document.compatMode == 'CSS1Compat' &&
//    document.documentElement &&
//    document.documentElement.offsetWidth) {
//        winH = document.documentElement.offsetHeight;
//    }
//    if (window.innerWidth && window.innerHeight) {
//        winH = window.innerHeight;
//    }

//    return  winH;
//}

function frameHeight() {
    var myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}

//function frameHeight() {
//    var height;

//    if (self.innerWidth) {
//        height = self.innerHeight;
//    }
//    else if (document.documentElement && document.documentElement.clientWidth) {
//        height = document.documentElement.clientHeight;
//    }
//    else if (document.body) {
//        height = document.body.clientHeight;
//    }
//    return height;
//}

function frameWidth() {
    var width;

    if (self.innerWidth) {
        width = self.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        width = document.documentElement.clientWidth;
    }
    else if (document.body) {
        width = document.body.clientWidth;
    }
    return width;
}

function validateTime(source, arguments) {
    var tijd = arguments.Value;
    var sign;
    var uren = 0;
    var minuten = 0;
    var posDubbelepunt = -1;

    //tijd = tijd.replace(".", ":");
    //tijd = tijd.replace(",", ":");

    arguments.IsValid = true;

    sign = tijd.substring(0, 1);
    if (sign == "-") {
        tijd = tijd.substring(1, tijd.length - 1);
    }

    posDubbelepunt = tijd.indexOf(":");

    if (posDubbelepunt >= 0) {
        uren = tijd.substring(0, posDubbelepunt);
        minuten = tijd.substring(posDubbelepunt + 1, tijd.length);
        //alert(uren);
        //alert(minuten);

        if (isNaN(uren))
            arguments.IsValid = false;

        if (isNaN(minuten))
            arguments.IsValid = false;

        if (minuten > 59)
            arguments.IsValid = false;
    }
    else {
        if (isNaN(tijd))
            arguments.IsValid = false;
    }
}

function SizeDatagrid(datagrid, dwidth, dheight) {
    //var breedte = screen.availWidth - dwidth;
    //var hoogte = screen.availHeight - dheight;

    var breedte = frameWidth() - dwidth;
    var hoogte = frameHeight() - dheight;

    //alert(breedte);
    //alert(hoogte);

    if (document.getElementById(datagrid) != null) {

        //if (dwidth != 0) {
        document.getElementById(datagrid).style.width = breedte;
        //}

        //if (dheight != 0) {
        document.getElementById(datagrid).style.height = hoogte;
        //}
    }
}

function Clickheretoprint(title, footer) {
    var disp_setting = "toolbar=no,location=no,directories=no,menubar=no,resizable=yes,";
    disp_setting += "scrollbars=yes,width=900, height=600, left=0, top=0";
    var content_vlue;
    var content_id;

    content_vlue = document.getElementById("print_content1").innerHTML;

    for (i = 2; i <= 10; i++) {
        content_id = "print_content" + i;
        if (document.getElementById(content_id) != null) {
            content_vlue += document.getElementById(content_id).innerHTML;
        }
    }

    var docprint = window.open("", "", disp_setting);
    docprint.document.open();
    docprint.document.write('<html xmlns="http://www.w3.org/1999/xhtml" ><head><title>mijnDienstrooster</title>');
    docprint.document.write('<link href="../Styles/Styles.css" type="text/css" rel="stylesheet" />');
    docprint.document.write('</head><body onLoad="self.print();self.close()">');
    //			docprint.document.write('</head><body onLoad="">');

    if (title != '')
        docprint.document.write('<H2>' + title + '</H2>');
        
        
    docprint.document.write(content_vlue);

    if (footer != '')
        docprint.document.write(footer);
    
    docprint.document.write('</body></html>');
    docprint.document.close();
    docprint.focus();
}

function showProgressBar() {

    document.write("<table id='tblProgress' cellSpacing='0' cellPadding='0' width='185' border='0'	style='BORDER-RIGHT: dimgray 1px solid; BORDER-TOP: dimgray 1px solid; Z-INDEX: 999; LEFT: 424px; BORDER-LEFT: dimgray 1px solid; WIDTH: 185px; BORDER-BOTTOM: dimgray 1px solid; POSITION: absolute; TOP: 192px; HEIGHT: 92px'>")
    document.write("<tr>")
    document.write("<td style='HEIGHT: 23px' align='center'><BR>Even geduld a.u.b.<BR>")
    document.write("</td>")
    document.write("</tr>")
    document.write("<tr>")
    document.write("<td>")
    document.write("<P align='center'>")
    document.write("<img src='../Images/Other/progressbar.gif'><BR>")
    document.write("</P>")
    document.write("</td>")
    document.write("</tr>")
    document.write("</table>")
}

function setFocusFirst() {
    //Set focus to first control
    var bFound = false;

    // for each form 
    for (f = 0; f < document.forms.length; f++) {
        // for each element in each form 
        for (i = 0; i < document.forms[f].length; i++) {
            // if it's not a hidden element 
            if (document.forms[f][i].type != "hidden") {
                // and it's not disabled 
                if (document.forms[f][i].disabled != true) {
                    // set the focus to it 
                    document.forms[f][i].focus();
                    var bFound = true;
                }
            }
            // if found in this element, stop looking 
            if (bFound == true)
                break;
        }
        // if found in this form, stop looking 
        if (bFound == true)
            break;
    }
}

function DeleteDienst(par_mdw, par_dag, par_datum, par_dienst, par_dienstnaam, par_id, par_herhalenid) {

    //alert('DeleteDienst');
    document.getElementById('SelectMedewerker').value = par_mdw;
    document.getElementById('SelectDay').value = par_dag;
    document.getElementById('DeleteHerhaling').value = "0";

    ok = window.confirm('Wilt u ' + par_dienstnaam + ' op ' + par_datum + ' verwijderen? ');

    if (par_herhalenid != "0") {
        ok2 = window.confirm('Wilt u de hele reeks verwijderen? (Klik op Afbreken/Cancel als u alleen het geselecteerd item wilt verwijderen)');
        if (ok2)
            document.getElementById('DeleteHerhaling').value = "1";
    }

    if (ok) {
        document.getElementById("ID").value = par_id;
        document.getElementById("DeleteOK").value = par_id;
        document.getElementById("SelectDatum").value = par_datum;

        //if (AutoRefresh())
        //noodzakelijk omdat anders het Contextmenu niet altijd goed werkt
        __doPostBack('grdRooster', '');
    }
}

function WijzigDienst(par_mdw, par_dag, par_datum, par_dienst, par_dienstnaam, par_id, par_functiegroep) {

    form = "RoosterEdit.aspx?datum=" + par_datum + "&emp=" + par_mdw + "&dienst=" + par_dienst + "&mode=0&id=" + par_id + "&fg=" + par_functiegroep;
    //alert(form);
    document.getElementById("SelectDatum").value = par_datum;
    document.getElementById("ID").value = par_id;
    OpenRoosterEdit(form);

    //noodzakelijk omdat anders het Contextmenu niet altijd goed werkt
    //__doPostBack('','');
}

function HerhaalDienst(par_mdw, par_dag, par_datum, par_dienst, par_dienstnaam, par_id) {

    document.getElementById("ID").value = par_id;
    form = "RoosterHerhalen.aspx?datum=" + par_datum + "&emp=" + par_mdw + "&dienst=" + par_dienst + "&id=" + par_id;
    //alert(form);
    OpenRoosterEdit(form);
}

function RuilenDienst(par_mdw, par_dag, par_datum, par_dienst, par_dienstnaam, par_id) {

    form = "DienstRuilen.aspx?datum=" + par_datum + "&emp=" + par_mdw + "&dienst=" + par_dienst + "&id=" + par_id;
    //alert(form);
    OpenRoosterRuilen(form);

    //noodzakelijk omdat anders het Contextmenu niet altijd goed werkt
    //__doPostBack('','');
}

function Ziekmelding(par_mdw, par_datum) {

    form = "Ziekmelding.aspx?datum=" + par_datum + "&emp=" + par_mdw;
    open_dialog(form, "500", "240", "no");
    __doPostBack('grdRooster', '');
}

function ChangeDienst(par_mdw, par_dag, par_maand, par_jaar, par_dienstold, par_meerdienstenperdag, par_dienstnaamold, par_diensttype, par_heledag, par_id, par_functiegroepID) {

    document.getElementById('SelectMedewerker').value = par_mdw;
    document.getElementById('SelectDay').value = par_dag;
    document.getElementById('SelectFunctiegroep').value = par_functiegroepID;

    var selectedindex, selectedaction, selecteddienst, i, ok, form;
    selectedindex = 99;
    selectedaction = '';
    selecteddienst = 0;

    par_maand = par_maand - 1;    //Januari = 0, December = 11
    var datum = new Date(par_jaar, par_maand, par_dag);
    
    //Nodig om te voorkomen dat het edit-scherm 2x achter elkaar komt
    if (editRooster == false) {

        if (document.getElementById("btlDienst")) {
            for (i = 0; i <= document.Form1.btlDienst.length - 1; i++) {
                if (document.Form1.btlDienst[i].checked == true) {
                    selectedindex = i
                }
            }
        }

        if (document.getElementById("lstDienst")) {
            selecteddienst = document.Form1.lstDienst.value;
        }

        if (selectedindex != 99)
            selectedaction = document.Form1.btlDienst[selectedindex].value;


        //    alert(selectedaction);
        //    alert(selecteddienst);

        //datum = par_dag + "-" + par_maand + "-" + par_jaar;

        document.getElementById("SelectDatum").value = datum.toDateString();

        if (selectedaction == '' || (selecteddienst == 0 && selectedaction == 'Toevoegen')) {
            //alert('Selecteer eerst een actie, dienst of taak ');
            //document.getElementById('SelectMedewerker').value = "";
            document.getElementById('SelectMedewerker').value = "";
            form = "RoosterEdit.aspx?datum=" + datum.toDateString() + "&emp=" + par_mdw + "&mode=0&fg=" + par_functiegroepID;
            OpenRoosterEdit(form);
        }
        else {

            ok = false;
            switch (selectedaction) {
                case 'Verwijder': 			//verwijder dienst
                    if (par_dienstold != 0 && par_dienstold != 999) {    //dienst gepland en geen roosterwens

                        //ok = window.confirm('Wilt u ' + par_dienstnaamold + ' op ' + par_dag + '-' + par_maand + '-' + par_jaar + ' verwijderen? ');
                        ok = window.confirm('Wilt u ' + par_dienstnaamold + ' op ' + datum.toDateString() + ' verwijderen? ');
                        if (ok) {
                            document.getElementById("DeleteOK").value = par_id;
                        }
                    }
                    else {
                        //alert('Er is geen dienst of taak gepland op deze datum. Verwijderen is niet mogelijk');
                        document.getElementById('SelectMedewerker').value = "";
                    }
                    break;

                case 'Wijzig': 			//dienst wijzigen, opmerking toevoegen
                    if (par_dienstold > 0 && par_dienstold < 999) {
                        ok = true;
                        //datum = par_dag + "-" + par_maand + "-" + par_jaar;
                        form = "RoosterEdit.aspx?datum=" + datum.toDateString() + "&emp=" + par_mdw + "&dienst=" + par_dienstold + "&mode=0&fg=" + par_functiegroepID;
                        OpenRoosterEdit(form);
                    }
                    else {
                        alert('Wijzigen is alleen mogelijk indien er een dienst of taak is gepland');
                        document.getElementById('SelectMedewerker').value = "";
                    }
                    break;

                case 'Toevoegen': 					//dienst toevoegen
                    if (par_dienstold == 0) {
                        ok = true;
                    }
                    else {
                        //if (par_diensttype == 0 && par_heledag) {    
                        //	alert('De medewerker is op deze datum afwezig. Er kan derhalve geen dienst of taak worden gepland');
                        //}
                        //else {
                        if (par_dienstold == 99999) {
                            ok = window.confirm('De medewerker heeft verzocht op deze datum geen dienst of taak te plannen. Wilt u toch een dienst plannen op deze datum?');
                            //document.getElementById('SelectMedewerker').value = "";
                        }
                        else {
                            if (par_dienstold == 99996) {     //verzoek
                                ok = true;
                            }
                            else {
                                if (par_meerdienstenperdag == 'True') {
                                    ok = true;
                                }
                                else {
                                    alert('Toevoegen niet mogelijk omdat er al een item is gepland op deze dag/tijd')
                                }
                            }
                        }
                    }
                    break;
                default:
                    alert("fout");
            }
            if (ok == true)
                __doPostBack('grdRooster', '');
            else
                document.getElementById('SelectMedewerker').value = "";
        }
    }
}

function SetFocus(par_control) {
    document.getElementById(par_control).focus();
    return false;
}

function LoadPage(par_page) {

    //alert(top.frames[par_frame].location);
    //alert(path());
    //top.frames[par_frame].location = path() + par_page;
    document.location = par_page;
}

function path() {
    //_path is the path + file name
    // var _path = top.frames[0].location.toString();
    var _path = document.location.toString();

    var lengte;

    //extract file name from _path
    lengte = _path.length;

    while (_path.substring(lengte - 1, lengte) != "/") {
        _path = _path.substring(0, lengte - 1);
        lengte = _path.length;
    }
    _path = _path.substring(0, lengte);
    return _path
}

function ValidateInfoForm(frm) {
    var returnVal = false

    //alert("start Validate");

    if (frm.naam.value == "") {
        alert("Vul uw naam in")
        frm.naam.focus()
    }
    else if (frm.email.value == "") {
        alert("Vul uw e-mail adres in")
        frm.email.focus()
    }
    else {
        returnVal = true
        frm.submit()
    }
    return returnVal
}

function MouseOn(button) {
    if (document.getElementById(button)) {
        var src = new String(document.getElementById(button).src);
        document.getElementById(button).src = src.substring(0, src.length - 4) + "_on.gif";
    }
}

function MouseOff(button) {
    if (document.getElementById(button)) {
        var src = new String(document.getElementById(button).src);
        document.getElementById(button).src = src.substring(0, src.length - 7) + ".gif";
    }
}

function ganaar(par_location) {
    //lert('ganaar');
    //alert(eval("'"+path()+par_location.options[par_location.selectedIndex].value+"'");
    //if (par_location != 0)
    eval("top.frames[1].location='" + path() + par_location.options[par_location.selectedIndex].value + "'");
}

function afdrukken(form) {
    //alert(form);
    window.open(form, "printwindow", "toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=500 ,width=740, ,top=20,left=20,screenx=20,screeny=20");
}

function open_disclaimer() {
    window.open(path() + "disclaimer.htm", "column", "toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=no,height=400,width=450");
}

function open_appwindow(form) {

    var breedte = screen.width - 12;
    var hoogte = screen.height - 100;
    var winname = "appwindow" + Math.random();
    var point = "."
    winname = winname.replace(point, "");
    var appwindow = window.open(form, winname, "fullscreen=no,toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,status=yes,titlebar=yes,width=" + breedte + ",height=" + hoogte + ",top=0,left=0,screenx=0,screeny=0");

    //if (appwindow == null) {
    if (!appwindow || !appwindow.top) {
        alert("Voor het starten van mijnDienstrooster moeten pop-ups zijn toegestaan. Schakel de pop-up blocker van Internet Explorer (of andere browser) uit voor mijnDienstrooster.nl of houd de CTRL-toets ingedrukt als u klikt op de login-knop");
    }
}

function maximize_window() {
    top.window.moveTo(0, 0);
    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }
    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}

function open_afbeelding(form, breedte, hoogte) {

    //appwindow = window.open(form,"appwindow","fullscreen=no,toolbar=no,directories=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no,titlebar=yes,width=" + breedte + ",height=" + hoogte + ",top=0,left=0,screenx=0,screeny=0");
    //appwindow = window.showModalDialog(form,"appwindow","fullscreen=no,toolbar=no,directories=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no,titlebar=yes,width=" + breedte + ",height=" + hoogte + ",top=0,left=0,screenx=0,screeny=0");
    window.showModalDialog(form, "", "dialogWidth:" + breedte + " px; dialogHeight:" + hoogte + "px; center:yes; scroll:no; status:no; resizable:no");

}

function open_help(helpid) {
    //alert(helpid);

    if (helpid != 0) {
        form = path() + "../help/help.aspx?helpid=" + helpid;
        open_dialog(form, "650", "550", "no");
    }
    else {
        alert("Voor deze pagina is geen help gevonden")
    }
}
function AutoRefresh() {
    var refresh = true;
    if (document.getElementById("chkRefresh"))
        refresh = document.getElementById("chkRefresh").checked;
    return refresh;
}

function OpenRoosterRuilen(form) {
    open_dialog(form, "700", "340", "no");

    if (AutoRefresh())
        __doPostBack('grdRooster', '');
}

function OpenRoosterEdit(form) {
    open_dialog(form, "670", "670", "no");

    if (AutoRefresh())
        __doPostBack('grdRooster', '');
}

function OpenAgendaEdit(form) {
    open_dialog(form, "660", "670", "no");
    //alert('postback');
    __doPostBack('UpdatePanel1', '');
}

function Verwijderen(mode, id, tekst, id2, id3) {
    var form = "Verwijderen.aspx?mode=" + mode + "&id=" + id + "&tekst=" + tekst + "&id2=" + id2 + "&id3=" + id3;
    open_dialog(form, "480", "130", "no");

    if (AutoRefresh())
        __doPostBack('', '');
}

function open_dienst(id, groep) {
    var form = "EditDienst.aspx?id=" + id + "&groep=" + groep;

    //alert(form);
    open_dialog(form, "570", "620", "no");
    //window.showModalDialog(form,"","dialogWidth:500px; dialogHeight:370px; center:yes; scroll:no; status:no; resizable:no");

    if (AutoRefresh())
        __doPostBack('', '');
}
function open_employee(id, mode) {
    var form = "EditEmployee.aspx?emp=" + id + "&mode=" + mode;
    //alert(form);
    //open_dialog(form, "600", "700", "yes");
    //Let op: In een dialog werkt het exporteren naar Excel niet (vakantiekaart)
    window.open(form,"editemployeewindow","toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=700 ,width=600, ,top=100,left=100,screenx=100,screeny=100");
    LoadPage(document.location);
}

function open_adres(id, type) {
    var form = "EditAdres.aspx?adresid=" + id + "&adrestype=" + type;
    //alert(form);
    open_dialog(form, "600", "600", "no");
    //window.open(form,"editemployeewindow","toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=700 ,width=600, ,top=100,left=100,screenx=100,screeny=100");
    LoadPage(document.location);
}

function open_vakantiekaart() {
    var form = "Vakantiekaart.aspx";
    //open_dialog(form,"600","700","no");	
    window.open(form, "vakantiekaartwindow", "toolbar=no,directories=no,menubar=no,location=no,scrollbars=no,resizable=yes,height=640 ,width=640, ,top=100,left=100,screenx=100,screeny=100");
}

function open_editvakantiekaart(mode, empid, year) {
    var form = "VakantieEdit.aspx?mode=" + mode + "&emp=" + empid + "&year=" + year;
    open_dialog(form, "500", "250", "no");
}

function open_opties() {
    var form = "Opties.aspx";
    open_dialog(form, "780", "690", "no");
}

function open_dialog(form, width, height, scroll) {
    //alert(form);
    if (window.showModalDialog == null || window.showModalDialog == "undefined")
        window.open(form, form, "modal=yes,toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width + ", ,top=20,left=20,screenx=20,screeny=20")
    else
        window.showModalDialog(form, form, "dialogWidth:" + width + "px; dialogHeight: " + height + "px; center:yes; scroll:" + scroll + "; status:no; resizable:no");
}

function close_window() {

    if (window.confirm("Wilt u stoppen?")) {
        window.parent.close()
        return true
    }
    else
        return false;
}

function change_status(par_status) {
    window.status = par_status;
}

function GetConfirm(msg) {
    if (confirm(msg) == true)
        return true;
    else
        return false;
}

function CheckPassword(objSource, objArgs) {
    var pwdValid = true;

    if (objArgs.Value != "") {
        var str = new String(objArgs.Value);

        if (str.length < 6) {
            pwdValid = false;
            //alert("Het wachtwoord is te kort. Gebruik minimaal 6 karakters.");
        }
    }
    objArgs.IsValid = pwdValid;
    return;
}

function CheckPassword2(objSource, objArgs) {
    var pwdValid = true;

    //alert(document.getElementById("txtPassword").value);

    if (document.getElementById("txtPassword").value != "") {
        if (objArgs.Value != document.getElementById("txtPassword").value) {
            pwdValid = false;
            //alert("Het wachtwoord is niet juist");
        }
    }
    objArgs.IsValid = pwdValid;
    return;
}

function CheckDatumTM(objSource, objArgs) {
    var pwdValid = true;
    //var dvanaf = new Date(document.getElementById("txtVanaf").datum);
    var dvanaf
    var dtm = new Date(objArgs.Value);

    alert("vanaf: " + dvanaf);
    alert("tm: " + dtm);

    if (dvanaf > dtm) {
        pwdValid = false;
        alert("De <Datum Tot en Met> moet na de <Datum Vanaf> liggen");
    }
    objArgs.IsValid = pwdValid;
    return;
}

