/* Browser Detection Script begins here. */
var theDOM1 = (document.getElementById) ? true : false;

/* theApp will contain the browser name */
var theApp = navigator.appName.toLowerCase();

/* UA (user agent) contains detailed browser info. For example,
UA for Internet Explorer on Mac would be 'mozilla/4.0 (compatible;
msie 5.0; mac_powerpc)' */
var UA = navigator.userAgent.toLowerCase();

/* variables for the two major browsers in existence today. */
var isIE = (UA.indexOf('msie') >= 0) ? true : false;
var isNS = (UA.indexOf('mozilla') >= 0) ? true : false;

/* 'compatible' text string is only in non-Netscape browsers */
if (UA.indexOf('compatible')>0){
	isNS = false;
}

/* platform */
var thePlatform = navigator.platform.toLowerCase();
var isMAC = (UA.indexOf('mac') >= 0) ? true : false;
var isWIN = (UA.indexOf('win') >= 0) ? true : false;

/* Most UNIX users use X-Windows so this detects UNIX most of
the time.*/
var isUNIX = (UA.indexOf('x11') >= 0) ? true : false;

/* browser version */
var version = navigator.appVersion;
var isMajor = parseInt( version );

/* Internet Explorer version 5 on the Mac reports itself as version
4. This code corrects the problem. */
if(isIE && isMAC) {
	if(UA.indexOf("msie 5")) {
		isMajor = 5;
		var stringLoc = UA.indexOf("msie 5");
		version = UA.substring(stringLoc + 5, stringLoc + 8);
	}
}

/* Internet Explorer version 6 on Windows reports itself as version
4. This code corrects the problem. */
if(isIE && isWIN) {
	if(UA.indexOf("msie 6")) {
		isMajor = 6;
		var stringLoc = UA.indexOf("msie 6");
		version = UA.substring(stringLoc + 5, stringLoc + 8);
	}
	if(UA.indexOf("msie 5.5")) {
		isMajor = 5;
		var stringLoc = UA.indexOf("msie 5.5");
		version = UA.substring(stringLoc + 5, stringLoc + 8);
	}
}

/* Netscape 6 reports itself as version 5 on all platforms.
This code corrects the problem. */
if(isNS && isMajor>4) {
	if(UA.indexOf("netscape6")) {
		isMajor = 6;
		var stringLoc = UA.indexOf("netscape6");
		version = UA.substring(stringLoc + 10, stringLoc + 14);
	}
}
var isMinor = parseFloat( version );

/* a function to report browser info */
function getBrowserInfo(){
	var temp="<p>";
	temp += "User Agent: " + UA + "<br>";
	temp += "Platform: " + thePlatform + "<br>";
	temp += "Macintosh: " + isMAC + "<br>";
	temp += "Windows: " + isWIN + "<br>";
	temp += "Application: " + theApp + "<br>";
	temp += "Version: " + version + "<br>";
	temp += "Netscape: " + isNS + "<br>";
	temp += "Internet Explorer: " + isIE + "<br>";
	temp += "Major Version: " + isMajor + "<br>";
	temp += "Full Version: " + isMinor + "<br>";
	temp += "<br>";
	if (theDOM1){
		temp += "You appear to have a modern browser.<br>";
		temp += "Netscape 6, IE 6, or IE5Mac are recommended.";
	}else{
		temp += "Alert! Your browser is obsolete.<br>";
		temp += "You may enjoy the Web more if you upgrade.";
	}
	temp +="<\/p>";
	return temp;
}
/* End of browser detection code */


/* Convert object name string or object reference
into a valid object reference */
function getObj(elementID){
	if (typeof elementID == "string") {
		return document.getElementById(elementID);
	}else{
		return elementID;
	}
}

/* Object Motion and Position Scripts */
/*This function places a positionable object (obj) in
three dimensions (x,y, and z).*/
function shiftTo(obj,x,y,z){
	var newObj = getObj(obj);
	newObj.style.left = x + "px";
	newObj.style.top = y + "px";
	newObj.style.zIndex = z;
}

/*This function gets the x coordinate of a positionable
object.*/
function getObjX(obj){
	return parseInt(getObj(obj).style.left);
}

/*This function gets the y coordinate of a positionable
object.*/
function getObjY(obj){
	return parseInt(getObj(obj).style.top);
}

/*This function gets the z-index of a positionable
object.*/
function getObjZ(obj){
	return parseInt(getObj(obj).style.zIndex);
}

/*The emptyNode() function loops through the array of
child nodes and removes each one.*/
function emptyNode(elementID){
	var theNode = getObj(elementID);
	for (i=0;i<theNode.childNodes.length;i++){
		theNode.removeChild(theNode.childNodes[i]);
	}
}


/*This function gets the available width of the window.*/
function getAvailableWidth(){
	var theWidth=null;
	/*Netscape uses window.innerWidth */
	if (window.innerWidth) {
		theWidth = window.innerWidth;
	}
	/*IE uses document.body.clientWidth */
	if (document.body.clientWidth) {
		theWidth = document.body.clientWidth;
	}
	return theWidth;
}

/*This function gets the available height of the window.
IE6.0 on Windows has a bug and returns null.*/
function getAvailableHeight(){
	var theHeight = null;
	/*Netscape uses window.innerHeight */
	if (window.innerHeight) {
		theHeight = window.innerHeight;
	}
	/*IE uses document.body.clientHeight */
	if (document.body.clientHeight) {
		theHeight = document.body.clientHeight;
	}
	return theHeight;
}

/*This function sets the total height and width of the
window.*/
function setWindowSize(w,h){
	window.resizeTo(w,h);
}

/*This function sets the size of the window to cover all
of the screen.*/
function maximizeWindow(){
	window.moveTo(0,0);
	window.resizeTo(screen.availWidth,screen.availHeight);
}



/* Redirects visitors who are using outdated browsers.*/
function checkDOM(newlocation){
	if (!theDOM1){
		window.location.replace(newlocation);
	}
}

/* This function changes the cursor.
The second argument is optional. */
function setCursor(cursortype,thisobj){
if (UA.indexOf("msie 5")>=0){
	if (cursortype == 'pointer') { cursortype='hand'; }
	}
	if (thisobj==null){
		document.body.style.cursor = cursortype;
	}else{
		getObj(thisobj).style.cursor = cursortype;
	}
}

/*Set the background color of an object*/
function setBackground(thisobj, color){
	getObj(thisobj).style.background = color;
}

/*Set the text color of an object*/
function setColor(thisobj, color){
	getObj(thisobj).style.color = color;
}

/*Setting the visibility of an object*/
function setVisibility(obj,vis){
	var theObj = getObj(obj);
	if (vis == true || vis=='visible' || vis=='y'){
		theObj.style.visibility = "visible";
	}else{
		theObj.style.visibility = "hidden";
	}
}

/*Getting the visibility of an object*/
function isVisible(obj) {
	var theObj = getObj(obj);
	return theObj.style.visibility;
}

/*Setting the display of an object*/
function setDisplay(obj,dis){
	var theObj = getObj(obj);
	if (dis==true || dis=='block' || dis=='y'){
		theObj.style.display = "block";
	}else{
		if (dis==false || dis=='n'){
			theObj.style.display = "none";
		}else{
			theObj.style.display = dis;
		}
	}
}

/*Getting the display of an object*/
function isDisplayed(obj) {
	var theObj = getObj(obj);
	return theObj.style.display;
}

/*Set the clip region of an object*/
function setClip(obj,top,right,bottom,left){
	var theObj = getObj(obj);
	var r = 'rect('+top+'px,'+right+'px,'+bottom+'px,'+left+'px)';
	theObj.style.clip = r;
}
