// Get the query string with javascript

  queryVar = this.location.href;
  var inq = queryVar.indexOf('?');
  queryVar = queryVar.substring(inq + 1);
  _query_string = '';
  if (inq > 0) {
    _query_string = queryVar; // full query is also available to body
  }
  var text1 = "&";
  var strLength = queryVar.length, txtLength = text1.length;
  var i = queryVar.indexOf(text1);
  while (i+txtLength < strLength) {
    if (i > 0) {
      qrysplit(queryVar.substring(0,i),"=");
    }
    else {
      qrysplit(queryVar,"=");
    }
    queryVar = queryVar.substring(i+txtLength,strLength);
    var i = queryVar.indexOf(text1);
    if (i < 1) {
      i = strLength + 1; // end while
    }
  }

  qrysplit(queryVar,"="); // last one

  function qrysplit(string,text) {
    name = string.substring(0,string.indexOf(text));
    value = string.substring(string.indexOf(text) + 1);
    //eval("query_" + name + " = value;");
    // comment the previous line and uncomment this next line if you want to
    // use UNESCAPE, that is, turn %20 into a space, %22 into double quotes, etc.
    eval("query_" + name + " = unescape(value);");
  }

  function getQueryVar(varname) {
    if (eval("query_" + varname))
      return eval("query_" + varname)
    else
      return '';
  }

  function queryExists() {
    return _query_string != '';
  }

// END GET QUERY STRING CODE

// creates a Month select control initialized to current month
// USAGE: <script language="javascript">createMonthSelect('myselectname', document, 2);</script>
function createMonthSelect(controlname, doc, tabindex)
{
	var selectstring;
	var today = new Date();
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	selectstring = '<select name="' + controlname + '" tabindex="' + tabindex + '">';
	for(var x = 0, val; x < 12; x++)
	{
		if(x + 1 < 10) val = '0' + (x + 1); else val = x + 1;
		if(today.getMonth() == x)
			selectstring += '<option selected value="' + val +'">' + months[x] + '</option>';
		else
			selectstring += '<option value="' + val +'">' + months[x] + '</option>';
	}
	selectstring += '</select>';
	doc.write(selectstring);
}

// inserts an Option into the email select for emailing invoices to the selected user
function getEmail(button)
{
	var bname = button.name;
	var invoice = bname.substring(1, bname.length);
	var email = prompt("Email invoice " + invoice + " to address?", "");
	if(email)
	{
		var selname = "S" + invoice;
		document.forms[0].elements[selname].options[0] = new Option(email);// replaces the current option
		document.forms[0].elements[selname].options[0].value = invoice + "_" + email;// set the value
		document.forms[0].elements[selname].selectedIndex = 0;
	}		
}
