/***********************************
 * Program: index_functions.js
 * Purpose: This program provides javascript
 *          functions to the index page.
 ************************************/

/*******************
 * function: autoSize
 * Purpose:  This function resizes the content div#mid to fit the browser height. 
 ********************/
function autoSize() {
  var myWidth = 0, myHeight = 0;
  var newHeight, TOP_OFFSET = 507;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  newHeight = myHeight - TOP_OFFSET;
  if (newHeight < 275) //inforce a minimum height
  {
	newHeight = 275;
  }
  document.getElementById("container").style.height = myHeight + "px" ;
  document.getElementById("mid").height = newHeight + "px" ;
	if (getQueryVariable("page") != ""){
		var page = getQueryVariable("page");
		
		if (getQueryVariable("qstr"))
		{
			var qStr = getQueryVariable("qstr");
			while ((qStr.indexOf("@@") != -1) || (qStr.indexOf("--") != -1))
			{
				qStr = qStr.replace(/@@/,"=");
				qStr = qStr.replace(/--/,"&");						
			}
			page = page+"?"+qStr;
		}
		document.getElementById("mid").src = page;					
	}
 }
 
/*******************
 * function: getQueryVariable
 * Purpose:  This function returns the querystring 
 *           value for any given querystring parameter.
 ********************/
 function getQueryVariable(variable) {
	  var query = window.location.search.substring(1);
	  var vars = query.split("&");
	  for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
		  return pair[1];
		}					
	  }
	  return false;
	}