/*****************************************
Logon Brick Methods
Max D. Grabowski v1.0 4/20/09
*****************************************/

function getAAID()
  {
    var aaList     = document.getElementById('accountType');
    var aaSelected = actType.selectedIndex;
    var aaValue    = 0;
   
    if (aaSelected < 1) // something other than first option is selected
    {
      var retValue = actType.options[selIdx].value;
    }
    return aaValue;
  }
  
  function setAAIndex()
  {
    // Set default index
	var index = 0;
	
	// Check if cookie exists to override index
	if (getCookie("account_access_selected") != null)
	{
	  index = getCookie("account_access_selected");
	}
	
	// Set index
	var obj = document.getElementById('accountType');
      obj.selectedIndex = index;
	
	// Set links associated with index
      setAALinks();
  }
  
  function setAALinks()
  {
     // get current selection index
	 var obj = document.getElementById('accountType');
     var index = obj.selectedIndex;
	 
	 // Set variables for hyperlinks
	 var aaLogonBtn = document.getElementById("acct_access_log_on_button");
	 var aaLearnBtn = document.getElementById("acct_access_learn_more_button");
	 var aaLogon    = document.getElementById("logon_link_" + index);
	 var aaLearn    = document.getElementById("learn_link_" + index);
	 
	 	 
	 // Get href, onclick values for index
	 if (index > 0)
	 {
	   aaLogonBtn.href    = aaLogon.href;
         if(aaLogon.onclick == null)
         {
           aaLogonBtn.setAttribute('onclick', 'event.returnValue=true; return true;');
         }
         else
         {
           aaLogonBtn.onclick = aaLogon.onclick;
         }
         if(aaLearn.onclick == null)
         {
           aaLearnBtn.setAttribute('onclick', 'event.returnValue=true; return true;')
         }
         else
         {
           aaLearnBtn.onclick = aaLearn.onclick;
         }
         aaLearnBtn.href = aaLearn.href;
	  
         //alert(aaLogonBtn.href+" : "+aaLogonBtn.onclick);

	 }
	 else
	 {
	   aaLogonBtn.href = "javascript:alert('Please select a service to log on to.');";
	   aaLogonBtn.setAttribute('onclick', 'alert("Please select a service to log on to."); event.returnValue=false; return false;')
	   aaLearnBtn.href = "javascript:alert('Please select a service to learn about.');";
	   aaLearnBtn.setAttribute('onclick', 'javascript:alert("Please select a service to learn about."); event.returnValue=false; return false;');
	 }
	 
	 // Update cookie
	 setCookie("account_access_selected", index);
  }

 function setCookie(name, value)
 {
   var date = new Date();
   date.setTime(date.getTime()+(365*24*60*60*1000));
   var expires = "; expires="+date.toGMTString();
   document.cookie = name+"="+value+expires+"; path=/";
 }
 function getCookie(name)
 {
   var nameString = name + "=";
   var cookies = document.cookie.split(';');
   for(var i=0;i < cookies.length;i++)
   {
     var cookie = cookies[i];
     while (cookie.charAt(0)==' ')
	 {
	   cookie = cookie.substring(1,cookie.length);
     }
     if (cookie.indexOf(nameString) == 0)
	 {
       return cookie.substring(nameString.length,cookie.length);
     }
   }
   return null;
 }