
/*
 To use the script you need to drop this in the login page. 

<div id="msgDlg"  style="background-color: #ccccdd; border: 2px solid white; height: 415px; position: absolute; width: 575px;" >
  <div style="background-color: #136495; padding:5px;"><img src="themes/blue/bc_webstation.gif" width="185" height="51" /></div>
  <div id = "CheckJavaAppletDiv"> </div>
  <div id="InfoMsg" >
    <p> The following must be enabled  in your web browser:
    <ul>
      <li>Javascript </li>
      <li>Cookies</li>
      <li>Java </li>
    </ul>
  </div>
  <div id="StatusMsg" > <br>
    <sapn>
    Unable to detect javascript, possible errors:
    <ul>
      <li>Your browser does not support java scripts </li>
      <li>Javascript setting is disabled in your browser . </li>
    </ul>
    </span>
   </div>
  <p> <a href="javascript:goodSetup();" >Cancel</a></p>
</div>
</div>

*/
var waitMsg = "<br>checking your browser's environment. Please wait...";

/*
function detectJavaVersion1(ver,vender){
	if ((vender == "Microsoft Corp." && ver  >1.0) || ver >1.3 ) {
		javaOk= true;
	 }
	 else {
	    var html = '<p><sapn> Incorrected Java version instlled please install the latest java version </span></p>' ;
		setStatusMsg(html,true);
	 }

	//alert(javaObj.object.myJava1Okay);

}


function checkNoJavaCallBack(){
	 if (!javaOk) {
	    var html = '<sapn> Unable to detect java, possible errors: <ul>'+
					'<li>Java is not installed in your system </li>'+
					'<li>Java setting is disabled in your browser </li>'+
					'</ul></span>';
	 	setStatusMsg(html ,true);			
	}			
}	

*/

function initCheck(codebase) {
	
    var okayCookies  = checkForCookies();
	var okayJava = checkForJava(codebase);
	if (okayJava && okayCookies){
		goodSetup();
	}	
	else {
		badSetup();
	}
}

function checkForJava(codebase){
   // http://webstation.barchart.com/applets
	var appletDiv =  document.getElementById('CheckJavaAppletDiv');
	if (!appletDiv){
		
		setStatusMsg("Script error: can't find CheckJavaAppletDiv object " ,true);
		return false;
	}

	appletDiv.innerHTML = '<applet width="1" height="1" archive="detect.jar" codebase="'+codebase+'" '+
							'code="com.barchart.tools.DetectJava.class"  id="DetectJava" name="DetectJava" mayscript>';

	var applet =  getPlugin('DetectJava');
	try{
		var vender = applet.getVender();		
		var ver = applet.getVersion();
		if ((vender == "Microsoft Corp." && ver  >1.0) || ver >1.3 ) {
		  return true;
		}
		else{
			 var html = '<sapn> Incorrect Java version installed please install Java version of 1.4 or higher</span>' ;
			 setStatusMsg(html,true);
		}
	}
	catch (e){
		var html = '<sapn> Unable to detect java, possible errors: <ul>'+
					'<li>Java is not installed in your system </li>'+
					'<li>Java setting is disabled in your browser </li>'+
					'</ul></span>';
		
		setStatusMsg(html ,true);
	}
	return false;
}


function checkForCookies() {
	 var tmpcookie = new Date();
	chkcookie = (tmpcookie.getTime() + '');
	document.cookie = "chkcookie=" + chkcookie + "; path=/";
	if (document.cookie.indexOf(chkcookie,0) < 0) {
    var html = '<sapn> Failed to detect cookies, possible errors: <ul>'+
					'<li>Cookies setting is disabled in your browser </li>'+
					'</ul></span>';
	 	setStatusMsg(html,true);
		return false;
 	}
	return true;
}


function setStatusMsg(html, add) {
	var statusMsgDiv =  document.getElementById('StatusMsg');

	if (statusMsgDiv.innerHTML == waitMsg || !add  )
		statusMsgDiv.innerHTML = html ;
	else 
	    statusMsgDiv.innerHTML =   statusMsgDiv.innerHTML + html;			
}

function goodSetup() {
	var dlgDiv =  document.getElementById('msgDlg');
	dlgDiv.style.visibility  = "hidden";	
}

function badSetup() {
	var dlgDiv =  document.getElementById('msgDlg');
	dlgDiv.style.visibility = "visible";	
}


function centerDiv(d) {
	var availHeight, availWidth;

	if (typeof(window.innerWidth) == 'number') {
		availHeight = window.innerHeight;
		availWidth = window.innerWidth;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		availHeight = document.documentElement.clientHeight;
		availWidth = document.documentElement.clientWidth;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		availHeight = document.body.clientHeight;
		availWidth = document.body.clientWidth;
	}

	var indicatorWidth = d.style.width.substring(0, d.style.width.length - 2);
	var indicatorHeight = d.style.height.substring(0, d.style.height.length - 2);
	var left = (availWidth / 2) - (indicatorWidth / 2);
	var top = (availHeight / 2) - (indicatorHeight / 2);

	//if (top < 25)
	//	top = 25;
	top = 25;
	d.style.top = top + 'px';
	d.style.left = left + 'px';
}

function getPlugin(plgId)
{
	if (document.applets[plgId])
	{
	  return document.applets[plgId];
	}

	if (document.embeds[plgId])
	{
	  return document.embeds[plgId];
	}

	if (document.plugins[plgId])
	{
	  return document.plugins[plgId];
	}
}

