function checkForm(oForm, sLanguage) {
       var bError = false;
       var sOutput_NL = 'Gelieve volgende problemen op te lossen:\n';
       var sOutput_FR = 'Veuillez résoudre les problèmes suivants :\n';
       var aElem = oForm.elements;
    
           for(var i=0; i<aElem.length; i++) {
           var aNamePrefix = aElem[i].name.split('_');
           if(aElem[i].getAttribute('haserror') == '1')
           {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is niet geldig\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' n\'est pas valide\n';
               bError = true;
           };
           if((aNamePrefix[0] == "textreq") && (aElem[i].value.length == 0)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is een verplicht veld\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' est un champ obligatoire\n';
               bError = true;
           }
     if((aNamePrefix[0] == "textreqemail") && (aElem[i].value.length == 0)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is een verplicht veld\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' est un champ obligatoire\n';
               bError = true;
           }
           if((aNamePrefix[0] == "textreqemail") && (!checkEmail(aElem[i].value))) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is niet geldig\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' n\'est pas valable\n';
               bError = true;
           }
           if((aNamePrefix[0] == "selectreq") && (aElem[i].value.length == 0)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is een verplichte keuze\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' est obligatoire\n';
               bError = true;
           }
           if((aNamePrefix[0] == "intreq") && (aElem[i].value.length == 0 || !parseInt(aElem[i].value) || parseInt(aElem[i].value) != aElem[i].value)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is een verplicht veld en moet numeriek zijn\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + 'doit être rempli avec un numéro\n';
               bError = true;
           }
           if((aNamePrefix[0] == "textreq500max") && (aElem[i].value.length == 0)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is een verplicht veld\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' est un champ obligatoire\n';
               bError = true;
           }
           if((aNamePrefix[0] == "textreq500max") && (aElem[i].value.length > 500)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' mag maximaal 500 karakters bevatten (je input: ' + aElem[i].value.length + ' karakters)\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' ne peut pas dépasser 500 caractères (votre texte: ' + aElem[i].value.length + ' caractères)\n';
               bError = true;
           }
           if((aNamePrefix[0] == "textreq2000max") && (aElem[i].value.length == 0)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is een verplicht veld\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' est un champ obligatoire\n';               bError = true;
           }
           if((aNamePrefix[0] == "textreq2000max") && (aElem[i].value.length > 2000)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' mag maximaal 2000 karakters bevatten (je input: ' + aElem[i].value.length + ' karakters)\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' ne peut pas dépasser 2000 caractères (votre texte: ' + aElem[i].value.length + ' caractères)\n';
               bError = true;
           }
           if((aNamePrefix[0] == "textreq6min") && (aElem[i].value.length == 0)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' is een verplicht veld\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' est un champ obligatoire\n';               bError = true;
           }
           if((aNamePrefix[0] == "textreq6min") && (aNamePrefix[2] != "oldpassword") && (aElem[i].value.length < 6)) {
               sOutput_NL +=  '- ' + aElem[i].getAttribute('desc') + ' moet ten minste 6 karakters bevatten (je input: ' + aElem[i].value.length + ' karakters)\n';
               sOutput_FR +=  '- ' + aElem[i].getAttribute('desc') + ' doit avoir 6 caractères au minimum (votre texte: ' + aElem[i].value.length + ' caractères)\n';
               bError = true;
           }
           if(aElem[i].name.value == "textreq_usr_password2") {
              if(oForm.textreq_usr_password.value != oForm.textreq_usr_password2.value) {
                sOutput_NL += 'Paswoorden zijn niet gelijk\n';
                sOutput_FR += 'Veuillez vous assurer que les deux mots de passe tapés sont identiques\n';
                bError = true;
        }
           }
       }
       if(bError){
          if(sLanguage == "NL")
              alert(sOutput_NL);
          else
              alert(sOutput_FR);
          return false;
       } else {
           return true;
       }
    
}
    function checkEmail(sEmail) {
        if (/^\w+([\.\-\\+]*\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(sEmail)) {
            return true;
        }
        return false;
    }
 
 function setBlogStatus(status) {
  var oForm = getObjectByID('post');
  oForm.status.value = status;
 }
 
 function submitBlogArticleForm(oForm) {
  
  var content = tinyMCE.getContent('body_text');
  if(oForm.content_type && oForm.content_type.value == 'ARTICLE') {
var contentintro = tinyMCE.getContent('intro_text');
}
  if(content.indexOf('<img src="') >= 0) {
   oForm.thumb.value = content.substring(content.indexOf('<img src="')+10,content.indexOf('"',content.indexOf('<img src="')+11)).replace('/large/','/thumb/').replace('/small/','/thumb/');
  }
if(oForm.content_type && oForm.content_type.value == 'ARTICLE' && contentintro.indexOf('<img src="') >= 0) {
oForm.thumb.value = contentintro.substring(contentintro.indexOf('<img src="')+10,contentintro.indexOf('"',contentintro.indexOf('<img src="')+11)).replace('/large/','/thumb/').replace('/small/','/thumb/');
}
  oForm.taxonomy.value = tree.getAllChecked();
  
  oForm.tags.value = "";
  for(var i=0;i<oForm.tag_list.options.length;i++) {
   if(i>0) oForm.tags.value += ",";
   oForm.tags.value += oForm.tag_list.options[i].text;
  }
  
  if(oForm.content_type && oForm.content_type.value == 'ARTICLE') {
   // prepare date fields
 oForm.published_startdate.value = oForm.published_startdate_year.value + '-' + oForm.published_startdate_month.value + '-' + oForm.published_startdate_day.value + ' ' + oForm.published_startdate_hour.value + ':' + oForm.published_startdate_minute.value;
 if(oForm.published_enddate_year.value.length > 0 && oForm.published_enddate_month.value.length > 0 && oForm.published_enddate_day.value.length > 0 && oForm.published_enddate_hour.value.length > 0 && oForm.published_enddate_minute.value.length > 0) {
  oForm.published_enddate.value = oForm.published_enddate_year.value + '-' + oForm.published_enddate_month.value + '-' + oForm.published_enddate_day.value + ' ' + oForm.published_enddate_hour.value + ':' + oForm.published_enddate_minute.value;
 }
  }
  
  if(oForm.title.value.length == 0) {
   alert("Titel is verplicht.");
   return false;
  }
  
  // check other stuff as well
  
  return true;
 
 }
 function addVideoForm(oForm){
  oForm.taxonomy.value = tree.getAllChecked();
  
  oForm.tags.value = "";
  for(var i=0;i<oForm.tag_list.options.length;i++) {
   if(i>0) oForm.tags.value += ",";
   oForm.tags.value += oForm.tag_list.options[i].text;
  }
   if(oForm.videoadd_title.value.length == 0) {
   alert("Titel is verplicht.");
   return false;
  }

if(!(oForm.videoform_co_id && oForm.videoform_co_id.value.length > 0)) {

  if(document.getElementById('rbVideoSource1').checked) 
  {
     if(oForm.videoadd_src.value.length == 0) 
     {
        alert("Een video is verplicht.");
        return false;
     };
  };
  
  if(document.getElementById('rbVideoSource2').checked) 
  {
     if(oForm.embedhtml.value.length == 0) 
     {
        alert("Embed code is verplicht.");
        return false;
     };
  };  
  
}

  if(document.getElementById('rbtargetgroup3') != null && document.getElementById('rbtargetgroup3').checked) 
  {
     if(oForm.album_password_field.value.length == 0) 
     {
        alert("Gelieve een wachtwoord in te geven.");
        return false;
     };
  };
  // check other stuff as well
  
  return true;
 }
function togglePasswordField(oCheck, sValue) {
 if((sValue == '1' || sValue == '2') && oCheck.checked) {
  getObjectByID('album_password').style.display = 'none';
 } else {
  if(sValue == '3' && oCheck.checked) {
   getObjectByID('album_password').style.display = '';
  } else {
   getObjectByID('album_password').style.display = 'none';
  }
 }
}
 function verifyCheckCount(id) {
  var sChecked = tree.getAllChecked();
  var aChecked = sChecked.split(',');
  if(aChecked.length > 3) {
   tree.setCheck(id,0);
   alert('Je kan maximum 3 categorieën selecteren.');
  }
  if(tree.getLevel(id) == 2) {
   checkBold(tree.getParentId(id));
  }
 }
 
 function checkBold(id) {
  // for all children of this id --> if at least 1 is checked put bold around it
 var sIDs = tree.getSubItems(id);
 var aIDs = sIDs.split(',');
 var bBold = false;
 for(var i=0; i<aIDs.length; i++) {
  if(tree.isItemChecked(aIDs[i])) bBold = true;
 }
 if(bBold) {
  tree.setItemStyle(id,'font-weight:bold;');
 } else {
  tree.setItemStyle(id,'font-weight:normal;');
 }
 }
 
 function addTag(o) {
  if(o.value.length > 0) {
  var list = getObjectByID('tag_list');
  if(list.options.length < 7) {
   list.options[list.options.length] = new Option(o.value,o.value);
   list.selectedIndex = -1;
  } else {
   alert('Maximum 7 tags zijn toegestaan.');
  }
  o.value = "";
 }
 return false;
 }
 
 function removeTag(id) {
  var list = getObjectByID('tag_list');
 if(list.selectedIndex >= 0) {
  list.options[list.selectedIndex] = null;
 }
 }
 function stripHTML( strSrc ) {
    return strSrc.replace( /<[^<|>]+?>/gi,'' );
 }
 
  function getObjectByID(sName) {
  var oObject;
  if (document.all) {
   oObject = document.all.item(sName);
  }
  else if (document.getElementById) {
   oObject = document.getElementById(sName);
  }
  return oObject;
 }
 
 function submitFotoAlbumForm(oForm) {
  oForm.taxonomy.value = tree.getAllChecked();
  oForm.tags.value = "";
  for(var i=0;i<oForm.tag_list.options.length;i++) {
   if(i>0) oForm.tags.value += ",";
   oForm.tags.value += oForm.tag_list.options[i].text;
  }
  
  if(oForm.title.value.length == 0) {
   alert("Titel is verplicht.");
 return false;
  }
  if(oForm.title.value.length > 100) {
   alert("Titel mag niet meer dan 100 karakters bevatten.");
 return false;
  }
  if(oForm.shortdesc.value.length > 2000) {
   alert("De beschrijving mag niet meer dan 2000 karakters bevatten.");
 return false;
  }
  
  if(oForm.targetgroup[2].checked && oForm.album_password_field.value.length == 0) {
   alert("Gelieve een wachtwoord in te geven.");
 return false;
  }
  
  return true;
 }
function viewDiv(idDiv) {
    if (document.getElementById(idDiv) != null){
     var div = document.getElementById(idDiv);
     div.style.visibility = 'visible';
     div.style.display = 'block';  
    }    
      }
 /*   function viewDiv(idDiv) {
      var obj = document.getElementById(idDiv);
      var parent = obj.parentNode;
      parent.removeChild(obj);
      document.body.appendChild(obj);
  
      if (obj != null){
        obj.style.visibility = 'visible';
        obj.style.display = 'block';  
      }  
    };*/

   function hiddenDiv(idDiv) {
    if (document.getElementById(idDiv) != null){
     var div = document.getElementById(idDiv);
     div.style.visibility = 'hidden';
     div.style.display = 'none';
    }
      }

    function checkCommentForm(oForm) {
        oForm.comments.value = stripHTML(oForm.comments.value);
        oForm.comments.value = oForm.comments.value.replace(/\r\n/g,'<br/>');

        if(oForm.comments.value.length == 0) {
            alert('Gelieve een reactie in te vullen.');
            return false;
        }
        return true;
    };

function checkTextareaLength(obj,i) {
    if(obj.value.length > i) {
        obj.value = obj.value.substr(0,i);
        alert('U mag maximum ' + i.toString() + ' karakters ingeven.');
    }
}
 
    function escamotableListener(div) {
        div.style.display = (div.style.display == 'none') ? 'block' : 'none';    
    };
 
 function callStoredProcedure( content_object_id, content_item_id, classified_id, comment_id, user_id, user_email, description  ) { 
  jQuery.post('/asp/wrap_StoredProc.asp', {'spname':'Zappy_Reporting_Message','content_object_id':content_object_id,
'content_item_id':content_item_id,'classified_id':classified_id, 'comment_id':comment_id, 'user_id':user_id, 'user_email':user_email, 'description':description}, callStoredProcedure_Callback);
 };
  
 function callStoredProcedure_Callback(res) {
  //alert('The response: ' + res);
  if(res == 1){
   if(currentForm != null){
       currentForm.comment_ongepast.value = '';
    currentForm.email_ongepast.value = '';
   }
   if(currentDiv != null){
    currentDiv.innerHTML = 'Message send.'
   }  
  } else {
   if(currentDiv != null){
    currentDiv.innerHTML = 'Sorry... Message not send...'
   } 
  }
  
  currentForm = null;
  currentDiv = null;
 };
 
 var currentForm = null;
 var currentDiv = null;
 function onPosted(oForm, oDiv) {
  currentForm = oForm;
  currentDiv = oDiv;
  oForm.comment_ongepast.value = stripHTML(oForm.comment_ongepast.value);
   if(oForm.comment_ongepast.value.length == 0) {
    alert('Gelieve een reactie in te vullen.');
         } else {
    if((oForm.user_ongepast.value == 0) && (!checkEmail(oForm.email_ongepast.value))) {
    alert('Gelieve je e-mailadres in te vullen.');
   } else {  
//alert('oForm.object_ongepast.value : '+oForm.object_ongepast.value);
//alert('oForm.item_ongepast.value : '+oForm.item_ongepast.value);
//alert('oForm.cls_ongepast.value : '+oForm.cls_ongepast.value);

    callStoredProcedure(oForm.object_ongepast.value, oForm.item_ongepast.value, oForm.cls_ongepast.value, oForm.com_ongepast.value, oForm.user_ongepast.value, oForm.email_ongepast.value, oForm.comment_ongepast.value); 
   }
  }
 };

   var currentForm = null;
   var currentDiv = null;
   function onSendMailToFriend(oForm, oDiv) {
    currentForm = oForm;
    currentDiv = oDiv;
    oForm.message.value = stripHTML(oForm.message.value);
    if(oForm.sender_name.value.length == 0) {
     alert('Gelieve je naam in te vullen.');
     return false;
    } else {
     if((oForm.friend_name.value.length == 0) || (!checkEmail(oForm.friend_email.value))) {
      alert('Gelieve je e-mail en de naam van je vriend(in) in te vullen.');
      return false;
     } else {  
      //alert('oForm.url_content.value : '+oForm.url_content.value);
      //alert('oForm.title_content.value : '+oForm.title_content.value);
  
      callMailFriend(oForm.sender_name.value, oForm.friend_email.value, oForm.friend_name.value, oForm.message.value, oForm.url_content.value, oForm.title_content.value); 
     }
    }
   };

   var currentForm = null;
   var currentDiv = null;
   function onSendMailToFriendFR(oForm, oDiv) {
    currentForm = oForm;
    currentDiv = oDiv;
    oForm.message.value = stripHTML(oForm.message.value);
    if(oForm.sender_name.value.length == 0) {
     alert('Veuillez remplir votre nom.');
     return false;
    } else {
     if((oForm.friend_name.value.length == 0) || (!checkEmail(oForm.friend_email.value))) {
      alert('Veuillez indiquer l\'e-mail et le nom de votre ami(e).');
      return false;
     } else {  
      //alert('oForm.url_content.value : '+oForm.url_content.value);
      //alert('oForm.title_content.value : '+oForm.title_content.value);
           callMailFriendFR(oForm.sender_name.value, oForm.friend_email.value, oForm.friend_name.value, oForm.message.value, oForm.url_content.value, oForm.title_content.value);

     }
    }
   };
 
 
   function callMailFriend(sender_name, friend_email, friend_name, message, url_content, title_content ) { 
    jQuery.post('/asp/Wrap_Mail.asp', {template:'nl_mail_to_friend.html', subject:'Een vriend stuurt u deze link door', sender_name:sender_name, to:friend_email, friend_name:friend_name, message:message, url_content:url_content, title_content:title_content}, callMailFriend_Callback);
   };

   function callMailFriendFR(sender_name, friend_email, friend_name, message, url_content, title_content ) { 
    jQuery.post('/asp/Wrap_Mail.asp', {template:'fr_mail_to_friend.html', subject:'Un ami vous envoi ce lien', sender_name:sender_name, to:friend_email, friend_name:friend_name, message:message, url_content:url_content, title_content:title_content}, callMailFriend_CallbackFR);
   };

   function callMailFriend_Callback(res) {
    //alert('The response: ' + res);
    if(res == 1){
     if(currentForm != null){
       //alert('sender_name:'+currentForm.sender_email.value);
jQuery.post('/asp/Wrap_Mail.asp', {template:'nl_confirm_sending_mail_to_friend.html', subject:'Mail Doorgestuurd', sender_name:currentForm.sender_name.value, to:currentForm.sender_email.value, friend_email:currentForm.friend_email.value, friend_name:currentForm.friend_name.value, title_content:currentForm.title_content.value }, callMailFriend_CallbackSecond);
      
      currentForm.friend_name.value = '';
      currentForm.friend_email.value = '';
      currentForm.message.value = '';
     }
     if(currentDiv != null){
      currentDiv.innerHTML = 'Message send.'
     }  
    } else {
      
      currentForm.friend_name.value = '';
      currentForm.friend_email.value = '';
      currentForm.message.value = '';
     
      if(currentDiv != null){
        currentDiv.innerHTML = 'Sorry... Message not send...'
      } 
    } 
    currentForm = null;
    currentDiv = null;
    escamotableListener(document.getElementById('post_mail_to_friend'));
   };

   function callMailFriend_CallbackFR(res) {
    //alert('The response: ' + res);
    if(res == 1){
     if(currentForm != null){
       //alert('sender_name:'+currentForm.sender_email.value);
jQuery.post('/asp/Wrap_Mail.asp', {template:'fr_confirm_sending_mail_to_friend.html', subject:'Mail transmis', sender_name:currentForm.sender_name.value, to:currentForm.sender_email.value, friend_email:currentForm.friend_email.value, friend_name:currentForm.friend_name.value, title_content:currentForm.title_content.value }, callMailFriend_CallbackSecond);
      
      currentForm.friend_name.value = '';
      currentForm.friend_email.value = '';
      currentForm.message.value = '';
     }
     if(currentDiv != null){
      currentDiv.innerHTML = 'Message envoyé.'
     }  
    } else {
      
      currentForm.friend_name.value = '';
      currentForm.friend_email.value = '';
      currentForm.message.value = '';
     
      if(currentDiv != null){
        currentDiv.innerHTML = 'Désolé... Le message n\'a pas pu être envoyé...'
      } 
    } 
    currentForm = null;
    currentDiv = null;
    escamotableListener(document.getElementById('post_mail_to_friend'));
   };


 function callMailFriend_CallbackSecond(res) {};

function getCookie(NameOfCookie){
if (document.cookie.length > 0) {  
begin = document.cookie.indexOf(NameOfCookie+" = ");
if (begin != -1) {     
begin += NameOfCookie.length+1;    
end = document.cookie.indexOf(";", begin); 
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end));
} }
return null; 
}
function setCookie(NameOfCookie, value, expiredays) {
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); 
}
function ShowBIMPopup() {
var Freq = 3;
var ShowOrNot = Math.floor(Freq * Math.random()+1);
if (ShowOrNot == 1){
visited=getCookie('BIMvisited');
if (visited==null){
setCookie('BIMvisited','yes',45)
document.write("<"+"script type=\"text/javascript\" src=\"http://bimonline.insites.be/nl/start.asp?SiteID=598&amp;TagID=1\"></scr"+"ipt>"); 
} } }

function popUpPage(URL, width, height, screenX, screenY) {
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ",screenX="+ screenX + ",screenY=" + screenY + "');");
}


function open_new_window(page) {
    OpenWin = this.open(page, "Zappybaby", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
}