function stringFilter(input) 
{
   var s = "";
   var i;
   var c;
   var returnString;
   
   s = input;
   
   filteredValues = "\\;¬/!\"£$%^&*()_-+={}[]'~#?><,.\|/";
   returnString = "";
   for (i = 0; i < s.length; i++) 
   {  
      c = s.charAt(i);
      if (filteredValues.indexOf(c) == -1) returnString += c;
   }
   return returnString;
}

function submitSearch()
{	
	var targetSearchTerm = "";
	targetSearchTerm = stringFilter(document.forms['searchForm'].strSearch.value) ;
	if (targetSearchTerm == "")
	{
		alert("Please enter a search term") ;
	}
	else
	{
		window.location.href='../siteSearch/search.asp?strSearch=' + targetSearchTerm;
	}
}

function submitSearchPage()
{	
	var targetSearchTerm = "";
	targetSearchTerm = stringFilter(document.forms['searchFormPage'].strSearch.value) ;
	if (targetSearchTerm == "")
	{
		alert("Please enter a search term") ;
	}
	else
	{
		window.location.href='search.asp?strSearch=' + targetSearchTerm;
	}
}


//=========================================================================
//=== BEGIN: GET LAYER													===
//=== ----------------------------------------------------------------- ===
//=== REQUIRES: detectBrowser()											===
//=== ----------------------------------------------------------------- ===
//=== getLayer(layerId)													===
//===																	===
//=== finds and returns a layer object using the parsed layer id		===
//=========================================================================
	function getLayer(layerID)
	{
		var layerobj = "" ;
		
		if ((currentBrowser == "NS4")||(currentBrowser == "NS6"))
		{
			if (currentBrowser == "NS6")
			{layerobj = document.getElementById(layerID) ;}
			else
			{layerobj = document.layers[layerID] ;}
		}
		else if ((currentBrowser == "IE")||(currentBrowser == "Mac"))
		{layerobj = document.getElementById(layerID) ;}
		
		return layerobj ;
	}
//=========================================================================
//=== END: GET LAYER													===
//=========================================================================



//=========================================================================
//=== BEGIN: DETECT FLASH												===
//=== ----------------------------------------------------------------- ===
//=== detectFlash()														===
//=== this will return 'true' or 'false'								===
//=========================================================================
	// declare variables
	var requiredVersion = 5;   		// Version the user needs to view movie (max 9, min 2)
	
	var flash2Installed  = false;	// boolean. true if flash 2 is installed
	var flash3Installed  = false;	// boolean. true if flash 3 is installed
	var flash4Installed  = false;	// boolean. true if flash 4 is installed
	var flash5Installed  = false;	// boolean. true if flash 5 is installed
	var flash6Installed  = false;	// boolean. true if flash 6 is installed
	var flash7Installed  = false;	// boolean. true if flash 7 is installed
	var flash8Installed  = false;	// boolean. true if flash 8 is installed
	var flash9Installed  = false;	// boolean. true if flash 9 is installed
	var maxVersion 		 = 9;		// highest version we can actually detect
	var actualVersion    = 0;		// version the user really has
	var hasRightVersion  = false;	// boolean. true if it's safe to embed the flash movie in the page
	var jsVersion 		 = 1.0;		// the version of javascript supported
	
	var flashisinstalled     = false ; // boolean.  true if any flash is installed
	var flashnotinstalledmsg = "<font class='generic_font' style='color:CC0000'><b>You do not have flash installed</b></font><br><a class='generic_font_white' href=''>You can download a version from here</a><br><br>" ;
	
	// Check the browser...we're looking for ie/win, but not aol
	var isAOL = (navigator.appVersion.indexOf("AOL") != -1) ? true : false;
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; // true if we're on windows
	
	// This is a js1.1 code block, so make note that js1.1 is supported.
	jsVersion = 1.1;
	
	// Write vbscript detection on ie win. IE on Windows doesn't support regular
	// JavaScript plugins array detection.
	if(isIE && isWin && !isAOL)
	{
	  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	  document.write('on error resume next \n');
	  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
	  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
	  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
	  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
	  document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	}
	
	function detectFlash()
	{
		// If navigator.plugins exists...
		if (navigator.plugins)
		{
	  		// ...then check for flash 2 or flash 3+.
			if ((navigator.plugins["Shockwave Flash 2.0"])||(navigator.plugins["Shockwave Flash"]))
			{
				// Some version of Flash was found.
		  		
				// Set convenient references to flash 2 and the plugin description.
				var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
				// alert("Flash plugin description: " + flashDescription);
				
				// A flash plugin-description looks like this: Shockwave Flash 4.0 r5
				// We can get the major version by grabbing the character before the period
				// note that we don't bother with minor version detection.
				// Do that in your movie with $version or getVersion().
				var flashVersion = parseInt(flashDescription.substring(16));
				
				// We found the version, now set appropriate version flags. Make sure
				// to use >= on the highest version so we don't prevent future version
				// users from entering the site.
				flash2Installed = flashVersion == 2;    
				flash3Installed = flashVersion == 3;
				flash4Installed = flashVersion == 4;
				flash5Installed = flashVersion == 5;
				flash6Installed = flashVersion == 6;
				flash7Installed = flashVersion == 7;
				flash8Installed = flashVersion == 8;
				flash9Installed = flashVersion >= 9;
			}
		}
		
		// Loop through all versions we're checking, and
		// set actualVersion to highest detected version.
		for (i=2;i<=maxVersion;i++)
		{
			if (eval("flash" + i + "Installed") == true)
			{actualVersion = i ;}
		}
		
		// If we're on msntv (formerly webtv), the version supported is 4 (as of
		// January 1, 2004). Note that we don't bother sniffing varieties
		// of msntv. You could if you were sadistic...
		if (navigator.userAgent.indexOf("WebTV")!=-1)
		{actualVersion = 4 ;}
		
		// DEBUGGING: uncomment next line to display flash version
		// alert("version detected: " + actualVersion);
		
		// We're finished getting the version on all browsers that support detection.
		// Time to take the appropriate action.
		
		// If the user has a new enough version...
		if (actualVersion >= requiredVersion)
		{
			flashisinstalled = true ;
			hasRightVersion  = true ;
			//document.write('<b>You have flash installed</b>');
		}
		else
		{
			flashisinstalled = false ;
		}
	}
//=========================================================================
//=== END: DETECT FLASH													===
//=========================================================================


//=========================================================================
//=== BEGIN: GET ABSOLUTE "LEFT" POSITION OF A LAYER					===
//=== ----------------------------------------------------------------- ===
//=== getAbsoluteLeftPos(layerid)										===
//=== this will return the absolute 'left' position 					===
//=== of the parsed layer												===
//=========================================================================
	function getAbsoluteLeftPos(layerid)
	{
		//get the actual object of the parsed layer and set it's current offsetLeft position
		layerobj		= document.getElementById(layerid) ;
		absoluteLeftPos = layerobj.offsetLeft ;
		
		//as long as the layer object has a parent, add it's parent's offsetLeft position to the current offsetLeft position
		//thus building up the absolute 'left' position of the parsed layer
		while(layerobj.offsetParent!=null)
		{
			layerobjParent   = layerobj.offsetParent ;
			absoluteLeftPos += layerobjParent.offsetLeft ;
			layerobj 		 = layerobjParent ;
		}
		
		//return the absolute 'left' position of the parsed layer
		return absoluteLeftPos ;
	}
//=========================================================================
//=== END: GET ABSOLUTE "LEFT" POSITION OF A LAYER						===
//=========================================================================


//=========================================================================
//=== BEGIN: GET ABSOLUTE "TOP" POSITION OF A LAYER						===
//=== ----------------------------------------------------------------- ===
//=== getAbsoluteTopPos(layerid)										===
//=== this will return the absolute 'top' position 						===
//=== of the parsed layer												===
//=========================================================================
	function getAbsoluteTopPos(layerid)
	{
		//get the actual object of the parsed layer and set it's current offsetTop position
		layerobj 	   = document.getElementById(layerid) ;
		absoluteTopPos = layerobj.offsetTop ;
		
		//as long as the layer object has a parent, add it's parent's offsetTop position to the current offsetTop position
		//thus building up the absolute 'top' position of the parsed layer
		while(layerobj.offsetParent!=null)
		{
			layerobjParent   = layerobj.offsetParent ;
			absoluteTopPos  += layerobjParent.offsetTop ;
			layerobj 		 = layerobjParent ;
		}
		
		//return the absolute 'top' position of the parsed layer
		return absoluteTopPos ;
	}
//=========================================================================
//=== END: GET ABSOLUTE "TOP" POSITION OF A LAYER						===
//=========================================================================


//=================================================================================================================================================================================================
//=== BEGIN: POPUP A NEW WINDOW																																									===
//=== ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ===
//=== doPopup(url, windowName, width, height, customparameters)																																	===
//=== pops up a new window with the parsed url loaded																																			===
//===																																															===
//=== example usage:																																											===
//=== doPopup('http://www.adobe.com/products/acrobat/readstep.html','popupAcrobat','600','600','directories=yes,status=yes,resizable=yes,scrollbars=yes,location=1,menubar=yes,left=0,top=0') 	===
//=================================================================================================================================================================================================
	function doPopup(url, windowName, width, height, customparameters)
	{
		//Determine the browser if positioning of pop-up window is supported
		theversion=navigator.appVersion.substring(0,3);
		
		if (navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) == '4')
		{
			X = screenX + myscreen(outerWidth-width)/2;
			myscreenY = screenY + (outerHeight-height)/2;
		}
		else
		{
			//IE & Nav3 don't do positioning, variables just have to exist...
			myscreenX = 0;
			myscreenY = 0;
		}
		
		if (customparameters)
		{
			windowparams = customparameters
		}
		else
		{
			windowparams = "directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no"
		}
		
		//Default window name if not passed to function
		if (!windowName)
		{
			windowName = "popup_window";
		}
		
		wref = window.open (url, windowName, "toolbar=no,width=" + width + ",height=" + height + ",screenX=" + myscreenX + ",screenY=" + myscreenY + "," + windowparams) ;
		wref.focus();
	}
//=================================================================================================================================================================================================
//=== END: POPUP A NEW WINDOW																																									===
//=================================================================================================================================================================================================


//=========================================================================
//=== BEGIN: VALIDATE PARSED DATE										===
//=== ----------------------------------------------------------------- ===
//=== togglelayer(layerid,imagelayer,displayedimage,hiddenimage)		===
//=== Validates the parsed value to check it 							===
//=== is a date.  Returns true or false									===
//=========================================================================
	function isdate(datevalue)
	{
	    
	    //var datepattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2})$/ ;
	    var datepattern = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{2}||\d{4})$/ ;
	    var matchArray  = datevalue.match(datepattern);
	    
	    if (matchArray == null)
	    {
	        //alert("Please enter Test Date as either dd/mm/yyyy or dd-mm-yyyy");
	        alert("Please enter Test Date as dd/mm/yyyy");
	        return false;
	    }
	    
	    day   = matchArray[1] ;
	    month = matchArray[3] ;
	    year  = matchArray[5] ;
	    
	    if ((day < 1)||(day > 31))
	    {
	        alert("Day must be between 1 and 31") ;
	        return false ;
	    }
	    
	    if (month < 1 || month > 12)
	    {
	        alert("Month must be between 1 and 12") ;
	        return false ;
	    }
	    
	    if (((month==4)||(month==6)||(month==9)||(month==11))&&(day==31))
	    {
	        alert("Month " + month + " doesn`t have 31 days") ;
	        return false ;
	    }
	    
	    //Check for february 29th
	    if (month == 2)
	    {
	        if (year.length == 2)
	        {
	            if (year.substring(0,1)==9)
	            {year = "19" + year ;}
	            else
	            {year = "20" + year ;}
	        }
	        
	        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	        
	        if ((day > 29)||(day==29 && !isleap))
	        {
	            alert("February " + year + " doesn`t have " + day + " days");
	            return false ;
	        }
	    }
	    return true ;
	}
//=========================================================================
//=== END: VALIDATE PARSED DATE											===
//=========================================================================



function doWinResize(imgWidth,imgHeight)
{
	if(navigator.appName =='Microsoft Internet Explorer')
	{
	    window.resizeTo(imgWidth, imgHeight);
	    var winWidth;
	    var winHeight;
	    winWidth = screen.AvailWidth - imgWidth;
	    winHeight = screen.AvailHeight - imgHeight;
	    window.moveTo((screen.AvailWidth/2)-(imgWidth/2), (screen.AvailHeight/2)-(imgHeight/2));
	}
	else
	{
	    parent.window.resizeTo(imgWidth, imgHeight);
	    var winWidth;
	    var winHeight;
	    winWidth = self.screen.width - imgWidth;
	    winHeight = self.screen.height - imgHeight;
	    parent.window.moveTo((self.screen.width/2)-(imgWidth/2), (self.screen.height/2)-(imgHeight/2));	
	}
	top.focus();
}


function doValidateLogin()
{
	document.forms['frmLogin'].txtHiddenLogin.value = '';
	
	var blnErrMsg;
	var errMsg;
	var errMsg_Header;
	var errMsg_Details;
	var isValidEmail;
	
	blnErrMsg =			0;
	errMsg =			'';
	errMsg_Header =		'The following error(s) have occured:-\n';
	errMsg_Details =	'';
	
	if(document.forms['frmLogin'].txtEmailAddress.value!='')			{document.forms['frmLogin'].txtHiddenLogin.value=document.forms['frmLogin'].txtHiddenLogin.value + '|txtEmailAddress'};
	if(document.forms['frmLogin'].txtPassword.value!='')			{document.forms['frmLogin'].txtHiddenLogin.value=document.forms['frmLogin'].txtHiddenLogin.value + '|txtPassword'};

	if(document.forms['frmLogin'].txtHiddenLogin.value.indexOf("|txtEmailAddress")>=0)		{}else{errMsg_Details += '\n- Email Address is a mandatory value';}
	if(document.forms['frmLogin'].txtHiddenLogin.value.indexOf("|txtPassword")>=0)			{}else{errMsg_Details += '\n- Password is a mandatory value';}

	if(document.forms['frmLogin'].txtHiddenLogin.value.length!=28)
	{
		//Not all mandatory values have been entered
		blnErrMsg = 1;
		errMsg += errMsg_Details;
	}	

	//Create entire error string here
	if(blnErrMsg==1)
	{
		errMsg = errMsg_Header + errMsg_Details;
		alert(errMsg);
	}
	else
	{	
		//All values have been supplied, perform a check to validate that the email address is syntactically correct
		isValidEmail = emailCheck(document.forms['frmLogin'].txtEmailAddress.value)
		if(isValidEmail)
		{
			//alert('ok to submit');
			document.forms['frmLogin'].submit();
		}
	}
}

function emailCheck (emailStr) 
{
	var email_errMsg_Header = 'The following error(s) have occured:-\n';
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) 
	{
		alert(email_errMsg_Header + "\nThe email address supplied seems to be invalid. (check @ and .'s)")
		return false
	}
												
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) 
	{											    
		alert(email_errMsg_Header + '\nThe username in the email address is invalid')
		return false
	}
											
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				alert("The Destination IP Address Is Invalid")
				alert(email_errMsg_Header + '\nThe destination IP address is invalid')
				return false
			}
		}
		return true
	}

	var domainArray=domain.match(domainPat)

	if (domainArray==null) 
	{
		alert(email_errMsg_Header + '\nThe email address supplied includes an invalid domain name')
		return false
	}
													
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length

	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) 
	{
		alert(email_errMsg_Header + '\nThe email address supplied does not have a correct suffix (.co.uk, .com...)')
		return false
	}
	if (len<2) 
	{
		alert(email_errMsg_Header + '\nThe email address supplied is missing a hostname')
		return false
	}

	//If we've gotten this far, everything's valid	
	return true;
}
