/*
	XPDOM Cross-Platform DOM 
	Compatibility Wrapper for Web Scripting with W3C DOM
	using  W3C Java DOM interfaces.
	http://xpdom.sourceforge.net
	http://www.sourceforge.net/projects/xpdom

	(c) 2000-2002, José María Arranz Santamaría
	mailto:jmarranz@users.sourceforge.net
	mailto:jmarranz@eresmas.com
	(Spanish citizen)
 
	Copyright of this library is covered with GNU General Public License (GPL) v2
	(see file COPYING)

	Comercial use at commercial web sites is forbidden without a license
	of the author.

	Use:

	In a HTML define a method that is called by onload event of BODY tag
	and call xpdom_init()
	Ex. 
		<html>
		<head>
		<script language="JavaScript">
		var xpdom_ptr = null;		
		function uninit()
		{
			xpdom_finalize(xpdom_ptr); // Only necessary with MSIE 4 and up
		}
		function init()
		{
			xpdom_ptr = xpdom_init(window); 
		}
		</script>
		</head>
		<body onload="init();" onunload="unint();">
		...
*/


// Auxiliary Functions
//*************************************************************************************

function xpdom_parseIntForced(arg)
{
	// If arg is a null string ("") parseInt returns a NaN
	// Normally not defined params like top, left etc. in not absolute positioned
	// elements must be considered value 0 
	var num = parseInt(arg);
	if (isNaN(num)) return 0;
	return num;
}


function xpdom_empty_function()
{
	return null; // Does nothing
}


//****************************************************************************************
//
// Initialization
//
//****************************************************************************************

function xpdom_isNetscape()
{
	if (navigator.appName == "Mozilla" || navigator.appName == "Netscape")
		return true;	
	return false;
}

function xpdom_isNav4()
{
	if (xpdom_isNetscape())
		if (navigator.appVersion.indexOf("4.") != -1)  // Navigator 4
			return true;

	return false;
}

function xpdom_isNS6()
{
	if (xpdom_isNetscape())
		if (navigator.appVersion.indexOf("4.") == -1)  // Netscape 6/Mozilla
			return true;
	
	return false;
}

function xpdom_isMSIE()
{
	if (navigator.appName == "Microsoft Internet Explorer")	// MSIE 4 and 5
		return true;

	return false;
}

function xpdom_isMSIE4()
{
	// En la cadena navigator.appVersion de MSIE 5 también aparece 4.0
	// debemos comprobar si no aparece 5.x
	return !xpdom_isMSIE5();
}

function xpdom_isMSIE5()
{
	if (xpdom_isMSIE())
		if (navigator.appVersion.indexOf("5.") != -1) 
			return true;
	return false;
}


function XPDOM(native_window)
{
	this.native_window = native_window;

	net = new Object();
	net.sf = new Object();
	net.sf.xpdom = new Object();
	net.sf.xpdom.views = new Object();
	net.sf.xpdom.core = new Object();
	net.sf.xpdom.htmlcore = new Object();
	net.sf.xpdom.events = new Object();
	net.sf.xpdom.css = new Object();


	if (xpdom_isMSIE())	// MSIE 4 and 5
	{	
		this.XPDOM_init = xpdom_ie4_XPDOM;
	}
	else if (xpdom_isNav4())
	{
		alert("Navigator 4.x not supported");
	}
	else if (xpdom_isNS6())
	{
		this.XPDOM_init = xpdom_ns6_XPDOM;
	}

	this.XPDOM_init();

	this.xpdom_unbound = null;

	if (xpdom_isMSIE())
	{
		this.xpdom_unbound = new Object();
		this.xpdom_unbound.XPDOM_init = xpdom_unbound_XPDOM;
		this.xpdom_unbound.XPDOM_init();
	}

	// Props
	if (!window.GlobalDOMImplementation)
	{
		var factory = this.createImplFactory();
		
		this.wrap_impl = new Object();
		var native_impl = this.getNativeImplementation();

		factory.overload(native_impl,this.wrap_impl);

		this.wrap_impl.init();

		if (this.xpdom_unbound != null)
		{
			var factoryUnbound = this.xpdom_unbound.createImplFactory();
			this.wrap_impl_unbound = new Object();
			factoryUnbound.overload(new Object(),this.wrap_impl_unbound);

			this.wrap_impl.aux_impl_unbound = this.wrap_impl_unbound;
			this.wrap_impl.aux_impl_unbound.init();	
		}

		window.GlobalDOMImplementation = this.wrap_impl;
	}
	else
	{
		this.wrap_impl = window.GlobalDOMImplementation;
	}

	this.wrap_impl.init_constants(native_window);
	this.wrap_window = this.wrap_impl.aux_overloadFrame(native_window);

	native_window = null; // Help garbage coll. in MSIE
}


function xpdom_init(native_window) 
{
	var objres = new XPDOM(native_window);
	native_window = null; // Help MSIE garbage coll.
	return objres;
}

function xpdom_finalize(xpdom_ptr) 
{
	// Only necesary with MSIE to free memory
	if (xpdom_ptr) xpdom_ptr.finalize();
	xpdom_ptr = null; // Help MSIE garbage coll.
}

