
function ExportIt() {
	var frmPrintFrame = window.document.forms["PrintFrame"];

	switch (frmPrintFrame.elements["Location"].value) {
		case "Detail":
			alert("Export is only supported for the Summary page.");
			break;
		case "Summary":
			ExportSummary();
			break;
		default:
			alert("No results to Export");
			break;
	}
}

function ExportSummary() {
	var frmCriteria = window.document.forms["Criteria"];
	var frmPrintFrame = window.document.forms["PrintFrame"];
	var Exporthref = "rptExport.csv?"
	var i
	var blnParams = false;

	for (i = 0; i < frmCriteria.elements.length; i++) {
		if (frmCriteria.elements[i].name != "PageSize" && frmCriteria.elements[i].name != "UseSoundex") {
			switch (frmCriteria.elements[i].type) {
				case "select-one": {
					if (i > 1) {
						Exporthref = Exporthref + "&";
					}
					if (frmCriteria.elements[i].options[frmCriteria.elements[i].selectedIndex].value != "") {
						blnParams = true;
					}
					Exporthref = Exporthref + frmCriteria.elements[i].name + "=" + StringReplace(StringReplace(frmCriteria.elements[i].options[frmCriteria.elements[i].selectedIndex].value, "%", "_"), "&", "%26");
					break;
				}
				case "text": {
					if (i > 1) {
						Exporthref = Exporthref + "&";
					}
					if (frmCriteria.elements[i].value != "") {
						blnParams = true;
					}
					Exporthref = Exporthref + frmCriteria.elements[i].name + "=" + StringReplace(StringReplace(frmCriteria.elements[i].value, "%", "_"), "&", "%26");
					break;
				}
				case "Text": {
					if (i > 1) {
						Exporthref = Exporthref + "&";
					}
					if (frmCriteria.elements[i].value != "") {
						blnParams = true;
					}
					Exporthref = Exporthref + frmCriteria.elements[i].name + "=" + StringReplace(StringReplace(frmCriteria.elements[i].value, "%", "_"), "&", "%26");
					break;
				}
				case "checkbox": {
					if (i > 1) {
						Exporthref = Exporthref + "&";
					}
					Exporthref = Exporthref + frmCriteria.elements[i].name + "=" + frmCriteria.elements[i].checked;
					break;
				}
				case "textarea": {
					if (i > 1) {
						Exporthref = Exporthref + "&";
					}
					if (frmCriteria.elements[i].value != "") {
						blnParams = true;
					}
					Exporthref = Exporthref + frmCriteria.elements[i].name + "=" + StringReplace(StringReplace(frmCriteria.elements[i].value, "%", "_"), "&", "%26");
					break;
				}
			}
		}
	}
	if (blnParams == true) {
		Exporthref = StringReplace(Exporthref, " ", "%20")
		window.open(Exporthref);
	}
	else {
		window.open(Exporthref);
	}
}

function ExportDetail() {
	var frmExport = window.parent.frames["Results"].document.forms["Print"];
	var Exporthref = "rptDirDetailExport.csv?"
	var i
	
	for (i = 0; i < frmExport.elements.length; i++) {
		if (i > 0) {
			Exporthref = Exporthref + "&"; 
		}
		Exporthref = Exporthref + frmExport.elements[i].name + "=" + frmExport.elements[i].value
	}
	Exporthref = StringReplace(Exporthref, "%", "_");
	window.open(Exporthref);
}


