﻿
  function EnableTableCells(enable_row,startcell) {
		for (i=startcell; i < document.getElementById("DataTable").rows(enable_row).cells.length; i++) {			
			document.getElementById("DataTable").rows(enable_row).cells(i).disabled=false;
		}
  }
  function DisableTableCells(disable_row) {
		for (i=1; i < document.getElementById("DataTable").rows(disable_row).cells.length; i++) {			
			document.getElementById("DataTable").rows(disable_row).cells(i).disabled=true;
		}
  }
  function DisableAllTableCells(startcell) {
		for (i=1; i < document.getElementById("DataTable").rows.length; i++) {
		  for (j=startcell; j < document.getElementById("DataTable").rows.item(i).cells.length; j++) {						  
			  document.getElementById("DataTable").rows.item(i).cells(j).disabled=true;
		  }
	  }
  }
function replaceAllString(strOrg,strFind,strReplace){
 var index = 0;
 while(strOrg.indexOf(strFind,index) != -1){
  strOrg = strOrg.replace(strFind,strReplace);
  index = strOrg.indexOf(strFind,index);
 }
 return strOrg;
} 
  
	
	//去空白
	function trim(string)
  	{
  	return string.replace(/^\s+|\s+$/g,"");
  	}
	//檢查小數點位數
	//str 欲檢查數字
	//num 小數位數
	function Check_dou(str,num){
		var dou=str.indexOf(".")+1;
		if(dou==0){return true}
		var str1=str.substring(dou,str.length);
		if(str1.length>num){
			return false
		}
		else{
			return true
		}
	}
	//數字格式化
	//number 想格式化的數字
	//pattern 格式樣式 
	//例: formatNumber(number,"#,###")
	function formatNumber(number,pattern){
    var str = number.toString();
    var strInt;
    var strFloat;
    var formatInt;
    var formatFloat;
    if(/\./g.test(pattern)){
        formatInt = pattern.split('.')[0];
        formatFloat = pattern.split('.')[1];
    }else{
        formatInt = pattern;
        formatFloat = null;
    }

    if(/\./g.test(str)){
        if(formatFloat!=null){
            var tempFloat = Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);
            strInt = (Math.floor(number)+Math.floor(tempFloat)).toString();                
            strFloat = /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';            
        }else{
            strInt = Math.round(number).toString();
            strFloat = '0';
        }
    }else{
        strInt = str;
        strFloat = '0';
    }
    if(formatInt!=null){
        var outputInt = '';
        var zero = formatInt.match(/0*$/)[0].length;
        var comma = null;
        if(/,/g.test(formatInt)){
            comma = formatInt.match(/,[^,]*/)[0].length-1;
        }
        var newReg = new RegExp('(\\d{'+comma+'})','g');

        if(strInt.length<zero){
            outputInt = new Array(zero+1).join('0')+strInt;
            outputInt = outputInt.substr(outputInt.length-zero,zero)
        }else{
            outputInt = strInt;
        }

        var 
        outputInt = outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')
        outputInt = outputInt.replace(/^,/,'');

        strInt = outputInt;
    }

    if(formatFloat!=null){
        var outputFloat = '';
        var zero = formatFloat.match(/^0*/)[0].length;

        if(strFloat.length<zero){
            outputFloat = strFloat+new Array(zero+1).join('0');
            //outputFloat        = outputFloat.substring(0,formatFloat.length);
            var outputFloat1 = outputFloat.substring(0,zero);
            var outputFloat2 = outputFloat.substring(zero,formatFloat.length);
            outputFloat = outputFloat1+outputFloat2.replace(/0*$/,'');
        }else{
            outputFloat = strFloat.substring(0,formatFloat.length);
        }

        strFloat = outputFloat;
    }else{
        if(pattern!='' || (pattern=='' && strFloat=='0')){
            strFloat = '';
        }
    }

    return strInt+(strFloat==''?'':'.'+strFloat);
}
//checkBox全部勾選
//num 傳入數量
function checkedAll(num){
	if(document.getElementById("checkbox").checked==true){
		for(i=1;i<=num;i++){
			if(document.getElementById("checkbox"+i).disabled!=true){
				document.getElementById("checkbox"+i).checked=true;
			}
		}
	}
	else{
		for(i=1;i<=num;i++){
			document.getElementById("checkbox"+i).checked=false;
		}
	}
}
//取得勾選的值
//num 數量
//name 取值對象的名稱
//return 陣列
function getAlldata(num,name){ 
	dataArray=new Array();
	var count=0;
	for(i=1;i<=num;i++){
		
		if(document.getElementById("checkbox"+i).checked==true){
				dataArray[count]=document.getElementById(name+i).value;
				count++;
		}		
	} 
	return dataArray;
}

function getAlldata2(num,name){
	dataArray=new Array();
	var count=0;
	for(i=1;i<=num;i++){
		if(document.getElementById("checkbox"+i).checked==true){
			if(document.getElementById("cbox"+i).checked==true){
				dataArray[count]="true";
				count++;
			}
			else{
				dataArray[count]=document.getElementById(name+i).value;
				count++;
				}
		}		
	}
	return dataArray;
}
function getAlldata3(num){
	dataArray=new Array();
	var count=0;
	for(i=1;i<=num;i++){
		if(document.getElementById("checkbox"+i).checked==true){
				dataArray[count]=document.getElementById("checkbox"+i).value;
				count++;
		}
	}
	return dataArray;
}
function getselectvalue(){
	var count=document.getElementById("select").selectedIndex;
	return count;
}
function checkDisable(num){
	if(document.getElementById("cbox"+num).checked==true){
		document.getElementById("_trigger_a"+num).disabled=true;
		}
	else{
		document.getElementById("_trigger_a"+num).disabled=false;
		}
}
function choose(radiobutton){
	if(radiobutton.value==1){
		document.getElementById("peachmoney").style.display='block';
		document.getElementById("peachbouns").style.display='none';
		document.getElementById("freebouns").style.display='none';
		document.getElementById("radiotype").value=1;
	}
	else if(radiobutton.value==2){
		document.getElementById("peachmoney").style.display='none';
		document.getElementById("peachbouns").style.display='block';
		document.getElementById("freebouns").style.display='none';
		document.getElementById("radiotype").value=2;
		}
	else{
		document.getElementById("peachmoney").style.display='none';
		document.getElementById("peachbouns").style.display='none';
		document.getElementById("freebouns").style.display='block';
		document.getElementById("radiotype").value=3;
		}

}

function bounsCheck(num){
	var money=0;
	var total=0;
	var count=0;
	var temp=0;
	
	if(document.getElementById("radiotype").value==1){
		total=document.getElementById("peach_t").value;
		for(i=1;i<=num;i++){
			if(document.getElementById("checkbox"+i).checked==true){
				if(document.getElementById("loveType"+i).value==1){
					money=document.getElementById("peach_1").value;

				}
				else if(document.getElementById("loveType"+i).value==2){
					money=document.getElementById("peach_2").value;

				}
				else if(document.getElementById("loveType"+i).value==3){
					money=document.getElementById("peach_3").value;	

				}
				temp+=parseInt(money);
			}
		}
		
		if(parseInt(temp)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}
	else if(document.getElementById("radiotype").value==2){
		total=document.getElementById("bouns_t").value;
		for(i=1;i<=num;i++){
			if(document.getElementById("checkbox"+i).checked==true){
				if(document.getElementById("loveType"+i).value==1){
					money=document.getElementById("bouns_1").value;

				}
				else if(document.getElementById("loveType"+i).value==2){
					money=document.getElementById("bouns_2").value;

				}
				else if(document.getElementById("loveType"+i).value==3){
					money=document.getElementById("bouns_3").value;	

				}
				temp+=parseInt(money);
			}
		}
		if(parseInt(temp)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}
	else if(document.getElementById("radiotype").value==3){
		total=document.getElementById("free_t").value;
		for(i=1;i<=num;i++){
			if(document.getElementById("checkbox"+i).checked==true){
				count++;
			}
		}		
		if(parseInt(count)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}
		
}
function bounsCheckDay(){
	var money=0;
	var total=0;
	var count=0;
	var temp=0;
	
	if(document.getElementById("radiotype").value==1){
		total=document.getElementById("peach_t").value;	
		money=document.getElementById("peach_1").value;
				
				
				temp+=parseInt(money);
		if(parseInt(temp)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}
	else if(document.getElementById("radiotype").value==2){
		total=document.getElementById("bouns_t").value;
		money=document.getElementById("bouns_1").value;
		temp+=parseInt(money);
		if(parseInt(temp)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}
	else if(document.getElementById("radiotype").value==3){
		total=document.getElementById("free_t").value;
		count++;		
		if(parseInt(count)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}		
}
function bounsCheckPhoto(){
	var money=0;
	var total=0;
	var count=0;
	var temp=0;
	
	if(document.getElementById("radiotype").value==1){		
		total=document.getElementById("peach_t").value;	
		if(document.getElementById("loveType").value==1){
		money=document.getElementById("peach_1").value;
		}
		else if(document.getElementById("loveType").value==3){	
		money=document.getElementById("peach_3").value;	
		}
				temp+=parseInt(money);
		if(parseInt(temp)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}
	else if(document.getElementById("radiotype").value==2){
		total=document.getElementById("bouns_t").value;
		
		if(document.getElementById("loveType").value==1){
		money=document.getElementById("bouns_1").value;
		}
		else if(document.getElementById("loveType").value==3){	
		money=document.getElementById("bouns_3").value;	
		}
		temp+=parseInt(money);
		if(parseInt(temp)>parseInt(total)){
			return true;
		}
		else{	
			return false;
		}
	}		
}

function movefcheck(num){
	for(i=1;i<=num;i++){
		if(document.getElementById("checkbox"+i).checked==true){
				document.getElementById("fcheckbox"+i).value=true;
			}
	}
}
function display_none(num){
	var name="Ouser";
	dataArray1=new Array();
	dataArray1=getAlldata(num,name);
	for(i=0;i<dataArray1.length;i++){
		document.getElementById("ertime"+dataArray1[i]).style.display='none';
	}
}
// JavaScript Document	

function regFileName(value){
		var regFN =/^([_A-Za-z0-9]|[^u4e00-u9fa5]){0,}$/;
		if(regNotEmpty(value)){
			 if(!regFN.test(value)){
				 return false;
			 }else{
				 return true;
				 }
			}else{
			return false;
			}
		}
			function regChinese(value){
		var regCh =/^[^u4e00-u9fa5]{0,}$/;
		if(regNotEmpty(value)){			
			 if(!regCh.test(value)){
				 return false;
			 }else{
				 return true;
				 }				 
		}else{
			return false;
			}
	}
	function regEnglish(value){
		var regEng =/^[A-Za-z]{0,}$/;
		if(regNotEmpty(value)){			
			 if(!regEng.test(value)){
				 return false;
			 }else{
				 return true;
				 }				 
		}else{
			return false;
			}
	}
	function regMath(value){
		var num = "0123456789";
		if(regNotEmpty(value)){
		for (j=0; j<value.length; j++){
				if (-1 == num.indexOf(value.charAt(j))){
					return false;
				}else{
					return true;
					}
			}
			}else{
			return false;
			}
		}
	function regEnglisAndMath(value){
		var regEngAndMath =/^[A-Za-z0-9]{0,}$/;
		if(regNotEmpty(value)){
			 if(!regEngAndMath.test(value)){
				 return false;
			 }else{
				 return true;
				 }				 
		}else{
			return false;
			}
	}
	function regSmallEnglishAndMath(value){
		var regEngAndMath =/^[a-z0-9]{0,}$/;
		if(regNotEmpty(value)){
			 if(!regEngAndMath.test(value)){
				 return false;
			 }else{
				 return true;
				 }	
		}else{
			return false;
			}
	}
	function regEMail(value){
		var regMail =/^[-_A-Za-z0-9\.]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/; 
		
			if(regNotEmpty(value)){
				 if(!regMail.test(value)){
					 return false;
				 }else{
					 return true;
					 }
			}else{
				return false;
				}			
	}
function regMobile(value){
		var re1 = /^(09)\d{8}$/;
		var len=value.length;
		if(regNotEmpty(value)){
				if(len==10){
					  if(!value.match(re1)) { 
						  return false ;
					  }else{ 
						  return true ;
					  } 
				}else{
					return false;
				}
		}else{
			return false;
		}
	}


	function regNotEmpty(value){
		if(value!=null && value.replace(/^\s+|\s+$/g,"")!= ""){
			return true;
		}
		else{
			return false;		
		}
		}

