

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
	oldonload();
      }
      func();
    }
  }
}




function makeTableRowAppearWhenTypeIsOther() {
  if (document.getElementById("organizationtype")) {
    var referenceToSelectBox = document.getElementById("organizationtype");
    // an example that works:
    // document.form1.select2.options[document.form1.select1.selectedIndex].value);
    var valueOfSelectBox = referenceToSelectBox.value;
    if (valueOfSelectBox == undefined) valueOfSelectBox = referenceToSelectBox.selectedIndex.value;
    if (valueOfSelectBox == "Other") {
      if (document.getElementById("explainOrganizationType")) {
	var referenceToTableRowToMakeVisible = document.getElementById("explainOrganizationType");
	referenceToTableRowToMakeVisible.style.display = "block"; 
	var referenceToTableRowToMakeVisible = document.getElementById("explainOrganizationType2");
	referenceToTableRowToMakeVisible.style.display = "block"; 
      }
    }
  }
}




addLoadEvent(function() {
	       makeTableRowAppearWhenTypeIsOther(); 
	     });



addLoadEvent(function() {
	       if (document.getElementById("organizationtype")) {
		 var referenceToSelectBox = document.getElementById("organizationtype");
		 referenceToSelectBox.onchange = function() {
		   makeTableRowAppearWhenTypeIsOther(); 
		 }
	       }
	     });










// this function gets the cookie, if it exists
// code stolen from here: 
// http://techpatterns.com/downloads/javascript_cookies.php
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}





function setCookiesAsFormValues() {
  var password = Get_Cookie("formInputs[password]");
  var username = Get_Cookie("formInputs[username]"); 
  if (document.getElementById("username")) {
    var referenceToUserNameInput = document.getElementById("username");
    referenceToUserNameInput.value = username; 
  }
  if (document.getElementById("password")) {
    var referenceToPassword = document.getElementById("password"); 
    referenceToPassword = password; 
  }
}


addLoadEvent(function() {
	       if (document.getElementById("loginForm")) {
		 setCookiesAsFormValues(); 
	       }
	     });






