var browserIE = document.all;
var browserFF = document.getElementById && !document.all;

function fncGlobal_doGoBack(sConfirmMsg)			{if(sConfirmMsg != ''){if(confirm(sConfirmMsg)){	window.history.go(-1);}}else{window.history.go(-1);}}
function fncGlobal_doGoTo(sUrl,sConfirmMsg)			{if(sConfirmMsg != ''){if(confirm(sConfirmMsg)){location.href=sUrl;}}else{location.href=sUrl;}}
function fncGlobal_doValidateAllSpaces(oValue)		{for (i=0;i<oValue.length;i++){if(oValue.charAt(i) != " "){ return false;}}return true;}
function fncGlobal_doTrimCharacters(oValue)			{if(oValue == null || oValue == ""){return "";}	while('' + oValue.charAt(0)==' '){oValue = oValue.substring(1, oValue.length);}	while('' + oValue.charAt(oValue.length-1)==' '){oValue = oValue.substring(0,oValue.length-1);}return oValue;}
function fncGlobal_doIsValidEmail(oValue)			{var IsValid = true;	var regEmail = /^[^@]+@[^@]+.[a-z]{2,}$/i;	if(oValue.length){IsValid = regEmail.test(oValue);}	return IsValid;}	
function fncGlobal_doRightTrim(oValue, oTrimChar)	{while (1){if (oValue.substring(oValue.length - 1, oValue.length) != oTrimChar){break;}oValue = oValue.substring(0, oValue.length - 1);}return oValue;}
function fncGlobal_doSelect(oElement, bSelected)
{
	var oLength = oElement.length;
	if(oLength == 0){/* Do Nothing */;}
	else if(oLength == 1 || oLength == null)
	{
		if(oElement.selected != bSelected)
			oElement.selected = bSelected;
	}
	else
	{
		for(i=0; i < oLength; i++)
		{
			if(oElement(i).selected != bSelected)
				oElement(i).selected = bSelected;
		}	
	}
    return true;
}

function fncGlobal_doIsRequiredFieldsValid(oForm, arrFields, arrNames)
{
	var IsValid = true;
	
	try
	{
		for(var i=0; i < arrFields.length; i++)
		{
			var oElement = oForm.elements[arrFields[i]];
			if(oElement)
			{
				if ((oElement.type == "text") 
					|| (oElement.type == "password")
					|| (oElement.type == "textarea")
					|| (oElement.type == "radio")) 
				{
					if(fncGlobal_doTrimCharacters(oElement.value).length == 0)
					{ 
						alert('Please enter the '+ arrNames[i] +' and try again.');
						oElement.focus();
						IsValid = false;
						break;
					}
				}
				else if (oElement.type.indexOf("select") != -1) 
				{
					if((fncGlobal_doTrimCharacters(oElement.value).length == 0)
						||(oElement.value == -1))
					{ 
						alert('Please select the '+ arrNames[i] +' and try again.');
						IsValid = false;
						oElement.focus();
						break;
					}
				}	
			}		
		}
	}
	catch (ex)
	{
		IsValid = false;	
	}	

	return IsValid;
}

function fncGlobal_doIsRequiredFieldsValidOld(oForm)
{
	var fieldCounter = 0;
	var IsValid = true;
						 
	try
	{
		while ((fieldCounter < oForm.elements.length) && (IsValid))
		{
			var oElement = oForm.elements[fieldCounter];

			if(oElement.required != null && ( oElement.required == "1" || oElement.required.toLowerCase() == "true"))
			{
				if ((oElement.type == "text") 
					|| (oElement.type == "password")
					|| (oElement.type == "textarea")
					|| (oElement.type == "radio")) 
				{
					if (oElement.value == '')
					{ 
						alert('Please enter the '+ oElement.label +' and try again.');
						oElement.focus();
						IsValid = false;
					}
				}
				else if (oElement.type.indexOf("select") != -1) 
				{
					if ((oElement.value == '')
						||(oElement.value == -1))
					{ 
						alert('Please select the '+ oElement.label +' and try again.');
						IsValid = false;
						oElement.focus();
					}
				}
			}
			fieldCounter ++;
		}
	}
	catch (ex)
	{
		IsValid = false;	
	}	

	return IsValid;
}			

function fncGlobal_doReplace(originalString,findText,replaceText) 
{
    var strLength = originalString.length, txtLength = findText.length;
    if ((strLength == 0) || (txtLength == 0)) return originalString;

    var i = originalString.indexOf(findText);
    if ((!i) && (findText != originalString.substring(0,txtLength))) return originalString;
    if (i == -1) return originalString;

    var newstr = originalString.substring(0,i) + replaceText;

    if (i+txtLength < strLength)
        newstr += replace(originalString.substring(i+txtLength,strLength),findText,replaceText);

    return newstr;
}

function fncGlobal_doAppendQuerystringParameter(sUrl, sName, sValue) { return sUrl + (sUrl.indexOf("?") == -1 ? "?" : "&") + sName + "=" + sValue; }