
var browser;
var windowWidth;
var windowHeight;

function getBrowserInfo() {
	var browserIdentString, i;

	this.userAgent = navigator.userAgent;	
	this.Opera	= false;
	this.Safari	= false;
	this.IE		= false;
	this.Mozilla	= false;

	// Check for Opera first, as it typically impersonates other browsers,
	// such as MSIE, even though it's not really compatible
	if ((i = this.userAgent.indexOf("Opera")) >= 0) {
		this.Opera = true;
		return;
	}

	if ((i = this.userAgent.indexOf("Safari")) >= 0) {
		this.Safari = true;
		return;
	}

	if ((i = this.userAgent.indexOf("MSIE")) >= 0) {
		this.IE = true;
		return;
	}

	// Check for generic 'Mozilla' browsers last. Not all will work,
	// (there are too many to test) but the majority will be just fine.
	if ((i = this.userAgent.indexOf("Mozilla")) >= 0) {
		this.Mozilla = true;
		return;
	}

	// If we end up here, then the user is out of luck, and we need
	// to let them know the web app almost certainly won't work.
	// We should really give them the option to say what browser they are
	// using. but for now I'm just going to assume it's a re-branded IE,
	// as that's the most likely (statistically).
	this.IE = true;
	return false;
	
}

function initialize() {
        browser = new getBrowserInfo();
}

function checkRadioBox(elementId) {
	document.getElementById(elementId).checked = true;
}

function updateSize() {
        browser = new getBrowserInfo();
       if (browser.IE) {
                windowWidth = document.body.offsetWidth;
                windowHeight = document.body.offsetHeight;
        } else {
                windowWidth = window.innerWidth;
                windowHeight = window.innerHeight;
        }
}

function resize() {
        resizeEditBox();
        resizeIframe();
}

function resizeEditBox() {
	// Main edit textarea elment - this makes it use the maximum height,
	// availible something you can't do in CSS on most browsers.
        updateSize();
        if (document.getElementById('editBox')) {
                document.getElementById('editBox').style.height = windowHeight - 230;
        }
}

function resizeIframe(elementId) {
	// Allows generic iframes (e.g. forum sites) to be embedded as max
	// height/width pages semlessly, with some supporting onLoad()
	// javascript. It is not possible to do this using straight CSS.
        browser = new getBrowserInfo();
        updateSize();
        if (document.getElementById(elementId)) {
                document.getElementById(elementId).style.position = 'absolute';
                document.getElementById(elementId).style.top = 0;
                document.getElementById(elementId).style.left = 170;
		// Slightly different alignment values needed on IE than on
		// Safari and Firefox, mostly to account for scroll bars
                if (browser.IE) {
                        document.getElementById(elementId).style.width = windowWidth - 210;
			document.getElementById(elementId).style.height = windowHeight - 95;
                } else {
                        document.getElementById(elementId).style.width = windowWidth - 180;
			document.getElementById(elementId).style.height = windowHeight - 85;
                }
        }
}
