<!--
	/*	
	全局的定义,
	*/
	var g_isdebug = false;
	var g_qmeshell = null;		//一个全局的shell,主要用于在多次调用时,优化使用
	var im_nouser = "qmeim_0";
	var im_prefix = "qmeim_";

	var im_msg = 1024+1227;		//IM接受信息

	var im_regid = 11;		//lparam是注册得到的ID
	var im_calluser = 12;		//lparam是被呼叫的用户ID
	var im_getid = 13;

function setDebugMode( debug )
{
	g_isdebug = debug;
}
	
function createGQmeShell(  )
{
	destroyGQmeShell();
		try{
		g_qmeshell = new ActiveXObject("sheller.QmeShell");		
		}
		catch(e)
		{
			if( g_isdebug )
				alert( e+" createGQmeShell" );
			g_qmeshell = null
		}
}
function destroyGQmeShell()
{
	try{
		if( g_qmeshell )
			g_qmeshell = null;
			}
		catch( e )
		{
				if( g_isdebug )
					alert( e+" destroyGQmeShell" );
				g_qmeshell = null
		}
}
function getQmeShell()
{
	if( g_qmeshell )
		return g_qmeshell;
	var qmeshell = null;
		try{
			qmeshell = new ActiveXObject("sheller.QmeShell");		
		}
		catch(e)
		{
			if( g_isdebug )
				alert( e+" getQmeShell" );
			qmeshell = null
		}
		return qmeshell;
}
function retQmeShell( qmeshell )
{
	if( qmeshell == g_qmeshell )
		return ;
	try{
		if( qmeshell )
			qmeshell = null;
			}
		catch( e )
		{
				if( g_isdebug )
					alert( e+" retQmeShell" );
				qmeshell = null
		}
	
}
/*
注册窗口
*/
function setRegUser( userid )
{
	var qmeshell = getQmeShell();
	
	if( qmeshell != null )
	{
		qmeshell.postMessage( im_nouser,im_msg,im_regid,userid );
		retQmeShell( qmeshell );
	}
	else
	{
		if( g_isdebug )
			alert( "getQmeshellError setRegUser" );
	}
}
/*
与指定的用户通讯
*/
function callUser( userid )
{
	var qmeshell = getQmeShell();
	if( qmeshell != null )
	{
		//var imaccp = im_prefix+"selfid";
		qmeshell.postMessage( im_nouser,im_msg,im_calluser,userid );
		retQmeShell( qmeshell );
	}
}
/*指定用那个im来通讯*/
function callUserWithFixId( userid, selfid )
{
	var qmeshell = getQmeShell();
	if( qmeshell != null )
	{
		var imaccp = im_prefix+selfid;
		qmeshell.postMessage( "qmeim_8000007",im_msg,im_calluser,userid );
		retQmeShell( qmeshell );
	}
}
/*
获得qmeshell的版本号.
*/
function getVersion()
{
	var qmeshell = getQmeShell();
	if( qmeshell != null )
	{
		//var imaccp = im_prefix+"selfid";
		id = qmeshell.getVersion( );
		retQmeShell( qmeshell );
		return id;
	}

	return 0;
}
/*
如果有qme开着,取得当前登录的用户ID
*/
function getId(  )
{
	var qmeshell = getQmeShell();
	
	if( qmeshell != null )
	{
		//var imaccp = im_prefix+"selfid";
		id = qmeshell.sendMessage( im_nouser,im_msg,im_getid,0 );
		retQmeShell( qmeshell );
		return id;
	}

	return 0;
}
/*检查是否装了qmeeitng*/
function checkInstallQme()
{
	var qmeshell = getQmeShell();
	if( qmeshell != null )
	{		
		id = qmeshell.haveQme( );
		retQmeShell( qmeshell );
		return id;
	}

	return 0;
}
/*检查qmeeitng是否在运行*/
function checkRunningQme()
{
	var qmeshell = getQmeShell();
	if( qmeshell != null )
	{		
		id = qmeshell.isQmeImRunning( );
		retQmeShell( qmeshell );
		return id;
	}

	return 0;
}
/*运行qmeeitng*/
function runQme()
{
	var qmeshell = getQmeShell();
	if( qmeshell != null )
	{		
		id = qmeshell.runQme( );
		retQmeShell( qmeshell );
		return id;
	}

	return 0;
}

function callQme(linkid)
{
	createGQmeShell( );
	if (checkInstallQme() == 1)
	{
		if (checkRunningQme() == 0)
		{
			if (runQme() == 0)
				alert("无法运行qme！");
		}
		else
		{	
			callUser(linkid);
		}
	}
	else
	{
		alert("您尚未安装Qme！请点确定下载安装Qme!(注：请安装在C盘！)");
		window.location.href="http://www.r-cn.net/Qme/qme.exe"
	}
	destroyGQmeShell();				
	return false;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->