
function AuthLogin_onSubmit( form )
{
	if( navigator.appVersion.indexOf( "MSIE 3.0;" ) != -1 )
	{
		// Some IE 3.0 folks had trouble with this JavaScript
		return true;
	}
	else if( !form.etis.value )
	{
		alert( "A site ID is required..." );
		return false;
	}
	else if( !form.resu.value )
	{
		alert( "A user name is required..." );
		return false;
	}
	else if( !form.ssap.value )
	{
		alert( "A password is required..." );
		return false;
	}
	else
	{
		//
		// Use the site ID provided in the cookie over that provided
		// by the form. This allows changing site ID's without having
		// to reload the login page to login.
		//
		var allcookies = document.cookie;
		var pos = allcookies.indexOf("site=");
		var site;
		var application;

		if ( pos != -1 )
		{
			var start = pos + 5;
			var end = allcookies.indexOf(";", start);
			if (end == -1) end = allcookies.length;
			site = allcookies.substring(start, end);
		}
		else site = form.etis.value;

		var authtype;

		if ( form.auth )
		{
			if ( form.auth.value == "site" )
			{
				site = form.etis.value;
			}
			authtype = form.auth.value;
		}

		var url = document.URL;
		pos = url.indexOf("app=");

		if ( pos != -1 )
		{
			var start = pos + 4;
			var end = url.indexOf("&", start);
			if (end == -1) end = url.length;
			application = url.substring(start, end);
		}

		return AuthLogin_login( site, form.resu.value, form.ssap.value, authtype, application );
	}
}

function AuthLogin_login( site, user, pass, auth, app )
{
	var nextYear = JavaScript_nextYear( );

	document.cookie = "site=" + site + "; path=/; expires=" + nextYear;
	if ( auth )
	{
		if ( auth != 'site' )
		{
			document.cookie = "site=" + site + "; path=/; expires=" + nextYear;
		}
		else document.cookie = "site=" + site + "; path=/";
	}
	document.cookie = "user=" + user + "; path=/; expires=" + nextYear;
	document.cookie = "pass=" + pass + "; path=/";

	// used to override the default app in the auth system for developers
  if ( app != undefined )
  {
    document.cookie = "app=" + app + "; path=/";
  }
	return true;
}
