/* SYSTEM REQUIREMENTS CHECK CODE
 * 
 * Note: to function correctly, the following HTML must be included in the current
 * web page:
 *
 * <applet id="sysApplet" code="com.futuresource.util.applet.SystemProperties.class"
 *     width="0" height="0" archive="sysapplet.jar"
 *     codebase="http://download.esignal.com/SYSAPP/sysapplet" mayscript>
 *   <param name="cabbase" value="sysapplet.cab">
 * </applet>
 *
 * Alternately, an inline call to "initSysApplet()" below will output this HTML for you.
 */

function checkValidity() {
    if ( isPopupBlocked() ) {
        alert("We have detected that you are using popup blocking software.\nThis may cause the application not to function.");
        var popupMessageDiv = document.getElementById("popup_blocker_message");
        if (popupMessageDiv) {
            popupMessageDiv.style.display = "block";
        }
    }

    setTimeout('checkJVMCompatibility()', 4000);
}

function isPopupBlocked() {
    var mine = window.open('','','width=1,height=1,left=0,top=0,resizable=yes');
    var blocked = false;
    if (mine) {
        try {
            popupPosX = mine.screenLeft;
            popupPosY = mine.screenTop;
        } catch (e) {}
        blocked = false;
        mine.close();
    } else {
        blocked = true;
    }

    return blocked;
}

function checkJVMCompatibility() {
    var sysApp = document.getElementById("sysApplet");
    var javaOK = false;
    // do JVM check only if applet is found and loaded
    if (sysApp != null)
    {
        if (typeof(sysApp.getJVMVendor) != "undefined" && typeof(sysApp.getJVMVersion) != "undefined" ) {
            if (sysApp.getJVMVendor() == "Sun Microsystems Inc." && sysApp.getJVMVersion() >= "1.5" ) {
                javaOK = true;
            }
        }
        sysApp.parentNode.removeChild(sysApp);
    }
    if (!javaOK) {
        alert("We have detected that no Java Runtime is installed on your system, or you are using an old version.\n" +
              "Please verify that you have Java Runtime Environment by Sun Microsystems Inc., version 1.5, or above.");
        var jreMessageDiv = document.getElementById("jre_message");
        if (jreMessageDiv) {
            jreMessageDiv.style.display = "block";
        }
    }
}

function validJVM()
{
	var sysApp=document.getElementById("sysApplet");
	var retval = true;
	if (sysApp!=null) {
		if (typeof(sysApp.getJVMVendor) != "undefined") {
			retval = false;
			if (sysApp.getJVMVendor() == "Microsoft Corp.") {
				retval = true;
			}
			if (sysApp.getJVMVendor() == "Sun Microsystems Inc." &&
					sysApp.getJVMVersion() > "1.5") {
				retval = true;
			}
		}
	}
	return retval;
}

function checkSysReq()
{
	var isCompat=false;
	var aVer=parseFloat(window.navigator.appVersion.replace(/.*MSIE\s([0-9\.]*);.*/,"$1"));

	if(window.navigator.appName == "Microsoft Internet Explorer" &&
			aVer >= 5.5 &&
			window.navigator.platform == "Win32" &&
			window.navigator.cookieEnabled &&
			validJVM())
		isCompat=true;

	return isCompat;
}

function initSysApplet()
{
// KH more hard code
	//document.write("<applet id=\"sysApplet\" ");
	//document.write("code=\"com.futuresource.util.applet.SystemProperties.class\" ");
	//document.write("width=\"0\" height=\"0\" archive=\"sysapplet.jar\" ");
	//document.write("codebase=\"http:\/\/platinum.fsxtra.com/common/applets\" mayscript>");
	//document.write("<param name=\"cabbase\" value=\"sysapplet.cab\"></applet>");
}

function setCookie (name, value, expires, path, domain, secure) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ){
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie =
    name + '=' + escape(value) +
    ( (expires) ? ';expires=' + expires_date.toGMTString() : '' ) +
    ( (path) ? ';path=' + path : '' ) +
    ( (domain) ? ';domain=' + domain : '' ) +
    ( (secure) ? ';secure' : '' );
}

function getCookie (check_name) {
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	for (i = 0; i < a_all_cookies.length; i++)
	{
		a_temp_cookie = a_all_cookies[i].split('=');
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if (cookie_name == check_name)
		{
			b_cookie_found = true;
			if (a_temp_cookie.length > 1)
			{
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found)
	{
		return null;
	}
}

