
//resizes the given child element to the bounds of the given parent element
function resizeToParent(parent, child, minBounds) {
    var parentBounds = Sys.UI.DomElement.getBounds(parent);
    Sys.UI.DomElement.setLocation(child, parentBounds.x, parentBounds.y);
    var width = parentBounds.width;
    var height = parentBounds.height;
    if (minBounds) {
        if (!isNaN(minBounds.width) &&
            minBounds.width > width) {
            width = minBounds.width;
        }
        if (!isNaN(minBounds.height) &&
            minBounds.height > height) {
            height = minBounds.height;
        }
    }
    child.style.width = width + 'px';
    child.style.height = height + 'px';
}

function yearPickerChangeYear(button, increase) {
    //cancel if already in postback
    if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
        return false;
    }
    //find dropdown
    var found = $(button).parent().parent().find('select');
    if (found && found.length > 0) {
        var ddl = found[0];
        //clear timeout if any
        window.clearTimeout(ddl.timerCookie);
        if (!increase &&
            ddl.selectedIndex < ddl.options.length - 1) {
            ddl.selectedIndex = ddl.selectedIndex + 1;                
        }
        if (increase &&
            ddl.selectedIndex > 0) {
            ddl.selectedIndex = ddl.selectedIndex - 1;
        }
        //set change after 500ms - this will allow user click more times
        ddl.timerCookie = window.setTimeout(function() { ddl.onchange(); }, 500);
    }
    return false;
}

function cancelEvent(evt) {
    var objEvent = new Sys.UI.DomEvent(evt);
    if (typeof (objEvent.cancelBubble) != "undefined") { objEvent.cancelBubble = true; }
    objEvent.stopPropagation();
    objEvent.preventDefault();
}

function createComparer(propertyName) {
    return function(a, b) {
        if (a[propertyName] > b[propertyName]) {
            return 1;
        }
        else if (a[propertyName] == b[propertyName]) {
            return 0;
        }
        else {
            return -1;
        }
    }
}