var curgroupid;

function ConfirmArchive (theaction)
{
    return (confirm ("Bist Du sicher, dass Du das gewählte Dokument " + theaction + " möchtest?"));
}

function CancelDownloadForm ()
{
    document.getElementById ("goodexit").value = 0;
    document.getElementById ("dm_frmupload").submit ();
}

function EnableDownloadForm (/*theform*/)
{
    document.getElementById ("upload").focus ();
}

function FocusDownloadTitle ()
{
    if (document.getElementById ("title").value.isEmpty () && ! document.getElementById ("upload").value.isEmpty ()) {
        var filename = document.getElementById ("upload").value;
        while (filename.indexOf ('\\') >= 0)
            filename = filename.replace ('\\', '/');
        var index = filename.lastIndexOf ('/');
        if (index >= 0)
            filename = filename.substr (index + 1);
        document.getElementById ("title").value = filename;
        document.getElementById ("title").select ();
    }
}

function ShowTooltip (thetitle, thedescription, thelink, thefilesize, thetype, thecreationdate, thegroup, themodificationdate)
{
    var text = "<div id=dm_tooltip>" +
               "  <table summary=\"todo\" cellspacing=\"0\" width=\"100%\">" +
               "    <caption>Details für <q><em>" + thetitle + "</em></q></caption>" +
               "    <col id=\"prop\" />" +
               "    <col id=\"val\" />" +
               "    <thead>" +
               "      <tr><td width=\"20\">&nbsp;Titel/Bezeichnung&nbsp;</td><td>Daten/Wert</td></tr>" +
               "    </thead>" +
               "    <tbody>" +
               "      <tr><td>Name</td><td>" + thetitle + "</td></tr>" +
               "      <tr><td>Beschreibung</td><td>" + thedescription + "</td></tr>" +
               "      <tr><td>Dateiname</dt><td>" + thelink + "</td></tr>" +
               "      <tr><td>Dateigröße</dt><td>" + thefilesize + "</td></tr>" +
               "      <tr><td>Dateityp</td><td>" + thetype + "</td></tr>" +
               "      <tr><td>Erstellt am</td><td>" + thecreationdate + "</td></tr>" +
               "      <tr><td>Betrachter</td><td>" + thegroup + "</td></tr>" +
               "      <tr><td>Zuletzt geändert</td><td>" + themodificationdate + "</td></tr>" +
               "    </tbody>" +
               "  </table>" +
               "</div>";
    return (overlib (text, CAPTION, "Details", ABOVE, RIGHT, WIDTH, 320, FGCOLOR, "#FFCCCC", BGCOLOR, "#993333"));
}

function ValidateDownloadForm (theform, thefilename)
{
    var isvalidfilename = function (thenewfilename) {
        if (thefilename.isEmpty ())
            return (true);
        var filename = thenewfilename.value;
        var i;
        for (i = filename.length; i > 0 && filename.charAt (i - 1) != '/' && filename.charAt (i - 1) != '\\' && filename.charAt (i - 1) != ':'; --i);
        if (i > 0 && (filename.charAt (i - 1) == '/' || filename.charAt (i - 1) == '\\'))
            filename = filename.substring (i);
        return (filename.toLowerCase () == thefilename.toLowerCase ());
    }
    var elems = [
        new CFormValidator ("upload", true, isvalidfilename, null, thefilename.isEmpty () ? "Bitte wähle eine Datei aus." : "Die ausgewählte Datei hat nicht den richtigen Namen.")
    ];
    FocusDownloadTitle ();
    if (! CForm.Validate (elems))
        return (false);
    var newgroup = document.getElementById ("fe_group").options [document.getElementById ("fe_group").selectedIndex].value;
    var has = false;
    for (var i = 0; ! has && i < curgroupid.length; has = curgroupid [i++] == newgroup);
    if (! has && ! confirm ("Du kannst die Datei aufgrund der Berechtigung nicht sehen.\nMöchtest Du fortfahren?"))
        return (false);
    document.getElementById ("goodexit").value = 1;
    return (true);
}

