/***********************************************
* Show Hint script- ? Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var bm_style = ['h_list_bm', 'h_tag_bm', 'h_compact_bm', 'h_grid_bm', 'h_detail_bm', 'h_full_bm', 'complete', 'compact']

var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all
var _opera=window.opera&&navigator.userAgent.match(/opera/gi)
function getposOffset(what, offsettype){
 var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
 var parentEl=what.offsetParent;
 while (parentEl!=null) {
 totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
 parentEl=parentEl.offsetParent;
 }
 return totaloffset;
}

function iecompattest(){
 return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
 var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
 if (whichedge=="rightedge") {
 var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
 dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
 if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) {
 edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
 }
 } else{
 var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
 dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
 if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) {
 edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
 }
 }
 return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
 if ((ie||ns6) && document.getElementById("hintbox")){
 dropmenuobj=document.getElementById("hintbox")
 dropmenuobj.innerHTML=menucontents
 dropmenuobj.style.left=dropmenuobj.style.top=-500
 if (tipwidth!="") {
 dropmenuobj.widthobj=dropmenuobj.style
 dropmenuobj.widthobj.width=tipwidth
 }
 dropmenuobj.x = getposOffset(obj, "left")
 dropmenuobj.y = getposOffset(obj, "top")
 dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + obj.offsetWidth+"px"
 dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
 dropmenuobj.style.visibility="visible"
 obj.onmouseout = hidetip
 }
}

function hidetip(e){
 dropmenuobj.style.visibility = "hidden"
 dropmenuobj.style.left="-500px"
}

function createhintbox(){
 var divblock=document.createElement("div")
 divblock.setAttribute("id", "hintbox")
 document.body.appendChild(divblock)
}

var wMarks = new Array();
var posX;
var posY;

function setVals(){
 if (!ie || _opera){
 posX = window.innerWidth / 2;
 posY = window.innerHeight / 2;
 } else {
 posX = document.documentElement.clientWidth / 2;
 posY = document.documentElement.clientHeight / 2;
 }
}

function wRefresh(){
 var x;

 if (!ie || _opera){
 for (x in wMarks) {
 width = 100;
 height = 60;

 if (wMarks[x].width != null ) {
 width = parseInt(wMarks[x].width.replace(/px/g,"")) / 2
 }
 if (wMarks[x].height != null ) {
 height = parseInt(wMarks[x].height.replace(/px/g,"")) / 2
 }

 /*
 wMarks[x].left = posX + window.pageXOffset - 100 + 'px';
 wMarks[x].top = posY + window.pageYOffset - 60 + 'px';
 */
 wMarks[x].left = posX + window.pageXOffset - width + 'px';
 wMarks[x].top = posY + window.pageYOffset - height + 'px';
 }
 } else {
 for (x in wMarks) {

 width = 100;
 height = 60;

 if (wMarks[x].width != null ) {
 width = parseInt(wMarks[x].width.replace(/px/g,"")) / 2
 }
 if (wMarks[x].height != null ) {
 height = parseInt(wMarks[x].height.replace(/px/g,"")) / 2
 }


 /*
 wMarks[x].left = posX + document.documentElement.scrollLeft - 100 + 'px';
 wMarks[x].top = posY + document.documentElement.scrollTop - 60 + 'px';
 */
 wMarks[x].left = posX + document.documentElement.scrollLeft - width + 'px';
 wMarks[x].top = posY + document.documentElement.scrollTop - height + 'px';
 }
 }
}

function markMe(){
 markID = setInterval("wRefresh()", 200);
}

function onBoydLoad() {

 setVals();

 box = document.getElementById("busy-box");
 if (box != null){
   wMarks[0] = box.style;
 }

 ajax_dialog = document.getElementById("ajax-dialog");
 if (ajax_dialog != null){
   wMarks[1] = ajax_dialog.style;
 }

 _sdialog = document.getElementById("sdialog");
 if (_sdialog != null){
   wMarks[2] = _sdialog.style;
 }

 mdialog = document.getElementById("mdialog");
 if (mdialog != null) {
 wMarks[3] = mdialog.style;
 }

 window.onresize = setVals;
 markMe();
 createhintbox();

}

if (window.addEventListener) {
 window.addEventListener("load", onBoydLoad, false)
} else if (window.attachEvent) {
 window.attachEvent("onload", onBoydLoad)
} else if (document.getElementById) {
 window.onload = onBoydLoad
}

/* for tag selection when add userbookmar */

function addFireFoxSearchPlugin() {
 if((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
 window.sidebar.addSearchEngine(
 "http://www.hemidemi.com/firefox/search_plugin/hemidemi.src",
 "http://www.hemidemi.com/firefox/search_plugin/hemidemi.gif",
 "HEMiDEMi FireFox Search Plugin",
 "General");
 } else {
 alert("For FireFox Only!!");
 }
}

function statbar(txt) {
 window.status = txt;
 return true;
}

function fieldClear(id) {
 document.getElementById(id).value = ''
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

 var xScroll, yScroll;

 if (window.innerHeight && window.scrollMaxY) {
 xScroll = document.body.scrollWidth;
 yScroll = window.innerHeight + window.scrollMaxY;
 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
 xScroll = document.body.scrollWidth;
 yScroll = document.body.scrollHeight;
 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
 xScroll = document.body.offsetWidth;
 yScroll = document.body.offsetHeight;
 }

 var windowWidth, windowHeight;
 if (self.innerHeight) { // all except Explorer
 windowWidth = self.innerWidth;
 windowHeight = self.innerHeight;
 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
 windowWidth = document.documentElement.clientWidth;
 windowHeight = document.documentElement.clientHeight;
 } else if (document.body) { // other Explorers
 windowWidth = document.body.clientWidth;
 windowHeight = document.body.clientHeight;
 }

 // for small pages with total height less then height of the viewport
 if(yScroll < windowHeight){
 pageHeight = windowHeight;
 } else {
 pageHeight = yScroll;
 }

 // for small pages with total width less then width of the viewport
 if(xScroll < windowWidth){
 pageWidth = windowWidth;
 } else {
 pageWidth = xScroll;
 }


 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
 return arrayPageSize;
}

function startOverlay(name, changeBG){
 hideSelects('hidden');
 // stretch overlay to fill page and fade in
 var arrayPageSize = getPageSize();
 _overlay = document.getElementById('overlay');
 _overlay.style.height = arrayPageSize[1] + 'px';
 new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
 new Effect.Appear(name);
 if (changeBG) {
 document.body.style.background="white";
 }
}

function stopOverlay(name) {
 /* bad! hardcode background color here */
 document.body.style.background='#4C4A48';
 hideSelects('visible');
 Element.hide(name);
 Element.hide('overlay');

}

function clearDefaultandCSS(el) {
 if (el.defaultValue==el.value) el.value = ""
 // If Dynamic Style is supported, clear the style
 if (el.style) el.style.cssText = ""
}

function hideSelects(visibility) {

  selects = document.getElementsByTagName('select');

  for(i = 0; i < selects.length; i++) {
  /* hack! bad solution! for save user_bookmark, we like to select channel */
  if (selects[i].id != 'bookmark_params_channel_id' && selects[i].id != 'user_bookmark_category_id' && selects[i].id != 'object_categories_parent_id' && selects[i].id != 'user_bookmark_permission') {
    if (selects[i] != null) {
      selects[i].style.visibility = visibility;
    }
  }
  }
  _embeds = document.getElementsByTagName('embed');
  for(i = 0; i < _embeds.length; i++){
    if (_embeds[i] != null) {
      _embeds[i].style.visibility = visibility;
    }
  }

  _objects = document.getElementsByTagName('object');
  for(i = 0; i < _objects.length; i++){
    if (_objects[i] != null) {
      _objects[i].style.visibility = visibility;
    }
  }
}

function getElementsByClass(searchClass,node,tag) {
 var classElements = new Array();
 if ( node == null )
 node = document;
 if ( tag == null )
 tag = '*';
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
 for (i = 0, j = 0; i < elsLen; i++) {
 if ( pattern.test(els[i].className) ) {
 classElements[j] = els[i];
 j++;
 }
 }
 return classElements;
}

function show_bookmark_attribute() {
 var v = document.getElementById('show_bookmark_attribute');
 var divs = getElementsByClass("attribute", document, "div");
 for (i=0; i<divs.length; i++) {
 if (v.checked == true) {
 divs[i].style.display = 'block';
 } else {
 divs[i].style.display='none';
 }
 }
}

function loadingimg(id, string)
{
 document.getElementById(id).innerHTML = "<img src='/images/ajaxtabs/loading.gif' />" + string
}

function clear_div(id)
{
 document.getElementById(id).innerHTML = ""
}

 function bookmarkStyle(new_style){
 if(new_style == ''){
 return;
 }

 all_nodes = document.getElementsByTagName("div");
 for(i = 0; i < all_nodes.length ; i++){
 for(j = 0; j < bm_style.length; j++){
 if(all_nodes[i].className == bm_style[j]){
 all_nodes[i].className = new_style;
 }
 }
}
}


function changeStyle(id, newstyle) {
  obj = document.getElementById(id)
  if (obj != null) {
    obj.className = newstyle;
  }
}

function blind_down_menu(id){
  if(document.getElementById(id).style.display == 'none')
    new Effect.BlindDown('view_style', {duration:0})
  else
    document.getElementById(id).style.display = 'none'
}

function set_priority_0(id){
 document.getElementById('user_item_'+id).className = 'h_priority_0';
// Element.show('user_hidden_name_'+id);
 Element.hide('user_close_button_'+id);
 Element.show('user_open_button_'+id);
 Element.show('user_mark_button_'+id);
 Element.hide('user_unmark_button_'+id);
 Element.hide('user_item_container_' + id);
}

function set_priority_1(id){
 document.getElementById('user_item_'+id).className = 'h_priority_1';
// Element.hide('user_hidden_name_'+id);
 Element.show('user_close_button_'+id);
 Element.hide('user_open_button_'+id);
 Element.show('user_mark_button_'+id);
 Element.hide('user_unmark_button_'+id);
 Element.show('user_item_container_' + id);
}

function set_priority_2(id){
 document.getElementById('user_item_'+id).className = 'h_priority_2';
// Element.hide('user_hidden_name_'+id);
 Element.show('user_close_button_'+id);
 Element.hide('user_open_button_'+id);
 Element.hide('user_mark_button_'+id);
 Element.show('user_unmark_button_'+id);
 Element.show('user_item_container_' + id);

}

function hsetCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function hgetCookie(Name){ 
  var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
  if (document.cookie.match(re)) //if cookie found
    return document.cookie.match(re)[0].split("=")[1] //return its value
  return ""
}

function hsetCookie(name, value){
  document.cookie = name+"="+value+"; expires=Tue, 1 Jan 2010 00:00:00 UTC;path=/;" //cookie value is domain wide (path=/)
}

function prevent(e){
  if (window.event)
    window.event.returnValue = false;
  else
    e.preventDefault()
}

function loadUserinfo() {
  username = hgetCookie(":username");
  if (username == null || username == '') {
    username = 'guest';
  }
  url = "/user/" + username + "/setting/userinfo";
  new Ajax.Updater('userinfo', url, {asynchronous:true, evalScripts:true, onComplete:function(request){}, onLoading:function(request){}});
}

function comment_bury_prompt(divid, id) {
  html = "<ul id=\"cbury_" + id + "_dropdown\" class=\"dropdown\" style=\"position:absolute;z-index:500;float:right;\">";
  html = html + "<li onMouseOver=\"this.className='mover';\" onMouseOut=\"this.className='mout';\" onclick=\"Element.hide('cbury_" + id + "_dropdown');\" style=\"display:block;\">關閉</li>";
  html = html + "<li onMouseOver=\"this.className='mover';\" onMouseOut=\"this.className='mout';\" onclick=\"comment_bury(" + id + ", 'spam');\" style=\"display:block;\">這是廣告</li>";
  html = html + "<li onMouseOver=\"this.className='mover';\" onMouseOut=\"this.className='mout';\" onclick=\"comment_bury(" + id + ", 'porn');\" style=\"display:block;\">不雅發言</li>";
  html = html + "<li onMouseOver=\"this.className='mover';\" onMouseOut=\"this.className='mout';\" onclick=\"comment_bury(" + id + ", 'inappropriate');\" style=\"display:block;\">人身攻擊、謾罵等不適當發言</li>";
  html = html + "</ul>";
  new Insertion.After(divid, html);
}

function comment_bury(id, flagname) {
  str = "cbury_" + id + "_dropdown";
  Element.hide(str);
  new Ajax.Updater('cbc_'+ id, '/comment/bury/' + id + '?flagname='+flagname, {asynchronous:true, evalScripts:true, onLoading:function(request){Element.toggle('cb_' + id);Element.toggle('cub_' + id);}});
}
