﻿function sSearch(sArr,iLength,SearchString) {
	for (i=1 ; i<=iLength ; i++) {
		if (sArr[i-1]==SearchString) {
			return i;
		}
	}
	return 0;
}

function WriteFlash(sVersion,sWidth,sHeight,sFile) {
	document.write(''
		+ '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + sVersion + '" width="' + sWidth + '" height="' + sHeight + '">'
			+ '<param name="movie" value="' + sFile + '.swf" />'
			+ '<param name="quality" value="high" />'
			+ '<embed src="' + sFile + '.swf" width="' + sWidth + '" height="' + sHeight + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" />'
		+ '</object>'
	);
}

function WriteFlash2(sVersion,sWidth,sHeight,sFile,sCallingURL) {
	document.write(''
		+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + sVersion + '" width="' + sWidth + '" height="' + sHeight + '" align="middle">'
			+ '<param name="movie" value="' + sFile + '.swf" />'
			+ '<param name="quality" value="high" />'
			+ '<param name="menu" value="true" />'
			+ '<param name="allowScriptAccess" value="sameDomain" />'
			+ '<param name="allowFullScreen" value="true" />'
			+ '<param name="FlashVars" value="gsCallingURL=' + sCallingURL + '" />'
			+ '<embed src="' + sFile + '.swf" quality="high" menu="true" allowScriptAccess="sameDomain" allowFullScreen="true" FlashVars="gsCallingURL=' + sCallingURL + '" width="' + sWidth + '" height="' + sHeight + '" name="' + sFile + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" align="middle" />'
		+ '</object>'
	);
}

function WriteFlash3(sVersion,sWidth,sHeight,sFile,sCallingURL) {
	document.write(''
		+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + sVersion + '" width="' + sWidth + '" height="' + sHeight + '" id="FlashObjectElement" align="middle">'
			+ '<param name="movie" value="' + sFile + '.swf" />'
			+ '<param name="quality" value="high" />'
			+ '<param name="menu" value="true" />'
			+ '<param name="allowScriptAccess" value="sameDomain" />'
			+ '<param name="FlashVars" value="gsCallingURL=' + sCallingURL + '" />'
			+ '<embed src="' + sFile + '.swf" quality="high" menu="true" allowScriptAccess="sameDomain" FlashVars="gsCallingURL=' + sCallingURL + '" width="' + sWidth + '" height="' + sHeight + '" name="' + sFile + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" id="FlashEmbedElement" align="middle" />'
		+ '</object>'
	);
}

function AppendQueryString(sString,sAppend) {
	if (sString.length) {
		return '&' + sAppend;
	}
	else {
		return '?' + sAppend;
	}
}

function DecryptEmail(sString) {
	var sMailTo = '';

	for (i=1 ; i<=sString.length ; i++) {
		sMailTo += String.fromCharCode(sString.charCodeAt(i-1)+1);
	}

	document.write('<a href="mailto:' + sMailTo + '">' + sMailTo + '</a>');
}

function ShowBody(bShow,iSeconds) {
	if (document.body) {
		if (bShow == false) {
//			alert('Hide Body');
			document.body.style.visibility='hidden';
			window.setTimeout('ShowBody(true)',iSeconds * 1000);
		}
		else {
//			alert('Show Body');
			document.body.style.visibility='visible';
		}
	}
}

function GetBody(sBody) {
	return ''
	+ '<body>\n'
	+ '\n'
	+ sBody
	+ '\n'
	+ '</body>\n'
}

function GetHead(sHead,sTitle) {
	return ''
	+ '<head>\n'
	+ '\n'
	+ '<title>' + sTitle + '</title>\n'
	+ sHead
	+ '\n'
	+ '</head>\n'
}

function GetHTML(sDocType,sHead,sBody) {
	return ''
	+ sDocType 
	+ '<html>\n'
	+ sHead
	+ sBody
	+ '</html>\n'
}

function GetBrowser() {
	if (navigator.appVersion.indexOf('MSIE') >= 0)
		return 'Internet Explorer';
	if (navigator.userAgent.indexOf('Firefox') >= 0)
		return 'Firefox';
	if (navigator.userAgent.indexOf('Chrome') >= 0)
		return 'Chrome';
	if (navigator.userAgent.indexOf('Netscape') >= 0)
		return 'Netscape';
	if (navigator.userAgent.indexOf('Opera') >= 0)
		return 'Opera';
	if (navigator.userAgent.indexOf('Safari') >= 0)
		return 'Safari';
	return "NA";
}

function GetWindowVisibleWidth() {
	if (typeof(window.innerWidth) == 'number') {
		if (document.documentElement && document.documentElement.clientWidth)
			return Math.min(window.innerWidth,document.documentElement.clientWidth);
		return window.innerWidth;
	}
	if (document.documentElement && document.documentElement.clientWidth)
		return document.documentElement.clientWidth;
	if (document.body && document.body.clientWidth)
		return document.body.clientWidth;
	return 0;
}

function GetWindowVisibleHeight() {
	if (typeof(window.innerHeight) == 'number') {
		if (document.compatMode == 'BackCompat') {
			if (document.body && document.body.clientHeight) 
				return Math.min(window.innerHeight,document.body.clientHeight);
		}
		if (document.documentElement && document.documentElement.clientHeight) 
			return Math.min(window.innerHeight,document.documentElement.clientHeight);
		return window.innerHeight;
	}
	if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	if (document.body && document.body.clientHeight)
		return document.body.clientHeight;
	return 0;
}

function GetWindowVisibleOffsetX() {
	if (typeof(window.pageXOffset) == 'number')
		return window.pageXOffset;
	if (document.body && document.body.scrollLeft)
		return document.body.scrollLeft;
	if (document.documentElement && document.documentElement.scrollLeft)
		return document.documentElement.scrollLeft;
	return 0;
}

function GetWindowVisibleOffsetY() {
	if (typeof(window.pageYOffset) == 'number')
		return window.pageYOffset;
	if (document.body && document.body.scrollTop)
		return document.body.scrollTop;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	return 0;
}

function GetElementOffsetX(oElement) {
	var iOffsetLeft = 0;

	if (oElement && oElement.offsetParent) {
		do {
			iOffsetLeft += oElement.offsetLeft;
		}
		while (oElement = oElement.offsetParent);
	}
	return iOffsetLeft;
}

function GetElementOffsetY(oElement) {
	var iOffsetTop = 0;

	if (oElement && oElement.offsetParent) {
		do {
			iOffsetTop += oElement.offsetTop;
		}
		while (oElement = oElement.offsetParent);
	}
	return iOffsetTop;
}

function ScaleFlash(sScale,iElementWidth,iElementHeight) {
	var oElement;

	if (oElement = document.getElementById('FlashObjectElement')) {
		if (sScale == "Expand") {
			oElement.width = GetWindowVisibleWidth();
			oElement.height = GetWindowVisibleHeight();
			oElement.width = GetWindowVisibleWidth();
			oElement.height = GetWindowVisibleHeight();
		}
		else {
			oElement.width = iElementWidth;
			oElement.height = iElementHeight;
		}
	}
	if (oElement = document.getElementById('FlashEmbedElement')) {
		if (sScale == "Expand") {
			oElement.width = GetWindowVisibleWidth();
			oElement.height = GetWindowVisibleHeight();
			oElement.width = GetWindowVisibleWidth();
			oElement.height = GetWindowVisibleHeight();
		}
		else {
			oElement.width = iElementWidth;
			oElement.height = iElementHeight;
		}
	}

	switch (GetBrowser()) {
		case "Firefox":
		case "Netscape":
			oElement = document.getElementById('FlashEmbedElement');
			break;
		default:
			oElement = document.getElementById('FlashObjectElement');
	}
	if (sScale == "Expand") {
		var iOffsetX = (gsDirection == 'LTR' ? GetElementOffsetX(oElement) - GetWindowVisibleOffsetX() : GetWindowVisibleOffsetX() - GetElementOffsetX(oElement));
		window.scrollBy(iOffsetX,(GetElementOffsetY(oElement) - GetWindowVisibleOffsetY()));
/**
		iWidth = 400;//Math.min(640,window.screen.availWidth);
		iHeight = 500;//Math.min(400,window.screen.availWidth);

		var oWindow = null;
		oWindow = window.open('','TestWindowJS',GetVisibleCenter(iWidth,iHeight) + ',width=' + iWidth + ',height=' + iHeight + ',resizable=1');
		oWindow.document.open();
		oWindow.document.clear();
		oWindow.document.write(iOffsetX + '<br />');
		oWindow.document.write(gsDirection + '<br />');
//		oWindow.document.write(GetElementOffsetX(oElement) + '<br />' + GetWindowVisibleOffsetX() + '<br />' + GetElementOffsetY(oElement) + '<br />' + GetWindowVisibleOffsetY() + '<br />');
//		oWindow.document.write((GetElementOffsetX(oElement) - GetWindowVisibleOffsetX()) + '<br />' + (GetElementOffsetY(oElement) - GetWindowVisibleOffsetY()) + '<br />');
//		oWindow.document.write(GetElementOffsetX(oElement) + '<br />' + GetWindowVisibleOffsetX() + '<br />' + GetElementOffsetY(oElement) + '<br />' + GetWindowVisibleOffsetY() + '<br />');
//		oWindow.document.write(GetHTML(gsDocType,GetHead(gsHead,gsThe100Games),GetBody(sBody)));
		oWindow.document.close();
//		oWindow.moveTo(nLeft,0);
		oWindow.focus();
/**/
	}
	else {
		window.scrollBy((GetElementOffsetX(oElement) - GetWindowVisibleOffsetX() - ((GetWindowVisibleWidth()-iElementWidth)/2)),(GetElementOffsetY(oElement) - GetWindowVisibleOffsetY() - ((GetWindowVisibleHeight()-iElementHeight)/2)));
	}
}

function FitWindow(oElement) {
	var iWidth = oElement.width;
	var iHeight = oElement.height;
	var iVisibleWidth = GetWindowVisibleWidth();
	var iVisibleHeight = GetWindowVisibleHeight();

	window.resizeBy(iWidth-iVisibleWidth,iHeight-iVisibleHeight);

	iVisibleWidth = GetWindowVisibleWidth();
	iVisibleHeight = GetWindowVisibleHeight();
	if (iWidth != iVisibleWidth || iHeight != iVisibleHeight) {
		window.resizeBy(iWidth-iVisibleWidth,iHeight-iVisibleHeight);
	}

	iVisibleWidth = GetWindowVisibleWidth();
	iVisibleHeight = GetWindowVisibleHeight();
	if (iWidth != iVisibleWidth || iHeight != iVisibleHeight) {
		window.moveBy(iWidth-iVisibleWidth,iHeight-iVisibleHeight);
		window.resizeBy(iWidth-iVisibleWidth,iHeight-iVisibleHeight);
	}
	if (typeof(window.outerWidth) == 'number' && window.outerWidth > window.screen.availWidth) {
		window.resizeBy(window.screen.availWidth-window.outerWidth,0);
	}
	if (typeof(window.outerHeight) == 'number' && window.outerHeight > window.screen.availHeight) {
		window.resizeBy(0,window.screen.availHeight-window.outerHeight);
	}
}
