function callUpdater(div, url, params){
    cursorLoading();
    new Ajax.Updater(div, url, {parameters:params , methode:'post', asynchronous:true, evalScripts:true, onSuccess: function(){cursorNormal();}}); 
}

function callUpdaterForSelect(div, url, fromselect)
{    
    id = $F(fromselect)
        
    if (id != '' && id != undefined){
        params = '?id='+id;
    } else {
        return;
    }
    
    new Ajax.Updater(div, url, {parameters:params , methode:'post', asynchronous:true, evalScripts:true}); 
}

function download(doctype){
    coolFunc = function() {
        cursorNormal();
    }   
    
    params = 'docurl=' + escape(document.location);
    
    switch (doctype)
    {
        case "pdf":
            window.open ('/export/GeneratePDF.rails?' + params);
            break;
        case "rtf" :
            window.open ('/export/GenerateRTF.rails?' + params);
            break;
    }
    
}

function downloadModule(moduleid, doctype){
    coolFunc = function() {
        cursorNormal();
    }
    
    var host = 'http://' + location.host + '/module/downloadmodule.rails?id=' + moduleid;
    params = 'docurl=' + escape(host);
    
    switch (doctype)
    {
        case "pdf":
            window.open ('/export/GeneratePDF.rails?' + params);
            break;
        case "rtf" :
            window.open ('/export/GenerateRTF.rails?' + params);
            break;
    }
    
}


function downloadPdfFromSelect(fromselect, url, redirectUrl)
{
    id = $F(fromselect)
        
    if (id != '' && id != undefined && id > 0){
        params = '&id='+id;
    } else {
        return;
    }    

    new Ajax.Request(url, {parameters:params , methode:'post', asynchronous:true, evalScripts:true, onSuccess: function(){document.location = redirectUrl;}});    
}

function voegFavoriettoe(url){
 function openInfoDialog(){
        Dialog.info("<br /><img src='/Content/images/ajax-loader.gif' /><br /><br />Dit onderdeel wordt toegevoegd aan jou favorieten.", {width:350, height:100, showProgress: false}); 
 } 
 
 function killInfoDialog(){
    Dialog.closeInfo();
    //$('bookmark_add').style.display = "none";
 }
 
 //openInfoDialog();
 //new Ajax.Request(url, {methode:'post', asynchronous:true, onSuccess: function(){setTimeout(killInfoDialog, 3000);}}); 
 new Ajax.Request(url, {methode:'post', asynchronous:true, onSuccess: function(){alert('Het onderdeel is toegevoegd aan je favorieten.');$('bookmark_add').style.display = "none";}}); 
}

function alertMe(f){
  var e = f.elements,t='';
  for (var i=0;i<e.length;i++) 
    if (e[i].type=='text')
      t+= e[i].name+'='+e[i].value+'&';
    alert(t);

} 

// WT: initEditor() en killEditor() zorgen voor dat de tinyMce correct partial ge-rendered wordt
// zie http://www.formassembly.com/forums/viewtopic.php?t=229
function initEditor(element, id){
   tinyMCE.idCounter= id ;
   tinyMCE.execCommand( 'mceAddControl', true, element );
}

function killEditor(element){
   tinyMCE.execCommand( 'mceRemoveControl', true, element );
} 

function cursorLoading(){
    try{
        document.getElementById('loadingOverlay').style.display='block';
    }catch(e){
    }
}

function cursorNormal(){
    try{
        function makeCursorNormal(){
            document.getElementById('loadingOverlay').style.display='none'
        }
        setTimeout(makeCursorNormal, 100);
    }catch(e){
    }   
}

// Wordt nu nog gebruikt voor het aan- en uitvinken van de checkbox bij "beheer beeldmaterialen"
// Wellicht refactoren naar een generieke functie
function vinkCheckBox(id, elem)
{
    var checkbox = elem;
   
    if(checkbox.checked == true)
    {
        checkbox.value = true;
    }
    else
    {
        checkbox.value = false;
    }
    
    var params = "?id=" + id + "&isActief=" + checkbox.value;
    var url = "/BackEnd/Admin/AdminMediatheekLijst/UpdateActieveStatusBeeldmateriaal";
       
    callUpdater('table600', url, params );      
}

function readOnlyCheckBox()
{
    return false;
}