﻿

$(function() {
    $('.collapsable-area-header').each(function() {
        $(this).prepend('<span></span>');
        $(this).click(function() {
            $(this).find('span').toggleClass('collapse-arrow-close');
            $(this).next().toggle('fast');
            return false;
        });
    });
});

function EnterKeyEvent(clientId, e) {
    var evtobj = window.event ? event : e;
    var keycode = evtobj.keyCode ? evtobj.keyCode : evtobj.charCode;
    if (keycode == 13) {
        $('#' + clientId).click();
        evtobj.returnValue = false;
    }
}

function ClearOnFocus(clientId, text) {
    $control = $('#' + clientId)
    if ($control.val() == text) {
        $control.val('');
    }
}

function ClearOnBlur(clientId, text) {
    $control = $('#' + clientId);
    if ($control.val() == '' || $control.val() == text) {
        $control.val(text);
    }
}

function parseJSONDates(v) {
    if (v != null) {
        if (v.constructor == String) {
            if (v.startsWith('/Date')) {
                v = new Date(parseInt(v.replace(/\/Date\((-?\d+)\)\//gi, "$1")));
            }
        }
        else if (v.constructor == Object || v.constructor == Array) {
            $.each(v, function(k, x) {
                v[k] = k != "__type" ? parseJSONDates(x) : x;
            });
        }
    }
    return v;
};


$.strPadLeft = function(i, l, s) {
    var o = i.toString();
    if (!s) { s = '0'; }
    while (o.length < l) {
        o = s + o;
    }
    return o;
};
$.strPadRight = function(i, l, s) {
    var o = i.toString();
    if (!s) { s = '0'; }
    while (o.length < l) {
        o = o + s;
    }
    return o;
};

String.prototype.trim = function() {
    return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}

String.prototype.startsWith = function(str) {
    return (this.match("^" + str) == str);
}

String.prototype.endsWith = function(str) {
    return (this.match(str + "$") == str);
}


