/* 
---------------------------------------------------------------
  start General
--------------------------------------------------------------- 
*/
function facebook() {
　void(window.open('http://www.facebook.com/share.php?u='.concat(encodeURIComponent(location.href))));
}
function facebook_invite(url) {
　void(window.open('http://www.facebook.com/share.php?u='.concat(encodeURIComponent(url))));
}
function twitter() {
　void(window.open('http://twitter.com/home?status='.concat(encodeURIComponent(location.href))));
}
// 加入書籤
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("您的瀏覽器不支援此向操作!");
	}
}
// 前往url
function goTo(url) {
  location.href = url;
}
// 中文 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(object, set) {
	var s = '';

	$(object+" 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 val_set(set, get) {
	var v = $(get).val();
	$(set).val(v);
}
// 顯示圖片路徑
function img_set(object, s) {
	$(object).attr({ src: s });
}
function o_show(object) {
	$(object).show();
}
function o_hide(object) {
	$(object).hide();
}
function o_empty(object) {
	$(object).empty();
}
function o_remove(object) {
	$(object).remove();
}
// 對話框圖層
function dialog(obj, s, h, w) {
	$(obj).dialog('destroy');
	$(obj).dialog('open');
	$(obj).dialog({
		bgiframe: true,
		title: s,
		height: h,
		width: w
	});
}
/* 
---------------------------------------------------------------
  end   General
--------------------------------------------------------------- 
---------------------------------------------------------------
  start Ajax
--------------------------------------------------------------- 
*/
function ajaxHtml(source, object) {
	$.ajax({
		type: 'GET',
		url: source,
		cache: false,
		timeout: 50000,
		error: function() {
			window.alert(source + " 伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(object).html(request);
		}
	});
}

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

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

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

function ajaxEvent(source, object, target) {
	var v = $(object).val();
	source += v;	
	
	ajaxHtml(source, target);
}
function ajaxCheckBox(source, form, method, object) {		
	var v = form;
	v = v.replace("#", "");
	
	$.ajax({
		url: source + '&validator=' + v,
		data: $(form).serialize(),
		type: method,
		cache: false,
		timeout: 50000,
		error: function() {
			window.alert(source + " 伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			if (request == '') {
				$.fn.colorbox.close();
				$(object).html(request);
			} else {
				$(form).append(request);
			}
		}
	});
}
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(source + " 伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(form).append(request);
		}
	});
}

function ajaxPost(source, form, method, object) {		
	$.ajax({
		url: source,
		data: $(form).serialize(),
		type: method,
		cache: false,
		timeout: 50000,
		error: function() {
			window.alert(source + " 伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(object).html(request);
		}
	});
}

function ajaxSearch(source, form, object) {		
	$.address.value(source + '&' + $(form).serialize());
	
	$.ajax({
		url: source,
		data: $(form).serialize(),
		type: 'get',
		cache: false,
		timeout: 50000,
		error: function() {
			window.alert(source + " 伺服器沒有回應!請重新操作");
		},
		success: function(request) {
			$(object).html(request);
		}
	});
}
/* 
---------------------------------------------------------------
  end   Ajax
--------------------------------------------------------------- 
*/
