﻿// JScript File

// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function (from, to) {
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
};

Date.prototype.toISOString = function () {
    var year = this.getFullYear();
    var month = (this.getMonth() + 1).toString();
    if (month.length == 1) { month = '0' + month.toString(); }
    var day = this.getDate().toString();
    if (day.length == 1) { day = '0' + day.toString(); }
    var hour = this.getHours().toString();
    if (hour.length == 1) { hour = '0' + hour.toString(); }
    var minute = this.getMinutes().toString();
    if (minute.length == 1) { minute = '0' + minute.toString(); }
    var second = this.getSeconds().toString();
    if (second.length == 1) { second = '0' + second.toString(); }

    return year + '-' + month + '-' + day + 'T' + hour + ':' + minute + ':' + second + 'Z';
}

function confirmDelete(obj, msg) {
    jQuery(obj).closest('tr').addClass('hiliteDelete');

    if (confirm(msg)) {
        return true;
    } else {
        jQuery(obj).closest('tr').removeClass('hiliteDelete');
        return false;
    }
}

/* jQuery Cookie */
jQuery.cookie = function (e, b, a) { if (arguments.length > 1 && String(b) !== "[object Object]") { a = jQuery.extend({}, a); if (b === null || b === undefined) a.expires = -1; if (typeof a.expires === "number") { var d = a.expires, c = a.expires = new Date; c.setDate(c.getDate() + d) } b = String(b); return document.cookie = [encodeURIComponent(e), "=", a.raw ? b : encodeURIComponent(b), a.expires ? "; expires=" + a.expires.toUTCString() : "", a.path ? "; path=" + a.path : "", a.domain ? "; domain=" + a.domain : "", a.secure ? "; secure" : ""].join("") } a = b || {}; c = a.raw ? function (f) { return f } : decodeURIComponent; return (d = RegExp("(?:^|; )" + encodeURIComponent(e) + "=([^;]*)").exec(document.cookie)) ? c(d[1]) : null };

/* Pretty Date */
function prettyDate(a) { a = new Date((a || "").replace(/-/g, "/").replace(/[TZ]/g, " ")); a = ((new Date).getTime() - a.getTime()) / 1E3; var b = Math.floor(a / 86400); if (!(isNaN(b) || b < 0 || b >= 31)) return b == 0 && (a < 60 && "just now" || a < 120 && "1 minute ago" || a < 3600 && Math.floor(a / 60) + " minutes ago" || a < 7200 && "1 hour ago" || a < 86400 && Math.floor(a / 3600) + " hours ago") || b == 1 && "Yesterday" || b < 7 && b + " days ago" || b < 31 && Math.ceil(b / 7) + " weeks ago" } if (typeof jQuery != "undefined") jQuery.fn.prettyDate = function () { return this.each(function () { var a = prettyDate(this.title); a && jQuery(this).text(a) }) };

/* Future Date */
function futureDate(b) { var b = new Date((b || "").replace(/-/g, "/").replace(/[TZ]/g, " ")), b = ((new Date).getTime() - b.getTime()) / 1E3, a = Math.floor(b / 86400); if (!isNaN(a) && !(a > 0 || a <= -31)) return a == 0 && "today" || b < 0 && b > -86400 && "today" || a == 1 && "Yesterday" || a == 0 && "today" || a >= -7 && "in " + Math.abs(a) + " day" + (Math.abs(a) == 1 ? "" : "s") || a >= -31 && "in " + Math.abs(Math.ceil(a / 7)) + " week" + (Math.abs(Math.ceil(a / 7)) == 1 ? "" : "s") } if (typeof jQuery != "undefined") jQuery.fn.futureDate = function () { return this.each(function () { var b = futureDate(this.title); b && jQuery(this).text(b) }) };

/* bgiframe 
* Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
* Version 2.1.2
*/
(function (a) { a.fn.bgiframe = (a.browser.msie && /msie 6\.0/i.test(navigator.userAgent) ? function (d) { d = a.extend({ top: "auto", left: "auto", width: "auto", height: "auto", opacity: true, src: "javascript:false;" }, d); var c = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="' + d.src + '"style="display:block;position:absolute;z-index:-1;' + (d.opacity !== false ? "filter:Alpha(Opacity='0');" : "") + "top:" + (d.top == "auto" ? "expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+'px')" : b(d.top)) + ";left:" + (d.left == "auto" ? "expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+'px')" : b(d.left)) + ";width:" + (d.width == "auto" ? "expression(this.parentNode.offsetWidth+'px')" : b(d.width)) + ";height:" + (d.height == "auto" ? "expression(this.parentNode.offsetHeight+'px')" : b(d.height)) + ';"/>'; return this.each(function () { if (a(this).children("iframe.bgiframe").length === 0) { this.insertBefore(document.createElement(c), this.firstChild) } }) } : function () { return this }); a.fn.bgIframe = a.fn.bgiframe; function b(c) { return c && c.constructor === Number ? c + "px" : c } })(jQuery);

if (typeof jQuery != 'undefined') {
    jQuery(document).ready(function ($) {
        jQueryPageInit($);
    });

    jQuery(window).load(function () {
        jQuery('#wait').hide();
    });
}

function jQueryPageInit($) {
    // setup superfish
    $('ul.sf-menu').superfish({ autoArrows: false }).find('ul');  //.bgiframe({ opacity: false });

    $('span.date').prettyDate();
    // update interval every 90 seconds
    setInterval(function () { $("span.date").prettyDate(); }, 90000);

    $('span.fdate').futureDate();
    // update interval every 15 minutes
    setInterval(function () { $('span.fdate').futureDate(); }, 900000);

    $('#jQTabs, div.jQTabs').tabs();

    $('#jQAccordion').accordion({ autoHeight: false });

    $('div.makeInlineDialog').each(function () {
        $(this).addClass('ui-dialog-content ui-widget ui-widget-content ui-corner-bottom');
        var oWrapper = $(this).parent();
        if (!oWrapper.hasClass('ui-inline-dialog')) {
            $(this).wrap('<div />');
            oWrapper = $(this).parent();
            oWrapper.addClass('ui-inline-dialog');
            var oTitle = $('<div />').addClass('ui-dialog-titlebar ui-widget-header ui-corner-top ui-helper-clearfix').append('<span>' + $(this).attr('title') + '</span>').addClass('ui-dialog-title');
            oWrapper.prepend(oTitle);
        }
    });

    $('.makeButtonPane').addClass('ui-dialog-buttonpane ui-widget-content ui-helper-clearfix').css('position', 'relative');
    $('input[type="submit"], input[type="button"], button, a', $('.makeButtonPane')).button().addClass('processed');
    $('a.makeBackButton').button({ icons: { primary: 'ui-icon ui-icon-arrowthick-1-w'} }).addClass('processed');
    $('a.makeWrenchButton').button({ icons: { primary: 'ui-icon ui-icon-wrench'} }).addClass('processed');
    $('a.makeWrenchButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-wrench' }, text: false }).addClass('processed');
    $('a.makeAddButton').button({ icons: { primary: 'ui-icon ui-icon-plusthick'} }).addClass('processed');
    $('a.makeAddButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-plusthick' }, text: false }).addClass('processed');
    $('a.makeEditButton').button({ icons: { primary: 'ui-icon ui-icon-pencil'} }).addClass('processed');
    $('a.makeEditButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-pencil' }, text: false }).addClass('processed');
    $('a.makeNotesButton').button({ icons: { primary: 'ui-icon ui-icon-comment'} }).addClass('processed');
    $('a.makeDocBButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-document-b' }, text: false }).addClass('processed');
    $('a.makeNotesButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-comment' }, text: false }).addClass('processed');
    $('a.makeNextButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-seek-next' }, text: false }).addClass('processed');
    $('a.makeEndButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-seek-end' }, text: false }).addClass('processed');
    $('a.makePrevButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-seek-prev' }, text: false }).addClass('processed');
    $('a.makeFirstButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-seek-first' }, text: false }).addClass('processed');
    $('a.makeDownloadButton').button({ icons: { primary: 'ui-icon ui-icon-circle-arrow-s'} }).addClass('processed');
    $('a.makeDownloadButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-circle-arrow-s' }, text: false }).addClass('processed');
    $('a.makeClockButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-clock' }, text: false }).addClass('processed');
    $('a.makeCommentButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-comment' }, text: false }).addClass('processed');
    $('a.makeDeleteButton').button({ icons: { primary: 'ui-icon ui-icon-trash'} }).addClass('processed').click(function (e) {
        var sConfirm = $(this).attr('confirmmsg');
        var bRet = true;
        if (sConfirm != '' && sConfirm != null) {
            bRet = confirm(sConfirm);
            if (!bRet) e.preventDefault();
        }
        return bRet;
    });
    $('a.makeTinyAddButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-plus' }, text: false }).addClass('processed');
    $('a.makeTinyRemoveButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-minus' }, text: false }).addClass('processed');
    $('a.makeDeleteButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-trash' }, text: false }).addClass('processed').click(function (e) {
        var sConfirm = $(this).attr('confirmmsg');
        var bRet = true;
        if (sConfirm != '' && sConfirm != null) {
            bRet = confirm(sConfirm);
            if (!bRet) e.preventDefault();
        }
        return bRet;
    });
    $('a.makePrintButton').button({ icons: { primary: 'ui-icon ui-icon-print'} }).addClass('processed').click(function (e) {
        e.preventDefault();
        window.print();
    });
    $('a.makePrintButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-print' }, text: false }).addClass('processed').click(function (e) {
        e.preventDefault();
        window.print();
    });
    $('a.makeSaveButton').button({ icons: { primary: 'ui-icon ui-icon-disk'} }).addClass('processed');
    $('a.makeSaveButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-disk' }, text: false }).addClass('processed');
    $('a.makeCancelButton').button({ icons: { primary: 'ui-icon ui-icon-arrowreturnthick-1-w'} }).addClass('processed');
    $('a.makeCancelButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-arrowreturnthick-1-w' }, text: false }).addClass('processed');
    $('a.makeReorderButton').button({ icons: { primary: 'ui-icon ui-icon-arrow-4' }, text: false }).addClass('processed').css('width', '1.2em').css('height', '1.2em').css('cursor', 'move');
    $('a.makeMoveRightButton').button({ icons: { primary: 'ui-icon ui-icon-arrowthick-1-e' }, text: false }).addClass('processed').css('width', '1.2em').css('height', '1.2em');
    $('a.makeMoveLeftButton').button({ icons: { primary: 'ui-icon ui-icon-arrowthick-1-w' }, text: false }).addClass('processed').css('width', '1.2em').css('height', '1.2em');
    $('a.makeExpandButton, .makeNextButton').button({ icons: { primary: 'ui-icon ui-icon-triangle-1-e'} }).addClass('processed');
    $('a.makeCollapseButton').button({ icons: { primary: 'ui-icon ui-icon-triangle-1-s'} }).addClass('processed');
    $('a.makeExpandButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-triangle-1-e' }, text: false }).addClass('processed');
    $('a.makeCollapseButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-triangle-1-s' }, text: false }).addClass('processed');
    //$('a.makePreviousButton').button({ icons: { primary: 'ui-icon ui-icon-triangle-1-w'} }).addClass('processed');
    $('a.makePreviousButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-triangle-1-w' }, text: false }).addClass('processed');
    $('a.makeTinyButton').button().addClass('processed')
    $('a.makeImageButton').button().addClass('processed').css('width', '2.4em').css('height', '2.4em').css('margin-top', '0.1em').find('span.ui-button-text').css('padding', '0.5em');
    $('a.makeOpenLinkButton').button({ icons: { primary: 'ui-icon ui-icon-extlink'} }).addClass('processed');
    $('a.makeOpenLinkButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-extlink' }, text: false }).addClass('processed');
    $('a.makeResetButton').button({ icons: { primary: 'ui-icon ui-icon-arrowrefresh-1-s'} }).addClass('processed');
    $('a.makeResetButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-arrowrefresh-1-s' }, text: false }).addClass('processed');
    $('a.makeFavoriteButton').button({ icons: { primary: 'ui-icon ui-icon-star'} }).addClass('processed');
    $('a.makeFavoriteButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-star' }, text: false }).addClass('processed');
    $('a.makePreviewButton').button({ icons: { primary: 'ui-icon ui-icon-zoomin'} }).addClass('processed');
    $('a.makePreviewButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-zoomin' }, text: false }).addClass('processed');
    $('a.makePublishButton').button({ icons: { primary: 'ui-icon ui-icon-signal-diag'} }).addClass('processed');
    $('a.makeCheckButton').button({ icons: { primary: 'ui-icon ui-icon-check'} }).addClass('processed');
    $('a.makeCheckButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-check' }, text: false }).addClass('processed');
    $('a.makeGearButton').button({ icons: { primary: 'ui-icon ui-icon-gear'} }).addClass('processed');
    $('a.makeGearButtonIcon').button({ icons: { primary: 'ui-icon ui-icon-gear' }, text: false }).addClass('processed');
    $('a.emailLink, a.makeEmailButton').button({ icons: { primary: 'ui-icon ui-icon-mail-closed'} });
    $('.makeButton:not(.processed), .jqButton:not(.processed), .jQButton:not(.processed)').button();
    $('div.ui-invertednavtabs ul.ui-tabs-nav li').each(function () {
        $(this).addClass('ui-corner-bottom ui-state-default').hover(function () { $(this).addClass('ui-state-hover'); }, function () { $(this).removeClass('ui-state-hover'); });
    });
    $('a.btnprocessed.disabled').addClass('ui-state-disabled');
    $('a.processed').each(function () {
        var b = this;
        if (b && typeof (b.click) == 'undefined') {
            b.click = function () {
                var result = true;
                if (b.onclick) result = b.onclick();
                if (typeof (result) == 'undefined' || result) {
                    eval(b.getAttribute('href'));
                }
            }
        }
    });

    $('img.hoverChange').each(function () {
        $(this).attr('orig', $(this).attr('src'));
        var oImg = new Image();
        oImg.src = $(this).attr('rel');
    });

    $('img.hoverChange').hover(function () {
        var sChange = $(this).attr('rel');
        if (sChange != '') {
            $(this).attr('src', sChange);
        }
    }, function () {
        var sChange = $(this).attr('orig');
        if (sChange != '') {
            $(this).attr('src', sChange);
        }
    });

    $('ul li:first-child').addClass('firstChild');
    $('ul li:last-child').addClass('lastChild');

    $('input:text, input:password, textarea').focus(function () {
        $(this).addClass('focused');
    }).blur(function () {
        $(this).removeClass('focused');
    });

    $('div.validationsumm').addClass('ui-state-error ui-corner-all').css('padding', '1em').css('margin', '1em');

    $('span.validationerror').each(function () {
        $(this).html('<img src="/images/spacer.gif" height="16" width="16" title="' + $(this).attr('errormessage') + '" />');
    });

    $('span.validationerror.showOnload').each(function () {
        $(this).css('visibility', 'visible')
    });

    $('span.validationerrlong').each(function () {
        $(this).html('<img src="/images/spacer.gif" height="16" width="16" title="' + $(this).attr('errormessage') + '" /> <b>' + $(this).attr('errormessage') + '</b>');
    });

    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');
    });

    $(".tabs-bottom .ui-tabs-nav, .tabs-bottom .ui-tabs-nav > *")
			.removeClass("ui-corner-all ui-corner-top")
			.addClass("ui-corner-bottom");
}

function ResponseStatusMessage(data, defaultMsg) {
    var aData = data.split('|');
    var bRet = aData[0];
    var sMsg = aData[1];
    if (sMsg == '') { sMsg = defaultMsg; }
    var oStatus = jQuery('#ResponseStatusMessage');
    jQuery('span.msg', oStatus).html(sMsg);
    if (bRet != 'true') {
        jQuery('span.ui-icon', oStatus).removeClass('ui-icon-info').addClass('ui-icon-alert');
        oStatus.removeClass('ui-state-highlight').addClass('ui-state-error').show().click(function () { jQuery(this).fadeOut('slow') });
    } else {
        jQuery('span.ui-icon', oStatus).removeClass('ui-icon-alert').addClass('ui-icon-info');
        oStatus.removeClass('ui-state-error').addClass('ui-state-highlight').show().fadeOut(5000);
    }
}

(function ($) {
    // plugin definition
    $.fn.pageTabs = function (options) {
        var selector = $(this).selector;
        var opts = $.extend({}, $.fn.pageTabs.defaults, options);

        return this.each(function () {
            var $this = $(this);
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
            $(this).addClass('ui-tabs ui-widget ui-widget-content ui-corner-all');
            $('ul:first', $(this)).addClass('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all');
            $('ul:first>li', $(this)).addClass('ui-state-default ui-corner-top').hover(function () {
                if (!$(this).hasClass('ui-tabs-selected')) { $(this).addClass('ui-state-hover'); }
            }, function () {
                $(this).removeClass('ui-state-hover');
            });
            $('div:first', $(this)).addClass('ui-tabs-panel ui-widget-content ui-corner-bottom');
            if (o.selected >= 0) {
                $('ul:first>li:eq(' + o.selected + ')', $(this)).addClass('ui-tabs-selected ui-state-active');
            }
        });
    };

    // plugin defaults - added as a property on our plugin function
    $.fn.pageTabs.defaults = {
        selected: 0
    };

})(jQuery);

