﻿///////// ROLLOVERS /////////////////////

// The View btn rollover.
function viewRollover(objIcon) {
    var oIcon = objIcon;
    var i = oIcon.src.indexOf("view.png", 0);
    if (i == -1) {
        oIcon.src = "../Systems/Graphics/Buttons/view.png";
    } else {
        oIcon.src = "../Systems/Graphics/Buttons/viewH.png";
    }
}

// The Info btn rollover.
function infoRollover(objIcon) {
    var oIcon = objIcon;
    if (oIcon.nameProp == "infoBtnH.png") {
        oIcon.src = "../Systems/Graphics/infoBtn.png";
    } else {
        oIcon.src = "../Systems/Graphics/infoBtnH.png";
    }
}

// The 18 hole btn rollover.
function ERollover(objIcon) {
    var oIcon = objIcon;
    var i = oIcon.src.indexOf("18up.png", 0);
    if (i == -1) {
        oIcon.src = "../Systems/Graphics/Buttons/18up.png";
    } else {
        oIcon.src = "../Systems/Graphics/Buttons/18over.png";
    }
}

// The 9 hole btn rollover.
function NRollover(objIcon) {
    var oIcon = objIcon;
    var i = oIcon.src.indexOf("9up.png", 0);
    if (i == -1) {
        oIcon.src = "../Systems/Graphics/Buttons/9up.png";
    } else {
        oIcon.src = "../Systems/Graphics/Buttons/9over.png";
    }
}

// The Playing Partners btn rollover.
function ppRollover(objIcon) {
    var oIcon = objIcon;
    if (oIcon.nameProp == "groupIconH.gif") {
        oIcon.src = "../Systems/Graphics/groupIcon.gif";
    } else {
        oIcon.src = "../Systems/Graphics/groupIconH.gif";
    }
}

//////////////////////////////

// Globals
var _sIconTop
var _sIconLeft

// Hide the popup
function hidePopup(sThePnl) {

    var oThePnl = getPnl(sThePnl);
    oThePnl.style.display = "none";

}

// Get the popup panel.
function getPnl(sThePnl) {
    return document.getElementById(sThePnl);
}

// Find the x,y position of an object and set the global variables (_sIconTop & _sIconLeft).
function findIconXY(objIcon) {
    _sIconLeft = _sIconTop = 0;
    if (objIcon.offsetParent) {
        do {
            _sIconLeft += objIcon.offsetLeft;
            _sIconTop += objIcon.offsetTop;
            objIcon = objIcon.offsetParent;
        } while (objIcon != null && objIcon.nodeName != 'HTML');
        if (objIcon != null) {
            _sIconLeft += objIcon.offsetLeft;
            _sIconTop += objIcon.offsetTop;
        }
    }

    // Slight adjustment to nudge the "balloon" closer to the center of the calling icon.
    _sIconLeft = _sIconLeft + 3;
    _sIconTop = _sIconTop + 5

}

// Show the popup. Includes a callback to a server side function that pulls and returns a dataset.
function showPopup(id, objIcon, sTheCallBackName, sThePnl) {

    // id = the id to use in order to get data id necessary.
    // objIcon = the icon in order to get the postion to place the popup.
    // sTheCallBackName = the name of the aspx callback to call.
    // sThePnl = the name of the popup panel.

    // If the popup is already visible, hide it (for a toggle effect).
    var oThePnl = getPnl(sThePnl);

    if (oThePnl.style.display == 'block') {
        hidePopup(sThePnl);
        return;
    }

    // find the position of the icon clicked.
    findIconXY(objIcon);

    switch (sTheCallBackName) {
        case "cbkExpTeesCHH":   // call expired tees popup for the course handicap control HOME. X
            cbkExpTeesCHH.PerformCallback(id);
            break;
        case "cbkExpTeesCHA":   // call expired tees popup for the course handicap control AWAY. X
            cbkExpTeesCHA.PerformCallback(id);
            break;
        case "cbkExpTeesPSH":   // call expired tees popup for the Post A Score control HOME. X
            cbkExpTeesPSH.PerformCallback(id);
            break;
        case "cbkExpTeesPSA":   // call expired tees popup for the Post A Score control AWAY.
            cbkExpTeesPSA.PerformCallback(id);
            break;
        case "cbkESI":          // call extended score information popup on wucGolferScoreHistoryDXGrid.ascx. X
            cbkESI.PerformCallback(id);
            break;
        case "cbkPPS":          // call Playing Partners popup on wucGolferScoreHistoryDXGrid.ascx. X
            cbkPPS.PerformCallback(id);
            break;
        case "cbkESI9":         // call extended score information popup on wucGolferScoreHistoryDXGrid.ascx. X
            cbkESI9.PerformCallback(id);
            break;
        case "cbkPPS9":         // call Playing Partners popup on wucGolferScoreHistoryDXGrid.ascx. X
            cbkPPS9.PerformCallback(id);
            break;
    }

}

// Show the popup. DOES NOT Include a callback to a server side function that pulls and returns a dataset.
function showSwitcher(objIcon, sThePnl) {

    // objIcon = the icon in order to get the postion to place the popup.
    // sThePnl = the name of the popup panel.

    // find the position of the icon clicked.
    findIconXY(objIcon);

    var element = getPnl(sThePnl);

    if (element != null) {
        $('#' + sThePnl).fadeIn('slow'); //jQuery
        element.style.display = 'block';
        element.style.position = 'absolute';
        var sTop = (_sIconTop - 10) + 'px';
        var sLeft = (_sIconLeft - (element.offsetWidth - 56)) + 'px';
        element.style.top = sTop;
        element.style.value = 'z-index: 999';
        element.style.left = sLeft;
    }
}


// Show the popup. DOES NOT Include a callback to a server side function that pulls and returns a dataset.
function showPopupWOData(objIcon, sThePnl) {

    // objIcon = the icon in order to get the postion to place the popup.
    // sThePnl = the name of the popup panel.

    // find the position of the icon clicked.
    findIconXY(objIcon);

    var element = getPnl(sThePnl);
    element.style.display = 'block';
    element.style.position = 'absolute';
    
    var sTop = (_sIconTop - (element.offsetHeight + 20)) + 'px';
    var sLeft = (_sIconLeft - (element.offsetWidth + 20)) + 'px';
    element.style.top = sTop;
    element.style.left = sLeft;

}

// Show the popup. DOES NOT Include a callback to a server side function that pulls and returns a dataset.
function showPopupWODataLo(objIcon, sThePnl) {

    // objIcon = the icon in order to get the postion to place the popup.
    // sThePnl = the name of the popup panel.

    // find the position of the icon clicked.
    findIconXY(objIcon);

    var element = getPnl(sThePnl);
    $('#' + sThePnl).fadeIn('fast'); //jQuery
    element.style.display = 'block';
    element.style.position = 'absolute';

    var sTop = (_sIconTop) + 'px';
    var sLeft = (_sIconLeft - element.offsetWidth - 20) + 'px';
    element.style.top = sTop;
    element.style.left = sLeft;

}

// Get the placeholder span that exists within the popup that will hold the generated html (the popup content).
function getPopupContentSpan(sTheContentSpan) {
    return document.getElementById(sTheContentSpan);
}
// End Popup
    
