//define trim functions
	String.prototype.trim = function() {
		return this.replace(/^\s*|\s(?=\s)|\s*$/g,"");
	}
	String.prototype.ltrim = function() {
		return this.replace(/^\s+/,"");
	}
	String.prototype.rtrim = function() {
		return this.replace(/\s+$/,"");
	}
/*
 *function name: check_mailstring
 *@input: string str
 *@return: true if email is valid, false if email is invalid
*/
	function check_mailstring(str){
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
			return true
		else{
			return false
		}
	}
/*
 *function name: check_halfsize
 *@input: string str
 *@return: true if str are number, chars or _ else return false
*/
	function check_halfsize(str){
		var filter = /^[a-zA-z0-9_]$/i
		for(var i=0;i<str.length;i++){
			if(filter.test(str.charAt(i))==false)
				return false
		}
		return true
	}
/*
 *function name: trimAll
 *@input: string str
 *@return: true if email is valid, false if email is invalid
*/
	function trimAll(sString) {
		while (sString.substring(0,1) == ' '){
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' '){
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}
/*
 *function name: checkIsHalfSize
 *@input: string str
 *@return: true if str are halfsize characters else return false
*/
	function checkIsHalfSize(str) {

		for (var i = 0; i < str.length; ++i) {
			var c = str.charCodeAt(i);		
			if (c >= 256 && (c < 0xff61 || c > 0xff9f)) {
				return false;
			}
		}
		return true;
	}
/*
 *function name: IsNumeric
 *@input: string str
 *@return: true if str are numbers else return false
*/
	function IsNumeric(str){
		var filter = /^[0-9]$/i
		for(var i=0;i<str.length;i++){
			if(filter.test(str.charAt(i))==false)
				return false
		}
		return true
	}
/*
 *function name: checkIsZenkaku
 *@input: string str
 *@return: true if str is fullsize else return false
*/
	function checkIsZenkaku(str) {

	for (var i = 0; i < str.length; ++i) {
		var c = str.charCodeAt(i);
		
		if (c < 256 || (c >= 0xff61 && c <= 0xff9f)) {
			return false;
		}
	}
	return true;
}
/*
 *function name: check_url
 *@input: string url
 *@return: true if url format is correct
*/
	function check_url (url){
	  var urlPattern = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|co|jp|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/;
	  return urlPattern.test(url.toLowerCase());
	}
/*
 *function name: check_MustHalfsizeNumAndChar
 *@input: string str
 *@return: true if str include number and char
*/	
	function check_MustHalfsizeNumAndChar(str){
		var filter_num = /^[0-9]$/i
		var num_exist = false;	
		for(var i=0;i<str.length;i++){
			if(filter_num.test(str.charAt(i))==true)
				num_exist = true
		}
		
		var filter_num = /^[a-zA-z_]$/i
		var char_exist = false;	
		for(var i=0;i<str.length;i++){
			if(filter_num.test(str.charAt(i))==true)
				char_exist = true
		}
		
		if (num_exist && char_exist) {
			return true;
		} else {
			return false;
		}
	}
/*
 *function name: countTextIgnoreEnterKey
 *@input: string str
 *@return: length after ignoring enter key
*/	
	function countTextIgnoreEnterKey(str){		
		
		browser_name = navigator.appName;		
		if(browser_name == "Microsoft Internet Explorer" || browser_name == "Opera")
			di = 2;
		else 
			di = 1;		
		
		len = str.length ;	
		cnt = 0;		
		for(i = 0; i <= len ; i ++){
			
			if(str.charCodeAt(i) == 10){				
				cnt  = cnt + di;						
			}
		}			
		return len - cnt ;
	}
/*
 *function name: addBackSpace
 *@input: string str
 *@return: str with backspace
*/	
	function addBackSpace(str){
		str = str.rtrim();		
		var prefix = "";		
		while(str.charCodeAt(0) == 32){			
			prefix = prefix + "&nbsp;";				
			len = str.length - 1;
			str = str.substr(1,len);			
		}			
		str = prefix + str;		
		for( var i = 0; i<str.length; i++ ){
			if(str.charCodeAt(i) == 32){				
				str = str.replace(str.substr(i,1),"&nbsp;");				
			}
		}		
		return str;
	}