/*
_|      _|  _|            _|                            _|  _|              _|      _|            
_|_|  _|_|      _|_|_|        _|_|_|  _|_|      _|_|_|  _|        _|_|_|  _|_|_|_|      _|    _|  
_|  _|  _|  _|  _|    _|  _|  _|    _|    _|  _|    _|  _|  _|  _|_|        _|      _|    _|_|    
_|      _|  _|  _|    _|  _|  _|    _|    _|  _|    _|  _|  _|      _|_|    _|      _|  _|    _|  
_|      _|  _|  _|    _|  _|  _|    _|    _|    _|_|_|  _|  _|  _|_|_|        _|_|  _|  _|    _|

  Website: Minimalistix.be
  Version: 1.0
  Programming: Hulpia Frederik - info at powerplant dot be - http://www.powerplant.be
  
  Filename: class.global.js
  Info: This class holds all global functions
*/ 

// Browser detection
var nav			= navigator.userAgent.toLowerCase();
var is_OPERA  	= ( nav.indexOf('opera') != -1 );
var is_SAFARI   = ( (nav.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.') );
var is_WEBTV  	= ( nav.indexOf('webtv') != -1 );
var is_IE     	= ( (nav.indexOf('msie') != -1) && (!is_OPERA) && (!is_SAFARI) && (!is_WEBTV) );
var is_IE4    	= ( (is_IE) && (nav.indexOf('msie 4.') != -1) );
var is_MOZILLA  = ( (navigator.product == 'Gecko') && (!is_SAFARI) );
var is_KONQ    	= ( nav.indexOf('konqueror') != -1 );
var is_NS     	= ( (nav.indexOf('compatible') == -1) && (nav.indexOf('mozilla') != -1) && (!is_OPERA) && (!is_WEBTV) && (!is_SAFARI) );
var is_NS4    	= ( (is_NS) && (parseInt(navigator.appVersion) == 4) );
var is_mac    	= ( nav.indexOf('mac') != -1 );

/*-----------------------------------
 Event Handler prevent event bubbling
 ------------------------------------
 
 @ input	event		event object
 
 @ return	event		
-----------------------------------*/
function doEvent(e)
{
	if (!e) var e = window.event
	// handle event
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return e
}

/*========================================================================
  Flex Global Class
========================================================================*/
function flexGlob()
{
}

/*--------------------------------------------------
 Method(get_object): Get object, by given id name
 ---------------------------------------------------
 
 @ input	string		id name
 
 @ return	mixed		null / object
--------------------------------------------------*/
flexGlob.prototype.getObject = function (name)
{
	if (document.getElementById)
	{
		return document.getElementById(name);
	}
	else if (document.all)
	{
		return document.all[name];
	}
	else if (document.layers)
	{
		return document.layers[name];
	}
	else
	{
		return null;
	}
}

/*--------------------------------------------------
 Method(readCookie): Get cookie value
 ---------------------------------------------------
 
 @ input	string		cookie name
 
 @ return	string		cookie value
--------------------------------------------------*/
flexGlob.prototype.readCookie = function (name)
{
	var searchName = name + "=";
	var csplit = document.cookie.split(';');
	for(var count = 0 ; count < csplit.length ; count++)
	{
		var cook = csplit[count];
		while (cook.charAt(0)==' ') 
		{
			cook = cook.substring(1,cook.length);
		}
		
		if (cook.indexOf(searchName) == 0) 
		{
			return cook.substring(searchName.length,cook.length);
		}
	}
	return null;
}

/*-------------------------------------------------
 Method(autoTab): Automatic Tab
 --------------------------------------------------
 
 @ input	object		Input object
 @ input	event		Keypress event (up / down)
 @ input	integer		Length of field
 @ input	object		Next input object
 
 @ return	none		none
-------------------------------------------------*/
flexGlob.prototype.autoTab = function (sField, ev, len, nField) 
{
	if (ev == "keydown")
	{
		fieldLength = sField.value.length;
	}
	else if (ev == "keyup") 
	{
		if (sField.value.length != fieldLength)
		{
			fieldLength = sField.value.length;
			if (fieldLength == len)
			{
				nField.focus();
			}
		}
	}
}

/*-------------------------------------------------
 Method(isNumber): Only allow numbers
 --------------------------------------------------
 
 @ input	event		Keypress event (up / down)
 
 @ return	boolean		true / false
-------------------------------------------------*/
flexGlob.prototype.isNumber = function (e)
{
	e = doEvent(e);

	var charCode = (e.which) ? e.which : e.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
		// Check for cursor keys
		if(charCode == 37 || charCode == 39)
		{
			return true;
		}
		return false;
	}
	return true;
}

// Initialize the global functions
var flexGlobal = new flexGlob();

/*========================================================================
  Flex Ajax Handler Class
========================================================================*/
function flexAjax ()
{
}

/*-----------------------------------------
 Method(init): Initialize the AJAX Handler
 ------------------------------------------
 
 @ input	none		none
 
 @ return	mixed		true / false
-----------------------------------------*/
flexAjax.prototype.init = function ()
{
	try 
	{
		// Create IE object
		this.AjaxHandler = new ActiveXObject('Microsoft.XMLHTTP');
		return true;
    }
	catch(e) 
	{
		try 
		{
			// Create other browser object
			this.AjaxHandler = new XMLHttpRequest();
			return true;
		}
      	catch (e)
		{
			// Browser does not support XMLHttpRequest
			alert("AJAX Not Supported!");
			return false;
		}
    }
}

/*-------------------------------------------
 Method(ready): Check if AJAX stream is ready
 --------------------------------------------
 
 @ input	none		none
 
 @ return	mixed		true / false
-------------------------------------------*/
flexAjax.prototype.ready = function ()
{
	// Check if ready
	return (this.AjaxHandler.readyState && (this.AjaxHandler.readyState < 4));
}

/*----------------------------------------------------------------------------------------
 Method(checkAjaxExists): Check if init has been run and if the AJAX handler object exists
 -----------------------------------------------------------------------------------------
 
 @ input	none		none
 
 @ return	mixed		true / false
----------------------------------------------------------------------------------------*/
flexAjax.prototype.checkAjaxExists = function ()
{
	// Check if both the init function was run & the AJAX handler exists
	return this.init && this.AjaxHandler ? true : false;	
}

/*----------------------------------------------------------
 Method(onreadystatechange): AJAX OnReadyStatechange Handler
 -----------------------------------------------------------
 
 @ input	function	event
 
 @ return	mixed		true / false
----------------------------------------------------------*/
flexAjax.prototype.onreadystatechange = function (event)
{
	// Check AJAX handler object
	if (!this.checkAjaxExists())
	{
		return false;
	}
	
	// Check if the event is a function
	if (typeof event != 'function')
	{
		// It's not a function return false
		return false;
	}
	else
	{
		// Execute the function
		this.AjaxHandler.onreadystatechange = event;
		return true;
	}
}

/*-------------------------------------------------------------
 Method(send): Sends the data thru the AJAX object, method POST
 --------------------------------------------------------------
 
 @ input	string		url
 @ input	string		post data
 
 @ return	mixed		true / false
-------------------------------------------------------------*/
flexAjax.prototype.send = function (url, data)
{
	// Check AJAX handler object
	if (!this.checkAjaxExists())
	{
		return false;
	}

	// Send if AJAX stream is ready
	if (!this.ready())
	{
		// Open the AJAX stream, using POST method and async mode
		this.AjaxHandler.open('POST', url, true);
		// Set request headers
		this.AjaxHandler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.AjaxHandler.setRequestHeader('X-Referer', document.location);
		
		// Send thru AJAX stream
		this.AjaxHandler.send(data); /* + '&ses=' + flexGlobal.readCookie("flexHASH")); */

		// Check if the send is complete
		if (this.AjaxHandler.readyState == 4 && this.AjaxHandler.status == 200)
		{
			// Return true when completed
			return true;
		}
	}
	else
	{
		// Return false if not ready
		return false;
	}
}