// Global browser version variables
var bIE4 = false;
var bIE5 = false;
var bNS4 = false;
var bNS6 = false;
var bOpera = false;
var strBrowserName = navigator.appName;
var nBrowserVer = parseInt(navigator.appVersion);
if (strBrowserName.indexOf('Microsoft') != -1)
{
	var strBrowserVersionData = navigator.appVersion;
	var nStartPos = strBrowserVersionData.indexOf('MSIE');
	var strVersion = strBrowserVersionData.substring(nStartPos + 5, nStartPos+13);
	var fBrowserVer = parseFloat(strVersion);

	if (fBrowserVer >= 5) 
		bIE5 = true;
	else
		bIE4 = true;
}
else if (strBrowserName.indexOf('Netscape') != -1)
{
	if (nBrowserVer >= 5)
		bNS6 = true;
	else
		bNS4 = true;
}
else if (navigator.userAgent.indexOf('Opera') != -1)
{
	bOpera = true;
	bIE5 = true;	// We will treat Opera like IE5!!
}

/////////////////////////////////////
// Include general javascript functions in here

// MJM 11/5/99
// If a search engine finds a frame page rather than a frameset document
// then the frame page can be displayed without it's frame.  Resolve this
// problem by adding  OnLoad="loadframe('frameset.html')"    to the BODY
// tag of the frame page, using the appropriate URL of the frameset page.
function loadframe(sFn)
{
    if (top==self)
        self.location.href = sFn;
};

// MJM 13/5/99
// Displays the string sDisplayText in the status bar.  Only works for Internet
// Explorer at the moment.
function statusbartext(sDisplayText)
{
	if (strBrowserName == "Microsoft Internet Explorer")
	    window.status = sDisplayText;
	else
		self.status = sDisplayText;
};

function CheckEmail(sEmail){
	//Quick check of Email pattern. Should catch more than 90% of emails
	var bMatch = sEmail.match(/^[\"\(\)\<\>\[\]\:\\\,\w-]+(\.[\"\(\)\<\>\[\]\:\\\,\w-]+)*@[\"\(\)\<\>\[\]\:\\\,\w-]+(\.[\"\(\)\<\>\[\]\:\\\,\w-]+)+$/) ? true : false;
	//If pattern is ok, verify if each special character accepted is quoted
	if (bMatch){
		//Check if there's a quote
		if (sEmail.indexOf(String.fromCharCode(34)) != -1){
			//There's a quote, so check if any exception is present
			var sTmpStr = sEmail;
			var sRegexp;
			//Check (
			if (sEmail.indexOf(String.fromCharCode(34) + "(" + String.fromCharCode(34)) != -1){
				sRegexp = /("\(")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check )
			if (sEmail.indexOf(String.fromCharCode(34) + ")" + String.fromCharCode(34)) != -1){
				sRegexp = /("\)")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check <
			if (sEmail.indexOf(String.fromCharCode(34) + "<" + String.fromCharCode(34)) != -1){
				sRegexp = /("<")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check >
			if (sEmail.indexOf(String.fromCharCode(34) + ">" + String.fromCharCode(34)) != -1){
				sRegexp = /(">")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check [
			if (sEmail.indexOf(String.fromCharCode(34) + "[" + String.fromCharCode(34)) != -1){
				sRegexp = /("\[")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check ]
			if (sEmail.indexOf(String.fromCharCode(34) + "<" + String.fromCharCode(34)) != -1){
				sRegexp = /("\]")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check :
			if (sEmail.indexOf(String.fromCharCode(34) + ":" + String.fromCharCode(34)) != -1){
				sRegexp = /(":")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check \
			if (sEmail.indexOf(String.fromCharCode(34) + String.fromCharCode(92) + String.fromCharCode(34)) != -1){
				sRegexp = /("\\")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Check ,
			if (sEmail.indexOf(String.fromCharCode(34) + "," + String.fromCharCode(34)) != -1){
				sRegexp = /(",")+/ig
				sTmpStr = sTmpStr.replace(sRegexp,"");
			}
			//Verify if sTmpStr still has quotes. If yes, it's an error
			if (sTmpStr.indexOf(String.fromCharCode(34)) != -1){
				bMatch = false;
			}
		}
		//If no quotes check if any invalid character is present and return false if yes
		else{
			if ((sEmail.indexOf("(") != -1) || (sEmail.indexOf(")") != -1) || (sEmail.indexOf("<") != -1) || (sEmail.indexOf(">") != -1) || (sEmail.indexOf("[") != -1) || (sEmail.indexOf("]") != -1) || (sEmail.indexOf(":") != -1) || (sEmail.indexOf(",") != -1) || (sEmail.indexOf(String.fromCharCode(92)) != -1)){
				bMatch = false;
			}
		}
	}
	return bMatch;
}
	
// Utility function to trim spaces from both ends of a string
function Trim(inString) 
{
  var retVal = "";
  var start = 0;
  
  while ((start < inString.length) && (inString.charAt(start) == ' ')) 
  {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) 
  {
    --end;
  }

  if (start >= end)
  {	
	retVal = "";
  }
  else
  {
	retVal = inString.substring(start, end);
  }

  return retVal;
}

function QueryString(sName) 
// URLs can contain information such as http://www.test.co.uk/test.htm?val1=321&val2=777.
// This function will extract the value of a named URL parameter.  ie. in the above case
// calling QueryString("val1") will return "321".
{
	var sURL = new String(window.location);
	var iLensName=sName.length;
  	//
	
	// Is our parameter the 1st parameter ?
	var iStart = sURL.indexOf('?' + sName +'=')
	if (iStart==-1)
	{
		// No, is our parameter a subsequent parameter.
        iStart = sURL.indexOf('&' + sName +'=')//limitation 1
		if (iStart==-1)
		{	
			// Finally, look for our parameter as a subsequent parameter but with the 
			// & symbol converted to %26
			iStart = sURL.indexOf("%26" + sName +'=')//limitation 1
			if (iStart==-1)
				return ""; //not found
			else
				iStart+=2;	// As it is a 3 char %26 we must add a 2 point increment.
		}   
	}
    
	// Now adjust start position to remove parameter name.
	iStart = iStart + iLensName + 2;
	
	// Determine if ours is the last parameter.
	var iTemp= sURL.indexOf('&',iStart); //next pair start
	if (iTemp ==-1)
	{
		// Again attempt again with %26 encoding of &
		iTemp= sURL.indexOf("%26",iStart); //next pair start
		if (iTemp ==-1)
			iTemp=sURL.length;
	}
	
  	return sURL.slice(iStart,iTemp ) ;
  	sURL=null;//destroy String
}

function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// End of general javascript functions
/////////////////////////////////////
