/*
 ***********************************************************************
* Copyright by State of Michigan (Unpublished) - All rights reserved.
*********************************************************************
* Name:  insurance_agent_comp_criteria.js
*
* Description:  Client script for  Locating Insurance 
*               Agents Appointed by an Insurance Entity web page.
*
* Special Logic:  None
*
***********************************************************************
* Modification Log:
*
* Programmer      Date      Request No.      Version   Changes
* Doug Cook       10/24/02  N/A              1.0       Original Code                      
*
***********************************************************************
*/

// Function:  leftTrim
// Purpose: Remove the leading spaces from the search criteria fields.
function leftTrim(strLeftTrimString)
{
	return strLeftTrimString.replace(/^\s*/gi, "");
}

// Function:  rightTrim
// Purpose: Remove the trailing spaces from the search criteria fields.
function rightTrim(strRightTrimString)
{
	return strRightTrimString.replace(/\s+$/gi, "");
}

// Function: validateForm
// Purpose: Submit event for the form.  Verify the user completed the form
// correctly.
function validateForm()
{
	if (verifySelection())
	{
	  return true;
	}   
	else
	{
	  return false;
	}
}
    
// Function: verifySelection

function verifySelection()
{
	// Trim the leading and trailing spaces from the Insurance Entity, 
	// City, and Zip Code fields.  
	
	strToTrim = document.frmIndustryCriteria.txtInsuranceEntity.value;
	strToTrim = rightTrim(strToTrim);
	strToTrim = leftTrim(strToTrim);
	document.frmIndustryCriteria.txtInsuranceEntity.value = strToTrim;
	
 	strToTrim = document.frmIndustryCriteria.txtCity.value;
	strToTrim = rightTrim(strToTrim);
	strToTrim = leftTrim(strToTrim);
	document.frmIndustryCriteria.txtCity.value = strToTrim;
	
 	strToTrim = document.frmIndustryCriteria.txtZipCode.value;
	strToTrim = rightTrim(strToTrim);
	strToTrim = leftTrim(strToTrim);
	document.frmIndustryCriteria.txtZipCode.value = strToTrim;
	
	// The user is required to enter search criteria for the Insurance Entity, City,
	// and State or the Insurance Entity and Zip Code.

	if (document.frmIndustryCriteria.txtInsuranceEntity.value == "" || 
		document.frmIndustryCriteria.lstState.value == "")
	{
		alert("Criteria must be entered for the Insurance Entity and State.  Please try again.");
		return false;
	}
	else
	{
	    // Critieria for the Insurance Entity, City must be at least two characters
	    // if criteria is entered.  The Zip Code must be four characters in length.

		if (document.frmIndustryCriteria.txtInsuranceEntity.value != "")
		{
			if (document.frmIndustryCriteria.txtInsuranceEntity.value.length < 2)
			{
				alert("If you wish to search by Insurance Entity, you must enter at least 2 characters.  Please try again.");
				return false;
			}		
		}
		
		if (document.frmIndustryCriteria.txtCity.value != "")
		{
			if (document.frmIndustryCriteria.txtCity.value.length < 2)
			{
				alert("If you wish to search by City, you must enter at least 2 characters.  Please try again.");
				return false;
			}		
		}
		
		if (document.frmIndustryCriteria.txtZipCode.value != "")
		{
			if (document.frmIndustryCriteria.txtZipCode.value.length < 4)
			{
				alert("If you wish to search by Zip Code, you must enter at least 4 characters.  Please try again.");
				return false;
			}		
		}
	}
		
 	document.frmIndustryCriteria.action = "/fis/ind_srch/ins_agnt_comp/insurance_comp_list.asp";
	return true; 
}
	
