/*
by Sharon Paine of Dynamic Web Coding
www.dyn-web.com
*/

/*
//////////////////////////////////////////////////////////////////////
  
   myapi.js is adapted from Danny Goodman's DHTMLapi.js 

    	"DHTMLapi.js custom API for cross-platform object positioning 
	  		by Danny Goodman (http://www.dannyg.com)"

	 plus other content from Dynamic HTML The Definitive Reference
	 by Danny Goodman pp. 93-98, 115
	 plus other content of my own and gleaned from other sites
	 as my learning process continues...

//////////////////////////////////////////////////////////////////////
*/

// browser sniffer
// set global variables
// Note - need 'nodhtml.html' page for non-version 4 browsers ...
var isNav4, isIE4
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav4 = true
	} else if (navigator.appVersion.indexOf("MSIE") != -1) {
		isIE4 = true
		coll = "all."
		styleObj = ".style"
	} else {
		window.location = "nodhtml.html"
	}
} else {
	window.location = "nodhtml.html"
}


// get a valid object reference for positioning
// and other *style* property scripting tasks
// (See contentObj function below)
function getObject(obj) {
	var theObj
	if (typeof obj == "string") {
		theObj = eval("document." + coll + obj + styleObj)
	} else {
		theObj = obj
	}
	return theObj
}

// Positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
	var theObj = getObject(obj)
	if (isNav4) {
		theObj.moveTo(x,y)
	} else {
		theObj.pixelLeft = x
		theObj.pixelTop = y
	}
}

// Moving an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
	var theObj = getObject(obj)
	if (isNav4) {
		theObj.moveBy(deltaX, deltaY)
	} else {
		theObj.pixelLeft += deltaX
		theObj.pixelTop += deltaY
	}
}

// Setting the z-order of an object
function setZIndex(obj, zOrder) {
	var theObj = getObject(obj)
	theObj.zIndex = zOrder
}

// Setting the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj)
	if (isNav4) {
		theObj.bgColor = color
	} else {
		theObj.backgroundColor = color
	}
}

// Setting the visibility of an object to visible
function show(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "visible"
}

// Setting the visibility of an object to hidden
function hide(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "hidden"
}

// Retrieving the x coordinate of a positionable object
// within its positioning context
function getObjectLeft(obj)  {
	var theObj = getObject(obj)
	if (isNav4) {
		return theObj.left
	} else {
		return theObj.pixelLeft
	}
}

// Retrieving the y coordinate of a positionable object
// within its positioning context
function getObjectTop(obj)  {
	var theObj = getObject(obj)
	if (isNav4) {
		return theObj.top
	} else {
		return theObj.pixelTop
	}
}

// see js bib p. 658
function showProps(o, objName) {
	var result = ""
	count = 0
	for (var i in o) {
		result += o + "." + i + "=" + o[i] + "\n"
		count++
		if (count == 25) {
			alert(result)
			result = ""
			count = 0
		}
	}
	alert(result)
}

///////////////////// The End of DHTMLapi.js /////////////////////

// special handling for resizing in Netscape
// CCS-P positioning bug workaround
// see pp. 93 and 95, 115 of Dynamic HTML The Definitive Reference
function handleResize() {
location.reload()
return false
}
if (isNav4) {
window.captureEvents(Event.RESIZE)
window.onresize = handleResize
}

// compare to getObject function at top
// This one gets object reference for element content
// Not for style properties (for IE DOM)
function contentObj(obj) {
	var contObj
	if (typeof obj == "string") {
		contObj = eval("document." + coll + obj)
	} else {
		contObj = obj
	}
	return contObj
}

// returns rendered height of object content in pixels
function getObjHeight(obj) {
	var contObj = contentObj(obj)
	if (isNav4) {
		return contObj.clip.height
	} else {
		return contObj.clientHeight
	}
}

// returns rendered width of object content in pixels
function getObjWidth(obj) {
	var contObj = contentObj(obj)
	if (isNav4) {
		return contObj.clip.width
	} else {
		return contObj.clientWidth
	}
}

// returns available content width space in browser window
function getInsideWindowWidth() {
		if (isNav4) {
		return window.innerWidth
	} else {
		return document.body.clientWidth
	}
}

// returns available content height space in browser window
function getInsideWindowHeight() {
	if (isNav4) {
		return window.innerHeight
	} else {
		return document.body.clientHeight
	}
}

// returns x coordinate of positionable object relative to page
function getPageLeft(obj) {
	var contObj = contentObj(obj)
	if (isNav4) {
		return contObj.pageX 
	} else {
		return contObj.offsetLeft
	}
}


// returns y coordinate of positionable object relative to page
function getPageTop(obj) {
	var contObj = contentObj(obj)
	if (isNav4) {
		return contObj.pageY 
	} else {
		return contObj.offsetTop
	}
}

// center object in window
function centerObj(obj) {
	var theObj = getObject(obj)
	var contObj = contentObj(obj)	
	var x = Math.round((getInsideWindowWidth()-getObjWidth(contObj))/2)
	var y = Math.round((getInsideWindowHeight()-getObjHeight(contObj))/2)
	shiftTo(theObj,x,y)
}

// mine start here

// write to layer
function writeLayer(obj,txt) {
	var contObj = contentObj(obj)
	if (isNav4) {
  	contObj.document.write(txt)
		contObj.document.close()
  } else {
		contObj.innerHTML = txt
	}
}


// Error Handler
// Displays form for users to submit error reports
// extensively modified adaptation of example 14-1, p 264 
// JavaScript: the Definitive Guide by David Flanagan

// so each error window created is unique
var errorCount = 0;

// email address to send error report to
var email = "contact@dyn-web.com"

function reportError(msg, url, line) {
var errWin = window.open("", "error"+errorCount++, "resizable,status,scrollbars=yes,width=600,height=450,left=30,top=20");
var errTxt = ''
errTxt += '<div align="center"><font face="arial" size="3">A JavaScript Error Has Occurred</font>'
errTxt += '<br><hr size=4 width="95%">'
errTxt +='<form action="mailto:' + email + '" Method=post'
errTxt +=' ENCTYPE="text/plain">'
errTxt +='<FONT size="2"><p>Click on the Report Error button to send this message to the Webmaster.</p>'
errTxt +='<p><input type=submit value="Report Error"> '
errTxt +='<input type=button value="Cancel" onClick="self.close()"></p></FONT></div>'
errTxt +='<FONT size="2"><div align=right><p>Error message: '
errTxt +='<INPUT TYPE="text" SIZE=42 NAME="message" VALUE="' + msg + '"></p>'
errTxt +='<p>Document: '
errTxt +='<INPUT TYPE="text" SIZE=42 NAME="url" VALUE="' + url + '"></p>'
errTxt +='<p>Line Number: '
errTxt +='<INPUT TYPE="text" SIZE=42 NAME="line" VALUE="' + line + '"></p>'
errTxt +='<p>Browser version: '
errTxt +='<INPUT TYPE="text" NAME="version" size="42" value="' + navigator.userAgent + '"></p>'
errTxt +='<p>Comments:<textarea cols="42" rows="3" wrap="virtual" name="cmnts"></textarea></p></div></font></form>'
errWin.document.write(errTxt)
errWin.document.close()

// return true so JS does not display its own error dialog
return true;
}

// register event handler for particular window
self.onerror=reportError;