
//--------------------------------------------------------------------
// TRIM A STRING
//--------------------------------------------------------------------
function trim(str)
{
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i > 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}



//--------------------------------------------------------------------
// SHOW THE MESSAGE BAR AT THE TOP OF THE PAGE
//--------------------------------------------------------------------
function showTopMsgBar(sMsg,sClass)
{
	if( sMsg != '' ) document.getElementById('topMsg').innerHTML = sMsg;
	if( sClass != '' ) document.getElementById('topMsg').className = sClass;
	document.getElementById('topMsgBar').style.display = '';
	document.documentElement.scrollTop = 0;
	return false;
}



//--------------------------------------------------------------------
// HIDE THE MESSAGE BAR AT THE TOP OF THE PAGE
//--------------------------------------------------------------------
function hideTopMsgBar()
{
	document.getElementById('topMsgBar').style.display = 'none';
	return false;
}



//--------------------------------------------------------------------
// 	Check if a string is a numeric value
//--------------------------------------------------------------------

function isNumeric( vTestValue )
{
	// put the TEST value into a string object variable
	var sField = new String(this.trim(vTestValue));

	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }

	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}

	// made it through the loop - we have a number
	return true;
}


//--------------------------------------------------------------------
// 	Check if a string is an integer value
//--------------------------------------------------------------------

function isInteger( vTestValue )
{
	// put the TEST value into a string object variable
	var sField = new String(this.trim(vTestValue));

	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }

	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9')) { /* do nothing */ }
		else { return false; }
	}

	// made it through the loop - we have a number
	return true;
}


//--------------------------------------------------------------------
// 	Set a dropdown box value
//--------------------------------------------------------------------

function selectDropdownValue( dropdownObjectId, valueToSelect )
{
	var obj = document.getElementById(dropdownObjectId);
	for( var o=0; o<obj.options.length; o++ )
	{
		if( obj.options[o].value == valueToSelect ) obj.options[o].selected = true;
		else obj.options[o].selected = false;
	}
}


