// Checks / unchecks checkboxes.

var checkflag = "false";

function check(field) {

if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}

// set the hidden "action" field of a form to a specified String value
// the form index starts at 0
// example:  setAction('search',1);

function setAction(actionKey, formIndex)
{
	if (arguments.length < 2)
	{
		formIndex = 0;
	}
	document.forms[formIndex].action.value = actionKey;
}



// set the hidden "pagesubmitByUser" field of a form to TRUE
// the form index starts at 0
// example:  setPageSubmitByUser();

function setPageSubmitByUser(formIndex)
{
	if (arguments.length == 0)
	{
		formIndex = 0;
	}
	
	if (document.forms[formIndex].pageSubmitByUser != null)
	 {
  	   document.forms[formIndex].pageSubmitByUser.value = 'true';
  	 }
}



// required by the <tabs> taglib
function submitIfFormValid(tabIdentifier, url) 
{
	document.location.href = url;
}



// expand or collapse a DIV element with a particular ID
// used for category/specialty select fields
function expandIt(whichEl) 
{
	if (navigator.appName == 'Microsoft Internet Explorer')	
	{
			whichEl.style.display = (whichEl.style.display == "block" ) ? "none" : "block";
	}
	else
	{ 
		return;
	}
}



// called before expandIt()
// writes the proper browser-specific style in the page
function writeExpandStyles()
{
	with (document) 
	{
		write("<STYLE TYPE='text/css'>");
		if (navigator.appName == 'Microsoft Internet Explorer')	
		{
			write(".hiddentext {display:none}  .outline {cursor:hand}");
		}
		write("</STYLE>");
	}
}

// Deselects the State from the County drop down.

function deselectState(dropDown)
  {
    //var countyDropDown = document.forms[0].countiesCd;

    if (dropDown.options[dropDown.selectedIndex].value == '')
      {
        dropDown.selectedIndex = 0;
      }
   }

// clears a multi-select field a resets the default option
function clearMultiSelect(fieldName, defaultText)
{
	document.forms[0].elements[fieldName].options.length = 0;
	document.forms[0].elements[fieldName].options[0] = new Option(defaultText, '', false, false);
}


// enables the Category multiselect box and disables the Specialty multiselect box
function activateCategory(defaultOption) 
{
	document.forms[0].catorspec[0].checked = true;
	document.forms[0].categoriesCd.disabled  = false; 
	document.forms[0].specialtiesCd.disabled = true; 
	
	document.forms[0].specialtiesCd.options.length = 1;
	document.forms[0].specialtiesCd.options[0] = new Option(defaultOption);
}


// enables the Specialty multiselect box and disables the Category multiselect box
function activateSpecialty(defaultOption) 
{
	document.forms[0].categoriesCd.disabled  = true; 
	document.forms[0].specialtiesCd.disabled = false; 
	
	document.forms[0].categoriesCd.options.length = 1;
	document.forms[0].categoriesCd.options[0] = new Option (defaultOption);	
}

// called after the category and specialty fields are rendered.  
// disables both by default.
// if user has already seelcted values for category or specialty, the
//   appropriate select box is enabled
function activateCategoryOrSpecialty()
{
	// both fields are disabled by default
	document.forms[0].categoriesCd.disabled  = true;
	document.forms[0].specialtiesCd.disabled = true;
	
	// if values are defined for categopry or specialty, turn on one field and trun off the other
	if (document.forms[0].categoriesCd.options.length > 0 && document.forms[0].categoriesCd.options[0].value.length > 0)
	{
		activateCategory();	
	}
	else if (document.forms[0].specialtiesCd.options.length > 0 && document.forms[0].specialtiesCd.options[0].value.length > 0)
	{
		activateSpecialty();
	}
}

function activateZipsorCounties()
 {
   if (document.forms[0].disableZips.value == "true")
    {
      activateCounties();
    }
   else if (document.forms[0].disableZips.value == "false")
   {
    activateZips();
   }
 }

function activateSectionCounties() 
{

	document.forms[0].countiesCd.disabled  = false;
	//set the zip cd to empty
	document.forms[0].countiesCd.value = "";
	document.forms[0].disableSectionZips.value="true";

	//set the distanceRangeCd to it's default value
	document.forms[0].distanceRangeCd.options.selectedIndex=0;
	
	//disable the fields
	document.forms[0].zipsCd.readonly = true; 
	document.forms[0].zipsCd.disabled = true; 
	document.forms[0].distanceRangeCd.disabled = true;
	
	document.forms[0].countiesorzips[0].checked = true;
}

function activateCounties() 
{
	document.forms[0].globalCountiesCd.disabled  = false;
	//set the zip cd to empty
	document.forms[0].globalZipsCd.value = "";
	document.forms[0].disableZips.value="true";
	//set the globalDistanceRangeCd to it's default value
	document.forms[0].globalDistanceRangeCd.options.selectedIndex=0;
	
	//disable the fields
	document.forms[0].globalZipsCd.readonly = true; 
	document.forms[0].globalZipsCd.disabled = true; 
	document.forms[0].globalDistanceRangeCd.disabled = true;
	
	document.forms[0].countiesorzips[0].checked = true;
}


function activateZips() 
{
	document.forms[0].disableZips.value="false";
	document.forms[0].globalCountiesCd.disabled  = true;
	document.forms[0].globalZipsCd.readonly = false;
	document.forms[0].globalZipsCd.disabled = false;
	document.forms[0].globalDistanceRangeCd.disabled = false;
	
	document.forms[0].countiesorzips[1].checked = true;
}

function activateSectionZips() 
{
	document.forms[0].disableSectionZips.value="false";
	document.forms[0].countiesCd.disabled  = true;
	document.forms[0].zipsCd.readonly = false;
	document.forms[0].zipsCd.disabled = false;
	document.forms[0].distanceRangeCd.disabled = false;
	document.forms[0].countiesorzips[1].checked = true;
}

// deactivates the county and zips/distance fields
function deactivateCountiesAndZips()
{
	document.forms[0].globalCountiesCd.disabled  = true;
	document.forms[0].globalZipsCd.disabled = true;
	document.forms[0].globalZipsCd.readonly = true;
	document.forms[0].globalDistanceRangeCd.disabled = true;
	document.forms[0].countiesorzips[0].checked = false;
	document.forms[0].countiesorzips[1].checked = false;
}

// deactivates the section county and zips/distance fields
function deactivateSectionCountiesAndZips()
{
	document.forms[0].countiesCd.disabled  = true;
	document.forms[0].zipsCd.disabled = true;
	document.forms[0].zipsCd.readonly = true;
	document.forms[0].distanceRangeCd.disabled = true;
	document.forms[0].countiesorzips[0].checked = false;
	document.forms[0].countiesorzips[1].checked = false;
}

