//
// NMBrowser
//
// Purpose	Common javascript functions for all web pages.
//
// Note		By placing these functions in a seperate file, browsers have the opportunity
//			to cache compalations of these functions.
//
// Owner	rhawes
//

// Used to submit a form with an action parameter
//

var helpWindow;
var supportWindow;

function openHelpWindow(sURL)
{ 	
        if ( sURL != null && sURL != "" )
		var sHelpURL = sURL;
	else
		var sHelpURL = g_sHelpURL ;  // main page level help url

	helpWindow = window.open(sHelpURL,
		"helpWin","menubar=no,toolbar=no,location=no,resizable=yes,width=800,height=450,top=240,left=200;" );
	helpWindow.focus();
}
 
function openSupportWindow(sSupportURL)
{ 
	if ( !supportWindow || supportWindow.closed)
	{
	 	supportWindow = window.open(sSupportURL, "supportWin");
	} 
	else 
	{
 	 	supportWindow.location =sSupportURL;
	}
	supportWindow.focus();
}

function closeWindow(bPrompt)
{
	if(!bPrompt)
		window.opener = self;
	
	if(!window.closed)
		window.close();
	if(helpWindow && !helpWindow.closed)
		helpWindow.close();
	if(supportWindow && !supportWindow.closed)
		supportWindow.close();
}

var g_iDelay;
var g_idTimer;

function Init(sDelay, sOnLoadProc)
{

   //2008-6-4 修改人：沉
   var url = window.location.href;
       url = url.toLowerCase();
	   if(url.indexOf("cmxlogin.php")!=-1)
	{
	    return;
	   }

	if ((null != sDelay) && ("" != sDelay) )
	{
		var iDelay = sDelay - 0;
		SetTimer(iDelay);
		g_iDelay = iDelay;
		if (IsNS())
		{
			document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.KEYDOWN);
		}
		document.onmousedown = ResetTimer
		document.onmousemove = ResetTimer
		document.onmousewheel = ResetTimer
		document.onkeydown = ResetTimer
	}
	if ((null != sOnLoadProc) && ("" != sOnLoadProc) )
	{
		eval(sOnLoadProc);
	}
}

function IsNS()
{
	var sBrowser = navigator.appName;
	if(document.layers != null)
		return true;	
	else
		return false;
}

function SetTimer(iDelay)
{
	g_idTimer = window.setTimeout("closeWindow(false)", iDelay);
}

function ResetTimer(e)
{
	window.clearTimeout(g_idTimer);
	SetTimer(g_iDelay);
}

function submitAction(sAction)
{
	var elForm = document.NMForm;
	var sURL = elForm.action;	
	elForm.action = SetActionParam(sURL,sAction);
	elForm.submit();
}

function SetActionParam(sURL,sAction)
{
	if ( sURL.match("action") )
	{
                // Checking for action param in the middle of the query string
		var re = /action=.*&/ ;
		if ( sURL.match(re))
		{
			var sURL = sURL.replace(re , "action=" + sAction + "&" );	
		}
		else
		{
                        // Checking for action param at the end of the query string
			var re = /action=.*/ ;
			var sURL = sURL.replace(re, "action=" + sAction  );
		}
	}
	else
	{
		var sURL = sURL + "&action=" + sAction ;		
	}
	return sURL;
}

function GrayOut(sChkBoxId , sFldId)
{
	if ( document.forms("NMForm").elements(sChkBoxId).checked == true )
	{
		document.forms("NMForm").elements(sFldId).style.backgroundColor='';
		document.forms("NMForm").elements(sFldId).disabled = false ;
	}
	else
	{
		document.forms("NMForm").elements(sFldId).disabled = true ;
		document.forms("NMForm").elements(sFldId).style.backgroundColor='gray' ;
	}
}

function selectAllClickHandler()
{
	submitAction("NMSelectAll");
}

function clearClickHandler()
{
	submitAction("NMClear");
}

function clickChangeFldsBtnHandler()
{
	var sAction = "NMChangeFlds&mode=change";
	submitAction(sAction);
}

function clickRevertFldsBtnHandler()
{
	var sAction = "NMChangeFlds&mode=revert";
	submitAction(sAction);
}


function SelectItems(fromList, toList)
{
	var aSelectedItems = new Array();
	
	for (var iFromIndx = 0 , i = 0; iFromIndx < fromList.length ; iFromIndx++ )
	{
		if( fromList.options[iFromIndx].selected == true )
		{
			// create the selected item in the toList
			var oOption = document.createElement("OPTION");
			toList.options.add(oOption);
			oOption.innerText = fromList.options[iFromIndx].innerText;
			oOption.Value = fromList.options[iFromIndx].Value ;
			oOption.selected = true ;
				
			// now remember the copied items
			aSelectedItems[i++] = iFromIndx ;			
		}
	}
	
	// Now delete the copied items from the fromList
	for( var i = aSelectedItems.length - 1; i >= 0 ; i-- )
		fromList.remove(aSelectedItems[i]);
		
	// Now delete the blank item from the toList
	for(var iToIndx = 0 ; iToIndx < toList.length ; iToIndx++ )
	{
		if ( toList.options[iToIndx].Value == "" )
			toList.remove(iToIndx);
	}
				
}

// ------------------ Client Manager access functions -------------------

function LaunchApplication(sUserParams, sApplicationName, sCommandLine, sConnectionSettingsId, sClientVersion, sCreateMsg, sInitMsg, sLaunchMsg)
{
	var oClientMgr = ClientMgrCreate(sClientVersion, sCreateMsg);
	if (oClientMgr == null)
		return null;
	var sParamString = sUserParams + ";ApplicationName=" + sApplicationName + 
	   ";ConnectionSettingID=" + sConnectionSettingsId + ";AsyncInvoke=1;SessionType=1";
	if (sCommandLine != "")
		sParamString += ";AppCommandLine=" + sCommandLine ;
	sRetVal = ClientMgrInvoke(oClientMgr, "ExternalLaunch", sParamString);
	defaultStatus = " ";
	return sRetVal;
}
function RefreshClientMgr(sUserParams, sClientVersion, sCreateMsg, sInitMsg, sRefreshDone) 
{
	var oClientMgr = ClientMgrCreate(sClientVersion, sCreateMsg);
	if (oClientMgr == null)
		return;
	var sRetVal = ClientMgrInit(oClientMgr, sUserParams, sInitMsg);
	defaultStatus = " ";
	if (sRefreshDone != "")
		alert(sRefreshDone);

}


function RefreshClientMgr2(sUserParams, sClientVersion, sCreateMsg, sInitMsg, sRefreshDone) 
{
	//2008-6-4 修改人：沉 
	var oClientMgr = ClientMgrCreate(sClientVersion, sCreateMsg);
	if (oClientMgr == null)
		return;

    var sRetVal = ClientMgrInit(oClientMgr, sUserParams, sInitMsg);

	var sParamString = sUserParams;
	defaultStatus = "";
	var sAppXML = ClientMgrInvoke(oClientMgr, "GetLaunchpadXML", sParamString);
		return(sAppXML);

}

function PasswordToClientMgr(sParamString, sClientVersion, sCreateMsg, sInitMsg) 
{
	var oClientMgr = ClientMgrCreate(sClientVersion, sCreateMsg);
	if (oClientMgr == null)
		return; 
	var sUser = document.NMForm.LoginName2.value;  //修改时间2007-12-25 修改人:沉 原代码: document.NMForm.LoginName.value;
	var sPassword = document.NMForm.Password2.value; //修改时间2007-12-25 修改人:沉 原代码: document.NMForm.Password.value;
	var sDomain = document.NMForm.Domain.value;
	sParamString += ";UserName=" + sUser + ";DomainName=" + sDomain + ";Password=" + sPassword;
	if (document.NMForm.SaveCookie != null && document.NMForm.SaveCookie.checked)
		sParamString += ";Prop_Persist_Passwd=1";		
	var sRetVal = ClientMgrInit(oClientMgr, sParamString, sInitMsg);
}

function ClientMgrInit(oClientMgr, sUserParams, sStatusMsg) 
{
	var sParamString = sUserParams;
	defaultStatus = sStatusMsg;
	var sRetVal = ClientMgrInvoke(oClientMgr, "InitLaunchpad", sParamString);
	defaultStatus = " ";
}

function GotoHomePage(sUserParams, sPageId, sClientVersion, sCreateMsg, sInitMsg, sGetAppMsg)
{

    var s = RefreshClientMgr(sUserParams, sClientVersion, sCreateMsg, sInitMsg, "");//2008-6-4 修改人：沉

	var oClientMgr = ClientMgrCreate(sClientVersion, sCreateMsg);
	if (oClientMgr == null)
		return;

	var sParamString = sUserParams;
	defaultStatus = sGetAppMsg;
	var sAppXML = ClientMgrInvoke(oClientMgr, "GetLaunchpadXML", sParamString);
	defaultStatus = " ";
	var sAction = "CmxCheckLogin.php"; //2008-6-4 修改人：沉
	if (sPageId != "")
		sAction += "?verify=true&from=home&pgid=" + sPageId;
	if (document.NMHiddenForm != null)
	{
		try{document.getElementById("RefreshClient").href="#";}catch(e){};
		document.NMHiddenForm.action = sAction;
		document.NMHiddenForm.HiddenOne.value=sAppXML;
		document.NMHiddenForm.submit();
	}

}


// --- Connection mgmt functions
function ManageTSEConnections(sParamString, sClientVersion, sActionType, chkBoxGrp, sStatusCreate)
{
	var timeout = 500;
	if(chkBoxGrp.length == null && chkBoxGrp.checked)
	{
		var sValue = chkBoxGrp.value;
		if(IsNative(sValue, false))
		{
			NativeLaunchHelper(sValue);
		}
		else	
		{
			var oClientMgr = ClientMgrCreate(sClientVersion, sStatusCreate);
			timeout += TSESessionAction(oClientMgr, sActionType, sValue, sParamString);
			window.setTimeout("window.document.NMForm.submit()", timeout);
		}
		return;
	}
	for (var idx=0; idx < chkBoxGrp.length; idx++)
	{
		if(chkBoxGrp[idx].checked == true)
		{
			var sValue = chkBoxGrp[idx].value;
			if(IsNative(sValue, false))
			{
				NativeLaunchHelper(sValue);
			}
			else
			{
				var oClientMgr = ClientMgrCreate(sClientVersion, sStatusCreate);
				timeout += TSESessionAction(oClientMgr, sActionType, sValue, sParamString);
			}
		}
	}
	
	if (timeout > 15000)
		timeout = 15000;
	window.setTimeout("window.document.NMForm.submit()", timeout);
	
}
function IsNative(sServerName_SessionID_AppID_Native, bSearchParams)
{
	if(bSearchParams)
		return ((sServerName_SessionID_AppID_Native.search("native=")==-1)? false:true);
	else
	{
		var aArray = sServerName_SessionID_AppID_Native.split("_");
		if(aArray[3]=="true")
			return true;
		else
			return false;
	}
}
function TSESessionAction(oClientMgr, sActionType, sValue, sParamString)
{
	var aNames = sValue.split("_");
	var timeout = 0;
	if (aNames.length > 2)
	{
		var sSessionParams = "ServerName=" + aNames[0] + ";WTSSessionId=" + aNames[1] + ";ApplicationName=" + aNames[2];
		var sRetVal = "";
		switch(sActionType)
		{
			case "disconnect":	
				sRetVal = ClientMgrInvoke(oClientMgr, "DisconnectSession", sSessionParams);
				timeout = 300;
				break;
			case "reconnect":	
				sParamString += ";" + sSessionParams;
				sParamString += ";AsyncInvoke=1;SessionType=2";
				sRetVal = ClientMgrInvoke(oClientMgr, "ExternalLaunch", sParamString);
				timeout = 10000;
				break;
			case "logoff":		
				sRetVal = ClientMgrInvoke(oClientMgr, "EndSession", sSessionParams);
				timeout = 500;
				break;
		}
	}
	return timeout;
}

// comparing version numbers
function IsCurrVersionGreaterOrEqual(string1, string2)
{
	var aString1 = string1.split(".");
	var aString2 = string2.split(".");
	
	for(var i=0; (i < aString1.length) && (i < aString2.length) ; i++)
	{
		var iSub1 = parseInt(aString1[i]);
		var iSub2 = parseInt(aString2[i]);
		
		if(isNaN(iSub1))
		{
			break;
		}
		if(isNaN(iSub2))
		{
			break;
		}
			
		if(iSub1 > iSub2)
			return true;  // string1 > string2
		if(iSub1 < iSub2)
			return false; // string1 < string2
	}
	
	if(aString1.length >= aString2.length)
		return true;   // string1 >= string2

	return false;	// string1 < string2
}

function RetrieveValue(sName, sKeyValue)
{
	var aPairs = sKeyValue.split(";");
	var sNameLower = sName.toLowerCase();
	for(var i in aPairs)
	{
		var aValues = aPairs[i].split("=");
		if (aValues[0].toLowerCase() == sNameLower)
			return aValues[1];
	}
	return null;
}

function GetLaunchpadPref(sUserParams, sCMVersion, sCreate, sPrefName)
{
	var oClientMgr = ClientMgrCreate(sCMVersion, sCreate);
	if (oClientMgr == null)
	{
		return null;
	}
	var sParamString = sUserParams + ";Prop_LaunchpadPreferenceName=" + sPrefName;
	sRetVal = ClientMgrInvoke(oClientMgr, "GetLaunchpadPref", sParamString);
	return sRetVal;
}

function SetLaunchpadPref(sUserParams, sCMVersion, sCreate, sPrefName, sPrefValue)
{
	var oClientMgr = ClientMgrCreate(sCMVersion, sCreate);
	if (oClientMgr == null)
	{
		return null;
	}
	var sParamString = sUserParams + ";Prop_LaunchpadPreferenceName=" + sPrefName + ";Prop_LaunchpadPreferenceValue=" + sPrefValue;
	ClientMgrInvoke(oClientMgr, "SetLaunchpadPref", sParamString);
}
	
function SetReconnectLabel(sUserParams, sCMVersion, sCreate, sElement, sNever, sAlways, sDefault)
{
	var sRetVal = GetLaunchpadPref(sUserParams, sCMVersion, sCreate, "ReuseDisconnectedSessions");
	var sLabel;
	switch(sRetVal)
	{
		case "0":
			sLabel = sNever; break;
		case "1":
			sLabel = sAlways; break;
		default:
			sLabel = sDefault; break;
	}
	var el = document.all(sElement);
	if (null != el)
		el.innerText = sLabel;
}

function SetReconnectDropDown(sUserParams, sCMVersion, sCreate, sElement, sDefault)
{
	var sRetVal = GetLaunchpadPref(sUserParams, sCMVersion, sCreate, "ReuseDisconnectedSessions");
	if (sRetVal == "")
		sRetVal = sDefault;
	var el = document.forms("NMForm").elements(sElement);
	if (null != el)
		el.value = sRetVal;
}


function UpdateReconnectPref(sUserParams, sCMVersion, sCreate, sElement, sNextPageURL)
{
	var el = document.forms("NMForm").elements(sElement);
	if (null != el)
	{
	    var sValue = el.value + "";
	    SetLaunchpadPref(sUserParams, sCMVersion, sCreate, "ReuseDisconnectedSessions", sValue);
	    window.location.href = sNextPageURL;
	}
}

var nScreenMargin = 65;
function CJCLaunch(sApplicationName)
{
	
	var sClientId = NativeLaunch_GetClientId();

	var sURL = "CmxNativeRDPLauncher.php?pgid=CJCLaunch&action=launch&clientid="+sClientId ;
	sURL +=  "&AppName=" + sApplicationName;
	var sUsrAgnt = navigator.userAgent;
	var windowWidth = 25;
	var windowHeight = 25;
	if(sUsrAgnt.search("Windows")!=-1)
	{
		windowWidth = 980;
		windowHeight = 665;
	}
	sURL += "&WindowWidth=" + windowWidth;
	sURL += "&WindowHeight=" + windowHeight;
	var sFeatures = "menubar=no,toolbar=no,location=no,scrollbars=yes,left=0,top=0,screenX=0,screenY=0";
	sFeatures += ",width=" + windowWidth;
	sFeatures += ",height=" + windowHeight;
	sFeatures += ",resizable=yes";
	var AppWindow = window.open(sURL, "_blank", sFeatures);
	if(sUsrAgnt.search("Linux")!=-1)
	{
		AppWindow.setTimeout('self.close()', 5000);
	}
	AppWindow.focus();
	return "";
}

function CJCReconnect(sServerSession)
{
	var sURL = "CmxCJCLauncher.php?pgid=CJCReconnect";
	sURL += "&ServerSession=" + sServerSession;
	var windowWidth = 430;
	var windowHeight = 260;
	sURL += "&WindowWidth=" + windowWidth;
	sURL += "&WindowHeight=" + windowHeight;
	var sFeatures = "menubar=no,toolbar=no,location=no,scrollbars=yes,left=0,top=0,screenX=0,screenY=0";
	sFeatures += ",width=" + windowWidth;
	sFeatures += ",height=" + windowHeight;
	sFeatures += ",resizable=yes";
	var AppWindow = window.open(sURL, "_blank", sFeatures);
	AppWindow.focus();
	return "";
}

function ManageCJCConnection(sActionType, chkBoxGrp)
{
	var timeout = 500;
	if(chkBoxGrp.length == null && chkBoxGrp.checked)
	{
		var sValue = chkBoxGrp.value;
		if (sActionType == 'reconnect')
		{
			CJCReconnect(sValue);
			timeout += 10000;
		}
	}
	else
	{
		for (var idx=0; idx < chkBoxGrp.length; idx++)
		{
			if(chkBoxGrp[idx].checked == true)
			{
				var sValue = chkBoxGrp[idx].value;
				if (sActionType == 'reconnect')
				{
					CJCReconnect(sValue);
					timeout += 10000;
				}
			}
		}
	}
	if (timeout > 15000)
		timeout = 15000;
	window.setTimeout("window.document.NMForm.submit()", timeout);
}

// -- Multi-Admin Console functions

// To clear out the selected group members if user does not need any

function ClearSelectedGroupMemberForAdminRole()
{
   
   var numOfRadios = document.forms("NMForm").radio1.length;
   
   if(numOfRadios == null)
   var numOfRadios = document.forms("NMForm").radio1.children.length;
   
   if(numOfRadios == 0)
   {
		if(document.forms("NMForm").radio1.checked)
		
			document.forms("NMForm").radio1.checked = false;
			
			
   }
   else
   {
		while(numOfRadios > 0)
		{
				  
				if(document.forms("NMForm").radio1(numOfRadios-1).checked)
				{	
						document.forms("NMForm").radio1(numOfRadios-1).checked = false;
						break;
				}
				numOfRadios = numOfRadios - 1;
		}
   }
}

// To clear out the checkbox on the add group member page for multi-admin

function UncheckGroupMemberClearCheckBox()
{
   var numOfRadios = document.forms("NMForm").radio1.length;
   
   if(numOfRadios == null)    
   
   var numOfRadios = document.forms("NMForm").radio1.children.length;
   
   if(numOfRadios == 0)
   {
		if(document.forms("NMForm").radio1.checked)
			{	
				document.forms("NMForm").radiooff.checked = false;
				
			}
   }
   else
   {
		while(numOfRadios > 0)
		{
				if(document.forms("NMForm").radio1(numOfRadios-1).checked)
				{	
						document.forms("NMForm").radiooff.checked = false;
						break;
				}
				numOfRadios = numOfRadios - 1;
		}
   }
	
}

function KeyPress(bConsole)
{
	if(window.event.keyCode == 13)
	{
		if(!bConsole)
			NMLoginOnSubmit();
		document.NMForm.submit();
	}	
}

function ManageServerAction(sActionType, chkBoxGrp, bLaunchType)
{
	bMacintosh = CheckIfMacintosh();
	
	var sURL = "CmxAppServerAction.php?pgid=CmxPgid_327&LaunchType="+bLaunchType+"&action="+sActionType+"&sesid=";
	if(chkBoxGrp.length == null && chkBoxGrp.checked)
	{
		var sValue = chkBoxGrp.value;
		sURL += sValue;
		window.location = sURL;
		
		return;
	}
	
	if(bMacintosh)
	{
		if(CheckedCount(chkBoxGrp) > 1)
		{
			alert(g_MacintoshWarning);
			return;
		}	
	}
	
	for (var idx=0; idx < chkBoxGrp.length; idx++)
	{
		if(chkBoxGrp[idx].checked == true)
		{
			var sValue = chkBoxGrp[idx].value;
			sURL += sValue + ",";
		}
	}
	window.location = sURL;
}
function CheckedCount(chkBoxGrp)
{
	var iCount = 0;
	for (var idx=0; idx < chkBoxGrp.length; idx++)
	{
		if(chkBoxGrp[idx].checked == true)
		{
			iCount++;
		}
	}
	return iCount;	
}
function CheckIfMacintosh()
{
	var sUsrAgnt = navigator.userAgent;
	var bMacintosh;
	if(sUsrAgnt.search("Macintosh")==-1)
		return false;
	else
		return true;	
		
}
var sDelimeter = "|";
function ReconnectSessions(sParamString, bNative)
{
	var aParamArray = sParamString.split(sDelimeter);
	for(var i=0;i<aParamArray.length;i++)
	{
		// This to handle the last member of the list.
		if(aParamArray[i]!="")
		{
			if(IsNative(aParamArray[i], true))
			{
				var start = (aParamArray[i].search("native="));
				var j = aParamArray[i].substring((start+7),(start+9));
				var sub = aParamArray[i].search("SessionInfo=");
				var session = aParamArray[i].substring((sub+12),(sub+12+(parseInt(j))));
				NativeLaunchHelper(session);
			}					
			else
			{
			aParamArray[i]+= ";AsyncInvoke=1;SessionType=2";
			var oClientMgr = ClientMgrCreate("2.0.0", "");
			sRetVal = ClientMgrInvoke(oClientMgr, "ExternalLaunch", aParamArray[i]);
		}
	}
	}
	var sURL;
	if(bNative)
		sURL ="window.location ='CmxMultiQuery.php?pgid=CmxPgid_383'";
	else
		sURL ="window.location ='CmxMultiQuery.php?pgid=CmxPgid_327'";
	window.setTimeout(sURL, 6000);
}

function NativeRDPLauncher(strUserName, strDomain, strServerIP, strAppID, strSessionCLSID, strBitmapCache, strCompress, strFullScreen, strColorDepth, strAudioRedirectionMode, strSmoothScroll, strEnableReconnect, strDisconnectedSessionTimeout, strMaxIdleTime, strScreenWidth, strScreenHeight, strRedirectPrinters, strRedirectDrives, strPerformanceFlag, strRDPPort)
{
	try
	{
		MsRdp.AdvancedSettings.BitmapPeristence = parseInt(strBitmapCache);  
	}
	catch(e)
	{	
		alert("Microsoft Terminal Services ActiveX Client (mstscax.dll) is not installed on your computer. This is mandatory for this operation. Please contact your system administrator.");
		window.close();
		return 0;
	}

	MsRdp.AdvancedSettings.Compress = parseInt(strCompress);
	MsRdp.AdvancedSettings.RDPPort = parseInt(strRDPPort);
	MsRdp.AdvancedSettings.RedirectDrives = parseInt(strRedirectDrives);
	MsRdp.AdvancedSettings.RedirectPrinters = parseInt(strRedirectPrinters);
	MsRdp.AdvancedSettings.ContainerHandledFullScreen = 0;
	MsRdp.AdvancedSettings2.SmoothScroll = parseInt(strSmoothScroll);
	MsRdp.AdvancedSettings2.PerformanceFlags = parseInt(strPerformanceFlag);
	MsRdp.AdvancedSettings3.EnableAutoReconnect = 1;
	MsRdp.username = strUserName;	
	MsRdp.Domain = strDomain;
	MsRdp.DesktopWidth = parseInt(strScreenWidth);
	MsRdp.DesktopHeight = parseInt(strScreenHeight);
	MsRdp.ColorDepth = parseInt(strColorDepth);
	MsRdp.SecuredSettings.StartProgram = "RasControl.exe SessionCLSID="+strSessionCLSID+"\\nAppId="+strAppID+"\\nEnableReconnect="+strEnableReconnect+"\\nDisconnectedSessionTimeout="+ strDisconnectedSessionTimeout +"\\nMaxIdleTime="+ strMaxIdleTime +"\\n/Native";
	MsRdp.SecuredSettings.FullScreen = parseInt(strFullScreen);
	
	MsRdp.server = strServerIP;
	MsRdp.connect();
}

//Native method
function NativeReconnect(sActionType, chkBoxGrp)
{
	bMacintosh = CheckIfMacintosh();
	
	var bFlag = 0;
	if(chkBoxGrp.length == null && chkBoxGrp.checked)
	{
		var sValue = chkBoxGrp.value;
		NativeLaunchHelper(sValue);
		bFlag = 1;
	}
	
	if(bMacintosh)
	{
		if(CheckedCount(chkBoxGrp) > 1)
		{
			alert(g_MacintoshWarning);
			return;
		}	
	}
	
	if(bFlag != 1)
	{
		for (var idx=0; idx < chkBoxGrp.length; idx++)
		{		
			if(chkBoxGrp[idx].checked == true)
			{
				var sValue = chkBoxGrp[idx].value;
				NativeLaunchHelper(sValue);
			}
		}
	}
	
}
function NativeLaunchHelper(sSessions)
{
	var sUsrAgnt = navigator.userAgent;

	var sURL = "CmxNativeRDPLauncher.php?pgid=CmxPgid_383&action=reconnect&ServerSession=" + sSessions;

	var windowWidth = 25;
	var windowHeight = 25;

	if(sUsrAgnt.search("Windows")!=-1)
	{
		windowWidth = 980;
		windowHeight = 665;
	}
	
	sURL += "&WindowWidth=" + windowWidth;
	sURL += "&WindowHeight=" + windowHeight;
	var sFeatures = "menubar=no,toolbar=no,location=no,scrollbars=yes,left=0,top=0,screenX=0,screenY=0";
	sFeatures += ",width=" + windowWidth;
	sFeatures += ",height=" + windowHeight;
	sFeatures += ",resizable=yes";

	var AppWindow = window.open(sURL, "_blank", sFeatures);
	
	if(sUsrAgnt.search("Linux")!=-1)
	{
		AppWindow.setTimeout('self.close()',3000);	
	}
}
var g_Flag = 0;

function onDisconnect(id)
{
	if(id == 1) 
	{	
		alert(g_DisconnectWarning);
	}
	g_Flag = 1;
	window.close();
}

function windowClose()
{
  if(g_Flag == 0)
  {
	event.returnValue = g_DisconnectWarning;	
  } 
}

function EnableOrDiableRelayConfigCheckBoxes()
{
	if( document.forms("NMForm").EnableCascadedRelay.checked == true )
	{
		document.forms("NMForm").EnableRDPIFSRouting.disabled = false;
		document.forms("NMForm").EnableHttpRouting.disabled = false;
		document.forms("NMForm").EnableRDPIFSRouting.checked = true;
		document.forms("NMForm").EnableHttpRouting.checked = true;
	}
	else if ( document.forms("NMForm").EnableCascadedRelay.checked == false )
	{
		document.forms("NMForm").EnableRDPIFSRouting.disabled = true;
		document.forms("NMForm").EnableHttpRouting.disabled = true;
		document.forms("NMForm").EnableRDPIFSRouting.checked = false;
		document.forms("NMForm").EnableHttpRouting.checked = false;
	}
}
function InstallDone ( name , result )
{
  alert("The package " + name + " was installed with a result of " + result);
}
function installPlugin(sLinkValue)
{
	var xpi = new Object();
	xpi["TSELinPlugin"] = sLinkValue;
	InstallTrigger.install(xpi,InstallDone);
} 

function DownloadMacPlugin(LinkURL)
{
	window.location = LinkURL;
}



 function down_printerSetup()
{
   //var s = window.confirm("系统提示：\n\n一般情况下，不需要安装此程序。\n只有在使用过程中，发现个别打印机不能正常映射时，才需要安装此程序。\n\n你确定要安装吗？");

   // if(s == true)
   //  {
       window.open("/Depot/TPRDPen.msi");
   //  }
}
