/**************************** CONFIGURATION *******************************/

// sets the configuration to DEBUG
function Set_CONFIGURATION_DEBUG()
{
	this.__CONFIGURATION_MODE = this.__CONFIGURATION_DEBUG;
}

// sets the configuration to RELEASE
function Set_CONFIGURATION_RELEASE()
{
	this.__CONFIGURATION_MODE = this.__CONFIGURATION_RELEASE;
}

// returns true if configuration mode is set to DEBUG, false otherwise
function Check_CONFIGURATION_DEBUG()
{
	return this.__CONFIGURATION_MODE == this.__CONFIGURATION_DEBUG;
}

// returns true if configuration mode is set to RELEASE, false otherwise
function Check_CONFIGURATION_RELEASE()
{	
	return this.__CONFIGURATION_MODE == this.__CONFIGURATION_RELEASE;
}

// function for creating a CONFIGURATION_MODE object
function CONFIGURATION_MODE()
{
	// attributes
	this.__CONFIGURATION_DEBUG			= 'CONFIGURATION_DEBUG';
	this.__CONFIGURATION_RELEASE		= 'CONFIGURATION_RELEASE';
	this.__CONFIGURATION_MODE			= this.__CONFIGURATION_DEBUG;
	
	// methods
	this.Set_CONFIGURATION_DEBUG		= Set_CONFIGURATION_DEBUG;
	this.Set_CONFIGURATION_RELEASE		= Set_CONFIGURATION_RELEASE;
	this.Check_CONFIGURATION_DEBUG		= Check_CONFIGURATION_DEBUG;
	this.Check_CONFIGURATION_RELEASE	= Check_CONFIGURATION_RELEASE;
}

// global variable for configuration mode
var __cfgMODE = __cfgMODE;
if ( false == __CheckReference(__cfgMODE) )
{
	__cfgMODE = new CONFIGURATION_MODE();
	//__cfgMODE.Set_CONFIGURATION_DEBUG();
	//__cfgMODE.Set_CONFIGURATION_RELEASE();
}
__cfgMODE.Set_CONFIGURATION_RELEASE();

/****************************** END - CONFIGURATION *****************************/






/********************************* Check functions ******************************/

// returns false is null reference is passed, true otherwise
function __CheckReference(obj)
{
	if ( null == obj || 'undefined' == obj )
	{
		return false;
	}
	
	return true;
}

// returns false is null reference is passed, true otherwise
function __CheckReferenceEx(obj, cfgMode)
{
	if ( false == __CheckReference(cfgMode) || true == cfgMode.Check_CONFIGURATION_DEBUG() )
	{
		return __CheckReference(obj);
	}

	return true;
}

// returns false if null reference is passed or string is empty, true otherwise
function __CheckString(str)
{
	if ( false == __CheckReference(str) || '' == str )
	{
		return false;
	}

	return true;
}

// returns false if null reference is passed or string is empty, true otherwise
function __CheckStringEx(str, cfgMode)
{
	if ( false == __CheckReference(cfgMode) || true == cfgMode.Check_CONFIGURATION_DEBUG() )
	{
		return __CheckString(str);
	}

	return true;
}

// returns false if null reference is passed or the number is invalid, true otherwise
function __CheckInteger(nr)
{
	if ( false == __CheckReference(nr) || true == isNaN(parseInt(nr, 10)) )
	{
		return false;
	}
	
	return true;
}

// returns false if null reference is passed or the number is invalid, true otherwise
function __CheckIntegerEx(nr, cfgMode)
{
	if ( false == __CheckReference(cfgMode) || true == cfgMode.Check_CONFIGURATION_DEBUG() )
	{
		return __CheckInteger(nr);
	}

	return true;
}


/************************** END - Check functions *************************/



// sets the object's opacity
// obj is the element object retrieved by document.getElementById
// (opacity is a number between or equal to 0 and 100)
function SetObjectOpacity(obj, opacity)
{
	if ( false == __CheckReference(obj) )
	{
		return;
	}

	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;
}




// shows a message on the screen
function __ALERT(message)
{
	if ( false == __CheckString(message) )
	{
		return;
	}
	
	window.alert(message);
}





/********************************** MESSAGE *******************************/

// structure messageType (used in TranslateMessage)
function __messageType()
{
	this.value					= 0;
	this.ON_WM_CLOSE			= ++this.value;
	this.ON_WM_QUESTION			= ++this.value;
	this.ON_WM_BEGINDRAG		= ++this.value;
	this.ON_WM_DRAG				= ++this.value;
	this.ON_WM_ENDDRAG			= ++this.value;
	this.ON_WM_BEGINRESIZE		= ++this.value;
	this.ON_WM_RESIZE			= ++this.value;
	this.ON_WM_ENDRESIZE		= ++this.value;
	this.ON_WM_MOUSEDOWN		= ++this.value;
	this.ON_WM_MOUSEUP			= ++this.value;
	this.ON_WM_MOUSECLICK		= ++this.value;
	this.ON_WM_MOUSEMOVE		= ++this.value;
	this.ON_WM_MOUSEOUT			= ++this.value;
}

// structure tagMSG (used in TranslateMessage)
function __MSG()
{
	this.message	= null;		//the message number
	this.sender		= null;		//the object that sends the message
	this.coordX		= null;		//the X screen coordinates where tne event took place
	this.coordY		= null;		//the Y screen coordinates where tne event took place
	//this.wParam		= null;		//Specifies additional information about the message. The exact meaning depends on the value of the message member
}

/******************************** END - MESSAGE ****************************/




/*********************************** PairArray *****************************/

// structure PairKeyValue
function PairKeyValue(key, value)
{
	this.key = key;
	this.value = value;
}


// returns the element at position index, or null if index is invalid
function GetPairAt(index)
{
	if ( false == __CheckIntegerEx(index) )
	{
		return null;
	}

	if ( index < 0 || index >= this.array.length )
	{
		return null;
	}

	return this.array[index];
}

// returns the value associated with the key, or null if not founded or an error detected
function GetPairValue(key)
{
	if ( false == __CheckStringEx(key, __cfgMODE) )
	{
		return null;
	}

	for ( var i = 0; i < this.array.length; ++i )
	{
		var elem = this.array[i];
		if ( elem.key == key )
		{
			return elem.value;
		}
	}
	
	return null;
}

// Add a pair to the array
function AddPair(objPair)
{
	if ( false == __CheckReference(objPair) )
	{
		__ALERT('AddPair: objPair - null reference !');
		return;
	}
	
	if ( false == __CheckString(objPair.key) )
	{
		__ALERT('AddPair: objPair.key - null reference or empty string !');
		return;
	}

	if ( true == __CheckReference(this.GetValue(objPair.key)) )
	{
		__ALERT('AddPair: objPair.key - duplicated key !');
		return;
	}
	
	this.array.push(objPair);
}

// function for creating an object
function PairArray()
{
	// --private
	this.array			= new Array();
	
	// --public
	this.Add			= AddPair;
	this.GetAt			= GetPairAt;
	this.GetValue		= GetPairValue;
}

/*************************** END - PairArray ***************************/





/****************************** Objects ********************************/

// ImageInfo object
function ImageInfo(src)
{
	this.src	= src;
}


// ColorInfo object
function ColorInfo(color)
{
	this.color = color;
}


// TextInfo object
function TextInfo(text)
{
	this.text = text;
}

/*************************** END - Objects *****************************/
