function LTrim( value ) 
{ 
 var re = /\s*((\S+\s*)*)/;
 return value.replace(re, "$1"); 
}
// Removes ending whitespaces
function RTrim( value ) 
{
 
 var re = /((\s*\S+)*)\s*/;
 return value.replace(re, "$1");
 
}

// Removes leading and ending whitespaces
function trim( value ) 
{ 
	 return LTrim(RTrim(value)); 
}
function checkchar(mystr,invalidChars1)
{
	for (i=0; i<invalidChars1.length; i++) // does it contain any invalid characters?

		{

			badChar1 = invalidChars1.charAt(i)

			if (mystr.indexOf(badChar1,0) > -1) 

				{

					return false;

				}

		}

return true;

}

function popUp(url)

{
	
	window.open (url,"mywindow","resizable=yes, scrollbars=yes");

}
function IsNumeric(str)

   {

	   var strValidChars = "0123456789";

	   var strChar;

	   var strString = str ;

	   var blnResult = true;

	   var field;



	   if (strString.length == 0) return false;

	

	   //  test strString consists of valid characters listed above

	   for (i = 0; i < strString.length && blnResult == true; i++)

		  {

		  strChar = strString.charAt(i);

		  if (strValidChars.indexOf(strChar) == -1)

			 {

			 	//alert('This value should be Numeric!');

				//field.value = "";

				blnResult = false;

			 }

		  }

	   return blnResult;

   }	//	End	of function IsNumeric

function IsPhoneNumeric(str)

   {

	   var strValidChars = "0123456789-+";

	   var strChar;

	   var strString = str ;

	   var blnResult = true;

	   var field;



	   if (strString.length == 0) return false;

	

	   //  test strString consists of valid characters listed above

	   for (i = 0; i < strString.length && blnResult == true; i++)

		  {

		  strChar = strString.charAt(i);

		  if (strValidChars.indexOf(strChar) == -1)

			 {

			 	//alert('This value should be Numeric!');

				//field.value = "";

				blnResult = false;

			 }

		  }

	   return blnResult;

   }	//	End	of function IsNumeric



function isNumber (id,val)

{

	if(document.getElementById(id).value != "")

	{

		if( IsNumeric (document.getElementById(id).value) == false )

		{

			alert("Only numeric values are allowed");

			document.getElementById(id).value = val;

			

		}

	}

}
function isPhoneValid (id,val)
{
	if(document.getElementById(id).value != "")
	{
		if( IsPhoneNumeric (document.getElementById(id).value) == false )
		{
			alert("Please write valid phone number.");
			document.getElementById(id).value = val;
			
		}
	}
}
function checkchar(mystr,invalidChars1)
{
			
	for (i=0; i<invalidChars1.length; i++) // does it contain any invalid characters?
		{
			badChar1 = invalidChars1.charAt(i)
			if (mystr.indexOf(badChar1,0) > -1) 
				{
					return false;
				}
		}
return true;
}
function isChar(id,val)
{
	if(document.getElementById(id).value != "")
	{	
		 if(!checkchar(document.getElementById(id).value,"?/:,;=+'\"<>|\\`~{}#$%@!^&*[]()_.-0123456789"))
		{
			alert("Only alphabets are allowed");
			document.getElementById(id).value = val;
		
		}		
	}// if(document.getElementById(id).value != "")ss	
}
