﻿//目的：判斷欄位一定要輸入英文或數字
//參數：objFld--傳入欄位ID
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS
//   1. 2005/04/22   1.00    Michael        New Create
function chkEAN(objFld)
{
    if(window.event.keyCode==37 || window.event.keyCode==38 || window.event.keyCode==39 || window.event.keyCode==40)
    {return;}
	var temp =objFld.value;		
	if (objFld.value!="")
	{			
		if (!((window.event.keyCode>=48 && window.event.keyCode<=57) || (window.event.keyCode>=65 && window.event.keyCode<=90) || window.event.keyCode==13 || window.event.keyCode==8 || window.event.keyCode==46 || window.event.keyCode==9))
		{
			//alert("A~Z,a~z or 0~9 only ");
			objFld.focus();
			window.event.returnValue=false;					
		}	
	}		
}

function KeyCodeOnlyChar()
{
    if(window.event.keyCode==37 || window.event.keyCode==38 || window.event.keyCode==39 || window.event.keyCode==40)
    {return;}
    if (!((window.event.keyCode>=65 && window.event.keyCode<=90) || window.event.keyCode==13 || window.event.keyCode==8 || window.event.keyCode==46 || window.event.keyCode==9))
	{
		window.event.returnValue=false;					
	}	
}

function KeyCodeOnlyNumber()
{
    if(window.event.keyCode==37 || window.event.keyCode==38 || window.event.keyCode==39 || window.event.keyCode==40)
    {return;}
    if (!((window.event.keyCode>=48 && window.event.keyCode<=57)|| (window.event.keyCode>=96 && window.event.keyCode<=105) || window.event.keyCode==13 || window.event.keyCode==8 || window.event.keyCode==46 || window.event.keyCode==9))
	{
		window.event.returnValue=false;					
	}	
}
//可以輸入數字和.
//add by saga
function KeyCodeOnlyNumberAndDot()
{
    if(window.event.keyCode==37 || window.event.keyCode==38 || window.event.keyCode==39 || window.event.keyCode==40)
    {return;}
    if (!((window.event.keyCode>=48 && window.event.keyCode<=57)|| (window.event.keyCode>=96 && window.event.keyCode<=105) || window.event.keyCode==13 || window.event.keyCode==8 || window.event.keyCode==46 || window.event.keyCode==9 || window.event.keyCode==190 || window.event.keyCode==110))
	{
		window.event.returnValue=false;					
	}	
}
//用於onBlur:輸入數字的位數LenTh，小數的位數DotLen,欄位obj
//整數位數超過則清空，小數部分超過則截取
//若欄位為空，則預設0.00
//add by saga
function funChkNum(obj,LenTh,DotLen)
{ 
    var ZLen = LenTh*1-DotLen*1;
    var DLen = DotLen*1;
    if (obj.value != "" && !isNaN(obj.value))
    {
        var arryValue = obj.value.split(".");
        if (arryValue.length == 1)//無小數點
        { 
            if (arryValue[0].length > ZLen)
            {
                obj.value = "0.00";
                obj.focus();  
                obj.select();
            }
            else
            {
                obj.value = obj.value * 1 + ".00";
            }
        }
        else if (arryValue.length == 2)//一個小數點
        {
            var leftNo;//小數點左邊數字
            var rightNo;//小數點右邊數字
            leftNo = arryValue[0];
            rightNo = arryValue[1];
            if(leftNo.length > ZLen)
            {
                obj.value = "0.00";
                obj.focus();  
                obj.select();
                return false;
            }
            obj.value = leftNo * 1 + ".";
            if (rightNo.length > DLen)
            {
                rightNo = rightNo.substring(0,DLen);
            }
            else
            {
                var i_ZeroNum = DLen-rightNo.length
                for(var i=0;i<i_ZeroNum;i++)
                {
                    rightNo += "0";
                }
            }
            obj.value = obj.value + rightNo;
        }
    }
    else
    {
          obj.value = "0.00";
          obj.focus();  
          obj.select();
          return false;
    }
}

//用於onBlur:輸入數字的位數LenTh，小數的位數DotLen,欄位obj
//整數位數超過則清空，小數部分超過則截取
//若欄位為空，則預設空
//add by saga
function funChkNumNull(obj,LenTh,DotLen)
{ 
    var ZLen = LenTh*1-DotLen*1;
    var DLen = DotLen*1;
    if (obj.value != "" && !isNaN(obj.value))
    {
        var arryValue = obj.value.split(".");
        if (arryValue.length == 1)//無小數點
        { 
            if (arryValue[0].length > ZLen)
            {
                obj.value = "0.00";
                obj.focus();  
                obj.select();
            }
            else
            {
                obj.value = obj.value * 1 + ".00";
            }
        }
        else if (arryValue.length == 2)//一個小數點
        {
            var leftNo;//小數點左邊數字
            var rightNo;//小數點右邊數字
            leftNo = arryValue[0];
            rightNo = arryValue[1];
            if(leftNo.length > ZLen)
            {
                obj.value = "0.00";
                obj.focus();  
                obj.select();
            }
            obj.value = leftNo * 1 + ".";
            if (rightNo.length > DLen)
            {
                rightNo = rightNo.substring(0,DLen);
            }
            else
            {
                var i_ZeroNum = DLen-rightNo.length
                for(var i=0;i<i_ZeroNum;i++)
                {
                    rightNo += "0";
                }
            }
            obj.value = obj.value + rightNo;
        }
    }
    else
    {
          obj.value = "";
          return false;
    }
}

//用於onBlur:判斷百分比合法性,obj為欄位
//若欄位為空，則預設為0.00
//add by saga
function funChkPer(obj)
{ 
    if (obj.value != "" && !isNaN(obj.value))
    {
        var arryValue = obj.value.split(".");
        if (arryValue.length == 1)//無小數點
        { 
            if (arryValue[0].length > 3)
            {
                obj.value = "0.00";
            }
            else if(arryValue[0].length == 3)
            {
                if(arryValue[0] == "100")
                {
                    obj.value = "100.00";
                }
                else
                {
                    obj.value = "0.00";
                }
            }
            else
            {
                obj.value = obj.value * 1 + ".00";
            }
        }
        else if (arryValue.length == 2)//一個小數點
        {
            var leftNo;//小數點左邊數字
            var rightNo;//小數點右邊數字
            leftNo = arryValue[0];
            rightNo = arryValue[1];
            if(leftNo.length > 3)
            {
                obj.value = "0.00";
            }
            else if(leftNo.length == 3)
            {
                if(leftNo == "100")
                {
                    obj.value = "100.00";
                }
                else
                {
                    obj.value = "0.00";
                }
            }
            else
            {
                obj.value = leftNo * 1 + ".";
                if (rightNo.length > 2)
                {
                    rightNo = rightNo.substring(0,2);
                }
                else
                {
                    var i_ZeroNum = 2-rightNo.length
                    for(var i=0;i<i_ZeroNum;i++)
                    {
                        rightNo += "0";
                    }
                }
                obj.value = obj.value + rightNo;
            }
        }
    }
    else
    {
          obj.value = "0.00";
          obj.focus();  
          obj.select();
          return false;
    }
}

//用於onBlur:判斷百分比合法性,obj為欄位
//若欄位為空，則預設為空
function funChkPerNull(obj)
{ 
    if (obj.value != "" && !isNaN(obj.value))
    {
        var arryValue = obj.value.split(".");
        if (arryValue.length == 1)//無小數點
        { 
            if (arryValue[0].length > 3)
            {
                obj.value = "0.00";
            }
            else if(arryValue[0].length == 3)
            {
                if(arryValue[0] == "100")
                {
                    obj.value = "100.00";
                }
                else
                {
                    obj.value = "0.00";
                }
            }
            else
            {
                obj.value = obj.value * 1 + ".00";
            }
        }
        else if (arryValue.length == 2)//一個小數點
        {
            var leftNo;//小數點左邊數字
            var rightNo;//小數點右邊數字
            leftNo = arryValue[0];
            rightNo = arryValue[1];
            if(leftNo.length > 3)
            {
                obj.value = "0.00";
            }
            else if(leftNo.length == 3)
            {
                if(leftNo == "100")
                {
                    obj.value = "100.00";
                }
                else
                {
                    obj.value = "0.00";
                }
            }
            else
            {
                obj.value = leftNo * 1 + ".";
                if (rightNo.length > 2)
                {
                    rightNo = rightNo.substring(0,2);
                }
                else
                {
                    var i_ZeroNum = 2-rightNo.length
                    for(var i=0;i<i_ZeroNum;i++)
                    {
                        rightNo += "0";
                    }
                }
                obj.value = obj.value + rightNo;
            }
        }
    }
    else
    {
          obj.value = "";
          return false;
    }
}
//目的：判斷欄位一定要輸入數字
//參數：objFld--傳入欄位ID
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS
//   1. 2005/04/22   1.00    Michael        New Create
function IsNumeric(objFld)
{
	var temp =objFld.value;		
	if (objFld.value!="")
	{		
		if (isNaN(objFld.value))
		{
			//alert("Number only");
			ShowError('J000036');
			objFld.value="";
			objFld.focus();
			window.event.returnValue=false;					
		}	
		var ary=objFld.value.split(".");
		if(ary.length==1)
		    return true;
		var strV1=ary[0];
		var strV2=ary[1];
		if(strV1=="") strV1="0";
		if(strV2=="") 
		    objFld.value=strV1;
		else
		    objFld.value=strV1+"."+strV2;		
	}	
	return true;	
}
//目的：當拉動datagrid的捲軸時標頭隨著捲軸動
//參數：
////  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS
////   1. 2005/05/07   1.00    Michael        New Create 
//function head_scroll()
//{
//	var objdiv=document.all.tags("div");
//	for (i=0;i<objdiv.length;i++)
//	{
//		if(objdiv[i].id.substring(0,23)=="ctl00_MainPlace_DG_Head")
//		{
//			var Head=objdiv[i];
//		}
//		if(objdiv[i].id.substring(0,25)=="ctl00_MainPlace_DG_detail")
//		{
//			var detail=objdiv[i];
//		}
//	}
//	if (Head!=null && detail!=null)
//    { 
//		Head.scrollLeft=detail.scrollLeft; 
//	}		
//}  
function head_scroll(objDivHead,objDivGrid)
{
	if (objDivHead!=null && objDivGrid!=null)
    { 
		objDivHead.scrollLeft=objDivGrid.scrollLeft; 
	}		
}  

//目的：設定有捲軸的datagrid的標題欄位，且隱藏原來grid的標題
//參數：
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS
//   1. 2005/05/07   1.00    Michael        New Create
function SetTitle()
{	
	if(document.forms[0].all("ctl00_MainPlace_txtDGName")!=null)
	{
		var ObjTable=document.forms[0].all("ctl00_MainPlace_txtDGName").value;
		var objdiv=document.all.tags("div");
		for (i=0;i<objdiv.length;i++)
		{		
			if(objdiv[i].id.substring(0,23)=="ctl00_MainPlace_DG_Head")
			{								
				var Head=objdiv[i];
				if (document.all(ObjTable)!=null)
    			{    		
  					var Content=document.all(ObjTable);
  					var dgtable=Content.cloneNode(false);  			
   					var dgtable_head=Content.rows(0).cloneNode(true);
  					var NewRow=dgtable.insertRow(0);
  					NewRow.replaceNode(dgtable_head);  
  					Head.insertBefore(dgtable); 
					Content.rows(0).style.display = "none"; 					
  					dgtable.id="Header";  		      
    			}    			
			}			
		}  		
    }
}
function disableall_control(){
      for(i=0;i<document.forms[0].elements.length;i++){
            document.forms[0].elements[i].disabled=true;
      }
}
function enableall_control(){

      for(i=0;i<document.forms[0].elements.length;i++){
            document.forms[0].elements[i].disabled=false;
      }
}
//字符串去空格的正則式
String.prototype.trim=function()
{
	return this.replace(/(^\s*)|(\s*$)/g,'');
}

//判斷日期是否合法
function FunIsDate(str) 
{ 
//	var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
//	if(r==null)return false;  
//	var d= new Date(r[1], r[3]-1, r[4]);  
//	return (d.getFullYear()==r[1] && (d.getMonth()+1)==r[3] && d.getDate()==r[4]); 
 	var objV=str;
	var sY;
	var sM;
	var sD;
	var strTimeAry1=objV.split("/");
	if(strTimeAry1.length != 3)
	    return false;
	sY=strTimeAry1[2];
	sM=strTimeAry1[0];
	sD=strTimeAry1[1];
	//alert(objV);
	try{
	    is=sY * 1;
	    is=sM * 1;
	    if(sD * 0 !=0)
	        return false;
	}catch(e)
	{return false;}
	if(sY.length !=4 || sM.length>2 || sD.length>2)
	    return false;
	if(sM>'12' || sM<'01' || sD<'01' || sD>'31')
		return false;
	else
		if(((sM=='04'||sM=='06'||sM=='09'||sM=='11')&& sD=='31')||(sM=='02' && sD>'29')||(sM=='02' && sD=='29' &&(sY%4!=0 ||(sY%100==0 && sY%400!=0))))
			return false;
	return true;				
}

//判斷欄位日期是否合法，不合法清空并提示
//add by saga
function chkDate(obj)
{
    var s_value = obj.value;
    if(s_value != "")
    {
        var bool_value = FunIsDate(s_value);
        if(bool_value == false)
        {  
            document.getElementById("lblOpenDate").innerHTML=ShowMessage("J000058","");//日期格式錯誤
//            ShowError("J000058"); //日期格式錯誤，請輸入如下格式的日期：mm/dd/yyyy
            obj.value = "";
        }
    }
}
//檢查時間欄位值的合法性
//objtime時間對象
//strH=0返回HH:MM，否則返回HH:MM:SS
function Check_Time_Field(objtime,strH)  
{
	var strTime
	var resStr="";
	var vH
	var vM
	var vS
	strTime=objtime.value.trim();
	if(strTime=="")	return true; //若時間為空值, 則不做	
	//設定時間為準模式 "12：00：00"	
	//XX.XX.XX
	resStr="";
	for(var i=0;i<strTime.length;i++)
		resStr=resStr +((strTime.substring(i,i+1)).replace('.',':'));
	strTime=resStr;
	//XX XX XX
	resStr="";
	for(var i=0;i<strTime.length;i++)
		resStr=resStr +((strTime.substring(i,i+1)).replace(' ',':'));
	strTime=resStr;
	//XX-XX-XX 
	resStr="";		
	for(var i=0;i<strTime.length;i++)
		resStr=resStr+((strTime.substring(i,i+1)).replace('-',':'));
	strTime=resStr;	
	//XXXXXXXX
	if(strTime.indexOf(":")<=0)
	{
		if(strTime.length==1)
			strTime="0"+""+strTime+":00:00";
		else{
			strTime=(strTime+'000000').substring(0,6)
		 	strTime=strTime.substring(0,2)+":"+strTime.substring(2,4)+ ":"+strTime.substring(4,6);
	 	}
	}
	//XX:XX
	if(strTime.lastIndexOf(":")>0 && strTime.lastIndexOf(":")<=2)
		strTime=strTime+':00';	
		
	var strTimeArry2=strTime.split(":");	
	vH=strTimeArry2[0];
	vM=strTimeArry2[1];
	vS=strTimeArry2[2];
	if(strTimeArry2.length==2)
		vS="00";
	if(!(isNaN(vH)||isNaN(vM)||isNaN(vS)))
	{
		if(vH>=24) vH=vH-24;
		if(vM>=60) vM=vM-60;
		if(vS>=60) vS=vS-60;	
		vH="00"+(vH*1).toString()
		vH=vH.substring(vH.length-2,vH.length)
		vM="00"+(vM*1).toString()
		vM=vM.substring(vM.length-2,vM.length)
		vS="00"+(vS*1).toString()
		vS=vS.substring(vS.length-2,vS.length)
	}	
	strTime=vH+":"+vM+":"+vS;
//對時間進行判斷
	if(!IsTime(strTime))
	{
		alert("Time error !") ;
		objtime.value="";
		objtime.focus();		
		return false;
	}	
	if(strH==0)
		strTime=strTime.substring(0,5);
	objtime.value=strTime;	
	return true;
}
//檢查時間合法性
function IsTime(strTime)
{
	var strHours;
	var strMinutes;
	var strSeconds;	
	var strTimeArry3=strTime.split(":");　//以":"為界分裝到數組中
	if(strTimeArry3.length!=3)//如果不是時分秒標准形式不判斷　　
		return false;
	strHours=strTimeArry3[0];
	strMinutes=strTimeArry3[1];
	strSeconds=strTimeArry3[2]
	if(isNaN(strHours)||isNaN(strMinutes)||isNaN(strSeconds))
		return false;
	if(strTimeArry3[0].length>2||strTimeArry3[1].length>2||strTimeArry3[2].length>2)
		return false;
	if(strHours>23||strHours<0||strMinutes>59||strMinutes<0||strSeconds>59||strSeconds<0)
		return false;
	return true;
}
//目的：欄位格式化，不足位時用0補足
//參數：obj對象,intBit欲補足的位數
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS
//   1. 2005/06/09   1.00    XIONG       Create
function funFormat(obj,intBit)
{
	var val=obj.value.trim();
	var str="";
	var i=0;
	if(val!="")
	{
		for(i=0;i<intBit;i++)
			str=str+"0";
		val=str + val;
		val=val.substring(val.length-intBit,val.length);
		obj.value=val;
		return true;
	}
	return false;
}
//左右兩個TEXT物件範圍帶值
function text_range(obj1,obj2,cho,pos){
   //obj1=起始物件;
   //obj2=終止物件;
   //cho=D:日期的物件;U:需轉成大寫的物件;L:需轉成小寫的物件
   //pos=1:值來自起始物件;pos=2:值來自終止物件
   flg = true 
   if (pos==1){
      text1=obj1
      text2=obj2
   }else{
      text1=obj2
      text2=obj1
   }

   if (text1.value==''){
       return true;
   }
   if (cho=='D')
   {
      var bool=FunIsDate(text1.value);
      if(bool==false)
      {
		flg=false;
		text1.value="";
	  }
      if (flg==true){
         if (text1.value !='' && text2.value !='')
         {    
            ary1=obj1.value.split("/");
            ary2=obj2.value.split("/");        
//            if (obj2.value !=''&& obj1.value > obj2.value ){
            if (obj2.value !=''&& ary1[2]+"/"+ary1[0]+"/"+ary1[1] > ary2[2]+"/"+ary2[0]+"/"+ary2[1] )
            {
               alert("End less than Begin");
               //改成將兩個欄位都清空，並 Focus 於起日才對
               text1.value=text2.value;
               text1.select(); 
               text1.focus();  
               return false;            
            }
         }
      }
   }else if(cho=='U'){
      text1.value=text1.value.toUpperCase()
   }else if(cho=='L'){
      text1.value=text1.value.toLowerCase()
   }else if (cho=='T'){
		if(obj1.value.trim()!="" && obj2.value.trim()!="" && obj1.value.trim()*1>obj2.value.trim()*1)
		{
			alert("End less than Begin");
			 obj1.value=obj2.value;
              obj1.select(); 
              obj1.focus();  
               return false;           
			return false;
		}
   }
   
   if (flg==true && text2.value ==''){
      text2.value=text1.value;
      text2.select();
      text2.focus();
      return false;
   }
   return true;
}
/******************************
*作用：判斷一個物件中輸入的值是否超過設定大小,不區分中英文的，中文占１個長度
*名稱：isOver_EN（）
*參數：sText：對像名，len：允許長度
*用法示例：isOver_EN(this,20)
*/
function isOver_EN(sText,len)
{
	var intlen=sText.value.length;	
	if (intlen>len)
	{
		//alert("資料要求長度不得超過"+len+"個字符，目前資料長度是"+intlen+"個字符");
		sText.focus();	
		sText.select();
		return false;
	}
	return true;
}
/**********************************************************
作用textarea長度限定
用法checkLength(this,300)
this：對像名，len：允許長度
add by skyshi*/
function checkLength(objField,MaxLength) 
{
    
    if(objField.value!="") //不為空的情況下判斷
    {
        if(objField.value.length > MaxLength) 
        {
            //ShowError('A00009','不能輸入長度大于 '+MaxLength+' 的字符,系統將自動截取'+MaxLength+'');
            //alert('不能輸入長度大于 '+MaxLength+' 的字符,系統將自動截取'+MaxLength+'');
//            objField.value =objField.value.substring(0,MaxLength);
            ShowError("J000029",""+MaxLength+"")
            objField.focus();  
            return;
        }
    }
    
}
/******************************
*作用：判斷一個物件中輸入的值是否超過設定大小,一般用來判斷區分中英文的，中文占２個長度
*名稱：isOver（）
*參數：sText：對像名，len：允許長度
*用法示例：isOver(this,20)
*/
function isOver(sText,len,lblvalue)
{
	var intlen=sText.value.length;
	if (intlen<=len && intlen>len/2)
   		intlen=bitLenght(sText);
	if (intlen>len)
	{
	    document.getElementById(lblvalue).innerHTML=ShowMessage("J000002",""+len+"");
//	    alert("資料要求長度不得超過"+len+"個字符，目前資料長度是"+intlen+"個字符");
//	    ShowError("J000029",""+len+"")
//	    sText.value="";
//		sText.focus();	
//		sText.select();
		return false;
	}
	else
	{
	    document.getElementById(lblvalue).innerHTML="";
	    return true;
	}
}

//function isZipCode(objCounty,sText,len,lblvalue)
//{
//    if(objCounty.value=="US")
//    {
//        len=5;
//    }
//    else    
//    {
//        len=20;
//    }
//	var intlen=sText.value.length;
//	if (intlen<=len && intlen>len/2)
//   		intlen=bitLenght(sText);
//	if (intlen>len)
//	{	
//	    document.getElementById(lblvalue).innerHTML=ShowMessage("J000029",""+len+"");
////	    alert("資料要求長度不得超過"+len+"個字符，目前資料長度是"+intlen+"個字符");
////	    ShowError("J000029",""+len+"")
////	    sText.value="";
////		sText.focus();	
////		sText.select();
//		return false;
//	}
//	else
//	{
//	    document.getElementById(lblvalue).innerHTML="";
//	    return true;
//	}
//}

/******************************
*作用：計算一個對象的值的長度，中文占２個長度
*名稱：bitLenght（）
*參數：sText：對像名
*用法示例：bitLenght(sText)
*/
function bitLenght(sText)
{
	var intlen;
	intlen=0;
	for(var i=0; i<sText.value.length; i++)
	{
		if(sText.value.charCodeAt(i)>255){
				intlen=intlen+2;}
			else{
				intlen++;}
	}
	return intlen;	
}

//作用：判斷一個物件中輸入的值是否超過設定大小,一般用來判斷區分中英文的，中文占２個長度
//*名稱：isOver_CN（）
//*參數：sText：對像名，len：允許長度
//*用法示例：isOver_CN(this,20)
function isOver_CN(sText,len)
{
	var intlen=sText.value.length;
	if (intlen<=len && intlen>len/2)
   		intlen=bitLenght(sText);
	if (intlen>len)
	{
		return false;
	}
	else
	{
	    return true;
	}
}


//作用：判斷一個物件中輸入的值是否等於設定大小
//*名稱：isLength（）
//*參數：sText：對像名，len：允許長度
//*用法示例：isOver_CN(this,20)
function isLength(sText,len)
{
	var intlen=sText.value.trim().length;
	if (intlen<=len && intlen>len/2)
   		intlen=bitLenght(sText);    			
	if (intlen==len)
	{
		return true;
	}
	else
	{
	    return false;
	}
}


//功能：驗証Email的格式
//參數：field-->欲驗証的欄位 
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS　　
//   1. 2009/04/29    1.00     Lisa        New Create
function IsEmail(objField)
{
    with (objField)
    {
        
        apos=value.trim().indexOf("@");
        dotpos=value.trim().lastIndexOf(".");
        re = /^[^\s]+@[^\s]+\.[^\s]{2,3}$/;
        if(re.test(value.trim())==true)
        {
            return true;
        }
        else 
        {
            return false;
        }
      
    }
}

//判斷是否為數字
function isNumeric(strNum)
{
    var strCheckNum = strNum.value + "";
    if(isNaN(strCheckNum)) //不是數值     {
	    return false;
     }	
    return true;
}


//判斷欄位值是否是正整數
function Check_Int_Field_Plus(objF)
{
	if(Check_Int_Field(objF))
	{
		var intV=objF.value*1;
		if(intV<0)
		{
			alert("欄位值不可小於0!")
			objF.value="";
			objF.focus();
			objF.select();
			return false;
		}
		objF.value=intV;
		return true;	
	}
}
//判斷欄位值是否是整數
function Check_Int_Field(ObjName)
{
	var LV_Value =ObjName.value.trim();
    if ((LV_Value != '') && (!isInteger(LV_Value)))
    {
        alert("Integer only！");
	      ObjName.value="";
        ObjName.focus();
        return false;
    }
    return true;
}
//判斷是否為數字

//判斷是否是整數
function isInteger(strNum)
{
	var strCheckNum = strNum*1 + "";
	if(strCheckNum.length < 1) //空字符串
		return false;
	if(isNaN(strCheckNum)) //不是數值

		return false;
	if(parseFloat(strCheckNum) > parseInt(strCheckNum)) //不是整數
		return false;
	return true;
}

//*******************************************
//目的：生成xml
//參數：
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS
//   1. 2006/05/04   1.00    Cindy       Create
function __ATLoadXml(vstrReq){
//var strReq;				variable to hold request string
	var root, source;		//A couple of XMLDOM objects (document and 
	var sT;

	//Show a searching message
	status = 'searching, please wait....';
	//Create an xml document object, and load the server's response
	source = new ActiveXObject('Microsoft.XMLDOM');
	source.async = false;

	//Send the request string and read the result into the XMLDOM object
	source.load(vstrReq);
	//Check to see if there was an error parsing the response from the server
	if (source.parseError != 0){
		sT = 'XML Error...<br>reason:' + source.parseError.reason + '<br>';
		sT += 'errorCode:' + source.parseError.errorCode + '<br>';
		sT += 'filepos:' + source.parseError.filepos + '<br>';
		sT += 'line:' + source.parseError.line + '<br>';
		sT += 'linepos:' + source.parseError.linepos + '<br>';
		sT += 'reason:' + source.parseError.reason + '<br>';
		sT += 'srcText:' + source.parseError.srcText + '<br>';
		sT += '<pre>' + source.xml + '</pre><br>';
		alert(sT);
		status = 'XML Error!';}
	else {
		root = source.documentElement;		//Get a reference to root XML object
		status = 'Done';
		return root;}
}
function GetXmlHttpRequest()
{
    var xhr=null; 
    try 
    { 
        xhr=new ActiveXObject("Msxml2.XMLHTTP");//initialize a xmlhttp object 
    } 
    catch(e)
    { 
        try 
        { 
            xhr=new ActiveXObject("Microsoft.XMLHTTP"); 
        }
        catch(oc)
        { 
            xhr=null 
        } 
    } 

    if (!xhr && typeof XMLHttpRequest != "undefined" ) 
    { 
        xhr=new XMLHttpRequest() 
    } 
    return xhr 
} 

/*
'''<summary>
    目的: 以XML為數據源綁定DropDownList或ListBox
    參數: oCtlDrp DropDownList控件
          XmlNodeList XML格式的數據源
          FirstValue,FirstText 第一行Value,Text
'''</summary>
''' <remarks></remarks>
''' <history>
''' </history>
*/
function  BindListCtl(oCtlDrp,XmlNodeList,FirstValue,FirstText)
{
    oCtlDrp.options.length=0;
    oCtlDrp.options.add(new Option(FirstText,FirstValue)); 
    
    for(var i=0;i<XmlNodeList.length;i++)
    {
        var node=XmlNodeList(i).childNodes;
        oCtlDrp.options.add(new Option(node.item(1).text , node.item(0).text));
     }
}
//功能: 當按Enter時就移到下一個欄位//參數：//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS　　
//   1. 2005/04/22   1.00    michael        New Create
function EnterKey()
{		
    try{
 
    if (window.event.keyCode==13)
    {			
        var type=document.activeElement.type;       
        if (!(type=="button" || type=="submit" || type=="textarea"))
        {						
			        var SName=document.activeElement.name;		
			        var Idx=ElementIdx(SName);					
			        if (Idx==-1)
			        {
				        window.event.returnValue=false;
			        }
			        else
			        {						
				        //注意:連結按鈕不能算				
				        var maxItem=document.forms[0].length;
				        while  (Idx<=maxItem-2)
				        {							
                var typeNext=document.forms[0].elements[Idx+1].type;																						
                    if (!(typeNext=="button" || typeNext=="submit" || typeNext=="hidden" || typeNext=="option" || typeNext=="select-one" || typeNext=="checkbox" || typeNext=="radio" || document.forms[0].elements[Idx+1].style.display=="none" ))
                    {								
                    if(document.forms[0].elements[Idx+1].readOnly==true || document.forms[0].elements[Idx+1].disabled==true || document.forms[0].elements[Idx+1].parentNode.style.display=="none" )
                    {
                        Idx++;
                        continue;
                    }
                    else
                    {										
                        document.forms[0].elements[Idx+1].focus();		
                        window.event.returnValue=false;	//由上一行替代Focus動作								
                        break;										
                    }
                }
					        else
					        {
						        if(Idx==maxItem-1)
						        {
							        document.forms[0].elements[Idx].focus();	
							        window.event.returnValue=false;
							        break;
						        }else{
						        Idx++;					
						        continue;	}					
					        }
				        }
				        window.event.returnValue=false;	//由上一行替代Focus動作	
			        }
        }
    }
    }catch(e){}
}

//功能: 回傳 Control 索引值 in <Form> tag
//參數：sSName傳入要Focus的欄位名稱
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS　　
//   1. 2005/04/21   1.00    michael        New Create
function ElementIdx(SName){
	var IsFound=false;		
	if (SName!=""){					
		for (var i=0;i<=document.forms[0].length-1;i++){
			var Name=document.forms[0].elements[i].name;					
			if (SName==Name){
				IsFound=true;
				break;
			}
		}
	}			
	if (IsFound) return i;  else  return -1;		
}
/*
'''</summary>
'''提供Clinet偵測到有捲軸就切換視窗大小
''' <remarks></remarks>
''' <history>
'''     1. 2007/04/19   1.00    [michael]     Create
''' </history>
*/
function fnSetWidowSize(){
    if (window.dialogHeight<parseInt(document.body.scrollHeight+50)){
        window.dialogHeight = document.body.scrollHeight+50+"px";
    }
}   
/*****************************************************
* 函數名稱: fnSelAll()
* 目    的: 全選
* 參數說明: gridID:Grid之ID; chListID:CheckBox之ID; boolValue 全選欄溝選狀態，選中為true，未選為false
*****************************************************/
function fnSelAll(gridID,chListID,boolValue)
{	
    var MainPage="ctl00_MainPlace_";
    try
    {
	    var ObjTable = document.all(MainPage+gridID); 
        for(i=2; i < ObjTable.rows.length; i++)
        {
            var intA=i*1+1;
            if((intA+"").length<2)
                intA="0"+intA;
	        //alert(MainPage+gridID+"_ctl"+intA+"_"+chListID);
            var objCheckBox = document.all(MainPage+gridID+"_ctl"+intA+"_"+chListID);
            objCheckBox.checked =boolValue;
        }
     }catch(e){//alert(e);
     }
}

//設置只可以選一個CHECKBOX,實例onclick="return SingleChk(this,'grdList','chkList')"
//BY INSON
function SingleChk(obj,grdList,chkList)
{
if(obj.checked==false)
{
}
else
{
        var MainPage="ctl00_MainPlace_";
        var ObjTable = document.all(MainPage + grdList);
        var intCount=0;
            for(var i=2; i < ObjTable.rows.length+1; i++)
            {
                var intA=i*1+1;
                if((intA+"").length<2)
                    intA="0"+intA;
                var objCheckBox = document.all(MainPage + grdList + "_ctl"+intA+"_"+chkList);
                if(objCheckBox!=null&&objCheckBox.id!=obj.id)
                {
                objCheckBox.checked=false;
                }
            }
  } 
}
/*****************************************************
* 函數名稱: fnGetSelctCount()
* 目    的: 計算Grid勾選的筆數
* 參數說明: gridID:Grid之ID; chListID:CheckBox之ID;
*****************************************************/
function fnGetSelctCount(gridID,chListID)
{	
    var MainPage="ctl00_MainPlace_";
    var intCount=0;
    try
    {
	    var ObjTable = document.all(MainPage+gridID); 
        for(i=2; i < ObjTable.rows.length; i++)
        {
            var intA=i*1+1;
            if((intA+"").length<2)
                intA="0"+intA;
            var objCheckBox = document.all(MainPage+gridID+"_ctl"+intA+"_"+chListID);
            if(objCheckBox.checked ==true)
                intCount +=1;
        }
     }catch(e){
     }
     return intCount;
}
//Grid選擇的顏色變化
function fnGridSelectRow(grdList,intRow)
{
    var MainPage="ctl00_MainPlace_";
//    var ObjTable = document.all(MainPage + grdList);
    var ObjTable = document.all(grdList);
    for(var i=1; i < ObjTable.rows.length; i++)
    {
        if(i % 2==0)
            ObjTable.rows[i].className="Row2";
        else
            ObjTable.rows[i].className="Row1";
    }
    ObjTable.rows[intRow].className="RowSel";
}
/**********************************************************************************************
* 函數名稱: funPrint(obj1,obj2)
* 目    的: 屏蔽報表打印時的按鈕，使打印出來的資料中按鈕不顯示在報表上。報表專用的JS方法
* 參數說明: obj1:上面一行Button的ID，這個ID放在<tr>或者<td>中，Ex:<tr id="trB1"></tr>.這樣就可以實現整行的button都隱藏。
            obj2:底部一行Button的ID，這個ID放在<tr>或者<td>中，Ex:<tr id="trB2"></tr>.這樣就可以實現整行的button都隱藏。
            
* 具體調用方法: this.btnPrint_Bottom.Attributes.Add("onclick", "funPrint('" + this.trB1.ClientID + "','" + this.trB2.ClientID + "');return false;");
**********************************************************************************************/
function funPrint(obj1,obj2)
{
    document.all(obj1).style.display='none';
    document.all(obj2).style.display='none';
    var ret = saveAndClearSetting(); 
    fnPrint();
    document.all(obj1).style.display='';
    document.all(obj2).style.display='';
    if ( ret ) restoreSetting();
    return false;
}

//執行EXE文件
function open_exe(shellp,str)  
{  
    try
    {
        var a = new ActiveXObject("WScript.Shell"); 
        a.run(shellp+" "+str);
        alert('true');
        return true;
    }
    catch(e)
    {
        alert('catch');
        return false;
    }
}

////new
//功能：清除IE fileUpLoad控件中選中的文件路徑，fileUpLoad控件只要选择了文件在Postback的时候这个文件都会被自动上传到服务器//參數：fileUpLoad控件的ID
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS　　
//   1. 2009/06/08   1.00    XY     New Create   
function fnClearFilePath(file)
{　
    var optype=1;//控制執行那種方法
	switch(optype)
	{
		case 0:
			var form=document.createElement('form');　
			document.body.appendChild(form);　
			//记住file在旧表单中的的位置　
			var pos=file.nextSibling;　
			form.appendChild(file);　
			form.reset();　
			pos.parentNode.insertBefore(file,pos);　
			document.body.removeChild(form);
			break;　
		case 1:
			file.select();
			document.selection.clear();
			break;
		case 2:
			//form.reset();
			break;
		case 3:
			file.outerHTML=file.outerHTML;
			break;
	}　	
}　
	
////new
//功能：清除指定的Element的子節點中的INPUT的輸入值//參數：可以接受4個參數，用動態參數列表arguments
//第1個，父節點的ID；第2個，排除清空的ID，用，分割；第3~n個，需要額外清理和默認給值的標籤ID列表用逗號(,)分割（格式：ID,表達式）
//值中不可以出現(,)
//  xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS　　
//   1. 2009/06/06   1.00    XY     New Create   
//   2. 2009/06/08   1.01    XY     Modify   
//以下是測試代碼
//<form>  
//<input type="radio" name='radio' id='r1'  value="1" >radio1  
//<input type="radio" name='radio' id='r2'  value="2" >radio2
//<input type="checkbox" name='check' id='c1' value="2" >checkbox
//<input type="file" name='file' id='f1' >file 
//<TEXTAREA STYLE="overflow:hidden" ID='txtComments'>TEXTAREA1</TEXTAREA>
//<Label id="l1">label1</label>
//<TEXTAREA STYLE="overflow:hidden" ID='txtComments2'>TEXTAREA2</TEXTAREA>
//<Label id="l2">label2</label>
//<input type="button" name='test' value="test" onclick="fnReset('','txtComments,l1','c1,checked=false','r1,checked=true');">button  
//</form>
function fnReset()
{
   var strPara0="";
   var strPara1="";
   //讀取參數列表
   if(arguments.length>=1) strPara0=arguments[0];
   if(arguments.length>=2) strPara1=arguments[1];
   
   var objParent=null;
	//第1個，父節點的ID；
    if(strPara0=="")
    {
        objParent=document;
    }
    else
    {
        objParent=document.getElementById(strPara0);
    }
	
	var objCtrl=null;
	var ilength=objParent.all.length;
	for(i = 0; i <ilength ; i++)
	{
		objCtrl=objParent.all(i);
		//第2個，排除清空的ID
		if(strPara1!="" && objCtrl.id!="" && strPara1.toUpperCase().indexOf(objCtrl.id.toUpperCase())>=0) continue;
		switch(objCtrl.tagName.toUpperCase())
		{
			case "INPUT":
				switch(objCtrl.type.toUpperCase())
				{
					case "TEXT":
						objParent.all(i).value="";
						break;
					case "CHECKBOX":
						objParent.all(i).checked=false;
						break;
					case "RADIO":
						objParent.all(i).checked=false;
						break;
					case "FILE":
						fnClearFilePath(objParent.all(i));
					default:
						break;
				}
				break;
			case "SELECT":
			    var ilen=objCtrl.options.length
			    if(objCtrl.type.toUpperCase()=="SELECT-MULTIPLE" || 
			    (objCtrl.type.toUpperCase()=="SELECT-ONE" && objCtrl.size>1))
			    {
			        for(j=0;j<ilen;j++)
			        {
			           objCtrl.remove(0);
			        }
			    }
			    else
			    {
			        if(ilen>0)
			           objCtrl.options[0].selected = true;
			    }
				break;
			case "TEXTAREA":
				objCtrl.innerText="";
				break;
			//case "LABEL":
		      //objCtrl.innerText="";
			  break;
			default:
				break;
		}
	}
	
   //第3~n個，需要額外清理、默認給值的標籤ID列表；用逗號（,）分割（格式：ID,表達式）
   if(arguments.length>=3)
   {
		for(i=2;i<arguments.length;i++)
		{
			var Datas=arguments[i].split(",");
			if(Datas[0]!="")
			{
				var objtmp=document.getElementById(Datas[0]);
				eval("objtmp." + Datas[1] + ";");
			}
		}
   }
}

function fnChangeCountry(txtCountry,objState,objtxtState)
{
    var str_Master="ctl00_MainPlace_";
    //當選中美國顯示State為下拉列表
    if(txtCountry=="US")
    {
        objState.style.display="inline";
        objtxtState.style.display="none";        
    }
    else
    {
        objState.style.display="none";
        objtxtState.style.display="inline";
//        objState.value="";
    }
//    if(document.getElementById(str_Master+"txtZipCode")!=null)
//    {
//       document.getElementById(str_Master+"txtZipCode").value="";
//    }
    //當選中美國電話號碼的顯示方式為：XXX-XXX-XXXX的形式
//    document.getElementById(str_Master+"txtTelphone").style.display="none";
//    document.getElementById(str_Master+"sp1").style.display="none";  
//    document.getElementById(str_Master+"sp2").style.display="none";  
//    document.getElementById(str_Master+"sp3").style.display="none";  
//    document.getElementById(str_Master+"txtPhone1").style.display="none";              
//    document.getElementById(str_Master+"txtPhone2").style.display="none";              
//    document.getElementById(str_Master+"txtPhone3").style.display="none";                                      
    switch (txtCountry)
    {
        case "US":
        if( document.getElementById(str_Master+"txtTelphone")!=null)
        {
            document.getElementById(str_Master+"txtTelphone").style.display="none";
            document.getElementById(str_Master+"sp1").style.display="";  
            document.getElementById(str_Master+"sp2").style.display="";  
            document.getElementById(str_Master+"sp3").style.display="";  
            document.getElementById(str_Master+"txtPhone1").style.display="";              
            document.getElementById(str_Master+"txtPhone2").style.display="";              
            document.getElementById(str_Master+"txtPhone3").style.display="";  
        }
        if(document.getElementById(str_Master+"txtFax")!=null&& document.getElementById(str_Master+"Span1")!=null) 
        {   
            document.getElementById(str_Master+"txtFax").style.display="none";          
            document.getElementById(str_Master+"Span1").style.display="";              
            document.getElementById(str_Master+"Span2").style.display="";              
            document.getElementById(str_Master+"Span3").style.display=""; 
            document.getElementById(str_Master+"txtFax1").style.display="";  
            document.getElementById(str_Master+"txtFax2").style.display="";  
            document.getElementById(str_Master+"txtFax3").style.display=""; 
         }                        
             break;
        default:
         if( document.getElementById(str_Master+"txtTelphone")!=null)
        {
            document.getElementById(str_Master+"txtTelphone").style.display="";
            document.getElementById(str_Master+"sp1").style.display="none";  
            document.getElementById(str_Master+"sp2").style.display="none";  
            document.getElementById(str_Master+"sp3").style.display="none";  
            document.getElementById(str_Master+"txtPhone1").style.display="none";              
            document.getElementById(str_Master+"txtPhone2").style.display="none";              
            document.getElementById(str_Master+"txtPhone3").style.display="none";
        }    
        if(document.getElementById(str_Master+"txtFax")!=null&& document.getElementById(str_Master+"Span1")!=null) 
        {     
            document.getElementById(str_Master+"txtFax").style.display="";          
            document.getElementById(str_Master+"Span1").style.display="none";              
            document.getElementById(str_Master+"Span2").style.display="none";              
            document.getElementById(str_Master+"Span3").style.display="none"; 
            document.getElementById(str_Master+"txtFax1").style.display="none";  
            document.getElementById(str_Master+"txtFax2").style.display="none";  
            document.getElementById(str_Master+"txtFax3").style.display="none";
        }            
       break;
      }
}

//檢查文本框是否有值，有值就去掉欄位為空的提示
function fnCheck(objtxt,lblValue)
{
    if(objtxt.value!="")
    {
        document.getElementById(lblValue).innerHTML="";
    }
}

//[檢查字符串是否包含除數值、橫綫以外的字符,是則返回true]
//eg:var bIs=fnCheckStrCN("1231")
function fnCheckPhone(strCheck) 
{ 
    for(var i=0;i<strCheck.value.length;i++)  
    {  
         var strTemp=strCheck.value.charAt(i);  
         if( (strTemp<"0" || strTemp>"9") && (strTemp!="-"))  
         {
             return false;  
         }
   } 
   return true ;  
} 

//確認刪除用戶評論
function FN_DelReviews(strCode)
{
   var strFLAG= window.confirm(ShowMessage(strCode));
   if(!strFLAG)
   {
      return false;
   }
   else
   {
      return true;
   }
}

//20091228 ayue驗證一個字串是否包含數字與字符，包含返回真，否則返回假
function FnCheckChNum(strChecked)
{
    if(strChecked.trim().length==0)
    {
        return true;
    }
    var strExp=/([0-9][a-zA-Z]|[a-zA-Z][0-9])+/;
    
    if(strExp.test(strChecked))
    {
        return true;
    }
    else
    {
        return false;
    }
}
