function copyToClipboard(e)
   {
	
    if (document.all){                                              //判斷IE
    
window.clipboardData.setData('text', e);
   alert("成功複製到剪貼板！");}
    else{
   alert("您的瀏覽器不支持剪貼板操作，請自行複製。");
     };
}


// 檢測日期有效性
// 必須使用格式  日/月/年
function checkDate(val) {
	var validformat = /^\d{2}\/\d{2}\/\d{4}jq/; // Basic check for format
	// validity
	var returnval = false;
	if (!validformat.test(val)) {
		// alert("Invalid Date Format. Please correct and submit again.")
		return false;
	} else { // Detailed check for valid date ranges
		var dayfield = val.split("/")[0];
		var monthfield = val.split("/")[1];
		var yearfield = val.split("/")[2];
		var dayobj = new Date(yearfield, monthfield - 1, dayfield);
		if ((dayobj.getMonth() + 1 != monthfield)
				|| (dayobj.getDate() != dayfield)
				|| (dayobj.getFullYear() != yearfield))
			// alert("Invalid Day, Month, or Year range detected. Please correct
			// and submit again.")
			returnal = false;
		else
			returnval = true;
	}
	/*
	 * if (returnval == false) input.select()
	 */
	return returnval;

}

//檢測日期有效性
function isValidDate(day, month, year) {
	/*
	 * Purpose: return true if the date is valid, false otherwise
	 * 
	 * Arguments: day integer representing day of month month integer
	 * representing month of year year integer representing year
	 * 
	 * Variables: dteDate - date object
	 * 
	 */
	var dteDate;

	// set up a Date object based on the day, month and year arguments
	// javascript months start at 0 (0-11 instead of 1-12)
	dteDate = new Date(year, month, day);

	/*
	 * Javascript Dates are a little too forgiving and will change the date to a
	 * reasonable guess if it's invalid. We'll use this to our advantage by
	 * creating the date object and then comparing it to the details we put it.
	 * If the Date object is different, then it must have been an invalid date
	 * to start with...
	 */

	return ((day == dteDate.getDate()) && (month == dteDate.getMonth()) && (year == dteDate
			.getFullYear()));
}



function confirmDialog(dialog) {
	if (dialog.title == '' || dialog.title == undefined) {
		dialog.title = '提示';
	}
	if (dialog.width == undefined || null == dialog.width) {
		width = 300;
	}
	if (dialog.height == undefined || null == dialog.height) {
		height = 200;
	}
	jq("#dialog-confirm").attr('title', dialog.title);
	jq("#dialog-confirm p span.msg").html(dialog.msg);
	jq("#dialog-confirm").dialog({
		height : height,
		width : width,
		modal : true,
		buttons : {
			"確定" : function() {
				jq(this).dialog("close");
				var func = dialog.func;
				eval(func);
			},
			"取消" : function() {
				jq(this).dialog("close");
			}

		},

		close : function(event, ui) {
			if (dialog.url != undefined && null != dialog.url) {
				location.href = dialog.url;
			}
		},
		resizable : false,
		draggable : false

	});
}

function _showDialog(dialog) {
	jq( "#dialog-modal" ).dialog( "destroy" );
	if (dialog.title == '' || dialog.title == undefined) {
		dialog.title = '提示';
	}
	if (dialog.width == undefined || null == dialog.width) {
		dialog.width = 300;
	}
	if (dialog.height == undefined || null == dialog.height) {
		dialog.height = 200;
	}
	jq("#dialog-modal").attr('title', dialog.title);
	jq("#dialog-modal p").html(dialog.msg);
	jq("#dialog-modal").dialog({
		height : dialog.height,
		width : dialog.width,
		modal : true,
		buttons : {
			Ok : function() {
				if (dialog.url == undefined || null == dialog.url || '' == dialog.url) {
					jq(this).dialog("close");
				} else {
					location.href = dialog.url.replace(/\&amp;/g, '&');
				}
			}
		},
		close : function(event, ui) {
			if (dialog.url != undefined && null != dialog.url) {
				location.href = dialog.url;
			}
		},
		resizable : false,
		draggable : false

	});
}

// email validation
function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

// ajax 共同函數
function doAjax(obj) {

	var response = jq.ajax({
		type : 'post',
		dataType : 'json',
		data : obj,
		url : obj.url,
		async : false,
		beforeSend : function(XMLHttpRequest) {
			if (obj.loading) {
				loading();
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
			if (obj.loading) {
				unloading();
			}

		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			var dialog = {
				'title' : '錯誤',
				'msg' : "程序出現未知錯誤，請聯繫我們取得技術支持。"
			};
			showDialog(dialog);
			
			
		} 		
	}).responseText;

	eval("var data=" + response);
	return data;
}

// 根據項目提取表記錄
function getDataListByField(obj) {
	var response = jq.ajax({
		type : 'post',
		dataType : 'json',
		data : obj,
		url : obj.url,
		async : false
	}).responseText;
	eval("var data=" + response);
	return data;
}

// 表單保存記錄
function addData(obj) {
	var response = jq.ajax({
		type : 'post',
		dataType : 'json',
		data : obj,
		url : obj.url,
		async : false,
		beforeSend : function(XMLHttpRequest) {
			if (obj.loading) {
				loading();
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
			if (obj.loading) {
				unloading();
			}

		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			var dialog = {
				'title' : '錯誤',
				'msg' : "程序出現未知錯誤，請聯繫我們取得技術支持。"
			};
			showDialog(dialog);
			
			
		} 				
	}).responseText;
	eval("var data=" + response);
	return data;
}

// 提取表記錄
function getDataByField(obj) {
	var response = jq.ajax({
		type : 'post',
		dataType : 'json',
		data : obj,
		url : obj.url,
		async : false
	}).responseText;
	eval("var data=" + response);
	return data;
}

function showInfo(showObj, msg) {

	var options = {};
	jq(".ui-widget div").addClass('ui-state-highlight')
			.addClass('ui-corner-all');
	jq(".ui-widget div .msg").text(msg);

	jq(showObj).show("slide", options, 500);

}

