//Created 21st February 2008.
//Used for the general functionality of the website.

var blnDom = false;
var blnBrowserGecko = false;
var blnBrowserExplorer = false;
var blnBrowserMozilla = false;
var blnBrowserNavigator = false;
var blnBrowserOpera = false;
var blnPngProblem = false;
var numBrowserVersion = null; 
var strBrowserName = new String("");


function getBenefitsImage()
//Change the image that initially starts with the benefits image.
{
	var img = document.getElementById("benefits");
	var aryImages = new Array("benefits", "new-site", "friend-introduction");
	
	var numImage = Math.random() * 2;
numImage = 0;	
	numImage = Math.round(numImage);
	var strImage = aryImages[numImage];
	var strImage = strImage + ".png";
	
	return strImage;
}

function getBrowserType()
//Need to ascertain the type of browser for certain functionality.
{
	var strUserAgent = window.navigator.userAgent;
	strUserAgent = strUserAgent.toUpperCase();
//alert(strUserAgent);
	with (strUserAgent)
	{
		blnBrowserMozilla = indexOf("MOZILLA") > -1;
		
		if (blnBrowserMozilla)
		{
			blnBrowserExplorer = indexOf("MSIE") > -1;
			
			if (!blnBrowserExplorer)
				blnBrowserGecko = indexOf("GECKO") > -1;
			else if (!blnBrowserGecko)
			{
				blnBrowserNavigator = indexOf("SPOOFER") == -1;
				blnBrowserNavigator = blnBrowserNavigator && indexOf("OPERA") == -1;
				blnBrowserNavigator = blnBrowserNavigator && indexOf("COMPATIBLE") == -1;
				blnBrowserNavigator = blnBrowserNavigator && indexOf("HOTJAVA") == -1;
				blnBrowserNavigator = blnBrowserNavigator && indexOf("WEBTV") == -1;
			}
		}
		else
		{
			blnBrowserOpera = indexOf("OPERA") > -1;
		}
	}

	//Need to know the browser version if possible.
	getBrowserVersion();
}

function getBrowserVersion()
//Get the version of the browser.
{
	var strVersion = "";
	var strAgent = window.navigator.userAgent;
	strAgent = strAgent.toUpperCase();
	
	//Need to test for certain strings.
	var aryTest = new Array("MSIE ", "FIREFOX/", "NETSCAPE/", "OPERA/", "MOZILLA/");
	var strTest = new String("");
	var blnFound = false;

	for (numElement in aryTest)
	{
		strTest = aryTest[numElement];
		blnFound = strAgent.indexOf(strTest) > -1;
		
		if (blnFound)
		{
			var aryVersion = strAgent.split(strTest);
			strVersion = aryVersion[1];
			numBrowserVersion = parseFloat(strVersion);
			break;
		}
	}
	//alert(numBrowserVersion);
}

function initPage()
//Initialise the page, called on loading into the browser.
{
	loadImages();
	initialiseMenus();
	initialiseMenuNames();
	blnInitialised = true;
}

function openCompanyCheckWindow()
//Opens the window for the online check with Companies House.
{
	var strAttributes = "width=800,height=600,"; 
	strAttributes += "menubar=no,scrollbars=yes,resizable=yes";
	
	window.open("http://www.companieshouse.gov.uk/info/", "", strAttributes);	
}

function openFeedbackForm()
//Open the pop up for the info pack form.
{
	var strAttributes = "width=600,height=500,menubar=no"; 
	var strLink = "https://secure.turnerlittle.com/feedback.php";
	
	window.open(strLink, "", strAttributes);
}


function openInfoPackForm()
//Open the pop up for the info pack form.
{
	var strAttributes = "width=600,height=500,menubar=no"; 
	var strLink = "https://secure.turnerlittle.com/info-pack.php";
	
	window.open(strLink, "", strAttributes);
}

function openLiveSupport()
//Opens the window for Live Support.
{
	var strAttributes = "width=500,height=350,"; 
	strAttributes += "menubar=no,scrollbars=no,resizable=no";
	var strLink = "http://www.chatstat.com/chatstat_offsiteHandle.asp?csuid=54203&email=any";
	
	window.open(strLink, "", strAttributes);		
}

function openPopup(strLink, numWidth, numHeight)
//opens up a pop up of specified width & height.
{
	var strAttributes = "width=" + numWidth + ","; 
	strAttributes += "height=" + numHeight.toString() + ",";
	strAttributes += "menubar=no";
	
	window.open(strLink, "", strAttributes);
}

function setBrowserCapabilities()
//Sets the various browser capabilites such as DOM or aplpa png images.
{
	if (blnBrowserExplorer)
	{
		blnDom = numBrowserVersion > 5;
		blnPngProblem = (numBrowserVersion == 5.5) || (numBrowserVersion == 6); 
	}
	else if (blnBrowserGecko)
	{
		blnDom = true;
	}
	else if (blnBrowserNavigator)
	{
		blnDom = winow.navigator.appVersion >= 5;
	}
	else if (blnBrowserOpera)
	{
		blnDom= numBrowserVersion >= 7;
	}
}
