
function showsubtypes() {
	var i = 0;
	var hld = document.getElementById('svcsub');
	hld.innerHTML = "";
	if ( !this.selectedIndex || !servsubtypes[this.selectedIndex] ) {
		return 1;
	}
	var subts = servsubtypes[this.selectedIndex];
	hld.innerHTML = "<strong><p class=\"or\">-- AND --</p></strong>\n";
	var l = document.createElement('SPAN');
	l.className = "row";
	l.innerHTML = "\n<label for=\"svcsubs\">Select specific type of service: </label>\n";
	hld.appendChild(l);
	var x = document.createElement('SELECT');
	x.id = x.name = "svcsubs";
	l.appendChild(x);
	while ( i < subts.length ) {
		var arrST = subts[i].split('|');
		var y = document.createElement('OPTION');
		y.innerHTML = arrST[0];
		if (arrST[1])
			y.value = arrST[1];
		else
			y.value = arrST[0];
		x.appendChild(y);
		i++;
	}

}

function defaultsubtype() {
	var i = 0;
	var hld = document.getElementById('svcsub');
	hld.innerHTML = "";
	var servtype = document.getElementById('servicetypes')
	if ( !servtype.selectedIndex || !servsubtypes[servtype.selectedIndex] ) {
		return 1;
	}
	var subts = servsubtypes[servtype.selectedIndex];
	hld.innerHTML = "<strong><p class=\"or\">-- AND --</p></strong>\n";
	var l = document.createElement ('SPAN');
	l.className = "row";
	l.innerHTML = "\n<label for=\"svcsubs\">Select specific type of service: </label>";
	hld.appendChild(l);
	var x = document.createElement('SELECT');
	x.id = x.name = "svcsubs";
	l.appendChild(x);
	var sel = decodeURIComponent(getQueryVariable("svcsubs"))
	while ( i < subts.length ) {
		var arrST = subts[i].split('|')
		var y = document.createElement('OPTION');
		y.innerHTML = arrST[0];
		if (arrST[1]) {
			y.value = arrST[1];
			if (arrST[1] == sel)
				y.selected = "selected";
		}
		else {
			y.value = arrST[0];
			if (arrST[0] == sel)
				y.selected = "selected";
		}
		x.appendChild(y);
		i++;
	}

}

function mksubtyp() {
	// add onchange function to service type dropdown:
	document.getElementById('servicetypes').onchange = showsubtypes;
}

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 "";
}
