﻿// JScript File

// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}

function Right(str, n)
/***
IN: str - the string we are RIGHTing
n - the number of characters we want to return

RETVAL: n characters from the right side of the string
***/
{
    if (n <= 0)     // Invalid bound, return blank string
        return "";
    else if (n > String(str).length)   // Invalid bound, return
        return str;                     // entire string
    else { // Valid bound, return appropriate substring
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}

function confirmDelete(obj, msg) {
    jQuery(obj).closest('tr').addClass('hiliteDelete');

    if (confirm(msg)) {
        return true;
    } else {
        jQuery(obj).closest('tr').removeClass('hiliteDelete');
        return false;
    }
}

if (typeof jQuery != 'undefined') {
    jQuery(document).ready(function() {
        jQuery('#jQTabs').tabs();

        jQuery('#jQAccordion').accordion();

        jQuery('input.pcase').blur(function() {
            var sVal = jQuery(this).val();
            var start = sVal.substr(0, 1);
            var rest = sVal.substr(1);
            jQuery(this).val(start.toUpperCase() + rest);
        });

        jQuery('input.datefld').datepicker();

        jQuery('input.csreadonly').focus(function() {
            jQuery(this).blur();
        });

        jQuery('tr.datarow, tr.altdatarow').mouseover(function() {
            jQuery(this).addClass('datarowhilite');
        }).mouseout(function() {
            jQuery(this).removeClass('datarowhilite');
        });


        jQuery('a.button-save, a.button-delete').each(function() {
            if (jQuery(this).parent().get(0).tagName.toUpperCase() != 'P' || jQuery(this).siblings().count > 0) {
                jQuery(this).wrap('<div></div>');
            }
            $(this).parent().css('margin-left', '25%');
            $(this).mouseover(function() {
                jQuery(this).addClass('ui-state-hover');
            }).mouseout(function() {
                jQuery(this).removeClass('ui-state-hover');
            });
        });

        jQuery('a.button-save').each(function() {
            jQuery(this).addClass('ui-state-default').addClass('ui-corner-all').prepend('<span class="ui-icon ui-icon-disk"/>');
        });

        jQuery('a.button-delete').each(function() {
            jQuery(this).addClass('ui-state-error').addClass('ui-corner-all').prepend('<span class="ui-icon ui-icon-closethick"/>');
        });

        jQuery('.msg-warning').each(function() {
            var sMsg = jQuery(this).text();
            jQuery(this).hide();
            jQuery.jGrowl(sMsg, { sticky: true });
        });

        jQuery('.msg-success').each(function() {
            var sMsg = jQuery(this).text();
            jQuery(this).hide();
            jQuery.jGrowl(sMsg);
        });
    });

    jQuery(window).load(function() {
        jQuery('#wait').hide();
    });
}
