
/*

DOM features
Three types of DOMs IE, Netscape Layer and W3C
Name or Id - all objects should be able to be accessed by id but IE only recognises images with a name so may need to use either.
Object ids appear to require defining in CSS with a position. The books specify relative or absolute but hopefully static works as well 
or we're fucked ! Actually tried it with the css definition commented out and it still worked !

Netscape Layer DOM used only in NS4, only allows you to control positiong, visibility, and clipping of an object
	It is NOT supported in NS6 !
	
IE ALL DOM, used in IE4, and IE5 allows you to access all element properties, including color, font etc....

W3C DOM, used in NS6 and IE5 / IE6, allows you to access all properties of all elements on screen


Use "feature sensing" rather than "browser sensing" if possible. This is because a new version of a browser
or an unknown browser may come along that does support the features that you require.
feature sensing allows any browser that is capable of running the codse to do so.

However a bug in NS4 prevents you from using feature sensing from an external javascripts file if that is the 
first file linked to in the HTML - what a load of arse. You have to either embed the code in the HTMl or 
link in another  file first. Or as in this case, use browser detection to confirm that this is NS4 if all
the other DOM detections have failed

Check for the best DOM first ( W3C ) then the others. Once one is found stop checking for the rest.


*/

	
		//Browser sensing
		///////////////////////////////////////////////
		var isLayers = 0; var isDHTML  = 0 ; var isALL   = 0 ; var isID = 0;
		var isIE = 0; var isNS = 0; var isOtherBrowser = 0;
		if ( navigator.appName.indexOf( 'Netscape' ) != -1 )
		{ isNS = 1; }
		else
		{
			if ( navigator.appName.indexOf( 'Microsoft Internet Explorer' ) != -1 )
			{ isIE = 1 ; }
			else { isOtherBrowser = 1 ; }
		}


		//Version sensing
		///////////////////////////////////////////////
		var browserVersion = 0;
		browserVersion = parseInt( navigator.appVersion ) ;



		// Feature sensing, getElementById is W3C only.
		///////////////////////////////////////////////
		if ( document.getElementById )
		{
			// sets global variables so that they can be accessed by subsequent calls to function findDOM()
			// here indicating that the browser supports the W3C DOM
			isID    = 1 ;
			isDHTML = 1 ;
		}
		else
		{
			if ( document.all )
			{
				// here indicating that the browser supports the IE ALL DOM
				isALL   = 1 ;
				isDHTML = 1 ;
			}
			else
			{
				// here indicating that the browser supports the NN4 DOM
				if ( isNS && browserVersion == 4 )
				{
					isLayers = 1 ;
					isDHTML  = 1 ;
				}

			}

		}


		//O/S sensing
		//////////////////////////////////////////////////////////////
		var isMac = 0; var isWin = 0; var isOtherO_S = 0;
		if ( navigator.appVersion.indexOf( 'Mac' ) != -1 )
		{ isMac = 1; }
		else
		{
			if ( navigator.appVersion.indexOf( 'Win' ) != -1 )
			{ isWin = 1 ; }
			else { isOtherO_S = 1 ; }
		}
		
		
function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

//It's called like this:

//var x = new getObj('layername');

		
		
function changeStyle( objectID, styleName, newVal )
{

	sMethod = "changeStyle()" ;
	
	var numArgsExpected = 3 ; 
	
 	try
 	{
 	
 		if ( changeStyle.length < numArgsExpected ) throw 1 ;	
 		
 		//var dom = findDOM( objectID, 0 ) ;
 		var dom = new getObj(objectID);
 		dom.style.backgroundImage = newVal ;
 

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR" );
				break ;
		}
	}
}


function findDOM( objectID, withStyle )
{
	// accepts two parameters, the object and the properties required to access( withStyle = 1 or 0 )
	// the reason for this is that NS4 layers DOM doesn't support the styles sub-class like the others do
	// this function supports NN4 nested layers which require recursion to drill down into the nesting
	// and access the objects. 

	// the name of the object needs to be saved first because the getElementById() function
	// seems to assign null to it if not found, preventing it from being used in the error mesage
	// the object needs to be assigned to a variable so it can be tested for existence and an 
	// exception thrown if neccessary
	
	sMethod = "findDOM()" ;
	
	var domObj, sObjId = objectID, sMsg = "", d= document ; 
	var numArgsExpected = 2 ;
	
 	try
 	{
 		if ( findDOM.length < numArgsExpected ) throw 1 ;	
		if ( isID ) 
		{ 
			domObj = d.getElementById( objectID ) ;
		}
		else 
		{ 
			if ( isALL ) 
			{  
				domObj = d.all[ objectId ] ; 
			} 
			else 
			{ 	
				if ( isLayers ) 
				{ 
					domObj = d.layers[ objectId ] ; 
				}  
			} 
		}

		// if the object is found then return it
		// if it is W3C or IE ALL and the style attribute was required then return its style
		// if the style attribute was NOT required OR it is an NN4 object then just return the object
		if ( domObj )
		{
			if ( withStyle == 1 && ! isLayers )
			{
				return  domObj.style ; 
			}
			else
			{  
				return( domObj ) ;
			}
		}
		else
		{ 
			// just return null, don't display an error message cos it would make more 
			// sense for it to be labelled with the calling method than with this one
			return null ; 
		}
	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS to findDOM()" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR in findDOM()" );
				break ;
		}
	}
}




function findLivePageHeight( args ) 
{ 
	var sMethod = "findLivePageHeight()" ;
	var numArgsExpected = 0 ;	
		
	// enclose all code in a try block, so exceptions can be caught and dealt with
	try
	{
		// check that the correct number of arguments, in this case one, have been passed
		// comment out if function takes no arguments
		if ( findLivePageHeight.arguments.length < numArgsExpected ) throw 1 ;
	

		if ( window.innerHeight != null ) { return window.innerHeight } ;
		
		if ( document.body.clientHeight != null ) { return document.body.clientHeight } ;
		
		return null ;

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR" );
				break ;
		}
	}
}

function findLivePageWidth( args ) 
{ 
	var sMethod = "findLivePageWidth()" ;
	var numArgsExpected = 0 ;	
		
	// enclose all code in a try block, so exceptions can be caught and dealt with
	try
	{
		// check that the correct number of arguments, in this case one, have been passed
		// comment out if function takes no arguments
		if ( findLivePageWidth.arguments.length < numArgsExpected ) throw 1 ;
	

		if ( window.innerWidth != null ) { return window.innerWidth } ;
		
		if ( document.body.clientWidth != null ) { return document.body.clientWidth } ;
		
		return null ;

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR" );
				break ;
		}
	}
}



function findScrollLeft( args ) 
{ 
	var sMethod = "findScrollLeft()" ;
	var numArgsExpected = 0 ;	
		
	// enclose all code in a try block, so exceptions can be caught and dealt with
	try
	{
		// check that the correct number of arguments, in this case one, have been passed
		// comment out if function takes no arguments
		if ( findScrollLeft.arguments.length < numArgsExpected ) throw 1 ;

		if ( window.pageXOffset != null ) { return window.pageXOffset } ;
		
		if ( document.body.scrollLeft != null ) { return document.body.scrollLeft } ;
		
		return null ;

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR" );
				break ;
		}
	}
}


function findScrollTop( args ) 
{ 
	var sMethod = "findScrollTop()" ;
	var numArgsExpected = 0 ;	
		
	// enclose all code in a try block, so exceptions can be caught and dealt with
	try
	{
		// check that the correct number of arguments, in this case one, have been passed
		// comment out if function takes no arguments
		if ( findScrollTop.arguments.length < numArgsExpected ) throw 1 ;

		if ( window.pageYOffset != null ) { return window.pageYOffset } ;
		
		if ( document.body.scrollTop != null ) { return document.body.scrollTop } ;
		
		return null ;

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR" );
				break ;
		}
	}
}


function scrollMainFrameToTop( args ) 
{ 
	var sMethod = "scrollMainFrameToTop()" ;
	var numArgsExpected = 1 ;	
		
	// enclose all code in a try block, so exceptions can be caught and dealt with
	try
	{
		// check that the correct number of arguments, in this case one, have been passed
		// comment out if function takes no arguments
		if ( scrollMainFrameToTop.arguments.length < numArgsExpected ) throw 1 ;

		if ( window.pageYOffset != null ) { top.window.pageYOffset = args[1] ; return top.window.pageYOffset ; } 
		
		if ( document.body.scrollTop != null ) { top.document.body.scrollTop = args[1] ; return top.document.body.scrollTop ; } 
		
		return null ;

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR" );
				break ;
		}
	}
}


function findLeft( objId ) 
{ 
	var sMethod = "findLeft()" ;
	var numArgsExpected = 1 ;	
		
	// enclose all code in a try block, so exceptions can be caught and dealt with
	try
	{
		// check that the correct number of arguments, in this case one, have been passed
		// comment out if function takes no arguments
		if ( findLeft.arguments.length < numArgsExpected ) throw 1 ;

		var domStyle 	= findDOM( objId, 1 );
		var dom		= findDOM( objId, 0 );
		
		if ( domStyle.left) return domStyle.left;

		if ( domStyle.pixelLeft) return domStyle.pixelLeft;
			
		if ( dom.offsetLeft) return dom.offsetLeft;	
		
		alert(domStyle.pixelLeft);
		
			
		return null ;

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS to findLeft()" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR in findLeft()" );
				break ;
		}
	}
}




function findTop( objId ) 
{ 
	var sMethod = "findTop()" ;
	var numArgsExpected = 1 ;	
		
	// enclose all code in a try block, so exceptions can be caught and dealt with
	try
	{
		// check that the correct number of arguments, in this case one, have been passed
		// comment out if function takes no arguments
		if ( findTop.arguments.length < numArgsExpected ) throw 1 ;

		var domStyle 	= findDOM( objId, 1 );
		var dom		= findDOM( objId, 0 );
		
		if ( domStyle.top) return domStyle.top;

		if ( domStyle.pixelTop) return domStyle.pixelTop;
			
		if ( dom.offsetTop) return dom.offsetTop;			
			
		return null ;

	}
	catch ( error )
	{    
		switch ( error )
		{
			case 1:
				alert( "INVALID_ARGUMENTS to findTop" ) ;
				break;


			default:
				alert(  "UNKNOWN_ERROR in findTop" );
				break ;
		}
	}
}

























