﻿window.addEvent("domready", function() {	
	if( $("favAddBtn") ){
		$("favAddBtn").addEvent("click", function(e) {
			$("favAddBtn").className = "divHide webpackbtn";
			$("favSaveBtn").className = "webpackbtn";
			$("favCatSel").className = "divShow";
			$("favCancelBtn").className = "webpackbtn";
			$("favMsg").className = "divShow";
		});
	}
	if( $("favCancelBtn") ){
		$("favCancelBtn").addEvent("click", function(e) {
			$("favAddBtn").className = "webpackbtn";
			$("favSaveBtn").className = "divHide webpackbtn";
			$("favCatSel").className = "divHide";
			$("favCancelBtn").className = "divHide webpackbtn";
			$("favMsg").className = "divHide";
			$("favNewCat").className = "divHide";
			$("favCatSel").value = "none";
		});
	}
	if( $("favCatSel") ){
		$("favCatSel").addEvent("change", function(e) {
			$("favNewCat").value = "";
			if( $("favCatSel").value == "new" ){
				$("favNewCat").className = "divShow";
				$("favNewCat").focus();	
			}
			else{
				$("favNewCat").className = "divHide";
			}
			
		});
	}
	if( $("favForm") ){
		$("favForm").addEvent("submit", function(e) {			
			e = new Event(e).stop();
			//先抓資料
			if( $("favCatSel").value == "new" ){
				$("favCat").value = $("favNewCat").value;
			}
			else{
				$("favCat").value = $("favCatSel").value;
			}
			
			var ckStr = $("favCat").value;
			
			if ( ckStr.trim() == "" ){
				alert("分類名稱不能空白");
				$("favCat").value = "";
				return false;
			}
			this.send({
				onComplete: function() {
					location.reload(true);
				}
			});
			
			
		});
	}
});
function deleteMyFavor(o){
	if( !confirm("確定刪除?"))
		return false;
		
	var favorID;
	favorID = o.id;
	var url = "IVaFavor/favor.userRemoveFavor.asp?gicuitem=" + favorID;

	var ajaxDeleteFavor = new Ajax(url, {
		method: 'get',
		onComplete: function() {
			location.reload(true);
		}
	});
	
	ajaxDeleteFavor.request();
	
}
function addUDNBookmark() {
	desc='';
	via='';
	if(document.referrer)via=document.referrer;
	if(typeof(_ref)!='undefined')via=_ref;
	if(window.getSelection)desc=window.getSelection();
	if(document.getSelection)desc=document.getSelection();
	if(document.selection)desc=document.selection.createRange().text;
	window.open('http://bookmark.udn.com/add?f_TITLE='+encodeURIComponent(document.title)+'&f_URL='+encodeURIComponent(location.href)+'&f_DIGEST='+encodeURIComponent(desc)+'&via='+encodeURIComponent(via));

}
function addHemidemiBookmark() {
	window.open('http://www.hemidemi.com/user_bookmark/new?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title));
}
function addMyshareBookmark() {
	window.open('http://myshare.url.com.tw/index.php?func=newurl&from=mysharepop&NewsMaster=1&url='+encodeURIComponent(location.href)+'&desc='+encodeURIComponent(document.title));
}

function addYahooBookmark() {
	window.open('http://tw.myweb2.search.yahoo.com/myresults/bookmarklet?u='+encodeURIComponent(location.href)+'&ei=UTF-8&t='+encodeURIComponent(document.title));
}
function addDeliciousBookmark() {
	window.open('https://secure.del.icio.us/login?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title));
}

function addfURIBookmark() {
	window.open('http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title));
}
