﻿/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    DICITI三维控件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

var ___begin___,

	TRUE = 1,FALSE = 0,
    IM_ALL_USER_ID = -1,	//“所有人”的ID
    IM_SYSTEM_MESSAGE = -2,	//系统消息
	
	EMBED_FRAME_ID = "__embed_frame",
	EMBED_WINDOW_ID = "__embed_window",
    
    //常用字符串
    TXT_NEED_UPDATE_DIRECTX_CH = "本系统需要DirextX8.0以上的版本支持，由于您的系统中的DirextX版本太低，所以需要更新DirectX才能正常浏览!",
    TXT_NEED_UPDATE_DIRECTX_EN = "You need to update the DirextX version which has to be greater than 8.0!",
    TXT_UPDATE_FILE_FAILED_CH = "文件更新失败!",
    TXT_UPDATE_FILE_FAILED_EN = "Update file failed!",
    TXT_INSTANCE_EXIST_CH = "你已经在另外一个标签页窗口中打开了相同的页面， 为了不影响系统性能，该页面将不再显示三维窗口，请切换到已经打开的页面浏览。",
    TXT_INSTANCE_EXIST_EN = "You have opened the same page in another tab,it won't diplay 3 dimensions page for the system performace,please go back to that tab to check out! ",
    TXT_ENV_NOT_SUPPORT_CH = "检测到您的系统环境不支持本软件的运行",
    TXT_ENV_NOT_SUPPORT_EN = "It doesn't work in your system environment",
    TXT_BROWSER_NOT_SUPPORT_CH = "暂时只支持IE内核的浏览器",
    TXT_BROWSER_NOT_SUPPORT_EN = "It can work in the browsers which has IE core",
    TXT_MEMORY_NOT_ENOUGH_CH = "您的系统内存太低，至少需要512MB的内存",
    TXT_MEMORY_NOT_ENOUGH_EN = "The memory should be greater than 512MB",
    TXT_MEMORY_CONFIRM_CH = "您的计算机内存过低，继续运行可能会导致错误。是否继续运行？",
    TXT_MEMORY_CONFIRM_EN = "The memory is too not enough, are you sure to continue?",
    TXT_OPENGL_INVALID_CH = "您的系统中显卡的OpenGL版本过低，请安装最新的显卡驱动程序后重试",
    TXT_OPENGL_INVALID_EN = "The OpenGL version of your system is too low,please install the lasted one",
    TXT_CONTAINER_INVALID_CH = "指定的控件容器无效",
    TXT_CONTAINER_INVALID_EN = "Invalid ActiveX Container",
    TXT_UNKNOWN_ERROR_CH = "未知错误",
    TXT_UNKNOWN_ERROR_EN = "unknown error",
    TXT_INSTALLING_CH = "正在安装，此过程可能需要几秒钟的等待，请稍候...",
    TXT_INSTALLING_EN = "The installing may take you a few seconds, please wait for a moment...",
    TXT_INSTALL_FINISH_CH = "安装完毕",
    TXT_INSTALL_FINISH_EN = "Install finished",

    //POI类别
    POI_TYPE_Undefined = 255,
    POI_TYPE_Search = 0,			//搜索结果
    POI_TYPE_SohuFavortite = 1,		//搜狐-用户标签
    POI_TYPE_SohuPalaestra = 2,		//搜狐-奥运场馆
    POI_TYPE_SohuSight = 3,			//搜狐-特色景点
    POI_TYPE_ManageEdit = 4,		//管理员编辑的标签
    POI_TYPE_UserFavorite = 5,		//用户的收藏夹标签
    POI_TYPE_DicitiPalaestra = 6,	//DICITI奥运场馆
    POI_TYPE_DicitiTourWorld = 7,	//DICITI云游天下
    POI_TYPE_SINA_NEWS = 8,			//新浪新闻`
    POI_TYPE_CANYIN = 9,			//餐饮
    POI_TYPE_TRAFFIC = 10,			//奥运交通
    POI_TYPE_SIGHT = 11,			//旅游景点
    POI_TYPE_COMMENTS = 12,			//用户留言
    POI_TYPE_OLYMPIC_GAME = 13,		//奥运赛事
    POI_TYPE_S7_PATH = 14,			//神七PATH
    POI_TYPE_S7_FILM = 15,			//神七FILM
	POI_TYPE_FORECAST= 16,			//天气预报
	POI_TYPE_EXPO = 17,				//世博安防

    //POI的特殊标志
    PRF_MARK_DELETE = -2,			//POI已被标志为删除属性
    PRF_OLYMPICS_SPEEK_INVALID = -5,//奥运北京版块中用户的发言
    PRF_OLYMPICS_SPEEK_VALID = -4,
    PRF_TOUR_SPEEK_INVALID = -7,	//云游天下版块中用户的发言
    PRF_TOUR_SPEEK_VALID = -6,
    PRF_ENTER_CITY_INVALID = -3,	//入住城市添加的POI
    PRF_ENTER_CITY_VALID = 0,
    PRF_SOHU_FAVORITE_INVALID = -10,//搜狐用户刚添加的POI
    PRF_SOHU_FAVORITE_VALID = -9,
    PRF_POS_INVALID = -30,			//Poi坐标值不可用，其他信息从其他网站抓取
    PRF_POS_VALID = 0,				//数据经过初步审核，Poi坐标可用，可以公开

    //POI图标种类
    PT_USER_DEFINED = 0,		//用户自定义标签大头针
    PT_SEARCH_RESULT_1 = 1,		//搜索结果1
    PT_SEARCH_RESULT_2 = 2,		//搜索结果2
    PT_SEARCH_RESULT_3 = 3,		//搜索结果3
    PT_SEARCH_RESULT_4 = 4,		//搜索结果4
    PT_SEARCH_RESULT_5 = 5,		//搜索结果5
    PT_SEARCH_RESULT_6 = 6,		//搜索结果6
    PT_SEARCH_RESULT_7 = 7,		//搜索结果7
    PT_SEARCH_RESULT_8 = 8,		//搜索结果8
    PT_SEARCH_RESULT_9 = 9,		//搜索结果9
    PT_SEARCH_RESULT_10 = 10,	//搜索结果10
    PT_CANYIN = 11,			//餐饮
    PT_WENYU = 12,			//文娱
    PT_JIUDIAN = 13,		//酒店
    PT_FANGCHAN = 14,		//房产
    PT_FUWU = 15,			//服务
    PT_YUNDONG = 16,		//运动
    PT_JIAOTONG = 17,		//交通
    PT_YILIAO = 18,			//医疗
    PT_JINRONG = 19,		//金融
    PT_JIAOYU = 20,			//教育
    PT_LVYOU = 21,			//旅游
    PT_GOUWU = 22,			//购物
    PT_JIGOU = 23,			//机构
    PT_QICHE = 24,			//汽车
    PT_AOYUN = 25,			//奥运
    PT_SHOUCANG = 26,		//收藏
    PT_YUNYOUTIANXIA = 27,	//云游天下
    PT_PAOPAO = 28,			//泡泡
    PT_M1 = 29,				//临时用标签
    PT_M2 = 30,				//临时用标签
    PT_M3 = 31,				//临时用标签
    PT_TONGXUN = 32,		//通讯
    PT_TINGCHECHANG = 33,	//停车场
    PT_LIJIAOQIAO = 34,		//立交桥
    PT_HUOCHEZHAN = 35,		//火车站
    PT_GONGJIAOZHAN = 36,	//公交站
    PT_FEIJICHANG = 37,		//飞机场
    PT_DITIE = 38,			//地铁
    PT_DITIEHUANCHENG = 39,	//地铁换乘
    PT_AOYUNZX = 40,		//奥运专线
    PT_AOYUNZXZHAN = 41,	//奥运专线站
    PT_SHENQI_1 = 42,		//神7
    PT_SHENQI_2 = 43,		//神7
    PT_SHENQI_3 = 44,		//神7
    PT_SHENQI_4 = 45,		//神7
    PT_SHENQI_5 = 46,		//神7
    PT_VEDIO = 47,			//视频
    PT_CEKONGZHAN = 48,		//测控站
    PT_CELIANGCHUAN = 49,	//测量船
	PT_GUOLUFANG = 50,		//锅炉房
	PT_FANGJIAN = 51,		//房间
	PT_DIANTI_ZHITI = 52,	//电梯直梯
	PT_DIANTI_XIETI = 53,	//电梯斜梯
	PT_XIAOFANGSHUAN = 54,	//消防栓
	PT_MIEHUOQI = 55,		//灭火器
	PT_MEIQI = 56,			//煤气
	PT_LOUTIKOU = 57,		//楼梯口
	PT_LOUTI = 58 ,			//楼梯
	PT_JIANKONGSHI = 59,	//监控室
	PT_HUOYAN = 60,			//火焰

    //场景事件类型
    ET_CAMERA_MODIFY = 0,
    ET_MAP_READY = 1,
    ET_CAMERA_PATH_FINISH = 2,	//相机路径结束
    ET_CAMERA_PATH_CANCEL = 3,	//相机路径被取消
    ET_FIRST_TIME_RENDER = 4,	//第一次绘制
    ET_NEED_SEARCH_POI = 5,		//相机停留在某处,需要触发周边POI的搜索
    ET_FLY_FINISHED = 6,		//飞到目标点
    ET_CREATE_CHARACTER = 7,	//创建角色

    //控件初始化错误代码
    ERROR_BROWSER_NOT_SUPPORT = 0,	//不支持该浏览器
    ERROR_MEMORY_NOT_ENOUGH = 1,	//当前系统内存不够运行本程序
    ERROR_OPENGL_INVALID = 2,		//OpenGL版本过低
    ERROR_ACTIVEX_INVALID = 3,		//插件没有正常安装
    ERROR_DIRECTX_INVALID = 4,		//需要DirextX8.0以上的版本支持
    ERROR_UPDATE_FAILED = 5,		//文件更新失败
    ERROR_INSTANCE_EXIST = 6,		//已经有一个实例在运行
    ERROR_CONTAINER_INVALID = 7,	//控件容器无效

	//AnfangViewMode
	ANFANG_FLOOR_VIEW = 0,			//楼层观察模式
	ANFANG_FIRST_PERSON_VIEW = 1,	//第一人称观察模式
	ANFANG_BUILDING_VIEW = 2,		//建筑观察模式
	
	//GuardControlEnum
	gc_start = 0,
	gc_pause = 1,
	gc_stop = 2,


	//绘制类型
	Shape_Points = 0,
	Shape_Lines = 1,
	Shape_Line_Strip = 2,
	Shape_Line_Loop = 3,
	Shape_Triangles = 4,
	Shape_Triangle_Strip = 5,
	Shape_Triangle_Fan = 6,
	Shape_Quads = 7,
	Shape_Quad_Strip = 8,
	Shape_Polygon = 9,
	
	//坐标类型
	coord_cartesian = 0,
	coord_sphere = 1,
	coord_utm = 2,

    //POI添加类型
    ap_undefined = 0,
    ap_manage = 1,
    ap_address = 2,
    ap_favorite = 3,
    ap_enter = 4,

    //POI编辑模式
    ep_undefined = 0,
    ep_manage = 4,		//管理员编辑
 
 	//EmbedDialogPosition
	edp_undefined = 0,
	edp_center_parent = 1,		//父窗口中央
	edp_center_desktop = 2,		//桌面中央
	edp_mouse_clickpos = 3,		//鼠标点击处
    edp_parent_rect = 4,		//父窗口大小
	edp_parent_rt = 5,			//父窗口右上角
	
    ___end___;


function getString(s){
    var strRet = eval(s + (__dl?"_CH":"_EN") );
    if(typeof __cityId != "undefined" && __cityId == CITY_MACAU)
    {
        if(typeof traditionalized != "undefined")
            strRet = traditionalized(strRet);
    }
    return strRet;
}

function handleError(e){ 
    //top.status = e.message;    
}


//根据__cityId进一步初始化配置文件
function cfg_init_by_cityid(){ 
    if(typeof __cityId == "undefined")
        return;

	for(var i=0; i<CFG.IdxVersionArray.Version0.length; i++){
		if(__cityId == CFG.IdxVersionArray.Version0[i]){
			CFG.IdxVersion = IDX_VERSION_0;
			break;
		}
	}

	for(var i=0; i<CFG.IdxVersionArray.Version1.length; i++){
		if(__cityId == CFG.IdxVersionArray.Version1[i]){
			CFG.IdxVersion = IDX_VERSION_1;
			break;
		}		
	}

	for(var i=0; i<CFG.IdxVersionArray.Version2.length; i++){
		if(__cityId == CFG.IdxVersionArray.Version2[i]){
			CFG.IdxVersion = IDX_VERSION_2;
			break;
		}		
	}

	var bFindSeperateVersion = false;
    for(var i=0; i<CFG.SeparatVersion.length; i++){
        if(__cityId == CFG.SeparatVersion[i][0]){
            CFG.DicitiControl = eval("CFG." + CFG.SeparatVersion[i][1]);
			bFindSeperateVersion = true;
			break;
		}
    }
	if(!bFindSeperateVersion){
		CFG.DicitiControl = CFG.DicitiControlLocal;
	}
}
cfg_init_by_cityid();


function __getv(){	
    if(typeof ____v != "undefined") {
		//____v.focus();
		return ____v;
	}
	else if(typeof(parent.____v) != "undefined")
		return parent.____v;
	else if(typeof(parent.parent.____v) != "undefined")
		return parent.parent.____v;
	else	
        return window.external;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    DicitiControl Interface (DI) Functions
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
var _diciti_control_interface_wrap = {
    
    valid: function(){
	    try{
		    __getv().Valid();
		    return true;
	    }  
	    catch(e) {return false;}
    },
    
    config: function(){
        this.load = function(){
            try{
                return __getv().config.Load();
            }catch(e){ handleError(e);}
        }

        this.unload = function(){
            try{
                //return __getv().config.Unload();
            }catch(e){ handleError(e);}
        }

        this.addServer = function(serverType,host,port){
            try{
                return __getv().config.AddServer(serverType,host,port);
            }catch(e){ handleError(e);}
        }

        this.setTimeout = function(dwConn,dwSend,dwRecv){
            try{
                return __getv().config.SetTimeout(dwConn,dwSend,dwRecv);
            }catch(e){ handleError(e);}
        }

        this.setCacheInfo = function(cacheEnable,cacheVersion,cacheName, cacheFormat){
            try{
                return __getv().config.SetCacheInfo(cacheEnable,cacheVersion,cacheName, cacheFormat);
            }catch(e){ handleError(e);}
        }

        this.setURL = function(urlType,url){
            try{
                return __getv().config.SetURL(urlType,url);
            }catch(e){ handleError(e);}
        }

        this.setRenderTimer = function(dwRenderTimer){
            try{
                return __getv().config.SetRenderTimer(dwRenderTimer);
            }catch(e){ handleError(e);}
        }

        this.setMinAltitude = function(min){
            try{
                return __getv().config.SetMinAltitude(min);
            }catch(e){ handleError(e);}
        }

        this.setDebugMode = function(bDebug){
            try{
                return __getv().config.SetDebugMode(bDebug);
            }catch(e){ handleError(e);}
        }

        this.setLanguage = function(langId){
            try{
                return __getv().config.SetLanguage(langId);
            }catch(e){ handleError(e);}
        }

        this.setMaxWindowNum = function(nWindow){
            try{
                return __getv().config.SetMaxWindowNum(nWindow);
            }catch(e){ handleError(e);}
        }

        this.setCity = function(cityId){
            try{
                return __getv().config.SetCity(cityId);
            }catch(e){ handleError(e);}
        }

        this.setIoType = function(ioType){
            try{
                return __getv().config.SetIoType(ioType);
            }catch(e){ handleError(e);}
        }

        this.setMacauPlan = function(plan){
            try{
                return __getv().config.SetMacauPlan(plan);
            }catch(e){ handleError(e);}
        }
	    this.setTriggerClick = function(bTrigger, bAutoReset){
            try{
                return __getv().config.setTriggerClick(bTrigger, bAutoReset);
            }catch(e){ handleError(e);}
        }
        this.setFullScreen = function(bFull){
             try{
                return __getv().config.SetFullScreen(bFull);
            }catch(e){ handleError(e);}
        }
        this.setUseScriptEvent = function(){
             try{
                return __getv().config.SetUseScriptEvent();
            }catch(e){ handleError(e);}
        }
        this.setRemoteControlType = function(rct){
             try{
                return __getv().config.SetRemoteControlType(rct);
            }catch(e){ handleError(e);}
        }
        this.getProjectName = function(){
             try{
                return __getv().config.GetProjectName();
            }catch(e){ handleError(e);}
        }
        this.setIdxVersion = function(idxVersion){
             try{
                return __getv().config.SetIdxVersion(idxVersion);
            }catch(e){ handleError(e);}
        }
   },
    
    utils: function(){
    	this.hideWindow = function(){
            try{
                return __getv().utils.HideWindow();
            }catch(e){ handleError(e);}
        }
        
        this.showWindow = function(url, sizeX, sizeY, hasTitle, position, rounder){
            try{
                __g.control.show3D();
                return __getv().utils.ShowWindow(url, sizeX, sizeY, hasTitle, position, rounder);                
            }catch(e){ handleError(e);}
        }
        
	    this.getPhysicalMemory = function(){
            try{
                return __getv().utils.GetPhysicalMemory();
            }catch(e){ handleError(e);}
        }
        
	    this.checkOpenGL = function(){
            try{
                return __getv().utils.CheckOpenGL();
            }catch(e){ handleError(e);}
        }
        
	    this.openURL = function(url){
            try{
                return __getv().utils.OpenURL(url);
            }catch(e){ handleError(e);}
        }
        this.sendRequest = function(req){
            try{
                return __getv().utils.sendRequest(req);
            }catch(e){ handleError(e);}
        }
        this.fireEvent = function(eventId, data){
            try{
                return __getv().utils.FireEvent(eventId, data);
            }catch(e){ handleError(e);}
        }
        this.shellOpenURI = function(fileURI){
            try{
                return __getv().utils.ShellOpenURI(fileURI);
            }catch(e){ handleError(e);}
        }
    },
    
    camera: function(){
        this.setCamera = function(eyeX, eyeY, eyeZ, dirX, dirY, dirZ){
	        try{
                __g.control.show3D();
		        return __getv().camera.SetCamera(eyeX, eyeY, eyeZ, dirX, dirY, dirZ);
	        }catch(e){ handleError(e);}
        }
        
        this.setLookPos = function(x,y,z){
	        try{
                __g.control.show3D();
		        return __getv().camera.SetLookPos(x,y,z);
	        }catch(e){ handleError(e);}
        }

        this.runWithPathFile = function(pathFile){
	        try{
                __g.control.show3D();
		        return __getv().camera.RunWithPathFile(pathFile);
	        }catch(e){ handleError(e);}
        }

        this.getCamera = function(){
	        try{
		        return __getv().camera.GetCamera();
	        }catch(e){ handleError(e);}
        }

        this.flyAround = function(x,y,z){
	        try{
                __g.control.show3D();
		        return __getv().camera.FlyAround(x,y,z);
	        }catch(e){ handleError(e);}
        }

        this.enableAutoFlyAround = function(bEnalbed){
	        try{
		        return __getv().camera.EnableAutoFlyAround(bEnalbed);
	        }catch(e){ handleError(e);}
        }
        this.setCameraSphere = function(longitude, latitude, altitude){
	        try{
                __g.control.show3D();
		        return __getv().camera.SetCameraSphere(longitude, latitude, altitude);
	        }catch(e){ handleError(e);}
        }
    },
    
    tags: function(){
        this.setInfo = function(tagId, poiInfo){
	        try{
		        return __getv().tags.SetInfo(tagId, poiInfo);
	        }catch(e){ handleError(e);}
        }

        this.setName = function(tagId, poiName){
	        try{
		        return __getv().tags.SetName(tagId, poiName);
	        }catch(e){ handleError(e);}
        }

        this.setSize = function(tagId, size){
	        try{
		        return __getv().tags.SetSize(tagId, size);
	        }catch(e){ handleError(e);}
        }

        this.addText = function(x, y, z, sName, vDis){
	        try{
		        return __getv().tags.AddText(x, y, z, sName, vDis);
	        }catch(e){ handleError(e);}
        }

        this.setCurrent = function(tagId){
	        try{
		        return __getv().tags.SetCurrent(tagId);
	        }catch(e){ handleError(e);}
        }

        this.setVisibleDistance = function(pvd){
	        try{
		        return __getv().tags.SetVisibleDistance(pvd);
	        }catch(e){ handleError(e);}
        }

        this.removeByTypeExId = function(typeId){
	        try{
		        return __getv().tags.RemoveByTypeExId(typeId);
	        }catch(e){ handleError(e);}
        }

        this.showHelp = function(){
	        try{
                __g.control.show3D();
		        return __getv().tags.ShowHelp();
	        }catch(e){ handleError(e);}
        }

        this.remove = function(tagId){
	        try{
		        return __getv().tags.Remove(tagId);
	        }catch(e){ handleError(e);}
        }

        this.click = function(poiId){
	        try{
		        return __getv().tags.Click(poiId);
	        }catch(e){ handleError(e);}
        }

        this.clear = function(){
	        try{
		        return __getv().tags.Clear();
	        }catch(e){ handleError(e);}
        }

        this.setEditable = function(editable, editType){
	        try{
		        return __getv().tags.SetEditable(editable, editType);
	        }catch(e){ handleError(e);}
        }

        this.addTag = function(x, y, z, tagId, texId, tagName, tagInfo){
	        try{
		        return __getv().tags.AddTag(x, y, z, tagId, texId, tagName, tagInfo);
	        }catch(e){ handleError(e);}
        }

        this.add = function(x, y, z, poiType, poiId, texId, typeId, poiName, poiInfo, data){
	        try{
		        return __getv().tags.Add(x, y, z, poiType, poiId, texId, typeId, poiName, poiInfo, data);
	        }catch(e){ handleError(e);}
        }
        this.setAddState = function(ap){
	        try{
                __g.control.show3D();
		        return __getv().tags.SetAddState(ap);
	        }catch(e){ handleError(e);}
        }
    },
    
    scene: function(){
        this.showHideSubway = function(bShow){
	        try{
		        return __getv().scene.ShowHideSubway(bShow);
	        }catch(e){ handleError(e);}
        }
	    this.showHideRoad = function(bShow){
	        try{
		        return __getv().scene.ShowHideRoad(bShow);
	        }catch(e){ handleError(e);}
	    }
	    this.showHideOlympic = function(bShow){
	        try{
		        return __getv().scene.ShowHideOlympic(bShow);
	        }catch(e){ handleError(e);}
	    }
	    this.highlightSubway = function(index){
	        try{
		        return __getv().scene.HighlightSubway(index);
	        }catch(e){ handleError(e);}
	    }
	    this.highlightOlympic = function(index){
	        try{
		        return __getv().scene.HighlightOlympic(index);
	        }catch(e){ handleError(e);}
	    }
	    this.setLayerVisible = function(layer, bVisible){
	        try{
		        return __getv().scene.SetLayerVisible(layer, bVisible);
	        }catch(e){ handleError(e);}
	    }
	    this.setProjectPlan = function(project, plan){
	        try{
		        return __getv().scene.SetProjectPlan(project, plan);
	        }catch(e){ handleError(e);}
	    }
	    this.getViewCoord4 = function(){
	        try{
		        return __getv().scene.GetViewCoord4();
	        }catch(e){ handleError(e);}
	    }
	    this.setVisibleDistance = function(fDis){
	        try{
		        return __getv().scene.SetVisibleDistance(fDis);
	        }catch(e){ handleError(e);}
	    }
	    this.addCustomShape = function(coord, shape, rgb, vnum, vdata){
	        try{
		        return __getv().scene.AddCustomShape(coord, shape, rgb, vnum, vdata);
	        }catch(e){ handleError(e);}
	    }
	    this.clearCustomShape = function(){
	        try{
		        return __getv().scene.ClearCustomShape();
	        }catch(e){ handleError(e);}
	    }
	    this.enableRender = function(enable){
	        try{
		        return __getv().scene.EnableRender(enable);
	        }catch(e){ handleError(e);}
	    }	
	    this.loopAddCustomShape = function(op, coord, shape, rgb, vnum, d1, d2, d3){
	        try{
		        return __getv().scene.LoopAddCustomShape(op, coord, shape, rgb, vnum, d1, d2, d3);
	        }catch(e){ handleError(e);}
	    }			
	    this.reqAddCustomShape = function(reqstr){
	        try{
		        return __getv().scene.ReqAddCustomShape(reqstr);
	        }catch(e){ handleError(e);}
	    }			
    },
	
	expo: function(){
		this.currentFocus = 0;
		this.guardViewMode = ANFANG_FLOOR_VIEW;
		
		//增加安防人员,ID必须大于0
	    this.addSecurityGuard = function(id, modelId, x, y, z, name){
	        try{				
		        return __getv().expo.AddSecurityGuard(id, modelId, x, y, z, name);
	        }catch(e){ handleError(e);}
	    }	
		
		//设置观察哪个安防人员,如果ID为0就是整楼观察
	    this.focusOnGuard = function(id){
	        try{
				if(id != 0)
					this.currentFocus = id;	
				____v.focus();
		        return __getv().expo.FocusOnGuard(id);
	        }catch(e){ handleError(e);}
	    }	
		
		//设置安防人员位置
	    this.setGuardPos = function(id, x, y, z){
	        try{
		        return __getv().expo.SetGuardPos(id, x, y, z);
	        }catch(e){ handleError(e);}
	    }	
		
		//设置视图模式
	    this.setGuardViewMode = function(vm){
	        try{				
				this.guardViewMode = vm;	
				____v.focus();
		        return __getv().expo.SetGuardViewMode(vm);
	        }catch(e){ handleError(e);}
	    }	
		
		//设置相邻楼层透明度
	    this.setNerghbourFloorTransparency = function(fTransparency){
	        try{
		        return __getv().expo.SetNerghbourFloorTransparency(fTransparency);
	        }catch(e){ handleError(e);}
	    }	
	    this.setGuardPosByPath = function(id, pathFile){
	        try{				
		        return __getv().expo.SetGuardPosByPath(id, pathFile);
	        }catch(e){ handleError(e);}
	    }	
	    this.getGuardPos = function(id){
	        try{				
		        return __getv().expo.GetGuardPos(id);
	        }catch(e){ handleError(e);}
	    }	
	    this.controlGuard = function(op, id){
	        try{
				id = id || this.currentFocus;
		        return __getv().expo.ControlGuard(id, op);
	        }catch(e){ handleError(e);}
	    }	
	},
    
    im: function(){
        this.setChatServerInfo = function(host, port){
	        try{
		        return __getv().im.SetChatServerInfo(host, port);
	        }catch(e){ handleError(e);}
	    }

        this.login = function(userName, userPass, userFace, modelID){
	        try{
		        return __getv().im.Login(userName, userPass, userFace, modelID);
	        }catch(e){ handleError(e);}
	    }

        this.logout = function(){
	        try{
		        return __getv().im.Logout();
	        }catch(e){ handleError(e);}
	    }

        this.sendMessage = function(userId, msg, bPrivate){
	        try{
		        return __getv().im.SendMessage(userId, msg, bPrivate);
	        }catch(e){ handleError(e);}
	    }

        this.getMessage = function(){
	        try{
		        return __getv().im.GetMessage();
	        }catch(e){ handleError(e);}
	    }

        this.getUserList = function(){
	        try{
		        return __getv().im.GetUserList();
	        }catch(e){ handleError(e);}
	    }

        this.changeUserName = function(userName){
	        try{
		        return __getv().im.ChangeUserName(userName);
	        }catch(e){ handleError(e);}
	    }

        this.changeUserFace = function(userFace){
	        try{
		        return __getv().im.ChangeUserFace(userFace);
	        }catch(e){ handleError(e);}
	    }

        this.setUserTalk = function(userId, msg){
	        try{
		        return __getv().im.SetUserTalk(userId, msg);
	        }catch(e){ handleError(e);}
	    }

        this.flyToUser = function(userId){
	        try{
		        return __getv().im.FlyToUser(userId);
	        }catch(e){ handleError(e);}
	    }

        this.setUserAction = function(animation){
	        try{
		        return __getv().im.SetUserAction(animation);
	        }catch(e){ handleError(e);}
	    }

        this.getUserNameById = function(userId){
	        try{
		        return __getv().im.GetUserNameById(userId);
	        }catch(e){ handleError(e);}
	    }
    }
};



function _diciti_config(){
    this.base = _diciti_control_interface_wrap.config;
    this.base();
}

function _diciti_scene(){
    this.base = _diciti_control_interface_wrap.scene;
    this.base();
	
	this.shapeAddBegin = function(coord, shape, rgb, vnum){
		this._coord = coord;
		this._shape = shape;
		this._rgb = rgb;
		this._vnum = vnum;
		
		this.loopAddCustomShape(0, coord, shape, rgb, vnum, 0.0, 0.0, 0.0);
		return this;
	}
	
	this.shapeAdd = function(d1, d2, d3){
		this.loopAddCustomShape(1, this._coord, this._shape, this._rgb, this._vnum, d1, d2, d3);
		return this;
	}
	
	this.shapeAddEnd = function(){
		this.loopAddCustomShape(2, this._coord, this._shape, this._rgb, this._vnum, 0.0, 0.0, 0.0);
		return this;
	}
}

function _diciti_expo(){
	this.base = _diciti_control_interface_wrap.expo;
	this.base();
}

function _diciti_utils(){
    this.base = _diciti_control_interface_wrap.utils;
    this.base();

    this.getCityByIP = function(ip){
        var strRet = this.sendRequest("http://www.zonediy.com/commons/findip.jsp?ip=" + ip + "&wise=txt");
        return strRet;
    },
	
	this.showWindowEx = function(url, sizeX, sizeY, hasTitle, position,  rounder){
		return this.showWindow(url,
							   sizeX, sizeY,
							   hasTitle || false,
							   position || edp_center_parent,
							   rounder || 24);
	}
    
    //构造参数
    this.constructParam = function(p){
        var b3 = false;
        var b6 = false;
        if(p.x && p.y && p.z)   
            b3 = true;
        if(p.cx && p.cy && p.cz && p.dx && p.dy && p.dz)    
            b6 = true;
        
        if(b3 && b6)             
            return (p.x + "," + p.y + "," + p.z + "," + p.cx + "," + p.cy + "," + p.cz + "," + p.dx + "," + p.dy + "," + p.dz );
        if(b3)
            return (p.x + "," + p.y + "," + p.z);
        if(b6)
            return ( p.cx + "," + p.cy + "," + p.cz + "," + p.dx + "," + p.dy + "," + p.dz );
    }

    this.createEmbedWindow = function(src){
        var embedWnd = document.getElementById(EMBED_WINDOW_ID);
        if(!embedWnd){
            embedWnd = document.createElement("DIV");
			var ehtml = "<iframe id='" + EMBED_WINDOW_ID + "' "
			ehtml += "style='display:none;position:absolute;z-index:1000;' ";
			ehtml += "src='" + src + "'";
			ehtml += "frameborder='0' scrolling='no'></iframe>";
            embedWnd.innerHTML = ehtml;
            document.body.appendChild(embedWnd);	
            embedWnd = document.getElementById(EMBED_WINDOW_ID);
        }  
    }
		
    this.cookie = function(name, value, options){
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            var path = options.path ? '; path=' + options.path : '';
            var domain = options.domain ? '; domain=' + options.domain : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = cookies[i].replace(/^\s*|\s*$/g,"");
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    } 
	
	this.isFunction = function(fn){
		return !!fn && typeof fn != "string" && !fn.nodeName &&
			fn.constructor != Array && /^[\s[]?function/.test( fn + "" );
	}
}

function _diciti_camera(){
    this.base = _diciti_control_interface_wrap.camera;
    this.base();
    this.getCameraEx = function(){
        return this.getCamera().split("\r\n");
    }    
    this.options = {
        enableLookAround: false,
        target: [],
        param: "",
        value: null,
        timer: null,
        reset: function() { 
            this.enableLookAround = false;
            this.target = [];
            this.param = "";
            this.value = null;
            this.killTimer();
        },
        killTimer: function(){
            clearTimeout(this.timer);
            this.timer = null;
        }    
    };
    
    this.setCameraEx = function(){
		__g.utils.hideWindow();
        var a = arguments;
        var argc = a.length;
        if(argc == 0)
            return;

        //Object, Array
        if(argc == 1){
            var p = a[0];
            if(!p)
                return;
                
            if(p.length == undefined){   //Object {x, y, z, cx, cy, cz, dx, dy, dz}
                if(p.cx && p.cy && p.cz && p.dx && p.dy && p.dz){
                    this.setCamera(p.cx, p.cy, p.cz, p.dx, p.dy, p.dz);   
                    this.options.target = null;
                }    
                else if(p.x && p.y && p.z){
                    this.setLookPos(p.x, p.y, p.z);
                    this.options.target = [p.x, p.y, p.z];
                }    
            }
            else{    //Array
                if(p.length == 3){   // [x,y,z]
                    this.setLookPos(p[0], p[1], p[2]);
                    this.options.target = p;
                }    
                else if(p.length == 6){  // [cx, cy, cz, dx, dy, dz]
                    this.setCamera(p[0], p[1], p[2], p[3], p[4], p[5]);    
                    this.options.target = null;
                }    
                else if(p.length == 9){  // [x, y, z, cx, cy, cz, dx, dy, dz]
                    this.options.target = p;
                    if(p[3] && p[4] && p[5] && p[6] && p[7] && p[8]){
                        this.setCamera(p[3], p[4], p[5], p[6], p[7], p[8]);
                    }    
                    else if(p[0] && p[1] && p[2]){
                        this.setLookPos(p[0], p[1], p[2]);         
                    }    
                }    
            }
        }
        else if(argc == 3){  //x, y, z
            this.setLookPos(a[0], a[1], a[2]);
            this.options.target = a;
        }   
        else if(argc == 6){  //cx, cy, cz, dx, dy, dz
            this.setCamera(a[0], a[1], a[2], a[3], a[4], a[5]);  
            this.options.target = null;
        }  
        else if(argc == 9){  //x, y, z, cx, cy, cz, dx, dy, dz
            this.options.target = a;
            if(a[3] && a[4] && a[5] && a[6] && a[7] && a[8]){
                this.setCamera(a[3], a[4], a[5], a[6], a[7], a[8]);
            }    
            else if(a[0] && a[1] && a[2]){
                this.setLookPos(a[0], a[1], a[2]);         
            }    
        }       
    }
    
    this.setLookAroundParam = function(enableLookAround, target, param, value){
        this.options.enableLookAround = enableLookAround;      
        if(enableLookAround){
            this.options.target = target;      
            this.options.param = param;   
            this.options.value = value;   
            this.setCameraEx(target);   
        }
        else{
            this.options.Reset();
        }
    }
    
    this.gotoPosWithOptions = function(enableLookAround, target, param, value){
        this.options.enableLookAround = enableLookAround;      
        this.options.target = target;      
        this.options.param = param;   
        this.options.value = value;   
        this.setCameraEx(target);   
    }
}

function _diciti_tag(){
    this.base = _diciti_control_interface_wrap.tags;
    this.base();
    
    this.addEx = function(x, y, z, poiType, poiId, poiIcon, typeExId, poiName, poiInfo, data){    
        poiInfo = poiInfo || "";
        if(poiInfo.length > 30)
            poiInfo = poiInfo.substr(0, 30) + "...";
        return this.add( x, y, z, 
                    poiType, poiId, poiIcon, 
                    typeExId, 
                    poiName||"", 
                    poiInfo, 
                    data||"" );
    }

    this.addEx2 = function(x, y, z, poiType, poiId, poiIcon, poiName, poiInfo, data){
        return this.addEx(x, y, z, poiType, poiId, poiIcon, -1, poiName, poiInfo, data);
    } 
}

function _diciti_im(){
    this.base = _diciti_control_interface_wrap.im;
    this.base();
}


function _diciti_control(){
    this.container = null; 
    this.notUpdate = false;
	this.embedFrame = null;
    this.createControl = function(clsid, codebase){
        var objStr =  "<object id='____v' "
                    + "' style='width:0;height:0"
                    + "' classid='clsid:" + clsid 
                    + "' onmousewheel='event.returnValue=false;'>"
                    + "</object>";
                    
        this.container.innerHTML = objStr;
    }


    this.watchInstall = function(forward){
        var pThis = this; 
        if(typeof __cityId != "undefined"){
            for(var i=0; i<CFG.SeparatVersion.length; i++){
                if(__cityId == CFG.SeparatVersion[i][0]){
                    pThis.notUpdate = true;
                    break;
                }    
            }
        }
        if(this.checkVersion())
            return;
			
        pThis.timerCheckVersion = setInterval(function(){
            if(pThis.checkVersion()){ 
                clearInterval(pThis.timerCheckVersion);
                top.status = getString("TXT_INSTALL_FINISH");
				var fromURL = pThis.getFromURL();
				if(fromURL){
					location.replace(fromURL);
				}
				else{
					if(__g.utils.isFunction(forward)){
						forward.call();											
					}
					else{
						if(forward)
							location.replace(forward);
						else
							setTimeout("location.reload()", 1000);
					}
				}
            }
        }, 1000);    
    }

    this.createLoader = function(forward){ 
        if(this.checkVersion())
            return;
        
        this.watchInstall(forward);
        
        if(location.href.indexOf("#setup") == -1)
            location.replace(location.href + "#setup");
            
        top.status = getString("TXT_INSTALLING");  
        var dicitiContainer = document.createElement("div");  
        dicitiContainer.style.display = "none";
        var objStr = "<object id='dLoader' classid='clsid:" + CFG.DicitiLoader.Clsid + "' codebase='" + CFG.DicitiLoader.CodeBase + "'></object>";
	    dicitiContainer.innerHTML = objStr;
	    document.body.appendChild(dicitiContainer);
    }

    //检查用户是否安装了最新版本的插件
    this.checkVersion = function(forward){
		var pThis = this;
	    var bRet = false;
		
		if(CFG.DicitiControl.notUpdate ) {
			pThis.notUpdate = true;
		}
		
	    if(pThis.notUpdate){
	        try{
	                var dControl = new ActiveXObject(CFG.DicitiControl.Progid);
	                dControl = null;    
	                bRet = true;
	                if(bRet && !!forward)
				    {
					    var fromURL = pThis.getFromURL();					
	                    window.location.replace(fromURL? fromURL : forward);  //禁止history
				    }
            }
	        catch(e){ 
	        }
	    }
	    else{
	        try{
	                var dLoader = new ActiveXObject(CFG.DicitiLoader.Progid);
                    if(typeof dLoader.GetVersion != "undefined"){
		                var version = dLoader.GetVersion();				
		                if(CFG.DicitiLoader.Version == version)
		                    bRet = true;
	                }
	                dLoader = null;    
	                if(bRet && !!forward)
				    {
					    var fromURL = pThis.getFromURL();					
	                    window.location.replace(fromURL? fromURL : forward);  //禁止history
				    }
            }
	        catch(e){ 
	        }
	    }
    	
	    return bRet;
    }

    this.updateFile = function(fn){
        var pThis = this;
        try{
            var dLoader = new ActiveXObject(CFG.DicitiLoader.Progid);
        }
        catch(e){
            return;
        }
           
        //更新文件
        dLoader.SetLogable(CFG.LogUpdate);
        var filelist = CFG.UpdateFile; 
        for(var i=0; i<filelist.length; i++)
            dLoader.AddFile(filelist[i][0], filelist[i][1], filelist[i][3]);       
        dLoader.SetCacheVersion(CFG.CacheInfo.CacheVersion, CFG.CacheInfo.CacheName);    
        var retval = dLoader.Update(CFG.Host, CFG.Port, __dl?0:1);
        if(retval == 0 || retval == 1){
            dLoader = null;
            if(fn)
                fn.call();
            return;
        }
        
        //监视文件更新
        pThis.updateTimer = setInterval(function(){
            if(dLoader.CheckComplete() == TRUE){
                dLoader = null;
                clearInterval(pThis.updateTimer);
                if(fn)
                    fn.call();
            }
        }, 200);        
    }
	
	this.getFromURL = function(){
		var fromURL = __g.utils.cookie("fromURL");
		if(fromURL)
			__g.utils.cookie("fromURL", location.href, {expires: -1, path: "/"});
		return fromURL;
	}

    //初始化DicitiControl控件
    this.init = function(options){
        var pThis = this;
		pThis.getFromURL();		//清除cookie
        if(!options.container)
            throw ERROR_CONTAINER_INVALID;
        pThis.container = options.container; 

        //检测浏览器
        if(!browser.msie)
            throw ERROR_BROWSER_NOT_SUPPORT;
        
        //检查DICITI控件
        pThis.notUpdate = options.notUpdate;
        if(!pThis.checkVersion())	
	        throw ERROR_ACTIVEX_INVALID;
        
        var fnInit = function(){
            //创建DicitiControl控件
            pThis.createControl(CFG.DicitiControl.Clsid)
            
            //监测系统物理内存
            if(__g.utils.getPhysicalMemory() < (400 * 1024 * 1024) )
                if(!confirm( getString("TXT_MEMORY_CONFIRM") ))
                   throw ERROR_MEMORY_NOT_ENOUGH;
          
            //检测OpenGL版本
            if(!__g.utils.checkOpenGL())   
                throw ERROR_OPENGL_INVALID; 

            if(typeof __cityId == "undefined")
                __g.config.setCity(CITY_BEIJING);
            else
                __g.config.setCity(__cityId);
			
			__g.config.setIdxVersion(CFG.IdxVersion);

            //事件处理
            __g.config.setUseScriptEvent();
            ____v.attachEvent("ConnectionEvent", pThis.eventHandler);    
            
            //服务器列表
            __g.config.addServer('Login', CFG.Host, CFG.Port, '')
            __g.config.setIoType(CFG.IO);
            for(var i=0; i<CFG.URL.length; i++){
                if(CFG.IO == IO_TYPE_NET_FILE)
                    __g.config.setURL(CFG.URL[i][0], '/' + CFG.URL[i][1] + '/' );
                if(CFG.IO == IO_TYPE_NET_DBMS)    
                    __g.config.setURL(CFG.URL[i][0], CFG.URL[i][2]);
                if(CFG.IO == IO_TYPE_LOCAL_FILE)
                    __g.config.setURL(CFG.URL[i][0], CFG.URL[i][3]);
            }
            __g.config.setMinAltitude(CFG.MinAltitude)
            __g.config.setRenderTimer(CFG.Timer.Render)
            __g.config.setTimeout(CFG.Timeout.Conn, CFG.Timeout.Send, CFG.Timeout.Recv)
            __g.config.setMaxWindowNum(CFG.MaxWindowNum);
            __g.config.addServer('Data', CFG.DataServer[0], CFG.DataServer[1], '')
            __g.config.setLanguage(__dl? 0:1);
            __g.config.setCacheInfo(CFG.CacheInfo.CacheEnable, 
                    pThis.notUpdate? CFG.CacheInfo.CacheVersion : -1, 
                    CFG.CacheInfo.CacheName, 
                    CFG.CacheInfo.CacheFormat)
                                
            var bRet = __g.config.load();
            if(bRet == 0)
                 throw ERROR_INSTANCE_EXIST;
            
            __g.config.setRemoteControlType(CFG.RemoteControl);
            __g.utils.hideWindow(); 
            ____v.style.width = options.width || "100%";
            ____v.style.height = options.height || "100%";
            if(options.fnSuccess)
                options.fnSuccess.call();          
        }
        
        //更新文件
        if(pThis.notUpdate)
            fnInit();
        else
            pThis.updateFile(fnInit);
    }

    this.showMessage = function(msg){
        this.container.innerHTML = "<span style='color:red;'>" + msg + "</span>";    
    }

    this.init2 = function(options){
		var pThis = this;
        try{
	        this.init(options);
	    }
        catch(e){
            if(options.fnError)
                options.fnError.apply(e);
                
            switch(e){
            
            case ERROR_CONTAINER_INVALID:
                alert(getString("TXT_CONTAINER_INVALID"));
                break;
                
            case ERROR_ACTIVEX_INVALID:
                if(options.setupURL){ 
					var expiresTime = 15 * 60 * 1000;
					__g.utils.cookie("fromURL", location.href, {expires: expiresTime, path: "/"});
                    location.href = options.setupURL;
                }
                break;
            
            case ERROR_OPENGL_INVALID:
                this.showMessage(getString("TXT_OPENGL_INVALID"));
                break;    
            	
            case ERROR_DIRECTX_INVALID:
                this.showMessage(getString("TXT_NEED_UPDATE_DIRECTX"));
                break;

            case ERROR_UPDATE_FAILED:
                this.showMessage(getString("TXT_UPDATE_FILE_FAILED"));
                break;

            case ERROR_INSTANCE_EXIST:
                this.showMessage(getString("TXT_INSTANCE_EXIST"));
                break;

             case ERROR_MEMORY_NOT_ENOUGH:
                this.showMessage(getString("TXT_MEMORY_NOT_ENOUGH"));
                break;
                
           default:
                if(typeof e == 'object' && e.message)    
                    this.showMessage(e.message);
                else
                    this.showMessage(getString("TXT_UNKNOWN_ERROR"));
                break;
            } 
            
            if(!options.setupURL && options.watch)
                this.watchInstall();
            
            return false;   
        }
        
        return true;
    }

     //控件事件处理函数
     this.eventHandler = function(){
        this.eventName = arguments[0];  
        this.eventCallbackName = "fn" + eventName;
        try{
            this.eventCallback = eval(eventCallbackName);
        }
        catch(e){
            return;
        }
        if(eventCallback)
            eventCallback.apply(null, arguments);
     }
	 
	this.createEmbedFrame = function(src, scrolling){
		if(this.container && !this.embedFrame){
			var embedFrameParent = document.createElement("DIV");
			embedFrameParent.innerHTML = "<iframe id='" + EMBED_FRAME_ID + "' src='"+src+"' scrolling='"+ (scrolling?"yes":"no") +"' width='100%' height='100%' style='display:none;' frameborder='0' ></iframe>";
			this.container.appendChild(embedFrameParent);	
			this.embedFrame = document.getElementById(EMBED_FRAME_ID);
		}
	}
	
	this.show3D = function(){
		if(this.embedFrame){
			this.embedFrame.style.display = "none";
		}
		
		var earthControl = document.getElementById("____v");
		if(earthControl){
			earthControl.style.display = "block";
		}
	    __g.scene.enableRender(true);
	}
	
	this.showEmbedFrame = function(){
		if(this.embedFrame){
			this.embedFrame.style.display = "block";
		}
		
		var earthControl = document.getElementById("____v");
		if(earthControl){
			earthControl.style.display = "none";
		}
	    __g.scene.enableRender(false);
	}
}


var __g = {
	valid:		_diciti_control_interface_wrap.valid,
	config:		new _diciti_config(),
	scene:		new _diciti_scene(),
	camera:		new _diciti_camera(),
	utils:		new _diciti_utils(),
	tags:		new _diciti_tag(),
	im:			new _diciti_im(),
	expo:		new _diciti_expo(),
	control:	new _diciti_control()
}

__g.tag = __g.tags;
