function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
function ClientProxyDateFormatted(methodName, paramArray, successFunction, errorFunction) {
    var pagePath = window.location.pathname;
    var paramList = '';

    if (paramArray.length > 1) {
        for (var i = 0; i < paramArray.length; i += 2) {
            if (paramList.length > 0) paramList += ',';

            paramList += '"' + paramArray[i] + '"' + ':' + '"' + convertQuotes(paramArray[i + 1].toString()) + '"';
        }
    }
    paramList = '{' + paramList + '}';
    var length = pagePath.length;
    if (pagePath.substring(length - 1, length) == "/")
        pagePath += "Default.aspx";
    else if (pagePath.substring(length - 5, length) != ".aspx")
        pagePath += "/Default.aspx";

    $.ajax({
        type: "POST",
        url: pagePath + "/" + methodName,
        contentType: "application/json; charset=utf-8",
        data: paramList,
        dataType: "text",
        processData: false,
        success: function(msgg) {
            var msg = JSON.parse(msgg, function(key, value) {
                var a;
                if (value != null) {
                    if (value.toString().indexOf('Date') >= 0) {
                        a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
                        if (a) {
                            var dt = new Date(parseInt(a[1], 10));
                            return (dt.getMonth()) + "/" + dt.getDate() + "/" + dt.getFullYear();
                        }
                    }
                    return value;
                }
            });
            successFunction(msg);
        },
        error: function() {
            errorFunction();
        }
    });
    return false;
}

function ClientProxy(methodName, paramArray, successFunction, errorFunction) {
    var pagePath = window.location.pathname;
    var paramList = '';

    if (paramArray.length > 1) {
        for (var i = 0; i < paramArray.length; i += 2) {
            if (paramList.length > 0) paramList += ',';
            paramList += '"' + paramArray[i] + '"' + ':' + '"' + convertQuotes(paramArray[i + 1].toString()) + '"';
        }
    }
    paramList = '{' + paramList + '}';
    var length = pagePath.length;
    if (pagePath.substring(length - 1, length) == "/")
        pagePath += "Default.aspx";
    else if (pagePath.substring(length - 5, length) != ".aspx")
        pagePath += "/Default.aspx";

    $.ajax({
        type: "POST",
        url: pagePath + "/" + methodName,
        contentType: "application/json; charset=utf-8",
        data: paramList,
        dataType: "json",
        success: function(msg) {
            successFunction(msg);
        },
        error: function() {
            errorFunction();
        }
    });
    return false;
}

function ClientProxyWithObjectParam(methodName, paramObj, successFunction, errorFunction) {
    var pagePath = window.location.pathname;
    var length = pagePath.length;
    if (pagePath.substring(length - 1, length) == "/") {
        pagePath += "Default.aspx";
    }
    else if (pagePath.substring(length - 5, length) != ".aspx") {
        pagePath += "/Default.aspx";
    }

    $.ajax({
        type: "POST",
        url: pagePath + "/" + methodName,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(paramObj),
        dataType: "json",
        success: function(msg) {
            successFunction(msg);
        },
        error: function(xhr, status, error) {
            errorFunction(xhr, status, error);
        }

    });
    return false;
}
function isValidEmail(email) {
    var expr = /^[A-Za-z0-9]([A-Za-z0-9_-]|(\.[A-Za-z0-9]))+@[A-Za-z0-9](([A-Za-z0-9]|(-[A-Za-z0-9]))+)\.([A-Za-z]{2,6})(\.([A-Za-z]{2}))?$/;
    if (email.match(expr)) { return true; }
    else { return false; }
}

function convertQuotes(doubleQuoteString) {
    return doubleQuoteString.replace(/"/g, "'");
}

function ToggleCheckBoxValue(objID, checkedValue) {
    if (objID == null || objID == undefined)
        return;
    var checked_status = checkedValue;
    $(objID + " input[type=checkbox]").each(function() {
        this.checked = checked_status;
    });
}

function DeSelectAllCheckBox(allCheckBox, checkedValue, obj) {
    if (allCheckBox == null || allCheckBox == undefined)
        return;
    if (!checkedValue)
        $(allCheckBox).attr("checked", false);
    else {
        var areAllChecked = true;
        $(obj + " input[type=checkbox]").each(function() {
            if (!this.checked) {
                areAllChecked = false;
            }
        });
        $(allCheckBox).attr("checked", areAllChecked);
    }
}

function EncodeHTML(id) {
    $(id).val(ReturnEncodedHTML($(id).val()));
    return true;
}

function parseDate(str) {
    var mdy = str.split('/');
    return new Date(mdy[2], mdy[1] - 1, mdy[0]);
}
function DateAdd(dte, numDays) {
    return new Date(parseInt(dte.getTime() + ((numDays-1) * (1000 * 60 * 60 * 24))));
}
function GetDaysBetweenDates(date1, date2) {
    return parseInt((date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24));
}

var regExpForHTMLTags = new RegExp("<html>|</html>|<head>|</head>|<body>|</body>", "i");
function IsHTMLTagsExist(text) {
    return regExpForHTMLTags.test(text.replace(/ /g, ""));
}
function ReturnEncodedHTML(text) {
    var encodedText = text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    return encodedText;
}

// colouring alternate table strips  
function ColorAltRecords(collection, class1, class2) {
    $('.' + collection + ':odd').removeClass(class1).addClass(class2);
}

// pagination
function Pagination(totalRecords, pageSize, pgCont, action) {
    // checking total no of pages and the current page number
    totalPages = Math.ceil(totalRecords / pageSize);
    if (totalPages > 1) {
        if (isNaN(currPage) || currPage < 0 || currPage == null)
            currPage = parseInt($('.activePgNo').text());

        // setting the lower limit and the upper limit of the set of page numbers to be displayed at a time        
        if (pgCont == false) {
            lowerPgLimit = 1;
            upperPgLimit = (totalPages > defaultNoOfPages) ? defaultNoOfPages : totalPages;
        }
        else {
            if (action == "previous")
                pagesOnLeft = 4;
            else
                pagesOnLeft = 2;

            lowerPgLimit = currPage - pagesOnLeft;
            remainingPages = totalPages - currPage;

            if (lowerPgLimit <= 1) {
                lowerPgLimit = 1;
                //upperPgLimit = defaultNoOfPages;
                upperPgLimit = (remainingPages > defaultNoOfPages) ? lowerPgLimit + defaultNoOfPages - 1 : currPage + remainingPages;
            }
            else
                upperPgLimit = (remainingPages > defaultNoOfPages) ? lowerPgLimit + defaultNoOfPages - 1 : currPage + remainingPages;
        }

        // removing the existing set of page numbers
        $('.pgNo').remove();

        // creating a new set of page numbers depending on the lower page limit and upper page limit
        for (var i = lowerPgLimit; i <= upperPgLimit; i++) {
            var pgNo = "<a class='pgNo'>" + i + "</a>";
            $('#next').before(pgNo);
        }

        // Highlighting the active page number
        if (pgCont == false)
            $(".pagination a:contains(" + (isNaN(currPage) ? 1 : currPage) + ")").addClass('activePgNo');
        //$('.pgNo').eq(0).addClass('activePgNo');
        else if (action == "next") {
            $(".pagination a:contains(" + currPage + ")").addClass('activePgNo');
        }
        else if (action == "previous") {
            $(".pagination a:contains(" + currPage + ")").addClass('activePgNo');
        }
    }
    // disabling prev,next buttons
    DisableButtons();
}

function DisableButtons() {
    if ($('.activePgNo').text() == "1") {
        $('#prev').css({ 'color': 'gray' }).attr('disabled', true);
    }
    else {
        $('#prev').css({ 'color': 'black' }).removeAttr('disabled');
    }

    if ($('.activePgNo').text() == totalPages) {
        $('#next').css({ 'color': 'gray' }).attr('disabled', true);
    }
    else {
        $('#next').css({ 'color': 'black' }).removeAttr('disabled');
    }

    if (totalPages == 1 || totalPages == 0) {
        $('.pagination').hide();
        $('.limit_results').hide();
    }
    else {
        $('.pagination').show();
        $('.limit_results').show();
    }

    $('.pgNo, #ddLimits').removeAttr("disabled").removeAttr("style");
    $('.activePgNo').attr("disabled", true);

}
function DisablePagingControls() {
    $(".pgNo, #ddLimits, #prev, #next").attr("disabled", "disabled").css({ "color": "gray" });
}

// toggle row expansion
function toggleRowExpansion(currentRow, container) {
    var currentSet = $(currentRow).next();
    var statusCurrentDetails;
    if ($(currentSet).hasClass('collapsed') == true) {
        statusCurrentDetails = "collapsed";
    }
    else if ($(currentSet).hasClass('expanded') == false) {
        statusCurrentDetails = "expanded";
    }
    $('.expanded').removeClass('expanded').addClass('collapsed');
    $('.ui-icon', $(currentRow)).removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
    if (statusCurrentDetails == "collapsed") {
        $(currentSet).removeClass('collapsed').addClass('expanded');
        $('.ui-icon', $(container)).removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
        $('.ui-icon', $(currentRow)).removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s');
    }
}

// Search Feature
function Search(e) {
    // track last key pressed
    lastKeyPressCode = e.keyCode;
    switch (e.keyCode) {
        case 38: // up
            e.preventDefault();
            moveSelect(-1);
            break;
        case 40: // down
            e.preventDefault();
            moveSelect(1);
            break;
        case 9:  // tab
        case 13: // return
            return false;
            break;
        default:
            active = -1;
            if (timeout) clearTimeout(timeout);
            timeout = setTimeout(function() { onChange(); }, delay);
            break;
    }
}

function onChange() {
    if (lastKeyPressCode > 8 && lastKeyPressCode < 32)
        return;
    //Reset the paging variables when no results found.    
    rePaging = true;
    currPage = 1;
    PopulationFn();
}

//Sorting Function
function Sort(evt, container) {
    flag = true;     
    target = $(evt.target); target.parent().children().eq(0).removeAttr("style");
    if (target.is('.sortTable') || target.is('.sortNone') || target.is('.sortAscending')
        || target.is('.sortDescending') || target.is('.sortTitle')) {

        if (target.is('.sortTable')) {
            sortColumnName = target.children('.sortColumnName').text();
            if (target.children('.sortNone').length > 0) {
                sortDirection = 1;
                target.children('.sortNone').removeClass('sortNone').addClass('sortAscending');
                PopulationFn();
            }
            else
                if (target.children('.sortAscending').length > 0) {
                sortDirection = 2;
                target.children('.sortAscending').removeClass('sortAscending').addClass('sortDescending');
                PopulationFn();
            }
            else
                if (target.children('.sortDescending').length > 0) {
                sortDirection = 1;
                target.children('.sortDescending').removeClass('sortDescending').addClass('sortAscending');
                PopulationFn();
            }
        }
        else {
            sortColumnName = target.siblings('.sortColumnName').text();
            if (target.siblings('.sortNone').length > 0) {
                sortDirection = 1;
                target.siblings('.sortNone').removeClass('sortNone').addClass('sortAscending');
                PopulationFn();
            }
            else
                if (target.siblings('.sortAscending').length > 0) {
                sortDirection = 2;
                target.siblings('.sortAscending').removeClass('sortAscending').addClass('sortDescending');
                PopulationFn();
            }
            else
                if (target.siblings('.sortDescending').length > 0) {
                sortDirection = 1;
                target.siblings('.sortDescending').removeClass('sortDescending').addClass('sortAscending');
                PopulationFn();
            }
            else
                if (target.is('.sortNone')) {
                sortDirection = 1;
                target.removeClass('sortNone').addClass('sortAscending');
                PopulationFn();
            }
            else
                if (target.is('.sortAscending')) {
                sortDirection = 2;
                target.removeClass('sortAscending').addClass('sortDescending');
                PopulationFn();
            }
            else
                if (target.is('.sortDescending')) {
                sortDirection = 1;
                target.removeClass('sortDescending').addClass('sortAscending');
                PopulationFn();
            }
        }
    }    
}

//calling the appropriate population function
function PopulationFn() {
    LoadData();    
}

function GetIndex(a, e) {
    for (j = 0; j < a.length; j++) if (a[j] == e) return j;
    return null;
}

function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}
function ReplaceNullWithEmptyString(str) {
    if (str == '' || str == ' ' || str == undefined || str == null)
        return strNoData;
    if (str == 0)
        return str;
    return str;
}

//Function to check that whether an element exists in an array or not
Array.prototype.ContainsValue = function(value) {
    var arrayLength = this.length;
    for (var i = 0; i < arrayLength; i++) {
        if (this[i] === value)
            return true;
    }
    return false;
}

function NoResultsFound(container) {
    InitializeGridVariables();
    var noSearchResults = "<label class='validationMessage'>No results found</label>";
    $("#" + container).html(noSearchResults);
    $(".resultscampaign").hide();
    //    $(".limit_results").hide();
    //    $(".pagination").hide();
}
//-------------------------------------------------Global variables--------------------------//
var defaultNoOfPages = 7;
var lowerPgLimit = 1;
var upperPgLimit = 1;
var pagesOnLeft = 2;
var totalPages = 0;
var currPgNo = null;
var remainingPages = 0;
var strNoData = '--';
var ioStatusID = 1;
var defaultPageSize = 0;
var pageSize = 0;
var totalRecords = 0;
var rePaging = true;
var pgCont = false;
var timeout = null;
var delay = 1000;
var searchKey = "";
var isUserChangedata = false;
$(document).ready(function() {
    //Common logic function to Paging, Sorting and Search
    // Changing the no of records to be shown
    //#region 
    var pagingDropDown = $('#ddLimits');
    if (pagingDropDown != null) {
        defaultPageSize = $(pagingDropDown).val();
        pageSize = defaultPageSize;
        if (pageSize == null) {
            pageSize = defaultPageSize = 0;
        }
    }
    //pageSize = 2; // commented for testing
    window.onbeforeunload = function() {
        if (isUserChangedata)
            return "You have unsaved changes in the document. Click Cancel now, then 'Save' to save them. Click OK now to discard them.";
    }

    $('#ddLimits').change(function() {
        var limit = $('#ddLimits  option:selected').val();
        var newPageSize = parseInt(limit);
        rePaging = true;
        pgCont = true;
        currPage = parseInt($('.activePgNo').text());
        if (currPage == 1)
            ;
        else {
            currPage = Math.ceil(((currPage) * pageSize) / newPageSize);
            if (currPage > (totalRecords / newPageSize))
                currPage = Math.ceil(totalRecords / newPageSize);
        }

        pageSize = newPageSize;
        LoadData();
        DisablePagingControls();
    });

    // Click action of subNav Approv, Reject, Pending and All.
    $('#tabnav li').click(function() {
        $('#tabnav .selected').removeClass('selected');
        $(this).addClass('selected');
        var subnavName = $('a', $(this)).attr("id");
        LoadSubNav(subnavName);
    });
    $('#subnav li').click(function() {
        $('#subnav .selected').removeClass('selected');
        $(this).addClass('selected');
        var subnavName = $('a', $(this)).attr("id");
        LoadSubNav(subnavName);
        rePaging = true;
        pgCont = false;
        LoadData();
    });

    // Click action of page numbers 
    $('.pgNo').live("click", function() {
        if (!$(this).attr("disabled")) {
            currPage = parseInt($(this).text());
            $('.pgNo').removeClass('activePgNo');
            $(this).addClass('activePgNo');
            rePaging = false;
            pgCont = false;
            LoadData();
            DisableButtons();
            DisablePagingControls();
        }
    });

    // Click action for next
    $('#next').click(function() {
        if (!$(this).attr("disabled")) {
            currPage++;
            var currentPageLink = $('.activePgNo');
            var nextPageLink = $(currentPageLink).next();

            if ($(nextPageLink).text() == "Next >") {
                if (totalPages == $(currentPageLink).text())
                    return;
                rePaging = true;
                pgCont = true;
            }
            else {
                $('.pgNo').removeClass('activePgNo');
                $(currentPageLink).next().addClass('activePgNo');
                rePaging = false;
                pgCont = false;
                DisableButtons();
            }
            action = "next";
            LoadData();
            DisablePagingControls();
        }
    });

    // Click action for previous
    $('#prev').click(function() {
        if (!$(this).attr("disabled")) {
            var currentPageLink = $('.activePgNo');
            var prevPageLink = $(currentPageLink).prev();

            if ($(currentPageLink).text() == "1")
                return;

            currPage--;
            if ($(prevPageLink).text() == "< Previous") {
                rePaging = true;
                pgCont = true;
            }
            else {
                $('.pgNo').removeClass('activePgNo');
                $(currentPageLink).prev().addClass('activePgNo');
                rePaging = false;
                pgCont = false;
                DisableButtons();
            }
            action = "previous";
            LoadData();
            DisablePagingControls();
        }
    });
    $('.lnkTerms').live('click', function() {
        OpenPopupWin('/Downloads/Brandscreen_Digital_Media_Trading_Platform_Demand_Side_Trading_Agreement_downloadable_1_0.pdf');
    });
    $('.lnkContactUs').click(function() {
        OpenPopupWin('/ContactUs.aspx');
    });
    $('.lnkBillingTab').live('click', function() {
		OpenPopupWin('Account.aspx?tab=tabBilling');
    });
});

function IsCreativeFormValid() {
    var isValid = false;
    var regExpForURL = new RegExp("(ftp|http|https)://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$", "i");
    if ($currentCreativeRow != null) {
        var source = $currentCreativeRow.find('.creativeSource').val(); // -1 1 2 3 4
        isValid = true;

        switch (source) {
            case "-1":
                if(creativeFileID <= 0) {
                    $currentCreativeRow.find(".msgSource").html("required").show().css({ "color": "red" });
                    isValid = false;
                }
                break;
            case "1":
                if ($currentIFrame.contents().find("body #hiddenCreativeFileID").val() == "") {
                    $currentCreativeRow.find(".msgSource").html("required").show().css({ "color": "red" });
                    isValid = false;
                }
                break;
            case "2":
                if ($.trim($currentCreativeRow.find('.txtUrl').val()) == '') {
                    $currentCreativeRow.find(".msgSource").html("required").show().css({ "color": "red" });
                    isValid = false;
                }
                break;
            case "3":
                if ($.trim($currentCreativeRow.find('.txtAdTag').val()) == '') {
                    $currentCreativeRow.find(".msgSource").html("required").show().css({ "color": "red" });
                    isValid = false;
                }
                else if (IsHTMLTagsExist($currentCreativeRow.find('.txtAdTag').val())) {
                    $currentCreativeRow.find(".msgSource").text("<html>, <head> and <body> tags are not allowed.").show().css({ "color": "red" });
                    isValid = false;
                }
                break;
            case "4":
                if (creativeFileID <= 0) {
                    $currentCreativeRow.find(".msgSource").html("required").show().css({ "color": "red" });
                    isValid = false;
                }
                break;
        }

        if (isValid == false)
            return false;

        if ($currentCreativeRow.find('.altText').val() != '')
        { isValid = isValid & true; $currentCreativeRow.find(".msgAlt").hide().removeAttr('style'); }
        else { isValid = false; $currentCreativeRow.find(".msgAlt").show().css({ "color": "red" }); }
        var clickThroughURL = $.trim($currentCreativeRow.find('.clickThrough').val());
        if (clickThroughURL != '') {
            if (clickThroughURL.substring(7, 0) != 'http://' && clickThroughURL.substring(7, 0) != 'https://') {
                clickThroughURL = 'http://' + clickThroughURL;
                $currentCreativeRow.find('.clickThrough').val(clickThroughURL);
            }
            if (!regExpForURL.test(clickThroughURL)) {
                isValid = false; $currentCreativeRow.find(".msgClickThrough").html("enter valid URL").show().css({ "color": "red" });
            }
            else {
                isValid = isValid & true; $currentCreativeRow.find(".msgClickThrough").hide().removeAttr('style');
            }
        }
        else { isValid = false; $currentCreativeRow.find(".msgClickThrough").html("required").show().css({ "color": "red" }); }
        if ($currentCreativeRow.find('.popup:checked').length > 0) {
            isValid = isValid & true;
            $currentCreativeRow.find(".msgPopup").hide().removeAttr('style');
        }
        else { isValid = false; $currentCreativeRow.find(".msgPopup").show().css({ "color": "red" }); }
        if ($currentCreativeRow.find('.other:checked').length > 0) {
            isValid = isValid & true;
            $currentCreativeRow.find(".msgOther").hide().removeAttr('style');
        }
        else { isValid = false; $currentCreativeRow.find(".msgOther").show().css({ "color": "red" }); }
        if ($currentCreativeRow.find('.promotional:checked').length > 0) {
            isValid = isValid & true;
            $currentCreativeRow.find(".msgPromotional").hide().removeAttr('style');
        }
        else { isValid = false; $currentCreativeRow.find(".msgPromotional").show().css({ "color": "red" }); }
        if ($currentCreativeRow.find('.language:checked').length > 0) {
            isValid = isValid & true;
            $currentCreativeRow.find(".msgLanguage").hide().removeAttr('style');
        }
        else { isValid = false; $currentCreativeRow.find(".msgLanguage").show().css({ "color": "red" }); }
    }
    return isValid;
}

//Readin QueryString
function QueryString() {
    // PROPERTIES
    this.arg = new Array;
    this.status = false;

    // METHODS
    this.clear = Clear;
    this.get = Get;
    this.getAll = GetAll;
    this.getStatus = GetStatus;
    this.read = Read;
    this.set = Set;
    this.write = Write;

    // FUNCTIONS

    // Clears the array, this.arg, of all query string data
    function Clear() {
        this.arg = new Array;
    }

    // Returns a named value from the query string
    function Get(sName) {
        return this.arg[sName];
    }

    // Return all data as an associative array
    function GetAll() {
        return this.arg;
    }

    function GetStatus() {
        return this.status;
    }

    // Reads the query string into an array named this.arg
    function Read(sUrl) {
        var aArgsTemp, aTemp, sQuery;
        // You can pass in a URL query string
        if (sUrl) {
            sQuery = sUrl.substr(sUrl.lastIndexOf("?") + 1, sUrl.length);
        }
        // Or read it from the browser location
        else {
            sQuery = window.location.search.substr(1, window.location.search.length);
        }
        // Check that query string exists and contains data
        // If not (length < 1) then return
        if (sQuery.length < 1) { return; }
        // Else set this.status to true and proceed
        else { this.status = true; }
        //
        aArgsTemp = sQuery.split("&");
        for (var i = 0; i < aArgsTemp.length; i++) {
            aTemp = aArgsTemp[i].split("=");
            this.arg[aTemp[0]] = aTemp[1];
        }
    }

    // Overwrites an existing named value in the array, this.arg
    // You can also pass null to delete from array
    function Set(sName, sValue) {
        if (sValue == null) { delete this.arg[sName]; }
        else { this.arg[sName] = sValue; }
    }

    // Writes out a string from the data in this.arg array
    // This string can be used to pass a new query string to the browser
    // when navigating to the next page. This allows a page
    // to create and pass data to another page via JavaScript.
    function Write() {
        var sQuery = new String("");
        for (var sName in this.arg) {
            if (sQuery != "") { sQuery += "&"; }
            if (this.arg[sName]) { sQuery += sName + "=" + this.arg[sName]; }
        }
        if (sQuery.length > 0) { return "?" + sQuery; }
        else { return sQuery; }
    }
}


$(function() {

    $(".accordion.left").accordion({ autoHeight: false });
    $(".accordion.right").accordion({ autoHeight: false, active: false });
    $(".datepickerstart").datepicker({ showOn: 'both', buttonImage: 'res/images/calendar.png', buttonImageOnly: true,
         dateFormat: 'dd/mm/yy',minDate: 3, onSelect:function(){GetDuration();}
    });
    $(".datepickerend").datepicker({ showOn: 'both', buttonImage: 'res/images/calendar.png', buttonImageOnly: true,
        dateFormat: 'dd/mm/yy', minDate: 4, onSelect:function(){GetDuration();}
    });
    $(".reset").click(function() { $(this).prev().attr("value", ""); });

    $(".toggle_switch").click(function() {
        $(this).find(".ui-icon-triangle-1-e, .ui-icon-triangle-1-s").toggleClass("ui-icon-triangle-1-e").toggleClass("ui-icon-triangle-1-s");
        $(this).next(".toggle").toggle();
    })

    $(".toggle_media_layer").click(function() {
        $(this).find(".ui-icon-triangle-1-e, .ui-icon-triangle-1-s").toggleClass("ui-icon-triangle-1-e").toggleClass("ui-icon-triangle-1-s");
        $(this).parent().next(".media_layer").toggle();
    })

    $(".toggle_barlist_openhide").click(function() {
        $(this).find(".ui-icon-triangle-1-e, .ui-icon-triangle-1-s").toggleClass("ui-icon-triangle-1-e").toggleClass("ui-icon-triangle-1-s");
        $(this).parent().next(".toggle_bar").toggle();
    })

    $(".dialog_editimpressions").click(function() { $("#editimpressions").dialog({ modal: true }); return false; });
    $("#overlay .inner").css("opacity", 0.8);
    $("button.save").click(function() { $("#overlay").show(); return false; });
    $(".creative .advert_popup_button").hover(function() {
        $(this).find(".advert_popup").show();
    }, function() {
        $(this).find(".advert_popup").hide();
    });

    var dialogs = [
    { name: "check_email", height: 240 },
    { name: "signup_complete", height: 240 },
    { name: "adserver_credentials", height: 370 }
  ];
    jQuery.each(dialogs, function(i, dialog) {
        $("#" + dialog.name + "_button").click(function() {
            $("#" + dialog.name).dialog({ modal: true, resizable: false, draggable: false, width: 515, height: dialog.height });
            return false;
        });
    });
});


function FormatCurrency(num) {
    var isPositive = num >= 0; num = Math.floor(num * 100); var cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10) {
        cents = "0" + cents.toString();
    } else { cents = cents.toString(); }
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
        num = num.substring(0, num.length - (4 * i + 3)) + "," + num.substring(num.length - (4 * i + 3));
    } num = num + "." + cents; return isPositive ? num : "($" + num + ")";
}

function FormatInt(num) {
    var isPositive = num >= 0; num = Math.floor(num * 100); var cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10) {
        cents = "0" + cents.toString();
    } else { cents = cents.toString(); }
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
        num = num.substring(0, num.length - (4 * i + 3)) + "," + num.substring(num.length - (4 * i + 3));
    } return isPositive ? num : "(" + num + ")";
}

(function($) {
    $.fn.ellipsis = function(enableUpdating) {
        var s = document.documentElement.style;
        if (!('textOverflow' in s || 'OTextOverflow' in s)) {
            return this.each(function() {
                var el = $(this);
                if (el.css("overflow") == "hidden") {
                    var originalText = el.html();
                    var w = el.width();

                    var t = $(this.cloneNode(true)).hide().css({
                        'position': 'absolute',
                        'width': 'auto',
                        'overflow': 'visible',
                        'max-width': 'inherit'
                    });
                    el.after(t);

                    var text = originalText;
                    while (text.length > 0 && t.width() > el.width()) {
                        text = text.substr(0, text.length - 1);
                        t.html(text + "...");
                    }
                    el.html(t.html());

                    t.remove();

                    if (enableUpdating == true) {
                        var oldW = el.width();
                        setInterval(function() {
                            if (el.width() != oldW) {
                                oldW = el.width();
                                el.html(originalText);
                                el.ellipsis();
                            }
                        }, 200);
                    }
                }
            });
        } else return this;
    };
})(jQuery);

function isNumeric(value) {
    if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
    return true;
}

//Created by: Kelvin P. Penus
//jQuery library for allowing only numeric input. Comma and decimal period is allowed.
(function($) {
    $.fn.numericOnly = function() {

        return this.each(function() {
            var $this = jQuery(this);

            $this.keydown(function(e) {
                if (e.which != 8 && e.which != 0 && e.which != 188 && e.which != 190 && e.which != 9 && e.which != 16 && e.which != 13 && e.which != 46 && e.which != 110 && (e.which < 35 || e.which > 40) && (e.which < 96 || e.which > 105) && (e.which < 48 || e.which > 57)) {
                    return false;
                }

            });
            $this.change(function(e) {
                if ($this.val() == "") { return "0.0"; }
                var val = parseFloat($this.val().replace(",", ""));
                return ($this.val(val));
            });
        });
    };
})(jQuery);

(function($) {
    $.fn.integerOnly = function() {
        return this.each(function() {
            var $this = jQuery(this);

            $this.keydown(function(e) {
                if (e.which != 8 && e.which != 0 && e.which != 9 && e.which != 13 && e.which != 16 && e.which != 46 && (e.which < 35 || e.which > 40) && (e.which < 96 || e.which > 105) && (e.which < 48 || e.which > 57)) {
                    $('#ModalDialog').showModalDialog('process', { message: 'Only numeric input is allowed', cssClass: 'error', timeout: 1500 });
                    $this.focus();
                    $this.val($this.val().substr(0, $this.length - 1));                    
                }
            });
        });
    };
})(jQuery);

(function($) {
    $.fn.numbersOnly = function() {
        return this.each(function() {
            var $this = jQuery(this);

            $this.keydown(function(e) {
                if (e.which != 8 && e.which != 0 && e.which != 9 && e.which != 13 && e.which != 16 && e.which != 46 && (e.which < 35 || e.which > 40) && (e.which < 96 || e.which > 105) && (e.which < 48 || e.which > 57)) {
                    return false;
                }
            });
        });
    };
})(jQuery);


function CloseDialog(id) {
    $("#" + id).dialog('close');
    $("#" + id).dialog('destroy');
}
(function($) {
    $.fn.showModalDialog = function(type, options) {
        settings = jQuery.extend({
            title: "",
            message: "",
            timeout: 0,
            callback: null,
            cssClass: "dialogIcons process",
            width: 340,
            height: 300,
            cssClass: ""
        }, options);

        var $this = $(this);
        $this.dialog({ bgiframe: true, modal: true, resizable: false, autoOpen: false, width: settings.width, height: settings.height, title: settings.title });
        $this.dialog('open');

        //Set HTML template of dialog      
        type = type.toLowerCase();
        var template = $("#htmDialog_" + type).html();
        $this.html(template);
        var dialogIcon = $this.find(".dialogIcons");
        dialogIcon.attr("class", dialogIcon.attr("class") + " " + settings.cssClass);
        $this.find("#msg").html(settings.message);

        if (settings.timeout > 0) {
            setTimeout("CloseDialog('" + $this.attr("id") + "')", settings.timeout);
        }
        else {
            $this.find(".smallButtons").click(function(evt) {
                if (settings.callback != null) {
                    if (!settings.callback($(this), evt)) {
                        CloseDialog($this.attr("id"));
                    }
                }
                else {
                    CloseDialog($this.attr("id"));
                }
                return;
            });
        }



    };
})(jQuery);

(function($) {
    $.fn.closeModalDialog = function() {
        var $this = this;
        $this.dialog("close");
        $this.dialog("destroy");
    };
})(jQuery);


(function($) {
$.fn.switchCss = function(oldCss,newCss) {
    $(this).removeClass(oldCss).addClass(newCss);
    };
})(jQuery);

function disableEnterKey(e) {
    var key;

    if (window.event)
        key = window.event.keyCode;
    else
        key = e.which;

    if (key == 13)
        return false;
    else
        return true;
}

$.fn.focusNextInputField = function() {
    return this.each(function() {
        var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
        var index = fields.index(this);
        if (index > -1 && (index + 1) < fields.length) {
            fields.eq(index + 1).focus();
        }
        return false;
    });
};

/* http://keith-wood.name/countdown.html
Countdown for jQuery v1.5.6.
Written by Keith Wood (kbwood{at}iinet.com.au) January 2008.
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
Please attribute the author if you use it. */
(function($) { function Countdown() { this.regional = []; this.regional[''] = { labels: ['Years', 'Months', 'Weeks', 'Days', 'Hours', 'Minutes', 'Seconds'], labels1: ['Year', 'Month', 'Week', 'Day', 'Hour', 'Minute', 'Second'], compactLabels: ['y', 'm', 'w', 'd'], timeSeparator: ':', isRTL: false }; this._defaults = { until: null, since: null, timezone: null, serverSync: null, format: 'dHMS', layout: '', compact: false, description: '', expiryUrl: '', expiryText: '', alwaysExpire: false, onExpiry: null, onTick: null }; $.extend(this._defaults, this.regional['']) } var w = 'countdown'; var Y = 0; var O = 1; var W = 2; var D = 3; var H = 4; var M = 5; var S = 6; $.extend(Countdown.prototype, { markerClassName: 'hasCountdown', _timer: setInterval(function() { $.countdown._updateTargets() }, 980), _timerTargets: [], setDefaults: function(a) { this._resetExtraLabels(this._defaults, a); extendRemove(this._defaults, a || {}) }, UTCDate: function(a, b, c, e, f, g, h, i) { if (typeof b == 'object' && b.constructor == Date) { i = b.getMilliseconds(); h = b.getSeconds(); g = b.getMinutes(); f = b.getHours(); e = b.getDate(); c = b.getMonth(); b = b.getFullYear() } var d = new Date(); d.setUTCFullYear(b); d.setUTCDate(1); d.setUTCMonth(c || 0); d.setUTCDate(e || 1); d.setUTCHours(f || 0); d.setUTCMinutes((g || 0) - (Math.abs(a) < 30 ? a * 60 : a)); d.setUTCSeconds(h || 0); d.setUTCMilliseconds(i || 0); return d }, periodsToSeconds: function(a) { return a[0] * 31557600 + a[1] * 2629800 + a[2] * 604800 + a[3] * 86400 + a[4] * 3600 + a[5] * 60 + a[6] }, _settingsCountdown: function(a, b) { if (!b) { return $.countdown._defaults } var c = $.data(a, w); return (b == 'all' ? c.options : c.options[b]) }, _attachCountdown: function(a, b) { var c = $(a); if (c.hasClass(this.markerClassName)) { return } c.addClass(this.markerClassName); var d = { options: $.extend({}, b), _periods: [0, 0, 0, 0, 0, 0, 0] }; $.data(a, w, d); this._changeCountdown(a) }, _addTarget: function(a) { if (!this._hasTarget(a)) { this._timerTargets.push(a) } }, _hasTarget: function(a) { return ($.inArray(a, this._timerTargets) > -1) }, _removeTarget: function(b) { this._timerTargets = $.map(this._timerTargets, function(a) { return (a == b ? null : a) }) }, _updateTargets: function() { for (var i = 0; i < this._timerTargets.length; i++) { this._updateCountdown(this._timerTargets[i]) } }, _updateCountdown: function(a, b) { var c = $(a); b = b || $.data(a, w); if (!b) { return } c.html(this._generateHTML(b)); c[(this._get(b, 'isRTL') ? 'add' : 'remove') + 'Class']('countdown_rtl'); var d = this._get(b, 'onTick'); if (d) { var e = b._hold != 'lap' ? b._periods : this._calculatePeriods(b, b._show, new Date()); d.apply(a, [e]) } var f = b._hold != 'pause' && (b._since ? b._now.getTime() < b._since.getTime() : b._now.getTime() >= b._until.getTime()); if (f && !b._expiring) { b._expiring = true; if (this._hasTarget(a) || this._get(b, 'alwaysExpire')) { this._removeTarget(a); var g = this._get(b, 'onExpiry'); if (g) { g.apply(a, []) } var h = this._get(b, 'expiryText'); if (h) { var i = this._get(b, 'layout'); b.options.layout = h; this._updateCountdown(a, b); b.options.layout = i } var j = this._get(b, 'expiryUrl'); if (j) { window.location = j } } b._expiring = false } else if (b._hold == 'pause') { this._removeTarget(a) } $.data(a, w, b) }, _changeCountdown: function(a, b, c) { b = b || {}; if (typeof b == 'string') { var d = b; b = {}; b[d] = c } var e = $.data(a, w); if (e) { this._resetExtraLabels(e.options, b); extendRemove(e.options, b); this._adjustSettings(a, e); $.data(a, w, e); var f = new Date(); if ((e._since && e._since < f) || (e._until && e._until > f)) { this._addTarget(a) } this._updateCountdown(a, e) } }, _resetExtraLabels: function(a, b) { var c = false; for (var n in b) { if (n.match(/[Ll]abels/)) { c = true; break } } if (c) { for (var n in a) { if (n.match(/[Ll]abels[0-9]/)) { a[n] = null } } } }, _adjustSettings: function(a, b) { var c = this._get(b, 'serverSync'); c = (c ? c.apply(a, []) : null); var d = new Date(); var e = this._get(b, 'timezone'); e = (e == null ? -d.getTimezoneOffset() : e); b._since = this._get(b, 'since'); if (b._since != null) { b._since = this.UTCDate(e, this._determineTime(b._since, null)); if (b._since && c) { b._since.setMilliseconds(b._since.getMilliseconds() + d.getTime() - c.getTime()) } } b._until = this.UTCDate(e, this._determineTime(this._get(b, 'until'), d)); if (c) { b._until.setMilliseconds(b._until.getMilliseconds() + d.getTime() - c.getTime()) } b._show = this._determineShow(b) }, _destroyCountdown: function(a) { var b = $(a); if (!b.hasClass(this.markerClassName)) { return } this._removeTarget(a); b.removeClass(this.markerClassName).empty(); $.removeData(a, w) }, _pauseCountdown: function(a) { this._hold(a, 'pause') }, _lapCountdown: function(a) { this._hold(a, 'lap') }, _resumeCountdown: function(a) { this._hold(a, null) }, _hold: function(a, b) { var c = $.data(a, w); if (c) { if (c._hold == 'pause' && !b) { c._periods = c._savePeriods; var d = (c._since ? '-' : '+'); c[c._since ? '_since' : '_until'] = this._determineTime(d + c._periods[0] + 'y' + d + c._periods[1] + 'o' + d + c._periods[2] + 'w' + d + c._periods[3] + 'd' + d + c._periods[4] + 'h' + d + c._periods[5] + 'm' + d + c._periods[6] + 's'); this._addTarget(a) } c._hold = b; c._savePeriods = (b == 'pause' ? c._periods : null); $.data(a, w, c); this._updateCountdown(a, c) } }, _getTimesCountdown: function(a) { var b = $.data(a, w); return (!b ? null : (!b._hold ? b._periods : this._calculatePeriods(b, b._show, new Date()))) }, _get: function(a, b) { return (a.options[b] != null ? a.options[b] : $.countdown._defaults[b]) }, _determineTime: function(k, l) { var m = function(a) { var b = new Date(); b.setTime(b.getTime() + a * 1000); return b }; var n = function(a) { a = a.toLowerCase(); var b = new Date(); var c = b.getFullYear(); var d = b.getMonth(); var e = b.getDate(); var f = b.getHours(); var g = b.getMinutes(); var h = b.getSeconds(); var i = /([+-]?[0-9]+)\s*(s|m|h|d|w|o|y)?/g; var j = i.exec(a); while (j) { switch (j[2] || 's') { case 's': h += parseInt(j[1], 10); break; case 'm': g += parseInt(j[1], 10); break; case 'h': f += parseInt(j[1], 10); break; case 'd': e += parseInt(j[1], 10); break; case 'w': e += parseInt(j[1], 10) * 7; break; case 'o': d += parseInt(j[1], 10); e = Math.min(e, $.countdown._getDaysInMonth(c, d)); break; case 'y': c += parseInt(j[1], 10); e = Math.min(e, $.countdown._getDaysInMonth(c, d)); break } j = i.exec(a) } return new Date(c, d, e, f, g, h, 0) }; var o = (k == null ? l : (typeof k == 'string' ? n(k) : (typeof k == 'number' ? m(k) : k))); if (o) o.setMilliseconds(0); return o }, _getDaysInMonth: function(a, b) { return 32 - new Date(a, b, 32).getDate() }, _generateHTML: function(c) { c._periods = periods = (c._hold ? c._periods : this._calculatePeriods(c, c._show, new Date())); var d = false; var e = 0; var f = $.extend({}, c._show); for (var g = 0; g < c._show.length; g++) { d |= (c._show[g] == '?' && periods[g] > 0); f[g] = (c._show[g] == '?' && !d ? null : c._show[g]); e += (f[g] ? 1 : 0) } var h = this._get(c, 'compact'); var i = this._get(c, 'layout'); var j = (h ? this._get(c, 'compactLabels') : this._get(c, 'labels')); var k = this._get(c, 'timeSeparator'); var l = this._get(c, 'description') || ''; var m = function(a) { var b = $.countdown._get(c, 'compactLabels' + periods[a]); return (f[a] ? periods[a] + (b ? b[a] : j[a]) + ' ' : '') }; var n = function(a) { var b = $.countdown._get(c, 'labels' + periods[a]); return (f[a] ? '<span class="countdown_section"><span class="countdown_amount">' + periods[a] + '</span><br/>' + (b ? b[a] : j[a]) + '</span>' : '') }; return (i ? this._buildLayout(c, f, i, h) : ((h ? '<span class="countdown_row countdown_amount' + (c._hold ? ' countdown_holding' : '') + '">' + m(Y) + m(O) + m(W) + m(D) + (f[H] ? this._minDigits(periods[H], 2) : '') + (f[M] ? (f[H] ? k : '') + this._minDigits(periods[M], 2) : '') + (f[S] ? (f[H] || f[M] ? k : '') + this._minDigits(periods[S], 2) : '') : '<span class="countdown_row countdown_show' + e + (c._hold ? ' countdown_holding' : '') + '">' + n(Y) + n(O) + n(W) + n(D) + n(H) + n(M) + n(S)) + '</span>' + (l ? '<span class="countdown_row countdown_descr">' + l + '</span>' : ''))) }, _buildLayout: function(c, d, e, f) { var g = this._get(c, (f ? 'compactLabels' : 'labels')); var h = function(a) { return ($.countdown._get(c, (f ? 'compactLabels' : 'labels') + c._periods[a]) || g)[a] }; var j = function(a, b) { return Math.floor(a / b) % 10 }; var k = { desc: this._get(c, 'description'), sep: this._get(c, 'timeSeparator'), yl: h(Y), yn: c._periods[Y], ynn: this._minDigits(c._periods[Y], 2), ynnn: this._minDigits(c._periods[Y], 3), y1: j(c._periods[Y], 1), y10: j(c._periods[Y], 10), y100: j(c._periods[Y], 100), y1000: j(c._periods[Y], 1000), ol: h(O), on: c._periods[O], onn: this._minDigits(c._periods[O], 2), onnn: this._minDigits(c._periods[O], 3), o1: j(c._periods[O], 1), o10: j(c._periods[O], 10), o100: j(c._periods[O], 100), o1000: j(c._periods[O], 1000), wl: h(W), wn: c._periods[W], wnn: this._minDigits(c._periods[W], 2), wnnn: this._minDigits(c._periods[W], 3), w1: j(c._periods[W], 1), w10: j(c._periods[W], 10), w100: j(c._periods[W], 100), w1000: j(c._periods[W], 1000), dl: h(D), dn: c._periods[D], dnn: this._minDigits(c._periods[D], 2), dnnn: this._minDigits(c._periods[D], 3), d1: j(c._periods[D], 1), d10: j(c._periods[D], 10), d100: j(c._periods[D], 100), d1000: j(c._periods[D], 1000), hl: h(H), hn: c._periods[H], hnn: this._minDigits(c._periods[H], 2), hnnn: this._minDigits(c._periods[H], 3), h1: j(c._periods[H], 1), h10: j(c._periods[H], 10), h100: j(c._periods[H], 100), h1000: j(c._periods[H], 1000), ml: h(M), mn: c._periods[M], mnn: this._minDigits(c._periods[M], 2), mnnn: this._minDigits(c._periods[M], 3), m1: j(c._periods[M], 1), m10: j(c._periods[M], 10), m100: j(c._periods[M], 100), m1000: j(c._periods[M], 1000), sl: h(S), sn: c._periods[S], snn: this._minDigits(c._periods[S], 2), snnn: this._minDigits(c._periods[S], 3), s1: j(c._periods[S], 1), s10: j(c._periods[S], 10), s100: j(c._periods[S], 100), s1000: j(c._periods[S], 1000) }; var l = e; for (var i = 0; i < 7; i++) { var m = 'yowdhms'.charAt(i); var o = new RegExp('\\{' + m + '<\\}(.*)\\{' + m + '>\\}', 'g'); l = l.replace(o, (d[i] ? '$1' : '')) } $.each(k, function(n, v) { var a = new RegExp('\\{' + n + '\\}', 'g'); l = l.replace(a, v) }); return l }, _minDigits: function(a, b) { a = '' + a; if (a.length >= b) { return a } a = '0000000000' + a; return a.substr(a.length - b) }, _determineShow: function(a) { var b = this._get(a, 'format'); var c = []; c[Y] = (b.match('y') ? '?' : (b.match('Y') ? '!' : null)); c[O] = (b.match('o') ? '?' : (b.match('O') ? '!' : null)); c[W] = (b.match('w') ? '?' : (b.match('W') ? '!' : null)); c[D] = (b.match('d') ? '?' : (b.match('D') ? '!' : null)); c[H] = (b.match('h') ? '?' : (b.match('H') ? '!' : null)); c[M] = (b.match('m') ? '?' : (b.match('M') ? '!' : null)); c[S] = (b.match('s') ? '?' : (b.match('S') ? '!' : null)); return c }, _calculatePeriods: function(f, g, h) { f._now = h; f._now.setMilliseconds(0); var i = new Date(f._now.getTime()); if (f._since) { if (h.getTime() < f._since.getTime()) { f._now = h = i } else { h = f._since } } else { i.setTime(f._until.getTime()); if (h.getTime() > f._until.getTime()) { f._now = h = i } } var j = [0, 0, 0, 0, 0, 0, 0]; if (g[Y] || g[O]) { var k = $.countdown._getDaysInMonth(h.getFullYear(), h.getMonth()); var l = $.countdown._getDaysInMonth(i.getFullYear(), i.getMonth()); var m = (i.getDate() == h.getDate() || (i.getDate() >= Math.min(k, l) && h.getDate() >= Math.min(k, l))); var n = function(a) { return (a.getHours() * 60 + a.getMinutes()) * 60 + a.getSeconds() }; var o = Math.max(0, (i.getFullYear() - h.getFullYear()) * 12 + i.getMonth() - h.getMonth() + ((i.getDate() < h.getDate() && !m) || (m && n(i) < n(h)) ? -1 : 0)); j[Y] = (g[Y] ? Math.floor(o / 12) : 0); j[O] = (g[O] ? o - j[Y] * 12 : 0); var p = function(a, b, c) { var d = (a.getDate() == c); var e = $.countdown._getDaysInMonth(a.getFullYear() + b * j[Y], a.getMonth() + b * j[O]); if (a.getDate() > e) { a.setDate(e) } a.setFullYear(a.getFullYear() + b * j[Y]); a.setMonth(a.getMonth() + b * j[O]); if (d) { a.setDate(e) } return a }; if (f._since) { i = p(i, -1, l) } else { h = p(new Date(h.getTime()), +1, k) } } var q = Math.floor((i.getTime() - h.getTime()) / 1000); var r = function(a, b) { j[a] = (g[a] ? Math.floor(q / b) : 0); q -= j[a] * b }; r(W, 604800); r(D, 86400); r(H, 3600); r(M, 60); r(S, 1); if (q > 0 && !f._since) { var s = [1, 12, 4.3482, 7, 24, 60, 60]; var t = S; var u = 1; for (var v = S; v >= Y; v--) { if (g[v]) { if (j[t] >= u) { j[t] = 0; q = 1 } if (q > 0) { j[v]++; q = 0; t = v; u = 1 } } u *= s[v] } } return j } }); function extendRemove(a, b) { $.extend(a, b); for (var c in b) { if (b[c] == null) { a[c] = null } } return a } $.fn.countdown = function(a) { var b = Array.prototype.slice.call(arguments, 1); if (a == 'getTimes' || a == 'settings') { return $.countdown['_' + a + 'Countdown'].apply($.countdown, [this[0]].concat(b)) } return this.each(function() { if (typeof a == 'string') { $.countdown['_' + a + 'Countdown'].apply($.countdown, [this].concat(b)) } else { $.countdown._attachCountdown(this, a) } }) }; $.countdown = new Countdown() })(jQuery);



/* http://keith-wood.name/datepick.html
Datepicker for jQuery 3.7.5.
Written by Marc Grabanski (m@marcgrabanski.com) and
Keith Wood (kbwood{at}iinet.com.au).
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
Please attribute the authors if you use it. */
var datePickDefaultFormat = 'M dd, yy';
(function($) { var bm = 'datepick'; function Datepick() { this._uuid = new Date().getTime(); this._curInst = null; this._keyEvent = false; this._disabledInputs = []; this._datepickerShowing = false; this._inDialog = false; this.regional = []; this.regional[''] = { clearText: 'Clear', clearStatus: 'Erase the current date', closeText: 'Close', closeStatus: 'Close without change', prevText: '&#x3c;Prev', prevStatus: 'Show the previous month', prevBigText: '&#x3c;&#x3c;', prevBigStatus: 'Show the previous year', nextText: 'Next&#x3e;', nextStatus: 'Show the next month', nextBigText: '&#x3e;&#x3e;', nextBigStatus: 'Show the next year', currentText: 'Today', currentStatus: 'Show the current month', monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], monthStatus: 'Show a different month', yearStatus: 'Show a different year', weekHeader: 'Wk', weekStatus: 'Week of the year', dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], dayStatus: 'Set DD as first week day', dateStatus: 'Select DD, M d', dateFormat: 'M dd, yy', firstDay: 0, initStatus: 'Select a date', isRTL: false, showMonthAfterYear: false, yearSuffix: '' }; this._defaults = { useThemeRoller: false, showOn: 'focus', showAnim: 'show', showOptions: {}, duration: 'normal', buttonText: '...', buttonImage: '', buttonImageOnly: false, alignment: 'bottom', autoSize: false, defaultDate: null, showDefault: false, appendText: '', closeAtTop: true, mandatory: false, hideIfNoPrevNext: false, navigationAsDateFormat: false, showBigPrevNext: false, stepMonths: 1, stepBigMonths: 12, gotoCurrent: false, changeMonth: true, changeYear: true, yearRange: 'c-10:c+10', changeFirstDay: false, showOtherMonths: false, selectOtherMonths: false, highlightWeek: false, showWeeks: false, calculateWeek: this.iso8601Week, shortYearCutoff: '+10', showStatus: false, statusForDate: this.dateStatus, minDate: null, maxDate: null, numberOfMonths: 1, showCurrentAtPos: 0, rangeSelect: false, rangeSeparator: ' - ', multiSelect: 0, multiSeparator: ',', beforeShow: null, beforeShowDay: null, onChangeMonthYear: null, onHover: null, onSelect: null, onClose: null, altField: '', altFormat: '', constrainInput: true }; $.extend(this._defaults, this.regional['']); this.dpDiv = $('<div style="display: none;"></div>') } $.extend(Datepick.prototype, { version: '3.7.3', markerClassName: 'hasDatepick', _mainDivId: ['datepick-div', 'ui-datepicker-div'], _mainDivClass: ['', 'ui-datepicker ' + 'ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'], _inlineClass: ['datepick-inline', 'ui-datepicker-inline ui-datepicker ' + 'ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'], _multiClass: ['datepick-multi', 'ui-datepicker-multi'], _rtlClass: ['datepick-rtl', 'ui-datepicker-rtl'], _appendClass: ['datepick-append', 'ui-datepicker-append'], _triggerClass: ['datepick-trigger', 'ui-datepicker-trigger'], _dialogClass: ['datepick-dialog', 'ui-datepicker-dialog'], _promptClass: ['datepick-prompt', 'ui-datepicker-prompt'], _disableClass: ['datepick-disabled', 'ui-datepicker-disabled'], _controlClass: ['datepick-control', 'ui-datepicker-header ' + 'ui-widget-header ui-helper-clearfix ui-corner-all'], _clearClass: ['datepick-clear', 'ui-datepicker-clear'], _closeClass: ['datepick-close', 'ui-datepicker-close'], _linksClass: ['datepick-links', 'ui-datepicker-header ' + 'ui-widget-header ui-helper-clearfix ui-corner-all'], _prevClass: ['datepick-prev', 'ui-datepicker-prev'], _nextClass: ['datepick-next', 'ui-datepicker-next'], _currentClass: ['datepick-current', 'ui-datepicker-current'], _oneMonthClass: ['datepick-one-month', 'ui-datepicker-group'], _newRowClass: ['datepick-new-row', 'ui-datepicker-row-break'], _monthYearClass: ['datepick-header', 'ui-datepicker-header ' + 'ui-widget-header ui-helper-clearfix ui-corner-all'], _monthSelectClass: ['datepick-new-month', 'ui-datepicker-month'], _monthClass: ['', 'ui-datepicker-month'], _yearSelectClass: ['datepick-new-year', 'ui-datepicker-year'], _yearClass: ['', 'ui-datepicker-year'], _tableClass: ['datepick', 'ui-datepicker-calendar'], _tableHeaderClass: ['datepick-title-row', ''], _weekColClass: ['datepick-week-col', 'ui-datepicker-week-col'], _weekRowClass: ['datepick-days-row', ''], _weekendClass: ['datepick-week-end-cell', 'ui-datepicker-week-end'], _dayClass: ['datepick-days-cell', ''], _otherMonthClass: ['datepick-other-month', 'ui-datepicker-other-month'], _todayClass: ['datepick-today', 'ui-state-highlight'], _selectableClass: ['', 'ui-state-default'], _unselectableClass: ['datepick-unselectable', 'ui-datepicker-unselectable ui-state-disabled'], _selectedClass: ['datepick-current-day', 'ui-state-active'], _dayOverClass: ['datepick-days-cell-over', 'ui-state-hover'], _weekOverClass: ['datepick-week-over', 'ui-state-hover'], _statusClass: ['datepick-status', 'ui-datepicker-status'], _statusId: ['datepick-status-', 'ui-datepicker-status-'], _coverClass: ['datepick-cover', 'ui-datepicker-cover'], setDefaults: function(a) { extendRemove(this._defaults, a || {}); return this }, _attachDatepick: function(a, b) { if (!a.id) a.id = 'dp' + (++this._uuid); var c = a.nodeName.toLowerCase(); var d = this._newInst($(a), (c == 'div' || c == 'span')); var e = ($.fn.metadata ? $(a).metadata() : {}); d.settings = $.extend({}, b || {}, e || {}); if (d.inline) { d.dpDiv.addClass(this._inlineClass[this._get(d, 'useThemeRoller') ? 1 : 0]); this._inlineDatepick(a, d) } else this._connectDatepick(a, d) }, _newInst: function(a, b) { var c = a[0].id.replace(/([^A-Za-z0-9_])/g, '\\\\$1'); return { id: c, input: a, cursorDate: this._daylightSavingAdjust(new Date()), drawMonth: 0, drawYear: 0, dates: [], inline: b, dpDiv: (!b ? this.dpDiv : $('<div></div>')), siblings: $([])} }, _connectDatepick: function(a, b) { var c = $(a); if (c.hasClass(this.markerClassName)) return; var d = this._get(b, 'appendText'); var e = this._get(b, 'isRTL'); var f = this._get(b, 'useThemeRoller') ? 1 : 0; if (d) { var g = $('<span class="' + this._appendClass[f] + '">' + d + '</span>'); c[e ? 'before' : 'after'](g); b.siblings = b.siblings.add(g) } var h = this._get(b, 'showOn'); if (h == 'focus' || h == 'both') c.focus(this._showDatepick); if (h == 'button' || h == 'both') { var i = this._get(b, 'buttonText'); var j = this._get(b, 'buttonImage'); var k = $(this._get(b, 'buttonImageOnly') ? $('<img/>').addClass(this._triggerClass[f]).attr({ src: j, alt: i, title: i }) : $('<button type="button"></button>').addClass(this._triggerClass[f]).html(j == '' ? i : $('<img/>').attr({ src: j, alt: i, title: i }))); c[e ? 'before' : 'after'](k); b.siblings = b.siblings.add(k); k.click(function() { if ($.datepick._datepickerShowing && $.datepick._lastInput == a) $.datepick._hideDatepick(); else $.datepick._showDatepick(a); return false }) } c.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress).keyup(this._doKeyUp); if (this._get(b, 'showDefault') && !b.input.val()) { b.dates = [this._getDefaultDate(b)]; this._showDate(b) } this._autoSize(b); $.data(a, bm, b) }, _autoSize: function(d) { if (this._get(d, 'autoSize') && !d.inline) { var e = new Date(2009, 12 - 1, 20); var f = this._get(d, 'dateFormat'); if (f.match(/[DM]/)) { var g = function(a) { var b = 0; var c = 0; for (var i = 0; i < a.length; i++) { if (a[i].length > b) { b = a[i].length; c = i } } return c }; e.setMonth(g(this._get(d, (f.match(/MM/) ? 'monthNames' : 'monthNamesShort')))); e.setDate(g(this._get(d, (f.match(/DD/) ? 'dayNames' : 'dayNamesShort'))) + 20 - e.getDay()) } d.input.attr('size', this._formatDate(d, e).length) } }, _inlineDatepick: function(a, b) { var c = $(a); if (c.hasClass(this.markerClassName)) return; c.addClass(this.markerClassName); $.data(a, bm, b); b.cursorDate = this._getDefaultDate(b); b.drawMonth = b.cursorDate.getMonth(); b.drawYear = b.cursorDate.getFullYear(); if (this._get(b, 'showDefault')) b.dates = [this._getDefaultDate(b)]; $('body').append(b.dpDiv); this._updateDatepick(b); b.dpDiv.width(this._getNumberOfMonths(b)[1] * $('.' + this._oneMonthClass[this._get(b, 'useThemeRoller') ? 1 : 0], b.dpDiv)[0].offsetWidth); c.append(b.dpDiv); this._updateAlternate(b) }, _dialogDatepick: function(a, b, c, d, e) { var f = this._dialogInst; if (!f) { var g = 'dp' + (++this._uuid); this._dialogInput = $('<input type="text" id="' + g + '" style="position: absolute; width: 1px; z-index: -1"/>'); this._dialogInput.keydown(this._doKeyDown); $('body').append(this._dialogInput); f = this._dialogInst = this._newInst(this._dialogInput, false); f.settings = {}; $.data(this._dialogInput[0], bm, f) } extendRemove(f.settings, d || {}); b = (b && b.constructor == Date ? this._formatDate(f, b) : b); this._dialogInput.val(b); this._pos = (e ? (isArray(e) ? e : [e.pageX, e.pageY]) : null); if (!this._pos) { var h = document.documentElement.scrollLeft || document.body.scrollLeft; var i = document.documentElement.scrollTop || document.body.scrollTop; this._pos = [(document.documentElement.clientWidth / 2) - 100 + h, (document.documentElement.clientHeight / 2) - 150 + i] } this._dialogInput.css('left', (this._pos[0] + 20) + 'px').css('top', this._pos[1] + 'px'); f.settings.onSelect = c; this._inDialog = true; this.dpDiv.addClass(this._dialogClass[this._get(f, 'useThemeRoller') ? 1 : 0]); this._showDatepick(this._dialogInput[0]); if ($.blockUI) $.blockUI(this.dpDiv); $.data(this._dialogInput[0], bm, f) }, _destroyDatepick: function(a) { var b = $(a); if (!b.hasClass(this.markerClassName)) { return } var c = $.data(a, bm); $.removeData(a, bm); if (c.inline) b.removeClass(this.markerClassName).empty(); else { $(c.siblings).remove(); b.removeClass(this.markerClassName).unbind('focus', this._showDatepick).unbind('keydown', this._doKeyDown).unbind('keypress', this._doKeyPress).unbind('keyup', this._doKeyUp) } }, _enableDatepick: function(b) { var c = $(b); if (!c.hasClass(this.markerClassName)) return; var d = $.data(b, bm); var e = this._get(d, 'useThemeRoller') ? 1 : 0; if (d.inline) c.children('.' + this._disableClass[e]).remove().end().find('select').attr('disabled', '').end().find('a').attr('href', 'javascript:void(0)'); else { b.disabled = false; d.siblings.filter('button.' + this._triggerClass[e]).each(function() { this.disabled = false }).end().filter('img.' + this._triggerClass[e]).css({ opacity: '1.0', cursor: '' }) } this._disabledInputs = $.map(this._disabledInputs, function(a) { return (a == b ? null : a) }) }, _disableDatepick: function(b) { var c = $(b); if (!c.hasClass(this.markerClassName)) return; var d = $.data(b, bm); var e = this._get(d, 'useThemeRoller') ? 1 : 0; if (d.inline) { var f = c.children('.' + this._inlineClass[e]); var g = f.offset(); var h = { left: 0, top: 0 }; f.parents().each(function() { if ($(this).css('position') == 'relative') { h = $(this).offset(); return false } }); c.prepend('<div class="' + this._disableClass[e] + '" style="' + 'width: ' + f.outerWidth() + 'px; height: ' + f.outerHeight() + 'px; left: ' + (g.left - h.left) + 'px; top: ' + (g.top - h.top) + 'px;"></div>').find('select').attr('disabled', 'disabled').end().find('a').removeAttr('href') } else { b.disabled = true; d.siblings.filter('button.' + this._triggerClass[e]).each(function() { this.disabled = true }).end().filter('img.' + this._triggerClass[e]).css({ opacity: '0.5', cursor: 'default' }) } this._disabledInputs = $.map(this._disabledInputs, function(a) { return (a == b ? null : a) }); this._disabledInputs.push(b) }, _isDisabledDatepick: function(a) { return (!a ? false : $.inArray(a, this._disabledInputs) > -1) }, _getInst: function(a) { try { return $.data(a, bm) } catch (err) { throw 'Missing instance data for this datepicker'; } }, _optionDatepick: function(a, b, c) { var d = this._getInst(a); if (arguments.length == 2 && typeof b == 'string') { return (b == 'defaults' ? $.extend({}, $.datepick._defaults) : (d ? (b == 'all' ? $.extend({}, d.settings) : this._get(d, b)) : null)) } var e = b || {}; if (typeof b == 'string') { e = {}; e[b] = c } if (d) { if (this._curInst == d) { this._hideDatepick(null, true) } var f = this._getDateDatepick(a); extendRemove(d.settings, e); this._autoSize(d); extendRemove(d, { dates: [] }); var g = (!f || isArray(f)); if (isArray(f)) for (var i = 0; i < f.length; i++) if (f[i]) { g = false; break } if (!g) this._setDateDatepick(a, f); if (d.inline) $(a).children('div').removeClass(this._inlineClass.join(' ')).addClass(this._inlineClass[this._get(d, 'useThemeRoller') ? 1 : 0]); this._updateDatepick(d) } }, _changeDatepick: function(a, b, c) { this._optionDatepick(a, b, c) }, _refreshDatepick: function(a) { var b = this._getInst(a); if (b) { this._updateDatepick(b) } }, _setDateDatepick: function(a, b, c) { var d = this._getInst(a); if (d) { this._setDate(d, b, c); this._updateDatepick(d); this._updateAlternate(d) } }, _getDateDatepick: function(a) { var b = this._getInst(a); if (b && !b.inline) this._setDateFromField(b); return (b ? this._getDate(b) : null) }, _doKeyDown: function(a) { var b = $.datepick._getInst(a.target); b.keyEvent = true; var c = true; var d = $.datepick._get(b, 'isRTL'); var e = $.datepick._get(b, 'useThemeRoller') ? 1 : 0; if ($.datepick._datepickerShowing) switch (a.keyCode) { case 9: $.datepick._hideDatepick(); c = false; break; case 13: var f = $('td.' + $.datepick._dayOverClass[e], b.dpDiv); if (f.length == 0) f = $('td.' + $.datepick._selectedClass[e] + ':first', b.dpDiv); if (f[0]) $.datepick._selectDay(f[0], a.target, b.cursorDate.getTime()); else $.datepick._hideDatepick(); break; case 27: $.datepick._hideDatepick(); break; case 33: $.datepick._adjustDate(a.target, (a.ctrlKey ? -$.datepick._get(b, 'stepBigMonths') : -$.datepick._get(b, 'stepMonths')), 'M'); break; case 34: $.datepick._adjustDate(a.target, (a.ctrlKey ? +$.datepick._get(b, 'stepBigMonths') : +$.datepick._get(b, 'stepMonths')), 'M'); break; case 35: if (a.ctrlKey || a.metaKey) $.datepick._clearDate(a.target); c = a.ctrlKey || a.metaKey; break; case 36: if (a.ctrlKey || a.metaKey) $.datepick._gotoToday(a.target); c = a.ctrlKey || a.metaKey; break; case 37: if (a.ctrlKey || a.metaKey) $.datepick._adjustDate(a.target, (d ? +1 : -1), 'D'); c = a.ctrlKey || a.metaKey; if (a.originalEvent.altKey) $.datepick._adjustDate(a.target, (a.ctrlKey ? -$.datepick._get(b, 'stepBigMonths') : -$.datepick._get(b, 'stepMonths')), 'M'); break; case 38: if (a.ctrlKey || a.metaKey) $.datepick._adjustDate(a.target, -7, 'D'); c = a.ctrlKey || a.metaKey; break; case 39: if (a.ctrlKey || a.metaKey) $.datepick._adjustDate(a.target, (d ? -1 : +1), 'D'); c = a.ctrlKey || a.metaKey; if (a.originalEvent.altKey) $.datepick._adjustDate(a.target, (a.ctrlKey ? +$.datepick._get(b, 'stepBigMonths') : +$.datepick._get(b, 'stepMonths')), 'M'); break; case 40: if (a.ctrlKey || a.metaKey) $.datepick._adjustDate(a.target, +7, 'D'); c = a.ctrlKey || a.metaKey; break; default: c = false } else if (a.keyCode == 36 && a.ctrlKey) $.datepick._showDatepick(this); else c = false; if (c) { a.preventDefault(); a.stopPropagation() } b.ctrlKey = (a.keyCode < 48); return !c }, _doKeyPress: function(a) { var b = $.datepick._getInst(a.target); if ($.datepick._get(b, 'constrainInput')) { var c = $.datepick._possibleChars(b); var d = String.fromCharCode(a.keyCode || a.charCode); return a.metaKey || b.ctrlKey || d < ' ' || !c || c.indexOf(d) > -1 } }, _doKeyUp: function(a) { var b = $.datepick._getInst(a.target); if (b.input.val() != b.lastVal) { try { var c = ($.datepick._get(b, 'rangeSelect') ? $.datepick._get(b, 'rangeSeparator') : ($.datepick._get(b, 'multiSelect') ? $.datepick._get(b, 'multiSeparator') : '')); var d = (b.input ? b.input.val() : ''); d = (c ? d.split(c) : [d]); var e = true; for (var i = 0; i < d.length; i++) { if (!$.datepick.parseDate($.datepick._get(b, 'dateFormat'), d[i], $.datepick._getFormatConfig(b))) { e = false; break } } if (e) { $.datepick._setDateFromField(b); $.datepick._updateAlternate(b); $.datepick._updateDatepick(b) } } catch (a) { } } return true }, _possibleChars: function(c) { var d = $.datepick._get(c, 'dateFormat'); var e = ($.datepick._get(c, 'rangeSelect') ? $.datepick._get(c, 'rangeSeparator') : ($.datepick._get(c, 'multiSelect') ? $.datepick._get(c, 'multiSeparator') : '')); var f = false; var g = function(a) { var b = (h + 1 < format.length && format.charAt(h + 1) == a); if (b) h++; return b }; for (var h = 0; h < d.length; h++) if (f) if (d.charAt(h) == "'" && !g("'")) f = false; else e += d.charAt(h); else switch (d.charAt(h)) { case 'd': case 'm': case 'y': case '@': e += '0123456789'; break; case 'D': case 'M': return null; case "'": if (g("'")) e += "'"; else f = true; break; default: e += d.charAt(h) } return e }, _doMouseOver: function(a, b, c) { var d = $.datepick._getInst($('#' + b)[0]); var e = $.datepick._get(d, 'useThemeRoller') ? 1 : 0; $(a).parents('.datepick-one-month').parent().find('td').removeClass($.datepick._dayOverClass[e]); $(a).addClass($.datepick._dayOverClass[e]); if ($.datepick._get(d, 'highlightWeek')) $(a).parent().parent().find('tr').removeClass($.datepick._weekOverClass[e]).end().end().addClass($.datepick._weekOverClass[e]); if ($(a).text()) { var f = new Date(c); if ($.datepick._get(d, 'showStatus')) { var g = ($.datepick._get(d, 'statusForDate').apply((d.input ? d.input[0] : null), [f, d]) || $.datepick._get(d, 'initStatus')); $('#' + $.datepick._statusId[e] + b).html(g) } if ($.datepick._get(d, 'onHover')) $.datepick._doHover(a, '#' + b, f.getFullYear(), f.getMonth()) } }, _doMouseOut: function(a, b) { var c = $.datepick._getInst($('#' + b)[0]); var d = $.datepick._get(c, 'useThemeRoller') ? 1 : 0; $(a).removeClass($.datepick._dayOverClass[d]).removeClass($.datepick._weekOverClass[d]); if ($.datepick._get(c, 'showStatus')) $('#' + $.datepick._statusId[d] + b).html($.datepick._get(c, 'initStatus')); if ($.datepick._get(c, 'onHover')) $.datepick._doHover(a, '#' + b) }, _doHover: function(a, b, c, d) { var e = this._getInst($(b)[0]); var f = $.datepick._get(e, 'useThemeRoller') ? 1 : 0; if ($(a).hasClass(this._unselectableClass[f])) return; var g = this._get(e, 'onHover'); var h = (c ? this._daylightSavingAdjust(new Date(c, d, $(a).text())) : null); g.apply((e.input ? e.input[0] : null), [(h ? this._formatDate(e, h) : ''), h, e]) }, _showDatepick: function(b) { b = b.target || b; if ($.datepick._isDisabledDatepick(b) || $.datepick._lastInput == b) return; var c = $.datepick._getInst(b); if ($.datepick._curInst && $.datepick._curInst != c) { $.datepick._curInst.dpDiv.stop(true, true) } var d = $.datepick._get(c, 'beforeShow'); var e = $.datepick._get(c, 'useThemeRoller') ? 1 : 0; extendRemove(c.settings, (d ? d.apply(b, [b, c]) : {})); c.lastVal = null; $.datepick._datepickerShowing = true; $.datepick._lastInput = b; $.datepick._setDateFromField(c); if ($.datepick._inDialog) b.value = ''; if (!$.datepick._pos) { $.datepick._pos = $.datepick._findPos(b); $.datepick._pos[1] += b.offsetHeight } var f = false; $(b).parents().each(function() { f |= $(this).css('position') == 'fixed'; return !f }); if (f && $.browser.opera) { $.datepick._pos[0] -= document.documentElement.scrollLeft; $.datepick._pos[1] -= document.documentElement.scrollTop } var g = { left: $.datepick._pos[0], top: $.datepick._pos[1] }; $.datepick._pos = null; c.dpDiv.css({ position: 'absolute', display: 'block', top: '-1000px' }); $.datepick._updateDatepick(c); c.dpDiv.width($.datepick._getNumberOfMonths(c)[1] * $('.' + $.datepick._oneMonthClass[e], c.dpDiv).width()); g = $.datepick._checkOffset(c, g, f); c.dpDiv.css({ position: ($.datepick._inDialog && $.blockUI ? 'static' : (f ? 'fixed' : 'absolute')), display: 'none', left: g.left + 'px', top: g.top + 'px' }); if (!c.inline) { var h = $.datepick._get(c, 'showAnim'); var i = $.datepick._get(c, 'duration'); var j = function() { var a = $.datepick._getBorders(c.dpDiv); c.dpDiv.find('iframe.' + $.datepick._coverClass[e]).css({ left: -a[0], top: -a[1], width: c.dpDiv.outerWidth(), height: c.dpDiv.outerHeight() }) }; if ($.effects && $.effects[h]) c.dpDiv.show(h, $.datepick._get(c, 'showOptions'), i, j); else c.dpDiv[h || 'show'](h ? i : '', j); if (!h) j(); if (c.input.is(':visible') && !c.input.is(':disabled')) c.input.focus(); $.datepick._curInst = c } }, _updateDatepick: function(a) { var b = this._getBorders(a.dpDiv); var c = this._get(a, 'useThemeRoller') ? 1 : 0; a.dpDiv.empty().append(this._generateHTML(a)).find('iframe.' + this._coverClass[c]).css({ left: -b[0], top: -b[1], width: a.dpDiv.outerWidth(), height: a.dpDiv.outerHeight() }); var d = this._getNumberOfMonths(a); if (!a.inline) a.dpDiv.attr('id', this._mainDivId[c]); a.dpDiv.removeClass(this._mainDivClass[1 - c]).addClass(this._mainDivClass[c]).removeClass(this._multiClass.join(' ')).addClass(d[0] != 1 || d[1] != 1 ? this._multiClass[c] : '').removeClass(this._rtlClass.join(' ')).addClass(this._get(a, 'isRTL') ? this._rtlClass[c] : ''); if (a == $.datepick._curInst && a.input && a.input.is(':visible') && !a.input.is(':disabled')) $(a.input).focus() }, _getBorders: function(c) { var d = function(a) { var b = ($.browser.msie ? 1 : 0); return { thin: 1 + b, medium: 3 + b, thick: 5 + b}[a] || a }; return [parseFloat(d(c.css('border-left-width'))), parseFloat(d(c.css('border-top-width')))] }, _checkOffset: function(a, b, c) { var d = this._get(a, 'alignment'); var e = this._get(a, 'isRTL'); var f = a.input ? this._findPos(a.input[0]) : null; var g = (!$.browser.mozilla || document.doctype ? document.documentElement.clientWidth : 0) || document.body.clientWidth; var h = (!$.browser.mozilla || document.doctype ? document.documentElement.clientHeight : 0) || document.body.clientHeight; if (g == 0) return b; var i = document.documentElement.scrollLeft || document.body.scrollLeft; var j = document.documentElement.scrollTop || document.body.scrollTop; var k = f[1] - (this._inDialog ? 0 : a.dpDiv.outerHeight()) - (c && $.browser.opera ? document.documentElement.scrollTop : 0); var l = b.top; var m = b.left; var n = f[0] + (a.input ? a.input.outerWidth() : 0) - a.dpDiv.outerWidth() - (c && $.browser.opera ? document.documentElement.scrollLeft : 0); var o = (b.left + a.dpDiv.outerWidth() - i) > g; var p = (b.top + a.dpDiv.outerHeight() - j) > h; if (d == 'topLeft') { b = { left: m, top: k} } else if (d == 'topRight') { b = { left: n, top: k} } else if (d == 'bottomLeft') { b = { left: m, top: l} } else if (d == 'bottomRight') { b = { left: n, top: l} } else if (d == 'top') { b = { left: (e || o ? n : m), top: k} } else { b = { left: (e || o ? n : m), top: (p ? k : l)} } b.left = Math.max((c ? 0 : i), b.left - (c ? i : 0)); b.top = Math.max((c ? 0 : j), b.top - (c ? j : 0)); return b }, _findPos: function(a) { while (a && (a.type == 'hidden' || a.nodeType != 1)) { a = a.nextSibling } var b = $(a).offset(); return [b.left, b.top] }, _hideDatepick: function(a, b) { var c = this._curInst; if (!c || (a && c != $.data(a, bm))) return false; var d = this._get(c, 'rangeSelect'); if (d && c.stayOpen) this._updateInput('#' + c.id); c.stayOpen = false; if (this._datepickerShowing) { var e = (b ? '' : this._get(c, 'showAnim')); var f = this._get(c, 'duration'); var g = function() { $.datepick._tidyDialog(c); $.datepick._curInst = null }; if ($.effects && $.effects[e]) c.dpDiv.hide(e, $.datepick._get(c, 'showOptions'), f, g); else c.dpDiv[(e == 'slideDown' ? 'slideUp' : (e == 'fadeIn' ? 'fadeOut' : 'hide'))](e ? f : '', g); if (f == '') g(); var h = this._get(c, 'onClose'); if (h) h.apply((c.input ? c.input[0] : null), [(c.input ? c.input.val() : ''), this._getDate(c), c]); this._datepickerShowing = false; this._lastInput = null; c.settings.prompt = null; if (this._inDialog) { this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' }); this.dpDiv.removeClass(this._dialogClass[this._get(c, 'useThemeRoller') ? 1 : 0]); if ($.blockUI) { $.unblockUI(); $('body').append(this.dpDiv) } } this._inDialog = false } return false }, _tidyDialog: function(a) { var b = this._get(a, 'useThemeRoller') ? 1 : 0; a.dpDiv.removeClass(this._dialogClass[b]).unbind('.datepick'); $('.' + this._promptClass[b], a.dpDiv).remove() }, _checkExternalClick: function(a) { if (!$.datepick._curInst) return; var b = $(a.target); var c = $.datepick._get($.datepick._curInst, 'useThemeRoller') ? 1 : 0; if (!b.parents().andSelf().is('#' + $.datepick._mainDivId[c]) && !b.hasClass($.datepick.markerClassName) && !b.parents().andSelf().hasClass($.datepick._triggerClass[c]) && $.datepick._datepickerShowing && !($.datepick._inDialog && $.blockUI)) $.datepick._hideDatepick() }, _adjustDate: function(a, b, c) { var d = this._getInst($(a)[0]); this._adjustInstDate(d, b, c); this._updateDatepick(d); return false }, _gotoToday: function(a) { var b = $(a); var c = this._getInst(b[0]); if (this._get(c, 'gotoCurrent') && c.dates[0]) c.cursorDate = new Date(c.dates[0].getTime()); else c.cursorDate = this._daylightSavingAdjust(new Date()); c.drawMonth = c.cursorDate.getMonth(); c.drawYear = c.cursorDate.getFullYear(); this._notifyChange(c); this._adjustDate(b); return false }, _selectMonthYear: function(a, b, c) { var d = $(a); var e = this._getInst(d[0]); e.selectingMonthYear = false; var f = parseInt(b.options[b.selectedIndex].value, 10); e.drawMonth -= $.datepick._get(e, 'showCurrentAtPos'); if (e.drawMonth < 0) { e.drawMonth += 12; e.drawYear-- } e['selected' + (c == 'M' ? 'Month' : 'Year')] = e['draw' + (c == 'M' ? 'Month' : 'Year')] = f; e.cursorDate.setDate(Math.min(e.cursorDate.getDate(), $.datepick._getDaysInMonth(e.drawYear, e.drawMonth))); e.cursorDate['set' + (c == 'M' ? 'Month' : 'FullYear')](f); this._notifyChange(e); this._adjustDate(d) }, _clickMonthYear: function(a) { var b = this._getInst($(a)[0]); if (b.input && b.selectingMonthYear && !$.browser.msie) b.input.focus(); b.selectingMonthYear = !b.selectingMonthYear }, _changeFirstDay: function(a, b) { var c = this._getInst($(a)[0]); c.settings.firstDay = b; this._updateDatepick(c); return false }, _selectDay: function(a, b, c) { var d = this._getInst($(b)[0]); var e = this._get(d, 'useThemeRoller') ? 1 : 0; if ($(a).hasClass(this._unselectableClass[e])) return false; var f = this._get(d, 'rangeSelect'); var g = this._get(d, 'multiSelect'); if (f) d.stayOpen = !d.stayOpen; else if (g) d.stayOpen = true; if (d.stayOpen) { $('.datepick td', d.dpDiv).removeClass(this._selectedClass[e]); $(a).addClass(this._selectedClass[e]) } d.cursorDate = this._daylightSavingAdjust(new Date(c)); var h = new Date(d.cursorDate.getTime()); if (f && !d.stayOpen) d.dates[1] = h; else if (g) { var j = -1; for (var i = 0; i < d.dates.length; i++) if (d.dates[i] && h.getTime() == d.dates[i].getTime()) { j = i; break } if (j > -1) d.dates.splice(j, 1); else if (d.dates.length < g) { if (d.dates[0]) d.dates.push(h); else d.dates = [h]; d.stayOpen = (d.dates.length != g) } } else d.dates = [h]; this._updateInput(b, true); if (d.stayOpen || d.inline) this._updateDatepick(d); return false }, _clearDate: function(a) { var b = $(a); var c = this._getInst(b[0]); if (this._get(c, 'mandatory')) return false; c.stayOpen = false; c.dates = (this._get(c, 'showDefault') ? [this._getDefaultDate(c)] : []); this._updateInput(b); return false }, _updateInput: function(a, b) { var c = this._getInst($(a)[0]); var d = this._showDate(c); this._updateAlternate(c); var e = this._get(c, 'onSelect'); if (e) e.apply((c.input ? c.input[0] : null), [d, this._getDate(c), c]); else if (c.input) c.input.trigger('change'); if (c.inline && !b) this._updateDatepick(c); else if (!c.stayOpen) { this._hideDatepick(); this._lastInput = c.input[0]; if (typeof (c.input[0]) != 'object') c.input.focus(); this._lastInput = null } return false }, _showDate: function(a) { var b = ''; if (a.input) { b = (a.dates.length == 0 ? '' : this._formatDate(a, a.dates[0])); if (b) { if (this._get(a, 'rangeSelect')) b += this._get(a, 'rangeSeparator') + this._formatDate(a, a.dates[1] || a.dates[0]); else if (this._get(a, 'multiSelect')) for (var i = 1; i < a.dates.length; i++) b += this._get(a, 'multiSeparator') + this._formatDate(a, a.dates[i]) } a.input.val(b) } return b }, _updateAlternate: function(a) { var b = this._get(a, 'altField'); if (b) { var c = this._get(a, 'altFormat') || this._get(a, 'dateFormat'); var d = this._getFormatConfig(a); var e = this.formatDate(c, a.dates[0], d); if (e && this._get(a, 'rangeSelect')) e += this._get(a, 'rangeSeparator') + this.formatDate(c, a.dates[1] || a.dates[0], d); else if (this._get(a, 'multiSelect')) for (var i = 1; i < a.dates.length; i++) e += this._get(a, 'multiSeparator') + this.formatDate(c, a.dates[i], d); $(b).val(e) } }, noWeekends: function(a) { return [(a.getDay() || 7) < 6, ''] }, iso8601Week: function(a) { var b = new Date(a.getTime()); b.setDate(b.getDate() + 4 - (b.getDay() || 7)); var c = b.getTime(); b.setMonth(0); b.setDate(1); return Math.floor(Math.round((c - b) / 86400000) / 7) + 1 }, dateStatus: function(a, b) { return $.datepick.formatDate($.datepick._get(b, 'dateStatus'), a, $.datepick._getFormatConfig(b)) }, parseDate: function(e, f, g) { if (e == null || f == null) throw 'Invalid arguments'; f = (typeof f == 'object' ? f.toString() : f + ''); if (f == '') return null; g = g || {}; var h = g.shortYearCutoff || this._defaults.shortYearCutoff; h = (typeof h != 'string' ? h : new Date().getFullYear() % 100 + parseInt(h, 10)); var j = g.dayNamesShort || this._defaults.dayNamesShort; var k = g.dayNames || this._defaults.dayNames; var l = g.monthNamesShort || this._defaults.monthNamesShort; var m = g.monthNames || this._defaults.monthNames; var n = -1; var o = -1; var p = -1; var q = -1; var r = false; var s = function(a) { var b = (x + 1 < e.length && e.charAt(x + 1) == a); if (b) x++; return b }; var t = function(a) { s(a); var b = (a == '@' ? 14 : (a == '!' ? 20 : (a == 'y' ? 4 : (a == 'o' ? 3 : 2)))); var c = new RegExp('^\\d{1,' + b + '}'); var d = f.substring(w).match(c); if (!d) throw 'Missing number at position ' + w; w += d[0].length; return parseInt(d[0], 10) }; var u = function(a, b, c) { var d = (s(a) ? c : b); for (var i = 0; i < d.length; i++) { if (f.substr(w, d[i].length) == d[i]) { w += d[i].length; return i + 1 } } throw 'Unknown name at position ' + w; }; var v = function() { if (f.charAt(w) != e.charAt(x)) throw 'Unexpected literal at position ' + w; w++ }; var w = 0; for (var x = 0; x < e.length; x++) { if (r) if (e.charAt(x) == "'" && !s("'")) r = false; else v(); else switch (e.charAt(x)) { case 'd': p = t('d'); break; case 'D': u('D', j, k); break; case 'o': q = t('o'); break; case 'w': t('w'); break; case 'm': o = t('m'); break; case 'M': o = u('M', l, m); break; case 'y': n = t('y'); break; case '@': var y = new Date(t('@')); n = y.getFullYear(); o = y.getMonth() + 1; p = y.getDate(); break; case '!': var y = new Date((t('!') - this._ticksTo1970) / 10000); n = y.getFullYear(); o = y.getMonth() + 1; p = y.getDate(); break; case "'": if (s("'")) v(); else r = true; break; default: v() } } if (w < f.length) throw 'Additional text found at end'; if (n == -1) n = new Date().getFullYear(); else if (n < 100) n += (h == -1 ? 1900 : new Date().getFullYear() - new Date().getFullYear() % 100 - (n <= h ? 0 : 100)); if (q > -1) { o = 1; p = q; do { var z = this._getDaysInMonth(n, o - 1); if (p <= z) break; o++; p -= z } while (true) } var y = this._daylightSavingAdjust(new Date(n, o - 1, p)); if (y.getFullYear() != n || y.getMonth() + 1 != o || y.getDate() != p) throw 'Invalid date'; return y }, ATOM: 'yy-mm-dd', COOKIE: 'D, dd M yy', ISO_8601: 'yy-mm-dd', RFC_822: 'D, d M y', RFC_850: 'DD, dd-M-y', RFC_1036: 'D, d M y', RFC_1123: 'D, d M yy', RFC_2822: 'D, d M yy', RSS: 'D, d M y', TICKS: '!', TIMESTAMP: '@', W3C: 'yy-mm-dd', _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000), formatDate: function(e, f, g) { if (!f) return ''; g = g || {}; var h = g.dayNamesShort || this._defaults.dayNamesShort; var i = g.dayNames || this._defaults.dayNames; var j = g.monthNamesShort || this._defaults.monthNamesShort; var k = g.monthNames || this._defaults.monthNames; var l = g.calculateWeek || this._defaults.calculateWeek; var m = function(a) { var b = (r + 1 < e.length && e.charAt(r + 1) == a); if (b) r++; return b }; var n = function(a, b, c) { var d = '' + b; if (m(a)) while (d.length < c) d = '0' + d; return d }; var o = function(a, b, c, d) { return (m(a) ? d[b] : c[b]) }; var p = ''; var q = false; if (f) for (var r = 0; r < e.length; r++) { if (q) if (e.charAt(r) == "'" && !m("'")) q = false; else p += e.charAt(r); else switch (e.charAt(r)) { case 'd': p += n('d', f.getDate(), 2); break; case 'D': p += o('D', f.getDay(), h, i); break; case 'o': p += n('o', (f.getTime() - new Date(f.getFullYear(), 0, 0).getTime()) / 86400000, 3); break; case 'w': p += n('w', l(f), 2); break; case 'm': p += n('m', f.getMonth() + 1, 2); break; case 'M': p += o('M', f.getMonth(), j, k); break; case 'y': p += (m('y') ? f.getFullYear() : (f.getFullYear() % 100 < 10 ? '0' : '') + f.getFullYear() % 100); break; case '@': p += f.getTime(); break; case '!': p += f.getTime() * 10000 + this._ticksTo1970; break; case "'": if (m("'")) p += "'"; else q = true; break; default: p += e.charAt(r) } } return p }, _get: function(a, b) { return a.settings[b] !== undefined ? a.settings[b] : this._defaults[b] }, _setDateFromField: function(a) { if (a.input.val() == a.lastVal) { return } var b = this._get(a, 'dateFormat'); var c = this._get(a, 'rangeSelect'); var d = this._get(a, 'multiSelect'); var e = a.lastVal = (a.input ? a.input.val() : ''); e = (c ? e.split(this._get(a, 'rangeSeparator')) : (d ? e.split(this._get(a, 'multiSeparator')) : [e])); a.dates = []; var f = this._getFormatConfig(a); for (var i = 0; i < e.length; i++) try { a.dates[i] = this.parseDate(b, e[i], f) } catch (event) { a.dates[i] = null } for (var i = a.dates.length - 1; i >= 0; i--) if (!a.dates[i]) a.dates.splice(i, 1); if (c && a.dates.length < 2) a.dates[1] = a.dates[0]; if (d && a.dates.length > d) a.dates.splice(d, a.dates.length); a.cursorDate = new Date((a.dates[0] || this._getDefaultDate(a)).getTime()); a.drawMonth = a.cursorDate.getMonth(); a.drawYear = a.cursorDate.getFullYear(); this._adjustInstDate(a) }, _getDefaultDate: function(a) { return this._restrictMinMax(a, this._determineDate(a, this._get(a, 'defaultDate'), new Date())) }, _determineDate: function(i, j, k) { var l = function(a) { var b = new Date(); b.setDate(b.getDate() + a); return b }; var m = function(a) { try { return $.datepick.parseDate($.datepick._get(i, 'dateFormat'), a, $.datepick._getFormatConfig(i)) } catch (e) { } var b = (a.toLowerCase().match(/^c/) ? $.datepick._getDate(i) : null); b = ($.isArray(b) ? b[0] : b) || new Date(); var c = b.getFullYear(); var d = b.getMonth(); var f = b.getDate(); var g = /([+-]?[0-9]+)\s*(d|w|m|y)?/g; var h = g.exec(a.toLowerCase()); while (h) { switch (h[2] || 'd') { case 'd': f += parseInt(h[1], 10); break; case 'w': f += parseInt(h[1], 10) * 7; break; case 'm': d += parseInt(h[1], 10); f = Math.min(f, $.datepick._getDaysInMonth(c, d)); break; case 'y': c += parseInt(h[1], 10); f = Math.min(f, $.datepick._getDaysInMonth(c, d)); break } h = g.exec(a.toLowerCase()) } return new Date(c, d, f) }; j = (j == null ? k : (typeof j == 'string' ? m(j) : (typeof j == 'number' ? (isNaN(j) || j == Infinity || j == -Infinity ? k : l(j)) : j))); j = (j && (j.toString() == 'Invalid Date' || j.toString() == 'NaN') ? k : j); if (j) { j.setHours(0); j.setMinutes(0); j.setSeconds(0); j.setMilliseconds(0) } return this._daylightSavingAdjust(j) }, _daylightSavingAdjust: function(a) { if (!a) return null; a.setHours(a.getHours() > 12 ? a.getHours() + 2 : 0); return a }, _setDate: function(a, b, c) { b = (!b ? [] : (isArray(b) ? b : [b])); if (c) b.push(c); var d = a.cursorDate.getMonth(); var e = a.cursorDate.getFullYear(); a.dates = (b.length == 0 ? [] : [this._restrictMinMax(a, this._determineDate(a, b[0], new Date()))]); a.cursorDate = (b.length == 0 ? new Date() : new Date(a.dates[0].getTime())); a.drawMonth = a.cursorDate.getMonth(); a.drawYear = a.cursorDate.getFullYear(); if (this._get(a, 'rangeSelect')) { if (b.length > 0) a.dates[1] = (b.length < 1 ? a.dates[0] : this._restrictMinMax(a, this._determineDate(a, b[1], null))) } else if (this._get(a, 'multiSelect')) for (var i = 1; i < b.length; i++) a.dates[i] = this._restrictMinMax(a, this._determineDate(a, b[i], null)); if (d != a.cursorDate.getMonth() || e != a.cursorDate.getFullYear()) this._notifyChange(a); this._adjustInstDate(a); this._showDate(a) }, _getDate: function(a) { var b = (!a.inline && a.input && a.input.val() == '' ? null : (a.dates.length ? a.dates[0] : null)); if (this._get(a, 'rangeSelect')) return (b ? [a.dates[0], a.dates[1] || a.dates[0]] : [null, null]); else if (this._get(a, 'multiSelect')) return a.dates.slice(0, a.dates.length); else return b }, _generateHTML: function(a) { var b = new Date(); b = this._daylightSavingAdjust(new Date(b.getFullYear(), b.getMonth(), b.getDate())); var c = this._get(a, 'showStatus'); var d = this._get(a, 'initStatus') || '&#xa0;'; var e = this._get(a, 'isRTL'); var f = this._get(a, 'useThemeRoller') ? 1 : 0; var g = (this._get(a, 'mandatory') ? '' : '<div class="' + this._clearClass[f] + '"><a href="javascript:void(0)" ' + 'onclick="jQuery.datepick._clearDate(\'#' + a.id + '\');"' + this._addStatus(f, c, a.id, this._get(a, 'clearStatus'), d) + '>' + this._get(a, 'clearText') + '</a></div>'); var h = '<div class="' + this._controlClass[f] + '">' + (e ? '' : g) + '<div class="' + this._closeClass[f] + '"><a href="javascript:void(0)" ' + 'onclick="jQuery.datepick._hideDatepick();"' + this._addStatus(f, c, a.id, this._get(a, 'closeStatus'), d) + '>' + this._get(a, 'closeText') + '</a></div>' + (e ? g : '') + '</div>'; var j = this._get(a, 'prompt'); var k = this._get(a, 'closeAtTop'); var l = this._get(a, 'hideIfNoPrevNext'); var m = this._get(a, 'navigationAsDateFormat'); var n = this._get(a, 'showBigPrevNext'); var o = this._getNumberOfMonths(a); var p = this._get(a, 'showCurrentAtPos'); var q = this._get(a, 'stepMonths'); var r = this._get(a, 'stepBigMonths'); var s = (o[0] != 1 || o[1] != 1); var t = this._getMinMaxDate(a, 'min', true); var u = this._getMinMaxDate(a, 'max'); var v = a.drawMonth - p; var w = a.drawYear; if (v < 0) { v += 12; w-- } if (u) { var x = this._daylightSavingAdjust(new Date(u.getFullYear(), u.getMonth() - (o[0] * o[1]) + 1, u.getDate())); x = (t && x < t ? t : x); while (this._daylightSavingAdjust(new Date(w, v, 1)) > x) { v--; if (v < 0) { v = 11; w-- } } } a.drawMonth = v + p; a.drawYear = w; if (a.drawMonth > 11) { a.drawMonth -= 12; a.drawYear++ } var y = this._get(a, 'prevText'); y = (!m ? y : this.formatDate(y, this._daylightSavingAdjust(new Date(w, v - q, 1)), this._getFormatConfig(a))); var z = (n ? this._get(a, 'prevBigText') : ''); z = (!m ? z : this.formatDate(z, this._daylightSavingAdjust(new Date(w, v - r, 1)), this._getFormatConfig(a))); var A = '<div class="' + this._prevClass[f] + '">' + (this._canAdjustMonth(a, -1, w, v) ? (n ? '<a href="javascript:void(0)" onclick="jQuery.datepick._adjustDate(\'#' + a.id + '\', -' + r + ', \'M\');"' + this._addStatus(f, c, a.id, this._get(a, 'prevBigStatus'), d) + '>' + z + '</a>' : '') + '<a href="javascript:void(0)" onclick="jQuery.datepick._adjustDate(\'#' + a.id + '\', -' + q + ', \'M\');"' + this._addStatus(f, c, a.id, this._get(a, 'prevStatus'), d) + '>' + y + '</a>' : (l ? '&#xa0;' : (n ? '<label>' + z + '</label>' : '') + '<label>' + y + '</label>')) + '</div>'; var B = this._get(a, 'nextText'); B = (!m ? B : this.formatDate(B, this._daylightSavingAdjust(new Date(w, v + q, 1)), this._getFormatConfig(a))); var C = (n ? this._get(a, 'nextBigText') : ''); C = (!m ? C : this.formatDate(C, this._daylightSavingAdjust(new Date(w, v + r, 1)), this._getFormatConfig(a))); var D = '<div class="' + this._nextClass[f] + '">' + (this._canAdjustMonth(a, +1, w, v) ? '<a href="javascript:void(0)" onclick="jQuery.datepick._adjustDate(\'#' + a.id + '\', +' + q + ', \'M\');"' + this._addStatus(f, c, a.id, this._get(a, 'nextStatus'), d) + '>' + B + '</a>' + (n ? '<a href="javascript:void(0)" onclick="jQuery.datepick._adjustDate(\'#' + a.id + '\', +' + r + ', \'M\');"' + this._addStatus(f, c, a.id, this._get(a, 'nextBigStatus'), d) + '>' + C + '</a>' : '') : (l ? '&#xa0;' : '<label>' + B + '</label>' + (n ? '<label>' + C + '</label>' : ''))) + '</div>'; var E = this._get(a, 'currentText'); var F = (this._get(a, 'gotoCurrent') && a.dates[0] ? a.dates[0] : b); E = (!m ? E : this.formatDate(E, F, this._getFormatConfig(a))); var G = (k && !a.inline ? h : '') + '<div class="' + this._linksClass[f] + '">' + (e ? D : A) + '<div class="' + this._currentClass[f] + '">' + (this._isInRange(a, F) ? '<a href="javascript:void(0)" onclick="jQuery.datepick._gotoToday(\'#' + a.id + '\');"' + this._addStatus(f, c, a.id, this._get(a, 'currentStatus'), d) + '>' + E + '</a>' : (l ? '&#xa0;' : '<label>' + E + '</label>')) + '</div>' + (e ? A : D) + '</div>' + (j ? '<div class="' + this._promptClass[f] + '"><span>' + j + '</span></div>' : ''); var H = parseInt(this._get(a, 'firstDay'), 10); H = (isNaN(H) ? 0 : H); var I = this._get(a, 'changeFirstDay'); var J = this._get(a, 'dayNames'); var K = this._get(a, 'dayNamesShort'); var L = this._get(a, 'dayNamesMin'); var M = this._get(a, 'monthNames'); var N = this._get(a, 'beforeShowDay'); var O = this._get(a, 'showOtherMonths'); var P = this._get(a, 'selectOtherMonths'); var Q = this._get(a, 'showWeeks'); var R = this._get(a, 'calculateWeek') || this.iso8601Week; var S = this._get(a, 'weekStatus'); var T = (c ? this._get(a, 'dayStatus') || d : ''); var U = this._get(a, 'statusForDate') || this.dateStatus; var V = this._getDefaultDate(a); for (var W = 0; W < o[0]; W++) { for (var X = 0; X < o[1]; X++) { var Y = this._daylightSavingAdjust(new Date(w, v, a.cursorDate.getDate())); G += '<div class="' + this._oneMonthClass[f] + (X == 0 && !f ? ' ' + this._newRowClass[f] : '') + '">' + this._generateMonthYearHeader(a, v, w, t, u, Y, W > 0 || X > 0, f, c, d, M) + '<table class="' + this._tableClass[f] + '" cellpadding="0" cellspacing="0"><thead>' + '<tr class="' + this._tableHeaderClass[f] + '">' + (Q ? '<th' + this._addStatus(f, c, a.id, S, d) + '>' + this._get(a, 'weekHeader') + '</th>' : ''); for (var Z = 0; Z < 7; Z++) { var bn = (Z + H) % 7; var bo = (!c || !I ? '' : T.replace(/DD/, J[bn]).replace(/D/, K[bn])); G += '<th' + ((Z + H + 6) % 7 < 5 ? '' : ' class="' + this._weekendClass[f] + '"') + '>' + (!I ? '<span' + this._addStatus(f, c, a.id, J[bn], d) : '<a href="javascript:void(0)" onclick="jQuery.datepick._changeFirstDay(\'#' + a.id + '\', ' + bn + ');"' + this._addStatus(f, c, a.id, bo, d)) + ' title="' + J[bn] + '">' + L[bn] + (I ? '</a>' : '</span>') + '</th>' } G += '</tr></thead><tbody>'; var bp = this._getDaysInMonth(w, v); if (w == a.cursorDate.getFullYear() && v == a.cursorDate.getMonth()) a.cursorDate.setDate(Math.min(a.cursorDate.getDate(), bp)); var bq = (this._getFirstDayOfMonth(w, v) - H + 7) % 7; var br = (s ? 6 : Math.ceil((bq + bp) / 7)); var bs = this._daylightSavingAdjust(new Date(w, v, 1 - bq)); for (var bt = 0; bt < br; bt++) { G += '<tr class="' + this._weekRowClass[f] + '">' + (Q ? '<td class="' + this._weekColClass[f] + '"' + this._addStatus(f, c, a.id, S, d) + '>' + R(bs) + '</td>' : ''); for (var Z = 0; Z < 7; Z++) { var bu = (N ? N.apply((a.input ? a.input[0] : null), [bs]) : [true, '']); var bv = (bs.getMonth() != v); var bw = (bv && !P) || !bu[0] || (t && bs < t) || (u && bs > u); var bx = (this._get(a, 'rangeSelect') && a.dates[0] && bs.getTime() >= a.dates[0].getTime() && bs.getTime() <= (a.dates[1] || a.dates[0]).getTime()); for (var i = 0; i < a.dates.length; i++) bx = bx || (a.dates[i] && bs.getTime() == a.dates[i].getTime()); var by = bv && !O; G += '<td class="' + this._dayClass[f] + ((Z + H + 6) % 7 >= 5 ? ' ' + this._weekendClass[f] : '') + (bv ? ' ' + this._otherMonthClass[f] : '') + ((bs.getTime() == Y.getTime() && v == a.cursorDate.getMonth() && a.keyEvent) || (V.getTime() == bs.getTime() && V.getTime() == Y.getTime()) ? ' ' + $.datepick._dayOverClass[f] : '') + (bw ? ' ' + this._unselectableClass[f] : ' ' + this._selectableClass[f]) + (by ? '' : ' ' + bu[1] + (bx ? ' ' + this._selectedClass[f] : '') + (bs.getTime() == b.getTime() ? ' ' + this._todayClass[f] : '')) + '"' + (!by && bu[2] ? ' title="' + bu[2] + '"' : '') + (bw ? '' : ' onmouseover="' + 'jQuery.datepick._doMouseOver(this,\'' + a.id + '\',' + bs.getTime() + ')"' + ' onmouseout="jQuery.datepick._doMouseOut(this,\'' + a.id + '\')"' + ' onclick="jQuery.datepick._selectDay(this,\'#' + a.id + '\',' + bs.getTime() + ')"') + '>' + (by ? '&#xa0;' : (bw ? bs.getDate() : '<a href="javascript:void(0)">' + bs.getDate() + '</a>')) + '</td>'; bs.setDate(bs.getDate() + 1); bs = this._daylightSavingAdjust(bs) } G += '</tr>' } v++; if (v > 11) { v = 0; w++ } G += '</tbody></table></div>' } if (f) G += '<div class="' + this._newRowClass[f] + '"></div>' } G += (c ? '<div style="clear: both;"></div><div id="' + this._statusId[f] + a.id + '" class="' + this._statusClass[f] + '">' + d + '</div>' : '') + (!k && !a.inline ? h : '') + '<div style="clear: both;"></div>' + ($.browser.msie && parseInt($.browser.version, 10) < 7 && !a.inline ? '<iframe src="javascript:false;" class="' + this._coverClass[f] + '"></iframe>' : ''); a.keyEvent = false; return G }, _generateMonthYearHeader: function(c, d, e, f, g, h, i, j, k, l, m) { var n = this._daylightSavingAdjust(new Date(e, d, 1)); f = (f && n < f ? n : f); var o = this._get(c, 'changeMonth'); var p = this._get(c, 'changeYear'); var q = this._get(c, 'showMonthAfterYear'); var r = '<div class="' + this._monthYearClass[j] + '">'; var s = ''; if (i || !o) s += '<span class="' + this._monthClass[j] + '">' + m[d] + '</span>'; else { var t = (f && f.getFullYear() == e); var u = (g && g.getFullYear() == e); s += '<select class="' + this._monthSelectClass[j] + '" ' + 'onchange="jQuery.datepick._selectMonthYear(\'#' + c.id + '\', this, \'M\');" ' + 'onclick="jQuery.datepick._clickMonthYear(\'#' + c.id + '\');"' + this._addStatus(j, k, c.id, this._get(c, 'monthStatus'), l) + '>'; for (var v = 0; v < 12; v++) { if ((!t || v >= f.getMonth()) && (!u || v <= g.getMonth())) s += '<option value="' + v + '"' + (v == d ? ' selected="selected"' : '') + '>' + m[v] + '</option>' } s += '</select>' } if (!q) r += s + (i || !o || !p ? '&#xa0;' : ''); if (i || !p) r += '<span class="' + this._yearClass[j] + '">' + e + '</span>'; else { var w = this._get(c, 'yearRange').split(':'); var x = new Date().getFullYear(); var y = function(a) { var b = (a.match(/c[+-].*/) ? e + parseInt(a.substring(1), 10) : (a.match(/[+-].*/) ? x + parseInt(a, 10) : parseInt(a, 10))); return (isNaN(b) ? x : b) }; var z = y(w[0]); var A = Math.max(z, y(w[1] || '')); z = (f ? Math.max(z, f.getFullYear()) : z); A = (g ? Math.min(A, g.getFullYear()) : A); r += '<select class="' + this._yearSelectClass[j] + '" ' + 'onchange="jQuery.datepick._selectMonthYear(\'#' + c.id + '\', this, \'Y\');" ' + 'onclick="jQuery.datepick._clickMonthYear(\'#' + c.id + '\');"' + this._addStatus(j, k, c.id, this._get(c, 'yearStatus'), l) + '>'; for (; z <= A; z++) { r += '<option value="' + z + '"' + (z == e ? ' selected="selected"' : '') + '>' + z + '</option>' } r += '</select>' } r += this._get(c, 'yearSuffix'); if (q) r += (i || !o || !p ? '&#xa0;' : '') + s; r += '</div>'; return r }, _addStatus: function(a, b, c, d, e) { return (b ? ' onmouseover="jQuery(\'#' + this._statusId[a] + c + '\').html(\'' + (d || e) + '\');" ' + 'onmouseout="jQuery(\'#' + this._statusId[a] + c + '\').html(\'' + e + '\');"' : '') }, _adjustInstDate: function(a, b, c) { var d = a.drawYear + '/' + a.drawMonth; var e = a.drawYear + (c == 'Y' ? b : 0); var f = a.drawMonth + (c == 'M' ? b : 0); var g = Math.min(a.cursorDate.getDate(), this._getDaysInMonth(e, f)) + (c == 'D' ? b : 0); a.cursorDate = this._restrictMinMax(a, this._daylightSavingAdjust(new Date(e, f, g))); a.drawMonth = a.cursorDate.getMonth(); a.drawYear = a.cursorDate.getFullYear(); if (d != a.drawYear + '/' + a.drawMonth) this._notifyChange(a) }, _restrictMinMax: function(a, b) { var c = this._getMinMaxDate(a, 'min', true); var d = this._getMinMaxDate(a, 'max'); b = (c && b < c ? new Date(c.getTime()) : b); b = (d && b > d ? new Date(d.getTime()) : b); return b }, _notifyChange: function(a) { var b = this._get(a, 'onChangeMonthYear'); if (b) b.apply((a.input ? a.input[0] : null), [a.cursorDate.getFullYear(), a.cursorDate.getMonth() + 1, this._daylightSavingAdjust(new Date(a.cursorDate.getFullYear(), a.cursorDate.getMonth(), 1)), a]) }, _getNumberOfMonths: function(a) { var b = this._get(a, 'numberOfMonths'); return (b == null ? [1, 1] : (typeof b == 'number' ? [1, b] : b)) }, _getMinMaxDate: function(a, b, c) { var d = this._determineDate(a, this._get(a, b + 'Date'), null); var e = this._getRangeMin(a); return (c && e && (!d || e > d) ? e : d) }, _getRangeMin: function(a) { return (this._get(a, 'rangeSelect') && a.dates[0] && !a.dates[1] ? a.dates[0] : null) }, _getDaysInMonth: function(a, b) { return 32 - new Date(a, b, 32).getDate() }, _getFirstDayOfMonth: function(a, b) { return new Date(a, b, 1).getDay() }, _canAdjustMonth: function(a, b, c, d) { var e = this._getNumberOfMonths(a); var f = this._daylightSavingAdjust(new Date(c, d + (b < 0 ? b : e[0] * e[1]), 1)); if (b < 0) f.setDate(this._getDaysInMonth(f.getFullYear(), f.getMonth())); return this._isInRange(a, f) }, _isInRange: function(a, b) { var c = this._getRangeMin(a) || this._getMinMaxDate(a, 'min'); var d = this._getMinMaxDate(a, 'max'); return ((!c || b >= c) && (!d || b <= d)) }, _getFormatConfig: function(a) { return { shortYearCutoff: this._get(a, 'shortYearCutoff'), dayNamesShort: this._get(a, 'dayNamesShort'), dayNames: this._get(a, 'dayNames'), monthNamesShort: this._get(a, 'monthNamesShort'), monthNames: this._get(a, 'monthNames')} }, _formatDate: function(a, b, c, d) { if (!b) a.dates[0] = new Date(a.cursorDate.getTime()); var e = (b ? (typeof b == 'object' ? b : this._daylightSavingAdjust(new Date(b, c, d))) : a.dates[0]); return this.formatDate(this._get(a, 'dateFormat'), e, this._getFormatConfig(a)) } }); function extendRemove(a, b) { $.extend(a, b); for (var c in b) if (b[c] == null || b[c] == undefined) a[c] = b[c]; return a }; function isArray(a) { return (a && a.constructor == Array) }; $.fn.datepick = function(a) { var b = Array.prototype.slice.call(arguments, 1); if (typeof a == 'string' && (a == 'isDisabled' || a == 'getDate' || a == 'settings')) return $.datepick['_' + a + 'Datepick'].apply($.datepick, [this[0]].concat(b)); if (a == 'option' && arguments.length == 2 && typeof arguments[1] == 'string') return $.datepick['_' + a + 'Datepick'].apply($.datepick, [this[0]].concat(b)); return this.each(function() { typeof a == 'string' ? $.datepick['_' + a + 'Datepick'].apply($.datepick, [this].concat(b)) : $.datepick._attachDatepick(this, a) }) }; $.datepick = new Datepick(); $(function() { $(document).mousedown($.datepick._checkExternalClick).find('body').append($.datepick.dpDiv) }) })(jQuery);

/* http://keith-wood.name/datepick.html
Datepicker Validation extension for jQuery 3.7.5.
Requires Jörn Zaefferer's Validation plugin (http://plugins.jquery.com/project/validate).
Written by Keith Wood (kbwood{at}iinet.com.au).
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
Please attribute the authors if you use it. */
(function($) { if ($.fn.validate) { $.datepick._selectDate2 = $.datepick._selectDate; $.extend($.datepick.regional[''], { validateDate: 'Please enter a valid date', validateDateMin: 'Please enter a date on or after {0}', validateDateMax: 'Please enter a date on or before {0}', validateDateMinMax: 'Please enter a date between {0} and {1}' }); $.extend($.datepick._defaults, $.datepick.regional['']); $.extend($.datepick, { _selectDate: function(a, b) { this._selectDate2(a, b); var c = this._getInst($(a)[0]); if (!c.inline && $.fn.validate) $(a).parents('form').validate().element(a) }, errorPlacement: function(a, b) { var c = b.next('.' + $.datepick._triggerClass); a.insertAfter(c.length > 0 ? c : b) }, errorFormat: function(a, b) { var c = ($.datepick._curInst ? $.datepick._get($.datepick._curInst, 'dateFormat') : $.datepick._defaults.dateFormat); $.each(b, function(i, v) { a = a.replace(new RegExp('\\{' + i + '\\}', 'g'), $.datepick.formatDate(c, v) || 'nothing') }); return a } }); function validateEach(a, b, c) { var d = $.datepick._getInst(b); var f = $.datepick._get(d, 'rangeSelect'); var g = $.datepick._get(d, 'multiSelect'); var h = (f ? a.split($.datepick._get(d, 'rangeSeparator')) : g ? a.split($.datepick._get(d, 'multiSeparator')) : [a]); var j = (f && h.length == 2) || (g && h.length <= g) || (!f && !g && h.length == 1); if (j) { try { var k = $.datepick._get(d, 'dateFormat'); var l = $.datepick._getFormatConfig(d); $.each(h, function(i, v) { h[i] = $.datepick.parseDate(k, v, l); j = j && c(h[i]) }) } catch (e) { j = false } } if (j && f) { j = (h[0].getTime() <= h[1].getTime()) } return j } $.validator.addMethod('dpDate', function(b, c) { return this.optional(c) || validateEach(b, c, function(a) { return true }) }, function(a) { return $.datepick._defaults.validateDate }); $.validator.addMethod('dpMinDate', function(b, c, d) { var e = $.datepick._getInst(c); d[0] = $.datepick._determineDate(e, $.datepick._get(e, 'minDate'), null); return this.optional(c) || validateEach(b, c, function(a) { return (!a || !d[0] || a >= d[0]) }) }, function(a) { return $.datepick.errorFormat($.datepick._defaults.validateDateMin, a) }); $.validator.addMethod('dpMaxDate', function(b, c, d) { var e = $.datepick._getInst(c); d[0] = $.datepick._determineDate(e, $.datepick._get(e, 'maxDate'), null); return this.optional(c) || validateEach(b, c, function(a) { return (!a || !d[0] || a <= d[0]) }) }, function(a) { return $.datepick.errorFormat($.datepick._defaults.validateDateMax, a) }); $.validator.addMethod('dpMinMaxDate', function(b, c, d) { var e = $.datepick._getInst(c); d[0] = $.datepick._determineDate(e, $.datepick._get(e, 'minDate'), null); d[1] = $.datepick._determineDate(e, $.datepick._get(e, 'maxDate'), null); return this.optional(c) || validateEach(b, c, function(a) { return (!a || ((!d[0] || a >= d[0]) && (!d[1] || a <= d[1]))) }) }, function(a) { return $.datepick.errorFormat($.datepick._defaults.validateDateMinMax, a) }) } })(jQuery);

function OpenPopupWin(url) {
    popupWindow = window.open(
		        url, '_blank', 'location=0,status=1,scrollbars=1,resizable=1, width=1000, height=600')
}
(function($) {
    $.formatCurrency = {}; $.formatCurrency.regions = []; $.formatCurrency.regions[""] = { symbol: "$", positiveFormat: "%s%n", negativeFormat: "(%s%n)", decimalSymbol: ".", digitGroupSymbol: ",", groupDigits: true };
    $.fn.formatCurrency = function(destination, settings) {
        if (arguments.length == 1 && typeof destination !== "string") {
            settings = destination; destination = false
        } var defaults = { name: "formatCurrency", colorize: false, region: "", global: true, roundToDecimalPlace: 2, eventOnDecimalsEntered: false }; defaults = $.extend(defaults, $.formatCurrency.regions[""]);
        settings = $.extend(defaults, settings); if (settings.region.length > 0) { settings = $.extend(settings, getRegionOrCulture(settings.region)) } settings.regex = generateRegex(settings);
        return this.each(function() {
            $this = $(this); var num = "0"; num = $this[$this.is("input, select, textarea") ? "val" : "html"](); if (num.search("\\(") >= 0) {
                num = "-" + num
            } if (num === "") { return } if (isNaN(num)) {
                num = num.replace(settings.regex, ""); if (num === "") { return } if (settings.decimalSymbol != ".") {
                    num = num.replace(settings.decimalSymbol, ".")
                } if (isNaN(num)) { num = "0" }
            } var numParts = String(num).split("."); var isPositive = (num == Math.abs(num)); var hasDecimals = (numParts.length > 1); var decimals = (hasDecimals ? numParts[1].toString() : "0");
            var originalDecimals = decimals; num = Math.abs(numParts[0]); if (settings.roundToDecimalPlace >= 0) {
                decimals = parseFloat("1." + decimals); decimals = decimals.toFixed(settings.roundToDecimalPlace);
                if (decimals.substring(0, 1) == "2") { num = Number(num) + 1 } decimals = decimals.substring(2)
            } num = String(num); if (settings.groupDigits) {
                for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3);
i++) { num = num.substring(0, num.length - (4 * i + 3)) + settings.digitGroupSymbol + num.substring(num.length - (4 * i + 3)) }
            } if ((hasDecimals && settings.roundToDecimalPlace == -1) || settings.roundToDecimalPlace > 0) {
                num += settings.decimalSymbol + decimals
            } var format = isPositive ? settings.positiveFormat : settings.negativeFormat; var money = format.replace(/%s/g, settings.symbol); money = money.replace(/%n/g, num);
            var $destination = $([]); if (!destination) { $destination = $this } else { $destination = $(destination) } $destination[$destination.is("input, select, textarea") ? "val" : "html"](money);
            if (hasDecimals && settings.eventOnDecimalsEntered) { $destination.trigger("decimalsEntered", originalDecimals) } if (settings.colorize) {
                $destination.css("color", isPositive ? "black" : "red")
            }
        })
    }; $.fn.toNumber = function(settings) {
        var defaults = $.extend({ name: "toNumber", region: "", global: true }, $.formatCurrency.regions[""]); settings = jQuery.extend(defaults, settings);
        if (settings.region.length > 0) { settings = $.extend(settings, getRegionOrCulture(settings.region)) } settings.regex = generateRegex(settings); return this.each(function() {
            var method = $(this).is("input, select, textarea") ? "val" : "html";
            $(this)[method]($(this)[method]().replace("(", "(-").replace(settings.regex, ""))
        })
    }; $.fn.asNumber = function(settings) {
        var defaults = $.extend({ name: "asNumber", region: "", parse: true, parseType: "Float", global: true }, $.formatCurrency.regions[""]);
        settings = jQuery.extend(defaults, settings); if (settings.region.length > 0) { settings = $.extend(settings, getRegionOrCulture(settings.region)) } settings.regex = generateRegex(settings);
        settings.parseType = validateParseType(settings.parseType); var method = $(this).is("input, select, textarea") ? "val" : "html"; var num = $(this)[method]();
        num = num ? num : ""; num = num.replace("(", "(-"); num = num.replace(settings.regex, ""); if (!settings.parse) { return num } if (num.length == 0) { num = "0" } if (settings.decimalSymbol != ".") {
            num = num.replace(settings.decimalSymbol, ".")
        } return window["parse" + settings.parseType](num)
    }; function getRegionOrCulture(region) {
        var regionInfo = $.formatCurrency.regions[region]; if (regionInfo) {
            return regionInfo
        } else { if (/(\w+)-(\w+)/g.test(region)) { var culture = region.replace(/(\w+)-(\w+)/g, "$1"); return $.formatCurrency.regions[culture] } } return null
    } function validateParseType(parseType) {
        switch (parseType.toLowerCase()) {
            case "int": return "Int";
            case "float": return "Float"; default: throw "invalid parseType"
        }
    } function generateRegex(settings) {
        if (settings.symbol === "") {
            return new RegExp("[^\\d" + settings.decimalSymbol + "-]", "g")
        } else { var symbol = settings.symbol.replace("$", "\\$").replace(".", "\\."); return new RegExp(symbol + "|[^\\d" + settings.decimalSymbol + "-]", "g") }
    }
})(jQuery);
(function($) {
    $.fn.showBusy = function() {        
        $(this).show();
    }    
})(jQuery);
(function($) {
    $.fn.hideBusy = function() {
        $(this).hide()
    }
})(jQuery);
