function Employee() 
{
    this.Location = window.location.pathname;
    this.LastQuery = "";
    this.LastFilter = "alfa";
    this.LastIndex = false;
    this.LastWorkareaID = "";
    this.LastDepartmentID = "";
}

Employee.prototype.Search = function(query, index) 
{
    employee.LastQuery =  encodeURI(query.strip());
    employee.LastIndex = index;    
    employee.UpdateList();
}

Employee.prototype.DepartmentChange = function(departmentID)
{
    employee.LastDepartmentID = departmentID;
    employee.UpdateList();
}

Employee.prototype.WorkareaChange = function(workareaID)
{
    employee.LastWorkareaID = workareaID;
    employee.UpdateList();
}


Employee.prototype.Delete = function(sitecoreID, title, location) 
{
    if (confirm("Vil du slette '" + title + "'?"))
        new Ajax.Request('/sitecore modules/databases/dispatcher.aspx', { method: 'post', postBody: 'command=delete&sitecoreID='+sitecoreID, onSuccess: function(transport) { window.location = location;}, onFailure:common.ShowError });
}

Employee.prototype.vCard = function(sitecoreID) 
{
    window.location.href = "/sitecore modules/web/databases/dispatcher.aspx?command=vcard&sitecoreID=" + sitecoreID;
}

Employee.prototype.UpdateList = function()
{
    if (employee.LastQuery.length >= 3 || employee.LastIndex)
        new Ajax.Updater('list', window.location.pathname + '?p=1&query=' + employee.LastQuery + '&filter=' + employee.LastFilter + '&workareaid=' + employee.LastWorkareaID + '&departmentid=' + employee.LastDepartmentID);
    else
        new Ajax.Updater('list', window.location.pathname + '?p=1&filter=' + employee.LastFilter + '&workareaid=' + employee.LastWorkareaID + '&departmentid=' + employee.LastDepartmentID);
}

var employee = new Employee();
