// Added by Michael Summers, 05/06/2009; edited by Oliver Pereira, 08/06/2009
// This function is to prefill the other info textbox with specific text supplied
// to this function.
// The function will only run if the PREFILL variable has been set in the product
// section template.
var PREFILL = '';

function setPreFillOtherText(text) {
	PREFILL = text;
}

// This could be inserted into specific sections or products if necessary. In this instance,
// we'll set it globally.
setPreFillOtherText("'s Room");


function checkForSetPreFillOtherText(id) {
	if (PREFILL != '') {
		var d = document.getElementById(id);
		if (d != null) {
			var childElements = d.childNodes;
			if (childElements != null) {
				for (var i = 0, maxI = childElements.length; i < maxI; i++) {
					var childElement = childElements[i];
					if (childElement.type == 'text') {
						childElement.value = PREFILL;
					}
				}
/*
				var tbh = d.innerHTML;
				tbh = tbh.replace(/VALUE=""/i, '');
				tbh = tbh.replace(/<INPUT/i, '<INPUT VALUE="' + PREFILL + '"');
				d.innerHTML = tbh;
*/
			}
		}
	}
}

// ---------------------------------------------------------------------------

// Note by Oliver Pereira, Wed 18 Jun 2008:
// The function getWindowDimensions() is based on the function alertSize(),
// which I found on the following Web page:
// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
// "JavaScript tutorial - Window size and scrolling"
function getWindowDimensions() {
	var myWidth = 0, myHeight = 0;
	if (typeof(window.innerWidth) == 'number') {
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		browser = 'Non-IE';
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		browser = 'IE 6+ in \'standards compliant mode\'';
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		browser = 'IE 4 compatible';
	}
	return [myWidth, myHeight, browser];
}

function resizeScrollingContentWindow() {
	var windowDimensions = getWindowDimensions();
	var windowWidth = windowDimensions[0];
	var windowHeight = windowDimensions[1];
	var browser = windowDimensions[2];
	//alert('Window width is: ' + windowWidth + 'px\nWindow height is: '+ windowHeight+ 'px\nBrowser is: ' + browser);
	var newScrollingContentWindowHeight;
	// If there is a horizontal scroll bar, Internet Explorer seems to exclude its height
	// from the window height, whereas Firefox doesn't. So, we want to work out whether
	// or not there is a horizontal scroll bar, and, if there is, whether or not we are
	// using Firefox.
	// N.B. - The number "802", below, refers to the width of the used area of the page.
	// I.e. the content, at 800 pixels wide, plus a 1-pixel border on each side.
	if (windowWidth >= 802 || browser != 'Non-IE') {
		newScrollingContentWindowHeight = Math.max(0, windowHeight - 178);
	} else {
		newScrollingContentWindowHeight = Math.max(0, windowHeight - 195);
	}
	//alert('newScrollingContentWindowHeight is: ' + newScrollingContentWindowHeight + 'px');
	document.getElementById('scrollingContentWindow').style.height = newScrollingContentWindowHeight + 'px';
}

window.onload=resizeScrollingContentWindow;
window.onresize=resizeScrollingContentWindow;
