﻿function UpdateMainDivSize() {


}
function ConfirmDelete() {
    return window.confirm("Are you sure you want to delete this record?");


}

function ConfirmCancel() {
    return window.confirm("Are you sure you want to cancel?");


}

function ConfirmAction() {
    return window.confirm("Are you sure?");


}

var msgConfirmAbadonShoppingCart = "If you leave this page the tickets that are temporarily reserved for you will be released.  Are you sure you want to leave?";
var timerShoppingCartIntervalId
var timerShoppingCartExpireTime = new Date();
var timerShoppingCartInterval = 1;
var timerExpireDisplayString
var timerShoppingCartDisplayObject
var remainingMinutes
var remainingSeconds
var timeRemainingMinutesId
var timeRemainingSecondsId
var hiddenRemainingMinutesId
var hiddenRemainingSecondsId
var disableLeaveCartWarning

disableLeaveCartWarning = false;

function SetRemainingTimeLabelIds(labelMinutesId, labelSecondsId) {

    timeRemainingMinutesId = labelMinutesId;
    timeRemainingSecondsId = labelSecondsId;

}
function SetRemainingTimeHiddenIds(labelMinutesId, labelSecondsId) {

    hiddenRemainingMinutesId = labelMinutesId;
    hiddenRemainingSecondsId = labelSecondsId;

}

function InitializeShoppingCartExpireTime(minutes) {
    var currentTime
    //alert(minutes + " - " + seconds);
    currentTime = new Date();
    //alert(currentTime);
    currentTime.setMinutes(currentTime.getMinutes() + minutes);
    //alert(currentTime);
//    if (seconds > 0) {
//        currentTime.setSeconds(seconds);
//    }
    //alert(currentTime);
    timerShoppingCartExpireTime = currentTime;
  
    //alert(timerShoppingCartExpireTime);
}

function SetShoppingCartExpireTime(minutes,seconds) {
    var timeLeft
    var totalSeconds
    //alert(minutes + " - " + seconds);
    timeLeft = new Date();
    //alert(currentTime);
    timeLeft.setMinutes(timeLeft.getMinutes() + minutes);
    //alert(currentTime);

    totalSeconds = timeLeft.getSeconds() + seconds;

    if (Number(totalSeconds) > 59) {
        if (Number(totalSeconds) < 120) {
            var secondsLeft = totalSeconds - 59;
            timeLeft.setMinutes(timeLeft.getMinutes() + 1);
            timeLeft.setSeconds(secondsLeft);
        }

    }
    else {
        timeLeft.setSeconds(totalSeconds);
    }

//    timeLeft.setSeconds();
//    
    //alert(currentTime);
    timerShoppingCartExpireTime = timeLeft;
    //alert(timerShoppingCartExpireTime);
    
}

function StartShoppingCartTimer() {
    //alert("startTimer");
    window.onbeforeunload = confirmExit;
    //window.onbeforeunload = ConfirmReleaseOfTicketsOnHold;
    window.onunload = StopShoppingCartTimer;
    //window.onscroll = PositionTimerToTop;
    UpdateShoppingCartTimerDisplay();
    timerShoppingCartIntervalId = window.setInterval("UpdateShoppingCartTimerDisplay()", timerShoppingCartInterval * 1000);
    if (document.getElementById("divTimeLeftLower")) {
        document.getElementById("divTimeLeftLower").style.display = 'block';
    }
    //PositionTimerToTop();

}

function PositionTimer() {
    //alert(document.documentElement.scrollTop);
//    var topOfTimer = document.documentElement.scrollTop + 200;
//    topOfTimer = topOfTimer + "px";
//   document.getElementById('divTimeLeft').style.top = topOfTimer;
//    document.getElementById('divTimeLeft').style.left = d
}

function confirmExit() {
    
    return msgConfirmAbadonShoppingCart;
}

function StopShoppingCartTimer() {
    

    window.onscroll = null;
    DisableShoppingCartLeavingWarningPrompt();
    window.clearInterval(timerShoppingCartIntervalId);
    if (document.getElementById("divTimeLeftLower")) {
        document.getElementById("divTimeLeftLower").style.display = 'none';
    }
}


function CalculateShoppingCartTimeRemainingBeforeExpiring() {
    
    var now = new Date();
    var timerShoppingCartTimeRemaining = new Date();


    timerShoppingCartTimeRemaining = timerShoppingCartExpireTime - now;
   
      
    return timerShoppingCartTimeRemaining;
}

function UpdateShoppingCartTimerDisplay() {

    // Set the unit values in milliseconds.
    var msecPerMinute = 1000 * 60;
    var msecPerHour = msecPerMinute * 60;
    var msecPerDay = msecPerHour * 24;
    var remainingTime = new Date();
    //alert("UpdateShoppingCartTimerDisplay");
    remainingTime = CalculateShoppingCartTimeRemainingBeforeExpiring();


    // Calculate how many days the interval contains. Subtract that
    // many days from the interval to determine the remainder.
    var days = Math.floor(remainingTime / msecPerDay);
    remainingTime = remainingTime - (days * msecPerDay);

    // Calculate the hours, minutes, and seconds.
    var hours = Math.floor(remainingTime / msecPerHour);
    remainingTime = remainingTime - (hours * msecPerHour);

    var minutes = Math.floor(remainingTime / msecPerMinute);
    remainingTime = remainingTime - (minutes * msecPerMinute);

    var seconds = Math.floor(remainingTime / 1000);

    if ((minutes === 0) && (seconds == 0)) {
        StopShoppingCartTimer();
        DisableShoppingCartLeavingWarningPrompt();
        window.location.replace("shoppingcarttimeout.aspx");
        return;
    }

    if (minutes.toString().length == 1) {
        minutes = "0" + minutes;
    }

    if (seconds.toString().length == 1) {
        seconds = "0" + seconds;
    }

    remainingMinutes = minutes;
    remainingSeconds = seconds;

    timerExpireDisplayString = minutes + ":" + seconds;

    if ((document.getElementById(timeRemainingMinutesId)) && (document.getElementById(timeRemainingSecondsId))) {
        //document.getElementById(timerShoppingCartDisplayObject).innerHTML = timerExpireDisplayString;
        document.getElementById(hiddenRemainingMinutesId).value = remainingMinutes;
        document.getElementById(hiddenRemainingSecondsId).value = remainingSeconds;

        document.getElementById(timeRemainingMinutesId).innerHTML = remainingMinutes;
        document.getElementById(timeRemainingSecondsId).innerHTML = remainingSeconds;
        
        document.getElementById("divTimeLeftLower").innerHTML = document.getElementById("divTimeLeft").innerHTML;
        //document.getElementById("divTimeLeftLower").innerHTML = document.getElementById("divTimeLeft").innerHTML;
    }
    else {
        StopShoppingCartTimer();
    }
    //alert(timerExpireDisplayString);
}

function SetShoppingCartTimerDisplayObject(nameOfObject) {
    timerShoppingCartDisplayObject = nameOfObject;
    ///alert(nameOfObject);
}

function SetShoppingCartTimerInterval(intervalSeconds) {
    timerShoppingCartInterval = intervalSeconds;
    //alert(interval);
}

function ConfirmReleaseOfTicketsOnHold() {
    var result
    if (disableLeaveCartWarning == false) {
        result = window.confirm(msgConfirmAbadonShoppingCart);
    }
    else {
        result = true;
    }

    if (result == true) {
        StopShoppingCartTimer();
    }
    return result;
}


function DisableShoppingCartLeavingWarningPrompt() {
    window.onbeforeunload = null;

}

function EnableShoppingCartLeavingWarningPrompt()
{
    window.onbeforeunload = ConfirmReleaseOfTicketsOnHold;
}

function NavButtonOn(navButtonId,navImageName) {

    document.getElementById(navButtonId).src = "/images/" + navImageName;
}
function NavButtonOff(navButtonId, navImageName) {

    document.getElementById(navButtonId).src = "/images/" + navImageName;
    
}

function ValidateCreditCardChecksum(sender,args) {
    var sum = 0;
    var input
    input = args.Value;

    if (input.length == 0) {
        args.IsValid = false;
        DisplayShoppingCartSubmitOrderButtons();
        return;    
    }

    var re = new RegExp("^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$", "g");
    if (input.match(re) == null) {
        args.IsValid = false;
        DisplayShoppingCartSubmitOrderButtons();
        return;
    }

    args.IsValid = true;
//    var numdigits = input.length;
//    var parity = numdigits % 2;
//    for (var i = 0; i < numdigits; i++) {
//        var digit = parseInt(input.charAt(i))
//        if (i % 2 == parity) digit *= 2;
//        if (digit > 9) digit -= 9;
//        sum += digit;
//    }
//    args.IsValid = (sum % 10) == 0;

}


function ValidateCreditCardVisaMasterCardOnly(sender, args) {
    var sum = 0;
    var input
    var validCard = false;
    input = args.Value;

    if (input.length == 0) {
        args.IsValid = false;
        DisplayShoppingCartSubmitOrderButtons();
        return;
    }

    //visa card check
    var re = new RegExp("^4[0-9]{12}(?:[0-9]{3})?$", "g");
    if (input.match(re) == null) {
        //master card check
        re = new RegExp("^5[1-5][0-9]{14}$", "g");
        if (input.match(re) == null) {
            args.IsValid = false;
            DisplayShoppingCartSubmitOrderButtons();
            return;
        }
    }

   

    args.IsValid = true;
    //    var numdigits = input.length;
    //    var parity = numdigits % 2;
    //    for (var i = 0; i < numdigits; i++) {
    //        var digit = parseInt(input.charAt(i))
    //        if (i % 2 == parity) digit *= 2;
    //        if (digit > 9) digit -= 9;
    //        sum += digit;
    //    }
    //    args.IsValid = (sum % 10) == 0;

}

function ValidateNewPassword(sender, args) {

    var input
    
    input = args.Value;

    if (input.length < 6) {
        args.IsValid = false;
        sender.errormessage = "Password must be at least 6 characters with at least one digit.";
        return;
    }

    var re = new RegExp("[0-9]{1,}", "g");

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Password must be at least 6 characters with at least one digit.";
        return;
    }

  
    args.isValid = true;
}

function ConfirmExitCart() {

    if (window.onunload != null) {
        return ConfirmReleaseOfTicketsOnHold()

    }
    return true;


}

function ValidateCreditCardSecurityCode(sender, args) {

    var re = new RegExp("^\\d{3}$|^\\d{4}$", "g");

    var input

    input = args.Value;

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Credit card security code must be a 3 or 4 digit number.";
        DisplayShoppingCartSubmitOrderButtons();
        setTimeout('window.scrollTo(0, 999999999)', 1000);
        return;
    }


    args.isValid = true;


}

function ValidateCreditCardSecurityCodeQuickSale(sender, args) {

    var re = new RegExp("^\\d{3}$|^\\d{4}$", "g");

    var input

    input = args.Value;

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Credit card security code must be a 3 or 4 digit number.";
        
        return;
    }


    args.isValid = true;


}

function submitenter(formSumbitButtonId, e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
        
        document.getElementById(formSumbitButtonId).click();
        return false;
    }
    else
        return true;
}






function ValidateMobileRecipientAreaCode(sender, args) {

    var input

    input = args.Value;

    if (input.length < 3) {
        args.IsValid = false;
        sender.errormessage = "Text recipient's mobile area code must be three digits.";
        return;
    }

    var re = new RegExp("^\\d{3}", "g");

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Text recipient's mobile area code must be three digits.";
        return;
    }


    args.isValid = true;
}

function ValidateMobileRecipientPrefix(sender, args) {

    var input

    input = args.Value;

    if (input.length < 3) {
        args.IsValid = false;
        sender.errormessage = "Text recipient's mobile prefix must be three digits.";
        return;
    }

    var re = new RegExp("^\\d{3}", "g");

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Text recipient's mobile prefix must be three digits.";
        return;
    }


    args.isValid = true;
}

function ValidateMobileRecipientLineNumber(sender, args) {

    var input

    input = args.Value;

    if (input.length < 4) {
        args.IsValid = false;
        sender.errormessage = "Text recipient's mobile line number must be four digits.";
        return;
    }

    var re = new RegExp("^\\d{4}", "g");

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Text recipient's mobile line number must be four digits.";
        return;
    }


    args.isValid = true;
}


function ValidatePhoneRecipientAreaCode(sender, args) {

    var input

    input = args.Value;

    if (input.length < 3) {
        args.IsValid = false;
        sender.errormessage = "Phone area code must be three digits.";
        return;
    }

    var re = new RegExp("^\\d{3}", "g");

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Phone area code must be three digits.";
        return;
    }


    args.isValid = true;
}

function ValidatePhoneRecipientPrefix(sender, args) {

    var input

    input = args.Value;

    if (input.length < 3) {
        args.IsValid = false;
        sender.errormessage = "Phone prefix must be three digits.";
        return;
    }

    var re = new RegExp("^\\d{3}", "g");

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Phone prefix must be three digits.";
        return;
    }


    args.isValid = true;
}

function ValidatePhoneRecipientLineNumber(sender, args) {

    var input

    input = args.Value;

    if (input.length < 4) {
        args.IsValid = false;
        sender.errormessage = "Phone line number must be four digits.";
        return;
    }

    var re = new RegExp("^\\d{4}", "g");

    if (input.match(re) == null) {
        args.IsValid = false;
        sender.errormessage = "Phone line number must be four digits.";
        return;
    }


    args.isValid = true;
}

function HideShoppingCartSubmitOrderButtons() {
    document.getElementById("divSubmitOrderButtons").style.display = "none";
    document.getElementById("divProcessingMessage").style.display = "block";


}

function DisplayShoppingCartSubmitOrderButtons() {
    document.getElementById("divSubmitOrderButtons").style.display = "block";
    document.getElementById("divProcessingMessage").style.display = "none";


}

function displayPopupDiv(divToDisplay) {
    var popupTopPosition
    var popupLeftPosition


    if (document.getElementById(divToDisplay)) {
        document.getElementById(divToDisplay).style.display = "block";
        document.getElementById("popupBackground").style.display = "block";
        document.getElementById("popupBackground").style.height = document.body.offsetHeight;
        popupTopPosition = f_scrollTop() + 10;
        document.getElementById(divToDisplay).style.top = popupTopPosition + "px";
        popupLeftPosition = (f_clientWidth() / 2) - 400
        document.getElementById(divToDisplay).style.left = popupLeftPosition + "px";
        document.getElementById("popupBackground").style.height = (f_clientHeight() + f_scrollTop() + document.body.offsetHeight) + "px";
    }

}

function displayBuyTicketsLargeImage() {
   // displayPopupDiv("buyTicketLargeImagePopup");
    var popupTopPosition
    var popupLeftPosition


    if (document.getElementById("buyTicketLargeImagePopup")) {
        document.getElementById("buyTicketLargeImagePopup").style.display = "block";
        document.getElementById("popupBackground").style.display = "block";
        document.getElementById("popupBackground").style.height = document.body.offsetHeight;
        document.getElementById("popupBackground").style.width = f_clientWidth();
        popupTopPosition = f_scrollTop() + 10;
        document.getElementById("buyTicketLargeImagePopup").style.top = popupTopPosition + "px";
        popupLeftPosition = (f_clientWidth() / 2) - 400
        document.getElementById("buyTicketLargeImagePopup").style.left = popupLeftPosition + "px";
        document.getElementById("popupBackground").style.height = (f_clientHeight() + f_scrollTop() + document.body.offsetHeight) + "px";
    }
}
function hideBuyTicketsLargeImage() {
    if (document.getElementById("buyTicketLargeImagePopup")) {
        document.getElementById("buyTicketLargeImagePopup").style.display = "none";
        document.getElementById("popupBackground").style.display = "none";
    }

}

function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function displayCenteredPopup(pageName) {
    var w = 480, h = 340;

//if (document.all) {
//   /* the following is only available after onLoad */
//   w = document.body.clientWidth;
//   h = document.body.clientHeight;
//}
//else if (document.layers) {
//   w = window.innerWidth;
//   h = window.innerHeight;
    //}
    h = document.body.offsetHeight;
    w = f_clientWidth();


var popW = w / 2
var popH = h / 2;

var leftPos = (w - popW) / 2;
var topPos = (h - popH) / 2;

popH = parseInt(popH, 10);
popW = parseInt(popW, 10);
leftPos = parseInt(leftPos, 10);
topPos = parseInt(topPos, 10);

var popupFeatures = "scrollbars=1,width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos;
window.open(pageName,'popup',popupFeatures);



}
