//
// RCS $Id: utility.js,v 1.2 2010/05/03 16:41:33 goodkar6 Exp $
//

// Validate that at least one photo is selected prior to submitting the form
function arePhotosSelected()
{
    var inputs = document.getElementsByTagName('input');
    for (var i=0; i < inputs.length; i++)
    {
        if ((inputs[i].type == 'checkbox') && (inputs[i].checked == true))
            return true;
    }

    alert('Please select one or more photos to download.');
    return false;
}

// Change all checkboxes on a form to value (1 = on, 0 = off)
function checkAllBoxes(value)
{
    var inputs = document.getElementsByTagName('input');
    for (var i=0; i < inputs.length; i++)
    {
        if (inputs[i].type == 'checkbox')
            inputs[i].checked = value;
    }
}

// Clear all text fields on page
function clearTextFields()
{
    var inputs = document.getElementsByTagName('input');
    for (var i=0; i < inputs.length; i++)
    {
        if (inputs[i].type == 'text')
            inputs[i].value = "";
    }
}

// Calculate window Dimensions in a way that is accurate in all browsers
function calculateWindowDimensions()
{
    var myHeight = 0; myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
      // Non-IE
      myHeight = window.innerHeight;
      myWidth = window.innerWidth;
    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
      // IE 6+ in 'standards compliant mode'
      myHeight = document.documentElement.clientHeight;
      myWidth = document.documentElement.clientWidth;
    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
      // IE 4 compatible
      myHeight = document.body.clientHeight;
      myWidth = document.body.clientWidth;
    }
    return [myWidth, myHeight];
}

// Calculate window scrolling offsets in a way that is accurate in all browsers
function getScrollXY()
{
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' )
    {
        // Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    }
    else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
    {
        // DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    }
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
    {
        // IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

// Get window visible dimensions
function getViewport()
{
    return [$(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
}
