// 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!!
}

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 getCookie(NameOfCookie)
{

// First we check to see if there is a cookie stored.
// Otherwise the length of document.cookie would be zero.

if (document.cookie.length > 0) 
{ 

// Second we check to see if the cookie's name is stored in the
// "document.cookie" object for the page.

// Since more than one cookie can be set on a
// single page it is possible that our cookie
// is not present, even though the "document.cookie" object
// is not just an empty text.
// If our cookie name is not present the value -1 is stored
// in the variable called "begin".

begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) // Note: != means "is not equal to"
{ 

// Our cookie was set. 
// The value stored in the cookie is returned from the function.

begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); } 
}
return null; 

// Our cookie was not set. 
// The value "null" is returned from the function.

}
 
 
function getCookie(NameOfCookie)
{ if (document.cookie.length > 0) 
{ begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) 
{ begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); } 
}
return null; 
}

function setCookie(NameOfCookie, value, expiredays) 
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + 
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) 
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

function Trim(strValue)
{
	if(strValue.length < 1)
	{
		return"";
	}
	strValue = RTrim(strValue);
	strValue = LTrim(strValue);
	if(strValue=="")
	{
		return "";
	}
	else
	{
		return strValue;
	}
} //End Function

function RTrim(strValue)
{
	var w_space = String.fromCharCode(32);
	var v_length = strValue.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(strValue.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = strValue.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;
} //End Function

function LTrim(strValue)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = strValue.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(strValue.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = strValue.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function
