// fs_base.js
// some commonly-used functions on my web pages.
// if you are reading this, presumably you're interested in how my js works.
// to be honest, you'd be better off spending your time with code written by
// someone who likes javascript. best of luck to you in finding such a person.

function gElement(id)
{
    var returnVar;
    if (document.getElementById) returnVar = document.getElementById(id);
    else if (document.all) returnVar = document.all[id];
    else if (document.layers) returnVar = document.layers[id];
    return returnVar;
}

function setCookie(c_name,value,expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function ajax(url, response_handler)
{
  //// change the stylesheet
  if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
  else // IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
      response_handler(xmlhttp.responseText);
  };
  xmlhttp.open("GET", url, true);
  xmlhttp.send();
}

function change_page_style(new_style)
{
  //// change the stylesheet
  ajax("http://www.fuzziqersoftware.com/site_images/style.php?style=" + new_style,
    function (response) {
      gElement('main_style').innerHTML = xmlhttp.responseText;
    });

  //// change the banner (only if "secret" banner isn't used)
  if (gElement('banner')) {
    ajax("http://www.fuzziqersoftware.com/site_images/style.php?get_banner_url&style=" + new_style,
      function() {
        gElement('banner').src = xmlhttp2.responseText;
      });
  }

  //// set the style cookie
  setCookie('style', new_style, 3650);
}

