// ----------------------------------------------------------------------------------------------
// This file contains functions for browser interaction like parsing query string and getting
// viewport width and height

//-----------------------------------------------------------------------------
// QueryString
//-----------------------------------------------------------------------------
function QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
	if (QueryString.keys[i]==key)
	{
		value = QueryString.values[i];
		break;
	}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

//-----------------------------------------------------------------------------
// ParseQueryString
//-----------------------------------------------------------------------------
function ParseQueryString()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");

for (var i=0;i<pairs.length;i++)
{
	var pos = pairs[i].indexOf('=');
	if (pos >= 0)
	{
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		QueryString.keys[QueryString.keys.length] = argname;
		QueryString.values[QueryString.values.length] = value;		
	}
}

}
ParseQueryString();


//-----------------------------------------------------------------------------
// Returns the height of the viewport.
//-----------------------------------------------------------------------------
function getViewportHeight() 
{
  var height = null;
  
  // supported in Mozilla, Opera, and Safari
  if (window.innerHeight)
    height = window.innerHeight;

  // supported in standards mode of IE, but not in any other mode
  if (height == null && window.document.documentElement.clientHeight)
    height = document.documentElement.clientHeight;
	
  // supported in quirks mode, older versions of IE, and mac IE (anything else).
  if (height == null && window.document.body.clientHeight)
    height = window.document.body.clientHeight;
    
  if (height == null || height == "" || height == "0")
  {
    height = "400";
  }
  
  return height;
}	

//-----------------------------------------------------------------------------
// Returns the width of the viewport.
//-----------------------------------------------------------------------------
function getViewportWidth() 
{
  var width = null;
  
  // supported in Mozilla, Opera, and Safari
  if (window.innerWidth)
    width = window.innerWidth;

  // supported in standards mode of IE, but not in any other mode
  if (width == null && window.document.documentElement.clientWidth)
    width = document.documentElement.clientWidth;
	
  // supported in quirks mode, older versions of IE, and mac IE (anything else).
  if (width == null && window.document.body.clientWidth)
    width = window.document.body.clientWidth;
    
  if (width == null || width == "" || width == "0")
  {
    width = "400";
  }
  
  return width;
}	