
var focus_set = 0; // Communicates with the ShowEditForm() function

function trySetFocus() 
{
  if ( !document.forms || !document.forms[0] || !document.forms[0].elements )
    {
      return;
    }

  if ( focus_set ) return;

	var pos = document.forms[0].name == 'searchForm' ? 1 : 0;

	var frm = document.forms[pos];

  for ( i = 0 ; i < frm.elements.length ; i++ ) 
    {
      var el = frm.elements[i];
      if ( el.type && el.type != 'hidden' && ! el.disabled )
        {
          el.focus();
          return; 
        }
    }
}

function doVfill()
{
	setTimeout( "setVfill()", 200 );
}

function setVfill()
{
	var vfill;
	var leftContent;
	if ( ( vfill = document.getElementById( 'vfill' ) ) && ( leftContent = document.getElementById( 'leftContent' ) ) )
	{
		var fillHeight = leftContent.offsetHeight - vfill.offsetTop - 15;
		vfill.style.height = fillHeight+"px";
	}
}

//////////////////////////////////////////////////////////////////////
// ajax call (HttpRequest is onvolledig)

function ajaxCall(dataUrl,returnFunction,nocache,debug,returnVar) {
  //create a variable for handling requests to be reused
  var http = null;
  
  //If nocache is passed, make each call unique
  if (nocache != null && nocache == 1) {
    var dt = new Date();
    var dtString = ''+dt.getFullYear()+dt.getMonth()+dt.getDate()+dt.getHours()+dt.getMinutes()+dt.getMilliseconds();
    //check for cookie - if disabled then append request.nocookies
    dataUrl = dataUrl + '&dtm='+dtString;
  }
  if (debug != null && debug == 1 ) {prompt('',dataUrl);};

  //try to create the xmlHttpRequest object with non-IE code first, else fallback on IE
  try {
    http = new XMLHttpRequest(); // non-IE
    }
  catch (a)
  {
    try
    {
      http = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (b)
    {
      try
      {
        http = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(c)
      {
        return false; 
      }
    } 
  }
  // more error checking
  try {
    http.open("GET", dataUrl , true);
  } catch (error) {
    return false;
  }
  //upon a change of status of the request for the lookup page, call the javascript handler
  http.onreadystatechange = function() {
    //readystate of 4 means the request is complete
    if (http.readyState == 4) {
      //status code of 200 means OK (regular status codes)
      if (http.status != 200) {
        return false;
      } else {
        returnFunction(http,returnVar);
      }
    }
  }
  //close the connection (very important for memory leaks)
  http.send(null);
  return false;
}

//////////////////////////////////////////////////////////////////////
// hier komt de HttpRequest-"class" die gebruikt wordt om het php pspell-script te raadplegen.

function HttpRequest() {
	var _xmlhttp;
	var _post;

	try
	{
		this._xmlhttp = new XMLHttpRequest();
	}
	catch (a)
	{
		try
		{
			this._xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (b)
		{
			try
			{
				this._xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(c)
			{
				this._xmlhttp = false;
			}
		}
  }
}

HttpRequest.prototype.sendGet = function(url)
{
	if (!this._xmlhttp) return false;
	this._xmlhttp.open("GET", url, false);
	this._xmlhttp.send(null);
	return this._xmlhttp.responseText;
}

HttpRequest.prototype.setPostVariables = function( post )
{
	if (!this._xmlhttp) return false;
	var separator = '';
	this._post = '';
	for ( name in post )
	{
		this._post +=	separator + encodeURIComponent( name ) + '=' +
									encodeURIComponent( post[name] );
		separator = '&';
	}
}

HttpRequest.prototype.sendPost = function(url)
{
	if (!this._xmlhttp) return false;
	this._xmlhttp.open("POST", url, false);
	this._xmlhttp.setRequestHeader(
		'Content-Type',
		'application/x-www-form-urlencoded; charset=UTF-8'
	);
	this._xmlhttp.setRequestHeader('Content-Length', this._post.length);
	this._xmlhttp.send(this._post);
	return this._xmlhttp.responseText;
}

/* ********************************************************************** */
/* Auto-tab                                                               */

/* Variable die gebruikt wordt voor getObjectById, niet alle dom functies worden door een browser
 * ondersteund. Middels de functie getObjectById wel.
 */
var domType = null;
	
function checkDomType(){
  if(document.getElementById){
     domType = "std";
  }else if(document.all){
     domType = "ie4";
  }else if (document.layers){
     domType = "ns4";
  }
}

//set variable for domType
checkDomType();    

function getObjectById(idName){
       switch(domType){
          case "std" :{
                         return document.getElementById(idName);
                      }break;

          case "ie4" :{
                         return document.all[idName];
                      }break;
        
          case "ns4" :{
                         return document.layers[idName];
                      }break;
   
          default    :{
                         alert('Oeps... Javascript method is not supported in this context.');
                      }break;
       }
    }

 /** Hoe te gebruiken...
     * <input type="text" maxlength="4" id="mijnId" onkeyup="autoTab(this,'mijnAndereId');">
     * <input type="text" maxlength="4" id="mijnAndereId">
     * Het resultaat is dat er nooit meer dan 4 karakters kan worden ingevoerd bij beide 
     * tekstvelden, als javascript gedisabled is. Bij enabled zal deze na het invoeren
     * van de 4 karakter een autotab worden gedaan naar het tweede veld. Hou er rekening mee
     * dat deze ten aller tijden wordt aangeroepen op het laaste moment van het event,
     * namelijk onkeyup, i.v.m. IMac
     */

function autoTab(blurredInput, toFocusedInputId){
	   //do not handle autotab when there is not alfanummeric key is pressed
	   if(blurredInput != null && blurredInput.getAttribute){
	     //get the blurred input fields maxlenght
	     var maxLenght = blurredInput.getAttribute('maxLength');
	     if(blurredInput.value.length == maxLenght){
	        //first get the next focussed element
	        var elementToFocus = getObjectById(toFocusedInputId);
	        elementToFocus.focus();
	     }
	   }   
}


