/*

 ***********************************************************************

* Copyright by State of Michigan (Unpublished) - All rights reserved.

*********************************************************************

* Name:  insurance_agency_criteria.js

*

* Description:  Client script for the Insurance Agency Criteria web page.

*

* Special Logic:  None

*

***********************************************************************

* Modification Log:

*

* Programmer      Date      Request No.      Version   Changes

* Doug Cook       09/21/01  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

// Purpose: Trim the leading and trailing spaces from the License Number, Insurance Agency, 

// City, and Zip Code fields.  

function verifySelection()

{

	// Trim the leading and trailing spaces from the System ID, License Number, Insurance

	// Agency, City, and Zip Code fields.  



 	strToTrim = document.frmIndustryCriteria.txtSystemID.value;

	strToTrim = rightTrim(strToTrim);

	strToTrim = leftTrim(strToTrim);

	document.frmIndustryCriteria.txtSystemID.value = strToTrim;



 	strToTrim = document.frmIndustryCriteria.txtLicenseNumber.value;

	strToTrim = rightTrim(strToTrim);

	strToTrim = leftTrim(strToTrim);

	document.frmIndustryCriteria.txtLicenseNumber.value = strToTrim;

	

 	strToTrim = document.frmIndustryCriteria.txtInsuranceAgency.value;

	strToTrim = rightTrim(strToTrim);

	strToTrim = leftTrim(strToTrim);

	document.frmIndustryCriteria.txtInsuranceAgency.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 at least one of the items below.

	

	if (document.frmIndustryCriteria.txtSystemID.value == "" &&

	    document.frmIndustryCriteria.txtLicenseNumber.value == "" &&

		document.frmIndustryCriteria.txtInsuranceAgency.value == "" &&

		document.frmIndustryCriteria.txtCity.value == "" &&

		document.frmIndustryCriteria.lstState.value == "" &&

		document.frmIndustryCriteria.txtZipCode.value == "")

	{

		alert("Criteria must be entered for at least one of the listed items.  Please try again.");

		return false;

	}



	// Ensure that the license number/federal ID number is formatted properly (99-9999999).

	

	if (document.frmIndustryCriteria.txtLicenseNumber.value != "")

	{

	  strCompare = document.frmIndustryCriteria.txtLicenseNumber.value

	  

	  strPattern = /\d\d\-\d\d\d\d\d\d\d/g;

	  strResult = strCompare.match(strPattern);

	  	  	  

	  // The Match function returns an array if the match is successful.  

	  

	  if (strResult != null)

	  {

        // Remove the - from the license number and place this value into a hidden column to

		// be used as search criteria for the list page.

		strHyphenRemoved = strCompare.substr(0,2) + strCompare.substr(3,10);

        document.frmIndustryCriteria.txtHiddenLicenseNumber.value = strHyphenRemoved;

	  }

	  else

	  {

	    alert("The License Number/Federal ID Number is not properly formatted (99-9999999).  Please try again.");

		return false;

      }  

	}



	// If the criteria for the system ID number is entered, the number must be formatted properly (all numerics).

		

	if (document.frmIndustryCriteria.txtSystemID.value != "" )

	{

		strCompare = document.frmIndustryCriteria.txtSystemID.value;

		

		if (strCompare.match(/\d\d\d\d\d\d\d/) == null)

		{

			alert("The System ID Number must contain 7 digits.  Please try again.");

			return false;



		}



	}



	// If the criteria for the state is entered, there must be additional criteria entered.

		

	if (document.frmIndustryCriteria.lstState.value != "" &&

		document.frmIndustryCriteria.txtSystemID.value == "" &&

	    document.frmIndustryCriteria.txtLicenseNumber.value == "" &&

		document.frmIndustryCriteria.txtInsuranceAgency.value == "" &&

		document.frmIndustryCriteria.txtCity.value == "" &&

		document.frmIndustryCriteria.txtZipCode.value == "")

	{

		alert("If you select a State, you must enter criteria in at least one other column.  Please try again.");

			return false;		

	}





    // If the Insurance Agency Name or City have a single quote, modify the single quote

	// to two single quotes so it will be compatible with Oracle.

    

    strTemp = document.frmIndustryCriteria.txtInsuranceAgency.value.replace(/\'/g, "''");

	document.frmIndustryCriteria.txtInsuranceAgencySQL.value = strTemp;

 

    strTemp = document.frmIndustryCriteria.txtCity.value.replace(/\'/g, "''");

	document.frmIndustryCriteria.txtCitySQL.value = strTemp;









	document.frmIndustryCriteria.action = "/fis/ind_srch/ins_agcy/insurance_agency_list.asp";

	return true; 

}

	







	






