This repository was archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.js
More file actions
111 lines (97 loc) · 3.04 KB
/
contact.js
File metadata and controls
111 lines (97 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Copyright (C) 2012-2016 Stephan Kreutzer
*
* This file is part of refugee-it.de.
*
* refugee-it.de is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3 or any later version,
* as published by the Free Software Foundation.
*
* refugee-it.de is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License 3 for more details.
*
* You should have received a copy of the GNU Affero General Public License 3
* along with refugee-it.de. If not, see <http://www.gnu.org/licenses/>.
*/
var xmlhttp = null;
// Mozilla
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
function request()
{
var eMail = document.getElementById('e_mail');
var content = document.getElementById('message');
if (xmlhttp != null &&
eMail != null &&
content != null)
{
var requestPath = "";
{
var scripts = document.getElementsByTagName("script");
// 'scripts' contains always the last script tag that was loaded.
var myPath = scripts[scripts.length-1].src;
requestPath = myPath.substring(0, myPath.lastIndexOf('/'));
requestPath += "/request.php";
}
// 'file://' is bad.
if (requestPath.substring(0, 7) == "file://")
{
requestPath = requestPath.substr(8);
requestPath = "http://" + requestPath;
}
xmlhttp.open('POST', requestPath, true);
xmlhttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = result;
xmlhttp.send('e_mail=' + encodeURIComponent(eMail.value) + '&' +
'content=' + encodeURIComponent(content.value));
}
}
function result()
{
if (xmlhttp.readyState != 4)
{
// Waiting...
}
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
if (xmlhttp.responseText == '')
{
return;
}
var dom = xmlhttp.responseXML.documentElement;
var result = dom.getElementsByTagName('result').item(0).firstChild.data;
var form = document.getElementById('form');
if (form != null)
{
if (result == "success")
{
form.innerHTML = "<p>Thank you!</p>";
}
else if (result == "failure")
{
form.innerHTML = "<p>Failed...</p>";
}
else
{
form.innerHTML = "<p>Unknown status...</p>";
}
}
}
else if (xmlhttp.readyState == 4 && xmlhttp.status == 0)
{
var form = document.getElementById('form');
if (form != null)
{
form.innerHTML = "<p>Offline...</p>";
}
}
}