/*
*********************************************************************
* autoinsc.js
***********************************************************************
*/

// Function: unCheckProfileAll
// Purpose: Unchecks the Select All Profiles check box when any
// individual check box is clicked.
function unCheckProfileAll()
{
	document.frmAutoInsuranceRateGuide.chk_PR00000000.checked=false;
}

// Function: unCheckTerrAll
// Purpose: Unchecks the Select All Territories check box when any
// individual check box is clicked.
function unCheckTerrAll()
{
	document.frmAutoInsuranceRateGuide.chk_TR00000000.checked=false;
}

// Function: unCheckInsurAll
// Purpose: Unchecks the Select All Insurance Companies check box when any
// individual check box is clicked.
function unCheckInsurAll()
{
	document.frmAutoInsuranceRateGuide.chk_IN00000000.checked=false;
}


// Function: validateForm
// Purpose: Submit event for the form.  Verify the user complete the form
// correctly.
function validateForm()
{
	if (verifySelection()) {
	  return true; 
	}
	else
	{
	  return false;
	}   
}

// Function: verifySelection
// Purpose: Verify the user selected at least one example, territory, and insurance company.
function verifySelection()
{
	var blnProfileSelected = false;
	var blnTerritorySelected = false;
	var blnInsuranceSelected = false;

	var strCheckBoxName;

    // Loop through all of the elements on the form and determine if an example and territory
	// were selected.
    for (lngCounter=0; lngCounter < document.frmAutoInsuranceRateGuide.elements.length; lngCounter++)
    {
      if (document.frmAutoInsuranceRateGuide.elements[lngCounter].checked){
	    strCheckBoxName = document.frmAutoInsuranceRateGuide.elements[lngCounter].name;
	   
	    if (strCheckBoxName.substr(0,6) == "chk_PR") {
	      blnProfileSelected = true;
        }
		else
		{
		  if (strCheckBoxName.substr(0,6) == "chk_TR") {
		    blnTerritorySelected = true;
		  }	
		  else
		  {
		    if (strCheckBoxName.substr(0,6) == "chk_IN") {
			  blnInsuranceSelected = true;
			}  
		  }	  
		}	 
	  }	
    }

	// Display an error message if no examples have been selected.  Also, return false
	// from this function so the form is not submitted.
	if (!blnProfileSelected) {
	  alert("No Profiles have been selected.  Please select Profiles and try again.");
	  return false;
	}
	
    // Display an error message if no territories have been selected.  Also, return false
	// from this function so the form is not submitted.
	if (!blnTerritorySelected) {
	  alert("No Territories have been selected.   Please select Territories and try again.");
	  return false;
	}
	
	
    // If no insurance companies were selected, display an error message.  Also, return false
	// from this function so the form is not submitted.
	if (!blnInsuranceSelected) {
          alert("No Insurance Companies have been selected.  Please select Insurance Companies and try again.");
	  return false;
	}
    return true;	
}
