function ImportCookies() {
  var buff = "";
  var cookies = Array("sColors", "sSticky", "sMulti", "sTimer", "sName", "sScore", "sGames");
  for (var e in cookies) {
    e = cookies[e];
    var c = ReadCookie(e);
    if (c == "true")
      c = 1;
    if (c == "false")
      c = 0;
    buff += "<input type='hidden' name='"+e+"' value='"+c+"'/> ";
  }
  cookies = Array("sBestTime0", "sBestTime1", "sBestTime2", "sBestTime3");
  for (var e in cookies) {
    e = cookies[e];
    var c = ReadCookie(e);
    if (c != null)
      c = Math.floor(Number(c));
    buff += "<input type='hidden' name='"+e+"' value='"+c+"'/> ";
  }
  document.write(buff);
}

function GetFlashMovieObject(movieName)
{
  if (window.document[movieName])
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }
  else
  {
    return document.getElementById(movieName);
  }
}

function Validate(url, message) {
  if (!confirm(message))
    return;
  window.location.href = url;
}

function CreateCookie(name,value,days)
{
  var date = new Date();
  document.cookie = name+"=1; expires="+date.toGMTString()+"; path=/"; // deprecated
  if (days) {
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else
    var expires = "";
  var domain = "; path=/; domain=.sudokushootout.com";
  document.cookie = name+"="+value+expires+domain;
}

function ReadCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  var v = null;
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ')
      c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) {
      var res = c.substring(nameEQ.length,c.length);
      if (res == "undefined")
       v = null;
     v = res;
       return v;
    }
  }
  return v;
}
function EraseCookie(name)
{
  CreateCookie(name,"",-1);
}

function HTTPComm(url, handler, params) {
  var xmlhttp =  new XMLHttpRequest();
  xmlhttp.open('POST', url, true);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
      if (xmlhttp.status != 200) {
	return;
      }
      if (handler != null) {
	handler(xmlhttp.responseText);
      }
    }
  }
  xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  if (params == null)
    params = "";
  xmlhttp.setRequestHeader('Content-length', params.length);

  xmlhttp.send(params); // null or name=value&name=value...
}

function RequestObject() {
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}