if (window.attachEvent) {
  window.attachEvent('onscroll', alignFloatLayers);
  window.attachEvent('onresize', alignFloatLayers);
  window.attachEvent('onload', showShortCut);
} else if (window.addEventListener) {
  window.addEventListener('resize', alignFloatLayers, false);
  window.addEventListener('scroll', alignFloatLayers, false);
  window.addEventListener('load', showShortCut, false);
}
var today = new Date();
var ckexpire = new Date(today.getTime() + 365 * 86400000);
var ShortCutLayer = 'shortcutlayer';
var ShortCutInnerLayer = 'scb_div';
var ShortCutStatus = 0;
var ShortCutList = getCookie("sc_num");
if (ShortCutList == null || ShortCutList.length < 1) {
  ShortCutList = ",";
}
var lockStatus = getCookie("sc_status");
if (lockStatus == null || lockStatus.length < 1) {
  lockStatus = "";
  ShortCutStatus = 0;
} else {
  ShortCutStatus = 1;
}
function showShortCut() {
  var lay  = document.getElementById(ShortCutInnerLayer);
  if (lay != null) {
    if (ShortCutStatus > 0) {
      lay.style.visibility = 'visible';
      lay.style.display = 'inline-block';
    } else {
      lay.style.visibility = 'hidden';
      lay.style.display = 'none';
    }
  }
  lay  = document.getElementById(ShortCutLayer);
  if (lay != null) {
    var left = getXCoord(lay);
    var top = getYCoord(lay);
    lay.style.position = 'absolute';
    lay.style.top = top;
    lay.style.left = left;
    if (window.attachEvent) {
      new FloatLayer(ShortCutLayer,10,-1,3);
      getFloatLayer(ShortCutLayer).initialize();
      alignFloatLayers();
    } else if (window.addEventListener) {
      new FloatLayer(ShortCutLayer,10,-1,3);
      getFloatLayer(ShortCutLayer).initialize();
      alignFloatLayers();
    }
  }
  shortCutButtonsDisplay();
}
function shortCutTrigger() {
  if (ShortCutStatus == 0) {
    ShortCutStatus = 1;
  } else {
    ShortCutStatus = 0; 
  }
  var lay  = document.getElementById(ShortCutInnerLayer);
  if (lay != null) {
    if (ShortCutStatus > 0) {
      lay.style.visibility = 'visible';
      lay.style.display = 'inline-block';
    } else {
      lay.style.visibility = 'hidden';
      lay.style.display = 'none';
    }
    getFloatLayer(ShortCutLayer).initialize();
    getFloatLayer(ShortCutLayer).align();
  }
  lay = document.getElementById("OpenCloseButton");
  if (lay != null) {
    if (ShortCutStatus > 0) {
      lay.innerHTML = "&nbsp;&#x25bc;&nbsp;";
      lay.title = label_shortcut_close;
    } else {
      lay.innerHTML = "&nbsp;&#x25b2;&nbsp;";
      lay.title = label_shortcut_open;
    }
  }
}
function shortCutButton(val) { 
  var pat = ","+val+",";
  var idx = ShortCutList.indexOf(pat);
  var len = pat.length;
  if (ShortCutList == pat) {
    ShortCutList = ",";
  } else if (idx != -1) {
    ShortCutList = ShortCutList.substring(0,idx) + ShortCutList.substring(idx+len-1);
  } else {
    if (ShortCutList.length > 0) {
      ShortCutList = ShortCutList + val + ",";
    } else {
      ShortCutList = "," + val + ",";
    }
  }
  setCookie("sc_num",ShortCutList,ckexpire);
  shortCutButtonsDisplay();
}
function shortCutButtonsDisplay() {
  var lay;
  for (var i = 1; i <= 49; i++) {
    lay  = document.getElementById('scb_'+i);
    if (lay != null) {
      if (ShortCutList.indexOf(","+i+",") != -1) {
        lay.style.backgroundColor = '#000000';
        lay.style.color = '#eeeeee';
      } else {
        lay.style.backgroundColor = '#eeeeee';
        lay.style.color = '#000000';
      }
    }
  }
  lay  = document.getElementById('scb_lock');
  if (lay != null) {
    if (lockStatus == "1") { 
      lay.value = label_shortcut_release;
    } else {
      lay.value = label_shortcut_lock;
    }
  }
  lay = document.getElementById("OpenCloseButton");
  if (lay != null) {
    if (ShortCutStatus > 0) {
      lay.innerHTML = "&nbsp;&#x25bc;&nbsp;";
      lay.title = label_shortcut_close;
    } else {
      lay.innerHTML = "&nbsp;&#x25b2;&nbsp;";
      lay.title = label_shortcut_open;
    }
  }
  lay = document.getElementById("PinButton");
  if (lay != null) {
    if (lockStatus > 0) {
      lay.innerHTML = "&nbsp;&#x27b7;&nbsp;";
      lay.title = label_shortcut_release;
    } else {
      lay.innerHTML = "&nbsp;&#x27b8;&nbsp;";
      lay.title = label_shortcut_lock;
    }
  }
}
function shortCutToReset() {
  ShortCutList = ",";
  setCookie("sc_num",ShortCutList,ckexpire);
  shortCutButtonsDisplay();
}
function shortCutToLock() {
  if (ShortCutStatus > 0) {
    if (lockStatus == "1") {
      lockStatus = "";
    } else {
      lockStatus = "1";
    }
    setCookie("sc_status",lockStatus,ckexpire);
    shortCutButtonsDisplay();
  }
}
function shortCutToDraw(errMessage) {
  var arr = ShortCutList.split(",");
  var newlist = "";
  var counter = 0;
  for (var i = 0; i < arr.length; i++) {
    if (arr[i].length > 0) {
      if (newlist.length > 0) {
        newlist += "+";
      }
      newlist += arr[i];
      counter++;
    }
  }
  if (counter < 1) {
    alert(errMessage);
    return;
  } else {
    window.location.href="numGenerator.html?number=" + newlist;
  }
}
function shortCutToCheck(errMessage) {
  var arr = ShortCutList.split(",");
  var newlist = "";
  var counter = 0;
  for (var i = 0; i < arr.length; i++) {
    if (arr[i].length > 0) {
      if (newlist.length > 0) {
        newlist += "+";
      }
      newlist += arr[i];
      counter++;
    }
  }
  if (counter > 7 || counter < 6) {
    alert(errMessage);
    return;
  } else {
    window.location.href="matchResult.html?numbers_input=" + newlist;
  }
}
