//Script required by the Site Access Pages

function HomePageLoaded()
//Home page has been loaded clear the cookies and set focus to the entry box
{
	ClearCookies();
	document.forms['SiteEntry'].txtAccessCode.focus();
}

function ClearCookies()
//Clear all of the cookies that have been created
{
	//Split all of the cookies
	var Cookies = document.cookie.split(";");
	var bRemoveCookie = true;

	//Load in the path used for the website - so the cookies can be cleared
	var Path = window.location.pathname;
	var WindowChar;

	//Loop looking for a slash
	while(Path.length > 0)
	{		
		WindowChar = Path.substring(Path.length - 1);			

		if((WindowChar == '\\') || (WindowChar == '/'))
		{
			Path = Path.substring(0, Path.length - 1);     
			break;
		}
		Path = Path.substring(0, Path.length - 1);
	}

	//Loop round all of the cookies
	for (var CookieCount=0; CookieCount < Cookies.length; CookieCount++)
	{ 
		//Split the cookie 
		var CookiePos = Cookies[CookieCount].indexOf('=');

		//if a cookie found then attempt to clear it
		if(CookiePos >= 0)
		{
			try
			{
				bRemoveCookie = !IsAuthCookie(Cookies[CookieCount].substring(0, CookiePos));
			}
			catch(e)
			{	
				bRemoveCookie = true;
			}

			if(bRemoveCookie)
			{			
				document.cookie = Cookies[CookieCount].substring(0, CookiePos) + '=0; Path=/; expires=Fri, 02-Jan-1970 00:00:00 GMT';
				document.cookie = Cookies[CookieCount].substring(0, CookiePos) + '=0; Path=' + Path + '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
			}
		}
	}
}

function AccessCodeKeyPress(event)
//Check to see if return key pressed
{
	var keycode = document.all ? event.keyCode : event.which;
		
	if(keycode == 13)
	{
		return AccessEntry(true);
	}
	else
		return true;	
}

function AccessEntry(HTMLInitiated)
//Submit the access entry form
{
	var EntryAllowed = false;

	//Ensure that a value has been entered or not initiated by HTML
	if((document.forms['SiteEntry'].txtAccessCode.value != '') || (HTMLInitiated == null))
	{
		document.forms['SiteEntry'].submit();
		EntryAllowed = true;
	}
	else
	{
		alert('Please enter your Access Code before continuing.');
		document.forms['SiteEntry'].txtAccessCode.focus();
	}

	//Return whether the entry is to be allowed
	return EntryAllowed;
}

function PopupWindowsDisabled()
//Return whether popup windows have been disabled for the site
{
	var PopupsDisabled = false;
	var PopupEnabledQueryCmd = 'popupsenabled=';

	//Check whether the query is passed indicating that the windows are disabled
	var PageQuery = unescape(window.location.search);
	PageQuery = PageQuery.toLowerCase();
	var PopupsEnabledCmdPos = PageQuery.indexOf(PopupEnabledQueryCmd);

	//if the popups enabled command exists
	if(PopupsEnabledCmdPos != -1)
	{
		//Read out the command information
		var PopupsEnabledCmd = PageQuery.substring(PopupsEnabledCmdPos + PopupEnabledQueryCmd.length, PageQuery.length);
		var PopupsEnabledCmdEndPos = PopupsEnabledCmd.indexOf('&');	
		
		//remove the following commands from the string
		if(PopupsEnabledCmdEndPos != -1)
			PopupsEnabledCmd = PopupsEnabledCmd.substring(0, PopupsEnabledCmdEndPos);		

		//set whether the windows are enabled
		PopupsDisabled = (PopupsEnabledCmd == '0' ? true : false);
	}

	//return whether the windows are enabled
	return PopupsDisabled;
}

function LaunchHelpWindow(helpURL)
//Launch a help window with the passed URL
{
var width=658;
var height=300;
var left=(screen.width - width - 50);
var top=(screen.height - height - 72);

window.open(helpURL, '_help', 'status=no,toolbar=no,location=no,menu=no,resizable=yes,scrollbars=yes,left=' + left + ',top=' + top + ',height=' + height + ',width=' + width);
}

function WritePortalHeader(baseImageURL)
//Write out the header for the portal pages - this includes logo and hyperlinks
{
	document.write('<table cellSpacing="0" cellPadding="0" border="0" class="PortalBanner">');
	document.write('<tr><td class="PortalBannerLeft">');
	document.write('<table cellSpacing="0" cellPadding="0" border="0">');
	document.write('<tr><td background="' + baseImageURL + 'custom\/images\/siteheader_menu.png" class="PortalHeaderMenu"><ul>');
	document.write('<li><a title="ClassCampus On-Line Learning Portal" href="\/">Home<\/a><\/li>');
	document.write('<li><a title="View guides on getting started with your site" href="\/gettingstarted">Guides<\/a><\/li>');
	document.write('<li><a title="Extra help and tips on using your site" href="/help/hosted" target="_blank">Help<\/a><\/li>');
	document.write('<li><a title="Frequently asked questions on ClassCampus" href="\/faqs">FAQ\'s<\/a><\/li>');
	document.write('<li><a title="Contact a person or department at LJ Create" href="http:\/\/www.ljcreate.com\/contacts">Contact Us<\/a><\/li>');
	document.write('<li><a title="Information about the LJ Create company" href="http:\/\/www.ljcreate.com/\about">About Us<\/a><\/li>');
	document.write('<\/ul><\/td><\/tr>');
	document.write('<tr><td><img src="' + baseImageURL + 'custom\/images\/siteheader_banner.jpg" alt="ClassCampus On-Line Learning Portal"><\/td>');
	document.write('<\/tr><\/table>');
	document.write('<\/td>');
	document.write('<td class="PortalBannerRight"><img src="' + baseImageURL + 'custom\/images\/siteheader_logo.jpg" alt="LJ Create - Learning for Life">');	
	document.write('<\/td><\/tr><\/table>');
}

function WritePortalFooter()
//Write out the footer for the portal pages 
{
	document.write('<table cellspacing="0" cellpadding="0" class="FooterTable" border="0">');
	document.write('<tr><td class="FooterSeparator">&nbsp;<\/td><\/tr>');
	document.write('<tr class="Footer">');
	WriteFooterData(false);
	document.write('<\/tr><\/table>');
}

function WriteSiteHomeFooter()
//Write out the footer for the site home pages
{

	document.write('<table border="0" width="100%" cellpadding="0" cellspacing="0" class="SiteFooter">');
	document.write('<tr>');
	WriteFooterData(true);
	document.write('<\/tr><\/table>');
}

function WriteFooterData(launchNewWindow)
//Write out the data required for the footer - includes the current year in the copyright message
{
	var currentDate = new Date();
	var targetLaunch = (launchNewWindow == true) ? ' target="ClassCampus_Info"' : '' ;

	document.write('<td>Copyright <strong>' + String.fromCharCode(169) + '<\/strong> <a title="Go to the LJ Create website" class="FooterCompanyLink" href="http:\/\/www.ljcreate.com"' + targetLaunch + '>LJ Create<\/a> ' + currentDate.getUTCFullYear() +'. All rights reserved.<\/td>');
	document.write('<td align="right">');
	document.write('<a title="About Your Privacy" href="http:\/\/www.classcampus.com\/about\/Privacy\/"' + targetLaunch + '>Privacy<\/a> | '); 
	document.write('<a title="About Our Website" href="http:\/\/www.classcampus.com\/about\/Website\/"' + targetLaunch + '>Website<\/a>');
	document.write('<\/td>');
}

