//Encode special characters in variable value before appending to query string
function UrlEncode(text) {		
	//text=ReplaceAll(text, "/\", "%2F"); 
	var s= new String(text);
	s=ReplaceAll(s, "?", "%3F");
	s=ReplaceAll(s, "=", "%3D");
	s=ReplaceAll(s, "&", "%26");
	s=ReplaceAll(s, " ", "+");
	s=ReplaceAll(s, ",", "%2c");	
	return s+'';
}

//Replace all given string from a string
function ReplaceAll(varb, replaceThis, replaceBy) {	
	newvarbarray=varb.split(replaceThis);
	newvarb=newvarbarray.join(replaceBy);	
	return newvarb;
}

//This function trims leading and trailing spaces and convert consecutive spaces in string to one space
function trimAll(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   return temp;
}

//This function trims only leading and trailing spaces
function rlTrim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}