var refreshTimer = null;
var hideTimer = null;

function cursor_wait() {
   //masterShow();
}

function cursor_clear() {
   //masterHide();
}

function hideDIV(name)
{
   return setTimeout("document.getElementById('"+name+"').style.visibility = 'hidden'", 0);
}

function showDIV(name, xpos, ypos)
{
   document.getElementById(name).style.visibility = 'visible';
}

function toggleDIV( id ) {
   var e = document.getElementById(id);
   if(e.style.visibility == 'visible')
      e.style.visibility = 'hidden';
   else
      e.style.visibility = 'visible';
}

function ShowAnimation()
{
	var na = 'animation';
	if(document.getElementById('no_animation')){
		var na = document.getElementById('no_animation');
		
	}
	
	if(na.value!='no_animation'){
		document.getElementById('sel.count').style.display = 'none';
		document.getElementById('sel.wait').style.display  = 'inline';
		cursor_wait();
	}
}

function HideAnimation()
{
	var na = document.getElementById('no_animation');
	
	if(na.value!='no_animation'){
	   document.getElementById('sel.count').style.display = 'inline';
	   document.getElementById('sel.wait').style.display  = 'none';
	   cursor_clear();
	}
}
function hidePopup(name)
{
   // hide popup
   document.getElementById(name).style.display = 'none';

   // show main site
   setOpacity(document.getElementById('main'), 100); 
}

function showPopup(name, xpos, ypos)
{
   // hide main site
   setOpacity(document.getElementById('main'), 30); 
   
   // show popup
   document.getElementById(name).style.display = 'block';
}

function fadeIn(objId, opacity)
{
  if(document.getElementById)
  {
    obj = document.getElementById(objId);
    if(opacity <= 100)
    {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 0);
    }
  }
}

function setOpacity(obj, opacity)
{
  opacity = (opacity == 100)?99.999:opacity;

  // IE/Win
  obj.style.filter = "alpha(opacity="+opacity+")";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function doAction(action)
{
   if(refreshTimer)
   {
      clearTimeout(refreshTimer);
   }

   refreshTimer = setTimeout(action+";refreshTimer = null", 1200);
}

// cross model event listener
function addEvtListener(element, type, func, bubbling) {
	if (window.addEventListener) { // w3c
		element.addEventListener(type, func, !!bubbling);
	} else if(window.attachEvent) { // msie
		element.attachEvent('on' + type, func);
	}
}


function onKeyPressOnlyPostcodeInteger( e )
{
	var key = window.event ? window.event.keyCode : e.which;
	var keychar = String.fromCharCode(key);

	if (key==0)
	{
	   return true;
	}
	
   reg = /[\d\b]/;
   return reg.test(keychar);
}

function onKeyPressOnlyPostcodeKarakter( e )
{
	var key = window.event ? window.event.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	
	if (key==0)
	{
	   return true;
	}
	
   reg = /[A-Za-z\b]/;
   return reg.test(keychar);
}

function masterHide()
{  
   document.getElementById('trailimageid').style.display  = 'none';
   masterVisible = false;
}

function masterShow()
{
   masterVisible = true;
}

function gettrailobj()
{
   if (document.getElementById)
      return document.getElementById("trailimageid").style
   else if (document.all)
      return document.all.trailimagid.style
}

function truebody()
{
   return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function followmouse(e)
{
   if (masterVisible)
   {
      var xcoord=ofsm[0]
      var ycoord=ofsm[1]
      if (typeof e != "undefined")
      {
         xcoord+=e.pageX
         ycoord+=e.pageY
      }
      else if (typeof window.event !="undefined")
      {
         xcoord+=truebody().scrollLeft+event.clientX
         ycoord+=truebody().scrollTop+event.clientY
      }
      
      var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
      var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
      
      // vaststellen boven marge, werkt niet in IE en Safari...
      var docheightUp = screen.height - docheight + YBoundryUp; 
      
      if (xcoord+trailimage[1]+3>docwidth || ycoord+trailimage[2]> docheight || ycoord < docheightUp)
         gettrailobj().display="none"
      else 
         gettrailobj().display=""
         gettrailobj().left=xcoord+"px"
         gettrailobj().top=ycoord+"px"
   }
   else
   { 
   gettrailobj().display="none"
   gettrailobj().left="-50px"
   gettrailobj().top="-50px"
   }
}

function getRadioValue( radio )
{
   var user_input;
   for ( i=0;
         i < radio.length;
         i++)
   {
      if (radio[i].checked)
   	{
   		user_input = radio[i].value;
   	}	
   }
   return user_input;
}

var downStrokeField;
function autojump(fieldName,nextFieldName,fakeMaxLength)
{
   var myForm=document.forms[document.forms.length - 1];
   var myField=myForm.elements[fieldName];
   myField.nextField=myForm.elements[nextFieldName];
   
   if (myField.maxLength == null)
      myField.maxLength=fakeMaxLength;
   
   myField.onkeydown=autojump_keyDown;
   myField.onkeyup=autojump_keyUp;
}

function autojump_keyDown()
{
   this.beforeLength=this.value.length;
   downStrokeField=this;
}

function autojump_keyUp()
{
   if (
      (this == downStrokeField) && 
      (this.value.length > this.beforeLength) && 
      (this.value.length >= this.maxLength)
      )
      this.nextField.focus();
   downStrokeField=null;
}
