title: Change cookie value onclick
body: <p>Sorry if this is really obvious, not great at coding and new to cookies so stil trying to get my head round it. I am trying to create a website redirect for my Magento installation. In the index.php I have placed the following code which checks the users IP location, directs them to the correct website and sets a cookie. If a cookie is already set it takes the value from the cookie and directs to a website based on this.</p>
  
  <pre><code>if ((isset($_COOKIE['penstore']) )){
  
       $_SERVER['MAGE_RUN_CODE'] = $_COOKIE['penstore'];
       $_SERVER['MAGE_RUN_TYPE'] = "website"; 
  } 
  else 
  { 
  
  include("geoip.inc");
  $ip=$_SERVER['REMOTE_ADDR'];
  $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
  
  $country_code = geoip_country_code_by_addr($gi, "$ip");
  
  geoip_close($gi);
  
  switch($country_code)
  
  { case "CA": case "US":
  $_SERVER['MAGE_RUN_CODE'] = "usa";
  $_SERVER['MAGE_RUN_TYPE'] = "website";
  setcookie("penstore",'usa',time()+43200);
  break;
    case "GB":
  $_SERVER['MAGE_RUN_CODE'] = "uk";
  $_SERVER['MAGE_RUN_TYPE'] = "website";
  setcookie("penstore",'uk',time()+43200);
  break;
    default:
  $_SERVER['MAGE_RUN_CODE'] = "int";
  $_SERVER['MAGE_RUN_TYPE'] = "website";
  setcookie("penstore",'int',time()+43200);
  }
  }
  </code></pre>
  
  <p>This all appears to work okay, my problem is finding a way to allow customers to change websites by clicking an image in the header. I have tried several different methods based on code found on the web and this site but I can't get any of it to work.  I currently have the following code in my header.phtml:</p>
  
  <pre><code>&lt;script language="text/javascript"&gt;
  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 var expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
      location.reload();
  }
  &lt;/script&gt;
  
  &lt;a href="#" onclick="createCookie('penstore','int',30)"&gt;&lt;img src="http://mysite.com/images/INT.gif"&gt;&lt;/a&gt;
  &lt;a href="#" onclick="createCookie('penstore','usa',30)"&gt;&lt;img src="http://mysite.com/images/US.gif"&gt;&lt;/a&gt;
  &lt;a href="#" onclick="createCookie('penstore','uk',30)"&gt;&lt;img src="http://mysite.com/images/GB.gif"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>The idea is that the customer clicks on the image which causes the cookie value to be updated and the current page to be reloaded, which based on the code in the index.php, would cause a different website to load. All that happens is the # gets added to the url?</p>
  
  <p>Edit: To clarify, I'm trying to switch websites, not stores, so can't use Magento store switcher.</p>