
function LTrim(str){if(str==null){return null;}for(var i=0;str.charAt(i)==" ";i++);return str.substring(i,str.length);}

function RTrim(str){if(str==null){return null;}for(var i=str.length-1;str.charAt(i)==" ";i--);return str.substring(0,i+1);}

function Trim(str){return LTrim(RTrim(str));}

function LTrimAll(str){if(str==null){return str;}for(var i=0;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i++);return str.substring(i,str.length);}

function RTrimAll(str){if(str==null){return str;}for(var i=str.length-1;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i--);return str.substring(0,i+1);}

function TrimAll(str){return LTrimAll(RTrimAll(str));}

function isNull(val){return(val==null);}

function isBlank(val){if(val==null){return true;}for(var i=0;i<val.length;i++){if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}}return true;}

function isInteger(val){if(isBlank(val)){return false;}for(var i=0;i<val.length;i++){if(!isDigit(val.charAt(i))){return false;}}return true;}

function isNumeric(val){return(parseFloat(val,10)==(val*1));}

function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

function isDigit(num){if(num.length>1){return false;}var string="1234567890";if(string.indexOf(num)!=-1){return true;}return false;}


function changbg(obj,color){
					obj.style.backgroundColor=color;
}

function compareobj(obj,value,Msg){
			if (obj.value == value){
					if(Msg != ""){
							alert(Msg);
							}
					obj.focus();
					obj.select();
			return true;
			}
			return false;
}
function compareobjarea(obj,value,Msg){
			if (obj.value == value){
					if(Msg != ""){
							alert(Msg);
							}
					obj.focus();
					//obj.select();
			return true;
			}
			return false;
}
function compareselection(obj,value,Msg){
			if (obj.value == value){
					if(Msg != ""){
							alert(Msg);
							}
						obj.focus();
			return true;
			}
			return false;
}

function compareobjradio(obj,Msg){
				for(i=0;i<obj.length;i++)
					{					
							if (obj[i].checked == true){
								return false;
						}
					}
			if (Msg != "") 
			{
			alert(Msg);
			}
			return true;;
}
function checkemail(obj,Msg){
		
			if (obj.value.indexOf('.')==-1) {
						alert(Msg);
						obj.focus();
						obj.select();
						return true;
			}
			if (obj.value.indexOf('@') == -1){
					alert(Msg);
						obj.focus();
						obj.select();
						return true;
			}	
		
}

function checkAlphabet(obj,Msg){
		var apha = /.+[a-z]|[0-9]|[_]/
		testresult = false;
			if(obj.value !=''){
					if(!(apha.test(obj.value))){
							testresult = true;
							alert(Msg);
			obj.focus();
			obj.select();
					}
			}
			else 
			{
			testresult = true;
			alert(Msg);
			obj.focus();
			obj.select();
			}
			
			return (testresult);
}

  function checknumtype(val){
	 var anum=/(^\d+$)|(^\d+\.\d+$)/
	testresult=true;
	if (val!=''){
	 if (!(anum.test(val))){
		testresult=false;
	 }
	}
	else testresult=false;
	 return (testresult);
  }

function checklength(obj,number,Msg){
			if(obj.value.length  <  number){
						alert(Msg);
						obj.focus();
						obj.select();
						return true;
			}
		return false;
}



function checklengthgt(obj,number,Msg){
			if(obj.value.length > number){
						alert(Msg);
						obj.focus();
						obj.select();
						return true;
			}
		return false;
}
function checknum(DnEvents)
{
  k = window.event.keyCode;
 if ((k ==13 || k==110) || (k > 47 && k < 58  ) || (k== 46))

 {
  }
 else
 {
    alert("กรุณากรอกตัวเลขเท่านั้น")
    window.event.keyCode = 46;

   	  }
 }	




function ClearValue(Obj)
{					
					Obj.value = "";
		
}
function VisibleObj(Obj,work)
{
						if(work){
								Visible="block";
						}
						else
						{
								Visible = "none";
						}
						
								
								Obj.style.display=Visible;
												

}

		


