// algemene functies

var _url;
var fteStatus = false;
var info = new Array();

var dynForm = "";

/*
function XpInv(popupId, url)
{
    openCenter(popupId, url, 750, 500, 'scrollbars=yes,status=yes,resizable=yes');
}
*/
function veranderImg(imgName, imgSrc){
  		document.images[imgName].src = imgSrc;
}
function openCenter(id, url, width, height, properties)
{
	if (screen)
	{
		x = (screen.availWidth - width) / 2;
		y = (screen.availHeight - height) / 2;
  }

  referentie = window.open(url, id, properties+',width='+width+',height='+height+',screenX='+x+',screenY='+y+',left='+x+',top='+y);
}
function XpInv(popupId, url)
{
  if (!_url)
  {
    openCenter(popupId, url, 750, 500, 'scrollbars=yes,status=yes,resizable=yes');
    return;
  }

  var xmlhttp = false;

  if (window.ActiveXObject) xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   else xmlhttp = new XMLHttpRequest();

  if (!xmlhttp) openCenter(popupId, url, 750, 500, 'scrollbars=yes,status=yes,resizable=yes');

//  url += "&hash=" + Math.random();     // nooit cachen

  try
  {
    xmlhttp.open("POST", _url, true);
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState == 4)  //  && xmlhttp.status == 200
      {
        var id = "";
        if (xmlhttp.status == 200) id = xmlhttp.responseText;
        openCenter(popupId, url + '&p_best='+id, 750, 500, 'scrollbars=yes,status=yes,resizable=yes');
      }
    }
    xmlhttp.send(null);
  }

  catch(e)
  {
    openCenter(popupId, url, 750, 500, 'scrollbars=yes,status=yes,resizable=yes');
  }
}


function XpOpen(url)
{
  var xmlhttp = false;

  if (window.ActiveXObject) xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   else xmlhttp = new XMLHttpRequest();

  if (!xmlhttp) return false;

//  url += "&hash=" + Math.random();     // nooit cachen

  try
  {
    xmlhttp.open("POST", _url, true);
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState == 4)  //  && xmlhttp.status == 200
      {
        var id = "";
        if (xmlhttp.status == 200) id = xmlhttp.responseText;
        window.location.href=url + '&p_best='+id;
      }
    }
    xmlhttp.send(null);
  }

  catch(e)
  {
    window.location.href=url;  	
  }
}

function swapImg(id, img)
{
  id.style.backgroundImage = 'url('+img+')';
}

function initBlad(id)
{
	openBlad = document.getElementById(id);
	openBlad.style.display='';
}

function toonBlad(id)
{
	id = document.getElementById(id);
	id.style.display='';
	openBlad.style.display = 'none';
	openBlad = id;
}

/* nieuwe tabbladfuncties */

function initTab(p_id)
{
  if (!p_id) p_id = 0;

  if (openDiv = document.getElementById("tb"+p_id))
    openDiv.style.display='';
  
  openTab = document.getElementById("t"+p_id);
  if (openTab) openTab.className='tab active';

  
}

function initTab2(p_id)
{
  if (!p_id) p_id = 0;

  if (openDiv = document.getElementById("tb"+p_id))
    openDiv.style.display='';
  
  openTab = document.getElementById("t"+p_id);
  if (openTab) openTab.className='tab active';

  
}
function initTabtest(p_id)
{
  if (!p_id) p_id = 0;

  if (openDiv = document.getElementById("b"+p_id))
    openDiv.style.display='';

  openTab = document.getElementById("t"+p_id);
  if (openTab) openTab.className='tabtest active';


}


function toonTabtest(p_id)
{
  if (openDiv)
  {
    openDiv.style.display = 'none';
    openTab.className = 'tabtest';
    id = document.getElementById("b"+p_id);
    id2 = document.getElementById("t"+p_id);
    id.style.display='';
    id2.className='tabtest active';
    openDiv = id;
    openTab = id2;
  }
}


function toonTab(p_id)
{
  if (openDiv)
  {
    openDiv.style.display = 'none';
    openTab.className = 'tab';
    id = document.getElementById("tb"+p_id);
    id2 = document.getElementById("t"+p_id);
    id.style.display='';
    id2.className='tab active';
    openDiv = id;
    openTab = id2;
  }
}
function toonTab2(p_id)
{
  if (openDiv)
  {
    openDiv.style.display = 'none';
    openTab.className = 'tab';
    id = document.getElementById("tb"+p_id);
    id2 = document.getElementById("t"+p_id);
    id.style.display='';
    id2.className='tab active';
    openDiv = id;
    openTab = id2;
  }
}
function wisselBlad(form){
if (bladid = form.options[form.selectedIndex].value)
	toonBlad(bladid);
}

function pImg(id, url){
  openCenter(id, url, 900, 650, 'scrollbars=yes,status=yes,resizable=yes');
}

function pInv(id, url){
  myWin = openCenter(id, "", 750, 500, 'scrollbars=yes,status=yes,resizable=yes');
  XpInv (id, url);
}

function pNt(id, url){
  myWin = openCenter(id, "",750,700,'scrollbars=yes,status=yes,resizable=yes');
  XpInv (id,url);
}


function pDet(id, url){
  myWin = openCenter(id, "", 750, 500, 'scrollbars=yes,status=yes,resizable=yes');
  XpInv (id, url);
}

function pOpen(url)
{
  XpOpen(url);
}

function disclaimer() {
	openCenter('disc','/0/disclaimer.html', 300,430); } function
sitemap() {
	openCenter('smap','/0/sitemap.html', 300,370);
}

function MediaPlayer(p_vast, p_id, p_path, p_adt_id, p_start, p_eind, p_frag)
{
  if(!p_start) p_start = "";
  if(!p_eind) p_eind = "";
  if(!p_frag) p_frag = "";
  openCenter('mp', 'zk2.mediaplayer?p_path='+p_path+'&p_vast='+p_vast+'&p_id='+p_id+'&p_adt_id='+p_adt_id +'&p_start='+p_start+'&p_eind='+p_eind+'&p_frag='+p_frag, 1, 1);
}

function toggleHulp(id, state, event, w)
{
  var DivRef = document.getElementById(id);
  var IfrRef = document.getElementById('schaduwDiv');
  var correctie = 10;

  bW = document.body.clientWidth;
  bH = document.body.clientHeight;

  if (window.event) 
  {
    sizeY = document.documentElement.clientHeight;

    mouseY = window.event.clientY;
    corrY = document.documentElement.scrollTop + document.body.scrollTop;
    x = window.event.clientX + document.documentElement.scrollLeft
                             + document.body.scrollLeft;
    y = window.event.clientY + corrY; 
  }
  else 
  {
    sizeY = window.innerHeight;
    mouseY = event.clientY;
    corrY = window.scrollY;
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  w = document.getElementById(id).offsetWidth;
  h = document.getElementById(id).offsetHeight;

  if (w + x > bW) x -= (w + x) - bW;

  (window.event) ? overY = (window.event.clientY + h) - sizeY : overY = (event.clientY + h) - sizeY;
  if (overY > 0) y -= overY;

  x += 10;
  y += 10;

  if(state)
  {
   DivRef.style.display = "block";
   if (w) DivRef.style.width = w + "px";
   IfrRef.style.width = w;
   IfrRef.style.height = h;
   IfrRef.style.top = DivRef.style.top;
   IfrRef.style.left = DivRef.style.left;
   IfrRef.style.zIndex = DivRef.style.zIndex - 1;
   IfrRef.style.display = "block";

   DivRef.style.left = x + 'px'; 
   DivRef.style.top = y + 'px';
   IfrRef.style.left = x + 'px'; 
   IfrRef.style.top = y + 'px';
   DivRef.style.visibility = "visible";
  }
  else
  {
    DivRef.style.display = "none";
    IfrRef.style.display = "none";
  }
}

var status=0;

// wrap tvoet --> toggleHulp
function tVoet(id, state, e)
{
	toggleHulp (id, state, e);
}

/* cookiefuncties */
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// einde cookiefuncties

function showBasket(pVast, pMethode)
{
  openCenter('basket', '/pls/m/zk2.html_co?p_vast=' + pVast + '&p_methode=' + pMethode, 750, 750, 'scrollbars=yes,status=no,resizable=yes');
}

function showreageer2(pVast, pAhd, pTxt)
{
  openCenter('reageer', '/pls/test/zk2.toon_react_form?p_vast=' + pVast + '&p_ahd_id=' + pAhd + '&p_txt=' + pTxt, 600, 600, 'scrollbars=yes,status=no,resizable=yes');
}

function swapTextDiv(id, l2, t1, t2)
{
  l = document.getElementById(id);
  if (l.style.display != 'none')
  {
    l.style.display = 'none';
    l2.innerHTML = t2;
  }
  else
  {
    l.style.display = 'block';
    l2.innerHTML = t1;
  }
}

function InitZoek()
{
  fteStatus = false;
//  var l = document.getElementById("zo_a");
//  ChangeZoek(l);
//  l.checked = true;
//  l = document.getElementById("zoekveld");
//  l.value = "vul uw zoekterm(en) in";
//  l.focus();
//  OutputHistory();
}

function ChangeZoek(e)
{
  l = document.getElementById("zoekinfo");
  l.innerHTML = info[e.id];
  l = document.getElementById("zoekinfosub");
  l.innerHTML = info[e.id+'_sub'];
}

function FirstTimeErase(e)
{
//  e = document.getElementById(e);
  if (!fteStatus)
  { 
    e.value = "";
    fteStatus = true; 
  }
}

function submitForm(myForm, myId)
{
  var result = true;
  var zoekveld = document.getElementById(myId);
  var words = zoekveld.value;
  var patt1 = new RegExp("trefwoord:");
  var patt2 = new RegExp("toegang:");
  
  words = words.replace(/^\s+/,'').replace(/\s+$/,'');          // trimmen!

  if (words == 'vul uw zoekterm(en) in') return false;
  if (patt1.test(words)==true) return true;
  if (patt2.test(words)==true) return true;
  if (words)
  {
    var splitwords = words.split(' ');
    for (x=0; x<splitwords.length; x++)
    {
      if (splitwords[x].length && splitwords[x].length<2 && splitwords[x]!=',')
      {
        alert('De zoekterm \''+splitwords[x]+'\' is te kort. Een zoekterm moet minimaal 2 karakters bevatten.');
        result = false;
        break;
      }
    }

    if (words.match(/([&|~.])+|[*|%]([a-zA-Z0-9]+)/g))
    {
      var bad;
      var weight;
      var pre;
      var x;

      bad = RegExp.$1;
      weight = RegExp.$2;
      if (weight && !bad)
      {
        if (weight <0 || weight>9)
        {
          alert ('Met het sterretje (*) kunt u de wegingsfactor vaststellen. Bij een hogere waarde telt het woord zwaarder mee in het zoekresultaat. De factor mag een getal zijn tussen 0 en 10.');
          result = false;
        }
        else if (weight >=0 && weight<=9)
          result = true;
        else 
        {
          pre = (words.match(/([a-zA-Z0-9]*)[%|*]/g))

          x = 0;

          while (pre[x])
          {
            if (pre[x]=="%" || pre[x]=="*")
            {
              alert ('Het sterretje (\'*\') of het procent-teken(\'%\') zijn niet toegestaan aan het begin van een woord.');
              result = false;
              break; 
            }
            x++;
          }
        }
      }
      else 
      {
        alert ('U heeft een ongeldig teken (\''+bad+'\') gebruikt in uw zoekvraag. De verboden tekens zijn: \'.\', \'&\', \'|\', en \'~\'.');
        result = false;
      }
    }
  }
  else 
  {
    alert ('Vul a.u.b. uw zoekvraag in.');
    result = false;
  }
  zoekveld.focus();
  if (result) myForm[1].disabled = true;

  return result;
}

function openHoofd2(url){
//	window.open(url, 'archievenmain');

  try{window.opener.location.href = url;
  window.opener.focus();
  }	
  catch(E){window.open(url)}
}

function openHoofd3(url){
	window.open(url, 'zoekenmain');

}

function checkWin()
  {
  alert(window.name);
  
  }
function setWin(name)
{window.name=name;
	}

