﻿/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    DICITI核心文件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function isZh()
{	
    if(typeof __iszh != "undefined")
        return __iszh;
    
    var lang = getParameter("lang");
    if(lang != null)
        return lang == "zh";
    
    lang = navigator.userLanguage || navigator.language;
    return  lang.substr(0,2) == "zh";
}

var __dl = isZh();
var __dln = __dl? "zh" : "en";


function __dicitiRegisterNamespaces()
{
    for (var d = 0; d < arguments.length; d++)
    {
        var b = arguments[d].split("."), c = window;
        for (var a = 0; a < b.length; a++)
        {
            if (!c[b[a]])
                c[b[a]] = {};
            c = c[b[a]];
        }
    }
}

__dicitiRegisterNamespaces("Diciti.Const");


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    字符串常量
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.TXT_NEED_UPDATE_DIRECTX_CH = "本系统需要DirextX8.0以上的版本支持，由于您的系统中的DirextX版本太低，所以需要更新DirectX才能正常浏览!";
Diciti.Const.TXT_NEED_UPDATE_DIRECTX_EN = "You need to update the DirextX version which has to be greater than 8.0!";
Diciti.Const.TXT_UPDATE_FILE_FAILED_CH = "文件更新失败!";
Diciti.Const.TXT_UPDATE_FILE_FAILED_EN = "Update file failed!";
Diciti.Const.TXT_INSTANCE_EXIST_CH = "你已经在另外一个标签页窗口中打开了相同的页面， 为了不影响系统性能，该页面将不再显示三维窗口，请切换到已经打开的页面浏览。";
Diciti.Const.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! ";
Diciti.Const.TXT_ENV_NOT_SUPPORT_CH = "检测到您的系统环境不支持本软件的运行";
Diciti.Const.TXT_ENV_NOT_SUPPORT_EN = "It doesn't work in your system environment";
Diciti.Const.TXT_BROWSER_NOT_SUPPORT_CH = "暂时只支持IE内核的浏览器";
Diciti.Const.TXT_BROWSER_NOT_SUPPORT_EN = "It can work in the browsers which has IE core";
Diciti.Const.TXT_MEMORY_NOT_ENOUGH_CH = "您的系统内存太低，至少需要512MB的内存";
Diciti.Const.TXT_MEMORY_NOT_ENOUGH_EN = "The memory should be greater than 512MB";
Diciti.Const.TXT_MEMORY_CONFIRM_CH = "您的计算机内存过低，是否继续运行？";
Diciti.Const.TXT_MEMORY_CONFIRM_EN = "The memory is too not enough, are you sure to continue?";
Diciti.Const.TXT_OPENGL_INVALID_CH = "您的系统中OpenGL版本过低，建议您安装最新的显卡驱动程序";
Diciti.Const.TXT_OPENGL_INVALID_EN = "The OpenGL version of your system is too low,please install the lasted one";
Diciti.Const.TXT_UNKNOWN_ERROR_CH = "未知错误";
Diciti.Const.TXT_UNKNOWN_ERROR_EN = "unknown error";
Diciti.Const.TXT_INSTALLING_CH = "正在安装，此过程可能需要几秒钟的等待，请稍候...";
Diciti.Const.TXT_INSTALLING_EN = "The installing may take you a few seconds, please wait for a moment...";
Diciti.Const.TXT_INSTALL_FINISH_CH = "安装完毕";
Diciti.Const.TXT_INSTALL_FINISH_EN = "Install finished";


Diciti.Const.GetString = function(s)
{
    return eval("Diciti.Const." + s + (__dl?"_CH":"_EN") );
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    POI类别
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.POI_TYPE_Undefined         =255;
Diciti.Const.POI_TYPE_Search			=0;		//搜索结果
Diciti.Const.POI_TYPE_SohuFavortite		=1;		//搜狐-用户标签
Diciti.Const.POI_TYPE_SohuPalaestra		=2;		//搜狐-奥运场馆
Diciti.Const.POI_TYPE_SohuSight			=3;		//搜狐-特色景点
Diciti.Const.POI_TYPE_ManageEdit		=4;		//管理员编辑的标签
Diciti.Const.POI_TYPE_UserFavorite		=5;		//用户的收藏夹标签
Diciti.Const.POI_TYPE_DicitiPalaestra   =6;     //DICITI奥运场馆
Diciti.Const.POI_TYPE_DicitiTourWorld   =7;     //DICITI云游天下
Diciti.Const.POI_TYPE_SINA_NEWS         =8;     //新浪新闻`
Diciti.Const.POI_TYPE_CANYIN            =9;     //餐饮
Diciti.Const.POI_TYPE_TRAFFIC			=10;	//奥运交通
Diciti.Const.POI_TYPE_SIGHT             =11;    //旅游景点
Diciti.Const.POI_TYPE_COMMENTS			=12;	//用户留言
Diciti.Const.POI_TYPE_OLYMPIC_GAME		=13;	//奥运赛事
Diciti.Const.POI_TYPE_S7_PATH			=14;	//神七PATH
Diciti.Const.POI_TYPE_S7_FILM			=15;	//神七FILM


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    POI的特殊标志
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.PRF_MARK_DELETE 				= -2;		//POI已被标志为删除属性
Diciti.Const.PRF_OLYMPICS_SPEEK_INVALID	    = -5;		//奥运北京版块中用户的发言
Diciti.Const.PRF_OLYMPICS_SPEEK_VALID		= -4;
Diciti.Const.PRF_TOUR_SPEEK_INVALID		    = -7;		//云游天下版块中用户的发言
Diciti.Const.PRF_TOUR_SPEEK_VALID			= -6;
Diciti.Const.PRF_ENTER_CITY_INVALID		    = -3;		//入住城市添加的POI
Diciti.Const.PRF_ENTER_CITY_VALID			= 0;		
Diciti.Const.PRF_SOHU_FAVORITE_INVALID	    = -10;		//搜狐用户刚添加的POI
Diciti.Const.PRF_SOHU_FAVORITE_VALID		= -9;		
Diciti.Const.PRF_POS_INVALID 				= -30;		//Poi坐标值不可用，其他信息从其他网站抓取
Diciti.Const.PRF_POS_VALID				    = 0;		//数据经过初步审核，Poi坐标可用，可以公开


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    POI图标
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.PT_USER_DEFINED         =0;		//用户自定义标签 大头针
Diciti.Const.PT_SEARCH_RESULT_1      =1;		//搜索结果1
Diciti.Const.PT_SEARCH_RESULT_2      =2;		//搜索结果2
Diciti.Const.PT_SEARCH_RESULT_3      =3;		//搜索结果3
Diciti.Const.PT_SEARCH_RESULT_4      =4;		//搜索结果4
Diciti.Const.PT_SEARCH_RESULT_5      =5;		//搜索结果5
Diciti.Const.PT_SEARCH_RESULT_6      =6;		//搜索结果6
Diciti.Const.PT_SEARCH_RESULT_7      =7;		//搜索结果7
Diciti.Const.PT_SEARCH_RESULT_8      =8;		//搜索结果8
Diciti.Const.PT_SEARCH_RESULT_9      =9;		//搜索结果9
Diciti.Const.PT_SEARCH_RESULT_10     =10;	    //搜索结果10
Diciti.Const.PT_CANYIN               =11;	    //餐饮
Diciti.Const.PT_WENYU                =12;	    //文娱
Diciti.Const.PT_JIUDIAN              =13;	    //酒店
Diciti.Const.PT_FANGCHAN             =14;	    //房产
Diciti.Const.PT_FUWU                 =15;	    //服务
Diciti.Const.PT_YUNDONG              =16;	    //运动
Diciti.Const.PT_JIAOTONG             =17;	    //交通
Diciti.Const.PT_YILIAO               =18;	    //医疗
Diciti.Const.PT_JINRONG              =19;	    //金融
Diciti.Const.PT_JIAOYU               =20;	    //教育
Diciti.Const.PT_LVYOU                =21;	    //旅游
Diciti.Const.PT_GOUWU                =22;	    //购物
Diciti.Const.PT_JIGOU                =23;	    //机构
Diciti.Const.PT_QICHE                =24;	    //汽车
Diciti.Const.PT_AOYUN                =25;	    //奥运
Diciti.Const.PT_SHOUCANG             =26;   	//收藏
Diciti.Const.PT_YUNYOUTIANXIA        =27;		//云游天下
Diciti.Const.PT_PAOPAO               =28;		//泡泡
Diciti.Const.PT_M1                   =29;   	//临时用标签
Diciti.Const.PT_M2                   =30;	    //临时用标签
Diciti.Const.PT_M3                   =31;	  	//临时用标签
Diciti.Const.PT_TONGXUN			     =32;	    //通讯
Diciti.Const.PT_TINGCHECHANG		 =33;       //停车场
Diciti.Const.PT_LIJIAOQIAO			 =34;       //立交桥
Diciti.Const.PT_HUOCHEZHAN           =35;       //火车站
Diciti.Const.PT_GONGJIAOZHAN		 =36;       //公交站
Diciti.Const.PT_FEIJICHANG			 =37;       //飞机场
Diciti.Const.PT_DITIE				 =38;       //地铁
Diciti.Const.PT_DITIEHUANCHENG		 =39;       //地铁换乘
Diciti.Const.PT_AOYUNZX				 =40;       //奥运专线
Diciti.Const.PT_AOYUNZXZHAN			 =41;       //奥运专线站
Diciti.Const.PT_SHENQI_1			 =42;       //神7
Diciti.Const.PT_SHENQI_2			 =43;       //神7
Diciti.Const.PT_SHENQI_3			 =44;       //神7
Diciti.Const.PT_SHENQI_4			 =45;       //神7
Diciti.Const.PT_SHENQI_5			 =46;       //神7
Diciti.Const.PT_VEDIO                =47;       //视频            
Diciti.Const.PT_CEKONGZHAN			 =48;       //测控站
Diciti.Const.PT_CELIANGCHUAN		 =49;       //测量船


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    POI编辑模式
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.epUndefined         = 0;
Diciti.Const.epSohuSight         = 1;	   //对旅游景点和特色街区POI的编辑
Diciti.Const.epSohuPalaestra     = 2;	   //对奥运场馆POI的编辑
Diciti.Const.epSearchResult      = 3;	   //对搜索结果POI的编辑
Diciti.Const.epManageEdit        = 4;      //管理员编辑
Diciti.Const.epManageAdd         = 5;      //管理员添加 
Diciti.Const.epUserAddressAdd    = 6;      //用户地址添加
Diciti.Const.epUserAddressEdit   = 7;      //用户地址修改
Diciti.Const.epUserFavoriteAdd   = 8;      //用户添加标签
Diciti.Const.epEnterCityAddress  = 9;      //入住城市时地址的编辑
Diciti.Const.epIWantToSpeek		 = 10;	   //我要发言
Diciti.Const.epCorrectPoiPos	 = 11;     //纠错POI


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    事件类型
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.EVENT_OnChangeDebugMode			= "OnChangeDebugMode";
Diciti.Const.EVENT_OnEditPoi					= "OnEditPoi";
Diciti.Const.EVENT_OnAddPoi						= "OnAddPoi";
Diciti.Const.EVENT_OnDeletePoi					= "OnDeletePoi"
Diciti.Const.EVENT_OnClickManageEditPoi			= "OnClickManageEditPoi";
Diciti.Const.EVENT_OnClickPOI					= "OnClickPOI";
Diciti.Const.EVENT_OnStartSearchAround          = "OnStartSearchAround";
Diciti.Const.EVENT_OnFavoritePoi				= "OnFavoritePoi";
Diciti.Const.EVENT_OnBatchUpdatePoi             = "OnBatchUpdatePoi";
Diciti.Const.EVENT_OnCopyAddress				= "OnCopyAddress";
Diciti.Const.EVENT_OnSceneEventHandle			= "OnSceneEventHandle";
Diciti.Const.EVENT_OnCloseHelp					= "OnCloseHelp";
Diciti.Const.EVENT_OnIMLoginSuccess				= "OnIMLoginSuccess";
Diciti.Const.EVENT_OnStopFly					= "OnStopFly";


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    场景事件类型
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.ET_CAMERA_MODIFY           =0;
Diciti.Const.ET_MAP_READY               =1;
Diciti.Const.ET_CAMERA_PATH_FINISH      =2;     //相机路径结束
Diciti.Const.ET_CAMERA_PATH_CANCEL      =3;     //相机路径被取消
Diciti.Const.ET_FIRST_TIME_RENDER       =4;     //第一次绘制
Diciti.Const.ET_NEED_SEARCH_POI         =5;     //相机停留在某处,需要触发周边POI的搜索
Diciti.Const.ET_FLY_FINISHED            =6;     //飞到目标点
Diciti.Const.ET_CREATE_CHARACTER        =7;     //创建角色



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    控件初始化错误类型
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.ERROR_BROWSER_NOT_SUPPORT   = 0;        //不支持该浏览器
Diciti.Const.ERROR_MEMORY_NOT_ENOUGH     = 1;        //当前系统内存不够运行本程序
Diciti.Const.ERROR_OPENGL_INVALID        = 2;        //OpenGL版本过低
Diciti.Const.ERROR_ACTIVEX_INVALID       = 3;        //插件没有正常安装
Diciti.Const.ERROR_DIRECTX_INVALID       = 4;        //需要DirextX8.0以上的版本支持
Diciti.Const.ERROR_UPDATE_FAILED         = 5;        //文件更新失败
Diciti.Const.ERROR_INSTANCE_EXIST        = 6;        //已经有一个实例在运行
Diciti.Const.ERROR_CONTAINER_INVALID     = 7;        //控件容器无效   



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    城市ID
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.CITY_BEIJING   = 1;    //北京
Diciti.Const.CITY_MACAU     = 2;    //澳门
Diciti.Const.CITY_NANNING   = 3;    //南宁
Diciti.Const.CITY_TANGSHAN  = 4;	//唐山
Diciti.Const.CITY_YANGZHOU  = 5;	//扬州

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    IM系统常量
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Const.IM_ALL_USER_ID     = -1;       //“所有人”的ID
Diciti.Const.IM_SYSTEM_MESSAGE  = -2;       // 系统消息

var TRUE    = 1;
var FALSE   = 0;

var IO_TYPE_NET_FILE = 0;
var IO_TYPE_NET_DBMS = 1;


__dicitiRegisterNamespaces("Diciti.Core");

Diciti.Core.container = null; 


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    VirtualChina Interface (VI) Functions
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

var Class = {
   create: function() {
     return function() {
       this.initialize.apply(this, arguments);
     }
   }
} 

Diciti.Core.VI = Class.create();

Diciti.Core.VI.prototype = 
{
	initialize: function(){
	    this.fnErrorHandler = null;
		this.isControlValid = false;
	},

	handleError: function(e){
		if(this.fnErrorHandler)
			this.fnErrorHandler.apply(e);
	},
	
	setErrorHandler: function(fn){
	    this.fnErrorHandler = fn;
	},

	TestInterface: function(){
		try
		{
			ocxvirtualchina.TestInterface();
			this.isControlValid = true;
			return true;
		}  
		catch(e)
		{
			this.isControlValid = false;
			return false;
		}
	},

	Load: function(flag){
		try{
				var ret = ocxvirtualchina.Load(flag); 
				this.isControlValid = (ret == FALSE)? false: true;
				return ret ;
		   }catch(e){ this.handleError(e); }
	},

	Unload: function(){
		try{
		    var ret = ocxvirtualchina.Unload(); 
		    this.isControlValid = false;
			return ret;
		   }catch(e){ this.handleError(e); }
	},

	AddServer: function(st, host, port, remark){
		try{
			return ocxvirtualchina.AddServer(st, host, port, remark); 
		   }catch(e){ this.handleError(e); }
	},

	HideInfoWnd: function(bNav){
		try{
			if(bNav == undefined)
				bNav = 1;
			return ocxvirtualchina.HideInfoWnd(bNav); 
		   }catch(e){ this.handleError(e); }
	},

	DeleteAllCache: function(){
		try{
			return ocxvirtualchina.DeleteAllCache(); 
		   }catch(e){ this.handleError(e); }
	},

	GetOneInstanceExsist: function(){
		try{
			return ocxvirtualchina.GetOneInstanceExsist(); 
		   }catch(e){ this.handleError(e); }
	},

	SetTimeout: function(conn, send, recv){
		try{
			return ocxvirtualchina.SetTimeout(conn, send, recv); 
		   }catch(e){ this.handleError(e); }
	},

	SetCacheVersion: function(ver){
		try{
			return ocxvirtualchina.SetCacheVersion(ver); 
		   }catch(e){ this.handleError(e); }
	},

	SetRenderTimer: function(dwTimer){
		try{
			return ocxvirtualchina.SetRenderTimer(dwTimer); 	
		   }catch(e){ this.handleError(e); }
	},

	SetPostInterval: function(dwSeconds){
		try{
			return ocxvirtualchina.SetPostInterval(dwSeconds); 
		   }catch(e){ this.handleError(e); }
	},

	SetMinAltitude: function(min){
		try{
			return ocxvirtualchina.SetMinAltitude(min); 
		   }catch(e){ this.handleError(e); }
	},

	ShowSohuInfoWnd: function(type, id){
		try{
			return ocxvirtualchina.ShowSohuInfoWnd(type, id); 
		   }catch(e){ this.handleError(e); }
	},

	SetActive: function(bActive){
		try{
			return ocxvirtualchina.SetActive(bActive); 
		   }catch(e){ this.handleError(e); }
	},

	SetEditPoi: function(bEdit, editType){
		try{
			return ocxvirtualchina.SetEditPoi(bEdit, editType); 
		   }catch(e){ this.handleError(e); }
	},

	SetCameraCartesian: function(eyeX, eyeY, eyeZ, dirX, dirY, dirZ){
		try{
				return ocxvirtualchina.SetCameraCartesian(eyeX, eyeY, eyeZ, dirX, dirY, dirZ); 
		   }
		catch(e){ 
		   this.handleError(e);
		 }
	},

	SetCameraSphere: function(longitude, latitude, altitude){
		try{
			return ocxvirtualchina.SetCameraSphere(longitude, latitude, altitude); 
		   }
		catch(e){ 
		   this.handleError(e);
		 }
	},

	SetLookPosCartesian: function(x, y, z, bTorch){
		try{
			return ocxvirtualchina.SetLookPosCartesian(x, y, z, bTorch? bTorch: 0) ; 
		   }
		catch(e){ 
		   this.handleError(e);
		 }      
	},

	RunWithPathData: function(pid){
		try{
			return ocxvirtualchina.RunWithPathData(pid); 
		   }catch(e){ this.handleError(e); }
	},

	RunWithPathFile: function(pathFile){ 
		try{
			return ocxvirtualchina.RunWithPathFile(pathFile); 
		   }catch(e){ this.handleError(e); }
	},

	AddSearchPOI: function(x, y, z, 
			poiType, poiId, texId, typeId, 
			poiName, poiInfo, data){
			
		try{
			data = data || "";        
			return ocxvirtualchina.AddSearchPOI(x, y, z, poiType, poiId, texId, typeId, poiName, poiInfo, data); 
		   }catch(e){ this.handleError(e); }
	},

	CleanSearchPOI: function(){
		try{
			return ocxvirtualchina.CleanSearchPOI(); 
		   }catch(e){ this.handleError(e); }
	},

	ClickSearchPOI: function(index, bTorch){
		try{
			ocxvirtualchina.HideInfoWnd();
			return ocxvirtualchina.ClickSearchPOI(index, bTorch); 
		   }catch(e){ this.handleError(e); }
	},

	AddTagCartesian: function(x, y, z, tagId, texId, tagName, tagInfo){
		try{
			return ocxvirtualchina.AddTagCartesian(x, y, z, tagId, texId, tagName, tagInfo); 
		   }catch(e){ this.handleError(e); }
	},

	RemoveTag: function(tagId){
		try{
			return ocxvirtualchina.RemoveTag(tagId); 
		   }catch(e){ this.handleError(e); }
	},

	MapTagID2PID: function(tagId, pid){
		try{
			return ocxvirtualchina.MapTagID2PID(tagId, pid); 
		   }catch(e){ this.handleError(e); }
	},

	SetDebugMode: function(bDebug){
		try{
			return ocxvirtualchina.SetDebugMode(bDebug); 
		   }catch(e){ this.handleError(e); }
	},

	SetURL: function(type, url){
		try{
			return ocxvirtualchina.SetURL(type, url); 
		   }catch(e){ this.handleError(e); }
	},



	ShowAddTagHelp: function(bShow){
		try{
			return ocxvirtualchina.ShowAddTagHelp(bShow); 
		   }catch(e){ this.handleError(e); }
	},

	GetVersion: function(){
		try{
			return ocxvirtualchina.GetVersion(); 
		   }catch(e){ this.handleError(e); }
	},

	SetVersion: function(version){
		try{
			return ocxvirtualchina.SetVersion(version); 
		   }catch(e){ this.handleError(e); }
	},

	RemoveTagByPoiType: function(typeId){
		try{
			return ocxvirtualchina.RemoveTagByPoiType(typeId); 
		   }catch(e){ this.handleError(e); }
	},

	ShowInfoWindow: function(url, sizeX, sizeY, spaceX, spaceY, rounder, bLazyShow){
		try{ 
			if(typeof bLazyShow == "undefined")
				bLazyShow = 0;
			return ocxvirtualchina.ShowInfoWindow(url, sizeX, sizeY, spaceX, spaceY, rounder, bLazyShow); 
		   }catch(e){ this.handleError(e); }
	},

	SetThroughput: function(rate) {
		try{ 
			return ocxvirtualchina.SetThroughput(rate);
		   }catch(e){ this.handleError(e); }
	},

	ShowHideRoad: function( bShow)	 {
		try{ 
			return ocxvirtualchina.ShowHideRoad(bShow);
		   }catch(e){ this.handleError(e); }
	},

	ShowHideSubway: function( bShow)	 {
		try{ 
			return ocxvirtualchina.ShowHideSubway(bShow);
		   }catch(e){ this.handleError(e); }
	},

	ShowHideOlympic: function( bShow)	 {
		try{ 
			return ocxvirtualchina.ShowHideOlympic(bShow);
		   }catch(e){ this.handleError(e); }
	},

	HighlightOlympic: function( index)	 {
		try{ 
			return ocxvirtualchina.HighlightOlympic(index);
		   }catch(e){ this.handleError(e); }
	},

	SetLanguage: function(lang) {
		try{ 
			return ocxvirtualchina.SetLanguage(lang);
		   }catch(e){ this.handleError(e); }
	},

	HighlightSubway: function(index) {
		try{ 
			return ocxvirtualchina.HighlightSubway(index);
		   }catch(e){ this.handleError(e); }
	},

	AddFavoriteCamera: function(favId, cx, cy, cz, dx, dy, dz) {
		try{ 
			return ocxvirtualchina.AddFavoriteCamera(favId, cx, cy, cz, dx, dy, dz);
		   }catch(e){ this.handleError(e); }
	},

	PlayFavorite: function(favId, dir){
		try{ 
			return ocxvirtualchina.PlayFavorite(favId, dir);
		   }catch(e){ this.handleError(e); }
	},

	CleanFavoriteCamera: function() {
		try{ 
			return ocxvirtualchina.CleanFavoriteCamera();
		   }catch(e){ this.handleError(e); }
	},

	GetCameraCartesian: function() {
		try{ 
			ocxvirtualchina.GetCameraCartesian();
			
			var a = [];
			a[0] = ocxvirtualchina.cx;
			a[1] = ocxvirtualchina.cy;
			a[2] = ocxvirtualchina.cz;
			a[3] = ocxvirtualchina.dx;
			a[4] = ocxvirtualchina.dy;
			a[5] = ocxvirtualchina.dz;
			
			return a;
		   }catch(e){ this.handleError(e); }
			
		return null;
	},

	Base64Encode: function(src) {
		try{ 
			return ocxvirtualchina.Base64Encode(src);
		   }catch(e){ this.handleError(e); }
	},

	Base64Decode: function(src) {
		try{ 
			return ocxvirtualchina.Base64Decode(src);
		   }catch(e){ this.handleError(e); }
	},

	SetCurrentTag: function(tagId) {
		try{ 
			return ocxvirtualchina.SetCurrentTag(tagId);
		   }catch(e){ this.handleError(e); }
	},

	AddTextCartesian: function(x, y, z, sName, vDis){
		try{ 
			return ocxvirtualchina.AddTextCartesian(x, y, z, sName, vDis);
		   }catch(e){ this.handleError(e); }
	},

	GetCurrentSearchPos: function(){
		try{ 
			   var c = [];
			   ocxvirtualchina.GetCurrentSearchPos()
			   c[0] = ocxvirtualchina.x;
			   c[1] = ocxvirtualchina.y;
			   c[2] = ocxvirtualchina.z;
			   
			   return c;
			   
		   }catch(e){ this.handleError(e); }
		
		return null;   
	},

	GetPhysicalMemory: function(b) {
		try{ 
			   return ocxvirtualchina.GetPhysicalMemory(b);
		   }catch(e){ this.handleError(e); }
	},

	CheckOpenGL: function() {
		try{ 
			   return ocxvirtualchina.CheckOpenGL();
		   }catch(e){ this.handleError(e); }
	},

	SetPoiVisibleDistance: function(pvd)
	{
		try{
			   return ocxvirtualchina.SetPoiVisibleDistance(pvd);
		   }catch(e){ this.handleError(e); }
	},

	OpenURL: function(url, ext)
	{
		try{
			   return ocxvirtualchina.OpenURL(url,ext);
		   }catch(e){ this.handleError(e); }
	},

	SetMaxWindowNum: function(nWindow)
	{
		try{
			   return ocxvirtualchina.SetMaxWindowNum(nWindow);
		   }catch(e){ this.handleError(e); }
	},

	SetCity: function(city) 
	{
		try{
			   return ocxvirtualchina.SetCity(city);
		   }catch(e){ this.handleError(e); }
	},

	SetMacauPlan: function(plan)
	{
		try{
			   return ocxvirtualchina.SetMacauPlan(plan);
		   }catch(e){ this.handleError(e); }
	},

	SetPoiSize: function(tagId, size)
	{
		try{
			   return ocxvirtualchina.SetPoiSize(tagId, size);
		   }catch(e){ this.handleError(e); }
	},

	SetPoiName: function(tagId, poiName)
	{
		try{
			   return ocxvirtualchina.SetPoiName(tagId, poiName);
		   }catch(e){ this.handleError(e); }

	},

	SetPoiInfo: function(tagId, poiInfo)
	{
		try{
			   return ocxvirtualchina.SetPoiInfo(tagId, poiInfo);
		   }catch(e){ this.handleError(e); }
	},

	FlyAroundCartesian: function(x, y, z)
	{
		try{
			   return ocxvirtualchina.FlyAroundCartesian(x, y, z);
		   }catch(e){ this.handleError(e); }

	},

	EnableAutoFlyAround: function(bEnable)
	{
		try{
			   return ocxvirtualchina.EnableAutoFlyAround(bEnable);
		   }catch(e){ this.handleError(e); }

	},

	FocusOnShen7: function()
	{
		try{
			   return ocxvirtualchina.FocusOnShen7();
		   }catch(e){ this.handleError(e); }
	},
	
	SetIoType: function(byType)
	{
		try{
			   return ocxvirtualchina.SetIoType(byType);
		   }catch(e){ this.handleError(e); }
	},

	IM_SetChatServerInfo: function(host, port)
	{
		try{
			   return ocxvirtualchina.IM_SetChatServerInfo(host, port);
		   }catch(e){ this.handleError(e); }
	},

	IM_Login: function(userName, userPass, userFace, modelId)
	{
		try{
			   return ocxvirtualchina.IM_Login(userName, userPass, userFace, modelId);
		   }catch(e){ this.handleError(e); }
	},

	IM_Logout: function()
	{
		try{
			   return ocxvirtualchina.IM_Logout();
		   }catch(e){ this.handleError(e); }
	},

	IM_SendMessage: function(userId, msg, bPrivate)
	{
		try{
			   return ocxvirtualchina.IM_SendMessage(userId, msg, bPrivate);
		   }catch(e){ this.handleError(e); }
	},

	IM_GetMessage: function()
	{
		try{
			   return ocxvirtualchina.IM_GetMessage();
		   }catch(e){ this.handleError(e); }
	},

	IM_GetUserList: function()
	{
		try{
			   return ocxvirtualchina.IM_GetUserList();
		   }catch(e){ this.handleError(e); }
	},

	IM_ChangeUserName: function(userName)
	{
		try{
			   return ocxvirtualchina.IM_ChangeUserName(userName);
		   }catch(e){ this.handleError(e); }
	},

	IM_ChangeUserFace: function(userFace)
	{
		try{
			   return ocxvirtualchina.IM_ChangeUserFace(userFace);
		   }catch(e){ this.handleError(e); }
	},

	IM_SetUserTalk: function(userName, msg)
	{
		try{
			   return ocxvirtualchina.IM_SetUserTalk(userName, msg);
		   }catch(e){ this.handleError(e); }
	},

	IM_FlyToUser: function(userName)
	{
		try{
			   return ocxvirtualchina.IM_FlyToUser(userName);
		   }catch(e){ this.handleError(e); }
	},

	IM_SetUserAction: function(animation)
	{
		try{
			   return ocxvirtualchina.IM_SetUserAction(animation);
		   }catch(e){ this.handleError(e); }
	},

	IM_GetUserNameById: function(userId)
	{
		try{
			   return ocxvirtualchina.IM_GetUserNameById(userId);
		   }catch(e){ this.handleError(e); }
	}
}

var __v = new Diciti.Core.VI();

/*
__v.setErrorHandler(function(){
    if(typeof this == 'object' && this.message)
        top.status = this.message;
    else
        top.status = this;    
})
*/

Diciti.Core.IsFunction = function( fn ) 
{
	return !!fn && typeof fn != "string" && !fn.nodeName &&
		fn.constructor != Array && /^[\s[]?function/.test( fn + "" );
}

Diciti.Core.userAgent = navigator.userAgent.toLowerCase();
Diciti.Core.browser = 
{
	version: (Diciti.Core.userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
	safari: /webkit/.test( Diciti.Core.userAgent ),
	opera: /opera/.test( Diciti.Core.userAgent ),
	msie: /msie/.test( Diciti.Core.userAgent ) && !/opera/.test( Diciti.Core.userAgent ),
	mozilla: /mozilla/.test( Diciti.Core.userAgent ) && !/(compatible|webkit)/.test( Diciti.Core.userAgent )
};



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 创建对象
 * writeVirtualChina: 创建VirtualChina
 * writeDiciti:       创建Diciti  
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

Diciti.Core.CreateVirtualChina = function(clsid, codebase)
{
    var objStr =  "<object id='ocxvirtualchina' "
                + "' style='width:0;height:0"
                + "' classid='clsid:" + clsid 
                + "' onmousewheel='event.returnValue=false;'>"
                + "</object>";
                
    Diciti.Core.container.innerHTML = objStr;
}

Diciti.Core.WatchInstall = function(fnCallback)
{
    if(!fnCallback || this.CheckVersion())
        return;
        
    var pThis = this; 
    pThis.timerCheckVersion = setInterval(function(){
        if(pThis.CheckVersion())
        {
            clearInterval(pThis.timerCheckVersion);
            top.status = Diciti.Const.GetString("TXT_INSTALL_FINISH");
            fnCallback.apply(null);
        }
    }, 1000);    
}

Diciti.Core.CreateDicitiLoader = function(fnCallback)
{
    if(this.CheckVersion())
        return;
    
    this.WatchInstall(fnCallback);
    
    if(location.href.indexOf("#setup") == -1)
        location.replace(location.href + "#setup");
        
    top.status = Diciti.Const.GetString("TXT_INSTALLING");  
    var dicitiContainer = document.createElement("div");  
    dicitiContainer.style.display = "none";
    var objStr = "<object id='dLoader' classid='clsid:" + CFG.DicitiLoader.clsid + "' codebase='../../js/s7/" + CFG.DicitiLoader.codebase + "'></object>";
	dicitiContainer.innerHTML = objStr;
	document.body.appendChild(dicitiContainer);
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 检查用户是否安装了最新版本的插件
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Diciti.Core.CheckVersion = function(forward)
{
	var bRet = false;
	try
	{
	        var dLoader = new ActiveXObject(CFG.Diciti.progid);
            if(typeof dLoader.GetDicitiVersion != "undefined")
		            bRet = true;
	        
	        if(bRet && !!forward)
	            window.location.replace(forward);  //禁止history
    }
	catch(e)
	{ 
	}
	
	return bRet;
}



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 初始化VirtualChina控件
 * 参数： Configuration配置对象 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
Diciti.Core.InitVirtualChina = function(options)
{
    var pThis = this;
    if(!options.container)
        throw Diciti.Const.ERROR_CONTAINER_INVALID;
    Diciti.Core.container = options.container; 


    //检测浏览器
    if(!pThis.browser.msie)
        throw Diciti.Const.ERROR_BROWSER_NOT_SUPPORT;
    
    //检查DICITI控件
    if(!pThis.CheckVersion())	
        throw Diciti.Const.ERROR_ACTIVEX_INVALID;

    //创建VirtualChina控件
    pThis.CreateVirtualChina(CFG.VirtualChina.clsid)
    
    //监测系统物理内存
    if(__v.GetPhysicalMemory() < (400 * 1024 * 1024) )
        if(!confirm( Diciti.Const.GetString("TXT_MEMORY_CONFIRM") ))
           throw Diciti.Const.ERROR_MEMORY_NOT_ENOUGH;
  
    //检测OpenGL版本
    if(__v.CheckOpenGL() == 0)   
        throw Diciti.Const.ERROR_OPENGL_INVALID; 

    if(typeof _city_ == "undefined")
        __v.SetCity(Diciti.Const.CITY_BEIJING);
    else
        __v.SetCity(_city_);

    //事件处理
    ocxvirtualchina.attachEvent("ConnectionEvent", pThis.EventHandler);    

    
    //服务器列表
    __v.AddServer('Login', CFG.Host, CFG.Port, '')
    __v.Load(0);    
    __v.SetIoType(CFG.IO);
    for(var i=0; i<CFG.URL.length; i++)
		__v.SetURL(CFG.URL[i][0], '/' + CFG.URL[i][1] + '/' );
    
    __v.SetMinAltitude(CFG.MinAltitude)
    __v.SetRenderTimer(CFG.Interval.render)
    __v.SetTimeout(CFG.Timeout.conn, CFG.Timeout.send, CFG.Timeout.recv)
    __v.SetMaxWindowNum(CFG.MaxWindowNum);
    __v.AddServer('Data', CFG.DataServer[0], CFG.DataServer[1], '')
    __v.SetLanguage(__dl? 0:1);
    var bRet = __v.Load(1);
    if(bRet == 0)
         throw Diciti.Const.ERROR_INSTANCE_EXIST;
    
    __v.HideInfoWnd();
    
    ocxvirtualchina.style.width = "100%";
    ocxvirtualchina.style.height = "100%";
    
    if(Diciti.Core.IsFunction(options.fnSuccess))
        options.fnSuccess.call();           
}

Diciti.Core.ShowMessage = function(msg)
{
    Diciti.Core.container.innerHTML = "<p>" + msg + "</p>";    
}

Diciti.Core.InitVirtualChina2 = function(options)
{
    try
    {
	    this.InitVirtualChina(options);
	}
    catch(e)
    {
        if(options.fnError)
            options.fnError.apply(e);
            
        switch(e) 
        {
        case Diciti.Const.ERROR_ACTIVEX_INVALID:
            if(options.setupURL)
                location.href = options.setupURL;
            break;
        	
        case Diciti.Const.ERROR_DIRECTX_INVALID:
            this.ShowMessage(Diciti.Const.GetString("TXT_NEED_UPDATE_DIRECTX"));
            break;

        case Diciti.Const.ERROR_UPDATE_FAILED:
            this.ShowMessage(Diciti.Const.GetString("TXT_UPDATE_FILE_FAILED"));
            break;

        case Diciti.Const.ERROR_INSTANCE_EXIST:
            this.ShowMessage(Diciti.Const.GetString("TXT_INSTANCE_EXIST"));
            break;

         case Diciti.Const.ERROR_MEMORY_NOT_ENOUGH:
            this.ShowMessage(Diciti.Const.GetString("TXT_MEMORY_NOT_ENOUGH"));
            break;
            
       default:
            if(typeof e == 'object' && e.message)    
                this.ShowMessage(e.message);
            else
                this.ShowMessage(Diciti.Const.GetString("TXT_UNKNOWN_ERROR"));
            break;
        } 
        
        if(options.watch)
            this.WatchInstall(function(){
                location.reload();
            });
        
        return false;   
    }
    
    return true;
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 控件事件处理函数
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 Diciti.Core.EventHandler = function()
 {
    this.eventName = arguments[0];  
    this.eventCallbackName = "fn" + eventName;
    try{
        this.eventCallback = eval(eventCallbackName);
    }
    catch(e){
        return;
    }
    
    if(eventCallback)
        eventCallback.apply(null, arguments);
 }





__dicitiRegisterNamespaces("Diciti.Camera", "Diciti.Utils");



Diciti.Camera.GotoPos = function()
{
    var a = arguments;
    var argc = a.length;
    if(argc == 0)
        return;
    
    //Object, Array
    if(argc == 1)
    {
        var p = a[0];
        if(!p)
            return;
            
        var plen = p.length;
        if(plen == undefined)   //Object {x, y, z, cx, cy, cz, dx, dy, dz}
        {
            if(p.cx && p.cy && p.cz && p.dx && p.dy && p.dz)
            {
                __v.SetCameraCartesian(p.cx, p.cy, p.cz, p.dx, p.dy, p.dz);   
                this.options.target = null;
            }    
            else if(p.x && p.y && p.z)
            {
                __v.SetLookPosCartesian(p.x, p.y, p.z);
                this.options.target = [p.x, p.y, p.z];
            }    
        }
        else    //Array
        {
            if(plen == 3)   // [x,y,z]
            {
                __v.SetLookPosCartesian(p[0], p[1], p[2]);
                this.options.target = p;
            }    
            else if(plen == 6)  // [cx, cy, cz, dx, dy, dz]
            {
                __v.SetCameraCartesian(p[0], p[1], p[2], p[3], p[4], p[5]);    
                this.options.target = null;
            }    
            else if(plen == 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])
                {
                    __v.SetCameraCartesian(p[3], p[4], p[5], p[6], p[7], p[8]);
                }    
                else if(p[0] && p[1] && p[2])
                {
                    __v.SetLookPosCartesian(p[0], p[1], p[2]);         
                }    
            }    
        }
    }
    else if(argc == 3)  //x, y, z
    {
        __v.SetLookPosCartesian(a[0], a[1], a[2]);
        this.options.target = a;
    }   
    else if(argc == 6)  //cx, cy, cz, dx, dy, dz
    {
        __v.SetCameraCartesian(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])
        {
            __v.SetCameraCartesian(a[3], a[4], a[5], a[6], a[7], a[8]);
        }    
        else if(a[0] && a[1] && a[2])
        {
            __v.SetLookPosCartesian(a[0], a[1], a[2]);         
        }    
    }   
}

Diciti.Camera.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;
    }    
};

Diciti.Camera.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.GotoPos(target);   
    }
    else
    {
        this.options.Reset();
    }
}

Diciti.Camera.GotoPosWithOptions = function(enableLookAround, target, param, value)
{
    this.options.enableLookAround = enableLookAround;      
    this.options.target = target;      
    this.options.param = param;   
    this.options.value = value;   
    this.GotoPos(target);   
}





//构造参数
Diciti.Utils.ConstructParam = function(p)
{
    return (p.x + "," + p.y + "," + p.z + "," + p.cx + "," + p.cy + "," + p.cz + "," + p.dx + "," + p.dy + "," + p.dz );
}

Diciti.Utils.ConstructParam3 = function(p)
{
    return (p.x + "," + p.y + "," + p.z);
}

Diciti.Utils.ConstructParam6 = function(p)
{
    return ( p.cx + "," + p.cy + "," + p.cz + "," + p.dx + "," + p.dy + "," + p.dz );
}


//添加图标
Diciti.Utils.AddTag = function(x, y, z, poiType, poiId, poiIcon, poiName, poiInfo, data)
{
    __v.AddSearchPOI(x, y, z, poiType, poiId, poiIcon, -1, poiName, cutStr(poiInfo, 30), data );
    return this;
}

Diciti.Utils.AddTag2 = function(x, y, z, poiType, poiId, poiIcon, poiName, poiInfo, data)
{
    return __v.AddSearchPOI(x, y, z, poiType, poiId, poiIcon, -1, poiName, cutStr(poiInfo, 30), data );
}

//清空图标
Diciti.Utils.CleanTag = function()
{
    __v.CleanSearchPOI();
    return this;
}



//显示信息窗口
Diciti.Utils.ShowInfoWindow = function(p)
{
    __v.ShowInfoWindow(p.url, p.sizeX, p.sizeY, p.spaceX, p.spaceY, p.rounder, p.bLazyShow);
}

Diciti.Utils.CreateInlaidWindow = function()
{
    var frameWnd = document.getElementById("inlaid_frame");
    if(!frameWnd)
    {
        frameWnd = document.createElement("DIV");
        frameWnd.innerHTML = "<iframe id='inlaid_frame' style='display:none;position:absolute;z-index:1000;' frameborder='0' scrolling='no'></iframe>";
        document.body.appendChild(frameWnd);	
        frameWnd = document.getElementById("inlaid_frame");
    } 
    var divWnd = document.getElementById("inlaid_div");
    if(!divWnd)
    {
        divWnd = document.createElement("DIV");
        divWnd.innerHTML = "<div id='inlaid_div' style='position:absolute;;z-index:1001;'></div>";
        document.body.appendChild(divWnd);	
        divWnd = document.getElementById("inlaid_div");
    }   
}


//动画路径
Diciti.Utils.RunAni = function(pathFile)
{   
    __v.RunWithPathFile("path_" + pathFile + ".bin");
}
