// set defaults
var ESPchosenColour = "dark";
var ESPchosenSize = "400";
var ESPchosenLocation= "";
var ESPchosenExclProjTypes = "";
var ESPdivHeight = "325";
var ESPiframeHeight = "330";

var ESPscripts = document.getElementsByTagName('script');
var ESPthisScript = ESPscripts[ ESPscripts.length - 1 ];

// get the root url
var ESPparsedurl = ESPthisScript.src.split('/');
var ESProotURL = "";
if (ESPparsedurl[0] == "..")
{
	// script url is relative (probably test page) so use doc loc for base url
	ESPparsedurl = document.location.href.split('/');
}
ESProotURL = "http://" + ESPparsedurl[2] + "/";

// get the arguments
var ESPqueryString = ESPthisScript.src.replace(/^[^\?]+\??/,'');

var ESPparams = ESPparseQuery( ESPqueryString );

function ESPparseQuery( ESPquery ) {
   var ESPinnerParams = new Object ();
   if ( ! ESPquery ) return ESPinnerParams;
   var ESPPairs = ESPquery.split(/[;&]/);
   for ( var ESPi = 0; ESPi < ESPPairs.length; ESPi++ ) {
      var ESPKeyVal = ESPPairs[ESPi].split('=');
      if ( ! ESPKeyVal || ESPKeyVal.length != 2 ) continue;
      var ESPkey = unescape( ESPKeyVal[0] );
      var ESPval = unescape( ESPKeyVal[1] );
      ESPval = ESPval.replace(/\+/g, ' ');
      ESPinnerParams[ESPkey] = ESPval;
   }
   return ESPinnerParams;
}

// output HTML for widget display

if (ESPparams['espWidth'] == '300')
{
	ESPchosenSize = "300";
	ESPdivHeight = "305";
	ESPiframeHeight = "310";
}
if (ESPparams['espColour'] == 'light') ESPchosenColour = "light";
if (ESPparams['espLocation'] != null) ESPchosenLocation = ESPparams['espLocation'];
if (ESPparams['exclprojecttypes'] != null) ESPchosenExclProjTypes = ESPparams['exclprojecttypes'];

document.write("<iframe src=\"" + ESProotURL  + "widget/pages/widget_content.aspx?widgetWidth=" + ESPchosenSize + "&widgetColour=" + ESPchosenColour + "&location=" + ESPchosenLocation + "&exclprojecttypes=" + ESPchosenExclProjTypes + "\" id=\"espWidget" + ESPchosenSize + ESPchosenColour + "\" width=\"" + ESPchosenSize + "\" height=\"" + ESPiframeHeight + "\" scrolling=\"no\" frameborder=\"0\" style=\"margin:-5px 0 0;padding:0;border:none;\">");
document.write("<p>Your browser does not support iframes, so the Economic Stimulus Plan widget cannot be displayed.</p>");
document.write("</iframe>");


