//globals
var	ENABLE_DEBUG = true;
//Access
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isOP   = (navigator.userAgent.indexOf("Opera") != -1)? true : false;

function getObject(id) {
 if (isDOM) if(document.getElementById(id)){ return document.getElementById(id) }else {alert('cannot get object '+id );};
 if (isIE4) if(document.all[id]){ return document.all[id] }else {alert('cannot get object '+id );};
 if (isNS4) if(document.layers[id]){ return document.layers[id] }else {alert('cannot get object '+id );};
 return false;
}
function getObjectNoAlert(id) {
 if (isDOM) if(document.getElementById(id))return document.getElementById(id);
 if (isIE4) if(document.all[id]) return document.all[id];
 if (isNS4) if(document.layers[id]) return document.layers[id];
 return false;
}
function getStyle(id) {
 return (isNS4 ? getObject(id) : getObject(id).style);
} 
//Debug 
function doAlert( oObj, sStr ) 
{
if(ENABLE_DEBUG)
{
if( getObjectNoAlert( 'debug' ) ){
getObjectNoAlert( 'debug' ).innerHTML = oObj.id + ": " + sStr + "<br/>" + getObjectNoAlert( 'debug' ).innerHTML; 
    }else{
  alert( 'doAlert:' + sStr );
	}	}	}
/**
 * Find the screen width to allow proper menu alignment/clipping.
 * Specifically, if the menuX + menuWidth > screenWidth, then 
 * right align the menu to the right border of the screen so that
 * menuX + menuWidth = screenWidth.
 * This code is from quirksmode.org
 */
function innerWidth() {
  var x;
  if (self.innerWidth) { //All except IE
	x = self.innerWidth;
  }
  else if (document.documentElement && 
      document.documentElement.clientWidth) { // Explorer 6 Strict Mode
	    x = document.documentElement.clientWidth;
    }
  else if (document.body) { // other Explorers
	x = document.body.clientWidth;
  }
  return x;
}
               
function updateCarrousel(itemid) {
//vars
var carrouselelement = document.getElementById('carrouselcontent');
var carrouselcontent = carrouselelement.childNodes;
var htmlcarrousels = new Array();
		
var i = 0;
for (i; i < carrouselcontent.length;i++)
{
if (carrouselcontent[i].nodeName == 'DIV' && carrouselcontent[i].className == 'htmlcarrousel')
	{
	var currentelement = carrouselcontent[i];
	if (currentelement.id == 'htmlcarrousel' + itemid)
	{currentelement.style.display = 'block';}
	else
	{currentelement.style.display = 'none';	}
	}
}
}

function resizeWindow() {
// calculate windowheight 
var myHeight = 0;
var winHeight = 0;
if( typeof(window.innerWidth ) == 'number' )
  {
  //Non-IE
  winHeight = window.innerHeight;
  }
  else if( document.documentElement && document.documentElement.clientHeight )
  {
  //IE 6+ in 'standards compliant mode'
  winHeight = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight )
  {
  //IE 4 compatible
  winHeight = document.body.clientHeight;
  }

var canvas = document.getElementById('canvas');
if (canvas)
 {
 for(var i=0; i < canvas.childNodes.length; i++){
 var wrapper = canvas.childNodes[i];
 if(canvas.childNodes[i].nodeType == 1){
 break;
 }
 }

 for(var i=0; i < wrapper.childNodes.length; i++){
  var innerwrapper = wrapper.childNodes[i];
  if(wrapper.childNodes[i].nodeType == 1){
  break;
  }
  }
 var carrousel = document.getElementById('carrousel');
 // reset any previous set heights
 if (innerwrapper) {innerwrapper.style.height = null;}
 // set and calculate heights
 var topheight = 154;
 var footerheight = 54;
 var innerwrapperheight = innerwrapper.clientHeight;
 var documentheight = topheight + footerheight + innerwrapperheight;;
 var restheight = winHeight - topheight - footerheight;
 // correction for heights if page is homepage
 if (carrousel != null)
 {
 var carrouselheight = carrousel.clientHeight;
 documentheight = documentheight + carrouselheight;
 restheight = restheight - carrouselheight;
 }
 }
// decide if resizing is needed and actually resize if appropriate
if (documentheight < winHeight)
 {innerwrapper.style.height = restheight + 'px';}
scrollFix();
}

function scrollFix()
{
// calculate windowheight 
var myWidth = 0;
var winWidth = 0;
var bodyelement;
if( typeof(window.innerWidth ) == 'number' )
 {
 //Non-IE
 winWidth = window.innerWidth;
 bodyelement = document.body;
 }
else if( document.documentElement && document.documentElement.clientWidth )
 {
 //IE 6+ in 'standards compliant mode'
 winWidth = document.documentElement.clientWidth;
 bodyelement = document.documentElement;				
 }
else if( document.body && document.body.clientWidth )
 {
 //IE 4 compatible
 winWidth= document.body.clientWidth;
 bodyelement = document.body;				
}				
if(bodyelement)
 {
 if (winWidth > 990)
  {
  bodyelement.style.overflow = "auto";
  bodyelement.style.overflowX = "hidden";				
  bodyelement.style.overflowY = "auto";
  }
 }
}

function repositionMenu( w , maxroom)
{
var listelement 		= document.getElementById('targetgrouplist');
var listitems 			= listelement.getElementsByTagName('li');
var lastitem			= listitems[listitems.length-1];
var iecorrection		= 4					  // is needed to correct ie bug not displaying items correctly when fit is very tight
var maxwidth    		= w - iecorrection; // maximum space reserved for menu items				
var itemsfit			= false;
// first decide if items fit anyway
var total_width = 0;	// total width of rendered width of to be spaced items (=listlength -1)
for(var i = 1; i < listitems.length;i++) // skip first item
 { total_width = total_width + (listitems[i].clientWidth); }
if(total_width <= maxwidth)
 {itemsfit = true;}
// if they fit, move on 				
if(itemsfit == true)
 {
 var total_spaceroom 	= maxwidth - total_width;	// total space left over, to be evenly added to item width
 var item_spaceroom 	= Math.floor(total_spaceroom / (listitems.length-2)); // space to be added to each item
 if (item_spaceroom>maxroom) { item_spaceroom=maxroom;}
 var cur_item = "";
 for(var i = 1; i < listitems.length-1;i++)
 {
 cur_item = listitems[i];
 cur_item.style.paddingRight = item_spaceroom + 16 + 'px';
 }
 lastitem.style.paddingRight = '16px';
}
			
}			

function addOnloadEvent(fnc)
{
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}

function getQueryParameter ( parameterName ) 
{
var queryString = window.top.location.search.substring(1);
parameterName = parameterName + "=";
if ( queryString.length > 0 ) {
 begin = queryString.indexOf ( parameterName );
 if ( begin != -1 ) {
  begin += parameterName.length;
  end = queryString.indexOf ( "&" , begin );
  if ( end == -1 ) {end = queryString.length}
  return unescape ( queryString.substring ( begin, end ) );
  }
 }
return "null";
} 

function setCookie(c_name,value,expireminutes)
{
deleteCookie( c_name );
var today = new Date();
today.setTime( today.getTime() );
var exdate=new Date( today.getTime() + (expireminutes*1000*60) );
document.cookie=c_name+ "=" +escape(value)+ "; expires=" + exdate.toGMTString() + "; path=/";
}

function getCookie(c_name)
{
if (document.cookie.length>0)
 {
 c_start=document.cookie.indexOf(c_name + "=");
 if (c_start!=-1)
  {
  c_start=c_start + c_name.length+1;
  c_end=document.cookie.indexOf(";",c_start);
  if (c_end==-1) c_end=document.cookie.length;
  return unescape(document.cookie.substring(c_start,c_end));
  }
 }
return "";
}

function deleteCookie ( cookie_name )
{
try
{
var cookie_date = new Date ( );  
cookie_date.setTime ( cookie_date.getTime() - 1 );
document.cookie = cookie_name + "=; expires=" + cookie_date.toGMTString() + "; path=/";
}
catch (e)
{}
}

function setSearchCookie ( formName, jsInputField )
// set the cookie from the calling page
{
removeJavascriptField( jsInputField );
var f = document.forms[formName].elements['freesearch']; 
if (f) 
 {
 searchCookie = f.value 
 if (searchCookie.length<2 || searchCookie=="<Zoekterm>" || searchCookie=="<Keyword>") 
  { 
  document.forms[formName].elements['freesearch'].value = "?";
  return false; 
  }
 setCookie('zoekterm', searchCookie.toLowerCase(), 20);
 f.value = searchCookie.toLowerCase();

 googleZoek = getQueryParameter('googleZoek');
 if (googleZoek == "ja")
  { setCookie( "googleZoek", googleZoek, 20); }
 else			      
  {
  if (googleZoek != "nee") {googleZoek = getCookie ( "googleZoek" );}
  }
 if (googleZoek == "ja" )
  {
  var input = document.createElement('input');
  input.type = 'hidden';
  input.name = 'view';
  input.value = 'ZoekMetGoogle';
  var s = document.getElementById('searchfield');
  s.parentNode.insertBefore( input, s );
  }

 }
// When called from Advanced search a dKey parameter may be supplied
var dKey;
dKey = getQueryParameter('dKey');
// check for field dKey in form
var f = document.forms[formName].elements['dKey']; 
if (f && dKey!=null) {setCookie('dKey', dKey, 20);}
 else
  deleteCookie('dkey'); 
// Show search is started
showSearchStarted ();
return true;
}
		          
function hideSearchStarted ()
{
var search = document.getElementById("search-started");
if (search) { search.style.display='none';} 
var canvasx = document.getElementById("canvas");
if (canvasx)
 {
 canvasx.style.display = 'block';
 var accessbar = document.getElementById("accessbar");
 if (accessbar) { accessbar.style.display='block';}
 }
}
		                
function showSearchStarted ()
{
try
{
var emccanvas = document.getElementById("canvas");
if (emccanvas)
 {
 emccanvas.style.display = 'none';
 var accessbar = document.getElementById("accessbar");
 if (accessbar) { accessbar.style.display='none';}
 var carrousel = document.getElementById("carrousel");
 if (carrousel) { carrousel.style.display='none';}
 var search = document.getElementById("search-started");
 if (search)
  { 
  search.style.display='block';
  // for IE only, which does not start animation when item was hidden
  var progressImage = document.getElementById("progress_image");
  if (progressImage) 
  {
  progressImage.style.display='inline';	
  progressImage.style.visibility='visible'; 
  setTimeout('document.images["progress_image"].src  = "/images/search-loader.gif"',300);  
  }
  }
 }
}
catch (e)
{}
}
		                
function setSearchField( keyword ) 
// set the field "freesearch" in the searchform
{
var searchParam;
searchParam = getCookie('zoekterm');

var searchView;
searchView = getQueryParameter('freesearch');
if (searchView != "null")
 {
 // een zoekopdracht
 searchParam = searchView;
 setCookie( "zoekterm", searchParam, 10);
 }
if (searchParam != "" && searchParam != "null")
 {
 var re = new RegExp("\\+","g");
 searchParam = searchParam.replace(re, " ");
 var f = document.forms["simpleSearch"]; 
 if (f) {f.freesearch.value = searchParam; }
 }
return true;
}

function setSearchFieldAdvanced( keyword )
{
// check for parameter " view=Uitgebreid_zoeken"
searchParam = getQueryParameter('view');
if (searchParam == "Uitgebreid_zoeken")
 {
 var f1 = document.forms['advancedSearch']; 
 if (f1) {f1.freesearch.value = keyword;}
 }
}
		
function clearSearchField( keyword, formName ) 
// clear the field "freesearch" in the searchform if value=keyword
{
result = true;
//f = document.forms["simpleSearch"];
f = document.forms[ formName ];
if (f)
 { if (f.freesearch.value == keyword ) { f.freesearch.value = ""; } }
return result;
}
			
function setLeftHandMenu ( keyS, keyC, keyR )
{
setCookie('keyS',keyS,30);
setCookie('keyC',keyC,30);
setCookie('keyR',keyR,30);
}
                        
function showLeftHandMenu ( id, lang )
{
keyS = getCookie( 'keyS' );
keyC = getCookie( 'keyC' );
keyR = getCookie( 'keyR' );
ajaxGetLeftMenuFunction( '/js/left_hand_menu.jsp', id, keyS, keyC, keyR, lang )
}

function removeJavascriptField( jsInputField, jsParent)
{
// remove the js indication when javascript enabled
var js = document.getElementById( jsInputField );
if (js) 
 { 
 js.value = "y";
 var fs = js.parentNode;
 if (fs) fs.removeChild(js);
 }
}
                        
function checkForEnter( myfield, e )
{
var keycode;
if (window.event) keycode = window.event.keyCode;
 else if (e) keycode = e.which;
  else return true;
if (keycode == 13) {setSearchCookie('simpleSearch', 'js');}
return true;
}

function searchAgain( url, requesItemUrl, view, freeSearch, siteid, userid, resultpageid, mediasurface_target, pageno, lang, dKey, searchItemName, search_type )

{
   ajaxSearchFunction( url, requestItemUrl, view, freeSearch, siteid, userid, resultpageid, mediasurface_target, pageno, lang, dKey, searchItemName, search_type ); 
}
			
function ajaxSearchFunction( url, requestItemUrl,  view, freeSearch, siteid, userid, resultpageid, mediasurface_target, pageno, lang, dKey,  searchItemName, search_type )

{
	
var xmlHttp;
try
  {  // Firefox, Opera 8.0+, Safari  
     xmlHttp=new XMLHttpRequest();  }
catch (e)
  {  // Internet Explorer  
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    
      try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      
             return false;      }    }  }
             
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      try
      {
      userStr = xmlHttp.responseText;
      //alert ("answer=" + userStr);
      if (userStr.length>0)
      {
       var searchBlock = document.getElementById('toon_zoek_resultaten');
       searchBlock.innerHTML = userStr;
      }
      else
      {
      }	

      }
      catch (e)
      {}
      }
    }
    
xmlHttp.open("POST", url , true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
var data = "requestItemUrl=" +  requestItemUrl +  "&view=" + view + "&freesearch=" + freeSearch + 
             "&siteid=" + siteid + "&userid=" + userid  +
  	     "&resultpageid=" + resultpageid + "&mediasurface_target=" + mediasurface_target +
  	     "&pageno=" + pageno + "&lang=" + lang + "&dKey=" + dKey + "&searchItemName=" + searchItemName + "&search_type=" + search_type;        
xmlHttp.send( data ); 

}
function ajaxSearchDepFunction( view, freeSearch, siteKey, hostKey, lang )
{
var xmlHttp;
try
  {  // Firefox, Opera 8.0+, Safari  
     xmlHttp=new XMLHttpRequest();  }
catch (e)
  {  // Internet Explorer  
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    
      try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      
             return false;      }    }  }
             
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
      {
      try
      {
      userStr = xmlHttp.responseText;
      //alert ("answerDep=" + userStr);
      if (userStr.length>0)
      {
       var searchBlock = document.getElementById('sideblocks');
       searchBlock.innerHTML = userStr;
      }
      else
      {
      }	

      }
      catch (e)
      {}
      }
    }
getUrl = location.pathname + "?view="+ view + "&freesearch=" + freeSearch ;
if (lang=="en") { getUrl = getUrl +"&lang=en"; }
xmlHttp.open("GET", getUrl , true);
xmlHttp.send( null ); 

}
	
function ajaxGetLeftMenuFunction( url, id, keyS, keyC, keyR, lang )

{
	
var xmlHttp;
try
  {  // Firefox, Opera 8.0+, Safari  
     xmlHttp=new XMLHttpRequest();  }
catch (e)
  {  // Internet Explorer  
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    
      try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      
             return false;      }    }  }
             
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      try
      {
      userStr = xmlHttp.responseText;
      //alert ("answerDep=" + userStr);
      if (userStr.length>0)
      {
       var searchBlock = document.getElementById( id );
       searchBlock.innerHTML = userStr;
      }
      else
      {
      }	

      }
      catch (e)
      {}
      }
    }
    
  var data = "?keyS=" + keyS + 
             "&keyC=" + keyC + 
             "&keyR=" + keyR + 
  	     "&lang=" + lang;        
  xmlHttp.open("GET", url+data , true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
  xmlHttp.send( null ); 

}

function trackBinary( me , trackerID, binaryUrl) 
{  
try 
{    
var pageTracker=_gat._getTracker( trackerID );    
pageTracker._trackPageview( binaryUrl );    
setTimeout('document.location = "' + me.href + '"', 100); 
}
catch(err)
{}
}
				
function windowOpen( n )
{
  var al = document.getElementById("link"+n);
  if (al.target.length>0)
   {
   window.open ( al.href );
   }
  else
   location.assign(al.href);
}

function highlightGroup( path )
{
 var pathId = document.getElementById( path );
 if (pathId)
  {
  pathId.className = 'selected ' + pathId.className ;
  pathId = document.getElementById ('img'+path );
  if (pathId)
   {
   pathId.src = '/images/icons/arrow1_s.jpg';
   }
  }
}

function openPrintWindow( pUrl )
{
window.open( pUrl,'Print','height=512,width=650,menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=no').focus();
return false;	
}

var w;
function createpopup( pUrl, name, specs, x, y )
{
w = window.open( pUrl, name, specs );
return false;
}

function openInNewWindow( pUrl , windowName )
{
try
 {
 nw = window.open( pUrl, windowName );
 if (event) { event.returnValue=false;}
 //if (event.preventDefault) event.preventDefault();
 }
catch (e)
 {}
return false;
}

/*
pageTracker = new Object()
pageTracker._trackPageview = function ( gUrl ) 
{
try
{
_gaq.push(['_trackPageview',gUrl  ]);
 }
catch (e)
 {}
return true;
}
*/

