function Law() {
    this.Location = window.location.pathname;
    this.LastQuery = "";
    this.LastSubjectID = "";
    this.LastTypeID = "";
    this.LastYear = "";
}

Law.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) { law.TypeChange(law.LastTypeID); }, onFailure: common.ShowError });

}

Law.prototype.Search = function(query) {
    law.LastQuery = encodeURI(query.strip());
    var pathString = window.location.pathname + '?p=1';
    if (law.LastSubjectID != "") pathString += '&subjectID=' + law.LastSubjectID;
    if (law.LastTypeID != "") pathString += '&typeID=' + law.LastTypeID;
    if (law.LastYear != "") pathString += '&year=' + law.LastYear;
    if (law.LastQuery != "") pathString += '&query=' + law.LastQuery;

    if (law.LastQuery.length > 0 || law.LastYear.length > 0 || law.LastTypeID.length > 0)
        new Ajax.Updater('LawList', pathString);
    else
        new Ajax.Updater('SubjectList', pathString);
}

Law.prototype.TypeChange = function(typeID) {
    law.LastTypeID = typeID;
    if (law.LastYear.length > 0 || law.LastQuery.length > 0 || law.LastTypeID.length > 0)
        new Ajax.Updater('LawList', law.Location + '?p=1&subjectID=' + law.LastSubjectID + '&typeID=' + law.LastTypeID + '&year=' + law.LastYear + '&query=' + law.LastQuery,
                      {
                          method: 'get',
                          evalScripts: true,
                          onComplete: function() {
                              externalLinks();
                          }
                      });
    else
        new Ajax.Updater('SubjectList', law.Location + '?p=1&subjectID=' + law.LastSubjectID + '&typeID=' + law.LastTypeID + '&year=' + law.LastYear,
                      {
                          method: 'get',
                          evalScripts: true,
                          onComplete: function() {
                              externalLinks();
                          }
                      });
}

Law.prototype.YearChange = function(year) {
    law.LastYear = year;

    if (law.LastYear.length > 0 || law.LastQuery.length > 0 || law.LastTypeID.length > 0)
        new Ajax.Updater('LawList', law.Location + '?p=1&subjectID=' + law.LastSubjectID + '&typeID=' + law.LastTypeID + '&year=' + law.LastYear + '&query=' + law.LastQuery,
                      {
                          method: 'get',
                          evalScripts: true,
                          onComplete: function() {
                              externalLinks();
                          }
                      });
    else
        new Ajax.Updater('SubjectList', law.Location + '?p=1&subjectID=' + law.LastSubjectID + '&typeID=' + law.LastTypeID + '&year=' + law.LastYear + '&query=' + law.LastQuery,
                      {
                          method: 'get',
                          evalScripts: true,
                          onComplete: function() {
                              externalLinks();
                          }
                      });
}

Law.prototype.SubjectChange = function(sitecoreID) {
law.LastSubjectID = sitecoreID;
    new Ajax.Updater('SubjectList', law.Location + '?p=1&subjectID=' + law.LastSubjectID,
                      {
                          method: 'get',
                          evalScripts: true,
                          onComplete: function() {
                                                    document.getElementById('CONTENT').style.display = 'none';
                                                    externalLinks();
                                                }
                      });
}


var law = new Law();



