/*  sniffer object */

function O_Sniffer(){
  var n = navigator;
  /* 
	string comparisons are much easier if we lowercase everything now.
	to make indexOf() tests more compact/readable, we prepend a space 
	to the userAgent string (to get around '-1' indexOf() comparison) 
	*/
  var ua = ' ' + n.userAgent.toLowerCase();
  
//alert(ua);

  var pl = n.platform.toLowerCase(); /* not supported in NS3.0 */
  var an = n.appName.toLowerCase();

  /* browser version */
  this.version = n.appVersion;
  this.opera = ua.indexOf('opera') > 0;
  this.hotjava = ua.indexOf('hotjava') > 0;
  this.spoofer = ua.indexOf('spoofer') > 0;
  this.webtv = ua.indexOf('webtv') > 0;
  this.gecko = ua.indexOf('gecko') > 0;
  
	this.ne  = ((ua.indexOf('mozilla')>0) && (ua.indexOf('compatible') <1) && (!this.spoofer) && (!this.opera) && (!this.webtv) && (!this.hotjava));
  this.ie = ((ua.indexOf('msie') > 0) && (!this.opera));
  this.aol = ua.indexOf('aol') > 0;
  this.omniweb = ua.indexOf('omniweb') > 0;
  this.galeon = ua.indexOf('galeon') > 0;
  

  this.major = parseInt( this.version );
  this.minor = parseFloat( this.version );
  if (this.ie){
		/* version information different if IE */
		var actual_index=ua.indexOf("msie ");
		var version = ua.substring (actual_index+5, ua.indexOf (".", actual_index ));
		this.major = parseInt( version );
		this.minor = parseFloat( version );
  }

  /* platform */
  this.mac = ua.indexOf('mac') > 0;
  this.mac68k = (ua.indexOf('68k') > 0 || ua.indexOf('68000') > 0);
  this.macppc = (ua.indexOf('ppc') > 0 || ua.indexOf('powerpc') > 0);

  this.win = ua.indexOf('win') > 0;
  this.win16 = (ua.indexOf('16') > 0 && ua.indexOf('win') > 0);
  this.win31 = this.win16;
  this.win95 = (ua.indexOf('95') > 0 && ua.indexOf('win') > 0);
  this.win98 = (ua.indexOf('98') > 0 && ua.indexOf('win') > 0);
  this.winme = (ua.indexOf('win 9x 4.90') > 0 && ua.indexOf('win') > 0);
  this.winnt = (ua.indexOf('nt') > 0 && ua.indexOf('win') > 0);
  this.win2k = (ua.indexOf('nt 5') > 0 && ua.indexOf('win') > 0);
  this.winxp = (ua.indexOf('nt 5.1') > 0 && ua.indexOf('win') > 0);
  this.winxp64 = (ua.indexOf('nt 5.2') > 0 && ua.indexOf('win') > 0);
  this.win2k3 = (ua.indexOf('nt 5.2') > 0 && ua.indexOf('win') > 0);
  this.winvista = (ua.indexOf('nt 6.0') > 0 && ua.indexOf('win') > 0);

  this.os2 = ua.indexOf('os/2') > 0;

  this.sun = ua.indexOf('sunos') > 0;
  this.irix = ua.indexOf('irix') > 0;
  this.hpux = ua.indexOf('hpux') > 0;
  this.aix = ua.indexOf('aix') > 0;
  this.dec = (ua.indexOf('dec') > 0 || ua.indexOf('alpha') > 0 || ua.indexOf('osf1') > 0 || ua.indexOf('ultrix') > 0);
  this.sco = (ua.indexOf('sco') > 0 || ua.indexOf('unix_sv') > 0);
  this.vms = (ua.indexOf('vax') > 0 || ua.indexOf('openvms') > 0);
  this.linux = ua.indexOf('linux') > 0;
  this.sinix = ua.indexOf('sinix') > 0;
  this.reliant = ua.indexOf('reliantunix') > 0;
  this.freebsd = ua.indexOf('freebsd') > 0;
  this.openbsd = ua.indexOf('openbsd') > 0;
  this.netbsd = ua.indexOf('netbsd') > 0;
  this.bsd = ua.indexOf('bsd') > 0;
  this.unixware = ua.indexOf('unix_system_v') > 0;
  this.mpras = ua.indexOf('ncr') > 0;

  this.unix = ua.indexOf("x11") > 0;

  /* workarounds - IE5/Mac reports itself as version 4.0 */
  if(this.ie && this.mac) {
    if(ua.indexOf("msie 5")) {
      this.major = 5;
      var actual_index = ua.indexOf("msie 5");
      var actual_major = ua.substring(actual_index + 5, actual_index + 8);
      this.minor = parseFloat(actual_major);
    }
  }
  this.ne4=(this.ne && this.major >= 4 && this.major < 5);
  this.ne45=(this.ne4 && this.minor >= 4.5);
  this.ne6plus = (this.ne && this.major >= 5);
  this.ie4 = (this.ie && this.major == 4);
  this.ie4plus = (this.ie && this.major >= 4);
  this.ie5 = (this.ie && this.major == 5);
  this.ie5plus = (this.ie && this.major >= 5);
  this.ie6 = (this.ie && this.major == 6);
  this.ie6plus = (this.ie && this.major >= 6);
  this.ie55plus = ((this.ie && this.minor >=5.5));
  this.ie7 = (this.ie && this.major == 7);
  this.ie7plus = (this.ie && this.major >= 7);
  this.ie8 = (this.ie && this.major == 8);
  this.ie8plus = (this.ie && this.major >= 8);
  
  /* MAC stuff  */
  this.ne6plusmac = (this.ne6plus && this.mac);
  this.iemac = (this.ie && this.mac);
  this.ie5mac = (this.ie5 && this.mac);
  this.ie5plusmac = (this.ie5plus && this.mac);
  this.ie52plusmac = (((this.ie && this.minor >=5.2)) && this.mac);

  this.shortname = __snfr__ShrtNme;
  
  return this;
}

function __snfr__ShrtNme(){
	if (this.ne6plus){return "NE5";}
	else if (this.ne4){return "NE4";}
	else if (this.ie52plusmac){return "IE52MAC";}
	else if (this.ie5plusmac){return "IE5MAC";}
	else if (this.ie55plus){return "IE55";}
	else if (this.ie5plus){return "IE5";}
	else if (this.ie4plus){return "IE4";}
	return "";
}

var _SNFR_ = new O_Sniffer();
//alert(_SNFR_.minor);


/* browser utility functions*/

if (!window._w){window._w=window;}


/* sniffer functions */
/*
var _n=navigator; var _nua=_n.userAgent; var _na=_n.appName;
var _IEV=_nua.indexOf("MSIE ");
function _isIE(){return _IEV >0;}
var _nv= _isIE()? parseInt(_nua.substring (_IEV+5, _nua.indexOf (".", _IEV ))) : parseFloat(_n.appVersion);
var _NE=(_na=="Netscape"); var _NE6=(_NE && (_nv>=5)); var _NE45=(_NE && (_nv>=4.5)&& (_nv<5));var _NE4=(_NE && (_nv>=4)&& (_nv<5));
var _IE=(_na=="Microsoft Internet Explorer"); var _IE55=(_IE && (_nv>=5.5)); var _IE4=(_IE && (_nv>=4)&& (_nv<5)); var _IE5=(_IE && (_nv>=5)&& (_nv<5.5)); var _IE6=(_IE && (_nv>=6));
*/
/*
function __NE(){return _NE;} function __NE6(){return _NE6;} function __NE45(){return _NE45;} function __NE4(){return _NE4;}
function __IE(){return _IE;} function __IE6(){return _IE6;} function __IE55(){return _IE55;} function __IE5(){return _IE5;} function __IE4(){return _IE4;}

function XXX__IE5PLUS(){return (_isIE() && _nv>=5);}
function XXX__IEDOWNVER(){return (_isIE() && _nv<5);}
function XXX__NEDOWNVER(){return (__NE() && _nv<5);}
function XXX__brswrShrtNme(){
	if (__NE6()){return "NE5";}
	else if (__NE4()){return "NE4";}
	else if (__IE55() || __IE6()){return "IE55";}
	else if (__IE5()){return "IE5";}
	else if (__IE4()){return "IE4";}
	return "";
}
*/

function __brswrShrtNme(){return _SNFR_.shortname;}
function __IE(){return _SNFR_.ie;} function __IE6(){return _SNFR_.ie6plus;} function __IE55(){return _SNFR_.ie55plus;} function __IE5(){return _SNFR_.ie5plus && !_SNFR_.ie55plus;} function __IE4(){return _SNFR_.ie4plus && !_SNFR_.ie5plus;}
function __NE(){return _SNFR_.ne;} function __NE6(){return _SNFR_.ne6plus;} function __NE45(){return _SNFR_.ne45;} function __NE4(){return _SNFR_.ne4;}
function __IEMAC(){return _SNFR_.iemac} function __IE5MAC(){return _SNFR_.ie5plusmac}
function __IE5PLUS(){return _SNFR_.ie5plus;}
function __IEDOWNVER(){return (_SNFR_.ie && _SNFR_.major<5);}
function __NEDOWNVER(){return (_SNFR_.nn && _SNFR_.major<5);}


/* object functions */
function __getObj(id){return __getWinObj(_w,id);}
function __getFrame(id){return __getWinFrame(_w,id);}
function __getWinFrame(win,id){
	var result = null;
	if (win.frames){result=eval("win.frames." + id);}
	return result;
}
function __getWinObj(win,id){
	var result = null;
	if (win){
		if (!result){if (win.getElementById){result = win.getElementById(id);} /* check DOM compliant browsers first */}
		if ((!result) && (win.document)){
			if (win.document.all){result = eval("win.document.all." + id);} /* check IE */
			if (!result) {result = eval("win.document." + id);}
			if (!result){
				if (win.document.getElementById){result = win.document.getElementById(id); }
				else if (__NE4()){
					result = eval("win.document." + id); 
					if (!result){result=eval("document." + id);}
					if (!result){result=eval("window." + id);}
					if (!result){result=eval("window.document." + id);}
				}
			}
		}
		if (!result) {result = eval("win." + id);}
	}
	return result;
}
function __getWinDoc(win){
	if(win){
		if (win.contentDocument) {/* NE6 */ return win.contentDocument; } 
		else if (win.contentWindow) {/* IE5.5 and IE6 */	return win.contentWindow.document;} 
		else if (win.document) {	/* For IE5 */	return win.document;} 
		else {}
	}
	return null;
}
function __getBodyObj(){return document.body;}
function __getPntrStyl(){return (__NE6() || __IE6())? "pointer":"hand";}
function XXXX__getQSValue(s){
	var qs=unescape(document.location.search);
	qsu=qs.toUpperCase();
	var qsPos=qsu.indexOf(s.toUpperCase() + '=');
	if (qsPos>-1){
		qsu=qsu.substring(qsPos);
		if (qsu.indexOf('&')>-1){qsu=qsu.substring(0,qsu.indexOf('&'));}
		qs=qs.substring(qsPos + qsu.indexOf('=')+1);
	}
	else{qs="";}
	return qs;
}
function __getQSValue(s){
	var qs=unescape(document.location.search);
	qsu=qs.toUpperCase();
	var qsPos=qsu.indexOf(s.toUpperCase() + '=');
	if (qsPos>-1){
		qsu=qsu.substring(qsPos);
		if (qsu.indexOf('&')>-1){
			qsu=qsu.substring(0,qsu.indexOf('&'));
		}
		qs=qsu.substring(qsPos + qsu.indexOf('='));
	}
	else{qs="";}
	return qs;
}
function __getQSValuePair(s, amp){
	var result = s + "=" + __getQSValue(s);
	if (amp){result= "&" + result;}
	return result;
}


/* dependencies:	detective.js */
function XlaunchJEDletByCode(code,compact,JEDletURL){
	/* construct the query string */
	var queryString = ('?jedlet=' + code);
	window.open(JEDletURL + queryString, "xxx");
//	if (compact){	launchJEDlet_WINX((JEDletURL + queryString));}
//	else {launchJEDlet((JEDletURL + queryString));}
}
function launchJEDletByCode(code,compact,UID){
	/* construct the query string */
//  var JEDletURL="http://192.168.1.12:7777/jedlet.starter.aspx";
	var JEDletURL="http://launch.jedlet.com/jedlet.starter.aspx";
//	var JEDletURL="http://elearn.jedlet.com/jedlet.starter.aspx";
	//var queryString = ('?jedlet=' + code + __getQSValuePair("audio", true) + __getQSValuePair("uid", true));
var _code = code;
/*
switch(code){
case "HRD-1605A-JT0-EN-01": _code="HRD-1605A-JT0-EN-61"; break;
case "HRD-1805A-PL0-EN-01": _code="HRD-1805A-PL0-EN-61"; break;
case "HRD-2602B-AO0-EN-02": _code="HRD-2602B-AO0-EN-62"; break;
default: break;
}
*/
	var queryString = ('?jedlet=' + _code + "&uid=" + UID + "&audio=true");
	/* launch */
	if (compact || __NEDOWNVER() || (screen.width < 1024)){
		var xp = _SNFR_.winxp;
		if (xp && (screen.width < 1024)){
			var alertTxt=""; 
			var lang = __getQSValue("lang");
			switch(lang.toLowerCase()){
				case "es":
					break;
				case "fr":
					alertTxt = "ATTENTION\n\n"
					alertTxt = alertTxt + "Vous utilisez Windows XP avec une résolution d'écran de ";
					alertTxt = alertTxt + screen.width + "x" + screen.height + ".\n\n";
					alertTxt = alertTxt + "Si les éléments de navigation n'apparaissent pas au bas du tutoriel, vous devez régler la résolution de votre écran à 1024x768.";
					break;
				default:
					alertTxt = "ATTENTION\n\n"
					alertTxt = alertTxt + "You are using Windows XP with a screen resolution of ";
					alertTxt = alertTxt + screen.width + "x" + screen.height + ".\n\n";
					alertTxt = alertTxt + "If you cannot see the navigation elements at the bottom of the tutorial, you will need to set your screen resolution to 1024x768.";
					break;
			}
			if (alertTxt.length>0){window.alert(alertTxt);}
		}


		launchJEDlet_WINX((JEDletURL + queryString));
	}
	else {launchJEDlet((JEDletURL + queryString));}
}
function positionWindow(win, x, y){
	if ((win) && win.moveTo){win.moveTo(x,y);}
}
function launchJEDlet(URL){
	var ne=true;//(__NE() || __IEDOWNVER());
	var nXOffset = ne?0:25;
	var nYOffset = ne?0:25;
	/* Setup the window position variables. */
	var nWindowWidth = ne?screen.availWidth-10:(screen.width + (nXOffset * 2));
	var nWindowHeight = ne?screen.availHeight-10:(screen.height + (nYOffset * 2));
	var nLeftPosition = ne?0:((screen.width - nWindowWidth) / 2);
	var nTopPosition = ne?0:((screen.height - nWindowHeight) / 2);
	/* Build the window parameters variable. */
	var sWindowParameters = ne? "height=" + nWindowHeight + ",width=" + nWindowWidth + ",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0," :"height=" + nWindowHeight + ",width=" + nWindowWidth + ",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,";
	sWindowParameters = sWindowParameters + "screenX=" + nLeftPosition + ",";
	sWindowParameters = sWindowParameters + "left=" + nLeftPosition + ",";
	sWindowParameters = sWindowParameters + "screenY=" + nTopPosition + ",";
	sWindowParameters = sWindowParameters + "top=" + nTopPosition;
	
	var d = new Date();
	var JEDLET_winName="JEDLET_" + d.getTime();
	var JEDLET_win=window.open( '', JEDLET_winName, sWindowParameters);
	positionWindow(JEDLET_win, -(nXOffset), -(nYOffset));
	JEDLET_win.location=URL;
}

function launchJEDlet_WINX(URL){

	var ne=(__NE() || __IEDOWNVER());
	var nXOffset = 0;
	var nYOffset = 0;
	/* Setup the window position variables. */
	var nWindowWidth = 788 + nXOffset;
	var nWindowHeight = 550 + nYOffset;
	var nLeftPosition = 0;
	var nTopPosition = 0;
	/* Build the window parameters variable. */
	var sWindowParameters = ne? "height=" + nWindowHeight + ",width=" + nWindowWidth + ",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0," : "height=" + nWindowHeight + ",width=" + nWindowWidth + ",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,";
	sWindowParameters = sWindowParameters + "screenX=" + nLeftPosition + ",";
	sWindowParameters = sWindowParameters + "left=" + nLeftPosition + ",";
	sWindowParameters = sWindowParameters + "screenY=" + nTopPosition + ",";
	sWindowParameters = sWindowParameters + "top=" + nTopPosition;
	
	var d = new Date();
	var JEDLET_winName="JEDLET_" + d.getTime();
	var JEDLET_win=window.open( '', JEDLET_winName, sWindowParameters);
	positionWindow(JEDLET_win, 0, 0);
	JEDLET_win.location=URL;
}


