function SpaceCheckAlert(strId,strName)
	dim strMessage
	SpaceCheckAlert=true
	aryId=split(strId,",")
	aryName=split(strName,",")
	for i=0 to ubound(aryId)
		'if CGetVal(aryId(i))="" or CGetVal(aryId(i))="0" then 
		if CGetVal(aryId(i))="" then 
			strMessage=strMessage+aryName(i)+chr(13)
		end if			
	next
	
	if strMessage<>"" then SpaceCheckAlert=false else exit function
	
	strMessage=left(strMessage,len(strMessage)-1)+"必須輸入!!"	
	window.alert(strMessage)
end function

function GetSqlValue(strSQL)
	if strSQL="" then exit Function 
	strSQL=Replace(strSQL,"+","保留字1")
	strSQL=Replace(strSQL,"%","保留字2")
	nowTime=now() & " "

	Set WinHttpReq = CreateObject("Msxml2.XMLHTTP")
	call WinHttpReq.Open("GET", "GetData.aspx?nowTime=" + nowTime + "&strSQL="+escape(strSQL), false)
	WinHttpReq.Send()							

	GetSqlValue = WinHttpReq.ResponseText

End function
	
dim oldValue,newValue


Sub Document_Onfocusin() 
	on error resume next
	set obj=window.event.srcElement
	strClass=obj.classname
	oldValue=trim(window.event.srcElement.value)
	
	if strClass="Date" then
		window.event.srcElement.value=Replace(window.event.srcElement.value,"/","")		  
	end if  

	if strClass="Time" then
		window.event.srcElement.value=Replace(window.event.srcElement.value,":","")		  
	end if  
end sub

Sub Document_Onfocusout() 
	on error resume next
	set obj=window.event.srcElement
	strClass=obj.classname
	newValue=trim(window.event.srcElement.value)
	if oldValue<>newValue and strClass="Dialog"  then
		set toobj=window.event.toElement
		strID=toobj.id	
		detailID=replace(toobj.Id,"dlg","")	
		
		if	strID<>"dlg"+right(obj.id,len(detailID)) then
			call Dialog_check(Obj)		
		end if   		
	end if
	
	if strClass="Date" then
	    strValue1=window.event.srcElement.value
		window.event.srcElement.value=Conv_Date(window.event.srcElement.value)				
		if strValue1<>"" and window.event.srcElement.value="" then
		   window.event.srcElement.focus()
		end if
	end if 
    
	if strClass="YM" then
	    strValue1=window.event.srcElement.value
		window.event.srcElement.value=Conv_YM(window.event.srcElement.value)				
		if strValue1<>"" and window.event.srcElement.value="" then
		   window.event.srcElement.focus()
		end if
	end if 

    if strClass="Time" then
        strValue1=window.event.srcElement.value
		window.event.srcElement.value=Conv_Time(window.event.srcElement.value)				
		if strValue1<>"" and window.event.srcElement.value="" then
		   window.event.srcElement.focus()
		end if		
	end if 
	
	if (strClass="Number" or strClass="DisplayNumber" or strClass="StringNumber") then
		if isnumeric(newValue)=false then window.event.srcElement.value=""
	end if
		
	
'	if	UCASE(obj.tagName)="INPUT" and obj.type="text" then 
'		if strClass="Dialog" or strClass="Display" then exit sub
'		obj.style.backgroundColor="white"
'	end if 
	  
end sub

Sub Document_OnKeyDown() 
	dim strClass		
	if myStatus="cbtnClear"	then exit sub			
	strClass=window.event.srcElement.classname
	intKeyCode=window.event.keycode
		
	if intKeyCode=13 and strClass<>"Key" and strClass<>"Area" then window.event.keyCode=9
	
end Sub

Sub CSetVal(Id,Val)		'設定 Form 的值
	on error resume next
	'strid=GetClientID(Id)
	strid=Id
	
    set obj=window.document.all(strid,0)	
	strClass=obj.classname
	if (strClass="Number" or strClass="DisplayNumber") and Val="" then Val="0"

    if strClass="radio" then
	    set obj=window.document.all(strid)
		for i=0 to obj.length-1
		    if obj(i).tagName="INPUT" then
		       if obj(i).value=val then
			    	obj(i).checked=true 
			    	exit for
			   else
			    	obj(i).checked=false 
			   end if
			 end if
		next
	else
		select case ucase(obj.tagName)
			case "INPUT"
				obj.value=Val
			
			case "TD","TEXTAREA","SPAN"
				obj.innertext=Val
								
			case "SELECT"			
				for i=0 to obj.options.length
				    if obj.options(i).value=val then
						obj.options(i).selected=true  
					else
						obj.options(i).selected=false  
					end if
					'if i=cint(val) then
					'	obj.options(i).selected=true  
					'else
					'	obj.options(i).selected=false  
					'end if	
				next					
		end select
	end if
End Sub


Function CGetVal(Id)		'取得Form的值
	on error resume next	
	dim strVal

	'strid=GetClientID(Id)
	strid=Id
	set obj=window.document.all(strid,0)
	strClass=obj.classname
	
	
	'如果是HTML Tage時
	if obj.tagName="INPUT" then
	   if obj.type="radio" then 
	      strClass="radio"
	   elseif obj.type="checkbox" then 
	      strClass="checkbox"
	   elseif obj.type="checkbox_tb" then 
	      strClass="checkbox_tb"
	   end if	      	   
	end if
	
	if strClass="radio" then
	    '取得 radiobutton 的 Listem Value
        set obj=window.document.all(strid)
		for i=0 to obj.length-1
		    if obj(i).tagName="INPUT" then
		       if obj(i).checked=true then
		          strVal=obj(i).value
		          exit for
		       end if
			 end if
		next	
	elseif strClass="checkbox" then
	    '取得 checkboxlist 的Index ,RepeatLayout="Flow"(預設值)
		set obj=window.document.all(strid)
		for i=0 to obj.children.length-1
			if obj.children(i).tagName="INPUT" then
				if obj.children(i).type="checkbox" then
					if obj.children(i).checked=true then
						strVal=strVal & "," & mid(obj.children(i).name,instr(1,obj.children(i).name,":")+1)
					end if
				end if
			end if
		next	
		if strVal<>"" then strVal=mid(strVal,2)
	elseif strClass="checkbox_tb" then
	    '取得 checkboxlist 的Index ,RepeatLayout="Table"
		set obj=window.document.all(strid)
		for i=0 to obj.children(0).children.length-1
			if obj.children(0).children(i).children(0).children(0).checked=true then
				strVal=strVal & "," & mid(obj.children(0).children(i).children(0).children(0).name,instr(1,obj.children(0).children(i).children(0).children(0).name,":")+1)
			end if
		next	
		if strVal<>"" then strVal=mid(strVal,2)		
	else 	
		select case ucase(obj.tagName)
			case "INPUT"
			   strVal=obj.value
			case "TD","TEXTAREA","SPAN"
				strVal=obj.innertext
			case "SELECT"
				for i=0 to obj.options.length
					if obj.options(i).selected=true then 
						strVal=obj.options(i).value
						'strVal=i					
						exit for
					end if	
				next	
			case  else
				exit function
		end select	
	end if
	
	if (strClass="Number" or strClass="DisplayNumber") and strVal="" then 
	    strVal="0"
	elseif (strClass="Number" or strClass="DisplayNumber") then
		strVal=CDbl(strVal)
	end if
	
	CGetVal=strVal
	
End Function


Function CSetFocus(Id)	
	'strid=GetClientID(Id)
	strid=Id
	document.all(strId,0).focus()
end function

sub Detail_onKeyDown()
	set obj=window.event.srcElement
	if ucase(obj.parentElement.tagname)<>"TD" then exit sub
	set TB=obj.parentElement.parentElement.parentElement
	intRow=obj.parentElement.parentElement.rowIndex
	
	if	window.event.keycode=38 then		
		if intRow=0 then exit sub
		TB.rows(intRow-1).cells(obj.parentElement.cellIndex).children.item(0).focus()
	end if	
	
	if window.event.keycode=40 then
		if intRow=TB.rows.length-1 then exit sub
		TB.rows(intRow+1).cells(obj.parentElement.cellIndex).children.item(0).focus()
	
	end if				
end sub		
				
Sub Document_OnKeyPress() 
	dim strClass				
	intKeyCode=window.event.keycode	
	strClass=window.event.srcElement.classname
	
	if intKeyCode=13 or intKeyCode=9 then exit sub					
	if strClass="Date" or strClass="YM" then
		if intKeyCode <48 or intKeyCode >=58 then 
			window.event.keycode=0
		end if	
	end if		
	
	if strClass="Number" or strClass="DNumber" or strClass="StringNumber" then
		if (intKeyCode <48 or intKeyCode >=58) AND intKeyCode <>45  AND intKeyCode <>46 then 
			window.event.keycode=0
		end if	
	end if	
	
End Sub

Sub Document_OnClick() 
    set obj=window.event.srcElement
    if instr(obj.className,"button")<=0 then exit sub
    
    if obj.value="刪" then 
       window.event.returnValue=window.confirm("確定刪除嗎?")
    end if
End Sub

Function get_toDate()
   get_toDate=cstr(datepart("yyyy",date())) +"/"+ right("0"+cstr(datepart("m",date())),2) +"/"+ right("0"+cstr(datepart("d",date())),2)
End function

Function get_toDateAdd(intday)
   date1=dateadd("d",intday,date())
   get_toDateAdd=cstr(datepart("yyyy",date1)) +"/"+ right("0"+cstr(datepart("m",date1)),2) +"/"+ right("0"+cstr(datepart("d",date1)),2)
End function

Function Conv_Date(strValue) 'Date Check
	strDate=replace(strValue,"/","")
    if len(strDate)<>8 then
		strDate=""
    End if
    strDate=left(strDate,4)+"/"+mid(strDate,5,2)+"/"+right(strDate,2)
    if isDate(strDate)=false then		
		strDate=""		       
    End if
    if strValue<>"" and strDate="" then 
       window.alert("日期格式錯誤!!(yyyy/mm/dd)")
    end if	
    Conv_Date=strDate
End Function			

Function Conv_YM(strYM) 'YM Check
	strYM=replace(strYM,"/","")
    if len(strYM)<>6 then
		strYM=""
    End if
    strYM=left(strYM,4)+"/"+mid(strYM,5,2)+"/01"
    if isDate(strYM)=false then		
		strYM=""
	else
	    strYM=left(strYM,7)
    End if	
    Conv_YM=strYM
End Function			

Function Conv_Time(strTime) 'Time Check
	strTime=replace(strTime,":","")
    if isnumeric(strTime)=false then
	   strTime=""
	end if	
	
	if len(strTime)=4 then
        strHour=left(strTime,2)
        strMins=mid(strTime,3,2)    
   		if strHour<0 or strHour>=24 then strTime=""
		if strMins<0 or strMins>=60 then strTime=""
        if strTime<>"" then    
		    strTime=strHour+":"+strMins
	    end if					
    elseif len(strTime)=6 then
        strHour=left(strTime,2)
        strMins=mid(strTime,3,2)
        strSec=right(strTime,2)
   		if strHour<0 or strHour>=24 then strTime=""
		if strMins<0 or strMins>=60 then strTime=""
		if strSec<0 or strSec>=60 then strTime=""    
        if strTime<>"" then    
		    strTime=strHour+":"+strMins+":"+strSec		
	    end if			
    else
		strTime=""
    End if
    Conv_Time=strTime
End Function				