/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}

function beginDownload() {
  // backupURL used for download if no URLs have a reliability rating > 64 and no URLs are in the U.S.
  // (backupURL is set to the last URL looped through when setting the URL arrays)
  
    var qs = new Querystring()
	var doc = qs.get("passthru")

  var domain = document.domain;
  
  var loc = '/stg/bespoke_images/monread/';
  
  if (doc == 1){
  	newlocation = loc + 'GMPE_Eval.zip';
  } else if (doc == 2){
  	newlocation = 'http://www.quotewerks.com/pdownload/qw4setup.exe';
  } else if (doc == 3){
  	newlocation = 'http://www.faxrush.com/downloads/assets/products/OmniRush_v9_Build_994.exe';
  }
  
 
  // Bizarre logic because JavaScript won't behave
  idl = 1;
  if (location.search) { // for NN2
    idl = -location.search.indexOf("idl=n");
  }
  if (idl > 0) {
    window.location = newlocation;
  }
  return 1;

}