// start info
if(typeof jsReport != 'undefined'){
	jsVersion = new Array(
	/*Name			=*/ 'Layout Guard',
	/*Version 		=*/ '1.5a',
	/*Date 			=*/ 20040216,
	/*Author		=*/ 'Maurice van Creij',
	/*ProjectCode	=*/ 'app_layoutguard',
	/*Summary		=*/ 'Monitor resizes and restrain an element to a maximum size.',
	/*Dependencies	=*/ new Array('app_layoutguard.js'),
	/*Browsers		=*/ new Array('MO','IE','OP'),
	/*Changes		=*/ new Array(
						'1.5: A small addition to the stylesheet will enable the script to operate in strict doctypes.',
						'1.4: Configuration is now stored in an array',
						'1.3: Added height as well as width',
						'1.2: Doesn\'t wait for onload event anymore',
						'1.1: Added a minimum width as well as the maximum width',
					  	'1.0: Basic functionality'
					  	),
	/*Usage			=*/ new Array(
							'<style>html, body {height : 100%;}</style>',
							'<script language="javascript" src="/~wmittensrdx/resources/layout_guard.js"></script>'
					  	)
	)
}else{
// end info

	// constants/configuration
		var intLayoutCorr	= (document.all && navigator.appVersion.indexOf('IE 7')<0) ? 4 : 0 ; // possible MSIE adjustment for the offsetHeight
		var arrLayoutHyst	=	new Array(
									//	new Array(strResizeId,new Array(intXmin,intXmax,intXoff),new Array(intYmin,intYmax,intYoff)),
									new Array('canvas0',	new Array(800,1024,22),	null),
									new Array('canvascol0',	null,					new Array(0,9999,0)),
									new Array('canvascol1',	null,					new Array(0,9999,0))
								);
	// functionality
		// return a parameter from the url's query strings
		function getQueryParameter(strParamName,strDefaultValue){
			// split the query string at the parameter name
			var arrQueryParameter = document.location.search.split(strParamName+"=");
			// split the parameter value from the rest of the string
			var strQueryParameter = (arrQueryParameter.length>1) ? arrQueryParameter[1].split("&")[0] : null ;
			// return the value or the default value
			return (strQueryParameter==null && strDefaultValue!=null) ? strDefaultValue : strQueryParameter;
		}
		// guess/measure the width of the document
		function getDocWidth(){
			var intMaxWidth = 9999;
			// choose the smallest value for the width
			if(document.body.scrollWidth<intMaxWidth)	intMaxWidth = document.body.scrollWidth;
			if(document.body.offsetWidth<intMaxWidth)	intMaxWidth = document.body.offsetWidth;
			if(window.innerWidth<intMaxWidth)			intMaxWidth = window.innerWidth;
			// pass the value back
			return intMaxWidth;
		}
		// guess/measure the height of the document
		function getDocHeight(){
			var intMaxHeight = 0;
			// choose the biggest value for the height
			if(document.body.scrollHeight>intMaxHeight)	intMaxHeight = document.body.scrollHeight;
			if(document.body.offsetHeight>intMaxHeight)	intMaxHeight = document.body.offsetHeight-intLayoutCorr;
			if(window.innerHeight>intMaxHeight)			intMaxHeight = window.innerHeight;
			// pass the value back
			return intMaxHeight;
		}
		// set the elements' dimensions if the window dimensions pass a treshold
		function setDimensions(){
			var strResizeId, strWidth, strHeight;
			// document dimensions
			var intWidthDoc = getDocWidth();
			var intHeightDoc = getDocHeight();
			// for all listed elements
			for(var intA=0; intA<arrLayoutHyst.length; intA++){
				if(document.getElementById(arrLayoutHyst[intA][0])!=null){
					// width limits
					if(arrLayoutHyst[intA][1]!=null){
						// pick element width by limit
						if		(intWidthDoc<arrLayoutHyst[intA][1][0]){	strWidth = (arrLayoutHyst[intA][1][0]-arrLayoutHyst[intA][1][2]) + 'px';}
						else if	(intWidthDoc>arrLayoutHyst[intA][1][1]){	strWidth = (arrLayoutHyst[intA][1][1]-arrLayoutHyst[intA][1][2]) + 'px';}
						else {												strWidth = (intWidthDoc-arrLayoutHyst[intA][1][2]) + 'px';}
						// set element width
						document.getElementById(arrLayoutHyst[intA][0]).style.width = strWidth;
					}
					// height limits
					if(arrLayoutHyst[intA][2]!=null){
						// pick element height by limit
						if (intHeightDoc<arrLayoutHyst[intA][2][0]){		strHeight = (arrLayoutHyst[intA][2][0]-arrLayoutHyst[intA][2][2]) + 'px';}
						else if (intHeightDoc>arrLayoutHyst[intA][2][1]){	strHeight = (arrLayoutHyst[intA][2][1]-arrLayoutHyst[intA][2][2]) + 'px';}
						else {												strHeight = (intHeightDoc-arrLayoutHyst[intA][2][2]) + 'px';}
						// set element height
						if(window.innerHeight){
							if(document.body.scrollHeight<=window.innerHeight){
								document.getElementById(arrLayoutHyst[intA][0]).style.height = strHeight;
							}else{
								document.getElementById(arrLayoutHyst[intA][0]).style.height = (parseInt(strHeight) + 10 ) + 'px';
							}
						}else {
							if(document.body.scrollHeight<=document.body.offsetHeight){
								document.getElementById(arrLayoutHyst[intA][0]).style.height = strHeight;
							}else{
								document.getElementById(arrLayoutHyst[intA][0]).style.height = (parseInt(strHeight) + 10 ) + 'px';
							}
						}
					}
				}
			}
		}
	// constructors
		function setColourTheme(){
			// get the theme parameter from the url
			var strTheme;
			if(document.location.href.indexOf('theme=green')>-1){
				strTheme = 'green';
			}else if(document.location.href.indexOf('theme=blue')>-1){
				strTheme = 'blue';
			}
			// is a custom colour string given?
			if(strTheme!=null){
				// the body class
				document.body.className = strTheme;
				// get all images
				var objImgs = document.body.getElementsByTagName('IMG');
				// for all images
				for(var intA=0; intA<objImgs.length; intA++){
					// check for the default colour string
					if(objImgs[intA].src.indexOf('_purple')>-1){
						// replace it with the given colour string
						objImgs[intA].src = objImgs[intA].src.replace('_purple','_'+strTheme);
					}
				}
			}
		}
		
		// add a default query parameter to any link in the given container
		function setAutoReferer(strContainer){
			var strHref, strTheme, arrHref, strLink, strHash;
			var objContainer = document.getElementById(strContainer);
			if(objContainer!=null){
				// all links in the container
				var objLinks = document.getElementById(strContainer).getElementsByTagName('A');
				// for all links
				for(var intA=0; intA<objLinks.length; intA++){
					strHref = objLinks[intA].getAttribute('href');
					if(strHref!=null && strHref.indexOf("javascript:")<0 && strHref.indexOf("cbpweb.exe")<0 && strHref.indexOf(".cfm")<0){
						arrHref = strHref.split("#");
						strLink = arrHref[0];
						strHash = (arrHref.length>1) ? "#"+arrHref[1] : "";
						if(document.location.href.indexOf(strLink)<0){
						// ?refer
							// if it's href has a 'refer' query parameter
							if(strHref.indexOf('refer=')>-1){
								// leave it alone
							// if it has ANY query parameters allready
							}else if(strHref.indexOf('?')>-1){
								// add one with a & prefix
							// objLinks[intA].setAttribute('href',strLink + '&refer=true');
							objLinks[intA].setAttribute('href', strLink);
							// else
							}else{
								// add one with a ? prefix
							// objLinks[intA].setAttribute('href',strLink + '?refer=true');
							objLinks[intA].setAttribute('href', strLink);
							}
						// &refurl
							// update href from node
							strLink = objLinks[intA].getAttribute('href');
							// if the link has a given refurl
							if(strHref.indexOf('refurl=')>-1){
								// leave it the way it is
							// if the link wants a refurl
							}else if(strHref.indexOf('refer=true')>-1){
								// salvage any existent refurl parameters
								strRefurl = getQueryParameter('refurl',escape(document.location.href));
								// add one with a & prefix
								objLinks[intA].setAttribute('href',strLink + '&refurl=' + strRefurl);
							}
						// &theme
							// update href from node
							strLink = objLinks[intA].getAttribute('href');
							// if it's href has a 'theme' query parameter
							if(strHref.indexOf('theme=')>-1){
								// leave it alone
							// else
							}else{
								// get the page theme from the body classname
								strTheme = document.body.className;
								// if the theme is purple
								if(strTheme.indexOf('purple')>-1){
									// add purple with a & prefix
									objLinks[intA].setAttribute('href',strLink + '&theme=purple' + strHash);
								// if the theme is green
								}else if(strTheme.indexOf('green')>-1){
									// add green with a & prefix
									objLinks[intA].setAttribute('href',strLink + '&theme=green' + strHash);
								// if the theme is blue
								}else if(strTheme.indexOf('blue')>-1){
									// add blue with a & prefix
									objLinks[intA].setAttribute('href',strLink + '&theme=blue' + strHash);
								}
							}
						}
					}
				}
			}
		}
		
	// event handlers 
		function handleResize(){
			setTimeout("setDimensions()",128);
		}
	// executed inline
		// hide the teaser
		
		//  if there's DOM support capture the resize event
		if(typeof(document.getElementById)!='undefined'){
			setDimensions();
			setColourTheme();
			if(document.body.getAttribute('onload')==null) onload = handleResize;
			onresize = handleResize;
		}
	
		// add a default query parameter to any link in the given containers
		setAutoReferer('content0');
		setAutoReferer('related0');
		
}
