Hello all,

I am trying have a link that switches between style sheets. It is working well at the moment except for one thing. I have a little conditional that displays a link to switch to a "grid view" if it the current style is "layout" which is the default (list view). So if you ended up at the page you would see the default layout in list view. If you click the link it will switch to grid view (the other style sheet) but does not seem to set the setting for the current style sheet so that it can switch back. Hope that is clear. Any help will greatly appreciated. Thanks

HTML Code:
<script type="text/javascript">
        function setActiveStyleSheet(title) {
          var i, a, main;
          for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
            if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
              a.disabled = true;
              if(a.getAttribute("title") == title) a.disabled = false;
            }
          }
        }

        function getActiveStyleSheet() {
          var i, a;
          for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
            if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
          }
          return null;
        }

        function getPreferredStyleSheet() {
          var i, a;
          for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
            if(a.getAttribute("rel").indexOf("style") != -1
               && a.getAttribute("rel").indexOf("alt") == -1
               && a.getAttribute("title")
               ) return a.getAttribute("title");
          }
          return null;
        }
</script>

<script type="text/javascript">
            var style = getActiveStyleSheet()

            if(style == "layout"){
                document.write('<a href="#" onclick="setActiveStyleSheet(\'gridviewlayout\'); return false;">Grid View<\/a>');
                document.write(style);
            }
            else if(style == "gridviewlayout"){
                document.write('<a href="#" onclick="setActiveStyleSheet(\'layout\'); return false;">List View<\/a>')
            }
</script>