
function OnSubmit()
{
	SetInnerText( "errmsg", "" );

	var user = document.getElementById( "user" ).value;
	var pass = document.getElementById( "pass" ).value;
	var domn = document.getElementById( "domn" );
	var newp = document.getElementById( "newp" );
	var conf = document.getElementById( "conf" );

	var msg   = "";
	var focus = null;

	if( user == "" )
	{
		msg   = "Enter a user ID.";
		focus = "user";
	}
	else if( pass == "" )
	{
		msg   = "Enter a password.";
		focus = "pass";
	}
	else if( domn && domn.value == "" )
	{
		msg   = "Enter a domain name.";
		focus = "domn";
	}
	else if( document.getElementById( "chgp" ).value )
	{
		if( newp && newp.value == "" )
		{
			msg   = "Enter a new password.";
			focus = "newp";
		}
		else if( conf && conf.value == "" )
		{
			msg   = "Enter a confirm password.";
			focus = "conf";
		}
		else if( newp && conf && newp.value != conf.value )
		{
			msg   = "The new password and the confirm password do not match.";
			focus = "conf";
		}
	}

	if( msg != "" )
	{
		alert( msg );
		SetFocus( focus );
		return false;
	}
	else
		return true;
}

function SetFocus( id )
{
    var obj = document.getElementById(id);

    if (obj) 
    {
        obj.focus();
        
        if (obj.select)
            obj.select();
    }
}

function ShowRow( id )
{
	var e = document.getElementById( id );
	if( e )
		e.style.display = "";
}

function HideRow( id )
{
	var e = document.getElementById( id );
	if( e )
		e.style.display = "none";
}

function ChgPass()
{
	ShowRow( "tr_new" );
	ShowRow( "tr_cnf" );
	ShowRow( "tr_can" );
	HideRow( "tr_chp" );
	SetFocus( "newp" );
	SetInnerText( "errmsg", "" );
	document.getElementById( "chgp" ).value = "1";
	document.getElementById( "main" ).style.color = "#000001"; // force redraw in Safari
}

function CancelChgPass()
{
	HideRow( "tr_new" );
	HideRow( "tr_cnf" );
	HideRow( "tr_can" );
	ShowRow( "tr_chp" );
	SetFocus( "pass" );
	document.getElementById( "chgp" ).value = "";
	document.getElementById( "main" ).style.color = "#000000"; // force redraw in Safari
}

function SetInnerText( elem, text )
{
	if( typeof( elem ) == "string" )
		elem = document.getElementById( elem );
	if( typeof( elem.innerText ) != "undefined" )
		elem.innerText = text;
	else
		elem.textContent = text;
}

function CheckPasswordExpires( days )
{
	if( confirm( "Your password will expire in " + days + " day(s).\nWould you like to change your password now?" ) )
		ChgPass();
	else
		window.location.href = "../default.aspx";
}
