title: Calling functions correctly in premade javascript
body: <p>I got this HTML code:</p>
  
  <pre><code>&lt;head&gt;
  &lt;link href="default.css" title="default" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="theme1.css" title="theme1" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="theme2.css" title="theme2" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="theme3.css" title="theme3" rel="stylesheet" type="text/css" /&gt;
  
  &lt;script type="text/javascript" src="javascript.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;ul id="dropdown"&gt;
    &lt;li&gt; Choose theme
      &lt;ul&gt; 
        &lt;li id="stylesheet1" &gt; &lt;a href="#"&gt; Default &lt;/a&gt;&lt;/li&gt;
        &lt;li id="stylesheet2" &gt; &lt;a href="#"&gt; Theme 1 &lt;/a&gt;&lt;/li&gt;
        &lt;li id="stylesheet3" &gt; &lt;a href="#"&gt; Theme 2 &lt;/a&gt;&lt;/li&gt;
        &lt;li id="stylesheet4" &gt; &lt;a href="#"&gt; Theme 3 &lt;/a&gt;&lt;/li&gt;
     &lt;/ul&gt;
   &lt;/li&gt; 
  &lt;/ul&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>And I got this is the code in the separate file javascript.js:</p>
  
  <pre><code>function setActiveStyleSheet(title) {
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
      if(a.getAttribute("rel").indexOf("style") != -1 &amp;&amp; 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 &amp;&amp; a.getAttribute("title") &amp;&amp; !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
         &amp;&amp; a.getAttribute("rel").indexOf("alt") == -1
         &amp;&amp; a.getAttribute("title")
         ) return a.getAttribute("title");
    }
    return null;
  }
  
  function createCookie(name,value,days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  }
  
  function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i &lt; ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }
  
  window.onload = function(e) {
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
  }
  
  window.onunload = function(e) {
    var title = getActiveStyleSheet();
    createCookie("style", title, 365);
  }
  
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  
  
  
  // Last part
  
  function initate()
  {
  var style1 = document.getElementById("stylesheet1");
  var style2 = document.getElementById("stylesheet2");
  var style3 = document.getElementById("stylesheet3");
  var style4 = document.getElementById("stylesheet4");
  
  style1.onclick = function () { 
      setActiveStyleSheet("default"); 
      return false;
      };
  style2.onclick = function () { 
      setActiveStyleSheet("theme1"); 
      return false;
      };
  style3.onclick = function () { 
      setActiveStyleSheet("theme2");
      return false
      };
  style4.onclick = function () { 
      setActiveStyleSheet("theme3"); 
      return false
      };            
  }
  
  window.onload = initate;
  </code></pre>
  
  <p>I'm new to javascripts and I haven't written this script myself (http://www.alistapart.com/articles/alternate/) and I managed to create the last part (as shown by comment in code) by myself to have the eventhandlers separate in the javascript file as I want and this part enables the style sheets to be changed the way I want it. But I can't figure out how to get the cookies to work as well to get the themes I'm using to be saved.</p>
  
  <p>EDIT:</p>
  
  <p>Since I'm new I still have a hard time figuring this code out but I've tried changing the last function <code>initiate</code> and used onClick eventhandlers for the saving of cookies but I can't get it to work. 
  I've used this:</p>
  
  <pre><code>style1.onclick = function () {
      createcookie(T1, style, 7);
  }
  </code></pre>
  
  <p>And </p>
  
  <pre><code>document.getElementById("stylesheet1").onclick(createCookie(T1, style, 7));
  </code></pre>
  
  <p>And when I did the changing of style sheets didn't work anymore.</p>