// JavaScript Common to Whole Application

// Add trim functions to String object
String.prototype.trim = function() 
{
	return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function() 
{
	return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function() 
{
	return this.replace(/\s+$/, "");
}

// Check for numeric value 
function isNumeric(value)
{
	var numericRegExp = /^\d+$/;
	var regExp = new RegExp(numericRegExp);
	return regExp.test(value);
}

function isValidEmail(emailAddress)
{
	var emailRegExp = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
    var regExp = new RegExp(emailRegExp);
	return regExp.test(emailAddress);
}

function isValidZip(zipCode)
{
	var zipRegExp =/^\d{5}$/;
	var regExp = new RegExp(zipRegExp);
	return regExp.test(zipCode);
}

function isValidPhone(value)
{
	var validFlag = false;
	var phoneRegExp = "[0-9\(\) -]";
	var regExp = new RegExp(phoneRegExp);
	if (regExp.test(value))
	{
		var numericValue = removeNonNumeric(value);
		if (numericValue.length >= 1)
		{
			validFlag = true;
		}
	}
	
	return validFlag;
}

function removeNonNumeric(value)
{
	// Remove all non-numeric characters
	var numericValue = value.replace(/[^0-9]/g, "");
	return numericValue;
}

// Function for trimming and updating a field value
function ftrim(fieldObj)
{
	fieldObj.value = fieldObj.value.trim();
	return fieldObj;
}

function activateMenu(selectedMenuID, nonSelectedID1, nonSelectedID2,
	nonSelectedID3, nonSelectedID4, nonSelectedID5) 
{
	document.getElementById(selectedMenuID).className="active";
	document.getElementById(nonSelectedID1).className="";
	document.getElementById(nonSelectedID2).className="";
	document.getElementById(nonSelectedID3).className="";
	document.getElementById(nonSelectedID4).className="";
	document.getElementById(nonSelectedID5).className="";
}

String.prototype.startsWith = function(str) 
{return (this.match("^"+str)==str)}

String.prototype.endsWith = function(str) 
{return (this.match(str+"$")==str)}
