﻿Function.prototype.Inherits = function(sc) {function f_ghost() {};f_ghost.prototype=sc.prototype;this.prototype=new f_ghost();this.prototype.constructor=this;this.__sc=sc;this.prototype.base = function() {var c=arguments[0];var a=new Array();for (var i=1;i<arguments.length;i++) {a.push(arguments[i]);} var cC = this.constructor;var mN=null;while((mN==null)&&(cC!=null)) {if(c===cC) return cC.__sc.apply(this,a);mN=fig_m_N(cC.prototype,c);cC=cC.__sc;} if(!mN) throw new Error("Could not find method: " + mN + ".");if(!cC) throw new Error("Prototype does not have an ancestor: "+ cC + ".");return cC.prototype[mN].apply(this, a);};function fig_m_N(p, m) {for (var k in p) {if (p.hasOwnProperty(k)&&(p[k]===m)) return k;} return null;}}
Iteration=function() {this.Cancel=false;}
Array.prototype.FindIndexByValue=function(v) {for(var x=0;x<this.length;x++) {if(v==this[x]) {return x;break;}} return -1;}
Array.prototype.ForEach=function(h) {var it=new Iteration();var _x=0;while(_x<this.length) {if(it.Cancel) {break;} else {h(it,_x,this[_x]); _x++;}}}

Number.prototype.InRange=function(sR,eR,exc) {if((typeof(sR)!="number")||(typeof(eR)!="number")||(sR>eR)) return false;var c=(exc && (this>sR))?true:(!exc && (this>=sR))?true:false;if (!c) return false;var c=(exc && (this<eR))?true:(!exc && (this<=eR))?true:false;if (!c) return false;return true;};Number.prototype.IsUShort=function() {if((this<0)||(this>65535)) return false;return true;};Number.prototype.IsShort=function() {if((this<-32768)||(this>32767)) return false;return true;};Number.prototype.IsInt=function() {if((this<-2147483648)||(this>2147483647)) return false;return true;};
Number.prototype.ForEach=function(h,i,inc) {if(!IsFunc(h)) return void(0);var _inc=1;var _i=0;var _l=0;var _it=new Iteration();if(IsNumber(i) && i<=this) _i=i;if(IsNumber(inc)) _inc=inc;while(_i<=this) {if(!_it.Cancel) {h(_it,_i);_i+=_inc;} else break;}};
String.prototype.Trim = function() {return this.replace(/^\s+|\s+$/g,"");};
String.prototype.LTrim = function() {return this.replace(/^\s+/,"");};
String.prototype.RTrim = function() {return this.replace(/\s+$/,"");};
IsNull=function(ex) {if((ex==null)||(ex==window.undefined)) return true;return false;};
IsBool=function(ex,v) {if(typeof(ex)=="boolean") {if(typeof(v)=="boolean") {if(v==ex) return true;return false;} return true;}return false;};
INES=function(ex) {if((typeof(ex)!="string")||(ex.length<=0)) return true;return false;}
IsNumber=function(ex) {if(typeof(ex)=="number") return true;return false;};IsShort=function(ex) {if(ex && ex.IsShort) return ex.IsShort();return false;};IsUShort=function(ex) {if(ex && ex.IsUShort) return ex.IsUShort();return false;};
InRange=function(ex,sR,eR,exc) {if(ex && ex.InRange) return ex.InRange(sR,eR,exc); else return false;};
IsInt=function(ex) {if(ex && ex.IsInt) return ex.IsInt();return false;};
IsFunc=function(ex) {if(typeof(ex)=="function") return true;return false;};
function addListener(el, evType, handle){if(el.addEventListener)el.addEventListener(evType,handle,false);else if(el.attachEvent){el["e"+evType+handle]=handle;el[evType+handle]=function(){el["e"+evType+handle](window.event)};el.attachEvent("on" + evType, el[evType + handle]);};};
function removeListener(el,evType,handle){if(el.removeEventListener)el.removeEventListener(evType, handle, false);else if(el.detachEvent){el.detachEvent("on"+evType,el[evType+handle]);el[evType+handle]=null;el["e"+evType+handle]=null;};};
if(!window.XMLHttpRequest){var _iepid=null;XMLHttpRequest = function() {if(!_iepid){var _iepidt=["Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];for (var x=0;x<_iepidt.length;x++) {if (INES(_iepid)) {try {var ieo=new ActiveXObject(_iepidt[x]);_iepid=_iepidt[x];} catch(exception) {};}}}return new ActiveXObject(_iepid);}};
ProcessEvent=function() {function EHD() {var _h=new Array();this.GetHandlers=function() {return _h;};this.AddHandler=function(h,o) {if ((o!=null)&&!INES(h)) _h[_h.length]=[h,o];else if(typeof(h)=="function") _h[_h.length]=[h,o];};this.Clear=function() {_h.length = 0;};this.RemoveHandler=function(h,o) {if ((o!=null)&&!INES(h)) {var th=new Array();for (var x=0;x<_h.length;x++) {if((_h[x][1]!== o)||(_h[x][0]!== f)) th[x]=_h[x];};_h=th;} else if(typeof(h)=="function") {var th=new Array();for (var x=0;x<_h.length;x++) {if(_h[x][0].toString()!=h.toString()) th[x]=_h[x];};_h=th;}}};function ExecH(h,s,a) {for(var x=0;x<h.length;x++) {var r=null;if(h[x][1]!=null) r=h[x][1][h[x][0]](s,a);else r=h[x][0](s,a);if(IsBool(r) && !r) return false;} return true;};this.IsEmpty=function() {if(_h.length<=0) return true;return false;};this.PrivateHandlers=new EHD();this.Handlers=new EHD();this.Raise=function(s,a) {if(s==null) return false;var pr=ExecH(this.PrivateHandlers.GetHandlers(),s,a);if(IsBool(pr) && !pr) return false;return ExecH(this.Handlers.GetHandlers(),s,a);}};


var ClientScriptFolderPath = "/clientScripting";
System = function() {
    var _as=new Object();
    var _q=new Array();
    var _aP = ClientScriptFolderPath;
    if(_aP.charAt(_aP.length-1) != "/") _aP += "/";
    function RDFQA(aN) {
        for (var x=0;x<_q.length;x++) {            
            var assemblyInQueue = _q[x];
            assemblyInQueue.TryRemoveDependency(aN); 
            if (!assemblyInQueue.HasDependencies) {
                ActivateAssembly(assemblyInQueue);
            }
        }
    }
    function RemoveQueuedAssembly(assembly) {
        var tempQueue = new Array();
        for(var x=0;x<_q.length;x++) {
            if (_q[x].Name != assembly.Name) tempQueue[tempQueue.length] = _q[x];
        }
        _q = tempQueue;
    }
    function ActivateAssembly(assembly) {        
        RemoveQueuedAssembly(assembly);
        eval(assembly.Code);
        _as[assembly.Name] = 1;
        RDFQA(assembly.Name);
    }
    function Assembly(name,code) 
    {
        if (INES(name)) return null;
        if (INES(code)) return null;        
        this.Name = name;
        this.Code = code;
        var dependencies = new Array();
        this.HasDependencies = false;
        this.IsDependentOf = function(aN) {
            for(var x=0;x<dependencies.length;x++) {
                if (dependencies[x].toLowerCase() == aN.toLowerCase()) return true;
            }
            return false;
        }
        this.TryRemoveDependency = function(aN) {
            var tempDependencies = new Array();
            for(var x=0;x<dependencies.length;x++) {
                if (dependencies[x].toLowerCase() != aN.toLowerCase()) {
                    tempDependencies[tempDependencies.length] = dependencies[x];
                }
            }
            dependencies = tempDependencies;
            if (dependencies.length == 0) this.HasDependencies = false;
            return dependencies.length;
        }
        this.AddDependency = function(aN) {
            if(!this.IsDependentOf(aN)) dependencies[dependencies.length] = aN;
        }
        //process code to find dependencies
        if (this.Code.indexOf("Using(") > -1) {
            var matchArray = this.Code.match(/(Using\("(([\w|\.])+)"\);)/g);
            if ((matchArray != null) && (matchArray.length > 0)) {
                for (var x=0;x<matchArray.length;x++) {
                    this.Code = this.Code.replace(matchArray[x],"");
                    var dependencyName = matchArray[x].match(/"([\w|\.]+)"/);
                    if (dependencyName != null) dependencyName = dependencyName[1];
                    var status = _as[dependencyName];
                    if (status != 1) {
                        this.AddDependency(dependencyName);
                        this.HasDependencies = true;
                        if ((status == window.undefined) || (status == null)) {
                            Using(dependencyName);
                        }
                    }
                }
            }
        }
        ActivateAssembly(this);
    }
    this.DeclareClass = function(classToDeclare,alias) {
        if (classToDeclare == null) alert("Cannot declare a null class");
        else if ((window[alias] != null) || (window[alias]!=window.undefined)) alert("A class is already declare with this alias");
        else {
            window[alias] = classToDeclare;
            return true;
        }
        return false;
    }
    
    this.LoadAssembly = function(aN,alias) {
        if (INES(aN)) return 0;
        //Check aNspace validity.
        if (_as[aN] != null) {
            alert("already exist");
            return null;
        }
        var assemblyFound = false;
        var assemblyPath = _aP + aN+".js";
        var AjaxProvider = new XMLHttpRequest();
        var isLoaded = false;
        if (AjaxProvider != null) {
            AjaxProvider.open("GET",assemblyPath,false);
            AjaxProvider.send(null);
            if (!INES(AjaxProvider.responseText)) {                
                _as[aN] = 0;
                isLoaded = true;
                var assembly = new Assembly(aN,AjaxProvider.responseText);
            }
        }
    }
}
System = new System();
Using = System.LoadAssembly;
Declare = System.DeclareClass;
C2={};


