temp = '';
function chkInput(obj){
focInput = 1*obj.name.replace('txt','');
key=event.keyCode;
//alert(key);
  if((key>=48&&key<=57)||(key>=96&&key<=105)||key==110||key==8||key==116||key==190||key==9||key==0||key==109){
  temp = obj.value;
  } else if(key==13){
   document.getElementById('txt'+(focInput+1)).focus(); 
  }else{
   alert('กรุณากรอกเป็นตัวเลข');
   obj.value=temp;
  }
  
return false;
}
//เลือก เช้คบล้อกทั้งหมด
function checkAll(elementName)
   {
     var boolValue = elementName.checked;
     for (var i=0;i<frm.elements.length;i++)
     {
       var e = frm.elements[i];
       if (e.name != elementName.name)
         e.checked = boolValue;
     }
   }

//เปิด windowใหม่
function open_url(width,height,path,sname)
	{
		//alert('Y');
		 width=width+20;
		 height=height+20;

		 setLEFT=(screen.width-width)/2;
		 setTOP=(screen.height-height)/2;

		 window.open(path,"","status=1,scrollbars=yes,width="+width+",height="+height+",left="+setLEFT+",top="+setTOP);

	}

//ตรวจสอบค่าของ Object
// Main Function ---------------------------------------------------------------
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isUndefined(a) {
    return typeof a == 'undefined';
} 
// End Main Function ---------------------------------------------------------------

//ตรวจค่าว่าเป็นตัวเลขไหม
function IsNumeric(sText)

{
   var ValidChars = "0123456789.-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      } 
   return IsNumber;
   
   }

//ไปยัง Url ที่ระบุ
function goURL(chk,url)
	{
		if(chk!="null" && url.length>0)
			{
				window.location.href=url;
			}
	}

//ทดสอบว่า include สำเร็จไหม
function scriptTest()
	{
		alert("Script Is Work");
	}

//Function ทำงานเกี่ยวกับ Multi Select โดยสามารถดึงข้อมูลจาก Select หลายๆตัวโดยไม่ต้องโหลดหน้าใหม่----------------------------------------------
//ทำงานคู่กับ การทำงานต้องใช้ function getTableFiled($TableName,$KeyFiled,$IdFiled,$ValueFiled,$ReturnVariable,$Orderby) ในการเรียกข้อมูล
/*
function getTableFiled($TableName,$KeyFiled,$IdFiled,$ValueFiled,$ReturnVariable,$orderby)
	{
		$mText="";

		if(strlen($ReturnVariable)==0){$textReturn="noVariable";}

		if(!empty($KeyFiled))
			{
				$sql="select $IdFiled,$KeyFiled,$ValueFiled from $TableName order by $orderby";
				$result=mysql_query($sql);
				$num=mysql_num_rows($result);

				if($num>0)
					{
						for($x=0;$x<=($num-1);$x++)
							{
								$row=mysql_fetch_array($result);
								$mText.=$row[$KeyFiled].":".$row[$IdFiled].":".$row[$ValueFiled].",";
							}

						$mText=substr($mText,0,strlen($mText)-1);

					}
			}
		
		return $ReturnVariable."=\"".$mText."\";\r\n";

	}
*/

// Detail Function แสดงผลไปยัง form ที่ต้องการ
//showSelect(ชื่อ form,ชื่อ select ที่ต้องการแสดงผล,ค่าที่สร้างจาก php,ค่าที่ต้องการตรวจสอบว่าเป็นหมวดหมู่อะไร,แสดงข้อความที่ option อันบนสุด)

function showSelect(frmName,selectName,selectTable,checkID,showTitle)
	{
		var arrayTable,tmp,chkData=0;
		var myfrm=eval("document.forms['"+frmName+"']."+selectName);

		//ล้างค่าเดิมทุกครั้ง
		myfrm.options.length=0;
		myfrm.options[0]=new Option(showTitle,"");
		//myfrm.disabled=true;
		//---------------------------------------------------------------------------
		
		
		//ตรวจสอบว่ามีค่าที่ต้องการตรวจสอบมีหรือไม่
		if(checkID!="null")
			{
				//ตรวจสอบว่ามีข้อมูลไหม
				if(selectTable.length!=0)
					{
						//ตัดข้อความ
						arrayTable=selectTable.split(",");
						for(x=0;x<=arrayTable.length-1;x++)
							{
								//ตัดข้อความย่อยแล้วตรวจสอบค่า key
								tmp=arrayTable[x].split(":");
								if(tmp[0]==checkID)
									{
										myfrm.options[myfrm.options.length]=new Option(tmp[2],tmp[1]);
										chkData++;
									}
							}
						//ถ้ามีข้อมูลจะทำการรายงานจำนวนที่พบ
						if(chkData)
							{
								myfrm.options[0].text="Found "+chkData+" Item";
								myfrm.options[0].style.backgroundColor="#9999FF";
							}
					}
			}
	}

// Detail Function ล้างค่า form ที่ต้องการ
//clearSelect(ชื่อ form,ชื่อ select ที่ต้องการแสดงผล,แสดงข้อความที่ option อันบนสุด)
function clearSelect(frmName,selectName,showTitle)
	{
		var myfrm;
		myfrm=eval("document.forms['"+frmName+"']."+selectName);
		myfrm.options.length=0;
		myfrm.options[0]=new Option(showTitle,"null");
		//myfrm.disabled=true;
	}
	//-----------------------------------------------------------------------------------------------------------------------------------

//แสดง msgbox ของ vbscript ถ้า browser สนุบสนุน
function	_alert(text)
	{
		if(navigator.appName=="Microsoft Internet Explorer")
			{
				document.write('<script language="VBScript">msgbox "'+text+'",vbOKOnly+32,"แจ้ง"<\/script>');
			}
		else{alert(text);}
	}

//ตรวจสอบ prompt
function _Pm(aText,text)
	{
		var x="";
		var old="";
		
		old=text;

		x=prompt(aText,text);

		if(!isNull(x) && x.length>0 && old!=x)
			{return x;}
		else{return false;}
	}

function _ChkText(text)
	{
		var filter  = /^[a-zA-Z0-9]+[a-zA-Z0-9_\.]+[a-zA-Z0-9]$/;
		if(filter.test(text)){return true;}
		else{return false;}
	}

function _CheckMail(text)
	{
		var x = text;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)){return true;}
		else {return false;};
	}

//ตรวจสอบค่าที่ป้อน
function _InputCHK(Objtext,altext)
	{
		if(Objtext.value=="null" || Objtext.value.length<=0){alert(altext);Objtext.focus();return false;}
		else{return true;}
	}


//Cookie Function 
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
	
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function menu(form,action) {
	if(action=='on') {
		form.style.backgroundColor='';
	} else {
		form.style.backgroundColor=''
	}
}
	
function showhide(varAction,num)
{
  if (varAction.style.display == 'none')
  {
    varAction.style.display='';
	document.getElementById('divImg'+num).innerHTML='<img src="images/subtract.gif" />';
  }else{
    varAction.style.display='none'
	document.getElementById('divImg'+num).innerHTML='<img src="images/plus.gif" />';
  }
}

