/* DeZaak VS: JS*/

function loadBanner(id1, id2){
  var obj1 = Global.getObject(id1);
  var obj2 = Global.getObject(id2);

  if(obj1 && obj2) {
    obj1.innerHTML = obj2.innerHTML;
  }
  if(obj2) {
    obj2.innerHTML = '';
  }
}

/* Background Image Cache */
try{//IE 6.0.2800.1106 SP1 - was error
if(document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand)
  document.execCommand('BackgroundImageCache', false, true);
} catch(e){

}
/* /Background Image Cache */

/* Login --------------------------------------------------------------------------------------------- */
function setFocusOnLoad() {
  var loginFieldId = "Emailadres";
  var zoekenFieldId = "zoekenStr";
  var FieldId = "";
  if  (Global.getObject(loginFieldId)) {
    FieldId=loginFieldId;
  } else {
    if (Global.getObject(zoekenFieldId)) {
      FieldId=zoekenFieldId;
    }
  }
  if (FieldId!="") {
//    setTimeout("Global.getObject('"+FieldId+"').focus();",100);
  }
}
/* /Login -------------------------------------------------------------------------------------------- */

/* Search -------------------------------------------------------------------------------------------- */
//searchStrDefVal="<Trefwoord>";
function onSearchClick(frm) {
  if (searchStrDefVal!="") {
    searchStrDefVal = searchStrDefVal.replace(/&lt;/g,'<');
    searchStrDefVal = searchStrDefVal.replace(/&gt;/g,'>');
  }
  if (frm.searchStr.value==searchStrDefVal || frm.searchStr.value.replace(/\s/g,'')=="") {
    alert ("U dient een zoekterm in het zoekveld in te vullen");
    return false;
  }
  frm.submit();
  return true;
}
function searchStrFocus(inp) {
  if (searchStrDefVal!="") {
    searchStrDefVal = searchStrDefVal.replace(/&lt;/g,'<');
    searchStrDefVal = searchStrDefVal.replace(/&gt;/g,'>');
  }
  if (inp.value==searchStrDefVal) inp.value="";
}
function searchStrBlur(inp) {
  if (inp.value=="") inp.value=searchStrDefVal;
}
/* /Search ------------------------------------------------------------------------------------------- */

function inputDefValFocus(inp,defVal) {
  if (defVal!="") {
    defVal = defVal.replace(/&lt;/g,'<');
    defVal = defVal.replace(/&gt;/g,'>');
  }
  if (inp.value==defVal) {
    inp.style.fontStyle="normal";
    inp.style.color="#000";
    inp.value="";
  }
}
function inputDefValBlur(inp,defVal) {
  if (inp.value=="" || inp.value==defVal) {
    inp.style.fontStyle="italic";
    inp.style.color="#666";
    inp.value=defVal;
  }
}


function inputDefValChange(inp,defVal) {
  if (defVal=="") {
    return;
  }
  if (inp.value=="") {
    inp.value=defVal;
    //return;
  }
  if (inp.value==defVal) {
    inp.style.fontStyle="italic";
    inp.style.color="#666";
  } else {
    inp.style.fontStyle="normal";
    inp.style.color="#000";
  }
}

function calendarDefValMutator(calendar,defVal) {
  inputDefValChange(calendar.getDisplayInput(),defVal);

  calendar.show2=calendar.show;
  calendar.hide2=calendar.hide;
  calendar.clear2=calendar.clear;
  
  calendar.show=function(x,y){
    calendar.show2(x,y);
    inputDefValChange(calendar.getDisplayInput(),defVal)
  }
  calendar.hide=function(){
    calendar.hide2();
    inputDefValChange(calendar.getDisplayInput(),defVal)
  }
  calendar.clear=function(){
    calendar.clear2();
    inputDefValChange(calendar.getDisplayInput(),defVal)
  }
}


/* MM JS --------------------------------------------------------------------------------------------- */
if (typeof hideIFrames == "undefined") {
  hideIFrames = new Object({mode:false},{obj:null});
}
hidden={
  counter:0,
  content:null
};
var timID;

function seMMPopUp(obj, url, w, h, r, m, t, s) {
  obj.blur(); 
  seMMOnClickCloseUL(obj); 
  openPopUp(''+((document.location.host=='') ? 'http:/' : 'http://'+document.location.host)+ url,'width='+w+',height='+h+',resizable='+r+',menubar='+m+',toolbar='+t+',scrollbars='+s);
}

function seMMOpenUL(obj, cl) {
  obj.className=obj.className.replace(RegExp(cl), "");
  obj.className += " "+cl;
  obj.style.zIndex = 900;
  clearTimeout(timID);
  if ((hidden.counter==0)&&(hidden.content)) {
    //hidden.content.style.visibility="hidden";
    hidden.content.style.left="-2000px";
  }
  hidden.counter++;
  //document.title=hidden.counter;
  if(hideIFrames.mode) {
    if(hideIFrames.obj.style.display != "none") {
      hideIFrames.obj.style.display="none";
    }
  }
}
function seMMCloseUL(obj, cl) {
//  obj.className=obj.className.replace(RegExp(cl), "");
  obj.className="seMMClosed";
  //obj.style.zIndex = 1;
  hidden.counter--;
  //document.title=hidden.counter;
  if ((hidden.counter==0)&&(hidden.content)) {
    //timID=setTimeout('hidden.content.style.visibility="visible"', 200)
    timID=setTimeout('hidden.content.style.left="auto"', 200)
  }
  if(hideIFrames.mode) {
    if(hideIFrames.obj.style.display != "block") {
      hideIFrames.obj.style.display="block";
    }
  }
}
function seMMOnClickCloseUL(obj) {
  var LIObj = obj;
  do {
    LIObj = LIObj.parentNode;
    if ((LIObj.tagName == "LI")&&(LIObj.className.indexOf("seMMJSOpened")!=-1)) {
//    LIObj.className=LIObj.className.replace("seMMJSOpened", "");
      LIObj.className="seMMClosed";
    }
  } while (LIObj.className.indexOf("seLevel0")==-1)
  
  hidden.counter=0;
  if (hidden.content) {
    hidden.content.style.visibility="visible"
  }
}
function seMMInit() {
//return false;
  var liArrObj = document.getElementById("seMM").getElementsByTagName("LI");
  for (var i=0; i<liArrObj.length; i++) {
    if (liArrObj[i].className.indexOf("seMMClosed")!=-1) {
      liArrObj[i].onmouseover = new Function ("","seMMOpenUL(this,'seMMJSOpened'); return false;");
      liArrObj[i].onmouseout = new Function ("","seMMCloseUL(this,'seMMJSOpened'); return false;");
    }
  }
  var aArrObj = document.getElementById("seMM").getElementsByTagName("A");
  for (var i=0; i<aArrObj.length; i++) {
    if(aArrObj[i].onclick) {
      if(aArrObj[i].target=="_blank") {
        
      } else {
         aArrObj[i].onclick = new Function ("","this.blur(); return false;");
      }
    } else {
      aArrObj[i].onclick = new Function ("","this.blur(); seMMOnClickCloseUL(this);");
    }
  }
  document.body.onload=initHiddenContent;
}
function initHiddenContent() {
  hidden.content=document.getElementById("seCPLayR");
  if (hidden.content) {
    hidden.content.style.position="relative";
  } else {
    hidden.content=null;
  }
}
/* /MM JS --------------------------------------------------------------------------------------------- */


/* >> Floating left bar banner */
function initiateLeftBanner() {

  if (!mustFloat) return;

//return false;
  paddingShift=0;
  leftBanner = Global.getObject('seScrollBanner');
    leftBanner.style.visibility = 'visible';
  leftBanner.style.paddingTop = "20px";
  mainScrollRangeBegin = getPageOffset(leftBanner)[1]+paddingShift;
  startPoint=mainScrollRangeBegin;

  mainBox = Global.getObject('layMain');
  boxHeight = mainBox.offsetHeight;
  footerHeight = 700;
  bannerHeight = 0;//leftBanner.offsetHeight;
  mainScrollRangeEnd = boxHeight-bannerHeight-footerHeight;
  mainScrollRangeEnd =(mainScrollRangeEnd>mainScrollRangeBegin) ? mainScrollRangeEnd : mainScrollRangeBegin;
  
  mainScrollObj = (Browser.isIe5 || Browser.isIe55) ? document.body : document.getElementsByTagName('HTML')[0];

//  window.onscroll = moveBanner;
  setInterval("moveBanner()",100);
  setInterval("recalcLeftBanner()",500);
}

function recalcLeftBanner() {
  boxHeight = mainBox.offsetHeight;
  mainScrollRangeEnd = boxHeight-bannerHeight-footerHeight;
  mainScrollRangeEnd =(mainScrollRangeEnd>mainScrollRangeBegin) ? mainScrollRangeEnd : mainScrollRangeBegin;
}

function moveBanner() {
  var scrollTop = mainScrollObj.scrollTop;
    var currentPadding = (leftBanner.style.paddingTop)? parseInt(leftBanner.style.paddingTop) : 0;
    var newPadding = 20;
    if (scrollTop < mainScrollRangeBegin) {
//      newPadding = 20;
    } else if (scrollTop > mainScrollRangeEnd) {
      newPadding = mainScrollRangeEnd-mainScrollRangeBegin+(20-paddingShift);
    }
    else {
      newPadding += scrollTop - mainScrollRangeBegin;
    }

    if (newPadding != currentPadding) {
      //leftBanner.style.visibility="hidden";
      if(newPadding-currentPadding < 0){
        leftBanner.style.paddingTop=-Math.ceil(Math.abs(newPadding-currentPadding)/6)+currentPadding +"px";
      } else {
        leftBanner.style.paddingTop=Math.ceil((newPadding-currentPadding)/6)+currentPadding +"px";
      }
      //leftBanner.style.visibility="visible";
    } else {
      startPoint=newPadding;
    }
/** /
  document.title = 
  "rangeBegin:"+mainScrollRangeBegin+"; "+
  "rangeEnd:"+mainScrollRangeEnd+"; "+
  "currTop:"+scrollTop+"; "+
  "newPadding:"+ newPadding+"; "+
  "isIe5:" + Browser.isIe5 + "; "+
  "isIe5.5:" + Browser.isIe55 + "; "+
  "isIe6:" + Browser.isIe6 + ";";
/**/
}

function getPageOffset(o) {
  var KL_left=0
  var KL_top=0
  do {
    KL_left+=o.offsetLeft
    KL_top+=o.offsetTop
  } while(o=o.offsetParent);
  return [KL_left, KL_top];
}
/* << Floating left bar banner */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function faqTitClick (num) {
  faqTitClickMode(num,true)  
  //faqTitClickMode(num,false)  
}

var prevFaqItm;
function faqTitClickMode (num,single) {
  if (prevFaqItm && single) {
    prevFaqItm.style.display="none";
    if (prevFaqItm.id == "faqItm"+num) {
      prevFaqItm = null;
      return;
    }
  }
var obj = Global.getObject("faqItm"+num);
  if (obj!=null) {
    if (obj.style.display=="block") {
      obj.style.display="none";
    }
    else {
      obj.style.display="block";
      if (single) {prevFaqItm=obj;}
    }
  }
}



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Functions from DeZaak: BEGIN
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function askDelete(){
  return (confirm("Weet u zeker dat u dit wilt verwijderen?"))
};

function askAcutalize(){
  return (confirm("Wilt u deze item heractiveren?"))
};

function setMailTo(statRedir, instId, Id, mailName, mailDomain, className) {
  result = mailName!="" && mailDomain!="";
  if (result) {
    document.write("<a href=\"mailto:" + mailName + "@" + mailDomain + "\" class=\"" + className +"\" onclick=\"requestURL('"+statRedir+ "instanceId/" + instId + "/newsId/" + Id + "/type/mailto/');\">email</a>");
  }
  return result;
}

function requestURL(url){
 image=new Image();
 image.src=url;
}

function goDetail( url ){
//  return openCenteredWindow( url, 580, 351 );
  return openCenteredWindow( url, 680, 480 );//510
}

function openCenteredWindow( url, width, height, params ) {
 var MyWin = window.open( url, "MyWin", "width=" + width + ", height=" + height + ", top=" + ( window.screen.height / 2 - height / 2 ) + ", left= " + ( window.screen.width / 2 - width / 2 ) + ", " + params );
 return MyWin;
}

function openPopUp(href,params)  {
  window.open(href,'',params);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function createRaquoButton(inputName, formName) {
  var buttonText = '<button class="button" style="width:20px;" onclick="insertRaquoCharacter(\''+inputName+'\',\''+formName+'\', this.innerHTML)">&raquo;</button>';
  document.write(buttonText);
}

function insertRaquoCharacter(inputName, formName, raquo) {
  FormManager.getInput(inputName, formName).value += raquo;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var html=document.getElementsByTagName('HTML')[0];
function publicityContentHeightResize() {
  var min_h=100;
  var objH_h = parseInt(Global.getObject('seBoxHeader').offsetHeight);
  var objT_h = parseInt(Global.getObject('seBoxTab').offsetHeight);
  var objF_h = parseInt(Global.getObject('seBoxFooter').offsetHeight);
  var windowHeight  = VisualElementManager.getWindowHeight();
  var objC = Global.getObject('seBoxContent');
  var objC_h = windowHeight - objH_h - objT_h - objF_h - ((Browser.firefox)?1:0);
  objC_h = (objC_h<min_h)?min_h:objC_h;
  objC.style.height = ""+objC_h+"px";
  //document.body.style.height=windowHeight+"px";
  html.style.height=windowHeight+"px";
  //document.title="WH"+windowHeight+"  c"+objC_h+"  h"+objH_h+"  t"+objT_h+"  f"+objF_h;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function getNormalizedLink(inputName, formName) {
  var linkInput = FormManager.getInput(inputName, formName);
  var linkValue = linkInput.value.replace(/^\s*|\s*$/g,"");
  if ((linkValue.indexOf('http://')!=0) && (linkValue.indexOf('javascript:')!=0)&&(linkValue.indexOf('/')!=0) && linkValue != "") {          
    linkValue = 'http://' + linkValue;
  }
  linkValue = linkValue.replace( /"/g, "%20" );
  return linkValue;
}

function normalizeLink(inputName, formName) {
  FormManager.getInput(inputName, formName).value = getNormalizedLink(inputName, formName);
}

function getFormat( isExtraLogo,isExtraSpace ){
  var result = "A";
  if( isExtraLogo && isExtraSpace ){
    result = "D";
  }else if( !isExtraLogo && isExtraSpace ){
    result = "C";
  }else if( isExtraLogo && !isExtraSpace ){
    result = "B";
  }
  return result;
}

function checkArrContain(arrayToSearch, val){
  for(var aaax=0;aaax<arrayToSearch.length;aaax++){
    if(arrayToSearch[aaax]==val)
      return true;
  }
  return false;
}

function encodeItem(str) {
  var s=str.replace(/'/g,"&#39;");
  return s.replace(/"/g,"&quot;");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// /Functions from DeZaak: END
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


rbClickFlag = false;

function processRightBarItemClick(elem,detailsURL) {

  if (!rbClickFlag) {
    rbClickFlag = true;

    var xmlhttp = null;
    // code for Mozilla, etc.
    if (window.XMLHttpRequest) {
      xmlhttp=new XMLHttpRequest()
    } 
    // code for IE
    else if (window.ActiveXObject) {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    if (xmlhttp!=null) {
      xmlhttp.open("GET",detailsURL,true);
      xmlhttp.send(null);
    }

  }

}

function checkEmailFormat(src){
  var filter=new RegExp();
  filter.compile('^([.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(([.]{1}([a-zA-Z0-9_-])+)+)?$');
  if(src.substr(src.indexOf("@")+1,src.length).indexOf(".")==-1)return false; 
  return filter.test(src);
}


function isBankNumber (/*:String:*/ bankNumber, /*:Boolean:*/ allowNineDigits ) {
  result = false;
  regEx = /^\d{9}$/;
  prefix = '0';
  if (/^\d{1,7}$/.test(bankNumber)) {
    result = true;
  } else if (regEx.test(bankNumber)) {
    aNumber = prefix + bankNumber;
    sum = 0;
    for (i=0; i<10; i++) {
      digit = aNumber.charAt(i)*(10-i);
      sum+=digit;
    }
    result = (sum%11==0)?true:false;
  }
  return result;
}

function DaysInMonth(currmonth,curryear) {
  if (currmonth == 2)
    if ((curryear % 4 != 0) || ((curryear % 100 == 0) && (curryear % 400 != 0))) return 28;
    else return 29;
  else if ((currmonth <= 7 && currmonth % 2 == 0) || (currmonth >= 8 && currmonth % 2 != 0))
         return 30;                   
  else
         return 31;
}
 
function FillDays(SelectObj,currmonth,curryear,dayselect,ChangeFlag) { 

  Global.getObject('date').value = Global.getObject('startDay')[Global.getObject('startDay').selectedIndex].value+'-'+Global.getObject('startMonth')[Global.getObject('startMonth').selectedIndex].value+'-'+Global.getObject('startYear')[Global.getObject('startYear').selectedIndex].value;

   if (currmonth==0 || curryear==0) return;

   var totaldays = DaysInMonth(currmonth,curryear);

   if (ChangeFlag==1)
     for (var i=SelectObj.length; i>0; i--) 
       SelectObj.options[i] = null;
       
    for (var i=1; i<=totaldays; i++) 
   {
     SelectObj.options[i] = new Option(i);
     if (i<10) SelectObj.options[i].value='0'+i;
     else      SelectObj.options[i].value=i;
    }

   if (dayselect<=totaldays)
   {
     for (i=1; i<=totaldays; i++) 
     {
      if (dayselect==SelectObj.options[i].value)
        { SelectObj.options[i].selected = true;break;}
     }
   }  
   else
     SelectObj.options[totaldays].selected = true;
}
