<!--
/*******************************************************************
File Name	:	tshcommon.js
Description	:	Common Javascript functions
Author		:	Niraj
Create Date	:	08-APR-2005
Modify Date	:	28-NOV-2005

FUNCTIONS AT GLANCE
									STRING HANDLING FUNCTION
									

									VALIDATION FUNCTION
ValidateEmailAddress	:	Validate email address
ValidateImageFileName	:	Validate Image file Name (eitehr gif or jpg)
*******************************************************************/


////////////////		STRING HANDLING FUNCTION		//////////////////
/**************************************************************
Method Name	:	LTrim
Description	:	LTrim Function
Parameter	:	Value to be LTrim (String)
Return		:	Left Trimeed value. (String)
**************************************************************/
function LTrim(sString){
	var w_space = String.fromCharCode(32);

	var v_length = sString.length;
	
	if(v_length < 1){
		return"";
	}	
	
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(sString.charAt(iTemp) != w_space){
			strTemp = sString.substring(iTemp,v_length);
			break;
		}
		
		iTemp = iTemp + 1;
	} //End While

	return strTemp;
} //End Function "LTrim"


/**************************************************************
Method Name	:	RTrim
Description	:	RTrim Function
Parameter	:	Value to be RTrim (String)
Return		:	Right Trimeed value. (String)
**************************************************************/
function RTrim(sString) {
	var w_space = String.fromCharCode(32);
	var v_length = sString.length;

	if(v_length < 1){
		return"";
	}
	
	var strTemp = "";
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(sString.charAt(iTemp) != w_space){
			strTemp = sString.substring(0,iTemp +1);
			break;
		}

		iTemp = iTemp-1;
	} 

	return strTemp;
} //End Function "RTrim"


/**************************************************************
Method Name	:	Trim
Description	:	Trim Function for the JavaScipt.
Parameter	:	Value to be Trim (String)
Return		:	Trimeed value. (String)
**************************************************************/
function Trim(sString){
	// STRING IS EMPTY THEN STRING LENGTH IS LESS THAN 1 AND THEN RETURN NULL VALUES
	if(sString.length < 1){
		return"";
	}
	
	sString = RTrim(sString);
	sString = LTrim(sString);
		
	return sString;
}	// END OF FUNCTION "Trim"


/////////////		VALIDATION FUNCTION		////////////////////

/**************************************************************
Method Name	:	ValidateEmailAddress
Description	:	Validate for the Email address
Parameter	:	Email address (string)
Return		:	True if email address is correct else false.
**************************************************************/
function ValidateEmailAddress(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}
		
	if (str.indexOf(" ")!=-1){
		return false;
	}

	return true;
}	// END OF FUNCTION "ValidateEmailAddress"


/**************************************************************
Method Name	:	ValidateImageFileName
Description	:	Validate image file name. (either jpg or gif)
Parameter	:	image file name (string)
Return		:	True if valid image file name else return false.
**************************************************************/
function ValidateImageFileName(sFileName) {
	sFileName = sFileName.toLowerCase();
	iJPGIndex = sFileName.indexOf('jpg');
	iGIFIndex = sFileName.indexOf('gif');
	
	if(iJPGIndex<0 && iGIFIndex<0) {
		return false;
	}

	return true;
}	// END OF FUNCTION "ValidateImageFileName"
-->
