var browser = navigator.appName;
var version = navigator.version;


function openWindow(page, width, height) {
        if (typeof width == "undefined") { width=800; }
        if (typeof height == "undefined") { height=800; }
        try
        {
            OpenWin = this.open(page, 'CtrlWindow', 'width='+width+',height='+height+',toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
        }
        catch (e)
        {
            try
            {
                OpenWin = window.open(page, 'CtrlWindow', 'width='+width+',height='+height+',toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
            }
            catch (e)
            {
                alert('Kan popup niet openen, heeft u toevallig een popup blocker?\n\n' + e);
            }
        }
}

function subframe(l,r,m) {

    if(r == '' || !r) {
        r = 'empty.php';
    }
    //refresh menu if there is no submenu
    if(m)
    {
        parent.menu.location = "menu.php?submenu="+m;
    }
    strLocation = '' + parent.sitemain.location;
    // patch om te zorgen dat vanuit een main frame ook naar subframes verwezen kan worden

    // lelijke hack om ervoor te zorgen dat het aantal frames klopt.
    // vanwege later toegevoegde iframes
    var frame_count = 0;
    for (var i=0; i < parent.sitemain.frames.length; i++)
    {
        //if (parent.sitemain.frames[i].location.match('kalender.php'))
        if (parent.sitemain.frames[i].name == 'mainleft' || parent.sitemain.frames[i].name == 'mainright')
        {
            frame_count++;
        }
    }

    if(frame_count == 0 || frame_count == 1 || strLocation.match('indexsubtb.php')) {
        parent.sitemain.location = 'indexsub.php?l=' + escape(l) + '&r=' + escape(r);
    } else {
        parent.sitemain.mainleft.location = l;
        parent.sitemain.mainright.location = r;
    }
}

function subsubframe(l,r,m) {

    if(r == '' || !r) {
        r = 'empty.php';
    }
    //refresh menu if there is no submenu
    if(m)
    {
        parent.parent.menu.location = "menu.php?submenu="+m;
    }
    strLocation = '' + parent.parent.sitemain.location;
    // patch om te zorgen dat vanuit een main frame ook naar subframes verwezen kan worden

    // lelijke hack om ervoor te zorgen dat het aantal frames klopt.
    // vanwege later toegevoegde iframes
    var frame_count = 0;
    for (var i=0; i < parent.parent.sitemain.frames.length; i++)
    {
        //if (parent.sitemain.frames[i].location.match('kalender.php'))
        if (parent.parent.sitemain.frames[i].name == 'mainleft' || parent.parent.sitemain.frames[i].name == 'mainright')
        {
            frame_count++;
        }
    }

    if(frame_count == 0 || frame_count == 1 || strLocation.match('indexsubtb.php')) {
        parent.parent.sitemain.location = 'indexsub.php?l=' + escape(l) + '&r=' + escape(r);
    } else {
        parent.parent.sitemain.mainleft.location = l;
        parent.parent.sitemain.mainright.location = r;
    }
}

function subtbframe(l,r,m) {
    if(r == '' || !r) {
        r = 'empty.php';
    }
    //refresh menu if there is no submenu
    if(m)
    {
        parent.menu.location = "menu.php?submenu="+m;
    }
    strLocation = '' + parent.sitemain.location;
    // patch om te zorgen dat vanuit een main frame ook naar subframes verwezen kan worden
    if(parent.sitemain.frames.length == 0 || parent.sitemain.frames.length == 1 || strLocation.match('indexsub.php')) {
        parent.sitemain.location = 'indexsubtb.php?l=' + escape(l) + '&r=' + escape(r);
    } else {
        parent.sitemain.mainleft.location = l;
        parent.sitemain.mainright.location = r;
    }
}

function mainframe(main, m) {
    //refresh menu if there is no submenu
    if(m)
    {
        parent.menu.location = "menu.php";
    }
    if(parent.frames.length == 2)
    {
        parent.location = main;
    } else
    {
        parent.sitemain.location = main;
    }
}

function HTML_Editor(code,langua) {
        window.open('cms_content_page_editor.php?id=' + code + '&language=' + langua,'popUpWindow','width=640,height=500,bookmarks=no,status=yes,toolbar=no');
}

function popupText(text, windowWidth, windowHeight, style)
{
    WindowObjectReference = window.open('','popUpWindow','width='+ windowWidth +',height='+ windowHeight +',bookmarks=no,status=yes,toolbar=no, resizable=yes, scrollbars=auto');
    WindowObjectReference.document.write('<html><body style="'+style+'">'+text+'</body></html>');
}

function doPopUp(locatie, windowWidth, windowHeight, bFullSize, body_style) 
{
    if (typeof bFullSize == "undefined" || bFullSize==false)
    {
        bFullSize = false;
    } else
    {
        bFullSize = true;
    }
    
    intMaxWidth = screen.availWidth;
    intMaxHeight = screen.availHeight;
    
    if(typeof windowWidth == "undefined")
    {
        windowWidth = 500;
    }
    if(typeof windowHeight == "undefined")
    {
        windowHeight = 500;
    }
    strScroll = 'auto';
    if(locatie != '') 
    {
        if(windowWidth > intMaxWidth || windowHeight > intMaxHeight)
        {
            windowWidth = (windowWidth > intMaxWidth) ? intMaxWidth  : windowWidth;
            windowHeight = (windowHeight > intMaxHeight) ? intMaxHeight : windowHeight;
            
            if(bFullSize==false)
            {
                if(windowWidth > intMaxWidth)
                {
                    photoWidth = intMaxWidth - 5;
                    locatie += "/width/" + photoWidth;
                } else
                {
                    photoHeight = intMaxHeight - 60;
                    locatie += "/height/" + photoHeight;
                }
                
            } else
            {
                strScroll = 'yes';
            }           

        }
        //window.open(locatie,'popUpWindow','width=500,height=500,bookmarks=no,status=yes,toolbar=no, resizable=yes');
        strContent = "<html>";
        strContent +=       "<head>";
        strContent +=           "<title></title>";
        strContent +=       "</head>";
        if(typeof body_style != 'undefined')
        {
            strContent +=       "<body style='"+body_style+"'>";
        }
        else
        {
            strContent +=       "<body>";
        }
        strContent +=           "<img src='"+ locatie +"'>";
        strContent +=       "</body>";
        strContent +=   "</html>";
        NFW = window.open('','_blank','width='+ windowWidth +',height='+ windowHeight +',bookmarks=no,status=yes,toolbar=no, resizable=yes, scrollbars=auto');
        NFW.document.open();
        NFW.document.write(strContent);
        NFW.document.close();
    } else {
        alert('Er moet een locatie ingevuld worden voor het popup scherm!');
    }
}

function doPopUpFrontend(locatie, windowWidth, windowHeight, bFullSize) {
    if (typeof bFullSize == "undefined" || bFullSize==false)
    {
        bFullSize = false;
    } else
    {
        bFullSize = true;
    }
    
    intMaxWidth = screen.availWidth;
    intMaxHeight = screen.availHeight;
    
    if(typeof windowWidth == "undefined")
    {
        windowWidth = 500;
    }
    if(typeof windowHeight == "undefined")
    {
        windowHeight = 500;
    }
    strScroll = 'auto';
    if(locatie != '') 
    {
        if(windowWidth > intMaxWidth || windowHeight > intMaxHeight)
        {
            windowWidth = intMaxWidth;
            windowHeight = intMaxHeight;
            
            if(bFullSize==false)
            {
                window.open(locatie,'popUpWindow','width='+windowWidth+',height='+windowHeight+',bookmarks=no,status=yes,toolbar=no');          
            } else
            {
                alert('ok');
                window.open(locatie,'popUpWindow','width='+intMaxWidth+',height='+intMaxHeight+',bookmarks=no,status=yes,toolbar=no');
            }           

        }
        else
        {
            if(bFullSize==false)
            {
                window.open(locatie,'popUpWindow','width='+windowWidth+',height='+windowHeight+',bookmarks=no,status=yes,toolbar=no');          
            } else
            {
                alert('ok');
                window.open(locatie,'popUpWindow','width='+intMaxWidth+',height='+intMaxHeight+',bookmarks=no,status=yes,toolbar=no');
            }
        }
    } else {
        alert('Er moet een locatie ingevuld worden voor het popup scherm!');
    }
}

function doPopUpLarge(locatie) {
    if(locatie != '') {
        window.open(locatie,'popUpWindow','width=650,height=700,bookmarks=no,status=yes,toolbar=no');
    } else {
        alert('Er moet een locatie ingevuld worden voor het popup scherm!');
    }
}

function doPopUpSections(locatie) {
    if(locatie != '') {
        window.open(locatie,'popUpWindow','width=750,height=600,bookmarks=no,status=yes,toolbar=no,scrollbars=yes,resizable=yes');
    } else {
        alert('Er moet een locatie ingevuld worden voor het popup scherm!');
    }
}

function charsLeft(controller, view, maxchars) {
    alert(controller.value);
    if (controller.value.length > maxchars) {
        controller.value = controller.value.substring(controller.value, maxchars);
    }
    
    view.value = maxchars - controller.value.length;
}

function moveSelectItem(index, to) {
    var list = document.forms[0].list;
    var total = list.options.length - 1;
    
    if (index == -1) {
        return false;
    }
    if (to == +1 && index == total) {
        return false;
    }
    if (to == -1 && index == 0) {
        return false;
    }
    
    var items = new Array;
    var values = new Array;
    
    for (i = total; i >= 0; i--) {
        items[i] = list.options[i].text;
        values[i] = list.options[i].value;
    }
    
    for (i = total; i >= 0; i--) {
        if (index == i) {
            list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
            list.options[i] = new Option(items[i + to], values[i]);
            i--;
        } else {
            list.options[i] = new Option(items[i], values[i]);
        }
    }
    list.focus();
}

function submitSelectForm() {
    var list = document.forms[0].list;
    var theList = "";
    
    for (i = 0; i <= list.options.length - 1; i++) { 
        theList += "list[" + i + "]=" + assocListArray[list.options[i].text];
        if (i != list.options.length - 1) {
            theList += "&";
        }
    }
    document.forms[0].theList.value = theList;
    document.forms[0].submit();
}

function OpenWindow(strZiel, strName, intWidth){
    Picker = window.open(strZiel, strName, 'width='+intWidth+',height=260,scrollbars=no,resizablel');
    
    if (document.all) {
        var ClickX = window.event.x;
        var ClickY = window.event.y;
        if (navigator.appVersion.indexOf("MSIE 5") > 0) {
            Picker.moveTo(ClickX + window.screenLeft + 5, ClickY + window.screenTop - 50);
        }
    }
}

function rtSelectAll( p_blnChecked )
{
    for (var i = 0; i < document.forms[0].elements.length; ++i)
    {
        objField = document.forms[0].elements[i];
        if ( objField.type == 'checkbox' )
        {
            objField.checked = p_blnChecked;
        }
    }
}

function rtHandleFull(p_intElement, p_strFrom, p_bSetChecked_false)
{
    //var objForm = document.forms[0];
    bCheckAll = false;
    
    objRight_inherent = document.getElementById('right_option[' + p_intElement + '][0]');
    objRight_full = document.getElementById('right_full[' + p_intElement + ']');
    if(objRight_full.value == 1)
    {
        bCheckAll = true;
        objRight_full.value = 0;
    } else
    {
        objRight_full.value = 1;
    }
    
    for(var i = 1; i < 7; i++)
    {
        objRight_option = document.getElementById('right_option[' + p_intElement + '][' + i + ']');
        
        if(objRight_option)
        {
            if(p_strFrom == "right_full")
            {
                if(!(objRight_option.disabled))
                {
                    objRight_option.checked = bCheckAll == true ? true : false;
                }
            }
            if(p_strFrom == "right_inherent" && objRight_inherent)
            {
                objRight_option.disabled = objRight_inherent.checked == true ? true : false;
                if(p_bSetChecked_false)
                {
                    objRight_option.checked = false;
                }
            }
        }
    }
}

function selectChanged(selectbox, subject)
{
    var index = selectbox.selectedIndex;
    
    var selectedValue = selectbox.options[index].value;
    
    if(selectedValue == "0")
    {
        alert("Dit is geen geldige " + subject + ", kies ï¿½n van de onderliggende items.");
        selectbox.selectedIndex = 0;
    }
} 

function charsLeft(controller, view, maxchars) 
{   
   if (controller.value.length > maxchars) {
        controller.value = controller.value.substring(controller.value, maxchars);
    }
    view.value = maxchars - controller.value.length;    
}

/*
*   Set the days of month, used for the calendar
*/
function setDays(objElementDay, objElementMonth, objElementYear)
{
    day = 1;
    selectDay = 0;
    var bAddDay = false;
    if(objElementDay.options[0].value != "01")
    {
        bAddDay = true;
    }
    if(objElementDay.selectedIndex > -1)
    {
        selectDay = objElementDay.selectedIndex;
        parseInt(objElementDay.options[selectDay].value);
        day = parseInt(objElementDay.options[selectDay].value);
    }
    month = parseInt(objElementMonth.options[objElementMonth.selectedIndex].value,10);
    year = parseInt(objElementYear.options[objElementYear.selectedIndex].value,10);
    month = month - 1; //de array telt anders
    // Nee een array begint bij 0 te tellen :)
    objElementDay.options.length = 0;
    var days = new Array(31, ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    var bNoDays = true;
    var i = 0;
    if(bAddDay)
    {
        objElementDay.options.length = objElementDay.options.length + 1;
        objElementDay.options[0].value = "00";
        objElementDay.options[0].text = "--";
        i = 1;
    }
    var j =0;
    for(i; i <= days[month]; i++)
    {
        bNoDays = false;
        strDay = (j+1);
        if (strDay<10) { strDay = '0'+strDay; }
        objElementDay.options.length = objElementDay.options.length + 1;
        objElementDay.options[i].value = strDay;
        objElementDay.options[i].text = strDay;
        j++;
    }
    if(bNoDays)
    {
        strDay = "--";
        objElementDay.options.length = objElementDay.options.length + 1;
        objElementDay.options[0].value = '';
        objElementDay.options[0].text = strDay;
    }
    if(selectDay > (objElementDay.options.length-1))
    {
        objElementDay.selectedIndex = (objElementDay.options.length-1);
    } else
    {
        objElementDay.selectedIndex = selectDay;
    }
}

function setMenuPos() {
    objMenubar = document.getElementById('menubar');
    objMenubar.style = 'position: absolute;';
    alert('TEST');
}

/* BEGIN POP-UP MENU BOTTOM  */

function setSubMenuHeight(id, intVerticalOffset) {
    if(!intVerticalOffset) {
        intVerticalOffset = 0;
    }
    var subMenuHeight = document.getElementById(id).offsetHeight + intVerticalOffset;
    document.getElementById(id).style.top = '-' + subMenuHeight + 'px';
}

function showSubMenu(id) {
    showSubMenu[id] = true;
    if(document.getElementById('submenu[' + id + ']')) {
        document.getElementById('submenu[' + id + ']').style.visibility = 'visible';
    }
}

function hideSubMenu(id, intDelay) {
    if(!intDelay) {
        intDelay = 1000
    }
    showSubMenu[id] = false;
    setTimeout('hide(\'' + id + '\')', intDelay);
}

function hide(id) {
    if(!showSubMenu[id]) {
        if(document.getElementById('submenu[' + id + ']')) {
            document.getElementById('submenu[' + id + ']').style.visibility = 'hidden';
        }
    }
}

function reloadParentAndClose()
{
    window.opener.location.reload();
    window.close();
}

function doPrint(strText, strLinkStyle, width, height)
{
    myStyle = "";
    if (typeof width == "undefined") { width=screen.availWidth; }
    if (typeof height == "undefined") { height=screen.availHeight; }
    if (typeof strLinkStyle != "undefined") { myStyle = "<link rel=\"stylesheet\" href=\""+strLinkStyle+"\" type=\"text/css\""; }

    try
    {
        myWindow = window.open("", "_blank", "width="+width+", height="+height);
        myWindow.document.write(myStyle+strText);
        myWindow.document.close();
        myWindow.window.print();
        myWindow.close();
    }
    catch (e)
    {
        alert("Kan het zijn dat de popup geblocked wordt? Schakel a.u.b uw popup-blocker uit en probeer opnieuw...");
    }
}

function changeAllStatuses(objCaller)
{
    if(objCaller.value>-1)
    {
        arrElements = document.getElementsByTagName("SELECT");
        for (i=0; i<arrElements.length; i++)
        {
            if(arrElements[i].getAttribute("bIsChangeable")=="true")
            {
                arrElements[i].value = objCaller.value;
            }
        }
    }
}


/* END POP-UP MENU BOTTOM */
