﻿function cancelEvent(e) {
  var evt = e ? e : window.event;

  // cancelBubble is supported by IE - this will kill the bubbling process.
  evt.cancelBubble = true;
  evt.returnValue = false;

  // stopPropagation works only in Firefox.
  if (evt.stopPropagation) {
    evt.stopPropagation();
    evt.preventDefault();
  }
}

function pngFix(blank) {
  return;
  var els = document.getElementsByTagName('*');
  var ip = /\.png/i;
  var i = els.length;
  while (i-- > 0) {
    var el = els[i];
    var es = el.style;
    if (el.src && el.src.match(ip) && !es.filter) {
      alert('src=' + el.src + ', width=' + el.width + ', height=' + el.height);
      es.height = el.height;
      es.width = el.width;
      es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + el.src + "',sizingMethod='crop')";
      el.src = blank;
    }
    else {
      var elb = el.currentStyle.backgroundImage;
      if (elb.match(ip)) {
        var path = elb.split('"');
        var rep = (el.currentStyle.backgroundRepeat == 'no-repeat') ? 'crop' : 'scale';
        es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + path[1] + "',sizingMethod='" + rep + "')";
        es.height = el.clientHeight + 'px';
        es.backgroundImage = 'none';
        var elkids = el.getElementsByTagName('*');
        if (elkids) {
          var j = elkids.length;
          if (el.currentStyle.position != "absolute")
            es.position = 'static';
          while (j-- > 0) {
            if (!elkids[j].style.position)
              elkids[j].style.position = "relative";
          }
        }
      }
    }
  }
}

function isValidDate(input) {
  var validFormat = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
  var result = false;

  if (validFormat.test(input.value) == true) {
    var m = parseInt(input.value.split("/")[0]);
    var d = parseInt(input.value.split("/")[1]);
    var y = parseInt(input.value.split("/")[2]);
    if (y < 100) y += 2000;
    var date = new Date(y, m - 1, d);
    if ((date.getMonth() + 1 == m) && (date.getDate() == d) && (date.getFullYear() == y))
      result = true;
  }

  if (result == false)
    input.select();
  return result;
}
