//flash detection script
var flash5 = false; 
var flash6 = false;
cnflashDetect=false;
detectFlash()

//Flash detect function
function detectFlash()
{ 
	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
	// Write vbscript detection on ie win. IE on Win 
	if(isIE && isWin)
	{
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
	document.write('flash6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
	document.write('</SCR' + 'IPT\> \n');
	} 
	// If netscape or mac(not version 4.5)
	if (navigator.plugins) 
	{		
		if ( navigator.plugins["Shockwave Flash"])// ...then check flash 3+. 
		{
		var flashDescription = navigator.plugins["Shockwave Flash"].description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		flash5 = flashVersion == 5;
		flash6 = flashVersion >= 6;	  
		}
	}
	//set flash detect variable
	if(flash6==true)
	{cnflashDetect=true;}
}
//end of flash detection script

//Generic popup function   
function openPopup(urllink,popName,h,w,scroll)
{
  dummy=window.open(urllink,popName,"toolbar=0,status=no,menuBar=0,scrollbars="+scroll+",resizable=no,width=" + w + ",height=" + h + ",left=10,top=10");
}

//Open link in new window
function openLink(urllink,popName)
{
	if (urllink != '')
		dummy=window.open(urllink,popName);
}

//Checks for blank elements
function isblank(s)
{
  for(var i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    if ((c!=' ') && (c!='\n') && (c!='\t')) return false;
  }
  return true;
}
 
//Checks for empty elements
function isEmpty(s)
{
  if (!(s.value==null || s.value=="" || isblank(s.value)))return false;
  return true;
}
 
function isValid(element) {
    if (isEmail(element.value) == false) {
        element.focus();
		FormError=FormError+"Please enter a valid email address.\n";
        return false;
    } 
    return true;
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}
	
function isPostcode(strPost,country) 
{
    var country=new String(country.value)
	country=country.toUpperCase()
	var strPost=new String(strPost.value)
	strPost=strPost.toLowerCase()
	if(country=="UK" || country=="BRITISH" || country=="BRITAIN" || country=="WALES" || country=="SCOTLAND" || country=="ENGLAND" || country=="UNITED KINGDOM")
		{
		if (strPost.search(/[a-z]{1,2}\d{1,2}[a-z]?\s*\d[a-z]{2}/) != -1)
			return true;
    	else
			FormError=FormError+"Please enter a valid postcode.\n";
        	return false;
		}
	else
		return true;
}

//Generic drop down handler
function DropDown(element, winType)
{
	if (element != null) 
	{
		if (element.options[element.selectedIndex].value != "")
		{
  			if(winType==1 || element.options[element.selectedIndex].value.indexOf('subscription') > -1)
			{
				var temp; 
				temp = window.open(element.options[element.selectedIndex].value)
			}
			else
			{
				top.location = element.options[element.selectedIndex].value;
			}
		}
	}
}

// BEGIN : Browser check script
var detect = navigator.userAgent.toLowerCase();
var OS, browser, version, total, thestring;
function detectBrowser() {
	if (checkIt("konqueror")) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt("safari")) browser = "Safari";
	else if (checkIt("omniweb")) browser = "OmniWeb";
	else if (checkIt("opera")) browser = "Opera";
	else if (checkIt("webtv")) browser = "WebTV";
	else if (checkIt("icab")) browser = "iCab";
	else if (checkIt("msie")) browser = "Internet Explorer";
	else if (!checkIt("compatible")) {
		browser = "Netscape Navigator";
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";
	if (!version) version = detect.charAt(place + thestring.length);
	if (!OS) {
		if (checkIt("linux")) OS = "Linux";
		else if (checkIt("x11")) OS = "Unix";
		else if (checkIt("mac")) OS = "Mac";
		else if (checkIt("win")) OS = "Windows";
		else OS = "an unknown operating system";
	}
};
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
};
// END : Browser check script

var mpuID = "AdBottom1";
var mpuPH = "divMpu"; // id of the mpu placeholder div

// alignMpu is used to move a div containing the MPU over a div that is used as a placeholder for where the MPU should sit
function alignMpu(placeholder, mpu) {
	// it would be better to use appendChild here to move mpu but this will kill the display of NS7/Mac
	// so we'll use a crappy browser sniff to detect the browser as object detection will not produce a good result
	if (OS == "Mac" && browser == "Netscape Navigator" && version == "5") {
		// copy the html of the mpu into the placeholder.
		placeholder.innerHTML = mpu.innerHTML;
		// remove the original mpu from the dom
		mpu.parentNode.removeChild(mpu);
	} else {placeholder.appendChild(mpu); }// do it the right way
	// display the mpu
	mpu.style.display = "block";
}
function addEventSimple(obj, evt, fn)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(evt, fn, false);
	}
	else if (obj.attachEvent)
	{
		obj.attachEvent("on" + evt, fn);
	}
};
function validateForm()
{
	var error = false;
	var errorMessage = "";

	//Validate all drop down lists
	var fieldIds = document.getElementsByTagName("select");
	for (var i = 0; i < fieldIds.length;i++)
	{
		var item = fieldIds[i];
		if (item.getAttribute("Required") != null && item.getAttribute("Required").toLowerCase() == "true" && item.selectedIndex == 0)
			errorMessage += getErrorMessage(item);
	}

	//Validate all inputs
	var fieldIds = document.getElementsByTagName("input");
	for (var i = 0; i < fieldIds.length;i++)
	{
		var item = fieldIds[i];
		if (item.getAttribute("Required") != null && item.getAttribute("Required").toLowerCase() == "true")
		{
			if ((item.type == "text" && item.value.length == 0) || (item.type == "checkbox" && item.checked == false))
				errorMessage += getErrorMessage(item);
		}
	}
	
	//Display error if it exists
	if (errorMessage.length > 0)
	{
		alert("The following errors were encountered\n" + errorMessage);
		return false;
	}
	else
		return true;
}

function getErrorMessage(item)
{
	if (item.getAttribute("ErrorMessage") != null)
		return "\n" + item.getAttribute("ErrorMessage");
	else
		return "\n" + item.id + " is required";
}