﻿

/*change the class of a object */
function changecssClass(objDivID,newclass) {
    var el = document.getElementById(objDivID);
       el.className = newclass 
}


function noBack() {
  window.history.forward();
  initnoback();
}

function initnoback() {
  window.onpageshow = function(evt) {
    if (evt.persisted) noBack();
  }
  window.onunload = function() {
    void (0);
  }
}

/* swap a style class of two object(s) */
function swapcssClass(objDivID1,objDivID2) 
{
    var el1 = document.getElementById(objDivID1);
    var el2 = document.getElementById(objDivID2);
    var style = el1.className;
    el1.className = el2.className;
    el2.className = style;
}


// hide expanded fields onLoad...
function init() {
  noBack();
  addExpand('uitlegLink', 'faq');
  addExpandVoorwaarden('voorwaardenLink', 'expand_container');
  addExpandVoorwaarden('voorwaardenLink', 'voorwaarden_expand_container');
  hideQuestion('hide');
  //hideQuestion('hideByJs'); 
  hideQuestion('KeuzenInNederlandBlijven');
  hideQuestion('KeuzevragenNaWensNederlanderWorden');
  // hideElement('subIntentieVraag');
  InitDuur('DuurVerblijf') 
  checkHoofdIntentie();
  setPageHeight();

  expand_selectBox(); 
  //HideNextBtn(); dit kan niet op ierder pagina !!
}

function addExpand(_clickClass, _containerClass) {
   $$('.'+_clickClass).each(
    function(_question) {
      // Find only those links that should get expand behaviour
      if(_questionLink = _question.up('.' + _containerClass) ? _question.down('a') : false) {
          Event.observe(_questionLink, 'click', function(_event) {
            Event.findElement(_event, 'div').toggleClassName('expanded');             
            //placeExpandChar(_question.id);          
            Event.stop(_event);
          }
        );
      }
    }
	);
    window.setTimeout('setPageHeight();', 500);  
}

function addExpandVoorwaarden(_clickClass, _containerClass) {
   
   $$('.'+_clickClass).each(
   
    function(_question) {      
    	//alert($$('.'+_clickClass));
      if(_questionLink = _question.up('.' + _containerClass) ? _question.down('a') : false) {
          Event.observe(_questionLink, 'click', function(_event) {           
            var toExpand = _question.up(1);            
            changeLink(_question);   
            toExpand.toggleClassName('showVoorwaarden');                        
            Event.stop(_event);
          }
        );
      }
    }
	); 
}

function changeLink(linkElement) {       
    if(linkElement) {    
    var anker = linkElement.down(0);    
    var temp = linkElement.up(1);
   // alert(temp.className);
    if(temp.className == 'voorwaarden-blok showVoorwaarden'){
        anker.innerHTML = 'Laat alle voorwaarden zien';
       // alert(anker.innerHTML);
       }
       else {
       anker.innerHTML = 'Laat minder voorwaarden zien';        
       }
     }
     window.setTimeout('setPageHeight();', 500);    
   }
   
function placeExpandChar(_questionId) {   
   var test = $(_questionId).down(1);
   if ((test.className = 'expand_blok') || (test.className = 'voorwaarden_expand_blok'))
   {
       if(test.up(2).className.match('expanded')) 
        {
           test.innerHTML= '&#0709;'; 
            }
            else {
        test.innerHTML= '&#0707; '; 
           } 
    }
}

function handleSubmit(elementId, selectOption) {  
	  //we gaan uit van idKeuzenInNederlandBlijven!!
	 setSelectValue(selectOption, elementId);		 
   ClickNextBtn();   
}

function onlineInvullen(elementId, valueToSet) {	
		var toCheckId = elementId+'-'+valueToSet;		
		var toCheck = document.getElementById(toCheckId);
		if(toCheck) {
			toCheck.checked = true;			
			ClickNextBtn();			
		}   	
}

function setSelectValue(selectBox, valueItem) {
	var selectList = document.getElementById(selectBox);
	if(selectList) {		
		var i;
		for(i=0; i < selectList.options.length; i++) {
			var toMatch= selectList.options[i].value;
			
			if(toMatch == valueItem) {
				selectList.selectedIndex = i;
			}
		}
	}
}

function hideQuestion(elementId) {
	
    var toHide = $(elementId);
    if (toHide) {
      $(elementId).hide();
     // hide questionlabel
     var label_toHide = $$('div.dialoglookupquestion');
     if (label_toHide) {
	     label_toHide.each (
	     	function(_labelHide) {
	     		_labelHide.hide();
	     		}
	     	);
		      
		     // hide ook de buttons
		     var buttons = $$('input.btn');     
		     $$('input.btnright').each(
		     function(_btn) {
		     _btn.hide();    
		     }
	     );   
   		}
     $$('input.btnleft').each(
     function(_btn) {
     _btn.hide();    
     }
     );   
      $$('input.btn').each(
     function(_btn) {
     _btn.hide();    
     }
     );    
    }  
}



/* kijk of er na het laden van de page al een waarde bij hoofdintentie is ingevoerd: zo ja: showSubintentie
 */
 function checkHoofdIntentie(){
    var hoofd = document.getElementById('Hoofdintentie');
    if(hoofd) {    
       if(hoofd.selectedIndex != 0) {        
        var subVraag = $(hoofd.value);
        if(subVraag) {
            subVraag.up('li').style.display ='block';
            }
       }        
    }
 }
 
 function checkDuur(toCheck) { 	
 	var duur = document.getElementById(toCheck);	
 	
 	if(duur) {
 		
 		//alert(duur.selectedIndex);
 		if(duur.selectedIndex == 2)
 			{
 							
 				// set value in hoofintentie;
 				// set value in subintentie;
 				// hide hoofdintentie en subintentie
 				setDummyHoofdintentie(); // and hide
 				setDummySubintentie();  // and hide 				
 			}
		if(duur.selectedIndex == 1)
 			{
 										
 				// reset value in hoofintentie;
 				// reset value in subintentie;
 				// hide hoofdintentie en subintentie
 			  
 			  resetDummySubintentie();  // and show
 			 resetDummyHoofdintentie(); // and show
 			} 		
 	}
}

function InitDuur(toCheck) {
  var duur = document.getElementById(toCheck);

  if (duur) {

    //alert(duur.selectedIndex);
    if (duur.selectedIndex == 2) {

      // set value in hoofintentie;
      // set value in subintentie;
      // hide hoofdintentie en subintentie
      setDummyHoofdintentie(); // and hide
      setDummySubintentie();  // and hide 				
    }
    if (duur.selectedIndex == 1) {

      // reset value in hoofintentie;
      // reset value in subintentie;
      // hide hoofdintentie en subintentie

     // resetDummySubintentie();  // and show
     // resetDummyHoofdintentie(); // and show
    }
  }
}


function resetDummyHoofdintentie(){
	var hoofd = document.getElementById('Hoofdintentie');
    if(hoofd) {   
    	hoofd.selectedIndex=0;
    }
    showSubintentie(hoofd);
    hoofd.up('li').style.display = 'block'; // hide
    
}

function resetDummySubintentie() {	
	var toSet = document.getElementById('n2Werken');
	if(toSet){
		toSet.selectedIndex = 0;
	}
	//toSet.up('li').style.display = 'block'; //hide
}



function setDummyHoofdintentie(){
	var hoofd = document.getElementById('Hoofdintentie');
    if(hoofd) {   
    	hoofd.selectedIndex=2;
    	hoofd.options[2].value='n.v.t';    	
    }
    showSubintentie(hoofd);
    hoofd.up('li').style.display = 'none'; // hide
}

function setDummySubintentie() {	
	var toSet = document.getElementById('n2Werken');
	if(toSet){
		toSet.selectedIndex = 2;
		toSet.options[2].value='n.v.t';
		toSet.up('li').style.display = 'none'; //hide
	}
	
}


function setSelectWidth (vraagId) {
		var vraag = $(vraagId);
		 vraag.style.width= 640+'px';        
     //alert(vraag.style.width);
		
}

/* show subintentie na selectie hoofdintentie */
function showSubintentie(hoofdIntentie) {  
   /* zet alle subintenties op niet geselecteerd en hide de li elementen
    
   */
	
	
	if   (!!(window.attachEvent && !window.opera)) 
  {  	
    document.getElementsByClassName('subIntentieVraag').each(
    function(_element) {  
    _element.down('select').selectedIndex = 0;    
    	_element.hide();
    }
    );
   }
   else {
   	$$('.subIntentieVraag').each(
    function(_element) {
 
    _element.down('select').selectedIndex = 0;
    	_element.hide();
    }
    );
  }
   var vraagElement = $(hoofdIntentie);  
   var toShow = $(vraagElement.value);    
   if (toShow) {
    toShow.up('li').style.display ='block';    
    } 
}

/* hide elements met opgegevens class*/
function hideElement(elementClass) {
  var toHide = $$('.'+elementClass);  
    if (toHide) {
     toHide.each(
     function(_element) {
    _element.hide();    
     }
     );      
    }   
}

function resetWidth(vraagElement) {
	 // vraagElement.style.width= 440+'px'; 
	 vraagElement.focus();
   alert(vraagElement);     
}

function setPageHeight() {
    var contentElHeight = document.getElementById('middlecolumn').clientHeight;   
   // alert(contentElHeight);
    var toSet=$$('.frame');
  //  alert(toSet);
    if ((contentElHeight != null) && (toSet != null)) {
      toSet[0].style.height = contentElHeight + 200 + 'px';
    }
}

/* for ie : expand width of selectbox if it is clicked....  */

function expand_selectBox() {	
    var toHide = $('OIA_Label_onlineInvullen-J');
    if (toHide) {
      HideNextBtn();
    }
}

function showDefinitie(term) {

 var termHolder = document.getElementById(term);	
 if (termHolder != null)
	 {
		 var content = termHolder.innerHTML;
		 var str = term+'_sp';		 
			var contentHolder = document.getElementById(str);		
			
			if (contentHolder != null)
			{
			  contentHolder.innerHTML = content;			
		  }
		
		}
}

function removeSpan(term) {
	var str = term+'_sp';		 
	var contentHolder = document.getElementById(str);					
	if (contentHolder != null)
	{
	  contentHolder.innerHTML = '';			
  }		
}