<script type="text/javascript"><!--
[gray]// our two style sheet paths[/gray]
var cStyleSheetBlue = "style1.css";
var cStyleSheetRed = "style2.css";
[gray]// this function changes the style sheet when the user clicks on a link
// and then calls the storing function[/gray]
function changeStyleSheet ( strLinkId, strStyleSheetLocation ) {
[gray]// switch the stylesheet location[/gray]
document.getElementById( strLinkId ).href = strStyleSheetLocation;
[gray]// call the storing function[/gray]
storeStyleSheetInCookie( strLinkId, strStyleSheetLocation );
}
[gray]// this function stores the style sheet preference in a cookie on the user's machine
// the cookie expires one year from the time it is stored
// and can be read from any page on your website[/gray]
function storeStyleSheetInCookie ( strCookieName, strStyleSheetLocation ) {
[gray]// get today's date[/gray]
var dtExpire = new Date();
[gray]// add a year to the date[/gray]
dtExpire.setYear( dtExpire.getFullYear() + 1 );
[gray]// store the cookie[/gray]
document.cookie = escape( strCookieName ) + "=" + escape( strStyleSheetLocation ) + "; expires=" + dtExpire.toGMTString() + "; path=/;";
}
[gray]// this function will attempt to retrieve the preffered stylesheet url from
// a cookie on the user's machine[/gray]
function getStyleSheetFromCookie ( strLinkId ) {
[gray]// the name of the cookie we are trying to find[/gray]
strLinkId = escape( strLinkId );
[gray]// if there are no cookies, leave the function[/gray]
if ( document.cookie == "" ) {
return false;
} else {
[gray]// store the raw cookie data in a string[/gray]
var strCookie = document.cookie;
[gray]// look for the cookie's name[/gray]
var intFirstChar = strCookie.indexOf( strLinkId );
[gray]// if the cookie we want does not exist, leave the function[/gray]
if ( intFirstChar < 0 ) return false;
[gray]// look for the end of the cookie value[/gray]
var intLastChar = strCookie.indexOf( ";" );
[gray]// if there is no separator, we'll just take the whole thing[/gray]
if ( intLastChar < 0 ) intLastChar = strCookie.length;
[gray]// skip the name= part of the cookie (so we only get the data we want)[/gray]
intFirstChar = strLinkId.length + 1;
[gray]// return the style sheet's url[/gray]
return unescape( strCookie.substring( intFirstChar, intLastChar ) );
}
}
[gray]// this function will set the preferred style sheet (if one exists) when the
// page initially loads[/gray]
function preloadStyleSheet ( strLinkId ) {
var strPreferredStyleSheet = getStyleSheetFromCookie( strLinkId );
if ( strPreferredStyleSheet != false )
changeStyleSheet( strLinkId, strPreferredStyleSheet );
}
[gray]// attach the preload function to the onload event[/gray]
onload = function() { preloadStyleSheet("ss") };
//--></script>