/*
 Author 		: Chairat Panpun
 Date			: 8/11/00
 Description 	: This module consists of a collection of functions concerning to
	utility functions.
 Module 		: Utility Functions
 Supervisor 	: Mark Able 
 Version 		: 1.0  
 Compatability	: IE 4.0+/Netscape 4.0+ 
*/

/*
 LTrim(inpVal) trims whitespace (spaces, tabs, and new line characters) 
 from the begining of the expression.
*/
function LTrim(inpVal) {
	var i = 0;
	
	while((i < inpVal.length) && ((inpVal.charAt(i)==' ') || (inpVal.charAt(i)=='	')) ) i++;
		inpVal = inpVal.substring(i);
	return(inpVal);
}

/* 
 RTrim(inpVal) trims whitespace (spaces, tabs, and new line characters) 
 from the end of the expression.
*/
function RTrim(inpVal) {
	var i = inpVal.length - 1;
	
	while((i >= 0) && ((inpVal.charAt(i)==' ') || (inpVal.charAt(i)=='	')) ) i--;
		inpVal = inpVal.substring(0, i+1);
	return(inpVal);
}

function isquote(inpVal) {
	var blnValid = true;
	var strTemp;
	for (var i = 0; i < inpVal.length; i++) {
		strTemp = "" + inpVal.substring(i, i+1);
		if ((strTemp.charCodeAt() == 34) || (strTemp.charCodeAt() == 39)) {
			blnValid = false;
		}
	}
	if (blnValid) {
		return true
	} else {
		return false
	}		
}

/*
 Trim(inpVal) trims whitespace (spaces, tabs, and new line characters) 
 from both the beginning and the end of the expression.
*/

function Trim(inpVal) {	
	inpVal = RTrim(inpVal);
	inpVal = LTrim(inpVal);
	return(inpVal);
}

/*
 isEmpty(inpVal) determines whether the inpVal is whitespace (spaces, tabs, 
 and new line characters) or null.
*/
function isEmpty(inpVal) {
	var strInvalid = " \t\r\n"		// Invalid characters are space, and tab
	var blnValid = true;
	var strTemp;

	for (var i = 0; i < inpVal.length; i++) {
		strTemp = "" + inpVal.substring(i, i+1);
		if (strInvalid.indexOf(strTemp) == "-1") blnValid = false;
	}
	if ( (blnValid) && (inpVal.value != "") ) {
		return true			// e.g. ''; ' '; '	'
	} else {
		return false		// e.g. 'a'; ' a '; '	a	b '
	}	
}

/*
 isSpace(inpVal) determines whether the inpVal contains whitespace (spaces, tabs, 
 and new line characters).
*/
function isSpace(inpVal) { 
	var strSpace1 = " "; 	// Invalid character is a space
	var strSpace2 = "	"; 	// Invalid character is a tab
	var blnValid = true;
	
	if ((inpVal.indexOf(strSpace1) > -1) || (inpVal.indexOf(strSpace2) > -1)) blnValid = false;
	if (blnValid) {
		return false;		// e.g. ''; 'aa'; 'avx'
	} else {
		return true;		// e.g. ' '; ' a  b '; '	a'
	}
}

/*
 Validation maxlength for textarea 
*/
function txtAreaMaxLength(txtArea, intMax) {
	if (txtArea.value.length > intMax) {
		Alert2(1,"This field",intMax);
		txtArea.value = txtArea.value.substring(0, intMax);
		return(txtArea.value);
	}
}

function txtIslnk(txt) {
	c=txt.indexOf( "<a");
	d=txt.indexOf( "href");
	if((c!=-1) && (d!=-1)) {
		return true;
	}
	else {
		b=txt.indexOf( "<img");
		a=txt.indexOf( "<!-");
		if((b!=-1) || (a!=-1)) {
			return true;
		}
		else {
			return false;
		}
	}
}