#!/usr/bin/perl
# -*- mode: perl -*-

$time = time;
$id = "$ENV{'SERVER_NAME'}.$time.$$";
$prot = $ENV{'SERVER_PROTOCOL'};

$content = <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>datango Trainer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<noscript>
  <link rel=stylesheet href="!start.css">
  <body>
    <table cellpadding=0 cellspacing=1 width=100% ID="Table1"><tr>
    <td><img style="border: 0px solid black;" src="skin/datango_logo.gif"></td>
    <td class="title2" style="padding: 0px;" width=100% valign=top>
      <table border=0 class="title" cellpadding=0 cellspacing=0 width=100% ID="Table2">
      <tr height=50%>
      <td id=title class="title" style="color: #a00000;" nowrap
        >datango Trainer <span style="font-size: 80%;">not available</span></td>
      </tr><tr>
      <td class="title2" style="color: #ff0000;">(Javascript is turned off)</td>
      </tr></table>
    </td></tr></table>
  </body>
</noscript>

<script language=javascript>

function dgoRescueStartpage(url_, name_, timeout_) {
    var doc = self.document;

    if (!self.document.body ||
        !self.document.body.tagName ||
        self.document.body.tagName != 'FRAMESET' ||
        !self.document.body.id ||
        self.document.body.id != "trainer_frameset")
    {
        var html = '<body onload="self.setTimeout(' +
                   "'self.dgoRescueAppStart()'" + ', ' +
                   (timeout_ || 0) + ' * 1000)"><p>';
        html += '<a href="' + url_ + '">Manual ' + (name_ || 'application') +
                ' start</a><br>';
        html += '<a href="' + url_ + '">Manueller Start ' +
                (name_ ? 'von <b>' + name_ + '</b>' : 'der Anwendung') + '</a>';
        html += '</p><' + 'script language=javascript>';
        html += 'function dgoRescueAppStart() {';

        if (timeout_) {
            html += '  self.location = "' + url_ + '";';
        }
        html += '}</' + 'script></body>';

        doc.writeln(html);
        doc.close();
    }
}

function dgoRescueInit() {
    var dgoUrlParam = new String(self.location.search);
    if (dgoUrlParam.substr(0,1) == '?') {
        dgoUrlParam = dgoUrlParam.substr(1);
    }

    var paramArray = dgoUrlParam.split('&');
    var appname = '';
    var appurl = '';
    var apptimeout = '';
    var startpage = '';
    var startpagename = '';
    var startpagetimeout = 0;
    var param, name, value;

    for (i = 0; i < paramArray.length; ++i) {
        param = paramArray[i].split('=', 2);
        name = param[0];
        value = unescape(param[1]);

        switch (name) {
        case 'startpage':        startpage = value;         break;
        case 'startpagename':    startpagename = value;     break;
        case 'startpagetimeout': startpagetimeout = value;  break;
        case 'appname':          appname = value;           break;
        case 'appurl':           appurl = value;            break;
        case 'apptimeout':       apptimeout = value;        break;
        default: break;
        }
    }

    if (startpage) {
        var param = '';

        if (appname) {
            param += '&appname=' + escape(appname);
        }

        if (appurl) {
            param += '&appurl=' + escape(appurl);
        }

        if (apptimeout) {
            param += '&apptimeout=' + escape(apptimeout);
        }

        if (param) {
            startpage +=
                (startpage.indexOf('?') >= 0 ? '&' : '?') + param.substr(1);
        }

        self.dgo.RescueInitId = self.setTimeout(
            'self.dgoRescueStartpage("' + startpage + '", "' +
            startpagename + '", ' + startpagetimeout + ')', 5000);
    }
}

// datango global boot object.
self.dgo = {};
dgoRescueInit();

self.dgo.Url = new String(self.location.href);
self.dgo.Referrer = new String(self.document.referrer);
var x = self.location.search;
self.dgo.UrlParam = (x.substr(0,1) == '?' ? x.substr(1) : x + '');
x += self.location.hash;
x = self.dgo.Url.substr(0, self.dgo.Url.length - x.length);
var p = x.lastIndexOf('/');
self.dgo.Home = (p < 0 ? x : x.substr(0, p + 1));

// Uncomment and adapt this for parameterless program start. i.e. in CHMs!
// self.dgo.UrlParam = 'config=projects/bubble/dmf/bu_xcfg.js';

var doc = self.document;
doc.write('<script src="' + self.dgo.Home +
    'jswidget/callback.js" language=javascript></' + 'script>');
doc.write('<script src="' + self.dgo.Home +
    'jswidget/check.js" language=javascript></' + 'script>');
doc.write('<script src="' + self.dgo.Home +
    'param.js" language=javascript></' + 'script>');
doc.write('<script src="' + self.dgo.Home +
    'jswidget/config.js" language=javascript></' + 'script>');
doc.write('<script src="' + self.dgo.Home +
    'boot_helper.js" language=javascript></' + 'script>');
doc.write('<script src="' + self.dgo.Home +
    'boot.js" language=javascript></' + 'script>');

</script>
</head>
<body onload="return boot();"></body>
<script>
/*
  Copyright Notice:

  Copyright 2000-2003 datango AG
  ALL RIGHTS RESERVED

  UNPUBLISHED -- Use of a copyright notice is precautionary only and
  does not imply publication or disclosure.

  THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  INFORMATION OF DATANGO AG. ANY DUPLICATION, MODIFICATION,
  DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS
  STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF
  DATANGO AG.
 */
</script>
</html>
EOF

# HTTP 1.1 headers crash NC4 !

if ($prot eq "HTTP/1.1") {
    print "Last-Modified: Sun, 9 Nov 2003 04:03:01 GMT\r\n";
    print "Cache-Control: no-cache, must-revalidate\r\n";
}

print "Expires: Mon, 10 Nov 2003 04:03:01 GMT\r\n";
print "Pragma: no-cache\r\n";
print "Content-Type: text/html\r\n";
print "Content-Length: " . (length $content) . "\r\n";
print "Set-Cookie: logid=$id;path=/\r\n";
print "\r\n";
print "$content";
