/*
 General site functions for jwb.com.au
 Including 'Stamp' menu setup
 
 Authors: Rod Pettit, Rod@Webtrix.com.au
 		  Graham Casidy, graham@webtrix.com.au
 Modified: 02/04/2005

*/


// ********************* General DHTML utility functions *******************************
var NS4DOM = (document.layers) ? true:false;
var IEDOM = (document.all) ? true:false;
var W3CDOM = (document.getElementById) ? true:false;

function getObject(id) {
   if (NS4DOM) ref="document."+id;
   else if (IEDOM) ref=id;
   else if (W3CDOM) ref="document.getElementById('"+id+"')";
   var object=eval(ref);
   return object;
}

function placeIt(id, x, y) {
   var object=getObject(id);
   if (NS4DOM) object.moveTo(x, y)
   else if (IEDOM || W3CDOM) {
      object.style.left=x+"px";
      object.style.top=y+"px";
   } 
}

function moveIt(id, dx, dy) {
   var object=getObject(id);
   if (NS4DOM) object.moveBy(dx, dy);
   else if (IEDOM) {
      object.style.pixelLeft=object.style.pixelLeft+dx;
      object.style.pixelTop=object.style.pixelTop+dy;
   } 
   else if (W3CDOM) {
      newleft=parseInt(object.style.left)+dx;
      newtop=parseInt(object.style.top)+dy;
      object.style.left=newleft+"px";
      object.style.top=newtop+"px";
   }
}

function getYCoord(id) {
   object=getObject(id);
   if (NS4DOM) return object.top;
   else if (IEDOM || W3CDOM) return parseInt(object.style.top);
}

function getXCoord(id ) {
   object=getObject(id);
   if (NS4DOM) return object.left;
   else if (IEDOM || W3CDOM) return parseInt(object.style.left);
}

//**************** Centering of pages ********************
// Allows for older browser that don't support div & css well

new_method = checkBrowser(0);
new_method = false;

function startCentre(level) {
	
	if	(new_method) {
		switch (level) {
			case 1: 	
				startText = "<div id='horizon'><div id='content' style='background-image:url(images/index/background.gif); background-repeat:no-repeat; background-color: #AA0000'>";
				break;
			default:
				startText = "<div class='horizon'><div class='center'>";
		}
}
	else {
		startText = "<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td align='center'>";
		switch (level) {
			case 1: 	
				startText += "<table width='750' height='100%' border='0' cellpadding='0' cellspacing='0' background='images/index/background.gif' bgcolor='#AA0000'><tr height='500'><td>";
				break;
			case 2: 	
				startText += "<table width='750' height='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'><tr height='500'><td>";
				break;
			default:
				startText += "<table width='750' height='100%' border='0' cellpadding='0' cellspacing='0''><tr height='500'><td>";
		}
				startText += "<div class='block'>";
	}
	document.write(startText);
}

function endCentre() {
	
	if	(new_method) {
		endText = "</div></div>";
	}
	else {	
		endText = "</div>";
		endText += "</td></tr></table></td></tr></table>";
	}
	document.write(endText);
}


//**************** Check browser version  ********************
function checkBrowser(popup) {
	agent = navigator.userAgent.toLowerCase();
	is_ie = ((agent.indexOf("msie") != -1) && (agent.indexOf("windows") != -1));
	is_ns = (agent.indexOf("netscape") != -1);
	is_gecko  = (navigator.product == "Gecko");
	ver = "";
	if (is_ie) {
		i = agent.indexOf("msie")+5;
		ver = agent.substr(i,3);
		if ( ver < "5.0")
			is_ie = false;
		}
	if (is_ns) {
		i = agent.indexOf("netscape/");
		if (i == -1)
			i = agent.indexOf("netscape")+8;
		else
			i +=9;
		ver = agent.substr(i,3);
		}
	if (is_gecko && navigator.productSub < 20030210)
		is_gecko = false;
	supported = is_ie || is_gecko;
	text1 = "A check of your Internet Browser shows...\n\n";

if (supported)
		text1 += "This Browser is supported.\n\n";
	else {
		text1 += "** SORRY - This Browser is NOT supported **\n";
		text1 += "Please use either MS Internet Explorer V5.0 or better for Windows\n";
		text1 += "or Mozilla V1.3 or better on any Platform.\n\n";
	}

	text1 += "Browser = " + navigator.appName + " " + ver +"\n";
	text1 += "Code = " + navigator.appCodeName + ", Version = " + navigator.appVersion.substring(0,4) + "\n";
	text1 += "Platform = " + navigator.platform + "\n\n";
	text1 += "Details: " + navigator.userAgent + "\n";
	if (popup) // Popup ?
		alert(text1);
	return supported;
}

//**************** Code for displaying a popup if a Javascript error occurs  ********************

function browserInfo() {
	this.code = 'unknown';
	this.version = 0;
	this.platform = 'Win';
	var ua = navigator.userAgent;
	var i = ua.indexOf('WebTV');
	if (i >= 0) {
		this.code = 'WebTV';
		i += 6;
	} else {
		i = ua.indexOf('MSIE');
		if (i >= 0) {
			this.code = 'MSIE';
			i += 5;
		} else {
			i = ua.indexOf('Opera');
			if (i >= 0) {
				this.code = 'OP';
				i = ua.indexOf(') ') + 2;
			} else {
				i = ua.indexOf('Mozilla/');
				if (i >= 0) {
					this.code = 'NS';
					i += 8;
				}
			}
		}
	}
	this.version = parseFloat(ua.substring(i, i+4));
	if (ua.indexOf('Mac') >= 0) {this.platform = 'Mac';}
	if (ua.indexOf('OS/2') >= 0) {this.platform = 'OS/2';}
	if (ua.indexOf('X11') >= 0) {this.platform = 'UNIX';}
	var v = this.version;
	var p = this.platform;
	var NS = (this.code == 'NS');
	var IE = (this.code == 'MSIE');
	var WTV = (this.code == 'WebTV');
	var OP = (this.code == 'OP');
	var OP32up = (OP && (v >= 3.2));
	var IE4up = (IE && (v >= 4));
	var NS3up = (NS && (v >= 3));
	this.canCache = NS3up || IE4up || OP32up || WTV;
	this.canOnMouseOut = this.canCache;
	this.canOnError = NS3up || IE4up || OP32up;
	this.canJSVoid = !((NS && !NS3up) || (IE && !IE4up) || (OP && (v < 3.5)));
	this.lineByLine = (v < 4);
	this.mustMoveAfterLoad = NS3up || (IE4up && (p != 'Mac')) || WTV;
	if (NS3up || IE4up || WTV) {
		this.reloadMethod = 'replace';
	} else {
		this.reloadMethod =  (NS && (v == 2.01) && (p != 'Win')) ? 'timeout' : 'href';
	}
	this.canFloat = NS || (IE && !((p == 'Mac') && (v >= 4) && (v < 5)));
	this.hasDHTML = ((NS || IE) && (v >= 4)) && !(IE && (p == 'Mac') && (v < 4.5));
	this.needLM = NS || (IE && (p == 'Mac') && (v >= 4.5));
	this.DHTMLRange = IE ? '.all' : '';
    this.DHTMLStyleObj = IE ? '.style' : '';
	this.DHTMLDivHeight = IE ? '.offsetHeight' : '.clip.height';
}

function defOnError(msg, url, lno) {
	if (jsErrorMsg == '') {
		return false;
	} else {
		alert(jsErrorMsg + '\n\n***** ERROR INFORMATION *****\n\nError: ' + msg + '\nPage: ' + url + '\nLine: ' + lno + '\nBrowser: ' + navigator.userAgent);
		return true;
	}
}

// Declare global variables
var theBrowser = new browserInfo;

var jsErrorMsg = '***** ERROR : A JavaScript error has occurred on this page *****\nPlease note down the following information and pass it on to me.\nthanks,\nRod@Webtrix.com.au';
if (theBrowser.canOnError) {self.onerror = defOnError;}


