

// Check Entry Numeric Only
function CheckNumber(objName)
{
	var str = objName.value;
	var strValid = "Y";
	for (var ind = 0;ind < str.length;ind++)
	{
		var ch = str.substring(ind,ind+1)
		if(!(ch >= "0" && ch <= "9"))
		{
			strValid = 'N';
			break;
		}		
	} // end for
	
	if(strValid=="N"){
		alert('กรุณาระบุข้อมูลเป็นตัวเลขเท่านั้น');
		objName.focus();
		return false;
	}else{
		return true;	
	}
	
} // end function
	//  Test Date Function  
	function CheckDate(objdate){
		var objdate = objdate;
		var strValid = "Y";
		var strReturnDate = "";
		var strDD = "";
		var strMM = "";
		var strYY = "";
		
		if(objdate.value!=""){
			var strDate =  objdate.value;
			if(!CheckNumDate(objdate)){			
					strValid = 'N';
			}else{

				var intLength = strDate.length;
				var intPos1 = strDate.indexOf("/");
				var intPos2 = strDate.indexOf("/",3);
					
				switch (intLength) {
					case 10: //  01/01/2004					
						if(intPos1==2 && intPos2==5){
							strDD = strDate.substr(0,2);
							strMM = strDate.substr(3,2);
							strYY =  strDate.substr(6,4);
						}else{
							strValid = 'N';
						}					
						break;
					case 8: //  01/01/04  OR 01012004					
						if(intPos1==2 && intPos2==5){
							strDD = strDate.substr(0,2);
							strMM = strDate.substr(3,2);
							strYY =  "25" + strDate.substr(6,2);
						}else if(intPos1<0 && intPos2<0){											
							strDD = strDate.substr(0,2);
							strMM = strDate.substr(2,2);
							strYY =  strDate.substr(4,4);
						}else{
							strValid = 'N';
						}					
						break;
					case 6: // 010104				
						if(intPos1<0 && intPos2<0){
							strDD = strDate.substr(0,2);
							strMM = strDate.substr(2,2);
							strYY =  "25" + strDate.substr(4,2);
						}else{
							strValid = 'N';
						}
						break;
					default:
						strValid = 'N';
				} // switch
			} // check num
			
			// validate date 
			if(!CheckDMY(strDD, strMM, strYY)){
				strValid = 'N';
			}

		} // chenk null

		if(strValid=="N"){
			alert("ระบุข้อมูลวันที่ผิดรูปแบบ กรุณาตรวจสอบ ");
			objdate.focus;
			return false;
		}else{
			objdate.value= strDD+"/"+ strMM+ "/"+ strYY;
			return true;	
		} // valid				
		
	} // function


	//Check Numeric Date Input  
	function CheckNumDate(objName){
		var str = objName.value;
		var strValid = "Y";
		for (var ind = 0;ind < str.length;ind++)
		{
			var ch = str.substring(ind,ind+1)
			if(!((ch >= "0" && ch <= "9") ||ch=="/"))
			{
				strValid = 'N';
				break;
			}		
		} // end for
		
		if(strValid=="N"){
			return false;
		}else{
			return true;	
		}			
	} // end function

	function OpenWindowMax(url){
		var w = window.open (url, "win", "height="+(screen.height-10)+",width="+(screen.width-10)+",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,left=0, top=0,screenX=0,screenY=0");
		w.focus();
	}
	function OpenWindow(url){
		var w = window.open (url, "win1", "height=500,width=600,resizable,scrollbars,status");
		w.focus();
	}
	function OpenWindowdimension(url, height, width){
		var w = window.open (url, "winDim", "height="+height+",width="+width+",resizable, scrollbars,status");
		w.focus();
	}
	function OpenWindowdimensionName(url, height, width, name){
		var w = window.open (url, name, "height="+height+",width="+width+",resizable,scrollbars,status");
		w.focus();
	}

	function cvDate(val){
		var tmp=val.split('/');
		return tmp[2]+'-'+tmp[1]+'-'+tmp[0];
	}

	function getParameter(){
		var url=new String();
		for(var i=0;i<document.forms[0].elements.length;i++){
			if(document.forms[0].elements[i].type=='checkbox'){
				if(document.forms[0].elements[i].checked)
					url=url+'&'+document.forms[0].elements[i].name+'='+document.forms[0].elements[i].value;
				else
					url=url+'&'+document.forms[0].elements[i].name+'=';
			}else if(document.forms[0].elements[i].type=='radio'){
				if(document.forms[0].elements[i].checked)
					url=url+'&'+document.forms[0].elements[i].name+'='+document.forms[0].elements[i].value;
			}else if(document.forms[0].elements[i].type!='button'){
					url=url+'&'+document.forms[0].elements[i].name+'='+document.forms[0].elements[i].value;
			}
		}
		return url;
	}


