
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";
	}
}

// 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;
}

function ajaxCall(dataUrl, returnFunction, nocache, debug, returnVar) 
{
	//status code of 200 means OK (regular status codes)
	return ajaxCallRich(dataUrl, function(http, returnVar) { if ( http.status == 200 ) returnFunction(http,returnVar); }, nocache, debug, returnVar);
}

function ajaxCallRich(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 ) returnFunction(http, returnVar);
	}
	//close the connection (very important for memory leaks)
	http.send(null);
	return true;
}

function empty() {
	;
}

String.prototype.addslashes = function()
{
        return this.replace(/\\/g,'\\\\').replace(/\'/g,'\\\'');

};

String.prototype.htmlSpecialChars = function(attribute)
{
	var str = this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;');
	if (typeof attribute != 'undefined' && !attribute) str = str.replace(/"/g, '&quot;');
	return str;
}

