diff 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
line wrap: on
line diff
--- a/src/en/javascript/main.js	Mon Feb 16 12:14:57 2009 +0100
+++ b/src/en/javascript/main.js	Mon Feb 16 07:14:20 2009 -0700
@@ -15,7 +15,7 @@
 
 var xmlhttp = null;
 
-function loadXMLDoc(url) {
+function loadXMLDoc(url, stateChange) {
     if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
         xmlhttp = new XMLHttpRequest();
     } else if (window.ActiveXObject) {// code for IE6, IE5
@@ -30,7 +30,8 @@
     }
 }
 
-function stateChange() {
+// client OS specific page section
+function browserUsageRequestStateChange() {
     if (xmlhttp.readyState==4) {// 4 = "loaded"
         document.getElementById('replace').innerHTML = xmlhttp.responseText;
     }
@@ -38,6 +39,21 @@
 
 addLoadEvent(function () {
     if (navigator.appVersion.indexOf("Win")!=-1) {
-        loadXMLDoc("win.html");
+        loadXMLDoc("win.html", browserUsageRequestStateChange);
     }
 });
+
+// random quotes
+function quoteRequestStateChange() {
+    if (xmlhttp.readyState==4) {// 4 = "loaded"
+        document.getElementById('quote').innerHTML = xmlhttp.responseText;
+    }
+}
+
+function randomNumber(low, high) {
+    return Math.floor(Math.random()*(high-low+1))+low;
+}
+
+addLoadEvent(function () {
+    loadXMLDoc("quotes/" + randomNumber(1, 17) + ".txt", quoteRequestStateChange);
+});