﻿
/***************************************************************
 *   Create By lion                                            *
 *   2005-08-29 11:54                                          *
 *   Copyright (C) 1998-2005 www.csdn.net All rights reserved. *
 *   Web: http://www.lionsky.net    http://www.csdn.net        *
 *   Email: lion-a@sohu.com                                    *
 ***************************************************************/
 
/*
ActiveXObject
*/
if(window.ActiveXObject && !window.XMLHttpRequest)
{    
    window.XMLHttpRequest = function()
    {
        var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	    var o;
	    for (var i = 0; i < prefixes.length; i++) 
	    {
		    try 
		    {
			    // try to create the objects
			    o = new ActiveXObject(prefixes[i] + ".XmlHttp");
			    return o;
		    }
		    catch (ex) {};
	    }
        throw new Error("Could not find an installed XML parser or Your browser does not support XmlHttp objects");
    }
}

var System=function(){return new System.getContainer('System')};
System.codebase=new Object();
try
{
    if (window!=parent && parent.System && parent.System.codebase)
    {
        System.codebase = parent.System.codebase;
    }
    else if (typeof opener!="undefined" && opener.System && opener.System.codebase)
    {
        System.codebase = opener.System.codebase;
    }
    else if (typeof dialogArguments!="undefined" && dialogArguments.System)
    {
        System.codebase = dialogArguments.System.codebase;
    }
}
catch(ex){}

System.author="lion";
System.version="20050227";
System.currentVersion="20060225";
System.hashCodePrefix="lionsky";
System.hashCodeCounter=0;

System.window=window; 

var t=document.getElementsByTagName("SCRIPT");

t=(System.scriptElement=t[t.length-1]).src.replace(/\\/g, "/");

System.path=(t.lastIndexOf("/")<0)?".":t.substring(0, t.lastIndexOf("/"));

System.supportsXmlHttp=function()
{
    return typeof(System.xmlHttp||(System.xmlHttp=new XMLHttpRequest()))=="object";
};

System.getContainer=function(namespace)
{
    return typeof(System.container[namespace])=="undefined" ?new Object:new System.container[namespace];
};

System.ie = window.navigator.userAgent.indexOf("MSIE")>0 && !window.opera;

System.alert=function(msg){alert(msg);}

System.load = function(namespace, path)
{
    var ex;
    try
    {
        if(System.supportsXmlHttp())
        {
            path=System.buildPath(namespace, path);
            System.xmlHttp.open("GET",path,false);
            System.xmlHttp.send(null);
            if (System.xmlHttp.readyState==4)
            {
                var jscode = System.xmlHttp.responseText;
                if (jscode==null || jscode.charAt(0)=="\uFFFD")
                {
                    System.alert("Maybe encoding of "+path+" file isn't ANSI or UTF-8!");return "";
                }
                if (jscode.charAt(0)=="\xef")
                {
                    jscode=jscode.substr(3); //for firefox
                }
                return jscode.replace(/(^|\n)\/\/+\s*((Using\(|Import\(|Include\()(\"|\')System\.)/g,"$1$2");
            }
        } 
        else
        {
            System.alert("Your browser don't support XMLHttp!");
        }
    }
    catch(ex)
    {
        System.alert("Error!\nmaybe "+path+" is inexistent!");return "";
    }
};


System.eval = function(namespace, path)
{
  //alert("System.eval(\""+ namespace +"\") = \r\n"+ System.codebase[namespace]);
    try
    {
        if(window.execScript)
        {
            window.execScript(System.codebase[namespace]); 
        }
        else        
        {
            var script=document.createElement("SCRIPT"); 
            script.type="text/javascript";
            script.innerHTML="eval(System.codebase['"+ namespace +"']);";
            var id = script.id = System.hashCodePrefix+System.hashCodeCounter++;
            document.getElementsByTagName("HEAD")[0].appendChild(script);
            setTimeout("t=document.getElementById('"+id+"');t.parentNode.removeChild(t)",1);
        }
    }
    catch(ex)
    {
        System.alert("Syntax error on load "+ namespace +"!");
    }
    System.classLoaded[namespace]=System.buildPath(namespace, path);
};
//判断是否已经载入命名空间所使用的路径缓存
System.classLoadedControl = function(namespace, path)
{
    if(typeof System.classLoaded[namespace]=="undefined")
    {
        return false;
    }
    return System.classLoaded[namespace]==System.buildPath(namespace,path);
};
System.buildPath = function(namespace, path)
{
    if(typeof path=="string" && path.length>0)
    {
        return path.toLowerCase();
    }
    var p = (System.path+"/"+namespace.substr(7).replace(/\./g,"/")+".js").toLowerCase();
    if(typeof path=="undefined")
    {
        return p; 
    }
    return p +"?temp="+ Math.random();
};

window.Using = function(namespace, path)
{
    if(namespace.indexOf("System.")!=0)
    {
        throw namespace+" isn't standard namespace!";
    }
    //判断是否已经载入命名空间所使用的路径缓存
    
    if(System.classLoadedControl(namespace, path))
    {
        return; 
    }
    var code=namespace +".";
    for(var i=code.indexOf("."); i>-1; i=code.indexOf(".", i+1))
    {
        var e = code.substring(0, i); 
        if(e&&typeof eval(e)=="undefined")
        {
            eval(e + "=function(){return new System.getContainer('"+ e +"')}");
        }
    }
    if(typeof path=="undefined" && typeof System.codebase[namespace]=="string")
    {
        System.eval(namespace, path);
    }
    else
    {
        if (code=System.load(namespace, path))
        {
            e = "$"+System.hashCodePrefix+"__id"+ new Date().getTime() +"$";
            var s="function "+e+"(){\r\n"+code+";\r\nSystem.container['";
            code=namespace.substr(namespace.lastIndexOf(".")+1);
            s += namespace +"']=window['"+ code +"']="+ code +";\r\n}"+e+"();";
            System.codebase[namespace]=s;s="";
            System.eval(namespace, path);
        }
    }
};
window.Import = function(namespace, path){Using(namespace, path)}

window.Instance = function(className)
{
    return System.instances[className];
}

window.Include = function(namespace, path)
{
    if(namespace.indexOf("System.")!=0)
    {
        throw namespace +" isn't standard namespace!";
    }
    if(System.classLoadedControl(namespace, path))
    {
        return;
    }
    var code;
    if(typeof path=="undefined" && typeof System.codebase[namespace]=="string")
    {
        System.eval(namespace, path);
    }
    else if(System.supportsXmlHttp())
    {
        if(code=System.load(namespace, path))
        {
            System.codebase[namespace]=code;
            System.eval(namespace, path);
        }
    }
    else
    {
        var script=document.createElement("SCRIPT");
        script.type="text/javascript"; 
        script.language="javascript";
        script.src=System.classLoaded[namespace]=System.buildPath(namespace,path);
        var id=script.id=System.hashCodePrefix+System.hashCodeCounter++;
        document.getElementsByTagName("HEAD")[0].appendChild(script);
        setTimeout("t=document.getElementById('"+id+"');t.parentNode.removeChild(t)",1);
    }
};

Function.prototype.Extends=function(SuperClass,ClassName)
{
    var p=this.prototype=new SuperClass();
    if(ClassName)
    {
        p.className=ClassName;
    }
    return p;
};
System.Object = function(){};
System.container=new Object();
System.container.System = System.Object;
System.container.System.Object = System.Objec;
System.instances=new Object();
System.classLoaded=new Object();
System.classLoaded["System"]=System.buildPath("System");
/*System.classLoaded["System.Object"]=System.buildPath("System.Object");

System.Object.prototype.Extends(Object, "System.Object").getHashCode=function()
{
    if(!this.hashCode)
    {
        this.hashCode=System.hashCodePrefix+System.hashCodeCounter++;
    }
    System.instances[this.hashCode]=this;
    return this.hashCode;
};
System.Object.prototype.equals=function(class1, class2)
{
    return typeof(class1.hashCode)!="undefined"&& typeof(class2.hashCode)!="undefined"&& class1.hashCode==class2.hashCode;
};
System.Object.prototype.toString = function()
{
    return "[object "+ (this.className || "Object") +"]";
};


if (window.opera)
{
    Include("System.Plugins.Opera"); //Opera support
}
if(System.ie)
{
    Include("System.Plugins.IE");
}
*/
Include("System.Global");

/*
for(t in System.codebase) alert( t +" = "+ System.codebase[t]);
*/
