
//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************

//*******************START UP FUNCTIONS *********

// start up
function startUp() {
	setTool(document.frmMain.tool.value);
	showPanel(document.frmMain.panel.value);
	setSearchTableCells();
	setZoomBoxSettings();
}


//*******************KEY DOWN FUNCTIONS *******

//print key down
function printKeyDown(event){
	if(event.keyCode == 13){
		window.event.keyCode = 0;
		doLayout();
	}
}

//search key down
function searchKeyDown(event){
	if(event.keyCode == 13){
		window.event.keyCode = 0;
		document.getElementById("imgSearch").click();
	}
}

//*******************PANEL FUNCTIONS *********
//hide panels
function hidePanel(){
	sOldPanel = document.frmMain.panel.value;
	theOldImg = eval("document.T_"+sOldPanel);
	theOldImg.src = "images/t_"+sOldPanel+"_off.gif";
	hideLayer(sOldPanel);
}

//show panel
function showPanel(sPanel){
	hidePanel();
	theImg = eval("document.T_"+sPanel);
	theImg.src = "images/t_"+sPanel+"_on.gif";
	showLayer(sPanel);
	document.frmMain.panel.value = sPanel;
}


//*******************TOOL FUNCTIONS *********

//set tool
function setTool(sTool){
	//MEASURE
	if(sTool == "MEASURE"){
		showLayer("PanelMeasure");
	}else{
		hideLayer("PanelMeasure");
	}
	resetMeasureTool();
	setToolImage(sTool);
	document.frmMain.tool.value = sTool;
	if(sTool == "RADIUS"){
		showPanel("RADIUS");
	}else{
		if(document.frmMain.panel.value == "RADIUS"){
			showPanel("SEARCH");
		}
	}
}

//unselect radius tool
function unselectRadiusTool(){
	if(document.frmMain.tool.value == "RADIUS"){
		setTool("ZOOMIN");
	}
}


//set tool image
function setToolImage(sTool){
	sOldTool = document.frmMain.tool.value;
	if(sOldTool != "RADIUS"){
		theOldImg = eval("document.B_"+sOldTool);
		theOldImg.src = "images/b_"+sOldTool+"_off.gif";
	}
	if(sTool != "RADIUS"){
		theNewImg = eval("document.B_"+sTool);
		theNewImg.src = "images/b_"+sTool+"_on.gif";
	}
}

//set cmd
function setCmd(sCmd){
	document.frmMain.cmd.value = sCmd;
	//document.getElementById("imgMap").click();
	document.frmMain.submit();
	showLayer("Splash");
}

// ************** ACTIVE LAYER FUNCTIONS **********

// set search table cells
function setSearchTableCells(){
	sLayer = document.frmMain.ddlActiveLayer.options[document.frmMain.ddlActiveLayer.options.selectedIndex].value;
	document.getElementById("SearchTitleCell").innerHTML = "Search " + sLayer + ":";
	if(sLayer == "Available Buildings"){
		document.getElementById("SearchMinCell").innerHTML = "Minimum Area (SQ FT):";
		document.getElementById("SearchMaxCell").innerHTML = "Maximum Area (SQ FT):";
	}else{
		document.getElementById("SearchMinCell").innerHTML = "Minimum Acreage:";
		document.getElementById("SearchMaxCell").innerHTML = "Maximum Acreage:";
	}
	if(document.frmMain.panel.value == "SEARCH"){
		if(sLayer == "Block Groups"){
			hideLayer("SEARCH");
		}else{
			showLayer("SEARCH");
		}
	}
}  



//****************** HELP FUNCTIONS ************

// show help
function showHelp(sTopic){
	helpURL = "help.htm"+"#"+sTopic;
	if (typeof helpWin == 'undefined'){
		helpWin = window.open(helpURL, "Help", "width=500,height=400,toolbar=0,menubar=0,scrollbars=1,resizable=1,left=300,top=0");
		helpWin.opener = self;
	} else {
		if (helpWin.closed){
			helpWin = window.open(helpURL, "Help", "width=500,height=400,toolbar=0,menubar=0,scrollbars=1,resizable=1,left=300,top=0");
			helpWin.opener = self;
		} else {
			helpWin = window.open(helpURL, "Help", "width=500,height=400,toolbar=0,menubar=0,scrollbars=1,resizable=1,left=300,top=0");			
			helpWin.focus();
		}
	}
}


//****************** WHAT IS INFOMAP POP-UP ************

// show What is InfoMap message
function showInfoMap(sTopic){
	InfoMapURL = "InfoMap.htm"+"#"+sTopic;
	if (typeof InfoMapWin == 'undefined'){
		InfoMapWin = window.open(InfoMapURL, "InfoMap", "width=525,height=590,toolbar=0,menubar=0,scrollbars=0,resizable=1,left=300,top=0");
		InfoMapWin.opener = self;
	} else {
		if (InfoMapWin.closed){
			InfoMapWin = window.open(InfoMapURL, "InfoMap", "width=525,height=590,toolbar=0,menubar=0,scrollbars=0,resizable=1,left=300,top=0");
			InfoMapWin.opener = self;
		} else {
			InfoMapWin = window.open(InfoMapURL, "InfoMap", "width=525,height=590,toolbar=0,menubar=0,scrollbars=0,resizable=1,left=300,top=0");			
			InfoMapWin.focus();
		}
	}
}



//****************** PRINT FUNCTIONS ***********

// do layout
function doLayout(){
	theForm = document.frmMain;
	title = escape(theForm.txtTitle.value);
	paper = theForm.ddlPaper.options[theForm.ddlPaper.options.selectedIndex].value;
	orient = theForm.ddlOrientation.options[theForm.ddlOrientation.options.selectedIndex].value;
	activelayer = document.frmMain.ddlActiveLayer.options[document.frmMain.ddlActiveLayer.options.selectedIndex].value;
	selid = document.frmMain.selid.value;
	minX = document.frmMain.minX.value;
	minY = document.frmMain.minY.value;
	maxX = document.frmMain.maxX.value;
	maxY = document.frmMain.maxY.value;
	layerlist = buildLayerList();
	theURL = "mapprint.aspx?activelayer="+activelayer+"&selid="+selid+"&minX="+minX+"&minY="+minY+"&maxX="+maxX+"&maxY="+maxY+"&layerlist="+layerlist+"&title="+title+"&orient="+orient+"&paper="+paper;
	//alert(theURL);
	printWin = window.open(theURL, "Print", "width=600,height=400,toolbar=0,menubar=1,scrollbars=1,resizable=1,left=200,top=0");
}

//build layer list
function buildLayerList(){
	var endoflist = 0;
	var i = 0;
	var layerlist = "";
	do{
		theChkBox = eval("document.frmMain.chkLayers_"+i);
		if(theChkBox != null){
			if(theChkBox.checked){
				layerlist = layerlist + "1";
			}else{
				layerlist = layerlist + "0";
			}
		}else{
			endoflist = 1;
		}
		i = i + 1;
	}
	while(endoflist == 0)
	return layerlist;
}

//****************** REPORT FUNCTIONS ***********

// show flier
function showFlier(sURL, sLayer, sID){
	//theURL = "flyer.aspx?layer="+sLayer+"&cogid="+sID;
//	theURL = "fliers/"+sID+".pdf";
//	flierWin = window.open(theURL, "Flier", "width=600,height=400,toolbar=0,menubar=1,scrollbars=1,resizable=1,left=200,top=0");
	
//	theURL = "BrochureForm.aspx?strType=" + sLayer + "&strCOGID=" + sID;
	theURL = sURL + "BrochureForm.aspx?strType=" + sLayer + "&strCODID=" + sID;
	flierWin = window.open(theURL, "Flier", "width=600,height=400,toolbar=0,menubar=1,scrollbars=1,resizable=1,left=200,top=0");
}

// show report
function showReport(){
	selX = document.frmMain.selX.value;
	selY = document.frmMain.selY.value;
	selRadius = document.frmMain.ddlRadius.options[document.frmMain.ddlRadius.options.selectedIndex].value;
	theURL = "report.aspx?selX="+selX+"&selY="+selY+"&radius="+selRadius;
	flierWin = window.open(theURL, "Flier", "width=800,height=400,toolbar=0,menubar=1,scrollbars=1,resizable=1,left=200,top=0");
}
