comparison src/en/javascript/main.js @ 54:baf1530ba0b0

added random quotes via ajax
author bbarry <bbarry@stellarfinancial.com>
date Mon, 16 Feb 2009 07:14:20 -0700
parents 18110c461824
children 16016cc18ded
comparison
equal deleted inserted replaced
44:b4e2beb77366 54:baf1530ba0b0
13 } 13 }
14 } 14 }
15 15
16 var xmlhttp = null; 16 var xmlhttp = null;
17 17
18 function loadXMLDoc(url) { 18 function loadXMLDoc(url, stateChange) {
19 if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc. 19 if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
20 xmlhttp = new XMLHttpRequest(); 20 xmlhttp = new XMLHttpRequest();
21 } else if (window.ActiveXObject) {// code for IE6, IE5 21 } else if (window.ActiveXObject) {// code for IE6, IE5
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
23 } 23 }
28 } else { 28 } else {
29 alert("Your browser does not support XMLHTTP."); 29 alert("Your browser does not support XMLHTTP.");
30 } 30 }
31 } 31 }
32 32
33 function stateChange() { 33 // client OS specific page section
34 function browserUsageRequestStateChange() {
34 if (xmlhttp.readyState==4) {// 4 = "loaded" 35 if (xmlhttp.readyState==4) {// 4 = "loaded"
35 document.getElementById('replace').innerHTML = xmlhttp.responseText; 36 document.getElementById('replace').innerHTML = xmlhttp.responseText;
36 } 37 }
37 } 38 }
38 39
39 addLoadEvent(function () { 40 addLoadEvent(function () {
40 if (navigator.appVersion.indexOf("Win")!=-1) { 41 if (navigator.appVersion.indexOf("Win")!=-1) {
41 loadXMLDoc("win.html"); 42 loadXMLDoc("win.html", browserUsageRequestStateChange);
42 } 43 }
43 }); 44 });
45
46 // random quotes
47 function quoteRequestStateChange() {
48 if (xmlhttp.readyState==4) {// 4 = "loaded"
49 document.getElementById('quote').innerHTML = xmlhttp.responseText;
50 }
51 }
52
53 function randomNumber(low, high) {
54 return Math.floor(Math.random()*(high-low+1))+low;
55 }
56
57 addLoadEvent(function () {
58 loadXMLDoc("quotes/" + randomNumber(1, 17) + ".txt", quoteRequestStateChange);
59 });