
formName = document.form;
var arrCities;

function DeleteProperty(PropertyId)
{
	if(confirm("Are you sure you want to delete this Property. This delete cannot be undone."))
		window.location = "PropertyDelete.asp?PropertyId=" + PropertyId
	 
}

function hideshow(sectionname, isSectionHidden)
{
	if ( sectionname.length > 0 )
	{
		elm = document.getElementById(sectionname);
		elm1 = document.getElementById(sectionname + "image");
		
		if (isSectionHidden )
		{
			elm.style.display = "block";
			elm.style.visiblity = "visible";
			elm.style.position = "static";
			elm1.src = "<%=collapseImage%>";
		}
		else
		{
			elm.style.display = "none";
			elm.style.visiblity = "hidden";
			elm.style.position = "absolute";
			elm1.src = "<%=expandImage%>";
		}
		
	}
	
}

function exportListChange(changeType)
{
	var list1,list2, item;
	
	list1 = formName.exportfieldlist;
	list2 = formName.exportSelectedFieldsList;
	
	if (changeType == "add all"  )
	{
		//loop through export field  list
		var len = list1.length;
		for (count=0;count<len;count++)
		{
		var newOption = document.createElement("OPTION");
		newOption.text = list1.options(0).text;
		newOption.value = list1.options(0).value;
		
		list1.options.remove(0);
		list2.options.add(newOption);    
		} 
		SortListBox( list2, 0, list2.length );
	}
	else if (changeType == "remove all"  )
	{
		//loop through export field  list
		var len = list2.length;
		for (count=0;count<len;count++)
		{
		var newOption = document.createElement("OPTION");
		newOption.text = list2.options(0).text;
		newOption.value = list2.options(0).value;

		list1.options.add(newOption);    
		list2.options.remove(0);
		 }
		 SortListBox( list1, 0, list1.length );
	}
	else if (changeType == "add" && (list1.selectedIndex >= 0) )
	{
		for (var i=0; i<list1.length; i++) 
                { 
                 	if(list1.options[i].selected ) 
                 	{
	                	var newOption = document.createElement("OPTION");
				newOption.text = list1.options(i).text;
				newOption.value = list1.options(i).value;
				list2.options.add(newOption);    
			}
		}
		for (var i=(list1.length-1); i>=0; i--) 
                { 
                 	if(list1.options[i].selected ) 
                 	{	
                 		list1.options[i].selected = false;
                		list1.options.remove(i);
			}
		}
    		SortListBox( list2, 0, list2.length );
        	
	}
	else if (list2.selectedIndex >= 0 )
	{
		for (var i=0; i<list2.length; i++) 
                { 
                 	if(list2.options[i].selected ) 
                 	{
	                	var newOption = document.createElement("OPTION");
				newOption.text = list2.options(i).text;
				newOption.value = list2.options(i).value;
				list1.options.add(newOption);    
			}
		} 
		for (var i=(list2.length-1); i>=0; i--) 
                { 
                 	if(list2.options[i].selected ) 
                 	{	
                 		list2.options[i].selected = false;
                		list2.options.remove(i);
			}
		}
		SortListBox( list1, 0, list1.length );
	}
	else
	{
		alert("Please select an item from the list.")
	}
	
}

function optswap( cboListBox, i, j )
{
   if ( i == j )
   {
      return (false);
   }

   with ( cboListBox )
   {
      var opttxt = options[i].text
      var optval = options[i].value
      var optsel = options[i].selected

      options[i].text      = options[j].text;
      options[i].value   = options[j].value;
      options[i].selected   = options[j].selected;

      options[j].text      = opttxt;
      options[j].value   = optval;
      options[j].selected   = optsel;
   }

   return (true);
}

function SortListBox( lstBox, start, end )
{
   // quick-sort algorithm for listbox widgets
   if ( start+1 < end )
   {
      var prevlow = start;

      for ( var i=start+1; i<end; ++i )
      {
         if ( lstBox.options[i].text.toUpperCase() < lstBox.options[start].text.toUpperCase() )
         {
            optswap( lstBox, i, ++prevlow );
         }
      }

      optswap( lstBox, start, prevlow );

      SortListBox( lstBox, start, prevlow );
      SortListBox( lstBox, prevlow+1, end );
   }
}


function submitExportForm(exportType)
{
	var exportFields, i;
	list = formName.exportSelectedFieldsList;
	exportFields = "";
	
		
	//build list of selected items from select box
	associatedDeptIds = "";
	for (i=0;i<list.length;i++)
	{	if (i > 0 ) exportFields += ",";
		exportFields  += list.options(i).value; 
	}
	
	formName.exportfields.value = exportFields;
	
	if (formName.exportfields.value.length == 0 ) 
	{	
		alert ("you must select at least one form field to export.")
	}
	else	 
	{
		form.exportType.value = exportType;
		formName.submit();
	}	
	
	var elm = document.getElementById("exporttool")
	elm.style.visibility = "hidden";
	
	
}


function sortPage(sortParams)
{
	formName.action = "?" + sortParams;
	formName.submit();
}

function reloadCities()  // pass in the current State index
 {
 	//arrCities was built on main page using cProperties.Search class
 	var curCountyIndex;
 	curCountyIndex = formName.county.selectedIndex;
 				
    	if ( curCountyIndex < 0 ) return;  // no county selected, so do nothing

    	var aryCityOpts = formName.location.options;  // points to city options array

    	aryCityOpts.length=0;  // first, clear the current City options ...
    	aryCityOpts.length++;  // add a new Option
	aryCityOpts[aryCityOpts.length-1].text  = "All";
	aryCityOpts[aryCityOpts.length-1].value  = "";
	
	// then re-load the City options with values for the current County
    	for ( var i=0; i<arrCities.length; i++ )
    	{
       		if(formName.county[curCountyIndex].value == arrCities[i][0]) 
		{
			aryCityOpts.length++;  // add a new Option, then put data in it (below)
			aryCityOpts[aryCityOpts.length-1].text  = arrCities[i][1];
			aryCityOpts[aryCityOpts.length-1].value = arrCities[i][1];
		} 	
	       
	}
	
 }
function reloadJurisdictions()  // pass in the current State index
 {
 	//arrCities was built on main page using cProperties.Search class
 	var curCountyIndex;
 	curCountyIndex = formName.county.selectedIndex;
 				
    	if ( curCountyIndex < 0 ) return;  // no county selected, so do nothing

    	var aryJurisdictionOpts = formName.Jurisdiction.options;  // points to city options array

    	aryJurisdictionOpts.length=0;  // first, clear the current City options ...
    	aryJurisdictionOpts.length++;  // add a new Option
	aryJurisdictionOpts[aryJurisdictionOpts.length-1].text  = "All";
	aryJurisdictionOpts[aryJurisdictionOpts.length-1].value  = "";
	
	// then re-load the City options with values for the current County
    	for ( var i=0; i<arrJurisdictions.length; i++ )
    	{
       		if(formName.county[curCountyIndex].value == arrJurisdictions[i][0]) 
		{
			aryJurisdictionOpts.length++;  // add a new Option, then put data in it (below)
			aryJurisdictionOpts[aryJurisdictionOpts.length-1].text  = arrJurisdictions[i][1];
			aryJurisdictionOpts[aryJurisdictionOpts.length-1].value = arrJurisdictions[i][1];
		} 	
	       
	}
	
 }

function reloadCities22(curStateIndex)  // pass in the current State index
 {
 		
    if ( curStateIndex < 0 ) return;  // no state selected, so do nothing

    var aryCityOpts = document.myform.selCity.options;  // points to selCity options array

    aryCityOpts.length=0;  // first, clear the current City options ...

    // then re-load the City options with values for the current State
    for ( var i=0,n=arrCities[curStateIndex].length; i<n; i++ )
    {
       //// the line below no longer works in IE5 (it works in IE4 and NS4+).
       // aryCityOpts[aryCityOpts.length-1] = new Option(aryCityData[curStateIndex][i].text,aryCityData[curStateIndex][i].value);
       //// therefore, it now takes three lines to do the same thing:

       aryCityOpts.length++;  // add a new Option, then put data in it (below)
       aryCityOpts[aryCityOpts.length-1].text  = aryCityData[curStateIndex][i].text;
       aryCityOpts[aryCityOpts.length-1].value = aryCityData[curStateIndex][i].value;
    }
 }


