// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str) {
	for (var i=0; str.charAt(i)==" "; i++);
	return str.substring(i,str.length);
}
function RTrim(str) {
	for (var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0,i+1);
}
function Trim(str) {
	return LTrim(RTrim(str));
}

//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val) {
	if (val == null) { return true; }
	return false;
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val) {
	if (val == null) { return true; }
	for (var i=0; i < val.length; i++) {
		if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n")) { return false; }
		}
	return true;
}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val) {
	for (var i=0; i < val.length; i++) {
		if (!isDigit(val.charAt(i))) { return false; }
		}
	return true;
}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val) {
	var dp = false;
	for (var i=0; i < val.length; i++) {
		if (!isDigit(val.charAt(i))) { 
			if (val.charAt(i) == '.') {
				if (dp == true) { return false; } // already saw a decimal point
				else {
					if (i == 0 && val.length ==1) { return false; } //special case: single decimal point
					else {
						dp = true; 
					}
				}
			} else {
				return false; 
			}
		}
	}
	return true;
}
	
//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	var string="1234567890";
	if (string.indexOf(num) != -1) {
		return true;
		}
	return false;
}

//-------------------------------------------------------------------
// isSpecialChar(val)
//   Returns true if val is a 1-character SpecialChar
//-------------------------------------------------------------------
function isSpecialChar(val){
	var string=" ~`!@#$%^&*()_-+=|\\{[}]:;\"\'<,>.?/";
	if (string.indexOf(val) != -1) {
		return true;
	}
	return false;
}

//-------------------------------------------------------------------
// isMonth(string)
//   Returns true if string is either a full month name or a month
//   abbreviation.
//-------------------------------------------------------------------
function isMonth(val) {
	val = val+"";
	val = val.toLowerCase();
	if ((val=="jan") || (val=="feb") || (val=="mar") || (val=="apr") || (val=="may") || (val=="jun") ||
	    (val=="jul") || (val=="aug") || (val=="sep") || (val=="oct") || (val=="nov") || (val=="dec")) {
			return true;
			}
	if ((val=="january") || (val=="february") || (val=="march") || (val=="april") || (val=="may") ||
	    (val=="june") || (val=="july") || (val=="august") || (val=="september") || (val=="october") ||
	    (val=="november") || (val=="december")) {
	    	return true;
	    	}
	return false;
}

//-------------------------------------------------------------------
// doReplace(string)
//   HTML-Encoding the XML Property Value
//-------------------------------------------------------------------
function doReplace(strSource, strReplace, strWith) {
	strIn = strSource;
	intPosn = strIn.indexOf(strReplace);
	if (intPosn >=0) {
		do {
			if (intPosn > 0)
				strLeft = strIn.substr(0, intPosn)
			else
				strLeft = '';
			if (intPosn < strIn.length - 1)
				strRight = strIn.substr(intPosn + 1)
			else
				strRight = '';
			strIn = strLeft + strWith + strRight;
			intPosn = strIn.indexOf(strReplace);
		} while(strIn.indexOf(strReplace) >=0);
	}
	return strIn;
}
function ReplaceChar(strSource) {

	strSource = ReplaceFunction(strSource, "&", "&amp;")
	strSource = ReplaceFunction(strSource, "<", "&lt;")
	strSource = ReplaceFunction(strSource, ">", "&gt;")
	strSource = ReplaceFunction(strSource, "\"", "&quot;")
	//strSource = strSource.replace("'", "&apos;")
		
	return strSource;
}

function isAlphabet(sChar) {

	if(sChar.charCodeAt(0) >= 97 && sChar.charCodeAt(0) <= 122
	 || sChar.charCodeAt(0) >= 65 && sChar.charCodeAt(0) <= 90) {
		return true;
	}
	return false;
}

function isValidFileName(svalue) {

	var test_value = doReplace(svalue,' ','');
	test_value = escape( test_value );
	if ( test_value.indexOf( "%" ) == -1 ) {
		var check_ok = true;
	} else {
		var check_ok = false;
	} 
	return check_ok;
}
