//Code which is used globally

//Default decimal symbol
var Default_DecimalSymbol = '.';


function FindCookieStr(FindCookie)
//Return the string found in the cookie for the passed information
{
var ReturnCookie = "";

//Make sure that a cookie exists
if (window.document.cookie.length != 0)
{
	//Find the position of the cookie item in the cookie
	var Index = window.document.cookie.indexOf(FindCookie);	
	
	//If an index entry exists
	if(Index != -1)
	{
		//Read all of the data
		Index += FindCookie.length;
		var CookieData = window.document.cookie.substring(Index, window.document.cookie.length);

		//Find the end of the cookie data
		var DataIndex =  (CookieData == "") ? -1 : CookieData.indexOf(";");

		//Set the length to the full length if last item
		if(DataIndex == -1)
			DataIndex = CookieData.length;

		//Set the return cookie data
		ReturnCookie = CookieData.substring(0, DataIndex);
	}
}

//Return the cookie data
return ReturnCookie;
}

function IsInstructorLoggedOn()
//Return whether an Instructor is already logged on to the system
{
//find if the instructor cookie has been set
var InstructorCookie = FindCookieStr('LJInstID');

//return true if an instructor is logged on
if (InstructorCookie.length > 0)
	return true;
else
	return false;
}

function IsStudentLoggedOn()
//Return whether a Student is already logged on to the system
{
//find if the student cookie has been set
var StudentCookie = FindCookieStr('LJStuCode');
var InstructorCookie = FindCookieStr('LJInstID');

//return true if a student is logged on and an instructor is not logged on
if ((StudentCookie.length > 0) && (InstructorCookie.length == 0))
	return true;
else
	return false;

}


function SetCookie (name, value, path) 
//Set the passed value into a cookie of the passed name using the passed path
{

document.cookie = name + "=" + escape (value) +
    ((path == null) ? "" : ("; path=" + path));

}


function SetObjectVisible(objdocument, objname, objvisible)
//Set the passed object visible or not
{

// if netscape 6 or greater
if (IsNS6orGreater())
{
	var objItem = objdocument.getElementById(objname);
	if(objItem)
		objItem.style.visibility = (objvisible ? 'visible' : 'hidden');
}

//if the browser supports layers
else if(objdocument.layers)
{
	if(objdocument.layers[objname])
		objdocument.layers[objname].visibility = (objvisible ? 'show' : 'hide');
}

//if the browser supports the all object		
else if (objdocument.all)
{
	var objItem = objdocument.all[objname];
	if(objItem)
		objItem.style.visibility = (objvisible ? 'visible' : 'hidden');
}

}

function SetObjectDisplay(objdocument, objname, objdisplay)
//Set the passed object display to blank string or none
{

	// if netscape 6 or greater
	if (IsNS6orGreater())
	{
		var objItem = objdocument.getElementById(objname);
		if(objItem)
			objItem.style.display = (objdisplay ? '' : 'none');
	}

	//if the browser supports ids (NN4)
	else if(objdocument.ids)
	{
		if(objdocument.ids[objname])
			objdocument.ids[objname].display = (objdisplay ? '' : 'none');
	}

	//if the browser supports the all object		
	else if (objdocument.all)
	{
		var objItem = objdocument.all[objname];
		if(objItem)
			objItem.style.display = (objdisplay ? '' : 'none');
	}

}

function GetFormElement(objform, objname)
{
	var objitem;
	
	objitem=objform.elements[objname];
	
	return objitem;
}


function GetDecimalSymbol()
//Return the symbol being used to indicate decimals
{
var DecimalSymbol = '';

//Check to see if using Internet Explorer
if(IsInternetExplorer())
{
  //Read out the locale
  var checknum = 0.1;
  var numstring = checknum.toLocaleString();
 
  //if characters exist then the decimal symbol is the second character
  if(numstring.length >= 3)
    DecimalSymbol = numstring.substring(1,2); 
}

//If netscape then load the client language
else if(IsNetscape())
{
  var langcode = navigator.language;

  //if a valid code is loaded use the first two characters
  if(langcode.length >= 2)
  {
    langcode = langcode.substring(0,2);

    //Set the symbol depending on the language
    switch(langcode)
    {
      //French - use commas
      case 'fr':  
          DecimalSymbol = ',';
          break;

      case 'FR':
          DecimalSymbol = ',';
          break;

      //Default use full stop
      default:
          DecimalSymbol = Default_DecimalSymbol;
          break;
    }
  }
}

//If no sumbol set use full stop
if(DecimalSymbol.length == 0)
  DecimalSymbol = Default_DecimalSymbol;

return DecimalSymbol;
}


function IsInternetExplorer()
//Return whether the Browser is Internet Explorer 5 or greater
{
var IsIE = false;

//Check to see if using Internet Explorer 5 or greater
if (navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf("Opera")==-1)
  IsIE = true;

return IsIE;
}


function IsIE5orGreater()
//Return whether the Browser is Internet Explorer 5 or greater
{
var IE5gt = false;

//Check to see if using Internet Explorer 5 or greater
if (navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf("Opera")==-1)
{
	if(parseFloat(navigator.appVersion) >= 5)
		IE5gt = true;
	else if(parseFloat(navigator.appVersion.substring(22,26)) >= 5)
		IE5gt = true;
}

return IE5gt;
}

function IsNetscape()
//Return where the browser is Netscape
{
var IsNetscape = false;

//Check to see if using Netscape
if (navigator.appName == 'Netscape' || navigator.userAgent.indexOf("Opera")!=-1)
  IsNetscape = true;

return IsNetscape;
}

function IsNS6orGreater()
//Return whether the browser is Netscape 6 or greater
{
var NS6gt = false;

//Check to see if using Netscape 6 or greater
if (navigator.appName == 'Netscape')
{
	if(parseFloat(navigator.appVersion) >= 5)
		NS6gt = true;
}
else if(navigator.userAgent.indexOf("Opera")!=-1)
	NS6gt = true;

return NS6gt;
}

function IsSiteCookie(CookieName)
//Return whether the passed cookie name is the site cookie
{
	return CookieMatch(CookieName, "LJSite");
}

function IsAuthCookie(CookieName)
//Return whether the passed cookie name is the authentication cookie
{
	return CookieMatch(CookieName, "LJAuth");
}

function CookieMatch(sSetCookie, sFindCookie)
//Return whether the passed cookie name matches the set cookie
{	
	var sSearch = sFindCookie + '=';
	var sCookie = sSetCookie + '=';

	return (sCookie.indexOf(sSearch) != -1);
}

function WriteFlashObject(FlashSrc, FlashHeight, FlashWidth)
//Write out a flash object onto the screen
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + FlashWidth + '" height="' + FlashHeight + '">');
	document.write('<param name=movie value="' + FlashSrc + '">');
	document.write('<param name=quality value=high>');
	document.write('<embed src="' + FlashSrc + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + FlashWidth + '" height="' + FlashHeight +'"></embed>');
	document.write('</object>');
}

function LogOffInstructorUser()
//Attempt to logoff any instructor user currently logged on
{
	try
	{
		//Clear any cookies that are currently loaded
		ClearCookies();		

		//Set the authentication cookie
		SetCookie("LJAuth", "-1", "/");
	}
	catch(e)
	{
	}
}
