var JsDiv =
{	
	getRefToDiv : function(divID,oDoc) {
		if( document.getElementById ) {
			return document.getElementById(divID); 
		}
		
		if( document.all ) {
			return document.all[divID];
		}
	
		if( !oDoc ) { 
			oDoc = document; 
		}
		
		if( document.layers ) {
			if( oDoc.layers[divID] ) {
				return oDoc.layers[divID]; 
			} else {
				//repeatedly run through all child layers
				for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
					//on success, return that layer, else return nothing
					y = getRefToDiv(divID,oDoc.layers[x].document); 
				}
				return y; 
			} 
		}
		
		return false;
	},
	
	show : function(divID_as_a_string, value) {
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		//now we have a reference to it
		if( myReference.style ) {
			//DOM & proprietary DOM
			myReference.style.visibility = 'visible';
		} else {
			//layers syntax
			myReference.visibility = 'show';
		}
	},

	move : function(divID_as_a_string, x, y) {
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		var noPx = document.childNodes ? 'px' : 0;
		if( myReference.style ) { 
			myReference = myReference.style; 
		}
		myReference.left = x + noPx;
		myReference.top = y + noPx;
	},
	
	bgcolor : function(divID_as_a_string, x, y) {
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		if( myReference.style ) { 
			myReference = myReference.style; 
		}
		if( myReference.background ) {
			//supported by most browsers
			//like Gecko browsers and the IE series
			myReference.background = '#00ff00';
		} else if( myReference.backgroundColor ) {
			//supported by most browsers
			myReference.backgroundColor = '#00ff00';
		} else if( myReference.bgColor ) {
			//used by layers browsers
			myReference.bgColor = '#00ff00';
		} else {
			//FAILURE, there is no way to change the background colour
		}
	},
	
	zIndex : function(divID_as_a_string, z) {
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		if( myReference.style ) { 
			myReference = myReference.style; 
		}
		myReference.zIndex = z;
	},
	
	clip : function(divID_as_a_string, x1, y1, x2, y2) {
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		if( myReference.style ) { 
			myReference = myReference.style; 
		}
		if( myReference.clip ) {
			myReference.clip.left = x1;
			myReference.clip.top = y1;
			myReference.clip.right = x2;
			myReference.clip.bottom = y2;
		} else if( myReference.style ) {
			//top right bottom left
			myReference.style.clip = 'rect('+x1+'px,'+y1+'px,'+x2+'px,'+y2+'px)';
		} else {
			//FAILURE, nothing works
		}
	},
	
	resize : function(divID_as_a_string, newWidth, newHeight) {
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		if( myReference.style ) { 
			myReference = myReference.style; 
		}	
	
		if( myReference.resizeTo ) {
			myReference.resizeTo( newWidth, newHeight );
		} else {
			var noPx = document.childNodes ? 'px' : 0;
			myReference.width = newWidth + noPx;
			myReference.pixelWidth = newWidth;
			myReference.height = newHeight + noPx;
			myReference.pixelHeight = newHeight;
		}
	},

	addStr : function(divID_as_a_string, str, nameOfIframe) {
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		if( myReference.style ) { 
			myReference = myReference.style; 
		}
	
		if( typeof( myReference.innerHTML ) != 'undefined' ) {
			//used by all current browsers
			myReference.innerHTML = str;
		} else if( myReference.document && myReference.document != window.document ) {
			//used by layers browsers
			myReference.document.open();
			myReference.document.write(str);
			myReference.document.close();
		} else if( window.frames && window.frames.length && window.frames[nameOfIframe] ) {
			//used by browsers like Opera 6-
			myReference = window.frames[nameOfIframe].window;
			myReference.document.open();
			myReference.document.write(str);
			myReference.document.close();
		}
	},
	
	popup : function(divID_as_a_string, str)
	{
		//get a reference as above ...
		myReference = JsDiv.getRefToDiv(divID_as_a_string);
		if( !myReference ) {
			window.alert('Nothing works in this browser');
			return; //don't go any further
		}
		if( myReference.style ) { 
			myReference = myReference.style; 
		}
			
		if( document.layers && window.Layer && document.classes ) {
			//create a layer 350px wide
			document.layers['newName'] = new Layer( 350, myReference );
			//write its content
			document.layers['newName'].document.open();
			document.layers['newName'].document.write(str);
			document.layers['newName'].document.close();
			//style it
			document.layers['newName'].left = 0;
			document.layers['newName'].top = 0;
			document.layers['newName'].visibility = 'show';
		} else {
			var theString = '<div style="position:absolute;left:0px;top:0px;' +
				'width:350px;">'+str+'</div>';
			if( myReference.insertAdjacentHTML ) {
				myReference.insertAdjacentHTML( 'beforeEnd', theString );
			} else if( typeof( myReference.innerHTML ) != 'undefined' ) {
				myReference.innerHTML += theString;
			} else {
				//FAILURE, nothing works
			}
		}
	},
		
	MWJ_findObj : function ( oName, oFrame, oDoc ) {
	  /* if not working on a layer, document should be set to the
	  document of the working frame
	  if the working frame is not set, use the window object
	  of the current document
	  WARNING: - cross frame scripting will cause errors if
	  your page is in a frameset from a different domain */
	  if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	
	  //check for images, forms, layers
	  if( oDoc[oName] ) { return oDoc[oName]; }
	
	  //check for pDOM layers
	  if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	
	  //check for DOM layers
	  if( oDoc.getElementById && oDoc.getElementById(oName) ) {
		return oDoc.getElementById(oName); }
	
	  //check for form elements
	  for( var x = 0; x < oDoc.forms.length; x++ ) {
		if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	
	  //check for anchor elements
	  //NOTE: only anchor properties will be available,
	  //NOT link properties (in layers browsers)
	  for( var x = 0; x < oDoc.anchors.length; x++ ) {
		if( oDoc.anchors[x].name == oName ) {
		  return oDoc.anchors[x]; } }
	
	  //check for any of the above within a layer in layers browsers
	  for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = JsDiv.MWJ_findObj( oName, null, oDoc.layers[x].document );
		  if( theOb ) { return theOb; } }
	
	  //check for frames, variables or functions
	  if( !oFrame && window[oName] ) { return window[oName]; }
	  if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	
	  //if checking through frames, check for any of the above within
	  //each child frame
	  for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = JsDiv.MWJ_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	
	  return null;
	}	
};






