function validateLoginInfoForm(){
 with ( window.document.forms.LoginInfoForm) {
  if (select_site.selectedIndex == "0")
   {
    alert("Please select the site you would like to log in to.");
    select_site.focus();
    return false;
   }
  else if (userId.value.length == "")
   {
    alert("Your User ID is required. Please try again.");
    userId.focus();
    return false;
   }
  else if (pswd.value.length == "")
   {
    alert("Your Password is required. Please try again.");
    pswd.focus();
    return false;
   }
  else
   {
   expirationDate = new Date();
   expirationDate.setYear(expirationDate.getYear() + 5);
   document.cookie = "corpEntCd=OK1; expires=" + expirationDate.toGMTString() + "; path=/;";
   document.cookie = "sso=N; expires=" + expirationDate.toGMTString() + "; path=/;";
   document.cookie = "fep=N; expires=" + expirationDate.toGMTString() + "; path=/;";
   submitLoginInfoForm();
   }
 }
}


function submitLoginInfoForm(){
 with (window.document.forms.LoginInfoForm) {
  if (select_site.selectedIndex == "1")
   {
    document.forms.LoginInfoForm.action = "https://members.hcsc.net/members/servlet/com.hcsc.member.LoginServlet";
    return true;
   }
  else if (select_site.selectedIndex == "2")
   {
    document.forms.LoginInfoForm.dsUserId.value = document.forms.LoginInfoForm.userId.value;
    document.forms.LoginInfoForm.dsPassword.value = document.forms.LoginInfoForm.pswd.value;
    document.forms.LoginInfoForm.action = "https://producers.hcsc.net/producers/login.do";
    return true;
   }
  else if (select_site.selectedIndex == "3")
   {
    document.forms.LoginInfoForm.AccountField.value = document.forms.LoginInfoForm.userId.value;
    document.forms.LoginInfoForm.AccountPinField.value = document.forms.LoginInfoForm.pswd.value;
    document.forms.LoginInfoForm.action = "https://employers.hcsc.net/employers/L001";
    return true;
   }
 }
}


function clearForms(){
 document.getElementById("membersContext").style.display = "none";
 document.getElementById("producersContext").style.display = "none";
 document.getElementById("employersContext").style.display = "none";
 document.forms.LoginInfoForm.select_site.selectedIndex = "0";
 document.forms.LoginInfoForm.userId.value='';
 document.forms.LoginInfoForm.pswd.value='';
 document.forms.LoginInfoForm.select_site.focus();
 document.forms.ProvFinderForm.name.value='';
 document.forms.ProvFinderForm.location.value='';
 document.forms.ProvFinderForm.networkID.value='';
}


function toggleLayer( whichLayer ){
 switch(whichLayer){
  case "" :
   document.getElementById("membersContext").style.display = "none";
   document.getElementById("producersContext").style.display = "none";
   document.getElementById("employersContext").style.display = "none";
   break;
  case "membersContext" :
   document.getElementById("membersContext").style.display = "inline";
   document.getElementById("producersContext").style.display = "none";
   document.getElementById("employersContext").style.display = "none";
   break;
  case "producersContext" :
   document.getElementById("membersContext").style.display = "none";
   document.getElementById("producersContext").style.display = "inline";
   document.getElementById("employersContext").style.display = "none";
   break;
  case "employersContext" :
   document.getElementById("membersContext").style.display = "none";
   document.getElementById("producersContext").style.display = "none";
   document.getElementById("employersContext").style.display = "inline";
   break;
 }
}


/** The p_object parameter is the object that called
 *  this function (i.e., send 'this' (without the quotes)
 *  as a parameter).  If the object calling this function
 *  is determined to be a submit button, the form is not
 *  submitted via this function, thus preventing the form
 *  from being submitted twice.
 */
function submitProvFinderForm(p_object, p_actionType){
 with (window.document.forms.ProvFinderForm) {
  window.document.forms.ProvFinderForm.actionType.value = p_actionType;
  if (p_object.type != 'submit')
	{
		//only submit if the calling object is not a submit button
		// disableButtons(); 
		// Disabled on 8-14-09 - this function prevented users from changing input fields and re-submitting form without refreshing page
		window.document.forms.ProvFinderForm.submit();
	}
 }
}


// Runs through the all elements on the form,
// disabling all buttons.
// Note that we assume one form per page.  Throughout
// all of the functions in this JavaScript file, it is
// assumed that the submitted form is the only form, thus
// the references to forms[0].  Should we ever move away
// from this assumption, add an extra loop in this function
// to go through all forms in the document.

// 5/16/06 Added second loop becuase we can no longer assume one form per page!
function disableButtons()
{
	for (j=0; j<document.forms.length;j++){		
		if (document.forms.length == 0
		||  document.forms[j].elements.length == 0)
		{
			return;
		}
		for (i=0; i<document.forms[j].elements.length;i++)
		{
			var form_element = document.forms[j].elements[i];
			if (form_element.type == 'submit'
			||  form_element.type == 'button')
			{
				form_element.disabled = 'true';
			}
		}	
	}
}
