//trim function
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 trim(str){  
 return str.replace(/^\s+/g, "").replace(/\s+$/g, "");
 }
// Check object
			function checkInput(obj, str) {
			
				if ((obj != null) && (trimAll(obj.value) == "")) {
					alert(str);
					obj.focus();
					return false;
				} else {
					return true;
				}
			}
			
// Check object for example in Dropdown we can check the first index value i.e. 0
			function checkValue(obj, str) {				
				if ((obj != null) && (obj.value == 0)) {
					alert(str);
					obj.focus();
					return false;
				} else {
					return true;
				}
			}
//checkemail			
			function checkEmail(obj,str)
			{
					var test=trimAll(obj.value);
					var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;	
					var arr=test.split(",");
						
				if ((obj != null) && (trimAll(obj.value) != "")) {					
					for(i=0;i<arr.length;i++)    
					if ((filter.test(arr[i])))  	
						{
							return true;
						}
					else
					{		  
						alert(str);
						obj.focus();
						return false;
					} 	
					return true;  
				}
			}
 
// Check object for numeric value
			function checkNumeric(obj, str) {					
				if ((obj != null) && (trimAll(obj.value) != "")) {
					if (isNaN(obj.value) || obj.value<0)
						{
							alert(str);
							obj.focus();
							return false;
						}	
					else
						return true;	
				} else {
					return true;
				}
			}	
			
//Max Length checking
		function maxlength(obj,obj1,str)
		{
		var max =obj.value.length;
			if (max>obj1)
			{
			alert(str);
			obj.focus();
			return false;
			}
				else
				{
				return true;
				}
		}			
//check length between minimum to maximum
			function checklength(obj,obj2,obj3,str)
			{
			var abc = obj.value;
			if ((abc.length < obj2) || (abc.length > obj3))
				{
				alert(str);
				obj.focus();
				return false;
				 }
				else 
				{
				return true;
				}
			 }
			 
//check length while updating
			 function checklengthEdit(obj,obj2,obj3,str)
			{
				if ((obj != null) && (obj.value != "")) 
				{
				var abc = obj.value;
						if ((abc.length < obj2) || (abc.length > obj3))
						{
						alert(str);
						obj.focus();
						return false;
						}
				 else
				 return true;
				 }
					else 
					{
					return true;
					}
			 }
			 	
//Password confirmation
		function PwdConfirm(obj,obj1,str)
		{
			var aaa=trimAll(obj.value);
			var zzz=trimAll(obj1.value);
			
				if (aaa != zzz) 
				{
				alert(str);
				obj1.focus();
				return false;
				}
					else
					{
					return true;
					}
		}
		
		
//check Case Lower Only	
function checkCase(obj, str) {	
//var abc=obj.value;
var abc= /[a-z]/;
///[a-z]/;

				if ((obj != null) && (trimAll(obj.value) != 0)) {
							
					//if (!(abc.search(/(a-z)+/)))
					 if(!abc.test(trimAll(obj.value))) 
						{
						alert(abc);
							alert(str);
							obj.focus();
							return false;
						}	
					else
						return true;	
				} else {
					return true;
				}
			}	
			
			
						

// Check object for uploading file extensions
			function checkFile(obj, str) {	
				var detLogo=obj.value;	
				var detLen=detLogo.length;		
				var imgext=detLogo.substr((detLen-3),3);
				var convertlo=imgext.toLowerCase();					
				
				if ((obj != null) && (obj.value != 0)) {
					if(convertlo != 'jpg' && convertlo != 'png' && convertlo != 'bmp' && convertlo != 'gif')
						{
							alert(str);
							obj.focus();
							return false;
						}	
					else
						return true;	
				} else {
					return true;
				}
			}		
			
			
// Check object for check date
			function checkDate(obj, str) {
				var tempDate	= new Date(trimAll(obj.value));
				tempDate		= new Date((tempDate.getMonth() + 1) + "/"  + tempDate.getDate() + "/" + tempDate.getYear());
				var todayDate	= new Date();
				todayDate		= new Date((todayDate.getMonth() + 1) + "/"  + todayDate.getDate() + "/" + todayDate.getYear());
				{
				if (tempDate < todayDate) {
					alert(str);
					obj.focus();
					return false;
				} else {
					return true;
				}
				}
			}
			
			function MM_swapImage(imgPath,obj)
				{	
					//document.Form1.imgClose.src=imgPath;
					obj.src=imgPath;		
				}
				
			function MM_swapImgRestore(imgPath,obj) 
				{	 
					//document.Form1.imgClose.src=imgPath;
					obj.src=imgPath;				
				}
			
//For NAvigating Back Ward
			function back()
					{
						history.back();		
						return false;
					} 
		 function character(obj,str)
		{
		//if(obj=="")
		//{
		//alert(str);
		//obj.focus();
		//return false;
		//}
		//else {

		var pattern = /^[a-zA-Z \s]+$/;
		if (pattern.exec(trim(obj.value))== null)
		{
		alert(str);
		obj.focus();

		return false;
		}
		else
		{
		//}
		return true;
		}
		}   
					
//Delete confirmation
function delconfrim(msg)
{
return confirm(msg); 
}
