
function focus ( sId )
{
    document.getElementById ( sId ) . focus  ( );
}

function init ( )
{
    var focusedFirstField = 0;
    
    var inputFields = document.getElementsByTagName ("INPUT");

    for ( i = 0; i < inputFields.length; i++ )
    {
        if ( inputFields[i].type == 'text' || inputFields[i].type == 'password' || inputFields[i].type == 'file' )
        {
            if ( !focusedFirstField )
            {
                inputFields[i].focus ( );
                
                focusedFirstField = 1;
            }
            inputFields[i].onfocus = function ( ) { this.className = 'focused'; return false; }

            inputFields[i].onblur = function ( ) { this.className = 'blurred'; return false; }
        }
    }
}

var fields = 0;

function write_field ( how_many )
{
    if ( fields > 50 )
    {
        return false;
    }
    box = document.getElementById('fields_box');

    for ( i = 0; i < how_many; i++ )
    {
        fields++;

        box.innerHTML += '<div style="margin-bottom:1px;background-color:' + ( fields % 2 == 0 ? '#FAFAFA' : '#F0F0F0' ) + ';padding:5px;">File ' + fields + ': <input type="file" name="file_' + fields + '" size="50" /></div>';
    }
    init ( );
    return false;
}

function ValidateLoginForm ( oForm )
{

    
    var username = document.getElementById('username').value;
    
    var password = document.getElementById('password').value;

    if ( username == '' || password == '' )
    {
        alert ( 'Please fill out both your username and your password.' );

        return false;
    }
    return true;
}

function is_folder_empty ( iFiles )
{
    if ( iFiles > 0 )
    {
        alert ( 'Folder is not empty. Delete files inside folder first.' );

        return false;
    }
    else
    {
        return true;
    }
}


function checkall(formName, boxName, checkval) {
	for(i = 0; i < formName.elements.length; i++)
	{
		var formElement = formName.elements[i];
		if(formElement.type == 'checkbox' && formElement.name == boxName && formElement.disabled == false)
		{
			formElement.checked = checkval.checked;
		}
	}	
}




