﻿// Called when async postback begins             
function prm_InitializeRequest(sender, args) {
    // get the divImage and set it to visible
    var panelProg = document.getElementById('activityDiv');
    panelProg.style.display = 'block';
    // position the div
    positionActivityDiv();
}

// Called when async postback ends             
function prm_EndRequest(sender, args) {
    // get the divImage and hide it again
    var panelProg = document.getElementById('activityDiv');
    panelProg.style.display = 'none';
    addCalenders();
    // check if the form is now valid
    var valid = "ctl00_ContentPlaceHolder1_ProductDrivewayToRunway_hidden_formValid";
    if (document.getElementById(valid).value == 'YES') {
        // finishd with the d2r tab now so hide and show all others
        // parse the url and swap showtab for showtab=AllExceptDrivewayToRunway
        var locate = document.forms["aspnetForm"].action;
        locate = locate.replace("DrivewayToRunwayONLY", "FinishDrivewayToRunway");
        document.getElementById('ctl00_ContentPlaceHolder1_tab_visible').value = "FinishDrivewayToRunway";
        document.forms["aspnetForm"].action = locate;
        // clear this on the page load event - document.getElementById(valid).value = 'NO';
        // submit this form and force a refresh so the basket updates
        document.forms["aspnetForm"].submit();
    }
}

function addCalenders() {
    // check it does not exist already
    if (A_TCALS['cal_return_airport_to_pc_departing_date'] == null) {
        new tcal({ 'formname': 'aspnetForm', 'controlname': 'ctl00_ContentPlaceHolder1_ProductDrivewayToRunway_transfer_out_pc_to_airport_departing_date', 'id': 'cal_out_pc_to_airport_departing_date' });
        new tcal({ 'formname': 'aspnetForm', 'controlname': 'ctl00_ContentPlaceHolder1_ProductDrivewayToRunway_transfer_out_airport_to_pc_departing_date', 'id': 'cal_out_airport_to_pc_departing_date' });
        new tcal({ 'formname': 'aspnetForm', 'controlname': 'ctl00_ContentPlaceHolder1_ProductDrivewayToRunway_transfer_return_pc_to_airport_departing_date', 'id': 'cal_return_pc_to_airport_departing_date' });
        new tcal({ 'formname': 'aspnetForm', 'controlname': 'ctl00_ContentPlaceHolder1_ProductDrivewayToRunway_transfer_return_airport_to_pc_departing_date', 'id': 'cal_return_airport_to_pc_departing_date' });
    }
}

function positionActivityDiv() {
    // hStr = getCenter('y') + 'px';
    hStr = '100px';
    document.getElementById("activityDiv").style.top = hStr;
    // width 6750 of main container, div is 200px wide left = 650 - 200 = 450/2 = 225
    document.getElementById("activityDiv").style.left = "225px";
}

function getCenter(whichOne) {
    // First, determine how much the visitor has scrolled 
    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window 

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    switch (whichOne) {
        case "x":
            return scrolledX + (centerX / 2);
            break;
        case "y":
            return scrolledY + (centerY / 2);
            break;
    }
}       