﻿if (!window.agahSystems) {
    window.agahSystems = new Object();
}

String.prototype.replaceAll = function(s1, s2) {
    if (s1 == null)
        return this;
    if (s1.length == 0)
        return this;
    if (s2 == null)
        s2 = '';

    //            
    var remained = this;
    var result = "";
    while (true) {
        var pos = remained.indexOf(s1);
        if (pos < 0)
            break;

        if (pos > 0) {
            result = result + remained.substr(0, pos);
        }
        result = result + s2;

        pos = pos + s1.length;
        if (pos >= remained.length) {
            remained = "";
            break;
        }
        remained = remained.substr(pos);
    }

    //
    result = result + remained;

    return (result);
}


$.fn.bindUp = function(type, fn) {

    type = type.split(/\s+/);

    this.each(function() {
        var len = type.length;
        while (len--) {
            $(this).bind(type[len], fn);

            var evt = $.data(this, 'events')[type[len]];
            evt.splice(0, 0, evt.pop());
        }
    });
};



function agahSystems_autoFillHtmlControls() {
    if (typeof (CKEDITOR) != "undefined") {
        if (typeof (CKEDITOR.instances) != "undefined") {
            for (instance in CKEDITOR.instances) {
                if (document.getElementById(instance)) {
                    document.getElementById(instance).value = CKEDITOR.instances[instance].getData();                    
                }
            }
        }
    }
}



