
function checkFields ( theForm )
{

    //USERNAME
	var x = new String(theForm.username.value); //get string for checking

	// check for all spaces
	var spacesx="";
    for (var i=0; i <x.length; i++)
    {
        spacesx = spacesx + " ";
    }
    if (x == spacesx)
    {
        theForm.username.value="";
        alert('You must enter a valid user name');
        theForm.username.focus();
        return false;
    }

   	// strip leading whitespace
	for (var i=0; i <x.length; i++)
	{
		var first_char = x.charAt(0);
		if (first_char == " ")
		{
			x = x.substring(1, x.length)
		}
	}
	// strip ending whitespace
	for (var i=0; i <x.length; i++)
	{
		var last_char = x.charAt(x.length-1);
		if (last_char == " ")
		{
			x = x.substring(0, x.length-1)
		}
	}

	theForm.username.value=x; //put the striped whitespace back on form

	if (x.length == 0)
	  {
		    alert('You must enter a valid user name');
		    theForm.username.focus();
		    return false;
	  }	

	// PASSWORD Validation
	if (theForm.password != null)
    {
        var y = new String(theForm.password.value); //get string for checking

        // check for all spaces
        var spacesy="";
        for (var i=0; i <y.length; i++)
        {
            spacesy = spacesy+" ";
        }
        if (y == spacesy)
        {
            theForm.password.value="";
            alert('You must enter a valid password');
            theForm.password.focus();
            return false;
        }

        // strip leading whitespace
        for (var i=0; i <y.length; i++)
        {
            var first_char = y.charAt(0);
            if (first_char == " ")
            {
                y = y.substring(1, y.length)
            }
        }

        // strip ending whitespace
        for (var i=0; i <y.length; i++)
        {
            var last_char = y.charAt(y.length-1);
            if (last_char == " ")
            {
                y = y.substring(0, y.length-1)
            }
        }

        theForm.password.value=y; //put the striped whitespace back on form

        if (y.length == 0)
          {
                alert('You must enter a valid password');
                theForm.password.focus();
                return false;
          }
    }

    //GROUP
    if (theForm.groupname != null)
    {
        var x = new String(theForm.groupname.value); //get string for checking

        // strip leading whitespace
        for (var i=0; i <x.length; i++)
        {
            var first_char = x.charAt(0);
            if (first_char == " ")
            {
                x = x.substring(1, x.length)
            }
        }

        // strip ending whitespace
        for (var i=0; i <x.length; i++)
        {
            var last_char = x.charAt(x.length-1);
            if (last_char == " ")
            {
                x = x.substring(0, x.length-1)
            }
        }

        theForm.groupname.value=x; //put the striped whitespace back on form

        if (x.length == 0)
          {
                alert('You must enter a valid group name');
                theForm.groupname.focus();
                return false;
          }
    }

	return true;
}

//Function to load the  initial page as a child window (written to handle sessions)
function loadFirstPage(url)
    {
        if(navigator.userAgent.indexOf("MSIE 6.0")>=0)
        {
            //alert(navigator.appVersion);
            testwindow=window.open(url,'');
            /*testwindow.moveTo(0,0);
            testwindow.resizeTo(screen.width,screen.height);*/
            self.opener=testwindow;
            self.close();
        }
       else
        window.open(url,'_self');
    }

