
///////////////////////動態欄位/////////////////////////////////
var gIntID = 1;

// 增加列
function insertRow(limit) {
	 var tbody = document.getElementById("fileTable").getElementsByTagName("tbody")[0]; 
	 var row = document.createElement("tr");
	 row.setAttribute("name","myRow"+gIntID);
	 
	 // 檔案欄位
	 var cell_1 = document.createElement("td");
	 var ctrl_1 =  document.createElement("input");
	 ctrl_1.setAttribute("type","file");
	 ctrl_1.setAttribute("name","myFile"+gIntID);
	 ctrl_1.setAttribute("id","myFile"+gIntID);
	 ctrl_1.setAttribute("size","");
	 ctrl_1.setAttribute("value","");
	 
	 //文字欄位
	 var cell_2 = document.createElement("td");
	 var ctrl_2 =  document.createElement("input");
	 ctrl_2.setAttribute("type","text");
	 ctrl_2.setAttribute("name","myText"+gIntID);
	 ctrl_2.setAttribute("size","18");
	 ctrl_2.setAttribute("value","");
	 ctrl_2.setAttribute("maxlength","50");
	 
	 //LABEL
	 var ctrl_3 =  document.createElement("label");
	 ctrl_3.setAttribute("innerText","照片說明：");
	 
	 //  -1 是不限制檔案數量
	 if (eval(gIntID) <= eval(limit) || eval(limit) == -1) {
		 cell_1.appendChild(ctrl_1);
		 cell_2.appendChild(ctrl_3);
		 cell_2.appendChild(ctrl_2);
		 row.appendChild(cell_1);
		 row.appendChild(cell_2);
		 tbody.appendChild(row);
		 
		 document.getElementById("fileCounter").value =  eval(gIntID) ; 
	
		 gIntID = gIntID + 1;
	 }else{
		 alert("最多只能上傳 "+ limit + " 個檔案!!");
	 }
}

// 減少列
function deleteRow() {
    var MaxID = document.getElementById("fileCounter").value ;
	var elem = document.getElementById("fileTable").getElementsByTagName("tbody")[0] ; 
	
	if (eval(MaxID) > 0) {
            elem.removeChild(elem.rows[eval(MaxID) - 1]);  // 移除 Row
			document.getElementById("fileCounter").value =  eval(MaxID) - 1 ; 
			gIntID = gIntID - 1;
	}
}
///////////////////////動態欄位/////////////////////////////////




//去空白
function trim(myStr){
  return myStr.replace(/[\s]*$/gi,"").replace(/^[\s]*/gi,"");
}

//檢查 Email 格式
function check_email(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


//判斷數值
function IsNum(num_string) {
	var re =/\d{1,}/ 
	var re_result=re.exec(num_string)
	if (re_result== num_string )
	{
		return true ;
	}else{
		return false ;
	}
	
}


//刪除確認
function Del_confirm(myStr) 
{ 
	return confirm(myStr);
}



function Change_bg(src, BackColor) 
{ 
   	if (!src.contains(event.fromElement)) 
		{
	   		src.style.cursor = "hand";
			src.bgColor = BackColor;
		}
}



function Restore_bg(src, BackColor)
{
		if (!src.contains(event.toElement))
		{
			src.style.cursor="default";
			src.bgColor = BackColor; 
		}
}

//等比例縮圖
function DrawImage(ImgD,FitWidth,FitHeight) 
{ 
var image=new Image(); 
image.src=ImgD.src; 
if(image.width>0 && image.height>0) 
{ 
if(image.width/image.height>= FitWidth/FitHeight) 
{ 
if(image.width>FitWidth) 
{ 
ImgD.width=FitWidth; 
ImgD.height=(image.height*FitWidth)/image.width; 
} 
else 
{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
} 
else 
{ 
if(image.height>FitHeight) 
{ 
ImgD.height=FitHeight; 
ImgD.width=(image.width*FitHeight)/image.height; 
} 
else 
{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
} 
} 
}
  

