$(function () {
  $(".home .bxslider").bxSlider({
    auto: true,
    /*mode: 'fade'*/
  });

  $("#day").datepicker({
    minDate: "0",
    maxDate: "+1M",
    /*changeMonth: true,*/
    numberOfMonths: 1,
    firstDay: 1,
    showButtonPanel: true,
    dateFormat: "dd-mm-yy",
    onSelect: function (date) {
      //$("#seleditions").fadeIn(1000);
      $("#seleditions").fadeIn(1000).css("display", "table-cell");
      filterEditions();
    },
  });

  $("#sxsidemenu").accordion({
    active: false,
    collapsible: true,
    heightStyle: "content",
  });
});

function checkTime(oToCheck, oPssEvt1) {
  var oKeyEvent = oPssEvt1 || window.event || { charCode: 0, keyCode: 0 },
    nChar = oKeyEvent.charCode,
    nKey = oKeyEvent.keyCode,
    sVal = oToCheck.value,
    sNewVal =
      sVal.substring(
        0,
        oToCheck.selectionStart - (nKey === 8 && nChar === 0 ? 1 : 0)
      ) +
      (nChar > 0 ? String.fromCharCode(nChar) : "") +
      sVal.slice(oToCheck.selectionEnd + (nKey === 46 && nChar === 0 ? 1 : 0)),
    bFormat = nChar === 0 || /^\d{1,2}(?:\:\d{1,2})?$/.test(sNewVal);

  if (bFormat) {
    var aCorrect = sNewVal.split(":");
    for (var nDigit = 0; nDigit < aCorrect.length; nDigit++) {
      if (parseFloat(aCorrect[nDigit]) > 23 + 36 * nDigit) {
        bFormat = false;
        break;
      }
    }
  }

  return bFormat;
}

function formatTime(oToFix, oPssEvt2) {
  var nKey = (oPssEvt2 || window.event || { keyCode: 8 }).keyCode,
    nSelS = oToFix.selectionStart,
    nSelE = oToFix.selectionEnd,
    sVal = oToFix.value;
  if (
    nSelS === nSelE &&
    nSelS === sVal.length &&
    /^\d{1,2}$/.test(sVal) &&
    (nSelS === 2 || parseFloat(sVal) > 2) &&
    nKey !== 8 &&
    nKey !== 46 &&
    (nKey < 32 || nKey > 41)
  ) {
    sVal += ":";
    oToFix.value = sVal.replace(/^(\d)\:/, "0$1:");
    oToFix.focus();
  } else if (/\:\d$/.test(sVal) && parseFloat(/\d$/.exec(sVal)) > 5) {
    oToFix.value = sVal.replace(/\d$/, "0$&");
    oToFix.focus();
  }
}

/*
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
	return pattern.test(emailAddress);
};
*/

/**
 * Create a cookie
 */
/*
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=/";
}
*/

/**
 * Get a cookie
 */
/*
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) {
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}
*/

function logout() {
  location.href = "logout.php";
  //	window.open("logout.php");
}

function getToday() {
  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth() + 1; //January is 0!
  var yyyy = today.getFullYear();

  if (dd < 10) dd = "0" + dd;
  if (mm < 10) mm = "0" + mm;

  today = dd + "-" + mm + "-" + yyyy;
  return today;
}
