﻿function CallCountDown() {
    Sys.Net.WebServiceProxy.invoke(countdownServicePath, 'GetTimeout', false, { "reservationTimeLimit": reservation_time_limit }, SetCountDown);
}
function SetCountDown(value) {
    timeout = value;
    countdown();
}
var stoptime = false;
function countdown() {
    if (timeout > -1) {
        if (!stoptime) {
            document.getElementById('countdown').innerHTML = timeFriendly(timeout);
        }
        timeout -= 1;
        t = setTimeout(countdown, 1000);
    }
    else {

        document.getElementById('expiry').innerHTML = '<b>EXPIRED</b>';
        if (stoptime) {
            t = setTimeout(countdown, 1000);
        }
        else {
            t = setTimeout(redirectTimeout, 600);
        }
    }
}

var time_countdown = 0;
function SetCountDownButton(value) {
    time_countdown = value;
    countdown_button();
}
function countdown_button() {
    var bt = $('#ctl00_ContentPlaceHolder1_WucShowsMain1_WucReserveTickets1_bntReserve');
    if (time_countdown > -1) {
        bt.val('Please wait ' + timeFriendly(time_countdown));
        bt.attr("disabled", "true");
        bt.click(function() {return false;});
        bt.css("background-image", "none");  
        bt.css("cursor", "default");  
        time_countdown -= 1;
        t = setTimeout(countdown_button, 1000);
    }
    else {
        bt.val('reserve tickets');
        bt.css("background-image", "");
        bt.css("cursor", "");  
        bt.removeAttr('disabled')
        bt.click(function () {
            //Reservation_Loading(); 
            //__doPostBack('ctl00$ContentPlaceHolder1$WucShowsMain1$WucReserveTickets1$bntReserve', '');
        });
    }
}

function redirectTimeout() {
    window.location = timeoutURL;
}

function timeFriendly(totalSeconds) {
    minutes = Math.floor(totalSeconds / 60);
    if (minutes.toString().length == 1) minutes = '0' + minutes;
    seconds = totalSeconds % 60;
    if (seconds.toString().length == 1) seconds = '0' + seconds;
    return minutes + ':' + seconds;
}

function pauseTimer(button) {
    button.onclick = function () {
        return false;
    }
    button.value = 'please wait...';
    button.className = 'wait';
    //clearTimeout(t);
    //document.getElementById('expiry').innerHTML = '<b>please wait...</b>';
}
function pauseButton(button, buttonValue) {
    button.onclick = function () {
        return false;
    }
    button.value = buttonValue + '...';
    button.className = 'wait';
    //clearTimeout(t);
    //document.getElementById('expiry').innerHTML = '<b>please wait...</b>';
}
function pauseButton(button) {
    button.onclick = function () {
        return false;
    }
    button.value = 'please wait...';
    button.className = 'wait';
    //clearTimeout(t);
    //document.getElementById('expiry').innerHTML = '<b>please wait...</b>';
}

function pauseReserve(button) {
    button.onclick = function () {
        return false;
    }
    button.style.backgroundImage = 'none';
    button.value = 'please wait...';
    //button.className = '';
    //clearTimeout(t);
    //document.getElementById('expiry').innerHTML = '<b>please wait...</b>';
}

function grayOut(vis, options) {
    // Pass true to gray out screen, false to ungray
    // options are optional.  This is a JSON object with the following (optional) properties
    // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
    // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
    // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
    // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
    // in any order.  Pass only the properties you need to set.
    var options = options || {};
    var zindex = 50;  //options.zindex || 50;
    var opacity = options.opacity || 70;
    var opaque = (opacity / 100);
    var bgcolor = options.bgcolor || '#000000';
    var dark = document.getElementById('darkenScreenObject');
    if (!dark) {
        // The dark layer doesn't exist, it's never been created.  So we'll
        // create it here and apply some basic styles.
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
        var tbody = document.getElementsByTagName("body")[0];
        var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position = 'absolute';                 // Position absolutely
        tnode.style.top = '0px';                           // In the top
        tnode.style.left = '0px';                          // Left corner of the page
        tnode.style.overflow = 'hidden';                   // Try to avoid making scroll bars            
        tnode.style.display = 'none';                      // Start out Hidden
        tnode.id = 'darkenScreenObject';                   // Name it so we can find it later
        tbody.appendChild(tnode);                            // Add it to the web page
        dark = document.getElementById('darkenScreenObject');  // Get the object.
    }
    if (vis) {
        // Calculate the page width and height 
        if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
            var pageWidth = document.body.scrollWidth + 'px';
            var pageHeight = document.body.scrollHeight + 'px';
        } else if (document.body.offsetWidth) {
            var pageWidth = document.body.offsetWidth + 'px';
            var pageHeight = document.body.offsetHeight + 'px';
        } else {
            var pageWidth = '100%';
            var pageHeight = '100%';
        }
        //set the shader to cover the entire page and make it visible.
        dark.style.opacity = opaque;
        dark.style.MozOpacity = opaque;
        dark.style.filter = 'alpha(opacity=' + opacity + ')';
        dark.style.zIndex = zindex;
        dark.style.backgroundColor = bgcolor;
        dark.style.width = pageWidth;
        dark.style.height = pageHeight;
        dark.style.display = 'block';
    } else {
        dark.style.display = 'none';
    }
}
function resTicketSteps(sender) {

    pauseReserve(sender);
    document.getElementById('resContainerId').style.display = 'none';
    document.getElementById('resWaitContainerId').style.display = 'block';
    grayOut(true);
    dark = document.getElementById('darkenScreenObject');
    if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
        var pageWidth = document.body.scrollWidth;
    } else {
        var pageWidth = document.body.offsetWidth;
    }
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');
    tnode.style.position = 'absolute';
    tnode.style.top = '250px';
    tnode.style.zIndex = 51;
    tnode.style.left = ((pageWidth / 2) - 180) + 'px';
    tnode.setAttribute('class', 'innerBox');
    var tnodeParent = document.createElement('div');
    tnodeParent.setAttribute('class', 'content');
    tbody.appendChild(tnodeParent);
    tnodeParent.appendChild(tnode);
    var tnodeTop = document.createElement('div');
    tnodeTop.setAttribute('class', 'innerBoxTop');
    tnode.appendChild(tnodeTop);
    var tnodeMiddle = document.createElement('div');
    tnodeMiddle.innerHTML = "<h3>Reservation in Process</h3>"
    tnodeMiddle.innerHTML += "<p>Please wait we are attempting to reserve tickets for your order, this process can take several minutes during peak time so please be patient and do not refresh the page or navigate away.</p>";
    tnodeMiddle.innerHTML += "<img src='/Images/loading.gif' alt='Loading ... ' style='padding-left:130px;/>";
    tnode.appendChild(tnodeMiddle);
    var tnodeBottom = document.createElement('div');
    tnodeBottom.setAttribute('class', 'innerBoxBottom');
    tnode.appendChild(tnodeBottom);

}
