/// <reference path="jquery-1.5.min.js" />
/// <reference path="jquery-1.5-vsdoc.js" />

var mWidth = 160; // Width value for the ebay right side ad
var mStartingHeight = 811; // Height to deduct from the left side table and end of right side google ad before then deciding to put the ebay ad (if there is any height left)
var mMaxHeight = 1400;
var mMinHeight = 150;

$(document).ready(function () {
    $('.pageGroups a').click(function (e) {
        // Set the cookie for the per page
        SetCookieValue($(this).attr('rel'));
    });
});

/* Cookie Helper Function */
function SetCookieValue(cookieValue) {
    $.cookie('itemsPerPage', cookieValue);
}

// Function gets called on the ebay ad call to calculate the height based on the height of the pop report table
function GetEbayAdHeight() {
    if ($.browser.msie) {
        mStartingHeight = 800;
    }

    var ebayAdHeight = ($('.main2columncontent').height() - mStartingHeight);

    return ebayAdHeight > mMaxHeight ? mMaxHeight : ebayAdHeight;
}

// (art) 04-02-2010. FB 37562.  added boolean parameter bShowPlusGrade
function ShowChildren (specNo, controlID, childRowCount, cellCount, columnCount, tabIndex, rowIndex, bShowPlusGrade)
{
    var parentHTML = $('#' + controlID).html();
    var imageControl = $('#' + controlID + '_img');
 
    SetCursorAction ('wait');
    
    // Remove all the rows is currently shown, this is called first due to a bug if users click too fast & too many times in the row.
    for(var i = 0; i <= childRowCount; i++)
    {
        var currentRowID = specNo + '_child_' + i;

        $('#' + currentRowID).remove();
    }
    
    // If the image is to expand then get the children and change the icon to collapse
    if (imageControl.attr('src') == 'images/expand.gif')
    {
        GetChildrenSpecRows(specNo, controlID, childRowCount, cellCount, columnCount, tabIndex, rowIndex, bShowPlusGrade);

        imageControl.attr('src', 'images/collapsed.gif');
    }
    else // Otherwise, reset the icon to expand
    {
        imageControl.attr('src', 'images/expand.gif');
    }
    
    SetCursorAction ('default');
}

function SetCursorAction (cursorAction)
{
    document.body.style.cursor = cursorAction;
}

function GetChildrenSpecRows (specNo, controlID, childRowCount, cellCount, columnCount, tabIndex, rowIndex, bShowPlusGrade)
{
    // Ajax to get the children rows, using synchronous calls to remove a bug if the user clicks too quickly several times on the row
    $.ajax({
        type: 'GET',
        url: '/pop/Services/ChildrenSpecDetail.aspx',
        data: 's=' + specNo + '&mn=getchildrenspecs&noheader=1&cc=' + cellCount + '&clmc=' + columnCount + '&t=' + tabIndex + '&ri=' + rowIndex + '&spg=' + bShowPlusGrade,
        dataType: 'text',
        cache: false,
        async: false,
        success: function(childrenRows) {
            // Strip out the table tags of the returning data
            var childrenRows = childrenRows.replace('<table id=\"tblChildrenRows\" border=\"0\">', '').replace('</table>', '');
            
            // Add the table rows after the parent spec record
            $('#' + controlID).after(childrenRows);
        },
        error: function(xhr, msg, e) {
            SetCursorAction ('cursor');
        }                
    });
}



