<!--

//Q9WWW v2.0.1
//Last modified : 2000/11/08
//Created by Fencol Yung
//Modified by Wiggins Ching

/////////////////////////////////////////////////////////////////////
// MODIFY THE FOLLOWING LINE TO REFLECT THE ACTUAL Q9WWW SERVER PATH
/////////////////////////////////////////////////////////////////////

var serverPath = "http://www.q9tech.com/q9/q9web/b5/server/";

/////////////////////////////////////////////////////////////////////

var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var bSameDomain = (location.href.substring(0, 21) != serverPath.substring(0, 21));
var bLocalDomain = (location.href.substring(0, 5) == "file:");
var charset = "big5";

var q9win = 0;
var q9TargetWin = window;

var lastInitControl = 0;
var isQ9Opened = 0;
var isPYOpened = 0;
var isCYOpened = 0;

if (bLocalDomain)
	serverPath = "server/";

////////////////////////////////////////////

function OpenQ9(targetControl, serverURL) {

	windowLeft = screen.width - 205;
	windowTop = screen.height - 320;

	if (charset == "gb2312")
		thePage = "q9gb.htm";
	else
		thePage = "q9.htm";
	q9win = window.open(serverURL + thePage + '#charset=' + charset + '&targetControl=' + targetControl, "q9", " toolbar=no,location=no,status=yes,menubar=no,resizable=no,scrollbars=no,width=175,height=250,left=" + windowLeft + ",top=" + windowTop);
	// q9win = window.open(serverURL + thePage + '#charset=' + charset + '&targetControl=' + targetControl, "q9");

	q9win.moveTo(windowLeft, windowTop);

	if (NS4) {
		layerref = 'layers["q9dataLayer"].document.layers["q9dataFrame"]';
	}
	else {
		layerref = 'q9dataFrame';
	}

	q9win.q9TargetWin = q9TargetWin;
}

function GetQ9WinTarget()
{
	if (q9win != 0) {
		if (NS4) {
			return q9win.document.q9char.document.q9form.targetcontrol.value;
		} else {
			return q9win.document.all.q9form.targetcontrol.value;
		}
	}
}

function SetQ9WinTarget(targetControl)
{
	if (q9win != 0) {
		if (GetQ9WinTarget() == "")
			ForceSetQ9WinTarget(targetControl)
	}
}

function ForceSetQ9WinTarget(targetControl)
{
	if (NS4)
		q9win.document.q9char.document.q9form.targetcontrol.value = targetControl;
	else
		q9win.document.all.q9form.targetcontrol.value = targetControl;
}

// Depreciating method
function OpenQ9Win(targetControl)
{
	OpenQ9WWW("big5", "q9", "", targetControl);
}

// Depreciating method
function OpenPYWin(targetControl)
{
	OpenQ9WWW("big5", "py", "", targetControl);
}

// Depreciating method
function OpenCYWin(targetControl)
{
	OpenQ9WWW("big5", "cy", "", targetControl);
}

// Depreciating method
function OpenSpecialQ9Win(charsetName, inputType, targetControl)
{
	OpenQ9WWW(charsetName, inputType, "", targetControl);
}

function OpenQ9WWW(charsetName, inputType, targetLayer, targetControl)
{
	if (!(IE4 || NS4)) {
		alert("This version need IE4 or NS4");
	}
	else {
		if (bSameDomain && (!bLocalDomain)) {
			alert("Q9WWW server path did not initialized or Q9WWW is running in different domain, please see Q9WWW documentation for details.");
			return;
		}

		targetControl = SetTargetObject(targetLayer, targetControl);

		if (charsetName.toUpperCase() == "GB2312")
			charset = "gb2312";
		else
			charset = "big5";

		if (q9win != 0) {
			if (!q9win.closed) {
				SetQ9WinTarget(targetControl);
			} else {
				q9win = 0;
				isQ9Opened = 0;
				isPYOpened = 0;
				isCYOpened = 0;
			}
		}
		if (inputType.toUpperCase() == "PY") {
			if((isQ9Opened == 1) || (isCYOpened == 1)) {
				CloseQ9Win();
			}
			if(isPYOpened == 0) {
				OpenQ9(targetControl, serverPath + "py/");
			}
			isQ9Opened = 0;
			isPYOpened = 1;
			isCYOpened = 0;
		} else if (inputType.toUpperCase() == "Q9"){
			if((isPYOpened == 1) || (isCYOpened == 1)) {
				CloseQ9Win();
			}
			if(isQ9Opened == 0) {
				OpenQ9(targetControl, serverPath + "q9/");
			}
			isPYOpened = 0;
			isQ9Opened = 1;
			isCYOpened = 0;
		}else {
			if((isQ9Opened == 1) || (isPYOpened == 1)) {
				CloseQ9Win();
			}
			if(isQ9Opened == 0) {
				OpenQ9(targetControl, serverPath + "cy/");
			}
			isPYOpened = 0;
			isQ9Opened = 0;
			isCYOpened = 1;
		}
		q9win.focus();
	}
}

function CloseQ9Win()
{
	if (q9win != 0) {
		if (NS4) {
			if (!q9win.closed) {
				q9win.close();
			}
		} else {
			while (!q9win.closed) {
				q9win.close();
			}
		}
		q9win = 0;
		isPYOpened = 0;
		isQ9Opened = 0;
		isCYOpened = 0;
	}
}

// Depreciating method
function SetQ9Target(target)
{
	targetObject = target.form.name + "." + target.name;
	SetQ9WWW("", targetObject)
}

function SetQ9WWW(targetLayer, targetObject)
{
	if (q9win != 0) {
		if (!q9win.closed) {
			targetObject = SetTargetObject(targetLayer, targetObject);
			ForceSetQ9WinTarget(targetObject);
		} else {
			q9win = 0;
			isPYOpened = 0;
			isQ9Opened = 0;
			isCYOpened = 0;
		}
	}
}

function SetTargetObject(targetLayer, targetObject)
{
	if (targetLayer != "") {
		if (NS4) {
			targetObject = "layers." + targetLayer + ".document." + targetObject;
		} else {
			targetObject = "all." + targetLayer + ".document." + targetObject;
		}
	}

	return targetObject;
}

//-->
