//************************************************************ // index of contents: //************************************************************ // 1. global variables and functions // 1a. browser tests // 1b. disable right click // 1c. print page // 1d. set status message // 1e. random number // 1f. get mouse position // // 2. image and rollover functions // 2a. macromedia rollover functions // 2b. alt image rollover function // 2c. random image // // 3. date and time // 3a. date string manipulations // 3b. time manipulations // 3c. is it a leap year // // 4. window operations // 4a. open window function // 4b. a new open window function // 4c. parent window location // // 5. get this page name // // 6. query string data // 6a. get key-value pairs // // 7. navigation functions // // 8. trim // // 9. cross browser XMLHttpRequest // // 10. changing a named html element // 10a. empty an element // 10b. add to an element // 10c. replace an element // 10d. change the class of an element // // 11. manipulations with visibility and display of elements // 11a. convert object name into a valid object reference // 11b. change the visibility-somewhat deprecated // 11c. change the display of an object // // 12. locates elements of a certain class // // 13. check variables // 13a. isEmpty // 13a. isZero // // 14. cookies // // 15. change style sheets //************************************************************ // // //************************************************************ // 1. global variables and functions // 1a. browser tests //************************************************************ /* * Browser name: BrowserDetect.browser * Browser version: BrowserDetect.version * OS name: BrowserDetect.OS */ var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i=3 && firefoxVersion<4)isFirefox3=true; //alert("You're using OS "+OSName+" with browser FF 3.x or above") else if (firefoxVersion>=2 && firefoxVersion<3)isFirefox2=true; // alert("You're using "+OSName+" with browser FF 2.x") else if (firefoxVersion>=1 && firefoxVersion<2)isFirefox1=true; //alert("You're using "+OSName+" with browser FF 1.x") } function getbrowser_details() { var x = navigator; var txt = "CodeName = " + x.appCodeName + "
"; txt += "MinorVersion = " + x.appMinorVersion + "
"; txt += "Name = " + x.appName + "
"; txt += "Version = " + x.appVersion + "
"; txt += "CookieEnabled = " + x.cookieEnabled + "
"; txt += "CPUClass = " + x.cpuClass + "
"; txt += "OnLine = " + x.onLine + "
"; txt += "Platform = " + x.platform + "
"; txt += "UA = " + x.userAgent + "
"; txt += "BrowserLanguage = " + x.browserLanguage + "
"; txt += "SystemLanguage = " + x.systemLanguage + "
"; txt += "UserLanguage = " + x.userLanguage; //alert(x.appVersion); return(txt); } var isNav,isNavSix; var coll = ""; var styleObj = ""; if (parseInt(navigator.appVersion) >= 4) { if (navigator.appName == "Netscape") { isNav = true; if (parseInt(navigator.appVersion) >= 5) { isNavSix = true; } } else { isIE = true; coll = "all."; styleObj = ".style"; } } var ie4 = document.all; var ns4 = document.layers; var ns6 = document.getElementById && !document.all; //************************************************************ function browserInfo() { this.codename = navigator.appCodeName; this.minorversion = navigator.appMinorVersion; this.name = navigator.appName; this.version = navigator.appVersion.substring(0,4); this.version2 = navigator.appVersion; this.cookieEnabled = navigator.cookieEnabled this.cpuClass = navigator.cpuClass this.mimeTypes = navigator.mimeTypes this.opsProfile = navigator.opsProfile this.plugins = navigator.plugins this.systemLanguage = navigator.systemLanguage this.userAgent = navigator.userAgent this.userLanguage = navigator.userLanguage this.userProfile = navigator.userProfile this.platform = navigator.platform; this.javaEnabled = navigator.javaEnabled(); this.screenWidth = screen.width; this.screenHeight = screen.height; } var thisBrowser = new browserInfo(); // Example: // alert(thisBrowser.version); //************************************************************ // 1b. disable right click //************************************************************ function disableRightClick(e) { var message = "Right click disabled"; // initialize if(!document.rightClickDisabled) { if(document.layers) { document.captureEvents(Event.MOUSEDOWN); document.onmousedown = disableRightClick; } else document.oncontextmenu = disableRightClick; return document.rightClickDisabled = true; } if (document.layers || (document.getElementById && !document.all)) { if (e.which==2||e.which==3) { alert(message); return false; } } else { alert(message); return false; } } //call using: //disableRightClick(); //************************************************************ // 1c. print page //************************************************************ function printPage() { print(document); } function printPage2() { if (document.body.firstChild.id == 'print_URL_header') { document.body.removeChild(document.body.firstChild); } else { entete = document.createElement('pre'); entete.setAttribute('id','print_URL_header'); entete.appendChild(document.createTextNode(document.URL)); document.body.insertBefore(entete, document.body.firstChild, null); window.print(); } } //************************************************************ // 1d. set status message //************************************************************ function setStatusBar(msgStr) { self.status = msgStr; } //************************************************************ // 1e. random number //************************************************************ function randomNumber(limit) { return Math.floor(Math.random()*limit); } //************************************************************ // 1f. get mouse position /* Example: function test() { if (document.layers) getMouseLoc; //NS else if (document.all) getMouseLoc(); //IE alert(mouseLocation.x+","+mouseLocation.y); } in the BODY: test */ //************************************************************ function Point(x,y) { this.x = x; this.y = y; } mouseLocation = new Point(-500,-500); function getMouseLoc(e) { if(!document.all) //NS { mouseLocation.x = e.pageX; mouseLocation.y = e.pageY; } else //IE { mouseLocation.x = event.x + document.body.scrollLeft; mouseLocation.y = event.y + document.body.scrollTop; } return true; } //NS init: if(document.layers){ document.captureEvents(Event.MOUSEMOVE); document.onMouseMove = getMouseLoc; } //************************************************************ // 2. image and rollover functions // 2a. macromedia rollover functions //************************************************************ // Example: obj = findObj("image1"); function findObj(theObj, theDoc) { var p, i, foundObj; if(!theDoc) theDoc = document; if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) { theDoc = parent.frames[theObj.substring(p+1)].document; theObj = theObj.substring(0,p); } if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document); if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj); return foundObj; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i"); } //************************************************************ // 3. date and time // 3a. date string manipulations //************************************************************ var monthNames = new Array ("January","February","March","April","May","June","July","August","September","October","November","December"); var now = new Date(); var amPm = (now.getHours() < 12) ? " AM" : " PM"; var hour = (now.getHours() > 12) ? (now.getHours() - 12) : (hour == 0) ? "12" : now.getHours(); var min = (now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes()); var theYear = (now.getYear() < 1900) ? (now.getYear() + 1900) : now.getYear(); var theDateString = monthNames[now.getMonth()] + " " + now.getDate() + ", " + theYear + " " + hour + ":" + min + amPm; if (isIE) { if (navigator.platform.match("Mac")) { theDateString = monthNames[now.getMonth()] + " " + now.getDate() + ", " + theYear; } } //************************************************************ // 3b. time manipulations //************************************************************ var timeStamp = new Date(); var timeStampMonth = timeStamp.getMonth() + 1; var timeStampDate = timeStamp.getDate(); //document.write(timeStampMonth + "/" + timeStampDate + " "); var timeStampHours = timeStamp.getHours(); var timeStampMins = timeStamp.getMinutes(); if (timeStampHours >= 12) { var timeStampTime = " P.M."; } else { var timeStampTime = " A.M."; } if (timeStampHours > 12) { timeStampHours -= 12; } if (timeStampHours == 0) { timeStampHours = 12; } if (timeStampMins < 10) { timeStampMins = "0" + timeStampMins; } //document.write(timeStampHours + ":" + timeStampMins + timeStampTime); //************************************************************ // 3c. is it a leap year //************************************************************ function IsLeapYear(intYear) { if (intYear % 100 == 0) { if (intYear % 400 == 0) { return true; } } else { if ((intYear % 4) == 0) { return true; } } return false; } //************************************************************ // 4. window operations // 4a. open window function //************************************************************ function openNewWindow(page,name,width,height,top,left,propSet) { var windowProps = new Array (8); windowProps[0] = "resizable=yes"; windowProps[1] = "scrollbars=yes"; windowProps[2] = "titlebar=yes"; windowProps[3] = "toolbar=yes"; windowProps[4] = "menubar=yes"; windowProps[5] = "location=yes"; windowProps[6] = "status=yes"; windowProps[7] = "directories=yes"; var myProps = ""; var mySize = ""; if (propSet == 'one') { myProps = ',' + windowProps[0] + ',' + windowProps[1]; } else if (propSet == "full") { myProps = ',' + windowProps.join(","); } else { myProps = ""; } if ((width > 50)||(height > 50)) { var mySize = 'width=' + width + ',' + 'height=' + height + ',' + 'top=' + top + ',' + 'left=' + left; } var myString = mySize + myProps; window.open(page,name,myString); } //************************************************************ /* function popGlossary(theUrl) { openNewWindow(theUrl,"gloss",484,289,0,0,"none"); }*/ //************************************************************ // 4b. a new open window function //************************************************************ function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i back to // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1 qs = qs.replace(/\+/g, ' ') var args = qs.split('&') // parse out name/value pairs separated via & // split out each name=value pair for (var i=0;i