/* 
---------------------------------------------------------------
  start General
--------------------------------------------------------------- 
*/
// 加入書籤
function bookmark() {
	if ($.browser.msie) {
		window.external.AddFavorite(location.href, document.title);
	} else if ($.browser.mozilla){
		window.sidebar.addPanel(document.title, location.href, '');
	} else {
		window.alert("您的瀏覽器不支援此向操作!");
	}
}
// 跳頁選單
function selectJump(targ, selObj, restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
// 開新視窗
function windowOpen(url, id) {
	myWindow = window.open(url, id);
}
// 前往url
function goTo(url) {
  location.href = url;
}
// 呼叫javascript
function evalString(s) { //v2.0
  return eval(s)
}
// 中文 to Unicode
function chineseToUnicode(obj, element){ 
	var s = $(obj).val;
  var v = ''; 
	
	for(var i=0; i<s.length; i++) { 
		var k = s.substring(i, i + 1);
		
		v += "&#"+s.charCodeAt(i)+";"; 
	} 
	
	$(element).val = v;
}
// 取得複選框值
function checkboxGet(obj, set) {
	var s = '';

	$(obj+" input:checked").each( function() {
		s += this.value+",";
	});

	var i = s.length - 1;
	$(set).val(s.substr(0, i));
}
function checkboxAll() {
	$('input[name*="choose"]').each( function() {
		this.checked = true;
	});
}
function checkboxUn() {
	$('input[name*="choose"]').each( function() {
		this.checked = false;
	});
}
// 置入值
function setValue(set, get) {
	var v = $("#"+get).val();
	$("#"+set).val(v);
}
// 顯示圖片路徑
function imgSrc(obj, s) {
	$(obj).attr({ src: s });
}
// 顯示圖層
function objShow(obj) {
	$(obj).show();
}
// 隱藏圖層
function objHide(obj) {
	$(obj).hide();
}
// 對話框圖層
function objDialog(obj, s, h, w) {
	$(obj).dialog('destroy');
	$(obj).dialog('open');
	$(obj).dialog({
		bgiframe: true,
		title: s,
		height: h,
		width: w
	});
}
// ckeditor
function editor(source){
	objDialog('#jEditor', 'HTML編輯器', 600, 900); 
	ajaxHtml(source, '#aEditor');
}
/* 
---------------------------------------------------------------
  end   General
--------------------------------------------------------------- 
---------------------------------------------------------------
  start Ajax
--------------------------------------------------------------- 
*/
function ajaxHistory(source, object) {
	location.hash = '#' + source;
	
	ajaxHtml(source, object);
}
function ajaxHtml(source, object) {
	location.hash = '#' + source;
	
	$.ajax({
		type: 'GET',
		url: source,
		cache: false,
		timeout: 50000,
		/*beforeSend: function(request){
			$('body').append(loading);
		},*/
		error: function() {
			window.alert("伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(object).html(request);
		}
	});
}

function ajaxText(source, object){
	$.ajax({
		type: 'GET',
		url: source,
		cache: false,
		timeout: 50000,
		error: function() {
			window.alert("伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(object).text(request);
		}
	});
}

function ajaxAppend(source, object){
	$.ajax({
		type: 'GET',
		url: source,
		cache: false,
		timeout: 50000,
		error: function() {
			window.alert("伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(object).append(request);
		}
	});
}

function ajaxDialog(s, h, w, source, object){
	objDialog('#jDialog', s, h, w); 
	ajaxHtml(source, object);
}

function ajaxEvent(source, object, target) {
	var v = $(object).val();
	source += v;	
	
	ajaxHtml(source, target);
}

function ajaxCheck(source, form, method) {		
	var v = form;
	v = v.replace("#", "");
	
	$.ajax({
		url: source + '&validator=' + v,
		data: $(form).serialize(),
		type: method,
		cache: false,
		timeout: 50000,
		error: function() {
			window.alert("伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(form).append(request);
		}
	});
}

function ajaxPost(source, form, method, object) {		
	//$('#jDialog').dialog('close');
	
	$.ajax({
		url: source,
		data: $(form).serialize(),
		type: method,
		cache: false,
		timeout: 50000,
		/*beforeSend: function(request){
			$(object).append(loading);
		},*/
		error: function() {
			window.alert("伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(object).html(request);
		}
	});
}
/* 
---------------------------------------------------------------
  end   Ajax
--------------------------------------------------------------- 
*/