var curTheme = "";
var curThemeFilter = "";

// ##### STARTUP FUNCTIONS #####
// start up
function startUp() {
	
	var cList = document.frmMain.report_locations.value;
	cList = cList.substring(0,cList.indexOf("?")+1);
	
	
	curTool = document.frmMain.tool.value;
	if (curTool != "")
	{	  
	  setTool(curTool);		
	}
	
		
	//alert("Current Tool: " + curTool);
    curTheme = document.frmMain.thematiclayer.value;
    curThemeFilter = document.frmMain.thematicfilter.value;
    //alert(curThemeFilter);
	checkOnLayers(); //restore checked layers
	DisableLayers(); //disable layer checkboxes in the disabled layer list
	//CreateLegend(); //turn legend items on\off
	setThemes(); //restore drop down lists and check boxes

	setCommSearch(); //restore check boxes
        //restore property search
	setPropSearch();		
	setRange(); //restore range drop down
	showPDFReport();	
	
	setZoomBoxSettings(); //start listening for zoom/pan mouse downs
	
	if(document.frmMain.cmd.value == "radius" || document.frmMain.tool.value == "Report_Radius")
	{		
		setTool('select');
		switchMapTabs('tools');
	}	
}

// ##### GENERAL FUNCTIONS #####

function setMapCreation(value)
{
  document.frmMain.create_map_on_load.value = value;
}
function setCmd(cmd)
{
  document.frmMain.cmd.value = cmd;
}

//show panel
function showPanel(sPanel){
	document.frmMain.panel.value = sPanel;
}


function submitMapRequest(){
	
	var radVal = document.frmMain.radius.value;	
	
	if(radVal == "" || radVal == null)
	{
		radius_other_text = findObj("radius_other");
		report_other_text = findObj("reportradius_other");
		
		if(radius_other_text != null && radius_other_text.value != "")
		{
			document.frmMain.radius.value = radius_other_text.value;
			
		}
		else if(report_other_text != null && report_other_text.value != "")
		{
			document.frmMain.radius.value = report_other_text.value;
			
		}
		else
		{		
			document.frmMain.radius.value = "County";			
		}
	}
		
	if (bLoad)
	{		
		showLayer("splashScreen");
		saveCommSearch(); //always save the state of commsearch since they can go back at anytime
		document.frmMain.submit();			 
	}
}
// get the layer object called "name"
function getLayer(name) {
	var theObj = document.getElementById(name);
	if(theObj != null)
	{
		return(theObj.style);
	} 
	else 
	{
		if (name != "")
		{
			if ( eval('document.all.' + name) != null) 
			{
				layer = eval('document.all.' + name + '.style');
				return(layer);
			}
		} 
		else 
		{
			return(null);
		}
	
	}
}

// toggle layer to invisible
function hideLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) 
	{
		layer.visibility = "hidden";
	}
}

// toggle layer to visible
function showLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) 
	{
	  	layer.visibility = "visible";
	}
}
// ##### LAYERS LIST FUNCTIONS #####
function RestoreDefaultLayers()
{
  //clear comm search
  document.frmMain.dynamic_county_labels.Value = "";
  document.frmMain.cmd.value = "";
  //clear theme
  document.frmMain.thematiclayer.value = "";
  document.frmMain.thematicfilter.value = "";

  document.frmMain.layerlist.value = "Ocean_State,Ocean_County,States,Duke Energy,Ocean_State,Ocean_County,States,Duke Energy Service Territory,Counties,Southeast Cities,State Capitol,Big Cities,Medium Cities,Small Cities,US Highways,State Highways,Southeast Interstates,Interstates,Secondary Roads,Local Roads,Lakes,Office Building,Site,Site Boundaries,Hospitals,Airports,thm_wag,thm_unemployment,";
  submitMapRequest();
}
function DisableLayers()
{
  var controlIndex;
  var element;
  var numberofControls = document.frmMain.length;
  disabledlayers = document.frmMain.enabledlayerlist.value;
 len = disabledlayers; 
 istart = 0; 
 found = 0;
 while (found != -1)
 {
   found = disabledlayers.indexOf(",",found);  //found contains the position in the string of current ","
   if (found != -1)
    {
     s = disabledlayers.substring(istart,found);

     //disable this layer
	for (controlIndex = 0; controlIndex<numberofControls;controlIndex++)
	{
	  element = document.frmMain[controlIndex];
	  if (element.type == "checkbox" && element.value == s)
	  {
	    //disable the layer
	    element.disabled = true;
	  }		
	}
     istart = found + 1;
     found++;
    }//if
  } //while
} 


function checkOnLayers()
{
  var controlIndex;
  var element;
  var numberofControls = document.frmMain.length;
  layers = document.frmMain.layerlist.value;

 len = layers.length;
 istart = 0; 
 found = 0;
 while (found != -1)
 {
   found = layers.indexOf(",",found);  //found contains the position in the string of current ","
   if (found != -1) //get the string
    {
     s = layers.substring(istart,found);
     //check to see if the string is a thm - these won't have a layer checkbox
 
     //find the checkbox with this value and check it on
	for (controlIndex = 0; controlIndex<numberofControls;controlIndex++)
	{
	  element = document.frmMain[controlIndex];
	  if (element.type == "checkbox" && element.value == s)
	  {
	    //check it on
	    element.checked = "true";
	  }		
	} //end for
     istart = found + 1;
     found++;
    }//if
  } //while
} 

function createLayerList()
{
	var controlIndex;
	var element;
	var numberofControls = document.frmMain.length;

	var layerlist = "";
	var foundAtPosition = 0
	for (controlIndex = 0; controlIndex<numberofControls;controlIndex++)
	{
		element = document.frmMain[controlIndex];
		if (element.type == "checkbox" && element.checked == true)
		{
			foundAtPosition = element.id.indexOf("lyr_");		
			if (foundAtPosition != -1)
			{
				layerlist = layerlist + element.value + ",";
				if (element.value == "Site") //add the site areas as well
				{
				  layerlist = layerlist + "Site Boundaries,";
				}
				if (element.value == "Interstates") //add the site areas as well
				{
				  layerlist = layerlist + "Southeast Interstates,";
				}
			}
		}
	}

	document.frmMain.layerlist.value = layerlist;
	//alert("Layer list : " + document.frmMain.layerlist.value);

	//switch to legend tab
	document.frmMain.panel.value = "legend";
}

function buildLayerList(){
	//build layers in separate function from submit
	//this function gets used by print without submit
	createLayerList();
	submitMapRequest();
}

//set tool
function setTool(sTool){
	document.frmMain.tool.value = sTool;
	if (sTool == "zoomin")
	{
		changeTool("zoomin","18px");
	}
	if (sTool == "zoomout")
	{
		changeTool("zoomout","67px");
	}
	if (sTool == "pan")
	{
		changeTool("pan","116px");
	}
	if (sTool == "select")
	{
		changeTool("select","167px");
	}
	if (sTool == "identify")
	{
		changeTool("identify","214px");
	}
	if (sTool == "identifybusiness")
	{
		changeTool("identifyBusiness","263px");
	}
}

// ##### CREATE LEGEND FUNCTIONS #####
function CreateLegend()
{

  legendlayers = document.frmMain.legendlayerlist.value;
  found = 0;
  len = legendlayers;
  istart = 0; 
  while (found != -1)
  {
    found = legendlayers.indexOf(",",found);  //found contains the position in the string of current ","
    if (found != -1)
    {
     s = legendlayers .substring(istart,found);
     //show legend for this layer
     if (s!= "")
     {
	//show legend item for this
	LegID = findObj("Leg " + s);
	LegID.style.display = ""; 
     }
     istart = found + 1;
     found++;
    }//if 
  }//while
}
// ##### THEMATIC LAYER FUNCTIONS #####
//thematic layer - run from the button
function getThematicMap(){

	var controlIndex;
	var element;
	var numberofControls = document.frmMain.length;
	var layerlist = "";
	var foundAtPosition = 0;
	var thmindint = 0;
	var thmDiv = document.frmMain.thematiclayer.value;  //option in drop down
    var bAddToList = "false";
	var bSubmit = "true";
    var bOther = "false";
 	var bManufAll = false;
	var iOtherCount = 0;
	//var int = 0;
	var thmind_count = 0;
	if (thmDiv != "" && thmDiv != "none") {  
	  //loop through controls to see if there are sub controls for our thmDiv
         //these sub controls will be our filter
	  for (controlIndex = 0; controlIndex<numberofControls;controlIndex++)
	  {
		element = document.frmMain[controlIndex];
		//check for the correct thematic section
		foundAtPosition = element.value.indexOf(thmDiv);	
			if (foundAtPosition != -1) 
			{
				if (element.checked == true)
				{
					//for industry theme, if thm_33_all is there, then don't include other thm_3 checks
					//they can only check 5 at on time.
					if (thmDiv == "thm_ind")
					{
						thmindint = layerlist.indexOf("thm_ind3_All");
						if (thmindint != -1) 
						{
							bManufAll = true;
							bAddToList = "false";
							//int = element.value.indexOf("thm_ind3");
							//if (int == -1)
							//{
							//	bAddToList = "true";
							//}					
						} else
						{
							bAddToList = "true";
							thmind_count = thmind_count + 1;
						}
						
					} else
					{
				           if (element.value == "thm_pop_other")
					   {
						bOther = "true";

                                           }
					   if (bOther=="true") //they've checked other - keep track of how many categories they pick under other
					   {
						iOtherCount = iOtherCount + 1;
					   }
					   bAddToList = "true";
					}					
				}
			}
		if (bAddToList == "true")
		{
			layerlist = layerlist + element.value + ",";  
		}
		bAddToList = "false";
	  }
        }
       //--------DATA VALIDATAION---------------
	if (layerlist != "")
	{
	        document.frmMain.thematicfilter.value = layerlist;
                document.frmMain.thematiclayer.value = thmDiv;
                bSubmit = "true";
	} else
	{
		if (thmDiv != "") //is a theme without subcontrols - unemployment or household income
		{
		  document.frmMain.thematicfilter.value = thmDiv; //set the filter = the thematic layer so it will launch the thematic map query
		}
	}

	if (thmDiv == "thm_ind" && thmind_count > 5 && bManufAll == false)
	{
		alert("You may check up to 5 distinct industries.  Please narrow your selection and try again.")
                bSubmit = "false";
	}
	//if they have chosed "other" make sure they've picked at least one subgroup.  Othewise they won't get a thematic map back.
	if (bOther == "true")
	{
		if (iOtherCount < 2) //it will == 1 if they have just clicked Other
		{
		 alert("Please choose at least one subcategory and retry.");
		 bSubmit = "false";
		}
	}
	//---------SUBMIT FORM---------------------------------
	if (bSubmit == "true")
	{
	   //switch to legend tab
	   document.frmMain.panel.value = "legend";
   	   //clear comm search 
	   document.frmMain.cmd.value = "";
	   document.frmMain.dynamic_county_labels.value = "";
	   //submit form
	   submitMapRequest();
	}
}


//check on the previous theme - run at startup
function setThemes()
{
  theme = document.frmMain.thematiclayer.value;
  themeselect = findObj("themeselect");
  if (theme != "") //some theme was chosen last time.  
  {
	//loop through dropdown - display theme in drop down list 
	for (i=0;i<9;i++)
	{
		if(themeselect.options[i].value == theme)
		{
			themeselect.options[i].selected = "true";
			switchThemes(theme);		
		}
	}
	//recheck the boxes that were previously checked
	//set legend items
	setThemeCheckBoxes();		
  }
}


//switch legend images and label for themes
function setThemeCheckBoxes()
{
  theme = document.frmMain.thematiclayer.value; //dropdown list choice - ex. thm_pop
  var filter = document.frmMain.thematicfilter.value; //filter checkboxes - ex. thm_pop_male
  istart = 0;
  found = 0;
 while (found != -1)
 {
    found = filter.indexOf(",",found);  //found contains the position in the string of current ","
    if (found != -1) //there is a comma, get first string
    {
     	 s = filter .substring(istart,found);
     	 if (s!= "")
     	 {
	   element = findObj(s);
	   element.checked = "true";
	   
	   //for the first substring
 	   if (istart==0 && s=="thm_pop_other")
	   {
   	     disableThemePop('enable');
	   }
     	 }
     	 istart = found + 1;
     	 found++;
    }
  }
}
// ##### RANGE SEARCH FUNCTIONS #####

function setRange()
{
  radius = document.frmMain.radius.value;
  range = findObj("range");
  reportrng = findObj("reportrange");
  
  if (radius != "") //some range was chosen last time.  display this in dropdown
  {
	//through options
	for (i=0;i<4;i++)
	{
		if(range.options[i].value == radius)
		{
		  range.options[i].selected = "true";
		}
	}
	
	if(reportrng != null)
	{
		for (i=0;i<4;i++)
		{
			if(reportrng.options[i].value == radius)
			{
				reportrng.options[i].selected = "true";
			}
		}
	}
	
	var reportradius_other_text = findObj("reportradius_other");
	var reportrad_other_div=findObj("reportradius_other_label");
	if(radius != "County" && radius != "15" && radius != "30" && radius != "60")
	{
		
		range.options[4].selected = "true";		
		var radius_other_text = findObj("radius_other");
		var rad_other_div=findObj("radius_other_label");
		rad_other_div.style.display='';
		radius_other_text.value = radius;
		
		if(reportrng != null)
		{
			reportrng.options[4].selected = "true";		
			//alert(radius);
			reportrad_other_div.style.display = '';
			reportradius_other_text.value = radius;
		}	
	}
	else
	{
		if(reportrad_other_div != null)
		{
			reportrad_other_div.style.display = 'none';
		}
	}		
	
  }
}

function doPropertyRangeSearch(type)
{   
  var bSubmit = "true";
  //check for valid radius
  document.frmMain.prop_search_query.value = "";
  disableLocation();
  if (document.frmMain.radius.value == "")
  {
	alert("Please select a search range from the dropdown list and then click on the map to specify a location.");
	bSubmit = "false";
  }
  else
  {	
    if (document.frmMain.selX.value == "" || document.frmMain.selY.value == "")
    {
		markerXY = document.frmMain.markerList.value;
		
		if (markerXY != null && markerXY != "")
		{
			 var found = markerXY.indexOf(" ");  //found contains the position in the string of current ","
			 if (found > 0)
			 {
			  x = markerXY.substring(0,found);
			  found = found + 1;
			  y = markerXY.substring(found);
			  document.frmMain.selX.value = x;
			  document.frmMain.selY.value = y;			  
			 }       
        }        
        else
		{	
			markerXY = document.frmMain.reportxy.value;	
			if (markerXY != null && markerXY != "")
			{
				var found = markerXY.indexOf(",");  //found contains the position in the string of current ","
				if (found > 0)
				{
				x = markerXY.substring(0,found);
				found = found + 1;
				y = markerXY.substring(found);
				document.frmMain.selX.value = x;
				document.frmMain.selY.value = y;
				document.frmMain.markerList.value = x + " " + y;
				
				}       
			}  
			else
			{			
				alert("Please click on the map to specify a location.");
				bSubmit = "false";					
			}
		}
	}	
	
  }

  if (bSubmit == "true")
  { 
    //set cur cmd to prop_search
    document.frmMain.cmd.value = "prop_search";
    document.frmMain.prop_search_type.value = type;
    if (type == "site")
    {
	//SET TYPE TO PROPERTY
 	prop = findObj("proptype_land");
  	prop.checked = "true";
	disableSites();

    }
    if (type == "building")
    {
	//SET PROP SEARCH TYPE TO BUILDING
 	building = findObj("proptype_bldg");
  	building.checked = "true";
	disableBuildings();
    }
    if (type == "both")
    {
	//SET PROP SEARCH TYPE TO Both
 	building = findObj("proptype_both");
  	building.checked = "true";
	disableBoth();
	document.frmMain.prop_search_type.value = "both";
    }
    //alert(document.frmMain.prop_search_type.value);
    //submit form and do prop search
    submitMapRequest();
  }
}

function doCommunityRangeSearch()
{
  //this runs when the user clicks the "Create Report" button from the Select tool.
  //make sure they have a valid X,Y
  
  X = document.frmMain.selX.value;
  Y = document.frmMain.selY.value;  

 if (X == "" && Y == "" && document.frmMain.reportxy.value == "")
 {
	alert("Please select a location by clicking on the map.");
  } 
  else
  { //change tool to report
	countyXY = document.frmMain.reportxy.value;
	if (countyXY != null && countyXY != "")
	{
			 var found = countyXY.indexOf(",");  //found contains the position in the string of current ","
			 if (found > 0)
			 {
			  x = countyXY.substring(0,found);
			  found = found + 1;
			  y = countyXY.substring(found);
			  document.frmMain.tool.value = "CommunityReport_Button";
			  document.frmMain.maintab.value = "report";
			  document.frmMain.cmd.value = "radius";
			  document.frmMain.selX.value = x;
			  document.frmMain.selY.value = y;
			  document.frmMain.markerList.value = x + " " + y;
			 }       
    } 
	
	else
	{	
		if(X != "" && Y != "")
		{
			document.frmMain.tool.value = "CommunityReport_Button";
			document.frmMain.maintab.value = "report";
			document.frmMain.cmd.value = "radius";
			document.frmMain.selX.value = X;
			document.frmMain.selY.value = Y;
			document.frmMain.markerList.value = X + " " + Y; 
			document.frmMain.reportxy.value = X + "," + Y;   
		}
		
     }
         
    //document.frmMain.reportxy.value = X + "," + Y;
    //document.frmMain.markerList.value = X + " " + Y;
    submitMapRequest();
   }   
}

// ##### COMMUNITY SEARCH FUNCTIONS #####

function dgRowHighlight(e, color)
{

  // Annoying code to get the desired event handler from the browser.
  if (!e) e = window.event; 
  var srcEl = e.target || e.srcElement;
  var curElement = srcEl;
   
  while (curElement && !(curElement.tagName == "TR"))
  {
     // Keep going until we reach the parent table row
     curElement = curElement.parentNode;
  }

  if (curElement != srcEl)
  { 
      // Modify your colors here for a selected object
      curElement.style.background = color;
  }
  else
  {
      curElement.style.background = "none";
  }
 
}

function commSearchClickLine(fips)
{
  
  document.frmMain.report_county_fips.Value = fips;
  //alert(document.frmMain.report_county_fips.Value);
  
}

function commSearchCheckRow(e, value, len)
{

  // Annoying code to get the desired event handler from the browser.
  if (!e) e = window.event; 
  var srcEl = e.target || e.srcElement;
  var curElement = srcEl;
  //alert(document.frmMain.comm_search_rows_checked.value); 
  //ADD REMOVE FIPS
  currFips = document.frmMain.comm_search_rows_checked.value;
  while (curElement && !(curElement.tagName == "TR"))
  {
     // Keep going until we reach the parent table row
     curElement = curElement.parentNode;
  }

  if (curElement != srcEl)
  {
     if (srcEl.checked)
     {        
	  document.frmMain.comm_search_rows_checked.value = document.frmMain.comm_search_rows_checked.value + value;
     }
     else
     {
	//remove fips from list
 	var found = currFips.indexOf(value,0);
  	if (found != -1) //remove from list
	{
       	var left = currFips .substring(0,found);
		right = currFips .substring(found + len);
	    document.frmMain.comm_search_rows_checked.value = left + right;
	}
      }
   }
//alert(document.frmMain.comm_search_rows_checked.value);
}
function clearCommSearch()
{
	//clear checked values
        document.frmMain.comm_search_rows_checked.value = "";
	//clear out the community search criteria
	//reset to intro
	switchCommSearch(0);
	//clear tag links
 	clearTaggedLinks(); 
	//clear all checked boxes
  	var controlIndex;
  	var element;
  	var numberofControls = document.frmCommSearch.length;
	for (controlIndex = 0; controlIndex<numberofControls;controlIndex++)
	{
	  element = document.frmCommSearch[controlIndex];
	  if (element.type == "checkbox")
	  {
	    element.checked = false;
	  }		
	}

	//reset the radio buttons
	document.frmCommSearch.comm_rate_pop_0.checked = "true";
	document.frmCommSearch.comm_pop_working_age.checked = "true";
	document.frmCommSearch.comm_rate_inc_0.checked = "true";
	document.frmCommSearch.comm_inc_low.checked = "true";
	document.frmCommSearch.comm_rate_sup_0.checked = "true";
	document.frmCommSearch.comm_sup11.checked = "true";
	document.frmCommSearch.comm_rate_cus_0.checked = "true";
	document.frmCommSearch.comm_cus11.checked = "true";
	document.frmCommSearch.comm_rate_com_0.checked = "true";
	document.frmCommSearch.comm_com11.checked = "true";
	document.frmCommSearch.comm_rate_une_0.checked = "true";
	document.frmCommSearch.comm_rate_edu_0.checked = "true";
	document.frmCommSearch.comm_edu_HS.checked = "true";
	document.frmCommSearch.comm_rate_deg_0.checked = "true";
	document.frmCommSearch.comm_deg_agrienv.checked = "true";
	document.frmCommSearch.comm_wag11.checked = "true";
	document.frmCommSearch.comm_rate_wag_0.checked = "true";
	document.frmCommSearch.comm_ocu_density_all.checked = "true";
	document.frmCommSearch.comm_rate_ocu_0.checked = "true";	
	document.frmCommSearch.comm_rate_int_0.checked = "true";
	document.frmCommSearch.comm_rate_air_0.checked = "true";
	document.frmCommSearch.comm_rate_rai_0.checked = "true";

	//change cmd value so map gets cleared
	document.frmMain.cmd.value = "clear_comm_search";
	//clear dynamic labels
	document.frmMain.dynamic_county_labels.value = "";
	submitMapRequest();
}
function clearCommCheckBoxes()
{
	//clear checked values
        document.frmMain.comm_search_rows_checked.value = "";
	//clear out the community search criteria
	//reset to intro
	switchCommSearch(0);
	//clear tag links
 	clearTaggedLinks();
	//clear all checked boxes
  	var controlIndex;
  	var element;
  	var numberofControls = document.frmCommSearch.length;
	for (controlIndex = 0; controlIndex<numberofControls;controlIndex++)
	{
	  element = document.frmCommSearch[controlIndex];
	  if (element.type == "checkbox")
	  {
	    element.checked = false;
	  }		
	}	
}
function setCommSearch()  //restore checked values
{
  idlist = document.frmMain.comm_search_query.value;
  if (idlist != "")
  {
   istart = 0;
   found = 0;
   while (found != -1)
   {
    found = idlist.indexOf(",",found);  //found contains the position in the string of current ","
    if (found != -1) //there is a comma, get first string
    {
     	 s = idlist.substring(istart,found);
     	 if (s!= "")
     	 {
	   element = findObj(s);
	   if (element.type == "checkbox" || element.type=="radio")
	   {
	    element.checked = "true";
	    //for the first substring
 	    if (istart == 0 && s=="comm_pop_other")
	    {
   	      disablePopType('enable');
	    }
	   } else //link
	   {
	        element.style.backgroundImage = "url(images/checkmark.gif)";
    		element.style.backgroundPosition = "left center";
    		element.style.backgroundRepeat = "no-repeat";
    		element.name = "1"; //change name to 1 to save that it is "checked"
           }
     	 }
     	 istart = found + 1;
     	 found++;
    }//end if
   }//while
  }//end if  
}

function getCommSearchMap(){

	var controlIndex;
	var element;
	var numberofControls = document.frmCommSearch.length;
	var layerlist = "";
	var idlist = "";
	var foundAtPosition = 0;
	var thmindint = 0;
	var thmDiv = "comm_" + document.frmMain.comm_search_themelayer.value;  //ex. "comm_pop"
        var bAddToList = "false";
	var bSubmit = "true";  //default to true.  will flag to false if there is invalid data
        var bOther = "false";
	var iOtherCount = 0;
	//alert("700map.js - Comm Map theme: " + document.frmMain.comm_search_themelayer.value);
	//var int = 0;
	var thmind_count = 0;
	var bTheme = "true"; //is theme or is layer
	//check for interstates and turn on layer
  	switch (thmDiv)
	{
	  case "comm_interstate":
	  	//turn on layer
	  	lyr = findObj("lyr_trans1");
	  	lyr.checked = "true";
	  	bTheme = "false";
	  	//document.frmMain.comm_search_themelayer.value = "";
	  	createLayerList();
  	        break;
	  case "comm_airport":
		  //turn on layer
		  lyr = findObj("lyr_trans5");
		  lyr.checked = "true";
		  bTheme = "false";
		  //document.frmMain.comm_search_themelayer.value = "";
	 	 createLayerList();
 		break;
	  case "comm_railroad":
		  //turn on layer
		  lyr = findObj("lyr_trans4");
		  lyr.checked = "true";
		  bTheme = "false";
		  //document.frmMain.comm_search_themelayer.value = "";
        	  createLayerList();
	  case "comm_sup":
	  	//check box must be checked
		bSubmit = commSearchValidateNAICS("sup", "map"); //suppliers
		break;
   	  case "comm_cus":
	  	//check box must be checked
		bSubmit = commSearchValidateNAICS("cus", "map"); //customers
		break;
   	  case "comm_com":
	  	//check box must be checked
		bSubmit = commSearchValidateNAICS("com", "map"); //competitors
		break;
	  default: //default
		break;
        }
	var bManufAll = false;
	if (thmDiv != "" && bTheme == "true") 
        {  
	  //loop through controls to see if there are sub controls for our thmDiv
         //these sub controls will be our filter
	  for (controlIndex = 0; controlIndex<numberofControls;controlIndex++)
	  {
		element = document.frmCommSearch[controlIndex];
		//check for the correct thematic section
		foundAtPosition = element.id.indexOf(thmDiv);	
			if (foundAtPosition != -1) 
			{
				if (element.checked == true)
				{
					//for industry theme, if thm_33_all is there, then don't include other thm_3 checks
					//they can only check 5 at on time.
					if (thmDiv == "comm_cus" || thmDiv == "comm_sup" || thmDiv == "comm_com")
					{
						if (bManufAll == true) 
						{
							if(element.value.indexOf("3") != -1) //other manuf - don't add
							{
							   bAddToList = "false";
							}
						} else
						{
							bAddToList = "true";
							thmind_count = thmind_count + 1;
						}
						if (element.value == "thm_ind3_All")  //selected all manufacturing
						{
							bManufAll = true;
							bAddToList = "true";
						}

						
					} else
					{
					   if (element.value == "thm_pop_other")
					   {
						bOther = "true";

                                           }
					   if (bOther=="true") //they've checked other - keep track of how many categories they pick under other
					   {
						iOtherCount = iOtherCount + 1;
					   }
					   bAddToList = "true";
					}
					
				}
			}

		if (bAddToList == "true")
		{ 		  
			//add to the layerlist so we can create a thematic map
			layerlist = layerlist + element.value + ",";  
			//store id list so we can recheck the controls when the page comes back
			idlist = idlist + element.id + ",";
		}
		bAddToList = "false";
	  }
        }
	
	//-----DATA VALIDATION------------------------
	//Always set the thematic layer if it's a theme
	thematiclayer = "";
	if (bTheme == "true")
	{
	 if (thmDiv == "comm_cus" || thmDiv == "comm_sup" || thmDiv == "comm_com") //need to set the thematic layer appropriately
 	 {
		thematiclayer = "thm_ind";
	 }else
	 {
    	        thematiclayer = "thm_" + document.frmMain.comm_search_themelayer.value;
 	 }
	 document.frmMain.thematiclayer.value = thematiclayer;
	}
	if (layerlist != "")
	{		  
		  document.frmMain.thematicfilter.value = layerlist;
		  document.frmMain.comm_search_themefilter.value = idlist;
		  bSubmit = "true";
	} else
	{
		if (thematiclayer  != "") //is a theme without subcontrols - unemployment or household income
		{
		  document.frmMain.thematicfilter.value = thematiclayer; //set the filter = the thematic layer so it will launch the thematic map query
		
		}
	}
	//alert("836map.js- thematicfilter mainFrm = " + document.frmMain.thematicfilter.value);
	
	
	if (thmDiv == "comm_cus" || thmDiv == "comm_sup" || thmDiv == "comm_com")
	{
		if (thmind_count > 5 && bManufAll == false)
		{
			//don't submit - send warning
			alert("You may check up to 5 distinct industries.  Please narrow your selection and try again.")
			bSubmit = "false";
		}
	}
	//if they have chosen "other" make sure they've picked at least one subgroup.  Othewise they won't get a thematic map back.
	if (bOther == "true")
	{
		if (iOtherCount < 2) //it will == 1 if they have just clicked Other
		{
		 alert("Please choose at least one subcategory and retry.");
		 bSubmit = "false";
		}
	}
	//---------SUBMIT FORM------------
	if (bSubmit == "true")
	{
  	   //clear comm search
  	   document.frmMain.dynamic_county_labels.value = "";
  	   document.frmMain.cmd.value = "";

	   //switch to legend tab
	   document.frmMain.panel.value = "legend";
	   //submit form
	   submitMapRequest()
	}
}

function saveCommSearch() //save comm search state
{
  //loop through all the controls, save checked status
  var theForm = document.frmCommSearch
  var values = "";
  var found = 0;
  var s = "";
  for (i=0;i<theForm.elements.length;i++) {
    if (theForm.elements[i].checked) 
    {
  
 	s = s + theForm.elements[i].id + ",";
     }//
  } //end for
   
   var commSearchArray = new Array('pop','inc','sup','cus','com','une','edu','deg','wag','ocu','int','air','rai');
   for (i=0;i<commSearchArray .length;i++) 
   {
    thisLink = findObj("link_" + commSearchArray[i]);
    if (thisLink.name == "1")
    {
	s = s + thisLink.id + ",";
    }
   }

   //save to hidden input
   commSearch = findObj("comm_search_query");
   commSearch.value = s;

}

function commSearchShowAll(type)
{
   document.frmMain.cmd.value = "comm_search_show_all," + type;
   submitMapRequest();
}

function doCommSearch()
{
  //clear thematic map if one is there
  document.frmMain.thematiclayer.value = "";
  document.frmMain.thematicfilter.value = "";
  //set cur tool to comm_Search
  document.frmMain.cmd.value = "comm_search_first";
  //show results tab
   document.frmMain.comm_active_div.value = "results_comm";
  //submit form and do community search
  submitMapRequest();
}

// ##### PROPERTY SEARCH FUNCTIONS #####

function propSearchClickLine(id)
{
  //alert(id);
  document.frmMain.report_county_fips.Value = id;
  
}
function propSearchCheckRow(e, value, len)
{
  //add quotes to value
  value = "'" + value + "'";
  // Annoying code to get the desired event handler from the browser.
  if (!e) e = window.event; 
  var srcEl = e.target || e.srcElement;
  var curElement = srcEl;
   
  //ADD REMOVE FIPS
  currIDs= document.frmMain.prop_search_rows_checked.value;
  while (curElement && !(curElement.tagName == "TR"))
  {
     // Keep going until we reach the parent table row
     curElement = curElement.parentNode;
  }

  if (curElement != srcEl)
  {
     if (srcEl.checked)
     {        
	  //add to list
	  document.frmMain.prop_search_rows_checked.value = document.frmMain.prop_search_rows_checked.value + value + ",";
     }
     else
     {
	//remove fips from list
 	var found = currIDs.indexOf(value,0);
  	if (found != -1) //remove from list
	{
		len = len + 2;  //add 2 for the single quotes that we are adding in the js. 
          	var left = currIDs .substring(0,found);
				
		right = currIDs .substring(found + len + 1);
	        document.frmMain.prop_search_rows_checked.value = left + right;
	}
      }
   }
//  alert(document.frmMain.prop_search_rows_checked.value);
}
function doPropertySearch()
{
   //clear previously selected buildings and properties each time
	document.frmMain.prop_search_type.value = "";
	document.frmMain.prop_search_query.value = "";
	document.frmMain.selbuildings.Value = "";
	document.frmMain.selproperties.Value = "";
	
  //validate search criteria
var ok = validatePropSearch("frmSearchProp");
if (ok)
 {

  var type = "";
  //get search type - buildings or property
  property = findObj("proptype_land");
  if (property.checked)
  {
    //property search
    type = "site";
    disableSites();    
  }  
  property = findObj("proptype_bldg");
  if (property.checked)
  {
    type = "building";
    disableBuildings();
  }
  property = findObj("proptype_both");
  if (property.checked)
  {
    //property search
    type = "both";
    disableBoth();    
  } 
  
  document.frmMain.prop_search_type.value = type;
  document.frmMain.cmd.value = "prop_search";


   //GET THE PROPERTY SEARCH FORM
   theForm = findObj("frmSearchProp");

   //build where clause
   var sWhere = "";
   var ctVal = "";
   var bSubmit = false;
  //PROPERTY RELATED QUERIES
    sWhere = "land_min:";
    //check for "other" user defined value.  
    if (theForm.land_min.value == "other")
    {
	sWhere = sWhere + "other";
	sWhere = sWhere + ",land_min_other:" + theForm.land_min_other.value;
	bSubmit = true;
    }else  //get value from dropdown
    {
	val = theForm.land_min.value;
	sWhere = sWhere + val;
	if (val != "")
	{
	  bSubmit = true;
        }

    }   
    sWhere = sWhere + ",land_max:";
     //check for "other" user defined value. 
    if (theForm.land_max.value == "other")
    {
	sWhere = sWhere + "other";
	sWhere = sWhere + ",land_max_other:" + theForm.land_max_other.value;
	bSubmit = true;
    }else  //get value from dropdown
    {
	val = theForm.land_max.value;
	sWhere = sWhere + val;
	if (val != "")
	{
	  bSubmit = true;
        }

    }   
    sWhere = sWhere + ",prop_natural_gas:" + theForm.prop_natural_gas.value;
	val = theForm.prop_natural_gas.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",prop_fiber:" + theForm.prop_fiber.value;
	val = theForm.prop_fiber.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",prop_crane:" + theForm.prop_crane.value;
	val = theForm.prop_crane.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",prop_terms:" + theForm.prop_terms.value;
	val = theForm.prop_terms.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",prop_dist_to_int:" + theForm.prop_dist_to_int.value;
	val = theForm.prop_dist_to_int.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",prop_dist_to_air:" + theForm.prop_dist_to_air.value;
	val = theForm.prop_dist_to_air.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",prop_selected_interstate:" + theForm.prop_selected_interstate.value;
	val = theForm.prop_selected_interstate.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",prop_rail:" + theForm.prop_rail.value;
	val = theForm.prop_rail.value;
	if (val != "")
	{
	  bSubmit = true;
    }
    
    sWhere = sWhere + ",prop_state:" + theForm.prop_state.value;
    val = theForm.prop_state.value;
    if (val != "")
    {
      bSubmit = true;
     }
     
     sWhere = sWhere + ",prop_region:" + theForm.prop_region.value;
     val = theForm.prop_region.value;
     if (val != "")
    {
      bSubmit = true;
     }
     
     if(theForm.prop_region.value != "" && theForm.prop_county.value == "")
     {	
		sWhere = sWhere + ",prop_county:" + theForm.prop_county.options[1].value;
		for(i=2;i<theForm.prop_county.options.length;i++)
		{
			sWhere = sWhere + "#" + theForm.prop_county.options[i].value;		
		}     
     
     }
     else
     {
		sWhere = sWhere + ",prop_county:" + theForm.prop_county.value;
		val = theForm.prop_county.value;
		if (val != "")
		{
		    bSubmit = true;	   
	    }
     }
     
        
     
    sWhere = sWhere + ",prop_name:" + theForm.prop_name.value;
     val = theForm.prop_name.value;
     
     if (val != "")
    {
      bSubmit = true;
     }
     sWhere = sWhere + ",prop_id:" + theForm.prop_id.value;
     val = theForm.prop_id.value;
     if (val != "")
    {
      bSubmit = true;
     }
    
  //BUILDING RELATED QUERIES
  if (type == "building")
  {
    sWhere = sWhere + ",bldg_min:";
    if (theForm.bldg_min.value == "other")
    {
	sWhere = sWhere + "other";
	sWhere = sWhere + ",bldg_min_other:" + theForm.bldg_min_other.value;
        bSubmit = true;
    }else
    {
        sWhere = sWhere + theForm.bldg_min.value;
	val = theForm.bldg_min.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    }    
    sWhere = sWhere + ",bldg_max:";
    if (theForm.bldg_max.value == "other")
    {
	sWhere = sWhere + "other";
	sWhere = sWhere + ",bldg_max_other:" + theForm.bldg_max_other.value;
        bSubmit = true;
    }else
    {
        sWhere = sWhere + theForm.bldg_max.value;
	val = theForm.bldg_max.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    }
    //CEILING HT has OTHER possibility
    sWhere = sWhere + ",bldg_ceiling_ht:";
    if (theForm.bldg_ceiling_ht.value == "other")
    {
	sWhere = sWhere + "other";
	sWhere = sWhere + ",bldg_ceiling_ht_other:" + theForm.bldg_ceiling_ht_other.value;
	bSubmit = true;
    }else
    {
        sWhere = sWhere + theForm.bldg_ceiling_ht.value;
	val = theForm.bldg_ceiling_ht.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    }

    sWhere = sWhere + ",bldg_build_year:" + theForm.bldg_build_year.value;
	val = theForm.bldg_build_year.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",bldg_occupancy_type:" + theForm.bldg_occupancy_type.value;
	val = theForm.bldg_occupancy_type.value;
	if (val != "")
	{
	  bSubmit = true;
        }
    sWhere = sWhere + ",bldg_docks:" + theForm.bldg_docks.value;
	val = theForm.bldg_docks.value;
	if (val != "")
	{
	  bSubmit = true;
        }
  }

   ck = findObj("ck_prop_search_communities");
   if (ck.checked)
   {
     sWhere = sWhere + ",ck_prop_search_communities:true";
   }
   else
   {
     sWhere = sWhere + ",ck_prop_search_communities:false";
   }
  //UNCOMMENT IF THEY WANT TO MAKE THEM SELECT AT LEAST ONE SEARCH CRITERIA
  //COMMENTED OUT 3/30/2005 BECAUSE THEY SAID THEY WANTED TO SEARCH WITH NO CRITERIA AND RETURN ALL RESULTS
  //if (bSubmit == false)
  //{
  //	alert("Please choose at least one search criteria and try again.");
  //}
  //else
  //{
    document.frmMain.prop_search_query.value = sWhere;
    //submit form and do community search
    submitMapRequest();
   //}
 }

}

function setPropSearch()  //restore checked values
{

  
  
  
	idlist = document.frmMain.prop_search_query.value + ","; //need extra comma for the substrings
	//alert(document.frmMain.prop_search_query.value);
	var tmpStr = "";
	
  if (idlist != "")
  {
   istart = 0;
   found = 0;
   while (found != -1)
   {
    found = idlist.indexOf(",",found);  //found contains the position in the string of current ","
    if (found != -1) //there is a comma, get first string
    {
     	 s = idlist .substring(istart,found);
	 
      if (s!= "")
      {
	   //separate name and value
	   foundcolon = 0;
       foundcolon = s.indexOf(":",foundcolon);
	   if (foundcolon != -1) //there is a value
	   {
		sid = s.substring(0,foundcolon);
	    svalue = s.substring(foundcolon + 1);

		if (sid != "" && svalue != "")
		{
		  element = findObj(sid);
		  if(sid == "prop_name" || sid == "prop_id")
		  {
			element.value = svalue;
		  }
		  if (sid == "bldg_min_other" || sid == "bldg_max_other" || sid == "land_min_other" || sid == "land_max_other" || sid == "bldg_ceiling_ht_other")
		  {
			element.value = svalue;
			label = findObj(sid + "_label");
			label.style.display = "";
  		  } 
  		  else if (sid == "ck_prop_search_communities")
		  {
			if (svalue == "true")
			{
 			  element.checked = true;
			} 
			else
			{ 
			   element.checked = false; 
			}

		  } 
		  else  //they are all dropdown lists
		  {
		    //see if the value is in the list
		    //set the selected item = the one with this value
                t = 0;
		    if (sid == "prop_selected_interstate")
			{ 
			  t=21; 
			}
			if (sid == "prop_state")
			{
				t=3;
			}
			if (sid == "prop_region")
			{
				t=15;
			}
			if (sid == "prop_county")
			{
				t=146;
			}
		    if(sid == "land_min" || sid == "land_max")
			{
		   	  t=8;
			}
		    if (sid == "bldg_min")
			{ 
			  t=7; 
			}
		    if (sid == "bldg_ceiling_ht" || sid == "bldg_max" || sid == "prop_dist_to_int" || sid == "prop_dist_to_air")
			{ 
			  t=6; 
			}
		    if (sid == "bldg_docks")
			{ 
			  t=5; 
			}
		    if (sid == "bldg_build_year")
			{ 
			  t=4; 
			}
		    if (sid == "bldg_occupancy_type" || sid == "prop_terms")
			{ 
			  t=3; 
			}
		    if (sid == "prop_fiber" || sid =="prop_crane" || sid == "prop_rail" || sid == "prop_natural_gas")
			{ 
			  t=2; 
			}		
			
						  
		   
		   if(sid == "prop_county")
		   {
			  //alert("county length = " + element.options.length + " county val = " + svalue);
			for (i=0;i<element.options.length;i++)
			{
				
				if(element.options[i].value == svalue)
				{
					//alert("item = " + element.options[i].value + " value = " + svalue.substring(0,svalue.length - 5));
		  			element.options[i].selected = "true";		  	     
				}
			}
		   }
		   else
		   {	   		     
		   
			
			for (i=0;i<t;i++)
			{	
				if(element.options[i].value == svalue)
				{
		  			element.options[i].selected = "true";		  	     
				}
			}
		   }

		  }

	   	}
	   
           }
     	 }
     	 istart = found + 1;
     	 found++;
    }//end if
   }//while
  }//end if 
  
  var theForm = findObj("frmSearchProp");
  chkDiv = findObj("prop_search_communities");
  if(theForm.ck_prop_search_communities.checked == true && chkDiv.style.display != "none")
  {	
	disableLocation();
  } 
  if(document.frmMain.radius.value != "County")
  {
	disableLocation();
  }
 
 
}


function clearPropSearch()
{
	//set the form
	theForm = findObj("frmSearchProp");
	//CLEAR STORED VALUES
	document.frmMain.prop_search_type.value = "";
	document.frmMain.prop_search_query.value = "";
	document.frmMain.selbuildings.Value = "";
	document.frmMain.selproperties.Value = "";
	//document.frmMain.tool.value = "zoomin";
        document.frmMain.prop_search_rows_checked.value = "";
	

	//CLEAR SELECTED COMMUNITIES - issues database 3/30/05
	document.frmMain.selcounties.Value = "";

	//CLEAR COMMUNITY FILTER
	label = findObj("lbl_prop_search_communities");
	label.text = "";
	//SET TYPE TO BUILDING
 	building = findObj("proptype_bldg");
  	building.checked = "true";

  	//CLEAR PROPERTY RELATED QUERIES
    	theForm.land_min.selectedIndex = 0;
    	theForm.land_min_other.value = "";
    	theForm.land_max.selectedIndex = 0;
    	theForm.land_max_other.value = "";
	theForm.prop_natural_gas.selectedIndex = 0;
	theForm.prop_fiber.selectedIndex = 0;
	theForm.prop_crane.selectedIndex = 0;
	theForm.prop_terms.selectedIndex = 0;
	theForm.prop_dist_to_int.selectedIndex = 0;
	theForm.prop_dist_to_air.selectedIndex = 0;
	theForm.prop_selected_interstate.selectedIndex = 0;
	theForm.prop_rail.selectedIndex = 0;

	//CLEAR BUILDING RELATED QUERIES
	theForm.bldg_min.selectedIndex = 0;
	theForm.bldg_min_other.value;
 	theForm.bldg_max.selectedIndex = 0;
	theForm.bldg_max_other.value;
	theForm.bldg_ceiling_ht.selectedIndex = 0;
	theForm.bldg_build_year.selectedIndex = 0;
	theForm.bldg_occupancy_type.selectedIndex = 0;
	theForm.bldg_docks.selectedIndex = 0;	

	
	//submit form to clear the map and clear the stored values;
	document.frmMain.cmd.value = "clear_prop_search";
	submitMapRequest();
	
}
function clearPropBoxes()
{
	//set the form
	theForm = findObj("frmSearchProp");
	//CLEAR STORED VALUES
	document.frmMain.prop_search_type.value = "";
	document.frmMain.prop_search_query.value = "";
	document.frmMain.selbuildings.Value = "";
	document.frmMain.selproperties.Value = "";
	//document.frmMain.tool.value = "zoomin";
        document.frmMain.prop_search_rows_checked.value = "";
	
	//CLEAR SELECTED COMMUNITIES - issues database 3/30/05
	document.frmMain.selcounties.Value = "";

	//submit form to clear the map and clear the stored values;
	document.frmMain.cmd.value = "clear_prop_search";
	submitMapRequest();
}	

//****************** MY PROSPECTS FUNCTIONS ***********
function myCommPropCheckRow(e, value, len)
{
  value = "'" + value + "'"; //add quotes to value, can't pass it in with the quotes
  len = len + 2; //add 2 for the quotes

  // Annoying code to get the desired event handler from the browser.
  if (!e) e = window.event; 
  var srcEl = e.target || e.srcElement;
  var curElement = srcEl;
   
  //ADD REMOVE FIPS
  currIDs= document.frmMain.my_comm_prop_search_rows_checked.value;
  while (curElement && !(curElement.tagName == "TR"))
  {
     // Keep going until we reach the parent table row
     curElement = curElement.parentNode;
  }

  if (curElement != srcEl)
  {
     if (srcEl.checked)
     {        
	  //add to list
	  document.frmMain.my_comm_prop_search_rows_checked.value = document.frmMain.my_comm_prop_search_rows_checked.value + value + ",";
    }
    else
    {
	//remove fips from list
 	var found = currIDs.indexOf(value,0);
  	if (found != -1) //remove from list
	{
          	var left = currIDs.substring(0,found);
				
		right = currIDs .substring(found + len + 1);
	        document.frmMain.my_comm_prop_search_rows_checked.value = left + right;
	}
      }
   }

//alert (document.frmMain.my_comm_prop_search_rows_checked.value);
}

function myCommCommCheckRow(e, value, len)
{

  // Annoying code to get the desired event handler from the browser.
  if (!e) e = window.event; 
  var srcEl = e.target || e.srcElement;
  var curElement = srcEl;
   
  //ADD REMOVE FIPS
  currIDs= document.frmMain.my_comm_comm_search_rows_checked.value;
  while (curElement && !(curElement.tagName == "TR"))
  {
     // Keep going until we reach the parent table row
     curElement = curElement.parentNode;
  }

  if (curElement != srcEl)
  {
     if (srcEl.checked)
     {        
	  //add to list
	  document.frmMain.my_comm_comm_search_rows_checked.value = document.frmMain.my_comm_comm_search_rows_checked.value + value;
    }
    else
    {
	//remove fips from list
 	var found = currIDs.indexOf(value,0);
  	if (found != -1) //remove from list
	{
          	var left = currIDs.substring(0,found);
				
		right = currIDs.substring(found + len + 1);
	        document.frmMain.my_comm_comm_search_rows_checked.value = left + right;
	}
      }
   }
//alert ("string=" + document.frmMain.my_comm_comm_search_rows_checked.value);

}



//****************** CONTACT FUNCTIONS ***********
function displayContacts()
{
	layer = getLayer("dukecontacts"); 
	if (layer != null) 
        {
	  switchMainTabs('contacts');
	} else
	{
	  document.frmMain.tool.value = "Contacts,false";
	  document.frmMain.maintab.value = "contacts";
	  submitMapRequest();
	}
}

//****************** PRINT FUNCTIONS ***********
function doLayout_serverside()
{
	//create layer list
	createLayerList();
	frmMain.cmd.value = "print";
	submitMapRequest();
}
// do layout
function doLayout(){
  //print will create a new map image (because image is of a different size for print)
  //this means we have to send in the map info to the new print page.
  //we also have to update our existing image
	//create layer list
	createLayerList();

	layeritems = frmMain.layerlist.value;
	//create legend list
	
	//retrieve values needed for print
	theForm = document.frmMain;
	cmd = theForm.cmd.value;		
	minx = theForm.minX.value;
	miny = theForm.minY.value;
	maxx = theForm.maxX.value;
	maxy = theForm.maxY.value;
	markerlist = theForm.markerList.value;
	selX = theForm.selX.value;
	selY = theForm.selY.value;
	selC = theForm.selcounties.value;
	selB = theForm.selbuildings.value;
	selP = theForm.selproperties.value;
	radius = theForm.radius.value;
	layercount = theForm.layercount.value;
	legend = theForm.legendlayerlist.value;
	currentMapUrl = theForm.mapURL.value;
    mapSize = theForm.msize.value;
    
        //reset themes
    curTheme = document.frmMain.comm_search_themelayer.value;
	theForm.thematiclayer.value = curTheme;
	//curTheme = "thm_pop";
	theForm.thematicfilter.value = curThemeFilter;
	
	
	//alert("current theme: " + theForm.thematiclayer.value);
	//alert("current themefilter: " + theForm.thematicfilter.value);
       
	//create print url
	theURL = "Print.aspx?cmd="+cmd+"&layeritems="+layeritems+"&theme="+curTheme+"&minx="+minx+"&miny="+miny+"&maxx="+maxx+"&maxy="+maxy+"&markerlist="+markerlist+"&selC="+selC+"&selB="+selB+"&selP="+selP+"&selX="+selX+"&selY="+selY+"&radius="+radius+"&layercount="+layercount+"&thematicfilter="+curThemeFilter+"&legend="+legend+"&curmap="+currentMapUrl+"&msize="+mapSize;
	//open in a new window
	window.open(theURL);
	showLayer("splashScreen");
	
	submitMapRequest();
}