// Common Scripts Used On All Pages //
// Version V1.0.0, 04/08/2007 WBM. //
// Copyright 2007. Property of Design Atom - wwww.designatom.com//

// Navigate to the link passed
function fctLoadPage(strLink) {
	window.location = strLink
}

// This is called when a key is pressed on the screen
function fctCheckKey(strKeycode,strPage){
	// Check if this is an accessibility key (1 - 4)
	switch(strKeycode){
		case 49 :
			// Toggle Large Text
			fctLargeText();
			break;
		case 50 :
			fctBraille();
			break;
		case 51 :
			fctFastkeys();
			break;
		case 52 :
			fctAudio(strPage);
			break;
	}
	
	// Check if Fastkeys are Enabled
	if(strFastkeys=="on" || strBraille=="on"){
		// Convert the ASCII code into a keytype
		strKeytype = String.fromCharCode(strKeycode);
	
		// Initialise Array
		var arrGenerickeys = new Array();
		arrGenerickeys["A"] = "../websites/accessibility.php";
		arrGenerickeys["B"] = "../company/aboutus.php";
		arrGenerickeys["C"] = "../websites/collaboration.php";
		arrGenerickeys["D"] = "../databases/databases.php";
		arrGenerickeys["E"] = "../websites/ecommerce.php";
		arrGenerickeys["H"] = "../index.php";
		arrGenerickeys["I"] = "../applications/integration.php";
		arrGenerickeys["J"] = "../domains/domains.php";
		arrGenerickeys["K"] = "../company/cookies.php";
		arrGenerickeys["L"] = "../help/help.php";
		arrGenerickeys["M"] = "../marketing/emarketing.php";
		arrGenerickeys["N"] = "../applications/applications.php";
		arrGenerickeys["O"] = "../video/podcasts.php";
		arrGenerickeys["P"] = "../pricing/prices.php";
		arrGenerickeys["R"] = "../company/privacy.php";
		arrGenerickeys["S"] = "../sitemap.php";
		arrGenerickeys["T"] = "../company/terms.php";
		arrGenerickeys["U"] = "../company/contactus.php";
		arrGenerickeys["V"] = "../video/videos.php";
		arrGenerickeys["W"] = "../websites/websites.php";
		arrGenerickeys["Y"] = "../company/whyus.php";
		
		// Check for this keypress in list of Generic keys
		strTarget = arrGenerickeys[strKeytype];

		// If a target has been set then navigate to it
		if(strTarget){
			window.location.href = strTarget;
		}
		
		// Check for this keypress in list of Page specific keys
		strTarget = arrPagekeys[strKeytype];

		// If a target has been set then navigate to it
		if(strTarget){
			window.location.href = strTarget;
		}
	}
}

// Accessibility Option Toggle Large Text On and Off
function fctLargeText(){
	// Check if Large Text is already selected
	if(strTextOptions=="on"){
		// Turn off the Large Text Option
		document.cookie = "largetext=off";
	}
	else{
		// Turn on the Large Text Option
		document.cookie = "largetext=on";
	}
	
	// Reload the current page to load accessibility options
	window.location.reload();
}

// Accessibility Option Toggle Braille On and Off
function fctBraille(){
	// Check if Braille is already selected
	if(strBraille=="on"){
		// Turn off the Braille Option
		document.cookie = "braille=off";
	}
	else{
		// Turn on the Braille Option
		document.cookie = "braille=on";
	}
	
	// Reload the current page to load accessibility options
	window.location.reload();
}

// Accessibility Option Toggle Fastkeys On and Off
function fctFastkeys(){
	// Check if Fastkeys is already selected
	if(strFastkeys=="on"){
		// Turn off the Fastkeys Option
		document.cookie = "fastkeys=off";
	}
	else{
		// Turn on the Fastkeys Option
		document.cookie = "fastkeys=on";
	}
	
	// Reload the current page to load accessibility options
	window.location.reload();
}

// Toggle the Audio Commentry On and Off
function fctAudio(strPage) {
	// Check if Audio is already selected
	if(strAudio=="on"){
		// Turn off the Audio Option
		document.cookie = "audio=off";
		
		// Check if the audio player is loaded
		if (document.getElementById("audioplayer").innerHTML!=""){
			// The audio player is loaded so stop the audio playing
			fctStopAudio();
		}
		
		// Set the user preference
		strAudio="off";
	}
	else{
		// Turn on the Audio Option
		document.cookie = "audio=on";
		
		// Check if the audio player is loaded
		if (document.getElementById("audioplayer").innerHTML==""){
		
			// The audio player is not loaded so load it now
			fctLoadAudio(strPage);
		}
		else {
			// Player is already loaded so play the commentry
			fctPlayAudio();
		}
		
		// Set the user preference
		strAudio="on";
	}
}

// Load the audio player into the current document
function fctLoadAudio(strPage){
	// Check if this is IE
	if (navigator.appName.indexOf("Microsoft")!=-1){
		// Audio player for IE
		document.getElementById('audioplayer').innerHTML='<object id="audio" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="150" height="10" codebase="http://www.apple.com/qtactivex/qtplugin.cab" style="visibility:visible"><param name="src" value="../_sounds/' + strPage + '.mp3" /><param name="autoplay" value="true" /><param name="controller" value="true" /></object>';
		
		// Return focus to the document to enable fastkeys
		document.body.focus();
	}
	else{
		// Audio player for other browsers
		document.getElementById('audioplayer').innerHTML='<object id="audio" type="audio/mpeg" width="150" height="10" data="../_sounds/' + strPage + '.mp3" style="visibility:visible"><param name="type" value="audio/mpeg" /><param name="autoplay" value="true" /><param name="showcontrols" value="false" /><param name="enableJavascript" value="true" /></object>';
	}
}

// Play the auditory commentry
function fctPlayAudio() {
	// Play the auditory commentry for this document
	if (navigator.appName.indexOf("Microsoft")!=-1 || navigator.appName.indexOf("Opera")!=-1) {
		document.all.audio.Play();
	}
	else {
		document.audio.Play();
	}
}

// Stop Playing the auditory commentry
function fctStopAudio() {
	// Stop the auditory commentry
	if (navigator.appName.indexOf("Microsoft")!=-1 || navigator.appName.indexOf("Opera")!=-1) {
		document.all.audio.Stop();
	}
	else {
		document.audio.Stop();
	}
}
