/*	_-_-_-_-_-_-_-_-_-_-_-_-_ Base Package -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
	@AUTHOR	: TIPHAINE JULIEN ;;
	@VERSION	: 2.0 ;;

	@DESCRIPTION	:
		This is the main Package. It must be included in each page where you
		want to use others libraries' functions and objects. ;;
	_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
*/

/* Copyright (C) 2001-2006 Julien Tiphaine (julien@_NOSPAM_bluemind.org)
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or (at
 *  your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */


// --== globals ==--
var __JS_LIBS_V2__ 	= true;					// PUBLIC [R-]: This is the mark of this include. It must be loaded first before all others
var __DEBUG__					= false;				// PRIVATE [RW]: Reflect debug mode status : enabled or disabled
var __DEBUG_WIN__	= null;					// PRIVATE [RW]: pointer to debug window;;
var __DEBUG_BUF__ = null;					// PRIVATE [RW]: buffer of debug message;;
var __PATH__						= "http://www.napload.net/JS2/";			// PRIVATE [R-]: Path to access base libs directories

var __CURRENT_NAVIGATOR__="";	// PRIVATE [R-] : string reflecting current navigator
var __IE__  			= false; 									// PUBLIC [R-]: Internet Explorer boolean identifier
var __NS__  		= false;  								// PUBLIC [R-]: Netscape < 6 (4.7x) boolean identifier
var __DOM__ = false;    							// PUBLIC [R-]: DOM compliant browser boolean identifier

var _trace 	= new function () { };
var _assert	= new function () { };
// --== globals ==--


// Determine which navigator is used //
// test for IE //
if(document.all)
  { __IE__ = true;
    __CURRENT_NAVIGATOR__ = "_IE_";
  }
  // test for NS < 6 (4.5+) //
  else if (document.layers)
  { __NS__ = true;
    __CURRENT_NAVIGATOR__ = "_NS_";
  }
  // test for DOM compliant (NS 6+, Konqueror, etc.) //
  else if (document.getElementById)
  { __DOM__ = true;
    __CURRENT_NAVIGATOR__ = "_DOM_";
  }
// !!! ERROR !!! Navigator not supported //
else alert("WARNING: This browser is NOT supported by jslibs !");


//	--== Include ==--
//	@Access	: public ;;
// 	@Args			: lib file with its relative path ;;
//	@role			: make include of given lib file ;;
//	@return		: nothing ;;
function Include(str_lib)
{
	//re = new RegExp("/","g");
	//tmp = str_lib.substring(0,str_lib.length-3);
	//tmp = tmp.replace(re,"_");
	//if(eval("typeof(__"+tmp.toUpperCase()+"__)=='undefined'"))
	//	document.write("<script language=\"javascript\" src=\""+__PATH__+str_lib+"\"> </script>");
	//if(eval("typeof(__"+tmp.toUpperCase()+"__)=='undefined'"))
		document.write("<script language=\"javascript\" src=\""+str_lib+"\"> </script>");
}


//	--== SetDebug ==--
//	@Access	: public ;;
// 	@Args			: debug status (bool) ;;
//	@role			: enable or disable debug mode ;;
//	@return		: nothing ;;
function SetDebug(sw)
{
	if(sw)
	{
		_trace = __trace;
		_assert = __assert;
		__DEBUG_BUF__ ="";
		window.onerror=jslibs_error_manager;
		if(!__DEBUG_WIN__) __DEBUG_WIN__ = window.open(__PATH__+"empty.html","jslibs","width=450,height=400,toolbar=0,resizable=1,scrollbars=1");
    if(!__DEBUG_WIN__)
    {
      alert("Could not open debug window !!! Debug mode is switched off...");
      SetDebug(false);
    }
	}
	else
	{
		_trace=function () {};
		_assert=function () {};
		__DEBUG_BUF__ =null;
		if(__DEBUG_WIN__) __DEBUG_WIN__.close();
	}

	__DEBUG__=sw;
}


//	--== SetDebug ==--
//	@Access	: private ;;
// 	@Args			: error message (string) ; file in which error appened (string) ; line off the faulty code (integer) ;;
//	@role			: redirect browser's error handler to jslibs error handler ;;
//	@return		: true to disable browser handler (bool) ;;
function jslibs_error_manager(msg,url,line)
{
	__DEBUG_BUF__+="<font color='red'><b>error : </b>"+msg+" ( "+url+" , line "+line+" ) </font><hr>";
	RefreshDebugWin();
	return true;
}


//	--== RefreshDebugWin ==--
//	@Access	: private ;;
//	@role			: refresh debug window by writing the debug buffer into its document ;;
//	@return		: nothing ;;
function RefreshDebugWin()
{
	__DEBUG_WIN__.document.open();
	__DEBUG_WIN__.document.write("<html><title>JSlibs debug output</title><body>"+__DEBUG_BUF__+"</body></html>");
  __DEBUG_WIN__.document.close();
}


//	--== _trace ==--
//	@Access	: public ;;
// 	@Args			: message to be printed (string) ;;
//	@role			: ouput a given message into the debug window. It will be printed in blue. ;;
//	@return		: nothing ;;
function __trace(msg)
{
   __DEBUG_BUF__+="<font color='blue'>"+msg+"</font><br>";
  RefreshDebugWin();
}


//	--== _assert ==--
//	@Access	: public ;;
// 	@Args			: condition to check (bool) ; message to print (string) ;;
//	@role			: ouput a given message into the debug window if the condition is true. It will be printed in orange. ;;
//	@return		: nothing ;;
function __assert(condition,msg)
{
	if(condition)
	{
		__DEBUG_BUF__+="<font color='orange'><b>error : </b>"+msg+"</font><hr>";
		RefreshDebugWin();
	}
}
