// ----------------------------------------------------------------------------// theo.lenaerts@opikanoba.com// 2006// ----------------------------------------------------------------------------

// ============================================================================// helper functies// ----------------------------------------------------------------------------// laad script bestandfunction _loadScript( src )
{
	document.writeln( '<script language="javascript" src="' + src + '"></script>' );
}// ----------------------------------------------------------------------------// laad style bestandfunction _loadStyle( src, title )
{
	document.writeln( '<link title="' + title + '" href="' + src + '" type="text/css" rel="stylesheet">' );
}// -------------------------------------------------------------------------------------
function _getPath( )
{
	var fullPath = this.location.href;
	var i = fullPath.lastIndexOf( '/' );
	var path = fullPath.substring(0, i);
	path += '/';
	return path;
}
// ----------------------------------------------------------------------------// geeft element terug voor gegeven id// werkt in IE and FFfunction _getElementById( id )
{
	if ( document.getElementById )
		return document.getElementById( id );	else if ( document.all )		return document.all[ id ];	else		return document[ id ];}// ----------------------------------------------------------------------------// zet element positie// werkt in IE en FFfunction _moveElement( elem, left, top )
{
	if ( elem )
	{
		if ( elem.style.left )	// IE en FF		{			elem.style.left = left;			elem.style.top = top;		}		else if ( elem.left )		{			elem.left = left;			elem.top = top;		}	}}// ----------------------------------------------------------------------------// zet element size// werkt in IE en FFfunction _sizeElement( elem, width, height )
{
	if ( elem )
	{
		if ( elem.style.width )	// IE en FF		{			elem.style.width = width;			elem.style.height = height;		}		else if ( elem.width )		{			elem.width = width;			elem.height = height;		}	}}// ----------------------------------------------------------------------------// zet element clip size// werkt in IE en FFfunction _clipElement( elem, top, right, bottom, left )
{
	if ( elem )
	{
		var c = 'rect(' + top + 'px,';
		c += right == 'auto' ? 'auto,' : right + 'px,';
		c += bottom == 'auto' ? 'auto,' : bottom + 'px,';
		c += left + 'px)';
		elem.style.clip = c;	}}// ----------------------------------------------------------------------------function _writeElement( elem,text ) 
{
	if ( elem )
	{
		if( document.getElementById )
		{
			elem.innerHTML = text;
		} 
		else if( document.all ) 
		{
			elem.innerHTML = text;
		} 
		else 
		{
			elem.document.open();
			elem.document.write( text );
			elem.document.close();
		}
	}
}
// ----------------------------------------------------------------------------function _showElement( elem, flag )
{
	var showFlag = true;
	if ( typeof( flag ) == 'boolean' )
		showFlag = flag;
	if ( elem )
		elem.style.visibility = showFlag == true ? 'visible' : 'hidden';
}
// ----------------------------------------------------------------------------function _displayElement( elem, flag )
{
	var displayFlag = true;
	if ( typeof( flag ) == 'boolean' )
		displayFlag = flag;
	if ( elem )
		elem.style.display = displayFlag == true ? 'block' : 'none';
}
// ----------------------------------------------------------------------------function _hideElement( elem )
{
	if ( elem )
		elem.style.visibility = 'hidden';
}
// ----------------------------------------------------------------------------function _setElementClass( elem, className )
{
	if ( elem )
		elem.className = className;
}
// ----------------------------------------------------------------------------function _setElementZIndex( elem, z )
{
	if ( elem )
	{
		if ( elem.style )
			elem.style.zIndex = z;
	}
}
// ----------------------------------------------------------------------------// geeft flash object terug voor gegeven id// werkt in IE en FF// is verschillend van vorige functie omdat anders in FF de flashfuncties // (bv Play()) niet herkend worden function _getFlashObject( id )
{
	var obj = null;
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	var isOpera = navigator.userAgent.indexOf("Opera") != -1;
	if ( isOpera )
	{
		obj = eval( 'window.document["' + id + '"]' );
		//_showObjectAttributes( obj );
	}
	else if ( isIE )
		obj = document.getElementById( id );
	else
	{
		if ( eval( 'window.' + id ) )
			obj = eval( 'window.document["' + id + '"]' );
		if ( eval( 'document.' + id ) )
			obj =  eval( 'document.' + id );
	}
	return obj;
}
// ----------------------------------------------------------------------------var first = true;function _showObjectAttributes( obj )
{
	if ( obj != null && first == true )
	{
		t = '';
		var i = 0
		for ( var attr in obj)
		{
			t += attr + ':';
			if ( i>0 && i%10 == 0 )
				t += '\n';
			i++;
		}
		alert(t);
		first = false;
	}
}
// ----------------------------------------------------------------------------function _getFormElement( form, elId )
{
	var e = null;
	if ( form )
	{
		if ( document.forms ) // zowel IE als FF
			e = eval( 'document.forms["' + form.name + '"].' + elId );
		else
			e = eval( form.name + '.' + elId );
	}
	return e;}
// ----------------------------------------------------------------------------function _setBkgColor( obj,color )
{
	if ( obj )
		obj.style.backgroundColor = color;
}

// ----------------------------------------------------------------------------// function: _imageGet// get image object// parameters: window, id of layer, id of image// example: _imageGet(window,'nextElement','nextImg')// ----------------------------------------------------------------------------function _imageGet(win,lyrid,imgid){	var img = null;	if (win.document.getElementById)	// Netscape6 en Explorer 5	{		img = win.document.getElementById(imgid);	}	else if (win.document.all)	// Explorer 4		img = win.document.images[imgid];	else if (win.document.layers)	// Netscape 4		{		if (lyrid!='' && win.document.layers[lyrid] )			img = win.document.layers[lyrid].document.images[imgid];		else			img = win.document.images[imgid];	}		return img;}	// _imageGet// ----------------------------------------------------------------------------// function: _imageReplace// changes source of an image// parameters: window, id of layer, id of image, image file name// example: _imageReplace(window,'nextElement','nextImg','../Img/next_1.gif')// ----------------------------------------------------------------------------function _imageReplace(win,lyrid,imgid,source){	//win.status='';	var img = _imageGet(win,lyrid,imgid);	if( img )		img.src = source;	return true;}	// _imageReplace// -----------------------------------------------------------------------------------------
// random functions
// theo.lenaerts@opikanoba.com// xGetRandom : returns a random number between a minimum and a maximum value
function _getRandom( min, max )
{
	var r = Math.random();
	var x = min + Math.round( eval((max-min)*r));
	return x;
}

// randomiseArray : randomises the first max numbers of an array of numbers
function _randomiseArray( a, max )
{
	var temp = new Array( max );
	var dup = new Array( max );
	for ( i=0; i<max; i++ )
		temp[i] = i+1;	
	for ( i=0; i<max; i++ )
	{
		x = _getRandom( 1, max-i );
		y = temp[x-1];
		dup[i] = a[y-1];
		for ( j=x-1; j<max-i-1; j++ )
			temp[j] = temp[j+1];
	}
	for ( i=0; i<max; i++ )
		a[i] = dup[i];
}

// -----------------------------------------------------------------------------------------
// verwijder gegeven karakter voor en achteraan een string
function _trim( str, cToRemove ) 
{
	var newStr = _trimLeft( str, cToRemove )
	return _trimRight( newStr, cToRemove );
}
function _trimLeft( str, cToRemove )
{
  while ( (str.substring(0,1) == cToRemove) )
  {
    str = str.substring(1,str.length);
  }
  return str;
}
function _trimRight( str, cToRemove )
{
  while ( (str.substring(str.length-1,str.length) == ' ') )
  {
    str = str.substring(0,str.length-1);
  }
	return str;
}

// -----------------------------------------------------------------------------------------
// conversie functies
var _ascii = ""
_setAscii( );
function _setAscii( )
{
	_ascii = " !\"#$%&'()*+,-./0123456789:;<=>?@";
	var loAZ = "abcdefghijklmnopqrstuvwxyz";
	_ascii += loAZ.toUpperCase( );
	_ascii += "[\\]^_`";
	_ascii += loAZ;
	_ascii += "{|}~";
}
function _asciiToChar( code )
{
	var index = code - 32;
	if ( index >=0 && index < _ascii.length ) 
		return _ascii.charAt( index );
	else
		return '';
}
function _charToAscii( c )
{
	var index = _ascii.indexOf( c );
	if ( index != -1 )
		return index + 32;
	else
		return 0;
}

// -----------------------------------------------------------------------------------------
// cookie functies
// ----------------------------------------------------------------------------function _cookiesEnabled( ) 
{
	var enabled = ( navigator.cookieEnabled ) ? true : false;
	// if not IE4+ nor NS6+
	if ( typeof( navigator.cookieEnabled ) == 'undefined' && !enabled )
	{
		document.cookie = 'testcookie';
		enabled = ( document.cookie.indexOf( 'testcookie' ) != -1 ) ? true : false;
	}
	return enabled;
}
// ----------------------------------------------------------------------------function _cookieGetVal( offset ) 
{  
    var endstr = document.cookie.indexOf ( ';', offset );  
    if (endstr == -1)    
        endstr = document.cookie.length;  
    return unescape( document.cookie.substring( offset, endstr ) );
}
// ----------------------------------------------------------------------------function cookieGet( name )
{  
    var arg = name + '=';  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while ( i < clen ) 
    {    
		var j = i + alen;    
		if ( document.cookie.substring( i, j ) == arg )      
            return _cookieGetVal (j);    
        i = document.cookie.indexOf( ' ', i) + 1;    
        if ( i == 0 ) break;   
    }  
    return '';
}
// ----------------------------------------------------------------------------function _cookieSet( name, value ) 
{  
    var argv = _cookieSet.arguments;  
    var argc = _cookieSet.arguments.length;  
    var expires = ( argc > 2 ) ? argv[2] : null;  
    var path = ( argc > 3 ) ? argv[3] : null;  
    var domain = ( argc > 4 ) ? argv[4] : null;  
    var secure = ( argc > 5 ) ? argv[5] : false;  
    document.cookie = name + '=' + escape( value ) + 
    ( ( expires == null ) ? '' : ( '; expires=' + expires.toGMTString( ) ) ) + 
    ( ( path == null ) ? '' : ( '; path=' + path ) ) +  
    ( ( domain == null ) ? '' : ( '; domain=' + domain ) ) +    
    ( ( secure == true ) ? '; secure' : '' );
}
// ----------------------------------------------------------------------------function _cookieDelete( name ) 
{  
    var exp = new Date( );  
    exp.setTime ( exp.getTime( ) - 1 );  
    // This cookie is history  
    var cval = _cookieGet( name );  
    document.cookie = name + '=' + cval + '; expires=' + exp.toGMTString( );
}