
//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************


// do step
function doStep(sStep){
	var ok = true;
	var msg = "";
	theGeog = document.frmMain.geog.value;
	theFList = document.frmMain.flist.value;
	theTables = document.frmMain.tables.value;
	if((sStep == "02") || (sStep == "03") || (sStep == "04")){
		if (theGeog == ""){
			ok = false;
			msg = "Please select a geography type before proceeding. \n";
		}
	}
	if((sStep == "03") || (sStep == "04")){
		if (theFList == ""){
			ok = false;
			msg = msg + "Please select at least one feature before proceeding. \n";
		}
	}
	if(sStep == "04"){
		if (theTables == ""){
			ok = false;
			msg = msg + "Please select at least one data field before proceeding.";
		}
	}
	if(ok){
		theURL = "step"+sStep+".asp?geog="+theGeog+"&flist="+theFList+"&tables="+theTables;
		document.location = theURL;
	} else {
		alert(msg);
	}
}

// do tables step
function doTablesStep(sStep){
	selectTables();
	doStep(sStep);
}

// select geog
function selectGeog(sGeog){
	if (document.frmMain.geog.value != sGeog){
		document.frmMain.flist.value = "";
		document.frmMain.tables.value = "";
		if (sGeog == "COUNTY"){
			document.frmMain.flist.value = "'BROWARD'";
		}
	}

	document.frmMain.geog.value = sGeog;
	document.frmMain.submit();
}

// set search tool
function setSearchTool(sSearch){
	document.frmMain.cmd.value = "REFRESH";
	document.frmMain.searchtool.value = sSearch;
	document.frmMain.addr1.value = "";
	document.frmMain.zip.value = "";
	document.frmMain.dist.selectedIndex = 0;
	document.frmMain.submit();
}

// set cmd
function setCmd(sCmd){
	document.frmMain.cmd.value = sCmd;
	document.frmMain.submit();
}

// add feature
function addFeature(){
	af = document.frmMain.addf.options[document.frmMain.addf.options.selectedIndex].value;
	if (af != ""){
		setCmd("ADD");
	}
}


// do addr search
function doAddrSearch(){
	var ok = true;
	msg = "";
	sSearch = document.frmMain.searchtool.value;
	theAddr1 = document.frmMain.addr1.value;
	theZip = document.frmMain.zip.value;
	theDist = parseFloat(document.frmMain.dist.options[document.frmMain.dist.options.selectedIndex].value);
	if(theAddr1 == ""){
		ok = false;
		msg = msg + "Please enter a valid address. \n";
	}
	if (sSearch == "addr"){
		if((theDist >= 0) && (theDist < 5.1)){
			ok = true;
		} else {
			ok = false;
			msg = msg + "Please enter a search distance between 0 and 5 miles. \n";
		}
	}
	if (sSearch == "int"){
		if((theDist > 0) && (theDist < 5.1)){
			ok = true;
		} else {
			ok = false;
			msg = msg + "Please enter a search distance between 0.1 and 5 miles. \n";
		}
		theAddr2 = document.frmMain.addr2.value;
		if(theAddr2 == ""){
			ok = false;
			msg = msg + "Please enter a valid intersecting street. \n";
		}
	}
	if (ok) {
		document.frmMain.cmd.value = "FINDADDR";
		document.frmMain.submit();
	} else {
		alert(msg);
	}
}

// select tables
function selectTables(){
	tList = "";
	theForm = document.frmMain;
	for (var c = 0; c < theForm.elements.length; c++) {
 		if (theForm.elements[c].type == 'checkbox') {
			if(theForm.elements[c].checked){
				if (tList.length > 0){
					tList = tList + "," + theForm.elements[c].name;
				} else {
					tList = theForm.elements[c].name;
				}
			} 
		}
	}
	theForm.tables.value = tList;
}

// update tables
function updateTables(){

}

// do download
function doDownload(sType){
	dwnURL = "download.asp?cmd="+sType;
	dwnWin = window.open(dwnURL, "Download", "width=640,height=250,toolbar=0,menubar=0,scrollbars=1,resizable=1,left=340,top=0");
	dwnWin.focus();
}


// show help
function showHelp(){
	if (typeof helpWin == 'undefined'){
		helpWin = window.open("help.htm", "Help", "width=500,height=400,toolbar=0,menubar=0,scrollbars=1,resizable=1,left=340,top=0");
		helpWin.opener = self;
	} else {
		if (helpWin.closed){
			helpWin = window.open("help.htm", "Help", "width=500,height=400,toolbar=0,menubar=0,scrollbars=1,resizable=1,left=340,top=0");
			helpWin.opener = self;
		} else {			
			helpWin.focus();
		}
	}
}


