/*
Copyright (c) 2005 JSON.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The Software shall be used for Good, not Evil.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/*
    The global object JSON contains two methods.

    JSON.stringify(value) takes a JavaScript value and produces a JSON text.
    The value must not be cyclical.

    JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
    return false if there is an error.
*/
var JSON = function () {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            'boolean': function (x) {
                return String(x);
            },
            number: function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            string: function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            },
            object: function (x) {
                if (x) {
                    var a = [], b, f, i, l, v;
                    if (x instanceof Array) {
                        a[0] = '[';
                        l = x.length;
                        for (i = 0; i < l; i += 1) {
                            v = x[i];
                            f = s[typeof v];
                            if (f) {
                                v = f(v);
                                if (typeof v == 'string') {
                                    if (b) {
                                        a[a.length] = ',';
                                    }
                                    a[a.length] = v;
                                    b = true;
                                }
                            }
                        }
                        a[a.length] = ']';
                    } else if (x instanceof Object) {
                        a[0] = '{';
                        for (i in x) {
                            v = x[i];
                            f = s[typeof v];
                            if (f) {
                                v = f(v);
                                if (typeof v == 'string') {
                                    if (b) {
                                        a[a.length] = ',';
                                    }
                                    a.push(s.string(i), ':', v);
                                    b = true;
                                }
                            }
                        }
                        a[a.length] = '}';
                    } else {
                        return;
                    }
                    return a.join('');
                }
                return 'null';
            }
        };
    return {
        copyright: '(c)2005 JSON.org',
        license: 'http://www.JSON.org/license.html',
/*
    Stringify a JavaScript value, producing a JSON text.
*/
        stringify: function (v) {
            var f = s[typeof v];
            if (f) {
                v = f(v);
                if (typeof v == 'string') {
                    return v;
                }
            }
            return null;
        },
/*
    Parse a JSON text, producing a JavaScript value.
    It returns false if there is a syntax error.
*/
        parse: function (text) {
            try {
                return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                        text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
                    eval('(' + text + ')');
            } catch (e) {
                return false;
            }
        }
    };
} ();




/*Base Nokair Script*/

String.prototype.format = function () {
    var s = this,
i = arguments.length;

    while (i--) {
        s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
    }
    return s;
};

String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); }

var Word = {
    SysFailed: { Title: 'Service unavailable', Msg: 'Sorry , service unavailable.Please try again.' }
}

$(document).ready(function () {

    if (typeof (application_start) == "function") {
        application_start();
    }
});

//function scollToId(id) {
//    window.scrollTo(0, $("#" + id).offset().top);
//}
function scollToId(id) {
    if ($("#" + id).length == 0) return;
    $('html,body').animate({ scrollTop: $("#" + id).offset().top }, 'slow');
}


var ComBoBox = {
    clearList: function (id) {
        $('#' + id).html('');
    },
    addOptions: function (options, id) {
        for (var i; i < options.length; i++) {
            "<option value='{0}'>{1}</option>".format(options[i].value, options[i].text).appendTo('#' + id);
        }
    },
    addOption: function (value, text, id) {
        $("<option value='{0}'>{1}</option>".format(value, text)).appendTo('#' + id);
    }

}

var MathManager = {
    addCommas: function (nStr) {
        nStr = nStr.toFixed(2);
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }
}







var _SPACE_ = 32;
var _TAB1_ = 8;
var _TAB2_ = 0;

/**
* input validation
*
*
*/
function _a(e) {
    var keynum;
    var keychar;
    var numcheck;
    if (window.event) /* IE*/
    {
        keynum = e.keyCode;
    }
    else if (e.which || e.which == 0) /* Netscape/Firefox/Opera*/
    {
        if (e.keyCode) {
            return true;
        }
        keynum = e.which;
    }

    return (keynum == _SPACE_ || _t(e) || _n(e) || _e(e));
}

/*extra signs*/
function _e(e) {
    var keynum;
    var keychar;
    var numcheck;
    if (window.event) /* IE*/
    {
        keynum = e.keyCode;
    }
    else if (e.which || e.which == 0) /* Netscape/Firefox/Opera*/
    {
        if (e.keyCode) {
            return true;
        }
        keynum = e.which;
    }
    return (8 == keynum || (33 <= keynum && keynum <= 47) || (58 <= keynum && keynum <= 62));
}

/*text for payment name*/
function _tpm(e) {
    var keynum;
    var keychar;
    var numcheck;

    if (window.event) /* IE*/
    {
        keynum = e.keyCode;
    }
    else if (e.which || e.which == 0) /* Netscape/Firefox/Opera*/
    {
        if (e.keyCode) {/*none char key.*/
            return true;
        }
        keynum = e.which;
    }

    return (_TAB1_ == keynum || _TAB2_ == keynum || _SPACE_ == keynum || (65 <= keynum && keynum <= 90) || (97 <= keynum && keynum <= 122));
}

/*only character*/
function _t(e) {
    var keynum;
    var keychar;
    var numcheck;
    if (window.event) /* IE*/
    {
        keynum = e.keyCode;
        e.keyCode = String.fromCharCode(keynum).toUpperCase().charCodeAt();
    }
    else if (e.which || e.which == 0) /* Netscape/Firefox/Opera*/
    {
        if (e.keyCode) {
            keynum = e.keyCode;
            e.keyCode = String.fromCharCode(keynum).toUpperCase().charCodeAt();
            return true;
        }
        keynum = e.which;
    }
    return (8 == keynum || (65 <= keynum && keynum <= 90) || (97 <= keynum && keynum <= 122));
}

/**
* text & numeric only
*/
function _tn(e) {
    var keynum;
    var keychar;
    var numcheck;

    if (window.event) /* IE*/
    {
        keynum = e.keyCode;
    }
    else if (e.which || e.which == 0) /* Netscape/Firefox/Opera*/
    {
        if (e.keyCode) {
            return true;
        }
        keynum = e.which;
    }


    return (8 == keynum || 32 == keynum || (48 <= keynum && keynum <= 57) || (65 <= keynum && keynum <= 90) || (97 <= keynum && keynum <= 122));
}


/**
* numeric only
*/
function _n(e) {
    var keynum;
    var keychar;
    var numcheck;

    if (window.event) /* IE*/
    {
        keynum = e.keyCode;
    }
    else if (e.which || e.which == 0) /* Netscape/Firefox/Opera*/
    {
        if (e.keyCode) {
            return true;
        }
        keynum = e.which;
    }


    return (8 == keynum || (48 <= keynum && keynum <= 57));
}

/**
*
*/
function _keyNum(e) {
    var keynum;

    if (window.event) /* IE*/
    {
        keynum = e.keyCode;
    }
    else if (e.which || e.which == 0) /* Netscape/Firefox/Opera*/
    {
        if (e.keyCode) {
            return true;
        }
        keynum = e.which;
    }

    return keynum;
}


var DateDiff = {
    inMinute: function (date1, date2) {
        var result = date1.getTime() - date2.getTime();
        var oneMinute = 1000 * 60;
        return result / oneMinute;
    },


    inDays: function (d1, d2) {
        var t2 = d2.getTime();
        var t1 = d1.getTime();

        return parseInt((t2 - t1) / (24 * 3600 * 1000));
    },

    inWeeks: function (d1, d2) {
        var t2 = d2.getTime();
        var t1 = d1.getTime();

        return parseInt((t2 - t1) / (24 * 3600 * 1000 * 7));
    },

    inMonths: function (d1, d2) {
        var d1Y = d1.getFullYear();
        var d2Y = d2.getFullYear();
        var d1M = d1.getMonth();
        var d2M = d2.getMonth();

        return (d2M + 12 * d2Y) - (d1M + 12 * d1Y);
    },

    inYears: function (d1, d2) {
        return d2.getFullYear() - d1.getFullYear();
    }
}

/**
*DREAM generated script
*/
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
