/**
 * @author Aravintha Krishnan Jagannathan
 * @since Moveo 1.0
 * String Functions
 */
 
 /*	global variables */

	
 /* function - to trim all trailing whitespaces of a string.
 	input - gets string
 	output - returns string
 */
 	function trimSpaceLeft(string) {
	 	return string.replace(TRIM_LEFT_SPACE_REG_EXPR, EMPTY_STRING);
	}


 /* function - to trim all trailing whitespaces of an element value.
 	input - gets element
 	output - returns true
 */
 	function elementTrimSpaceLeft(elementObject) {
 		var elementValue = trimSpaceLeft(elementObject.value);
	 	return updateElementValue(elementObject,elementValue);
	}

 
 /* function - to trim all leading whitespaces of a string.
 	input - gets string
 	output - returns string
 */
 	function trimSpaceRight(string) {
	 	return string.replace(TRIM_RIGHT_SPACE_REG_EXPR, EMPTY_STRING);
	}


 /* function - to trim all leading whitespaces of an element value.
 	input - gets element
 	output - returns true
 */
 	function elementTrimSpaceRight(elementObject) {
 		var elementValue = trimSpaceRight(elementObject.value);
	 	return updateElementValue(elementObject,elementValue);
	}

 
 /* function - to trim trailing and leading whitespaces of the string.
 	input - gets string
 	output - returns string
 */
 	function trimSpace(string){
 		return trimSpaceRight(trimSpaceLeft(string));
 	}

 
 /* function - to trim trailing and leading whitespaces of an element value.
 	input - gets element
 	output - returns true
 */
 	function elementTrimSpace(elementObject) {
 		var elementValue = trimSpaceRight(trimSpaceLeft(elementObject.value));
	 	return updateElementValue(elementObject,elementValue);
	}


 /* function - to concatenate two strings
	input - gets two strings
 	output - returns string
 */
 	function concatString(stringOne, StringTwo) {
	  	return stringOne + StringTwo;
	}

  
 /* function - to match the string with a regular expression
 	input - gets string and regular expression
 	output - returns true or false
 */
 	function matchString(string, regularExpression) {
	 	return string.match(regularExpression);
	}


 /*	function - to get the caption of the element object
  	if "caption" attribute is not available for the element, it returns the name of the element
  	input - gets an element Object
  	output - returns string
 */
	function getCaption(elementObject) {
		return (elementObject.caption) ? ((trimSpace(elementObject.caption) != EMPTY_STRING) ? elementObject.caption : elementObject.name) : elementObject.name;
	}

 
 /* function - to format the given string
	input - gets a string
 	output - returns string
 */
 	function formatString(string) {
	  	string = HYPHEN + string + NEW_LINE_FEED;
	  	return string;
	}

  
 /* function - to validate string
 	input - gets an element Object
 	output - returns true or false
 */
	function isString(elementObject) {
		var stringValue=elementObject.value;
		return !isSpecialString(elementObject);
		//return matchString(stringValue,ISSTRING_REG_EXPR);
	}
	

 /* function - to validate whether string has special characters or not
 	input - gets an element Object
 	output - returns true or false
 */
	function isSpecialString(elementObject) {
		var stringValue=elementObject.value;
                 
		for(var i=0,charValue=EMPTY_STRING; i<stringValue.length; i++) {
			charValue = stringValue.charAt(i);
			if(SPECIAL_STRING.indexOf(charValue) != -1)	{
				return TRUE_FLAG;
			}
		}

		return FALSE_FLAG;
	}
	

 /* function - to validate Alphabet value
 	input - gets an element Object
 	output - returns true or false
 */
	function isAlphabet(elementObject) {
		var alphabetValue=elementObject.value;
		return matchString(alphabetValue,ISALPHABET_REG_EXPR);
	}

	
 /* function - to display an alert message in an alert box
	input - gets a string
	output - returns true or false
 */
 	function alertMessage(displayMessage,object) {
 		if(!isEmpty(displayMessage)) {
 			mMsgBox.alert('INFO','Alert',displayMessage, 
			   		 function button(btn){
		              	if(btn == btn1){	              	 
		               		elementFocus(object);
 	                		return FALSE_FLAG;
		              	} 
		    		});
 		}
 		return TRUE_FLAG;
 	}
 	

 /* function - to check the given string is empty
 	input - gets a string
 	output - returns true or false
 */
 	function isEmpty(displayMessage){
 		return displayMessage == EMPTY_STRING;
 	}

 	
 /* function - to check the given element is null
 	input - gets an element
 	output - returns true or false
 */
 	function isNull(elementObject){
 		return elementObject == NULL_VALUE;
 	}


 /* function - to check the flag string is passed to the function
 			   the flag string can be 'true' or 'false' or any string or undefined string
 	input - gets a string
 	output - returns the flag string or empty string
 */
	function checkFlag(flag) {
		if (flag == UNDEFINED_STRING || (flag != TRUE_STRING && flag != FALSE_STRING)) {
			return EMPTY_STRING;
		}
		return flag;
	}


 /* function - to check whether first alert message to be displayed in an alert
 	input - gets two string
 	output - returns true or false
 */
	function checkAlert(alertFlag, displayMessage) {
 		return (isEmpty(alertFlag) && !isEmpty(displayMessage));
	}


 /* function - to check whether all alert messages to be displayed in an alert
 	input - gets two string
 	output - returns true or false
 */
	function checkAllAlert(alertFlag, displayMessage) {
 		return (alertFlag == TRUE_STRING && !isEmpty(displayMessage));
	}


 /* function - to check whether no alert to be displayed
 	input - gets two string
 	output - returns true or false
 */
	function checkNoAlert(alertFlag, displayMessage) {
 		return (alertFlag == FALSE_STRING && !isEmpty(displayMessage));
	}
 	