//*************************************************************************************** // BrowserUtil.js - Browser-Specific Functions // // There are 2 main browser specific functions: // 1. Event passing // - Mozilla/Netscape pass their events into the current function (i.e. MouseDown(e)) // - IE has it's events available in the window (i.e. window.event) // 2. Event function overrides // - Mozilla need explicit function override (document.onmousedown=MouseDown) // - IE just needs overrides in tab (onmousedown='MouseDown()') // // Copyright (c) 2006, // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. //*************************************************************************************** //*************************************************************************************** // Constants //*************************************************************************************** //*************************************************************************************** // browswer manufacturers and versions //*************************************************************************************** function BrowserUtil_IsIE() { var Flag=true; if (BrowserUtil_IsNavigator()) Flag=false; return(Flag); } // for navigator, // 4 and older do not support layers // 5 may support layers through the "layer" object but this is not recommended // 6 and up should support innerHTML function BrowserUtil_IsNavigator() { var Flag = false; if (navigator.appName.indexOf("Netscape")>=0) Flag=true; // return(false); return(Flag); } function BrowserUtil_IsNavigator4() { var Flag=false; if (BrowserUtil_IsNavigator()) { if (parseFloat(navigator.appVersion)<5) Flag=true; } return(Flag); } //*************************************************************************************** // Mouse functions //*************************************************************************************** function BrowserUtil_KeyCode(e) // // returns ASCII character typed // { var KeyCode=-1; // indicates a failure if (BrowserUtil_IsNavigator()) { // alert(e.pageX); KeyCode=e.which; } else { var Event=window.event; KeyCode=Event.keyCode; } return(KeyCode); } function BrowserUtil_MouseButton(e) // // Returns 1 for left and 3 for right // { var Button=-1; // indicates a failure if (BrowserUtil_IsNavigator()) { // alert(e.pageX); Button=e.which; } else { var Event=window.event; Button=Event.button; if (Button==2) Button=3; } return(Button); } function BrowserUtil_MouseModifiers(e) // // // { var Modifiers=0; // no modifiers if (BrowserUtil_IsNavigator()) { if (e.ctrlKey) Modifiers+=1; if (e.shiftKey) Modifiers+=2; } else { var Event=window.event; if (Event.ctrlKey) Modifiers+=1; if (Event.shiftKey) Modifiers+=2; } return(Modifiers); } function BrowserUtil_MouseX(e) { var mouseX=-1; // indicates a failure if (BrowserUtil_IsNavigator()) { mouseX=e.pageX; } else { var Event=window.event; mouseX=Event.clientX; } mouseX+=BrowserUtil_ScrollX(); // add the offset from the body being scrolled return(mouseX); } function BrowserUtil_MouseY(e) { var mouseY=-1; // indicates a failure if (BrowserUtil_IsNavigator()) { mouseY=e.pageY; } else { var Event=window.event; mouseY=Event.clientY; } mouseY+=BrowserUtil_ScrollY(); // add the offset from the body being scrolled return(mouseY); } function BrowserUtil_GetX() { var Result=0; if (BrowserUtil_IsNavigator()) { Result=window.screenX; } else { Result=window.screenLeft; } return(Result); } function BrowserUtil_GetY() { var Result=0; if (BrowserUtil_IsNavigator()) { Result=window.screenY; } else { Result=window.screenTop; } return(Result); } function BrowserUtil_GetContentWidth() { var Result=0; if (BrowserUtil_IsNavigator()) { Result=window.innerWidth-20; // this is required because FireFox reports 41 less pixels than explorer } else { Result=document.body.clientWidth; } return(Result); } function BrowserUtil_GetContentHeight() { var Result=0; if (BrowserUtil_IsNavigator()) { Result=window.innerHeight; } else { Result=document.documentElement.clientHeight; // Result=document.body.clientHeight; } return(Result); } /* function BrowserUtil_HideScrollBars() { var Result=0; if (BrowserUtil_IsNavigator()) { window.scrollbars.visible=0; } else { // window.scrollbars="no"; // window.scrollbars=false; } return(Result); } */ function BrowserUtil_ScrollX() { var Result=0; if (BrowserUtil_IsNavigator()) { Result=window.pageXOffset; } else { Result=document.body.scrollLeft; } return(Result); } function BrowserUtil_ScrollY() { var Result=0; if (BrowserUtil_IsNavigator()) { Result=window.pageYOffset; } else { Result=document.body.scrollTop; } return(Result); } //*************************************************************************************** // Miscenaneous functions //*************************************************************************************** function BrowserUtil_GetCookie(Name) { var Result=null; var AllCookies=document.cookie; // prompt("AllCookies",AllCookies); var Position=AllCookies.indexOf(Name+"="); if (Position!=-1) { var Start=Position+Name.length+1; var End=AllCookies.indexOf(';',Start); if (End==-1) End=AllCookies.length; var Result=AllCookies.substring(Start,End); Result=unescape(Result); //"window.alert(progress); } // alert("Cooke Name="+Name+"="+Result); return(Result); } function BrowserUtil_CleanCookie(CookieString) { // alert("CookeString="+CookieString); var re = /[+]/; // weird syntax for javascript replace function for (var i=0;i<10;i++) { CookieString=CookieString.replace(re," "); // change '+'s to spaces } return(CookieString); } function BrowserUtil_SetCookie(Name,Value) { alert("Name="+Value); document.cookie=Name+"="+escape(Value); // document.cookie=Name+"="+escape(Value)+"; path=/"; } //*************************************************************************************** // Utility Functions //*************************************************************************************** function BrowserUtil_FormatFloat(Value,NumDigits) { var Result=parseFloat(Value); var Negative=false; if (isNaN(Value)) { Result=0; } else { if (Value<0) { Value=-Value; Negative=true; } if (Value>10) { var Temp=Value; var NumTenDigits=0; while ((Temp>1)&&(NumTenDigits<20)) { NumTenDigits++; Temp=Temp/10; } var NumFractionDigits=NumDigits-NumTenDigits; if (NumFractionDigits>0) { var Magnitude=Math.pow(10,NumFractionDigits); Temp=parseInt(Value*Magnitude); Result=Temp/Magnitude; } else // no fraction digits, just use the whole portion { Result=parseInt(Value); } } if (Negative) Result=-Result; } return(Result); } /* function GetHexString(Value) { var Result=Value.toString(16); return(Result); } */ function BrowserUtil_GetHexColorFromDecimalColor(DecimalColor) { // alert("GetHexColorFromDecimalColor() DecimalColor="+DecimalColor); DecimalColor=DecimalColor.toString(); // alert("GetHexColorFromDecimalColor() DecimalColor="+DecimalColor); var Colors=DecimalColor.split(","); var HexColor="#"; var Sample=parseInt(Colors[0]).toString(16); if (Sample.length<2) HexColor=HexColor+"0"; HexColor=HexColor+Sample; var Sample=parseInt(Colors[1]).toString(16); if (Sample.length<2) HexColor=HexColor+"0"; HexColor=HexColor+Sample; var Sample=parseInt(Colors[2]).toString(16); if (Sample.length<2) HexColor=HexColor+"0"; HexColor=HexColor+Sample; // alert("GetHexColorFromDecimalColor() HexColor="+HexColor); return(HexColor); } function BrowserUtil_GetDecimalColorFromHexColor(HexColor) { // alert("GetHexColorFromDecimalColor() HexColor="+HexColor); HexColor=HexColor.toString(); // trip a leading pound sign if needed if (HexColor.charAt(0)=="#") HexColor=HexColor.substr(1); var Red=parseInt("0x"+HexColor.substr(0,2)); var Green=parseInt("0x"+HexColor.substr(2,2)); var Blue=parseInt("0x"+HexColor.substr(4,2)); var DecimalColor=Red+','+Green+','+Blue; // alert("GetHexColorFromDecimalColor() DecimalColor="+DecimalColor); return(DecimalColor); } function BrowserUtil_IsValid(Thing) { var Result=false; if ((typeof(Thing)!="undefined")&&(Thing!=null)) Result=true; return(Result); } function BrowserUtil_GetStyleFromName(StyleName) // // StyleName - the 'SelectorText' for the style (i.e. .Custom, a:link, etc) // Uncommenting the PanelDebugging functions will dump all styles in the document // { var Style=null; // alert("hi="+document.styleSheets.length); // alert("NumStyleSheets(document.styleSheets.length)="+document.styleSheets.length); for (i=0;(i"); document.write("Login"); document.write(""); } else // user is logged in { var Name=BrowserUtil_GetCookie("Name"); Name=Name.replace("+", " "); //document.write("Welcome "+Name+" "); document.write(""); document.write("Logout"); document.write(""); document.write("   "); document.write(" | "); document.write("My Profile"); } } function BrowserUtil_WriteTopLoginList(WebsiteID) { // var WebSiteID=BrowserUtil_GetCookie("WebSiteID"); // alert("WebsiteID: "+WebsiteID+"*"); var UserID=BrowserUtil_GetCookie("UserID"); // if ((UserID=="")||(UserID==null)) // not logged in { document.write(""); document.write("Login"); document.write(""); } else // user is logged in { var Name=BrowserUtil_GetCookie("Name"); Name=Name.replace("+", " "); //document.write("Welcome "+Name+" "); document.write(""); document.write("Logout"); document.write(""); document.write(""); document.write("
  • "); document.write("My Profile"); } }